MCPcopy Create free account
hub / github.com/cli/cli / TestVerifyCertExtensions

Function TestVerifyCertExtensions

pkg/cmd/attestation/verification/extensions_test.go:26–106  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24}
25
26func TestVerifyCertExtensions(t *testing.T) {
27 results := []*AttestationProcessingResult{createSampleResult()}
28
29 certSummary := certificate.Summary{
30 SourceRepositoryOwnerURI: "https://github.com/owner",
31 SourceRepositoryURI: "https://github.com/owner/repo",
32 Issuer: GitHubOIDCIssuer,
33 SourceRepositoryRef: "refs/heads/main",
34 }
35
36 c := EnforcementCriteria{
37 Certificate: certSummary,
38 }
39
40 t.Run("passes with one result", func(t *testing.T) {
41 verified, err := VerifyCertExtensions(results, c)
42 require.NoError(t, err)
43 require.Len(t, verified, 1)
44 })
45
46 t.Run("passes with 1/2 valid results", func(t *testing.T) {
47 twoResults := []*AttestationProcessingResult{createSampleResult(), createSampleResult()}
48 require.Len(t, twoResults, 2)
49 twoResults[1].VerificationResult.Signature.Certificate.Extensions.SourceRepositoryOwnerURI = "https://github.com/wrong"
50
51 verified, err := VerifyCertExtensions(twoResults, c)
52 require.NoError(t, err)
53 require.Len(t, verified, 1)
54 })
55
56 t.Run("fails when all results fail verification", func(t *testing.T) {
57 twoResults := []*AttestationProcessingResult{createSampleResult(), createSampleResult()}
58 require.Len(t, twoResults, 2)
59 twoResults[0].VerificationResult.Signature.Certificate.Extensions.SourceRepositoryOwnerURI = "https://github.com/wrong"
60 twoResults[1].VerificationResult.Signature.Certificate.Extensions.SourceRepositoryOwnerURI = "https://github.com/wrong"
61
62 verified, err := VerifyCertExtensions(twoResults, c)
63 require.Error(t, err)
64 require.Nil(t, verified)
65 })
66
67 t.Run("with wrong SourceRepositoryOwnerURI", func(t *testing.T) {
68 expectedCriteria := c
69 expectedCriteria.Certificate.SourceRepositoryOwnerURI = "https://github.com/wrong"
70 verified, err := VerifyCertExtensions(results, expectedCriteria)
71 require.ErrorContains(t, err, "expected SourceRepositoryOwnerURI to be https://github.com/wrong, got https://github.com/owner")
72 require.Nil(t, verified)
73 })
74
75 t.Run("with wrong SourceRepositoryURI", func(t *testing.T) {
76 expectedCriteria := c
77 expectedCriteria.Certificate.SourceRepositoryURI = "https://github.com/foo/wrong"
78 verified, err := VerifyCertExtensions(results, expectedCriteria)
79 require.ErrorContains(t, err, "expected SourceRepositoryURI to be https://github.com/foo/wrong, got https://github.com/owner/repo")
80 require.Nil(t, verified)
81 })
82
83 t.Run("with wrong OIDCIssuer", func(t *testing.T) {

Callers

nothing calls this directly

Calls 5

createSampleResultFunction · 0.85
VerifyCertExtensionsFunction · 0.85
RunMethod · 0.65
LenMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected