-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Anubhav Gupta <mail.anubhav06@gmail.com> Co-authored-by: Serta莽 脰zercan <852750+sozercan@users.noreply.github.com>
- Loading branch information
Showing
5 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package e2e | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
"testing" | ||
) | ||
|
||
var ( | ||
buildkitAddr string | ||
copaPath string | ||
scannerPlugin string | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
flag.StringVar(&buildkitAddr, "addr", "", "buildkit address to pass through to copa binary") | ||
flag.StringVar(&copaPath, "copa", "./copa", "path to copa binary") | ||
flag.StringVar(&scannerPlugin, "scanner", "trivy", "Scanner used to generate the report") | ||
flag.Parse() | ||
|
||
if copaPath == "" { | ||
panic("missing --copa") | ||
} | ||
|
||
ec := m.Run() | ||
os.Exit(ec) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPlugins(t *testing.T) { | ||
testCases := []struct { | ||
image string | ||
report string | ||
err error | ||
}{ | ||
{ | ||
image: "docker.io/library/alpine:3.14.0", | ||
report: "./testdata/invalid_report.json", | ||
err: fmt.Errorf("exit status 1"), | ||
}, | ||
{ | ||
image: "docker.io/library/alpine:3.7.3", | ||
report: "./testdata/valid_report.json", | ||
err: nil, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc // capture range variable | ||
t.Run(tc.image, func(t *testing.T) { | ||
t.Parallel() | ||
_, err := runPatch(tc.image, tc.report) | ||
if err != nil { | ||
assert.Equal(t, tc.err, fmt.Errorf(err.Error())) | ||
} else { | ||
assert.Equal(t, tc.err, nil) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func runPatch(image, report string) ([]byte, error) { | ||
//#nosec G204 | ||
cmd := exec.Command( | ||
copaPath, | ||
"patch", | ||
"-i="+image, | ||
"-r="+report, | ||
"-s="+scannerPlugin, | ||
"-a="+buildkitAddr, | ||
) | ||
out, err := cmd.CombinedOutput() | ||
return out, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
invalid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"OSType": "alpine", | ||
"OSVersion": "3.7.3", | ||
"Arch": "amd64", | ||
"Packages": [ | ||
{ | ||
"Name": "musl", | ||
"InstalledVersion": "1.1.18-r3", | ||
"FixedVersion": "1.1.18-r4", | ||
"VulnerabilityID": "CVE-2019-14697" | ||
} | ||
] | ||
} |