(given, expected certificate.Summary)
| 41 | } |
| 42 | |
| 43 | func verifyCertExtensions(given, expected certificate.Summary) error { |
| 44 | if !strings.EqualFold(expected.SourceRepositoryOwnerURI, given.SourceRepositoryOwnerURI) { |
| 45 | return fmt.Errorf("expected SourceRepositoryOwnerURI to be %s, got %s", expected.SourceRepositoryOwnerURI, given.SourceRepositoryOwnerURI) |
| 46 | } |
| 47 | |
| 48 | // if repo is set, compare the SourceRepositoryURI fields |
| 49 | if expected.SourceRepositoryURI != "" && !strings.EqualFold(expected.SourceRepositoryURI, given.SourceRepositoryURI) { |
| 50 | return fmt.Errorf("expected SourceRepositoryURI to be %s, got %s", expected.SourceRepositoryURI, given.SourceRepositoryURI) |
| 51 | } |
| 52 | |
| 53 | // compare the OIDC issuers. If not equal, return an error depending |
| 54 | // on if there is a partial match |
| 55 | if !strings.EqualFold(expected.Issuer, given.Issuer) { |
| 56 | if strings.Index(given.Issuer, expected.Issuer+"/") == 0 { |
| 57 | return fmt.Errorf("expected Issuer to be %s, got %s -- if you have a custom OIDC issuer policy for your enterprise, use the --cert-oidc-issuer flag with your expected issuer", expected.Issuer, given.Issuer) |
| 58 | } |
| 59 | return fmt.Errorf("expected Issuer to be %s, got %s", expected.Issuer, given.Issuer) |
| 60 | } |
| 61 | |
| 62 | if expected.BuildSignerDigest != "" && !strings.EqualFold(expected.BuildSignerDigest, given.BuildSignerDigest) { |
| 63 | return fmt.Errorf("expected BuildSignerDigest to be %s, got %s", expected.BuildSignerDigest, given.BuildSignerDigest) |
| 64 | } |
| 65 | if expected.SourceRepositoryDigest != "" && !strings.EqualFold(expected.SourceRepositoryDigest, given.SourceRepositoryDigest) { |
| 66 | return fmt.Errorf("expected SourceRepositoryDigest to be %s, got %s", expected.SourceRepositoryDigest, given.SourceRepositoryDigest) |
| 67 | } |
| 68 | // SourceRepositoryRef must be a case-sensitive comparison |
| 69 | if expected.SourceRepositoryRef != "" && expected.SourceRepositoryRef != given.SourceRepositoryRef { |
| 70 | return fmt.Errorf("expected SourceRepositoryRef to be %s, got %s", expected.SourceRepositoryRef, given.SourceRepositoryRef) |
| 71 | } |
| 72 | |
| 73 | return nil |
| 74 | } |
no test coverage detected