Skip to content

Commit

Permalink
Fixed golangci-lint notices
Browse files Browse the repository at this point in the history
Added integration test for `wordpress-plugin`

Signed-off-by: disc <[email protected]>
  • Loading branch information
disc committed Oct 12, 2023
1 parent acc7dca commit fedcd49
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion syft/pkg/cataloger/cataloger.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ catalogers defined in child packages as well as the interface definition to impl
package cataloger

import (
"github.com/anchore/syft/syft/pkg/cataloger/wordpress"
"strings"

"github.com/anchore/syft/internal/log"
Expand Down Expand Up @@ -36,6 +35,7 @@ import (
"github.com/anchore/syft/syft/pkg/cataloger/rust"
"github.com/anchore/syft/syft/pkg/cataloger/sbom"
"github.com/anchore/syft/syft/pkg/cataloger/swift"
"github.com/anchore/syft/syft/pkg/cataloger/wordpress"
)

const AllCatalogersPattern = "all"
Expand Down
1 change: 1 addition & 0 deletions syft/pkg/cataloger/common/cpe/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func Generate(p pkg.Package) []cpe.CPE {
return cpes
}

//nolint:funlen
func candidateVendors(p pkg.Package) []string {
// in ecosystems where the packaging metadata does not have a clear field to indicate a vendor (or a field that
// could be interpreted indirectly as such) the project name tends to be a common stand in. Examples of this
Expand Down
5 changes: 3 additions & 2 deletions syft/pkg/cataloger/common/cpe/wordpress_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cpe

import (
"fmt"
"github.com/anchore/syft/internal"
"github.com/anchore/syft/syft/pkg"
"regexp"
"strings"

"github.com/anchore/syft/internal"
"github.com/anchore/syft/syft/pkg"
)

var (
Expand Down
7 changes: 4 additions & 3 deletions syft/pkg/cataloger/wordpress/parse_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package wordpress

import (
"fmt"
"io"
"path/filepath"
"regexp"

"github.com/anchore/syft/internal"
"github.com/anchore/syft/syft/artifact"
"github.com/anchore/syft/syft/file"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/pkg/cataloger/generic"
"io"
"path/filepath"
"regexp"
)

var patterns = map[string]*regexp.Regexp{
Expand Down
1 change: 1 addition & 0 deletions syft/pkg/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func TypeFromPURL(p string) Type {
return TypeByName(ptype)
}

//nolint:funlen
func TypeByName(name string) Type {
switch name {
case packageurl.TypeDebian:
Expand Down
8 changes: 8 additions & 0 deletions test/integration/catalog_packages_cases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,12 @@ var commonTestCases = []testCase{
"glibc": "2.34-210",
},
},
{
name: "find wordpress plugins",
pkgType: pkg.WordpressPluginPkg,
pkgLanguage: pkg.PHP,
pkgInfo: map[string]string{
"Akismet Anti-spam: Spam Protection": "5.3",
},
},
}
7 changes: 0 additions & 7 deletions test/integration/catalog_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ func TestPkgCoverageImage(t *testing.T) {
definedPkgs.Remove(string(pkg.SwiftPkg))
definedPkgs.Remove(string(pkg.GithubActionPkg))
definedPkgs.Remove(string(pkg.GithubActionWorkflowPkg))
definedPkgs.Remove(string(pkg.WordpressPluginPkg))

var cases []testCase
cases = append(cases, commonTestCases...)
Expand Down Expand Up @@ -140,7 +139,6 @@ func TestPkgCoverageImage(t *testing.T) {
}
t.Fatalf("unexpected package count: %d!=%d", pkgCount, len(c.pkgInfo))
}

})
}

Expand Down Expand Up @@ -220,7 +218,6 @@ func TestPkgCoverageDirectory(t *testing.T) {
}
t.Fatalf("unexpected package count: %d!=%d", actualPkgCount, len(test.pkgInfo))
}

})
}

Expand Down Expand Up @@ -279,7 +276,6 @@ func TestPkgCoverageImage_HasEvidence(t *testing.T) {

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {

for a := range sbom.Artifacts.Packages.Enumerate(c.pkgType) {
assert.NotEmpty(t, a.Locations.ToSlice(), "package %q has no locations (type=%q)", a.Name, a.Type)
for _, l := range a.Locations.ToSlice() {
Expand All @@ -289,7 +285,6 @@ func TestPkgCoverageImage_HasEvidence(t *testing.T) {
}
}
}

})
}

Expand All @@ -309,7 +304,6 @@ func TestPkgCoverageDirectory_HasEvidence(t *testing.T) {

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {

for a := range sbom.Artifacts.Packages.Enumerate(c.pkgType) {
assert.NotEmpty(t, a.Locations.ToSlice(), "package %q has no locations (type=%q)", a.Name, a.Type)
for _, l := range a.Locations.ToSlice() {
Expand All @@ -319,7 +313,6 @@ func TestPkgCoverageDirectory_HasEvidence(t *testing.T) {
}
}
}

})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* @package Akismet
*/
/*
Plugin Name:Akismet Anti-spam: Spam Protection
Plugin URI: https://akismet.com/
Description: Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from spam</strong>. Akismet Anti-spam keeps your site protected even while you sleep. To get started: activate the Akismet plugin and then go to your Akismet Settings page to set up your API key.
Version: 5.3
Requires at least: 5.8
Requires PHP: 5.6.20
Author: Automattic - Anti-spam Team
Author URI: https://automattic.com/wordpress-plugins/
License: GPLv2 or later
Text Domain: akismet
*/
// rest of plugin's code ...

0 comments on commit fedcd49

Please sign in to comment.