mirror of
https://github.com/anchore/syft.git
synced 2026-10-30 22:12:28 +01:00
`ProcessPathErrors` cut the `path="..."` it pulled out of an error at the first `!/` and built nested coordinates from it, so a host file with `!/` in its name was reported as a file inside an archive. - paths from error text are taken as plain real paths again, as on main - the php extension reader already has the location in hand, so it records the unknown against that instead of re-parsing the error (this is the one caller that could see a nested path). It also no longer defers `Close` on a nil reader when the read fails Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package unknown
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/anchore/syft/syft/file"
|
|
)
|
|
|
|
func Test_ProcessPathErrors(t *testing.T) {
|
|
tests := []struct {
|
|
errorText string
|
|
expected error
|
|
}{
|
|
{
|
|
errorText: `prefix path="/var/lib/thing" suffix`,
|
|
expected: &CoordinateError{
|
|
Coordinates: file.NewCoordinates("/var/lib/thing", ""),
|
|
Reason: fmt.Errorf(`prefix path="/var/lib/thing" suffix`),
|
|
},
|
|
},
|
|
{
|
|
errorText: `prefix path="/var/lib/thing"`,
|
|
expected: &CoordinateError{
|
|
Coordinates: file.NewCoordinates("/var/lib/thing", ""),
|
|
Reason: fmt.Errorf(`prefix path="/var/lib/thing"`),
|
|
},
|
|
},
|
|
{
|
|
errorText: `path="/var/lib/thing" suffix`,
|
|
expected: &CoordinateError{
|
|
Coordinates: file.NewCoordinates("/var/lib/thing", ""),
|
|
Reason: fmt.Errorf(`path="/var/lib/thing" suffix`),
|
|
},
|
|
},
|
|
{
|
|
errorText: `path="/data/Hello!/world.txt"`,
|
|
expected: &CoordinateError{
|
|
Coordinates: file.NewCoordinates("/data/Hello!/world.txt", ""),
|
|
Reason: fmt.Errorf(`path="/data/Hello!/world.txt"`),
|
|
},
|
|
},
|
|
{
|
|
errorText: "all your base are belong to us",
|
|
expected: nil,
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.errorText, func(t *testing.T) {
|
|
got := ProcessPathErrors(fmt.Errorf("%s", test.errorText))
|
|
require.Equal(t, test.expected, got)
|
|
})
|
|
}
|
|
}
|