mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-12 15:50:15 -08:00
fix(wolfi): support new APK database location (#8937)
Signed-off-by: knqyf263 <knqyf263@gmail.com>
This commit is contained in:
@@ -666,7 +666,7 @@ func TestAnalyzerGroup_AnalyzerVersions(t *testing.T) {
|
||||
Analyzers: map[string]int{
|
||||
"alpine": 1,
|
||||
"apk-repo": 1,
|
||||
"apk": 2,
|
||||
"apk": 3,
|
||||
"bundler": 1,
|
||||
"dpkg-license": 1,
|
||||
"ubuntu": 1,
|
||||
@@ -692,7 +692,7 @@ func TestAnalyzerGroup_AnalyzerVersions(t *testing.T) {
|
||||
},
|
||||
want: analyzer.Versions{
|
||||
Analyzers: map[string]int{
|
||||
"apk": 2,
|
||||
"apk": 3,
|
||||
"bundler": 1,
|
||||
},
|
||||
PostAnalyzers: map[string]int{
|
||||
@@ -729,6 +729,7 @@ func TestAnalyzerGroup_StaticPaths(t *testing.T) {
|
||||
"etc/apk/repositories",
|
||||
"etc/lsb-release",
|
||||
"lib/apk/db/installed",
|
||||
"usr/lib/apk/db/installed",
|
||||
"etc/alpine-release",
|
||||
|
||||
"usr/share/doc/",
|
||||
|
||||
@@ -27,9 +27,9 @@ func init() {
|
||||
analyzer.RegisterAnalyzer(newAlpinePkgAnalyzer())
|
||||
}
|
||||
|
||||
const analyzerVersion = 2
|
||||
const analyzerVersion = 3
|
||||
|
||||
var requiredFiles = []string{"lib/apk/db/installed"}
|
||||
var requiredFiles = []string{"lib/apk/db/installed", "usr/lib/apk/db/installed"}
|
||||
|
||||
type alpinePkgAnalyzer struct{}
|
||||
|
||||
|
||||
@@ -449,3 +449,40 @@ func TestParseApkInfo(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequired(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
filePath string
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "legacy APK database location",
|
||||
filePath: "lib/apk/db/installed",
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "new APK database location",
|
||||
filePath: "usr/lib/apk/db/installed",
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "unrelated file",
|
||||
filePath: "etc/os-release",
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "similar but different path",
|
||||
filePath: "lib/apk/db/other",
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
|
||||
a := alpinePkgAnalyzer{}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := a.Required(tt.filePath, nil)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,14 @@ import (
|
||||
_ "github.com/aquasecurity/trivy/pkg/fanal/handler/sysfile"
|
||||
)
|
||||
|
||||
// Common blob IDs used across multiple test cases to reduce duplication
|
||||
const (
|
||||
alpineBaseLayerID = "sha256:be60f1fe61fc63ab50b10fe0779614e605a973a38cd7d2a02f3f20b081e56d4a"
|
||||
alpineBaseLayerDiffID = "sha256:beee9f30bc1f711043e78d4a2be0668955d4b761d587d6f60c2c8dc081efb203"
|
||||
alpineArtifactID = "sha256:3c709d2a158be3a97051e10cd0e30f047225cb9505101feb3fadcd395c2e0408"
|
||||
composerImageID = "sha256:a187dde48cd289ac374ad8539930628314bc581a481cdb41409c9289419ddb72"
|
||||
)
|
||||
|
||||
func TestArtifact_Inspect(t *testing.T) {
|
||||
alpinePkgs := types.Packages{
|
||||
{
|
||||
@@ -353,12 +361,12 @@ func TestArtifact_Inspect(t *testing.T) {
|
||||
},
|
||||
wantBlobs: []cachetest.WantBlob{
|
||||
{
|
||||
ID: "sha256:5d77c13a4b76f19d2a01bb971b3d6c67e550dffdfb82aed6a0086e87218f33cb",
|
||||
ID: alpineBaseLayerID,
|
||||
BlobInfo: types.BlobInfo{
|
||||
SchemaVersion: types.BlobJSONSchemaVersion,
|
||||
Size: 5861888,
|
||||
Digest: "",
|
||||
DiffID: "sha256:beee9f30bc1f711043e78d4a2be0668955d4b761d587d6f60c2c8dc081efb203",
|
||||
DiffID: alpineBaseLayerDiffID,
|
||||
CreatedBy: "ADD file:0c4555f363c2672e350001f1293e689875a3760afe7b3f9146886afe67121cba in / ",
|
||||
OS: types.OS{
|
||||
Family: "alpine",
|
||||
@@ -402,7 +410,7 @@ func TestArtifact_Inspect(t *testing.T) {
|
||||
},
|
||||
},
|
||||
wantArtifact: cachetest.WantArtifact{
|
||||
ID: "sha256:3c709d2a158be3a97051e10cd0e30f047225cb9505101feb3fadcd395c2e0408",
|
||||
ID: alpineArtifactID,
|
||||
ArtifactInfo: types.ArtifactInfo{
|
||||
SchemaVersion: types.ArtifactJSONSchemaVersion,
|
||||
Architecture: "amd64",
|
||||
@@ -414,12 +422,12 @@ func TestArtifact_Inspect(t *testing.T) {
|
||||
want: artifact.Reference{
|
||||
Name: "../../test/testdata/alpine-311.tar.gz",
|
||||
Type: types.TypeContainerImage,
|
||||
ID: "sha256:3c709d2a158be3a97051e10cd0e30f047225cb9505101feb3fadcd395c2e0408",
|
||||
BlobIDs: []string{"sha256:5d77c13a4b76f19d2a01bb971b3d6c67e550dffdfb82aed6a0086e87218f33cb"},
|
||||
ID: alpineArtifactID,
|
||||
BlobIDs: []string{alpineBaseLayerID},
|
||||
ImageMetadata: artifact.ImageMetadata{
|
||||
ID: "sha256:a187dde48cd289ac374ad8539930628314bc581a481cdb41409c9289419ddb72",
|
||||
ID: composerImageID,
|
||||
DiffIDs: []string{
|
||||
"sha256:beee9f30bc1f711043e78d4a2be0668955d4b761d587d6f60c2c8dc081efb203",
|
||||
alpineBaseLayerDiffID,
|
||||
},
|
||||
ConfigFile: v1.ConfigFile{
|
||||
Architecture: "amd64",
|
||||
@@ -485,7 +493,7 @@ func TestArtifact_Inspect(t *testing.T) {
|
||||
},
|
||||
wantBlobs: []cachetest.WantBlob{
|
||||
{
|
||||
ID: "sha256:67c88202c1f92978398a3ceff0c536282eb31972d92c1b913afb055f05dd05fd",
|
||||
ID: "sha256:f2a647dcf780c603f864e491dca1a042b1e98062b530c813681d1bb4a85bcb18",
|
||||
BlobInfo: types.BlobInfo{
|
||||
SchemaVersion: types.BlobJSONSchemaVersion,
|
||||
Size: 3061760,
|
||||
@@ -573,7 +581,7 @@ func TestArtifact_Inspect(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "sha256:b81648381fb192c7034e72d517dd46aedf392f628b2a242c0ed0b06b8e9c2bec",
|
||||
ID: "sha256:c988cc5a0b8f3dc542c15c303d9200dee47d4fbed0e498a5bfbf3b4bef7a5af7",
|
||||
BlobInfo: types.BlobInfo{
|
||||
SchemaVersion: types.BlobJSONSchemaVersion,
|
||||
Size: 15441920,
|
||||
@@ -668,7 +676,7 @@ func TestArtifact_Inspect(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "sha256:2d916a1f47dadcbf5c842a0dd26fe4fb2f94743d829e23dc614c0883e5473aaf",
|
||||
ID: "sha256:05c19ffd5d898588400522070abd98c770b2965a7f4867d5c882c2a8783e40cc",
|
||||
BlobInfo: types.BlobInfo{
|
||||
SchemaVersion: types.BlobJSONSchemaVersion,
|
||||
Size: 29696,
|
||||
@@ -875,7 +883,7 @@ func TestArtifact_Inspect(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "sha256:ed1912a62cc8057cbb5ed9e1cfa47d34270e2417dd51514185e24852d8001686",
|
||||
ID: "sha256:c737743c0f8b35906650a02125f05c8b35916c0febf64984f4dfaacd0f72509d",
|
||||
BlobInfo: types.BlobInfo{
|
||||
SchemaVersion: types.BlobJSONSchemaVersion,
|
||||
Size: 6656,
|
||||
@@ -1738,10 +1746,10 @@ func TestArtifact_Inspect(t *testing.T) {
|
||||
Type: types.TypeContainerImage,
|
||||
ID: "sha256:0bebf0773ffd87baa7c64fbdbdf79a24ae125e3f99a8adebe52d1ccbe6bed16b",
|
||||
BlobIDs: []string{
|
||||
"sha256:67c88202c1f92978398a3ceff0c536282eb31972d92c1b913afb055f05dd05fd",
|
||||
"sha256:b81648381fb192c7034e72d517dd46aedf392f628b2a242c0ed0b06b8e9c2bec",
|
||||
"sha256:2d916a1f47dadcbf5c842a0dd26fe4fb2f94743d829e23dc614c0883e5473aaf",
|
||||
"sha256:ed1912a62cc8057cbb5ed9e1cfa47d34270e2417dd51514185e24852d8001686",
|
||||
"sha256:f2a647dcf780c603f864e491dca1a042b1e98062b530c813681d1bb4a85bcb18",
|
||||
"sha256:c988cc5a0b8f3dc542c15c303d9200dee47d4fbed0e498a5bfbf3b4bef7a5af7",
|
||||
"sha256:05c19ffd5d898588400522070abd98c770b2965a7f4867d5c882c2a8783e40cc",
|
||||
"sha256:c737743c0f8b35906650a02125f05c8b35916c0febf64984f4dfaacd0f72509d",
|
||||
},
|
||||
ImageMetadata: artifact.ImageMetadata{
|
||||
ID: "sha256:58701fd185bda36cab0557bb6438661831267aa4a9e0b54211c4d5317a48aff4",
|
||||
@@ -1846,7 +1854,7 @@ func TestArtifact_Inspect(t *testing.T) {
|
||||
},
|
||||
wantBlobs: []cachetest.WantBlob{
|
||||
{
|
||||
ID: "sha256:f804054cbf18c82fbb7a136450a161264bb3e531d29aedb4c13eada052b379e6",
|
||||
ID: "sha256:48b4a983ef1ec8f0d19934ccf7fca3d2114466ad32207e16371620628f149984",
|
||||
BlobInfo: types.BlobInfo{
|
||||
SchemaVersion: types.BlobJSONSchemaVersion,
|
||||
Size: 3061760,
|
||||
@@ -1856,7 +1864,7 @@ func TestArtifact_Inspect(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "sha256:5d76e1081a0f708a98132175ac81b897c8efa5d39ab75e5df87f42ac619962d8",
|
||||
ID: "sha256:a4d2820bd2c076f6153a9053843d4a56d31147ce486ec5e4a2c0405cec506d6c",
|
||||
BlobInfo: types.BlobInfo{
|
||||
SchemaVersion: types.BlobJSONSchemaVersion,
|
||||
Size: 15441920,
|
||||
@@ -1866,7 +1874,7 @@ func TestArtifact_Inspect(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "sha256:6937ca98d84de22331089747a24e9e8b032c61133958a42990d5a5af718fdcd8",
|
||||
ID: "sha256:c5fa5e736cee843c563c222963eb89fc775f0620020ff9d51d5e5db8ef62eec4",
|
||||
BlobInfo: types.BlobInfo{
|
||||
SchemaVersion: types.BlobJSONSchemaVersion,
|
||||
Size: 29696,
|
||||
@@ -1877,7 +1885,7 @@ func TestArtifact_Inspect(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "sha256:b6d38e35ff57fda90aa2e57f02fd96e9919d29dbb22d45d95fe3534d79af08fc",
|
||||
ID: "sha256:7e223b95d6d589cdb196e29ef6c6ac0acdd2c471350dd9880a420b4249f6e7bb",
|
||||
BlobInfo: types.BlobInfo{
|
||||
SchemaVersion: types.BlobJSONSchemaVersion,
|
||||
Size: 6656,
|
||||
@@ -1893,10 +1901,10 @@ func TestArtifact_Inspect(t *testing.T) {
|
||||
Type: types.TypeContainerImage,
|
||||
ID: "sha256:0bebf0773ffd87baa7c64fbdbdf79a24ae125e3f99a8adebe52d1ccbe6bed16b",
|
||||
BlobIDs: []string{
|
||||
"sha256:f804054cbf18c82fbb7a136450a161264bb3e531d29aedb4c13eada052b379e6",
|
||||
"sha256:5d76e1081a0f708a98132175ac81b897c8efa5d39ab75e5df87f42ac619962d8",
|
||||
"sha256:6937ca98d84de22331089747a24e9e8b032c61133958a42990d5a5af718fdcd8",
|
||||
"sha256:b6d38e35ff57fda90aa2e57f02fd96e9919d29dbb22d45d95fe3534d79af08fc",
|
||||
"sha256:48b4a983ef1ec8f0d19934ccf7fca3d2114466ad32207e16371620628f149984",
|
||||
"sha256:a4d2820bd2c076f6153a9053843d4a56d31147ce486ec5e4a2c0405cec506d6c",
|
||||
"sha256:c5fa5e736cee843c563c222963eb89fc775f0620020ff9d51d5e5db8ef62eec4",
|
||||
"sha256:7e223b95d6d589cdb196e29ef6c6ac0acdd2c471350dd9880a420b4249f6e7bb",
|
||||
},
|
||||
ImageMetadata: artifact.ImageMetadata{
|
||||
ID: "sha256:58701fd185bda36cab0557bb6438661831267aa4a9e0b54211c4d5317a48aff4",
|
||||
|
||||
@@ -2498,6 +2498,7 @@ func TestArtifact_AnalysisStrategy(t *testing.T) {
|
||||
wantRoots: []string{
|
||||
"testdata/alpine/etc/alpine-release",
|
||||
"testdata/alpine/lib/apk/db/installed",
|
||||
"testdata/alpine/usr/lib/apk/db/installed",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -118,16 +118,16 @@ func TestArtifact_Inspect(t *testing.T) {
|
||||
rootDir: "testdata/alpine",
|
||||
wantBlobs: []cachetest.WantBlob{
|
||||
{
|
||||
ID: "sha256:84a726d23c36d0e1857101969b257c1199de5432489d44581750d54ea8eff8cd",
|
||||
ID: "sha256:fecb09f4a7f0382a4feb2fb086ed5e37eaab644fef7b8f87c550a6e94a7f780f",
|
||||
BlobInfo: expectedBlobInfo,
|
||||
},
|
||||
},
|
||||
want: artifact.Reference{
|
||||
Name: "rawdata.img",
|
||||
Type: types.TypeVM,
|
||||
ID: "sha256:84a726d23c36d0e1857101969b257c1199de5432489d44581750d54ea8eff8cd",
|
||||
ID: "sha256:fecb09f4a7f0382a4feb2fb086ed5e37eaab644fef7b8f87c550a6e94a7f780f",
|
||||
BlobIDs: []string{
|
||||
"sha256:84a726d23c36d0e1857101969b257c1199de5432489d44581750d54ea8eff8cd",
|
||||
"sha256:fecb09f4a7f0382a4feb2fb086ed5e37eaab644fef7b8f87c550a6e94a7f780f",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -137,16 +137,16 @@ func TestArtifact_Inspect(t *testing.T) {
|
||||
rootDir: "testdata/alpine",
|
||||
wantBlobs: []cachetest.WantBlob{
|
||||
{
|
||||
ID: "sha256:c28da2df41e019b5d18459440178341ec05e9082b12b6f11afe73f0600bfe96a",
|
||||
ID: "sha256:d1690d3201420ddb690be85be011afd36be4c8bff47c474d7fcfe9c7efea9a3f",
|
||||
BlobInfo: expectedBlobInfo,
|
||||
},
|
||||
},
|
||||
want: artifact.Reference{
|
||||
Name: "ebs-012345",
|
||||
Type: types.TypeVM,
|
||||
ID: "sha256:c28da2df41e019b5d18459440178341ec05e9082b12b6f11afe73f0600bfe96a",
|
||||
ID: "sha256:d1690d3201420ddb690be85be011afd36be4c8bff47c474d7fcfe9c7efea9a3f",
|
||||
BlobIDs: []string{
|
||||
"sha256:c28da2df41e019b5d18459440178341ec05e9082b12b6f11afe73f0600bfe96a",
|
||||
"sha256:d1690d3201420ddb690be85be011afd36be4c8bff47c474d7fcfe9c7efea9a3f",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user