@@ -57,91 +57,116 @@ func TestVerificationPolicyInherit(t *testing.T) {
5757
5858 globalIDs , err := toComponentIdentifiers ([]string {"@method" , "content-digest" })
5959 require .NoError (t , err )
60+ localIDs , err := toComponentIdentifiers ([]string {"@status" })
61+ require .NoError (t , err )
6062
61- required := true
63+ localBuilder := & AcceptSignatureBuilder { label : "custom" }
6264 global := & verificationPolicy {
6365 tolerance : new (2 * time.Second ),
6466 maxAge : new (30 * time.Second ),
6567 identifiers : globalIDs ,
66- reqCreatedTS : & required ,
67- reqExpiresTS : & required ,
68+ reqCreatedTS : new ( true ) ,
69+ reqExpiresTS : new ( true ) ,
6870 asb : & AcceptSignatureBuilder {label : "sig" },
6971 requiredParameters : []SignatureParameter {Nonce },
7072 forbiddenParameters : []SignatureParameter {Alg },
7173 expectedParameters : []parameterOption {{name : "audience" , value : "service-a" }},
7274 }
7375
74- t .Run ("inherits global configuration" , func (t * testing.T ) {
75- t .Parallel ()
76-
77- local := & verificationPolicy {}
78- require .NoError (t , local .inherit (global , "profile" ))
79-
80- assert .Equal (t , global .tolerance , local .tolerance )
81- assert .Equal (t , global .maxAge , local .maxAge )
82- assert .Equal (t , global .identifiers , local .identifiers )
83- assert .Equal (t , global .reqCreatedTS , local .reqCreatedTS )
84- assert .Equal (t , global .reqExpiresTS , local .reqExpiresTS )
85- assert .Equal (t , global .requiredParameters , local .requiredParameters )
86- assert .Equal (t , global .forbiddenParameters , local .forbiddenParameters )
87- assert .Equal (t , global .expectedParameters , local .expectedParameters )
88-
89- require .NotSame (t , global .asb , local .asb )
90- assert .Equal (t , "profile" , local .asb .tag )
91- assert .Empty (t , global .asb .tag )
92- assert .True (t , local .asb .wantContentDigest )
93- assert .True (t , local .asb .addCreatedTS )
94- assert .True (t , local .asb .addExpiresTS )
95- })
96-
97- t .Run ("keeps local overrides" , func (t * testing.T ) {
98- t .Parallel ()
99-
100- created := false
101- expires := false
102- localIDs , err := toComponentIdentifiers ([]string {"@status" })
103- require .NoError (t , err )
104-
105- localBuilder := & AcceptSignatureBuilder {label : "custom" }
106- local := & verificationPolicy {
107- tolerance : new (time.Second ),
108- maxAge : new (5 * time.Second ),
109- identifiers : localIDs ,
110- reqCreatedTS : & created ,
111- reqExpiresTS : & expires ,
112- asb : localBuilder ,
113- }
114- require .NoError (t , local .inherit (global , "profile" ))
115-
116- require .NotNil (t , local .tolerance )
117- assert .Equal (t , time .Second , * local .tolerance )
118- require .NotNil (t , local .maxAge )
119- assert .Equal (t , 5 * time .Second , * local .maxAge )
120- assert .Equal (t , localIDs , local .identifiers )
121- assert .False (t , * local .reqCreatedTS )
122- assert .False (t , * local .reqExpiresTS )
123- assert .Same (t , localBuilder , local .asb )
124- assert .Equal (t , "custom" , local .asb .label )
125- assert .False (t , local .asb .wantContentDigest )
126- assert .False (t , local .asb .addCreatedTS )
127- assert .False (t , local .asb .addExpiresTS )
128- })
129-
130- for uc , local := range map [string ]verificationPolicy {
76+ for uc , tc := range map [string ]struct {
77+ local * verificationPolicy
78+ assert func (t * testing.T , err error , local * verificationPolicy )
79+ }{
80+ "inherits global configuration" : {
81+ local : & verificationPolicy {},
82+ assert : func (t * testing.T , err error , local * verificationPolicy ) {
83+ t .Helper ()
84+
85+ require .NoError (t , err )
86+ assert .Equal (t , global .tolerance , local .tolerance )
87+ assert .Equal (t , global .maxAge , local .maxAge )
88+ assert .Equal (t , global .identifiers , local .identifiers )
89+ assert .Equal (t , global .reqCreatedTS , local .reqCreatedTS )
90+ assert .Equal (t , global .reqExpiresTS , local .reqExpiresTS )
91+ assert .Equal (t , global .requiredParameters , local .requiredParameters )
92+ assert .Equal (t , global .forbiddenParameters , local .forbiddenParameters )
93+ assert .Equal (t , global .expectedParameters , local .expectedParameters )
94+
95+ require .NotSame (t , global .asb , local .asb )
96+ assert .Equal (t , "profile" , local .asb .tag )
97+ assert .Empty (t , global .asb .tag )
98+ assert .True (t , local .asb .wantContentDigest )
99+ assert .True (t , local .asb .addCreatedTS )
100+ assert .True (t , local .asb .addExpiresTS )
101+ },
102+ },
103+ "keeps local overrides" : {
104+ local : & verificationPolicy {
105+ tolerance : new (time.Second ),
106+ maxAge : new (5 * time.Second ),
107+ identifiers : localIDs ,
108+ reqCreatedTS : new (false ),
109+ reqExpiresTS : new (false ),
110+ asb : localBuilder ,
111+ },
112+ assert : func (t * testing.T , err error , local * verificationPolicy ) {
113+ t .Helper ()
114+
115+ require .NoError (t , err )
116+ require .NotNil (t , local .tolerance )
117+ assert .Equal (t , time .Second , * local .tolerance )
118+ require .NotNil (t , local .maxAge )
119+ assert .Equal (t , 5 * time .Second , * local .maxAge )
120+ assert .Equal (t , localIDs , local .identifiers )
121+ assert .False (t , * local .reqCreatedTS )
122+ assert .False (t , * local .reqExpiresTS )
123+ assert .Same (t , localBuilder , local .asb )
124+ assert .Equal (t , "custom" , local .asb .label )
125+ assert .False (t , local .asb .wantContentDigest )
126+ assert .False (t , local .asb .addCreatedTS )
127+ assert .False (t , local .asb .addExpiresTS )
128+ },
129+ },
130+ "local disablement overrides global max age" : {
131+ local : & verificationPolicy {maxAge : new (time.Duration )},
132+ assert : func (t * testing.T , err error , local * verificationPolicy ) {
133+ t .Helper ()
134+
135+ require .NoError (t , err )
136+ require .NotNil (t , local .maxAge )
137+ assert .Zero (t , * local .maxAge )
138+ },
139+ },
131140 "local requirement conflicts with global prohibition" : {
132- requiredParameters : []SignatureParameter {Alg },
141+ local : & verificationPolicy {requiredParameters : []SignatureParameter {Alg }},
142+ assert : func (t * testing.T , err error , _ * verificationPolicy ) {
143+ t .Helper ()
144+
145+ require .ErrorIs (t , err , ErrParameter )
146+ },
133147 },
134148 "local prohibition conflicts with global required parameter" : {
135- forbiddenParameters : []SignatureParameter {Nonce },
149+ local : & verificationPolicy {forbiddenParameters : []SignatureParameter {Nonce }},
150+ assert : func (t * testing.T , err error , _ * verificationPolicy ) {
151+ t .Helper ()
152+
153+ require .ErrorIs (t , err , ErrParameter )
154+ },
136155 },
137156 "local value conflicts with global expectation" : {
138- expectedParameters : []parameterOption {{name : "audience" , value : "other" }},
157+ local : & verificationPolicy {expectedParameters : []parameterOption {{name : "audience" , value : "other" }}},
158+ assert : func (t * testing.T , err error , _ * verificationPolicy ) {
159+ t .Helper ()
160+
161+ require .ErrorIs (t , err , ErrParameter )
162+ },
139163 },
140164 } {
141165 t .Run (uc , func (t * testing.T ) {
142166 t .Parallel ()
143167
144- require .ErrorIs (t , local .inherit (global , "profile" ), ErrParameter )
168+ err := tc .local .inherit (global , "profile" )
169+ tc .assert (t , err , tc .local )
145170 })
146171 }
147172}
@@ -294,6 +319,69 @@ func TestVerificationPolicyAssertMetadata(t *testing.T) {
294319 require .ErrorContains (t , err , "too old" )
295320 },
296321 },
322+ "old signature accepted without max age" : {
323+ params : httpsfv.InnerList {
324+ Params : func () * httpsfv.Params {
325+ params := httpsfv .NewParams ()
326+ params .Add (string (Created ), now .Add (- 2 * time .Minute ).Unix ())
327+
328+ return params
329+ }(),
330+ },
331+ exp : verificationPolicy {
332+ maxAge : new (time.Duration ),
333+ reqCreatedTS : & falseVal ,
334+ reqExpiresTS : & falseVal ,
335+ },
336+ assert : func (t * testing.T , err error ) {
337+ t .Helper ()
338+
339+ require .NoError (t , err )
340+ },
341+ },
342+ "future created rejected without max age" : {
343+ params : httpsfv.InnerList {
344+ Params : func () * httpsfv.Params {
345+ params := httpsfv .NewParams ()
346+ params .Add (string (Created ), now .Add (2 * time .Minute ).Unix ())
347+
348+ return params
349+ }(),
350+ },
351+ exp : verificationPolicy {
352+ maxAge : new (time.Duration ),
353+ reqCreatedTS : & falseVal ,
354+ reqExpiresTS : & falseVal ,
355+ },
356+ assert : func (t * testing.T , err error ) {
357+ t .Helper ()
358+
359+ require .ErrorIs (t , err , ErrValidity )
360+ require .ErrorContains (t , err , "not yet valid" )
361+ },
362+ },
363+ "expired signature rejected without max age" : {
364+ params : httpsfv.InnerList {
365+ Params : func () * httpsfv.Params {
366+ params := httpsfv .NewParams ()
367+ params .Add (string (Created ), now .Add (- 3 * time .Minute ).Unix ())
368+ params .Add (string (Expires ), now .Add (- 2 * time .Minute ).Unix ())
369+
370+ return params
371+ }(),
372+ },
373+ exp : verificationPolicy {
374+ maxAge : new (time.Duration ),
375+ reqCreatedTS : & falseVal ,
376+ reqExpiresTS : & falseVal ,
377+ },
378+ assert : func (t * testing.T , err error ) {
379+ t .Helper ()
380+
381+ require .ErrorIs (t , err , ErrValidity )
382+ require .ErrorContains (t , err , "expired" )
383+ },
384+ },
297385 "expected component identifier has different parameter value" : {
298386 params : httpsfv.InnerList {
299387 Items : []httpsfv.Item {{
0 commit comments