github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/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"},
    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{"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"},
    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  	for _, test := range tests {
    76  		t.Run(test.name, func(t *testing.T) {
    77  			actual := candidateVendorsForWordpressPlugin(test.pkg).uniqueValues()
    78  			assert.ElementsMatch(t, test.expected, actual, "different vendors")
    79  		})
    80  	}
    81  }
    82  
    83  func Test_candidateProductsWordpressPlugin(t *testing.T) {
    84  	tests := []struct {
    85  		name     string
    86  		pkg      pkg.Package
    87  		expected []string
    88  	}{
    89  		{
    90  			name: "All-in-One WP Migration",
    91  			pkg: pkg.Package{
    92  				Name: "All-in-One WP Migration",
    93  				Metadata: pkg.WordpressPluginEntry{
    94  					PluginInstallDirectory: "all-in-one-wp-migration",
    95  				},
    96  			},
    97  			expected: []string{"all-in-one_wp_migration", "all-in-one-wp-migration"},
    98  		},
    99  		{
   100  			name: "Akismet Anti-spam: Spam Protection",
   101  			pkg: pkg.Package{
   102  				Name: "Akismet Anti-spam: Spam Protection",
   103  				Metadata: pkg.WordpressPluginEntry{
   104  					PluginInstallDirectory: "akismet",
   105  				},
   106  			},
   107  			expected: []string{"akismet_anti-spam:_spam_protection", "akismet"},
   108  		},
   109  		{
   110  			name: "Access Code Feeder",
   111  			pkg: pkg.Package{
   112  				Name: "Access Code Feeder",
   113  				Metadata: pkg.WordpressPluginEntry{
   114  					PluginInstallDirectory: "access-code-feeder",
   115  				},
   116  			},
   117  			expected: []string{"access_code_feeder", "access-code-feeder"},
   118  		},
   119  		{
   120  			name: "CampTix Event Ticketing",
   121  			pkg: pkg.Package{
   122  				Name: "CampTix Event Ticketing",
   123  				Metadata: pkg.WordpressPluginEntry{
   124  					PluginInstallDirectory: "camptix",
   125  				},
   126  			},
   127  			expected: []string{"camptix_event_ticketing", "camptix"},
   128  		},
   129  	}
   130  	for _, test := range tests {
   131  		t.Run(test.name, func(t *testing.T) {
   132  			assert.ElementsMatch(t, test.expected, candidateProductsForWordpressPlugin(test.pkg).uniqueValues(), "different products")
   133  		})
   134  	}
   135  }