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

Function TestRedirectTargetClassificationError

internal/safepaths/root_validation_test.go:58–76  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

56}
57
58func TestRedirectTargetClassificationError(t *testing.T) {
59 rootDir := t.TempDir()
60 require.NoError(t, os.WriteFile(filepath.Join(rootDir, "target"), []byte("target"), 0o644))
61 require.NoError(t, os.Symlink("target", filepath.Join(rootDir, "link")))
62
63 root, err := OpenRoot(rootDir)
64 require.NoError(t, err)
65 defer root.Close()
66 root.stat = func(*os.Root, string) (os.FileInfo, error) {
67 return nil, errors.New("stat failed")
68 }
69
70 file, err := root.Create("link", 0o644, 0o755, true)
71 assert.Nil(t, file)
72 require.ErrorContains(t, err, "could not safely classify redirect target")
73 info, err := os.Lstat(filepath.Join(rootDir, "link"))
74 require.NoError(t, err)
75 assert.NotZero(t, info.Mode()&os.ModeSymlink)
76}

Callers

nothing calls this directly

Calls 6

OpenRootFunction · 0.85
WriteFileMethod · 0.80
JoinMethod · 0.80
ModeMethod · 0.80
CloseMethod · 0.65
CreateMethod · 0.65

Tested by

no test coverage detected