update test
This commit is contained in:
parent
c1adb1a6cf
commit
e21e5ef5c5
4 changed files with 32 additions and 23 deletions
|
|
@ -10,7 +10,7 @@ func VerifyCertExtensions(results []*AttestationProcessingResult, owner string,
|
|||
if owner != "" {
|
||||
expectedSourceRepositoryOwnerURI := fmt.Sprintf("https://github.com/%s", owner)
|
||||
sourceRepositoryOwnerURI := attestation.VerificationResult.Signature.Certificate.Extensions.SourceRepositoryOwnerURI
|
||||
if !strings.EqualFold(expectedSourceRepositoryOwnerURI, sourceRepositoryOwnerURI) {
|
||||
if sourceRepositoryOwnerURI != "" && !strings.EqualFold(expectedSourceRepositoryOwnerURI, sourceRepositoryOwnerURI) {
|
||||
return fmt.Errorf("expected SourceRepositoryOwnerURI to be %s, got %s", expectedSourceRepositoryOwnerURI, sourceRepositoryOwnerURI)
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ func VerifyCertExtensions(results []*AttestationProcessingResult, owner string,
|
|||
if repo != "" {
|
||||
expectedSourceRepositoryURI := fmt.Sprintf("https://github.com/%s", repo)
|
||||
sourceRepositoryURI := attestation.VerificationResult.Signature.Certificate.Extensions.SourceRepositoryURI
|
||||
if !strings.EqualFold(expectedSourceRepositoryURI, sourceRepositoryURI) {
|
||||
if sourceRepositoryURI != "" && !strings.EqualFold(expectedSourceRepositoryURI, sourceRepositoryURI) {
|
||||
return fmt.Errorf("expected SourceRepositoryURI to be %s, got %s", expectedSourceRepositoryURI, sourceRepositoryURI)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,18 +24,27 @@ func TestVerifyCertExtensions(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
err := VerifyCertExtensions(results, "owner", "owner/repo")
|
||||
require.NoError(t, err)
|
||||
t.Run("VerifyCertExtensions with owner and repo", func(t *testing.T) {
|
||||
err := VerifyCertExtensions(results, "owner", "owner/repo")
|
||||
require.NoError(t, err)
|
||||
})
|
||||
t.Run("VerifyCertExtensions with repo", func(t *testing.T) {
|
||||
err := VerifyCertExtensions(results, "", "owner/repo")
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
err = VerifyCertExtensions(results, "", "owner/repo")
|
||||
require.NoError(t, err)
|
||||
t.Run("VerifyCertExtensions with owner", func(t *testing.T) {
|
||||
err := VerifyCertExtensions(results, "owner", "")
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
err = VerifyCertExtensions(results, "owner", "")
|
||||
require.NoError(t, err)
|
||||
t.Run("VerifyCertExtensions with wrong owner", func(t *testing.T) {
|
||||
err := VerifyCertExtensions(results, "wrong", "")
|
||||
require.ErrorContains(t, err, "expected SourceRepositoryOwnerURI to be https://github.com/wrong, got https://github.com/owner")
|
||||
})
|
||||
|
||||
err = VerifyCertExtensions(results, "wrong", "")
|
||||
require.ErrorContains(t, err, "expected SourceRepositoryOwnerURI to be https://github.com/wrong, got https://github.com/owner")
|
||||
|
||||
err = VerifyCertExtensions(results, "", "wrong")
|
||||
require.ErrorContains(t, err, "expected SourceRepositoryURI to be https://github.com/wrong, got https://github.com/owner/repo")
|
||||
t.Run("VerifyCertExtensions with wrong repo", func(t *testing.T) {
|
||||
err := VerifyCertExtensions(results, "", "wrong")
|
||||
require.ErrorContains(t, err, "expected SourceRepositoryURI to be https://github.com/wrong, got https://github.com/owner/repo")
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ func TestSetPolicyFlags(t *testing.T) {
|
|||
opts.SetPolicyFlags()
|
||||
require.Equal(t, "sigstore", opts.Owner)
|
||||
require.Equal(t, "sigstore/sigstore-js", opts.Repo)
|
||||
require.Equal(t, "^https://github.com/sigstore/sigstore-js/", opts.SANRegex)
|
||||
require.Equal(t, "(?i)^https://github.com/sigstore/sigstore-js/", opts.SANRegex)
|
||||
})
|
||||
|
||||
t.Run("does not set SANRegex when SANRegex and Repo are provided", func(t *testing.T) {
|
||||
|
|
@ -99,7 +99,7 @@ func TestSetPolicyFlags(t *testing.T) {
|
|||
|
||||
opts.SetPolicyFlags()
|
||||
require.Equal(t, "sigstore", opts.Owner)
|
||||
require.Equal(t, "^https://github.com/sigstore/", opts.SANRegex)
|
||||
require.Equal(t, "(?i)^https://github.com/sigstore/", opts.SANRegex)
|
||||
})
|
||||
|
||||
t.Run("does not set SANRegex when SANRegex and Owner are provided", func(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ func TestNewVerifyCmd(t *testing.T) {
|
|||
Limit: 30,
|
||||
OIDCIssuer: GitHubOIDCIssuer,
|
||||
Owner: "sigstore",
|
||||
SANRegex: "^https://github.com/sigstore/",
|
||||
SANRegex: "(?i)^https://github.com/sigstore/",
|
||||
SigstoreVerifier: verification.NewMockSigstoreVerifier(t),
|
||||
},
|
||||
wantsErr: false,
|
||||
|
|
@ -91,7 +91,7 @@ func TestNewVerifyCmd(t *testing.T) {
|
|||
Limit: 30,
|
||||
OIDCIssuer: GitHubOIDCIssuer,
|
||||
Owner: "sigstore",
|
||||
SANRegex: "^https://github.com/sigstore/",
|
||||
SANRegex: "(?i)^https://github.com/sigstore/",
|
||||
SigstoreVerifier: verification.NewMockSigstoreVerifier(t),
|
||||
},
|
||||
wantsErr: false,
|
||||
|
|
@ -105,7 +105,7 @@ func TestNewVerifyCmd(t *testing.T) {
|
|||
OIDCIssuer: GitHubOIDCIssuer,
|
||||
Owner: "sigstore",
|
||||
Limit: 30,
|
||||
SANRegex: "^https://github.com/sigstore/",
|
||||
SANRegex: "(?i)^https://github.com/sigstore/",
|
||||
SigstoreVerifier: verification.NewMockSigstoreVerifier(t),
|
||||
},
|
||||
wantsErr: true,
|
||||
|
|
@ -133,7 +133,7 @@ func TestNewVerifyCmd(t *testing.T) {
|
|||
Limit: 30,
|
||||
OIDCIssuer: GitHubOIDCIssuer,
|
||||
Owner: "sigstore",
|
||||
SANRegex: "^https://github.com/sigstore/",
|
||||
SANRegex: "(?i)^https://github.com/sigstore/",
|
||||
SigstoreVerifier: verification.NewMockSigstoreVerifier(t),
|
||||
},
|
||||
wantsErr: false,
|
||||
|
|
@ -147,7 +147,7 @@ func TestNewVerifyCmd(t *testing.T) {
|
|||
OIDCIssuer: GitHubOIDCIssuer,
|
||||
Owner: "sigstore",
|
||||
Limit: 101,
|
||||
SANRegex: "^https://github.com/sigstore/",
|
||||
SANRegex: "(?i)^https://github.com/sigstore/",
|
||||
SigstoreVerifier: verification.NewMockSigstoreVerifier(t),
|
||||
},
|
||||
wantsErr: false,
|
||||
|
|
@ -161,7 +161,7 @@ func TestNewVerifyCmd(t *testing.T) {
|
|||
OIDCIssuer: GitHubOIDCIssuer,
|
||||
Owner: "sigstore",
|
||||
Limit: 0,
|
||||
SANRegex: "^https://github.com/sigstore/",
|
||||
SANRegex: "(?i)^https://github.com/sigstore/",
|
||||
SigstoreVerifier: verification.NewMockSigstoreVerifier(t),
|
||||
},
|
||||
wantsErr: true,
|
||||
|
|
@ -176,7 +176,7 @@ func TestNewVerifyCmd(t *testing.T) {
|
|||
OIDCIssuer: GitHubOIDCIssuer,
|
||||
Owner: "sigstore",
|
||||
SAN: "https://github.com/sigstore/",
|
||||
SANRegex: "^https://github.com/sigstore/",
|
||||
SANRegex: "(?i)^https://github.com/sigstore/",
|
||||
SigstoreVerifier: verification.NewMockSigstoreVerifier(t),
|
||||
},
|
||||
wantsErr: true,
|
||||
|
|
@ -191,7 +191,7 @@ func TestNewVerifyCmd(t *testing.T) {
|
|||
Limit: 30,
|
||||
OIDCIssuer: GitHubOIDCIssuer,
|
||||
Owner: "sigstore",
|
||||
SANRegex: "^https://github.com/sigstore/",
|
||||
SANRegex: "(?i)^https://github.com/sigstore/",
|
||||
SigstoreVerifier: verification.NewMockSigstoreVerifier(t),
|
||||
},
|
||||
wantsExporter: true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue