MCPcopy Create free account
hub / github.com/cli/cli / TestRootRejectsJunction

Function TestRootRejectsJunction

internal/safepaths/link_windows_test.go:89–110  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

87}
88
89func TestRootRejectsJunction(t *testing.T) {
90 rootDir := t.TempDir()
91 target := t.TempDir()
92 junction := filepath.Join(rootDir, "junction")
93 if output, err := exec.Command("cmd", "/c", "mklink", "/J", junction, target).CombinedOutput(); err != nil {
94 t.Skipf("junctions unavailable: %v: %s", err, output)
95 }
96
97 root, err := OpenRoot(rootDir)
98 require.NoError(t, err)
99 defer root.Close()
100
101 err = root.WriteFile(filepath.Join("junction", "file.txt"), []byte("content"), 0o644, 0o755, false)
102 require.ErrorContains(t, err, "symbolic link")
103 assert.NoFileExists(t, filepath.Join(target, "file.txt"))
104
105 err = root.WriteFile("junction", []byte("content"), 0o644, 0o755, true)
106 require.Error(t, err)
107 info, err := os.Lstat(junction)
108 require.NoError(t, err)
109 assert.NotZero(t, info.Sys().(*syscall.Win32FileAttributeData).FileAttributes&syscall.FILE_ATTRIBUTE_REPARSE_POINT)
110}
111
112func TestOpenFileRejectsWindowsTrailingSeparator(t *testing.T) {
113 tests := []struct {

Callers

nothing calls this directly

Calls 7

OpenRootFunction · 0.85
JoinMethod · 0.80
CommandMethod · 0.80
WriteFileMethod · 0.80
SysMethod · 0.80
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected