@@ -27,6 +27,8 @@ import (
2727var (
2828 ExampleAttestation = filepath .Join ("test" , "testdata" , "example_attestation.json" )
2929 LocalKeysPolicy = filepath .Join ("test" , "testdata" , "local-policy-real" )
30+ LocalParamPolicy = filepath .Join ("test" , "testdata" , "local-policy-param" )
31+ ExpiresPolicy = filepath .Join ("test" , "testdata" , "expires" )
3032)
3133
3234const (
@@ -60,7 +62,7 @@ func TestVerifyAttestations(t *testing.T) {
6062 return policy .AllowedResult (), tc .policyEvaluationError
6163 },
6264 }
63- _ , err := VerifyAttestations (ctx , resolver , & mockPE , & policy.Policy {ResolvedName : "" })
65+ _ , err := verifyAttestations (ctx , resolver , & mockPE , & policy.Policy {ResolvedName : "" }, & policy. Options { })
6466 if tc .expectedError != nil {
6567 if assert .Error (t , err ) {
6668 assert .Equal (t , tc .expectedError .Error (), err .Error ())
@@ -204,24 +206,24 @@ func TestSignVerify(t *testing.T) {
204206 keysYaml , err := yaml .Marshal (config )
205207 require .NoError (t , err )
206208
207- // write keysYaml to config.yaml in LocalKeysPolicy.
208- err = os .WriteFile (filepath .Join (LocalKeysPolicy , "config.yaml" ), keysYaml , 0o600 )
209- require .NoError (t , err )
210-
211209 testCases := []struct {
212210 name string
213211 signTL bool
214212 policyDir string
215213 imageName string
216214 expectedNonSuccess Outcome
215+ spitConfig bool
216+ param string
217217 }{
218218 {name : "happy path" , signTL : true , policyDir : PassNoTLPolicyDir },
219219 {name : "sign tl, verify no tl" , signTL : true , policyDir : PassPolicyDir },
220220 {name : "no tl" , signTL : false , policyDir : PassPolicyDir },
221221 {name : "mirror" , signTL : false , policyDir : PassMirrorPolicyDir , imageName : "mirror.org/library/test-image:test" },
222222 {name : "mirror no match" , signTL : false , policyDir : PassMirrorPolicyDir , imageName : "incorrect.org/library/test-image:test" , expectedNonSuccess : OutcomeNoPolicy },
223223 {name : "verify inputs" , signTL : false , policyDir : InputsPolicyDir },
224- {name : "mirror with verification" , signTL : false , policyDir : LocalKeysPolicy , imageName : "mirror.org/library/test-image:test" },
224+ {name : "mirror with verification" , signTL : false , policyDir : LocalKeysPolicy , imageName : "mirror.org/library/test-image:test" , spitConfig : true },
225+ {name : "policy with input params" , spitConfig : true , signTL : false , policyDir : LocalParamPolicy , param : "bar" },
226+ {name : "policy without expected param" , spitConfig : true , signTL : false , policyDir : LocalParamPolicy , param : "baz" , expectedNonSuccess : OutcomeFailure },
225227 }
226228
227229 attIdx , err := oci .IndexFromPath (test .UnsignedTestIndex ())
@@ -232,6 +234,11 @@ func TestSignVerify(t *testing.T) {
232234 if tc .signTL {
233235 opts .TransparencyLog = tlog .GetMockTL ()
234236 }
237+ if tc .spitConfig {
238+ // write keysYaml to config.yaml in LocalKeysPolicy.
239+ err = os .WriteFile (filepath .Join (tc .policyDir , "config.yaml" ), keysYaml , 0o600 )
240+ require .NoError (t , err )
241+ }
235242
236243 signedManifests , err := SignStatements (ctx , attIdx .Index , signer , opts )
237244 require .NoError (t , err )
@@ -254,6 +261,17 @@ func TestSignVerify(t *testing.T) {
254261 DisableTUF : true ,
255262 Debug : true ,
256263 }
264+ if tc .signTL {
265+ getTL := func (_ context.Context , _ * attestation.VerifyOptions ) (tlog.TransparencyLog , error ) {
266+ return tlog .GetMockTL (), nil
267+ }
268+ verifier , err := attestation .NewVerfier (attestation .WithLogVerifierFactory (getTL ))
269+ require .NoError (t , err )
270+ policyOpts .AttestationVerifier = verifier
271+ }
272+ if tc .param != "" {
273+ policyOpts .Parameters = policy.Parameters {"foo" : tc .param }
274+ }
257275 results , err := Verify (ctx , spec , policyOpts )
258276 require .NoError (t , err )
259277 if tc .expectedNonSuccess != "" {
0 commit comments