github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/redhat/dependency_test.go (about) 1 package redhat 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/anchore/syft/syft/pkg" 9 "github.com/anchore/syft/syft/pkg/cataloger/internal/dependency" 10 ) 11 12 func Test_dbEntryDependencySpecifier(t *testing.T) { 13 tests := []struct { 14 name string 15 p pkg.Package 16 want dependency.Specification 17 }{ 18 { 19 name: "keeps given values + package name", 20 p: pkg.Package{ 21 Name: "package-c", 22 Metadata: pkg.RpmDBEntry{ 23 Provides: []string{"a-thing"}, 24 Requires: []string{"b-thing"}, 25 }, 26 }, 27 want: dependency.Specification{ 28 ProvidesRequires: dependency.ProvidesRequires{ 29 Provides: []string{"package-c", "a-thing"}, 30 Requires: []string{"b-thing"}, 31 }, 32 }, 33 }, 34 { 35 name: "strip unsupported keys", 36 p: pkg.Package{ 37 Name: "package-a", 38 Metadata: pkg.RpmDBEntry{ 39 Provides: []string{"libc.so.6(GLIBC_2.11)(64bit)"}, 40 Requires: []string{"config(bash)", "(llvm if clang)"}, 41 }, 42 }, 43 want: dependency.Specification{ 44 ProvidesRequires: dependency.ProvidesRequires{ 45 Provides: []string{"package-a", "libc.so.6(GLIBC_2.11)(64bit)"}, 46 Requires: []string{"config(bash)"}, 47 }, 48 }, 49 }, 50 { 51 name: "empty dependency data entries", 52 p: pkg.Package{ 53 Name: "package-a", 54 Metadata: pkg.RpmDBEntry{ 55 Provides: []string{""}, 56 Requires: []string{""}, 57 }, 58 }, 59 want: dependency.Specification{ 60 ProvidesRequires: dependency.ProvidesRequires{ 61 Provides: []string{"package-a"}, 62 Requires: nil, 63 }, 64 }, 65 }, 66 } 67 for _, tt := range tests { 68 t.Run(tt.name, func(t *testing.T) { 69 assert.Equal(t, tt.want, dbEntryDependencySpecifier(tt.p)) 70 }) 71 } 72 } 73 74 func Test_isSupportedKey(t *testing.T) { 75 76 tests := []struct { 77 name string 78 key string 79 want bool 80 }{ 81 { 82 name: "paths allowed", 83 key: "/usr/bin/sh", 84 want: true, 85 }, 86 { 87 name: "spaces stripped", 88 key: " filesystem ", 89 want: true, 90 }, 91 { 92 name: "empty key", 93 key: "", 94 want: true, 95 }, 96 { 97 name: "boolean expression", 98 key: "(pyproject-rpm-macros = 1.9.0-1.el9 if pyproject-rpm-macros)", 99 want: false, 100 }, 101 { 102 name: "boolean expression with spaces stripped", 103 key: " (llvm if clang)", 104 want: false, 105 }, 106 } 107 for _, tt := range tests { 108 t.Run(tt.name, func(t *testing.T) { 109 assert.Equal(t, tt.want, isSupportedKey(tt.key)) 110 }) 111 } 112 }