@@ -17,6 +17,8 @@ package biz_test
1717
1818import (
1919 "context"
20+ "encoding/json"
21+ "os"
2022 "testing"
2123
2224 schemav1 "github.com/chainloop-dev/chainloop/app/controlplane/api/workflowcontract/v1"
@@ -31,6 +33,7 @@ import (
3133 "github.com/secure-systems-lab/go-securesystemslib/dsse"
3234 "github.com/stretchr/testify/assert"
3335 "github.com/stretchr/testify/mock"
36+ "github.com/stretchr/testify/require"
3437 "github.com/stretchr/testify/suite"
3538)
3639
@@ -106,7 +109,7 @@ func (s *workflowRunIntegrationTestSuite) TestSaveAttestation() {
106109 assert := assert .New (s .T ())
107110 ctx := context .Background ()
108111
109- validEnvelope := & dsse. Envelope {}
112+ validEnvelope := testEnvelope ( s . T (), "testdata/attestations/full.json" )
110113
111114 s .T ().Run ("non existing workflowRun" , func (t * testing.T ) {
112115 _ , err := s .WorkflowRun .SaveAttestation (ctx , uuid .NewString (), validEnvelope )
@@ -122,7 +125,7 @@ func (s *workflowRunIntegrationTestSuite) TestSaveAttestation() {
122125
123126 d , err := s .WorkflowRun .SaveAttestation (ctx , run .ID .String (), validEnvelope )
124127 assert .NoError (err )
125- wantDigest := "sha256:f845058d865c3d4d491c9019f6afe9c543ad2cd11b31620cc512e341fb03d3d8 "
128+ wantDigest := "sha256:1a077137aef7ca208b80c339769d0d7eecacc2850368e56e834cda1750ce413a "
126129 assert .Equal (wantDigest , d )
127130
128131 // Retrieve attestation ref from storage and compare
@@ -309,6 +312,14 @@ type workflowRunTestData struct {
309312 digestAtt1 , digestAttOrg2 , digestAttPublic string
310313}
311314
315+ func testEnvelope (t * testing.T , path string ) * dsse.Envelope {
316+ attJSON , err := os .ReadFile (path )
317+ require .NoError (t , err )
318+ var envelope * dsse.Envelope
319+ require .NoError (t , json .Unmarshal (attJSON , & envelope ))
320+ return envelope
321+ }
322+
312323// extract this setup to a helper function so it can be used from other test suites
313324func setupWorkflowRunTestData (t * testing.T , suite * testhelpers.TestingUseCases , s * workflowRunTestData ) {
314325 var err error
@@ -346,7 +357,7 @@ func setupWorkflowRunTestData(t *testing.T, suite *testhelpers.TestingUseCases,
346357 WorkflowID : s .workflowOrg1 .ID .String (), RobotaccountID : s .robotAccount .ID .String (), ContractRevision : s .contractVersion , CASBackendID : s .casBackend .ID ,
347358 })
348359 assert .NoError (err )
349- s .digestAtt1 , err = suite .WorkflowRun .SaveAttestation (ctx , s .runOrg1 .ID .String (), & dsse. Envelope { PayloadType : "test" } )
360+ s .digestAtt1 , err = suite .WorkflowRun .SaveAttestation (ctx , s .runOrg1 .ID .String (), testEnvelope ( t , "testdata/attestations/full.json" ) )
350361
351362 assert .NoError (err )
352363
@@ -355,15 +366,15 @@ func setupWorkflowRunTestData(t *testing.T, suite *testhelpers.TestingUseCases,
355366 WorkflowID : s .workflowOrg2 .ID .String (), RobotaccountID : s .robotAccount .ID .String (), ContractRevision : s .contractVersion , CASBackendID : s .casBackend .ID ,
356367 })
357368 assert .NoError (err )
358- s .digestAttOrg2 , err = suite .WorkflowRun .SaveAttestation (ctx , s .runOrg2 .ID .String (), & dsse. Envelope { PayloadType : "test2" } )
369+ s .digestAttOrg2 , err = suite .WorkflowRun .SaveAttestation (ctx , s .runOrg2 .ID .String (), testEnvelope ( t , "testdata/attestations/empty.json" ) )
359370 assert .NoError (err )
360371
361372 s .runOrg2Public , err = suite .WorkflowRun .Create (ctx ,
362373 & biz.WorkflowRunCreateOpts {
363374 WorkflowID : s .workflowPublicOrg2 .ID .String (), RobotaccountID : s .robotAccount .ID .String (), ContractRevision : s .contractVersion , CASBackendID : s .casBackend .ID ,
364375 })
365376 assert .NoError (err )
366- s .digestAttPublic , err = suite .WorkflowRun .SaveAttestation (ctx , s .runOrg2Public .ID .String (), & dsse. Envelope { PayloadType : "test3" } )
377+ s .digestAttPublic , err = suite .WorkflowRun .SaveAttestation (ctx , s .runOrg2Public .ID .String (), testEnvelope ( t , "testdata/attestations/with-string.json" ) )
367378 assert .NoError (err )
368379}
369380
0 commit comments