mirror of
https://github.com/anchore/syft.git
synced 2026-11-03 16:06:36 +01:00
rename file.Location.VirtualPath to AccessPath (#2288)
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
@@ -90,13 +90,13 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
cwd string
|
||||
root string
|
||||
base string
|
||||
input string
|
||||
expectedRealPath string
|
||||
expectedVirtualPath string // if empty, the virtual path should be the same as the real path
|
||||
name string
|
||||
cwd string
|
||||
root string
|
||||
base string
|
||||
input string
|
||||
expectedRealPath string
|
||||
expectedAccessPath string // if empty, the virtual path should be the same as the real path
|
||||
}{
|
||||
{
|
||||
name: "relative root, relative request, direct",
|
||||
@@ -319,32 +319,32 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
|
||||
},
|
||||
// link to outside of root cases...
|
||||
{
|
||||
name: "relative root, relative request, abs indirect (outside of root)",
|
||||
root: filepath.Join(relative, "path"),
|
||||
input: "to/the/abs-outside.txt",
|
||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
||||
name: "relative root, relative request, abs indirect (outside of root)",
|
||||
root: filepath.Join(relative, "path"),
|
||||
input: "to/the/abs-outside.txt",
|
||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
expectedAccessPath: "to/the/abs-outside.txt",
|
||||
},
|
||||
{
|
||||
name: "abs root, relative request, abs indirect (outside of root)",
|
||||
root: filepath.Join(absolute, "path"),
|
||||
input: "to/the/abs-outside.txt",
|
||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
||||
name: "abs root, relative request, abs indirect (outside of root)",
|
||||
root: filepath.Join(absolute, "path"),
|
||||
input: "to/the/abs-outside.txt",
|
||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
expectedAccessPath: "to/the/abs-outside.txt",
|
||||
},
|
||||
{
|
||||
name: "relative root, abs request, abs indirect (outside of root)",
|
||||
root: filepath.Join(relative, "path"),
|
||||
input: "/to/the/abs-outside.txt",
|
||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
||||
name: "relative root, abs request, abs indirect (outside of root)",
|
||||
root: filepath.Join(relative, "path"),
|
||||
input: "/to/the/abs-outside.txt",
|
||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
expectedAccessPath: "to/the/abs-outside.txt",
|
||||
},
|
||||
{
|
||||
name: "abs root, abs request, abs indirect (outside of root)",
|
||||
root: filepath.Join(absolute, "path"),
|
||||
input: "/to/the/abs-outside.txt",
|
||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
||||
name: "abs root, abs request, abs indirect (outside of root)",
|
||||
root: filepath.Join(absolute, "path"),
|
||||
input: "/to/the/abs-outside.txt",
|
||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
expectedAccessPath: "to/the/abs-outside.txt",
|
||||
},
|
||||
{
|
||||
name: "relative root, relative request, relative indirect (outside of root)",
|
||||
@@ -352,8 +352,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
|
||||
input: "to/the/rel-outside.txt",
|
||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
// TODO: the real path is not correct
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedAccessPath: "to/the/rel-outside.txt",
|
||||
},
|
||||
{
|
||||
name: "abs root, relative request, relative indirect (outside of root)",
|
||||
@@ -361,8 +361,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
|
||||
input: "to/the/rel-outside.txt",
|
||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
// TODO: the real path is not correct
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedAccessPath: "to/the/rel-outside.txt",
|
||||
},
|
||||
{
|
||||
name: "relative root, abs request, relative indirect (outside of root)",
|
||||
@@ -370,8 +370,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
|
||||
input: "/to/the/rel-outside.txt",
|
||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
// TODO: the real path is not correct
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedAccessPath: "to/the/rel-outside.txt",
|
||||
},
|
||||
{
|
||||
name: "abs root, abs request, relative indirect (outside of root)",
|
||||
@@ -379,41 +379,41 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
|
||||
input: "/to/the/rel-outside.txt",
|
||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
// TODO: the real path is not correct
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedAccessPath: "to/the/rel-outside.txt",
|
||||
},
|
||||
// link to outside of root cases... cwd within symlink root
|
||||
{
|
||||
name: "relative root, relative request, abs indirect (outside of root), cwd within symlink root",
|
||||
cwd: relativeViaLink,
|
||||
root: "path",
|
||||
input: "to/the/abs-outside.txt",
|
||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
||||
name: "relative root, relative request, abs indirect (outside of root), cwd within symlink root",
|
||||
cwd: relativeViaLink,
|
||||
root: "path",
|
||||
input: "to/the/abs-outside.txt",
|
||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
expectedAccessPath: "to/the/abs-outside.txt",
|
||||
},
|
||||
{
|
||||
name: "abs root, relative request, abs indirect (outside of root), cwd within symlink root",
|
||||
cwd: relativeViaLink,
|
||||
root: filepath.Join(absolute, "path"),
|
||||
input: "to/the/abs-outside.txt",
|
||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
||||
name: "abs root, relative request, abs indirect (outside of root), cwd within symlink root",
|
||||
cwd: relativeViaLink,
|
||||
root: filepath.Join(absolute, "path"),
|
||||
input: "to/the/abs-outside.txt",
|
||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
expectedAccessPath: "to/the/abs-outside.txt",
|
||||
},
|
||||
{
|
||||
name: "relative root, abs request, abs indirect (outside of root), cwd within symlink root",
|
||||
cwd: relativeViaLink,
|
||||
root: "path",
|
||||
input: "/to/the/abs-outside.txt",
|
||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
||||
name: "relative root, abs request, abs indirect (outside of root), cwd within symlink root",
|
||||
cwd: relativeViaLink,
|
||||
root: "path",
|
||||
input: "/to/the/abs-outside.txt",
|
||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
expectedAccessPath: "to/the/abs-outside.txt",
|
||||
},
|
||||
{
|
||||
name: "abs root, abs request, abs indirect (outside of root), cwd within symlink root",
|
||||
cwd: relativeViaLink,
|
||||
root: filepath.Join(absolute, "path"),
|
||||
input: "/to/the/abs-outside.txt",
|
||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
expectedVirtualPath: "to/the/abs-outside.txt",
|
||||
name: "abs root, abs request, abs indirect (outside of root), cwd within symlink root",
|
||||
cwd: relativeViaLink,
|
||||
root: filepath.Join(absolute, "path"),
|
||||
input: "/to/the/abs-outside.txt",
|
||||
expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
expectedAccessPath: "to/the/abs-outside.txt",
|
||||
},
|
||||
{
|
||||
name: "relative root, relative request, relative indirect (outside of root), cwd within symlink root",
|
||||
@@ -422,8 +422,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
|
||||
input: "to/the/rel-outside.txt",
|
||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
// TODO: the real path is not correct
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedAccessPath: "to/the/rel-outside.txt",
|
||||
},
|
||||
{
|
||||
name: "abs root, relative request, relative indirect (outside of root), cwd within symlink root",
|
||||
@@ -432,8 +432,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
|
||||
input: "to/the/rel-outside.txt",
|
||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
// TODO: the real path is not correct
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedAccessPath: "to/the/rel-outside.txt",
|
||||
},
|
||||
{
|
||||
name: "relative root, abs request, relative indirect (outside of root), cwd within symlink root",
|
||||
@@ -442,8 +442,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
|
||||
input: "/to/the/rel-outside.txt",
|
||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
// TODO: the real path is not correct
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedAccessPath: "to/the/rel-outside.txt",
|
||||
},
|
||||
{
|
||||
name: "abs root, abs request, relative indirect (outside of root), cwd within symlink root",
|
||||
@@ -452,8 +452,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
|
||||
input: "/to/the/rel-outside.txt",
|
||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
// TODO: the real path is not correct
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedAccessPath: "to/the/rel-outside.txt",
|
||||
},
|
||||
{
|
||||
name: "relative root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
|
||||
@@ -462,8 +462,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
|
||||
input: "to/the/rel-outside.txt",
|
||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
// TODO: the real path is not correct
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedAccessPath: "to/the/rel-outside.txt",
|
||||
},
|
||||
{
|
||||
name: "abs root, relative request, relative indirect (outside of root), cwd within DOUBLE symlink root",
|
||||
@@ -472,8 +472,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
|
||||
input: "to/the/rel-outside.txt",
|
||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
// TODO: the real path is not correct
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedAccessPath: "to/the/rel-outside.txt",
|
||||
},
|
||||
{
|
||||
name: "relative root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
|
||||
@@ -482,8 +482,8 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
|
||||
input: "/to/the/rel-outside.txt",
|
||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
// TODO: the real path is not correct
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedAccessPath: "to/the/rel-outside.txt",
|
||||
},
|
||||
{
|
||||
name: "abs root, abs request, relative indirect (outside of root), cwd within DOUBLE symlink root",
|
||||
@@ -492,14 +492,14 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
|
||||
input: "/to/the/rel-outside.txt",
|
||||
//expectedRealPath: filepath.Join(absolute, "/somewhere/outside.txt"),
|
||||
// TODO: the real path is not correct
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedVirtualPath: "to/the/rel-outside.txt",
|
||||
expectedRealPath: "../somewhere/outside.txt",
|
||||
expectedAccessPath: "to/the/rel-outside.txt",
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
if c.expectedVirtualPath == "" {
|
||||
c.expectedVirtualPath = c.expectedRealPath
|
||||
if c.expectedAccessPath == "" {
|
||||
c.expectedAccessPath = c.expectedRealPath
|
||||
}
|
||||
|
||||
// we need to mimic a shell, otherwise we won't get a path within a symlink
|
||||
@@ -523,7 +523,7 @@ func Test_UnindexDirectoryResolver_FilesByPath_request_response(t *testing.T) {
|
||||
}
|
||||
require.Len(t, refs, 1)
|
||||
assert.Equal(t, c.expectedRealPath, refs[0].RealPath, "real path different")
|
||||
assert.Equal(t, c.expectedVirtualPath, refs[0].VirtualPath, "virtual path different")
|
||||
assert.Equal(t, c.expectedAccessPath, refs[0].AccessPath, "virtual path different")
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -847,14 +847,14 @@ func Test_UnindexedDirectoryResover_IndexingNestedSymLinks(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, locations, 1)
|
||||
assert.Equal(t, "readme", locations[0].RealPath)
|
||||
assert.Equal(t, "link_to_new_readme", locations[0].VirtualPath)
|
||||
assert.Equal(t, "link_to_new_readme", locations[0].AccessPath)
|
||||
|
||||
// check that we can access the same file via 2 symlinks
|
||||
locations, err = resolver.FilesByPath("./link_to_link_to_new_readme")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, locations, 1)
|
||||
assert.Equal(t, "readme", locations[0].RealPath)
|
||||
assert.Equal(t, "link_to_link_to_new_readme", locations[0].VirtualPath)
|
||||
assert.Equal(t, "link_to_link_to_new_readme", locations[0].AccessPath)
|
||||
|
||||
// check that we can access the same file via 2 symlinks
|
||||
locations, err = resolver.FilesByGlob("**/link_*")
|
||||
@@ -862,7 +862,7 @@ func Test_UnindexedDirectoryResover_IndexingNestedSymLinks(t *testing.T) {
|
||||
require.Len(t, locations, 1) // you would think this is 2, however, they point to the same file, and glob only returns unique files
|
||||
|
||||
// returned locations can be in any order
|
||||
expectedVirtualPaths := []string{
|
||||
expectedAccessPaths := []string{
|
||||
"link_to_link_to_new_readme",
|
||||
//"link_to_new_readme", // we filter out this one because the first symlink resolves to the same file
|
||||
}
|
||||
@@ -872,13 +872,13 @@ func Test_UnindexedDirectoryResover_IndexingNestedSymLinks(t *testing.T) {
|
||||
}
|
||||
|
||||
actualRealPaths := strset.New()
|
||||
actualVirtualPaths := strset.New()
|
||||
actualAccessPaths := strset.New()
|
||||
for _, a := range locations {
|
||||
actualVirtualPaths.Add(a.VirtualPath)
|
||||
actualAccessPaths.Add(a.AccessPath)
|
||||
actualRealPaths.Add(a.RealPath)
|
||||
}
|
||||
|
||||
assert.ElementsMatch(t, expectedVirtualPaths, actualVirtualPaths.List())
|
||||
assert.ElementsMatch(t, expectedAccessPaths, actualAccessPaths.List())
|
||||
assert.ElementsMatch(t, expectedRealPaths, actualRealPaths.List())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user