File tree Expand file tree Collapse file tree 3 files changed +58
-5
lines changed
app/controlplane/api/workflowcontract/v1 Expand file tree Collapse file tree 3 files changed +58
-5
lines changed Original file line number Diff line number Diff line change @@ -244,10 +244,22 @@ func TestValidateRefs(t *testing.T) {
244
244
ref : "foobar:policy_name@foobar" ,
245
245
wantErrString : "invalid digest" ,
246
246
},
247
+ {
248
+ name : "valid digest" ,
249
+ ref : "foobar:policy-name@sha256:133d39edc0f0d32780dd9c940951df0910ef53e6fd64942801ba6fb76494bbf9" ,
250
+ },
247
251
{
248
252
name : "chainloop provider with valid digest" ,
249
253
ref : "foobar:policy-name@sha256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c" ,
250
254
},
255
+ {
256
+ name : "custom policy with valid digest" ,
257
+ ref : "readonly-demo/policy-name@sha256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c" ,
258
+ },
259
+ {
260
+ name : "builtin policy with valid digest" ,
261
+ ref : "policy-name@sha256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c" ,
262
+ },
251
263
{
252
264
name : "unsupported protocol" ,
253
265
ref : "unsupported://foobar/policy_name" ,
Original file line number Diff line number Diff line change @@ -205,7 +205,19 @@ type ProviderRef struct {
205
205
}
206
206
207
207
// ProviderParts returns the provider information for a given reference
208
- func ProviderParts (ref string ) * ProviderRef {
208
+ func ProviderParts (reference string ) * ProviderRef {
209
+ var ref , digest string
210
+ // first of all, remove the @sha256 suffix to make the parsing easier
211
+ withDigest := strings .SplitN (reference , "@sha256:" , 2 )
212
+
213
+ if len (withDigest ) > 1 {
214
+ // it has digest
215
+ ref = withDigest [0 ]
216
+ digest = withDigest [1 ]
217
+ } else {
218
+ ref = reference
219
+ }
220
+
209
221
parts := strings .SplitN (ref , "://" , 2 )
210
222
var pn []string
211
223
if len (parts ) == 1 {
@@ -232,6 +244,11 @@ func ProviderParts(ref string) *ProviderRef {
232
244
name = scoped [1 ]
233
245
}
234
246
247
+ // return the digest back
248
+ if digest != "" {
249
+ name = fmt .Sprintf ("%s@sha256:%s" , name , digest )
250
+ }
251
+
235
252
return & ProviderRef {
236
253
Provider : provider ,
237
254
Name : name ,
Original file line number Diff line number Diff line change @@ -249,10 +249,11 @@ func (s *testSuite) TestVerifyAttestations() {
249
249
250
250
func (s * testSuite ) TestProviderParts () {
251
251
testCases := []struct {
252
- ref string
253
- prov string
254
- name string
255
- org string
252
+ ref string
253
+ prov string
254
+ name string
255
+ org string
256
+ digest string
256
257
}{
257
258
{
258
259
ref : "chainloop://cyclonedx-freshness" ,
@@ -302,6 +303,29 @@ func (s *testSuite) TestProviderParts() {
302
303
org : "myorg" ,
303
304
name : "cyclonedx-freshness" ,
304
305
},
306
+ {
307
+ ref : "myorg/cyclonedx-freshness@sha256:123123123" ,
308
+ org : "myorg" ,
309
+ name : "cyclonedx-freshness@sha256:123123123" ,
310
+ },
311
+ {
312
+ ref : "builtin:myorg/cyclonedx-freshness@sha256:123123123" ,
313
+ prov : "builtin" ,
314
+ org : "myorg" ,
315
+ name : "cyclonedx-freshness@sha256:123123123" ,
316
+ },
317
+ {
318
+ ref : "chainloop://builtin:myorg/cyclonedx-freshness@sha256:123123123" ,
319
+ prov : "builtin" ,
320
+ org : "myorg" ,
321
+ name : "cyclonedx-freshness@sha256:123123123" ,
322
+ },
323
+ {
324
+ ref : "chainloop://myorg/cyclonedx-freshness@sha256:123123123" ,
325
+ prov : "" ,
326
+ org : "myorg" ,
327
+ name : "cyclonedx-freshness@sha256:123123123" ,
328
+ },
305
329
}
306
330
307
331
for _ , tc := range testCases {
You can’t perform that action at this time.
0 commit comments