github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/internal/cpegenerate/wordpress_test.go (about) 1 package cpegenerate 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/anchore/syft/syft/pkg" 9 ) 10 11 func Test_candidateVendorsForWordpressPlugin(t *testing.T) { 12 tests := []struct { 13 name string 14 pkg pkg.Package 15 expected []string 16 }{ 17 { 18 name: "Akismet Anti-spam: Spam Protection", 19 pkg: pkg.Package{ 20 Name: "Akismet Anti-spam: Spam Protection", 21 Metadata: pkg.WordpressPluginEntry{ 22 PluginInstallDirectory: "akismet", 23 Author: "Automattic - Anti-spam Team", 24 AuthorURI: "https://automattic.com/wordpress-plugins/", 25 }, 26 }, 27 expected: []string{"automattic - anti-spam team", "automattic"}, 28 }, 29 { 30 name: "All-in-One WP Migration", 31 pkg: pkg.Package{ 32 Name: "All-in-One WP Migration", 33 Metadata: pkg.WordpressPluginEntry{ 34 PluginInstallDirectory: "all-in-one-wp-migration", 35 AuthorURI: "https://servmask.com", 36 }, 37 }, 38 expected: []string{"servmask"}, 39 }, 40 { 41 name: "Booking Ultra Pro Appointments Booking Calendar", 42 pkg: pkg.Package{ 43 Name: "Booking Ultra Pro Appointments Booking Calendar", 44 Metadata: pkg.WordpressPluginEntry{ 45 PluginInstallDirectory: "booking-ultra-pro", 46 Author: "Booking Ultra Pro", 47 AuthorURI: "https://bookingultrapro.com/", 48 }, 49 }, 50 expected: []string{"booking ultra pro", "bookingultrapro"}, 51 }, 52 { 53 name: "Coming Soon Chop Chop", 54 pkg: pkg.Package{ 55 Metadata: pkg.WordpressPluginEntry{ 56 PluginInstallDirectory: "cc-coming-soon", 57 Author: "Chop-Chop.org", 58 AuthorURI: "https://www.chop-chop.org", 59 }, 60 }, 61 expected: []string{"chop-chop.org", "chop-chop"}, 62 }, 63 { 64 name: "Access Code Feeder", 65 pkg: pkg.Package{ 66 Name: "Access Code Feeder", 67 Metadata: pkg.WordpressPluginEntry{ 68 PluginInstallDirectory: "access-code-feeder", 69 }, 70 }, 71 // When a plugin as no `Author URI` use plugin_name + _project as a vendor 72 expected: []string{"access_code_feeder_project"}, 73 }, 74 { 75 name: "WP Coder", 76 pkg: pkg.Package{ 77 Name: "WP Coder", 78 Metadata: pkg.WordpressPluginEntry{ 79 PluginInstallDirectory: "wp-coder", 80 Author: "Wow-Company", 81 AuthorURI: "https://wow-estore.com/", 82 }, 83 }, 84 // found in the wild https://plugins.trac.wordpress.org/browser/wp-coder/tags/2.5.1/wp-coder.php 85 expected: []string{ 86 "wow-company", // this is the correct answer relative to CPEs registered on CVE-2021-25053 87 "wow-estore", 88 }, 89 }, 90 } 91 for _, test := range tests { 92 t.Run(test.name, func(t *testing.T) { 93 actual := candidateVendorsForWordpressPlugin(test.pkg).uniqueValues() 94 assert.ElementsMatch(t, test.expected, actual, "different vendors") 95 }) 96 } 97 } 98 99 func Test_candidateProductsWordpressPlugin(t *testing.T) { 100 tests := []struct { 101 name string 102 pkg pkg.Package 103 expected []string 104 }{ 105 { 106 name: "All-in-One WP Migration", 107 pkg: pkg.Package{ 108 Name: "All-in-One WP Migration", 109 Metadata: pkg.WordpressPluginEntry{ 110 PluginInstallDirectory: "all-in-one-wp-migration", 111 }, 112 }, 113 expected: []string{"all-in-one_wp_migration", "all-in-one-wp-migration"}, 114 }, 115 { 116 name: "Akismet Anti-spam: Spam Protection", 117 pkg: pkg.Package{ 118 Name: "Akismet Anti-spam: Spam Protection", 119 Metadata: pkg.WordpressPluginEntry{ 120 PluginInstallDirectory: "akismet", 121 }, 122 }, 123 expected: []string{"akismet_anti-spam:_spam_protection", "akismet"}, 124 }, 125 { 126 name: "Access Code Feeder", 127 pkg: pkg.Package{ 128 Name: "Access Code Feeder", 129 Metadata: pkg.WordpressPluginEntry{ 130 PluginInstallDirectory: "access-code-feeder", 131 }, 132 }, 133 expected: []string{"access_code_feeder", "access-code-feeder"}, 134 }, 135 { 136 name: "CampTix Event Ticketing", 137 pkg: pkg.Package{ 138 Name: "CampTix Event Ticketing", 139 Metadata: pkg.WordpressPluginEntry{ 140 PluginInstallDirectory: "camptix", 141 }, 142 }, 143 expected: []string{"camptix_event_ticketing", "camptix"}, 144 }, 145 } 146 for _, test := range tests { 147 t.Run(test.name, func(t *testing.T) { 148 assert.ElementsMatch(t, test.expected, candidateProductsForWordpressPlugin(test.pkg).uniqueValues(), "different products") 149 }) 150 } 151 }