Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsimon committed Aug 4, 2022
1 parent 0cb53fe commit e3dfe05
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 51 deletions.
31 changes: 16 additions & 15 deletions verifiers/internal/gha/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"

serrors "github.com/slsa-framework/slsa-verifier/errors"
"github.com/slsa-framework/slsa-verifier/options"
)

func Test_VerifyWorkflowIdentity(t *testing.T) {
t.Parallel()
tests := []struct {
name string
workflow *WorkflowIdentity
buildOpts *BuilderOpts
buildOpts *options.BuilderOpts
builderID string
source string
err serrors.Error
err error
}{
{
name: "invalid job workflow ref",
Expand Down Expand Up @@ -87,7 +88,7 @@ func Test_VerifyWorkflowIdentity(t *testing.T) {
Issuer: certOidcIssuer,
},
source: e2eTestRepository,
buildOpts: &BuilderOpts{
buildOpts: &options.BuilderOpts{
ExpectedID: asStringPointer("https://github.com/" + trustedBuilderRepository + "/.github/workflows/builder_go_slsa3.yml"),
},
},
Expand All @@ -101,7 +102,7 @@ func Test_VerifyWorkflowIdentity(t *testing.T) {
Issuer: certOidcIssuer,
},
source: e2eTestRepository,
buildOpts: &BuilderOpts{
buildOpts: &options.BuilderOpts{
ExpectedID: asStringPointer("some-other-builderID"),
},
err: serrors.ErrorUntrustedReusableWorkflow,
Expand Down Expand Up @@ -162,7 +163,7 @@ func Test_VerifyWorkflowIdentity(t *testing.T) {
Issuer: certOidcIssuer,
},
source: "asraa/slsa-on-github-test",
buildOpts: &BuilderOpts{
buildOpts: &options.BuilderOpts{
ExpectedID: asStringPointer("https://github.com/" + trustedBuilderRepository + "/.github/workflows/builder_go_slsa3.yml"),
},
},
Expand All @@ -176,7 +177,7 @@ func Test_VerifyWorkflowIdentity(t *testing.T) {
Issuer: certOidcIssuer,
},
source: "asraa/slsa-on-github-test",
buildOpts: &BuilderOpts{
buildOpts: &options.BuilderOpts{
ExpectedID: asStringPointer("some-other-builderID"),
},
err: serrors.ErrorUntrustedReusableWorkflow,
Expand Down Expand Up @@ -238,7 +239,7 @@ func Test_VerifyWorkflowIdentity(t *testing.T) {
Issuer: certOidcIssuer,
},
source: "github.com/asraa/slsa-on-github-test",
buildOpts: &BuilderOpts{
buildOpts: &options.BuilderOpts{
ExpectedID: asStringPointer("https://github.com/" + trustedBuilderRepository + "/.github/workflows/builder_go_slsa3.yml"),
},
},
Expand All @@ -252,7 +253,7 @@ func Test_VerifyWorkflowIdentity(t *testing.T) {
Issuer: certOidcIssuer,
},
source: "github.com/asraa/slsa-on-github-test",
buildOpts: &BuilderOpts{
buildOpts: &options.BuilderOpts{
ExpectedID: asStringPointer("some-other-builderID"),
},
err: serrors.ErrorUntrustedReusableWorkflow,
Expand All @@ -264,11 +265,11 @@ func Test_VerifyWorkflowIdentity(t *testing.T) {
t.Parallel()
opts := tt.buildOpts
if opts == nil {
opts = &BuilderOpts{}
opts = &options.BuilderOpts{}
}
_, err := VerifyWorkflowIdentity(tt.workflow, opts, tt.source)
if !errCmp(err, tt.err) {
t.serrors.Errorf(cmp.Diff(err, tt.err, cmpopts.Equateserrors.Errors()))
t.Errorf(cmp.Diff(err, tt.err, cmpopts.EquateErrors()))
}
})
}
Expand All @@ -284,7 +285,7 @@ func Test_verifyTrustedBuilderID(t *testing.T) {
name string
id *string
path string
expected serrors.Error
expected error
}{
{
name: "default trusted",
Expand Down Expand Up @@ -327,14 +328,14 @@ func Test_verifyTrustedBuilderID(t *testing.T) {

id, err := verifyTrustedBuilderID(tt.path, tt.id)
if !errCmp(err, tt.expected) {
t.serrors.Errorf(cmp.Diff(err, tt.expected, cmpopts.Equateserrors.Errors()))
t.Errorf(cmp.Diff(err, tt.expected, cmpopts.EquateErrors()))
}
if err != nil {
return
}
expectedID := "https://github.com/" + tt.path
if id != expectedID {
t.serrors.Errorf(cmp.Diff(id, expectedID))
t.Errorf(cmp.Diff(id, expectedID))
}
})
}
Expand All @@ -346,7 +347,7 @@ func Test_verifyTrustedBuilderRef(t *testing.T) {
name string
callerRepo string
builderRef string
expected serrors.Error
expected error
}{
// Trusted repo.
{
Expand Down Expand Up @@ -484,7 +485,7 @@ func Test_verifyTrustedBuilderRef(t *testing.T) {

err := verifyTrustedBuilderRef(&wf, tt.builderRef)
if !errCmp(err, tt.expected) {
t.serrors.Errorf(cmp.Diff(err, tt.expected, cmpopts.Equateserrors.Errors()))
t.Errorf(cmp.Diff(err, tt.expected, cmpopts.EquateErrors()))
}
})
}
Expand Down
Loading

0 comments on commit e3dfe05

Please sign in to comment.