Skip to content

Commit d9eb062

Browse files
bdehamerCopilot
andcommitted
Assert digest prefix in release verify no-attestation tests
Address PR review feedback: - Rename SHA1 tests to make the algorithm explicit - Assert the sha1:/sha256: prefix appears in the error - Use a capturing MockClient so we verify the actual digest sent to GetByDigest, not just the wrapped error message Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5c437a8 commit d9eb062

2 files changed

Lines changed: 44 additions & 6 deletions

File tree

pkg/cmd/release/verify-asset/verify_asset_test.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func Test_verifyAssetRun_SuccessNoTagArg(t *testing.T) {
166166
require.NoError(t, err)
167167
}
168168

169-
func Test_verifyAssetRun_FailedNoAttestations(t *testing.T) {
169+
func Test_verifyAssetRun_FailedNoAttestations_SHA1(t *testing.T) {
170170
ios, _, _, _ := iostreams.Test()
171171
tagName := "v1"
172172

@@ -180,6 +180,14 @@ func Test_verifyAssetRun_FailedNoAttestations(t *testing.T) {
180180

181181
releaseAssetPath := test.NormalizeRelativePath("../../attestation/test/data/github_release_artifact.zip")
182182

183+
var capturedParams api.FetchParams
184+
attClient := &api.MockClient{
185+
OnGetByDigest: func(params api.FetchParams) ([]*api.Attestation, error) {
186+
capturedParams = params
187+
return api.OnGetByDigestFailure(params)
188+
},
189+
}
190+
183191
cfg := &VerifyAssetConfig{
184192
Opts: &VerifyAssetOptions{
185193
AssetFilePath: releaseAssetPath,
@@ -189,12 +197,14 @@ func Test_verifyAssetRun_FailedNoAttestations(t *testing.T) {
189197
},
190198
IO: ios,
191199
HttpClient: &http.Client{Transport: fakeHTTP},
192-
AttClient: api.NewFailTestClient(),
200+
AttClient: attClient,
193201
AttVerifier: nil,
194202
}
195203

196204
err = verifyAssetRun(cfg)
197205
require.ErrorContains(t, err, "no attestations found for tag v1")
206+
require.ErrorContains(t, err, "sha1:"+fakeSHA)
207+
require.Equal(t, "sha1:"+fakeSHA, capturedParams.Digest)
198208
}
199209

200210
func Test_verifyAssetRun_FailedNoAttestations_SHA256(t *testing.T) {
@@ -211,6 +221,14 @@ func Test_verifyAssetRun_FailedNoAttestations_SHA256(t *testing.T) {
211221

212222
releaseAssetPath := test.NormalizeRelativePath("../../attestation/test/data/github_release_artifact.zip")
213223

224+
var capturedParams api.FetchParams
225+
attClient := &api.MockClient{
226+
OnGetByDigest: func(params api.FetchParams) ([]*api.Attestation, error) {
227+
capturedParams = params
228+
return api.OnGetByDigestFailure(params)
229+
},
230+
}
231+
214232
cfg := &VerifyAssetConfig{
215233
Opts: &VerifyAssetOptions{
216234
AssetFilePath: releaseAssetPath,
@@ -220,13 +238,14 @@ func Test_verifyAssetRun_FailedNoAttestations_SHA256(t *testing.T) {
220238
},
221239
IO: ios,
222240
HttpClient: &http.Client{Transport: fakeHTTP},
223-
AttClient: api.NewFailTestClient(),
241+
AttClient: attClient,
224242
AttVerifier: nil,
225243
}
226244

227245
err = verifyAssetRun(cfg)
228246
require.ErrorContains(t, err, "no attestations found for tag v1")
229247
require.ErrorContains(t, err, "sha256:"+fakeSHA)
248+
require.Equal(t, "sha256:"+fakeSHA, capturedParams.Digest)
230249
}
231250

232251
func Test_verifyAssetRun_FailedTagNotInAttestation(t *testing.T) {

pkg/cmd/release/verify/verify_test.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func Test_verifyRun_Success(t *testing.T) {
103103
require.NoError(t, err)
104104
}
105105

106-
func Test_verifyRun_FailedNoAttestations(t *testing.T) {
106+
func Test_verifyRun_FailedNoAttestations_SHA1(t *testing.T) {
107107
ios, _, _, _ := iostreams.Test()
108108
tagName := "v1"
109109

@@ -115,6 +115,14 @@ func Test_verifyRun_FailedNoAttestations(t *testing.T) {
115115
baseRepo, err := ghrepo.FromFullName("owner/repo")
116116
require.NoError(t, err)
117117

118+
var capturedParams api.FetchParams
119+
attClient := &api.MockClient{
120+
OnGetByDigest: func(params api.FetchParams) ([]*api.Attestation, error) {
121+
capturedParams = params
122+
return api.OnGetByDigestFailure(params)
123+
},
124+
}
125+
118126
cfg := &VerifyConfig{
119127
Opts: &VerifyOptions{
120128
TagName: tagName,
@@ -123,12 +131,14 @@ func Test_verifyRun_FailedNoAttestations(t *testing.T) {
123131
},
124132
IO: ios,
125133
HttpClient: &http.Client{Transport: fakeHTTP},
126-
AttClient: api.NewFailTestClient(),
134+
AttClient: attClient,
127135
AttVerifier: nil,
128136
}
129137

130138
err = verifyRun(cfg)
131139
require.ErrorContains(t, err, "no attestations for tag v1")
140+
require.ErrorContains(t, err, "sha1:"+fakeSHA)
141+
require.Equal(t, "sha1:"+fakeSHA, capturedParams.Digest)
132142
}
133143

134144
func Test_verifyRun_FailedNoAttestations_SHA256(t *testing.T) {
@@ -143,6 +153,14 @@ func Test_verifyRun_FailedNoAttestations_SHA256(t *testing.T) {
143153
baseRepo, err := ghrepo.FromFullName("owner/repo")
144154
require.NoError(t, err)
145155

156+
var capturedParams api.FetchParams
157+
attClient := &api.MockClient{
158+
OnGetByDigest: func(params api.FetchParams) ([]*api.Attestation, error) {
159+
capturedParams = params
160+
return api.OnGetByDigestFailure(params)
161+
},
162+
}
163+
146164
cfg := &VerifyConfig{
147165
Opts: &VerifyOptions{
148166
TagName: tagName,
@@ -151,13 +169,14 @@ func Test_verifyRun_FailedNoAttestations_SHA256(t *testing.T) {
151169
},
152170
IO: ios,
153171
HttpClient: &http.Client{Transport: fakeHTTP},
154-
AttClient: api.NewFailTestClient(),
172+
AttClient: attClient,
155173
AttVerifier: nil,
156174
}
157175

158176
err = verifyRun(cfg)
159177
require.ErrorContains(t, err, "no attestations for tag v1")
160178
require.ErrorContains(t, err, "sha256:"+fakeSHA)
179+
require.Equal(t, "sha256:"+fakeSHA, capturedParams.Digest)
161180
}
162181

163182
func Test_verifyRun_FailedTagNotInAttestation(t *testing.T) {

0 commit comments

Comments
 (0)