(t *testing.T)
| 34 | ) |
| 35 | |
| 36 | func TestNewVerifyCmd(t *testing.T) { |
| 37 | testIO, _, _, _ := iostreams.Test() |
| 38 | var testReg httpmock.Registry |
| 39 | var metaResp = api.MetaResponse{ |
| 40 | Domains: api.Domain{ |
| 41 | ArtifactAttestations: api.ArtifactAttestations{ |
| 42 | TrustDomain: "foo", |
| 43 | }, |
| 44 | }, |
| 45 | } |
| 46 | testReg.Register(httpmock.REST(http.MethodGet, "meta"), |
| 47 | httpmock.StatusJSONResponse(200, &metaResp)) |
| 48 | |
| 49 | f := &cmdutil.Factory{ |
| 50 | IOStreams: testIO, |
| 51 | HttpClient: func() (*http.Client, error) { |
| 52 | reg := &testReg |
| 53 | client := &http.Client{} |
| 54 | httpmock.ReplaceTripper(client, reg) |
| 55 | return client, nil |
| 56 | }, |
| 57 | ExternalHttpClient: func() (*http.Client, error) { |
| 58 | return nil, nil |
| 59 | }, |
| 60 | } |
| 61 | |
| 62 | testcases := []struct { |
| 63 | name string |
| 64 | cli string |
| 65 | wants Options |
| 66 | wantsErr bool |
| 67 | wantsExporter bool |
| 68 | }{ |
| 69 | { |
| 70 | name: "Invalid digest-alg flag", |
| 71 | cli: fmt.Sprintf("%s --bundle %s --digest-alg sha384 --owner sigstore", artifactPath, bundlePath), |
| 72 | wants: Options{ |
| 73 | ArtifactPath: test.NormalizeRelativePath("../test/data/sigstore-js-2.1.0.tgz"), |
| 74 | BundlePath: test.NormalizeRelativePath("../test/data/sigstore-js-2.1.0-bundle.json"), |
| 75 | DigestAlgorithm: "sha384", |
| 76 | Hostname: "github.com", |
| 77 | Limit: 30, |
| 78 | OIDCIssuer: verification.GitHubOIDCIssuer, |
| 79 | Owner: "sigstore", |
| 80 | PredicateType: verification.SLSAPredicateV1, |
| 81 | SigstoreVerifier: verification.NewMockSigstoreVerifier(t), |
| 82 | }, |
| 83 | wantsErr: true, |
| 84 | }, |
| 85 | { |
| 86 | name: "Use default digest-alg value", |
| 87 | cli: fmt.Sprintf("%s --bundle %s --owner sigstore", artifactPath, bundlePath), |
| 88 | wants: Options{ |
| 89 | ArtifactPath: test.NormalizeRelativePath("../test/data/sigstore-js-2.1.0.tgz"), |
| 90 | BundlePath: test.NormalizeRelativePath("../test/data/sigstore-js-2.1.0-bundle.json"), |
| 91 | DigestAlgorithm: "sha256", |
| 92 | Hostname: "github.com", |
| 93 | Limit: 30, |
nothing calls this directly
no test coverage detected