Skip to content

Commit

Permalink
feat: v1.9.0 regression tests (#696)
Browse files Browse the repository at this point in the history
Add regression tests for BYOB releae.

---------

Signed-off-by: laurentsimon <laurentsimon@google.com>
  • Loading branch information
laurentsimon committed Aug 24, 2023
1 parent 58eede7 commit 80c7d86
Show file tree
Hide file tree
Showing 72 changed files with 418 additions and 9 deletions.
76 changes: 67 additions & 9 deletions cli/slsa-verifier/main_regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func pString(s string) *string {
const TEST_DIR = "./testdata"

var (
GHA_ARTIFACT_PATH_BUILDERS = []string{"gha_go", "gha_generic"}
GHA_ARTIFACT_PATH_BUILDERS = []string{"gha_go", "gha_generic", "gha_delegator", "gha_maven", "gha_gradle"}
// TODO(https://github.com/slsa-framework/slsa-verifier/issues/485): Merge this with
// GHA_ARTIFACT_PATH_BUILDERS.
GHA_ARTIFACT_CONTAINER_BUILDERS = []string{"gha_container-based"}
Expand Down Expand Up @@ -80,6 +80,9 @@ func Test_runVerifyGHAArtifactPath(t *testing.T) {
t.Parallel()
goBuilder := "https://github.com/slsa-framework/slsa-github-generator/.github/workflows/builder_go_slsa3.yml"
genericBuilder := "https://github.com/slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml"
delegatorBuilder := "https://github.com/slsa-framework/example-trw/.github/workflows/builder_high-perms_slsa3.yml"
mavenBuilder := "https://github.com/slsa-framework/slsa-github-generator/.github/workflows/builder_maven_slsa3.yml"
gradleBuilder := "https://github.com/slsa-framework/slsa-github-generator/.github/workflows/builder_gradle_slsa3.yml"

tests := []struct {
name string
Expand Down Expand Up @@ -532,9 +535,15 @@ func Test_runVerifyGHAArtifactPath(t *testing.T) {

for _, v := range checkVersions {
var provenancePath string
var byob bool
if tt.provenancePath == "" {
testPath := filepath.Clean(filepath.Join(TEST_DIR, v, tt.artifacts[0]))
provenancePath = fmt.Sprintf("%s.intoto.jsonl", testPath)
if strings.Contains(testPath, "delegator") || strings.Contains(testPath, "maven") || strings.Contains(testPath, "gradle") {
provenancePath = fmt.Sprintf("%s.build.slsa", testPath)
byob = true
} else {
provenancePath = fmt.Sprintf("%s.intoto.jsonl", testPath)
}
} else {
provenancePath = filepath.Clean(filepath.Join(TEST_DIR, v, tt.provenancePath))
}
Expand Down Expand Up @@ -564,14 +573,25 @@ func Test_runVerifyGHAArtifactPath(t *testing.T) {
builder = goBuilder
case strings.HasSuffix(name, "_generic"):
builder = genericBuilder
case strings.HasSuffix(name, "_delegator"):
builder = delegatorBuilder
case strings.HasSuffix(name, "_maven"):
builder = mavenBuilder
case strings.HasSuffix(name, "_gradle"):
builder = gradleBuilder
default:
builder = genericBuilder
}

// Default builders to test.
builderIDs := []*string{
pString(builder),
nil,
}

// Do not run without explicit builder ID for the delegator,
// because it's hosted on a different repo slsa-framework/example-package.
if builder != delegatorBuilder {
builderIDs = append(builderIDs, nil)
}

// We only add the tags to tests for versions >= 1,
Expand Down Expand Up @@ -600,6 +620,10 @@ func Test_runVerifyGHAArtifactPath(t *testing.T) {
BuildWorkflowInputs: tt.inputs,
}

// BYOB-based builders ignore the reusable workflow.
if errCmp(tt.err, serrors.ErrorUntrustedReusableWorkflow) && byob {
tt.err = serrors.ErrorMismatchBuilderID
}
// The outBuilderID is the actual builder ID from the provenance.
// This is always long form for the GHA builders.
outBuilderID, err := cmd.Exec(context.Background(), artifacts)
Expand Down Expand Up @@ -699,6 +723,10 @@ func Test_runVerifyGHAArtifactImage(t *testing.T) {
// or testdata from malicious untrusted builders.
// When true, this does not iterate over all builder versions.
noversion bool
// minversion is a special case to test a newly added feature into a builder.
minversion string
// maxversion is a special case to handle incompatible error changes in the builder.
maxversion string
}{
{
name: "valid main branch default",
Expand All @@ -718,7 +746,6 @@ func Test_runVerifyGHAArtifactImage(t *testing.T) {
source: "github.com/slsa-framework/example-package",
pbranch: pString("main"),
},

{
name: "wrong branch master",
artifact: "container_workflow_dispatch",
Expand All @@ -745,19 +772,37 @@ func Test_runVerifyGHAArtifactImage(t *testing.T) {
err: serrors.ErrorMismatchSource,
},
{
name: "tag no match empty tag workflow_dispatch",
artifact: "container_workflow_dispatch",
source: "github.com/slsa-framework/example-package",
ptag: pString("v1.2.3"),
err: serrors.ErrorInvalidRef,
name: "tag no match empty tag workflow_dispatch",
artifact: "container_workflow_dispatch",
source: "github.com/slsa-framework/example-package",
ptag: pString("v1.2.3"),
maxversion: "v1.8.0",
err: serrors.ErrorInvalidRef,
},
{
name: "versioned tag no match empty tag workflow_dispatch",
artifact: "container_workflow_dispatch",
source: "github.com/slsa-framework/example-package",
pversiontag: pString("v1"),
maxversion: "v1.8.0",
err: serrors.ErrorInvalidRef,
},
{
name: "tag no match empty tag workflow_dispatch > v1.9.0",
artifact: "container_workflow_dispatch",
source: "github.com/slsa-framework/example-package",
ptag: pString("v1.2.3"),
minversion: "v1.9.0",
err: serrors.ErrorMismatchTag,
},
{
name: "versioned tag no match empty tag workflow_dispatch > v1.9.0",
artifact: "container_workflow_dispatch",
source: "github.com/slsa-framework/example-package",
pversiontag: pString("v1"),
minversion: "v1.9.0",
err: serrors.ErrorMismatchTag,
},
}
for _, tt := range tests {
tt := tt // Re-initializing variable so it is not changed while executing the closure below
Expand All @@ -770,6 +815,19 @@ func Test_runVerifyGHAArtifactImage(t *testing.T) {
}

for _, v := range checkVersions {
parts := strings.Split(v, "/")
version := ""
if len(parts) > 1 {
version = parts[1]
}
if version != "" && tt.minversion != "" && semver.Compare(version, tt.minversion) <= 0 {
fmt.Println("skiping due to min:", version)
continue
}
if version != "" && tt.maxversion != "" && semver.Compare(version, tt.maxversion) > 0 {
fmt.Println("skiping due to max:", version)
continue
}
image := filepath.Clean(filepath.Join(TEST_DIR, v, tt.artifact))
// TODO(#258): test for tagged builder.
sv := filepath.Base(v)
Expand Down
Empty file.

Large diffs are not rendered by default.

Empty file.
Empty file.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Empty file.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello

Large diffs are not rendered by default.

Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Binary file not shown.

0 comments on commit 80c7d86

Please sign in to comment.