Skip to content

Commit 70d23d4

Browse files
authored
test: re-generate container-based tests (#627)
Signed-off-by: Asra Ali <[email protected]>
1 parent db0560e commit 70d23d4

File tree

4 files changed

+60
-64
lines changed

4 files changed

+60
-64
lines changed

cli/slsa-verifier/main_regression_test.go

+59-63
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ var (
4040
GHA_ARTIFACT_PATH_BUILDERS = []string{"gha_go", "gha_generic"}
4141
// TODO(https://github.com/slsa-framework/slsa-verifier/issues/485): Merge this with
4242
// GHA_ARTIFACT_PATH_BUILDERS.
43-
GHA_ARTIFACT_DOCKER_BUILDERS = []string{"gha_docker-based"}
44-
GHA_ARTIFACT_IMAGE_BUILDERS = []string{"gha_generic_container"}
45-
GCB_ARTIFACT_IMAGE_BUILDERS = []string{"gcb_container"}
43+
GHA_ARTIFACT_CONTAINER_BUILDERS = []string{"gha_container-based"}
44+
GHA_ARTIFACT_IMAGE_BUILDERS = []string{"gha_generic_container"}
45+
GCB_ARTIFACT_IMAGE_BUILDERS = []string{"gcb_container"}
4646
)
4747

4848
func getBuildersAndVersions(t *testing.T,
@@ -1298,16 +1298,14 @@ func Test_runVerifyGCBArtifactImage(t *testing.T) {
12981298
}
12991299
}
13001300

1301-
// TODO(https://github.com/slsa-framework/slsa-verifier/issues/485): Version the test-cases
1302-
// when a version for the builder is released.
1303-
func Test_runVerifyGHADockerBased(t *testing.T) {
1301+
// TODO(#485): Version the test-cases when a version for the builder is released.
1302+
func Test_runVerifyGHAContainerBased(t *testing.T) {
13041303
// We cannot use t.Setenv due to parallelized tests.
13051304
os.Setenv("SLSA_VERIFIER_EXPERIMENTAL", "1")
13061305
os.Setenv("SLSA_VERIFIER_TESTING", "1")
13071306

13081307
t.Parallel()
13091308

1310-
builder := "https://github.com/slsa-framework/slsa-github-generator/.github/workflows/builder_docker-based_slsa3.yml"
13111309
tests := []struct {
13121310
name string
13131311
artifacts []string
@@ -1319,44 +1317,38 @@ func Test_runVerifyGHADockerBased(t *testing.T) {
13191317
inputs map[string]string
13201318
err error
13211319
}{
1322-
// TODO(#610): Re-enable these tests.
1323-
// {
1324-
// name: "valid main branch default",
1325-
// artifacts: []string{"workflow_dispatch.main.default"},
1326-
// source: "github.com/slsa-framework/example-package",
1327-
// pBuilderID: pString("https://github.com/slsa-framework/slsa-github-generator/.github/workflows/builder_docker-based_slsa3.yml"),
1328-
// },
1329-
// {
1330-
// name: "versioned tag no match empty tag workflow_dispatch",
1331-
// artifacts: []string{"workflow_dispatch.main.default"},
1332-
// source: "github.com/slsa-framework/example-package",
1333-
// pBuilderID: pString("https://github.com/slsa-framework/slsa-github-generator/.github/workflows/builder_docker-based_slsa3.yml"),
1334-
// pversiontag: pString("v1"),
1335-
// err: serrors.ErrorInvalidSemver,
1336-
// },
1337-
// {
1338-
// name: "tag no match empty tag workflow_dispatch",
1339-
// artifacts: []string{"workflow_dispatch.main.default"},
1340-
// source: "github.com/slsa-framework/example-package",
1341-
// pBuilderID: pString("https://github.com/slsa-framework/slsa-github-generator/.github/workflows/builder_docker-based_slsa3.yml"),
1342-
// ptag: pString("v1.2.3"),
1343-
// err: serrors.ErrorMismatchTag,
1344-
// },
1345-
// {
1346-
// name: "wrong branch master",
1347-
// artifacts: []string{"workflow_dispatch.main.default"},
1348-
// source: "github.com/slsa-framework/example-package",
1349-
// pbranch: pString("master"),
1350-
// pBuilderID: pString("https://github.com/slsa-framework/slsa-github-generator/.github/workflows/builder_docker-based_slsa3.yml"),
1351-
// err: serrors.ErrorMismatchBranch,
1352-
// },
1353-
// {
1354-
// name: "valid main branch set",
1355-
// artifacts: []string{"workflow_dispatch.main.default"},
1356-
// source: "github.com/slsa-framework/example-package",
1357-
// pBuilderID: pString("https://github.com/slsa-framework/slsa-github-generator/.github/workflows/builder_docker-based_slsa3.yml"),
1358-
// pbranch: pString("main"),
1359-
// },
1320+
{
1321+
name: "valid main branch default",
1322+
artifacts: []string{"workflow_dispatch.main.default"},
1323+
source: "github.com/slsa-framework/example-package",
1324+
},
1325+
{
1326+
name: "versioned tag no match empty tag workflow_dispatch",
1327+
artifacts: []string{"workflow_dispatch.main.default"},
1328+
source: "github.com/slsa-framework/example-package",
1329+
pversiontag: pString("v1"),
1330+
err: serrors.ErrorInvalidSemver,
1331+
},
1332+
{
1333+
name: "tag no match empty tag workflow_dispatch",
1334+
artifacts: []string{"workflow_dispatch.main.default"},
1335+
source: "github.com/slsa-framework/example-package",
1336+
ptag: pString("v1.2.3"),
1337+
err: serrors.ErrorMismatchTag,
1338+
},
1339+
{
1340+
name: "wrong branch master",
1341+
artifacts: []string{"workflow_dispatch.main.default"},
1342+
source: "github.com/slsa-framework/example-package",
1343+
pbranch: pString("master"),
1344+
err: serrors.ErrorMismatchBranch,
1345+
},
1346+
{
1347+
name: "valid main branch set",
1348+
artifacts: []string{"workflow_dispatch.main.default"},
1349+
source: "github.com/slsa-framework/example-package",
1350+
pbranch: pString("main"),
1351+
},
13601352
{
13611353
name: "valid main branch default - invalid builderID",
13621354
artifacts: []string{"workflow_dispatch.main.default"},
@@ -1365,33 +1357,30 @@ func Test_runVerifyGHADockerBased(t *testing.T) {
13651357
err: serrors.ErrorUntrustedReusableWorkflow,
13661358
},
13671359
{
1368-
name: "wrong source append A",
1369-
artifacts: []string{"workflow_dispatch.main.default"},
1370-
source: "github.com/slsa-framework/example-packageA",
1371-
pBuilderID: pString("https://github.com/slsa-framework/slsa-github-generator/.github/workflows/builder_docker-based_slsa3.yml"),
1372-
err: serrors.ErrorMismatchSource,
1360+
name: "wrong source append A",
1361+
artifacts: []string{"workflow_dispatch.main.default"},
1362+
source: "github.com/slsa-framework/example-packageA",
1363+
err: serrors.ErrorMismatchSource,
13731364
},
13741365
{
1375-
name: "wrong source prepend A",
1376-
artifacts: []string{"workflow_dispatch.main.default"},
1377-
source: "Agithub.com/slsa-framework/example-package",
1378-
pBuilderID: pString("https://github.com/slsa-framework/slsa-github-generator/.github/workflows/builder_docker-based_slsa3.yml"),
1379-
err: serrors.ErrorMismatchSource,
1366+
name: "wrong source prepend A",
1367+
artifacts: []string{"workflow_dispatch.main.default"},
1368+
source: "Agithub.com/slsa-framework/example-package",
1369+
err: serrors.ErrorMismatchSource,
13801370
},
13811371
{
1382-
name: "wrong source middle A",
1383-
artifacts: []string{"workflow_dispatch.main.default"},
1384-
source: "github.com/Aslsa-framework/example-package",
1385-
pBuilderID: pString("https://github.com/slsa-framework/slsa-github-generator/.github/workflows/builder_docker-based_slsa3.yml"),
1386-
err: serrors.ErrorMismatchSource,
1372+
name: "wrong source middle A",
1373+
artifacts: []string{"workflow_dispatch.main.default"},
1374+
source: "github.com/Aslsa-framework/example-package",
1375+
err: serrors.ErrorMismatchSource,
13871376
},
13881377
}
13891378
for _, tt := range tests {
13901379
tt := tt // Re-initializing variable so it is not changed while executing the closure below
13911380
t.Run(tt.name, func(t *testing.T) {
13921381
t.Parallel()
13931382

1394-
checkVersions := getBuildersAndVersions(t, "", nil, GHA_ARTIFACT_DOCKER_BUILDERS)
1383+
checkVersions := getBuildersAndVersions(t, "", nil, GHA_ARTIFACT_CONTAINER_BUILDERS)
13951384

13961385
for _, v := range checkVersions {
13971386
testPath := filepath.Clean(filepath.Join(TEST_DIR, v, tt.artifacts[0]))
@@ -1408,9 +1397,16 @@ func Test_runVerifyGHADockerBased(t *testing.T) {
14081397
// 3. With only the name of the builder.
14091398
// 4. With no builder ID.
14101399
sv := path.Base(v)
1400+
builder := "https://github.com/slsa-framework/slsa-github-generator/.github/workflows/builder_container-based_slsa3.yml"
1401+
1402+
refName := "@refs/tags/"
1403+
if sv == "main" {
1404+
refName = "@refs/heads/"
1405+
}
1406+
// TODO(#485): Add pString(builder + "@" + sv) when migrating to tagged builders
1407+
// and remove main builder test.
14111408
builderIDs := []*string{
1412-
pString(builder + "@" + sv),
1413-
pString(builder + "@refs/tags/" + sv),
1409+
pString(builder + refName + sv),
14141410
pString(builder),
14151411
nil,
14161412
}

0 commit comments

Comments
 (0)