@@ -96,22 +96,22 @@ func TestBiscuit(t *testing.T) {
96
96
b3deser , err := Unmarshal (b3ser )
97
97
require .NoError (t , err )
98
98
99
- v3 , err := b3deser .Authorizer ( publicRoot )
99
+ v3 , err := b3deser .AuthorizerFor ( WithSingularRootPublicKey ( publicRoot ) )
100
100
require .NoError (t , err )
101
101
102
102
v3 .AddFact (Fact {Predicate : Predicate {Name : "resource" , IDs : []Term {String ("/a/file1" )}}})
103
103
v3 .AddFact (Fact {Predicate : Predicate {Name : "operation" , IDs : []Term {String ("read" )}}})
104
104
v3 .AddPolicy (DefaultAllowPolicy )
105
105
require .NoError (t , v3 .Authorize ())
106
106
107
- v3 , err = b3deser .Authorizer ( publicRoot )
107
+ v3 , err = b3deser .AuthorizerFor ( WithSingularRootPublicKey ( publicRoot ) )
108
108
require .NoError (t , err )
109
109
v3 .AddFact (Fact {Predicate : Predicate {Name : "resource" , IDs : []Term {String ("/a/file2" )}}})
110
110
v3 .AddFact (Fact {Predicate : Predicate {Name : "operation" , IDs : []Term {String ("read" )}}})
111
111
v3 .AddPolicy (DefaultAllowPolicy )
112
112
require .Error (t , v3 .Authorize ())
113
113
114
- v3 , err = b3deser .Authorizer ( publicRoot )
114
+ v3 , err = b3deser .AuthorizerFor ( WithSingularRootPublicKey ( publicRoot ) )
115
115
require .NoError (t , err )
116
116
v3 .AddFact (Fact {Predicate : Predicate {Name : "resource" , IDs : []Term {String ("/a/file1" )}}})
117
117
v3 .AddFact (Fact {Predicate : Predicate {Name : "operation" , IDs : []Term {String ("write" )}}})
@@ -172,7 +172,7 @@ func TestSealedBiscuit(t *testing.T) {
172
172
b2deser , err := Unmarshal (b2ser )
173
173
require .NoError (t , err )
174
174
175
- _ , err = b2deser .Authorizer ( publicRoot )
175
+ _ , err = b2deser .AuthorizerFor ( WithSingularRootPublicKey ( publicRoot ) )
176
176
require .NoError (t , err )
177
177
}
178
178
@@ -256,7 +256,7 @@ func TestBiscuitRules(t *testing.T) {
256
256
257
257
func verifyOwner (t * testing.T , b Biscuit , publicRoot ed25519.PublicKey , owners map [string ]bool ) {
258
258
for user , valid := range owners {
259
- v , err := b .Authorizer ( publicRoot )
259
+ v , err := b .AuthorizerFor ( WithSingularRootPublicKey ( publicRoot ) )
260
260
require .NoError (t , err )
261
261
262
262
t .Run (fmt .Sprintf ("verify owner %s" , user ), func (t * testing.T ) {
@@ -284,18 +284,31 @@ func verifyOwner(t *testing.T, b Biscuit, publicRoot ed25519.PublicKey, owners m
284
284
285
285
func TestCheckRootKey (t * testing.T ) {
286
286
rng := rand .Reader
287
+ const rootKeyID = 123
287
288
publicRoot , privateRoot , _ := ed25519 .GenerateKey (rng )
288
289
289
- builder := NewBuilder (privateRoot )
290
+ builder := NewBuilder (privateRoot , WithRootKeyID ( rootKeyID ) )
290
291
291
292
b , err := builder .Build ()
292
293
require .NoError (t , err )
293
294
294
- _ , err = b .Authorizer (publicRoot )
295
+ _ , err = b .AuthorizerFor (WithRootPublicKeys (map [uint32 ]ed25519.PublicKey {
296
+ rootKeyID : publicRoot ,
297
+ }, nil ))
295
298
require .NoError (t , err )
296
299
300
+ _ , err = b .AuthorizerFor (WithRootPublicKeys (map [uint32 ]ed25519.PublicKey {
301
+ rootKeyID + 1 : publicRoot ,
302
+ }, nil ))
303
+ require .ErrorIs (t , err , ErrNoPublicKeyAvailable )
304
+
305
+ _ , err = b .AuthorizerFor (WithRootPublicKeys (map [uint32 ]ed25519.PublicKey {
306
+ rootKeyID : nil ,
307
+ }, nil ))
308
+ require .ErrorIs (t , err , ErrNoPublicKeyAvailable )
309
+
297
310
publicNotRoot , _ , _ := ed25519 .GenerateKey (rng )
298
- _ , err = b .Authorizer ( publicNotRoot )
311
+ _ , err = b .AuthorizerFor ( WithSingularRootPublicKey ( publicNotRoot ) )
299
312
require .Equal (t , ErrInvalidSignature , err )
300
313
}
301
314
@@ -430,11 +443,11 @@ func TestBiscuitVerifyErrors(t *testing.T) {
430
443
b , err := builder .Build ()
431
444
require .NoError (t , err )
432
445
433
- _ , err = b .Authorizer ( publicRoot )
446
+ _ , err = b .AuthorizerFor ( WithSingularRootPublicKey ( publicRoot ) )
434
447
require .NoError (t , err )
435
448
436
449
publicTest , _ , _ := ed25519 .GenerateKey (rng )
437
- _ , err = b .Authorizer ( publicTest )
450
+ _ , err = b .AuthorizerFor ( WithSingularRootPublicKey ( publicTest ) )
438
451
require .Error (t , err )
439
452
}
440
453
@@ -461,7 +474,7 @@ func TestBiscuitSha256Sum(t *testing.T) {
461
474
b, err = b.Append(rng, root, blockBuilder.Build())
462
475
require.NoError(t, err)
463
476
require.Equal(t, 1, b.BlockCount())
464
-
477
+ p
465
478
h10, err := b.SHA256Sum(0)
466
479
require.NoError(t, err)
467
480
require.Equal(t, h0, h10)
@@ -587,7 +600,7 @@ func TestInvalidRuleGeneration(t *testing.T) {
587
600
require .NoError (t , err )
588
601
t .Log (b .String ())
589
602
590
- verifier , err := b .Authorizer ( publicRoot )
603
+ verifier , err := b .AuthorizerFor ( WithSingularRootPublicKey ( publicRoot ) )
591
604
require .NoError (t , err )
592
605
593
606
verifier .AddFact (Fact {Predicate : Predicate {
0 commit comments