MCPcopy
hub / github.com/cli/cli / TestNewVerifyCmd

Function TestNewVerifyCmd

pkg/cmd/attestation/verify/verify_test.go:36–318  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

34)
35
36func 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,

Callers

nothing calls this directly

Calls 11

RegisterMethod · 0.95
TestFunction · 0.92
RESTFunction · 0.92
StatusJSONResponseFunction · 0.92
ReplaceTripperFunction · 0.92
NormalizeRelativePathFunction · 0.92
NewMockSigstoreVerifierFunction · 0.92
NewVerifyCmdFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected