@@ -100,22 +100,22 @@ func TestBiscuit(t *testing.T) {
100
100
b3deser , err := Unmarshal (b3ser )
101
101
require .NoError (t , err )
102
102
103
- v3 , err := b3deser .Authorizer ( publicRoot )
103
+ v3 , err := b3deser .AuthorizerFor ( WithSingularRootPublicKey ( publicRoot ) )
104
104
require .NoError (t , err )
105
105
106
106
v3 .AddFact (Fact {Predicate : Predicate {Name : "resource" , IDs : []Term {String ("/a/file1" )}}})
107
107
v3 .AddFact (Fact {Predicate : Predicate {Name : "operation" , IDs : []Term {String ("read" )}}})
108
108
v3 .AddPolicy (DefaultAllowPolicy )
109
109
require .NoError (t , v3 .Authorize ())
110
110
111
- v3 , err = b3deser .Authorizer ( publicRoot )
111
+ v3 , err = b3deser .AuthorizerFor ( WithSingularRootPublicKey ( publicRoot ) )
112
112
require .NoError (t , err )
113
113
v3 .AddFact (Fact {Predicate : Predicate {Name : "resource" , IDs : []Term {String ("/a/file2" )}}})
114
114
v3 .AddFact (Fact {Predicate : Predicate {Name : "operation" , IDs : []Term {String ("read" )}}})
115
115
v3 .AddPolicy (DefaultAllowPolicy )
116
116
require .Error (t , v3 .Authorize ())
117
117
118
- v3 , err = b3deser .Authorizer ( publicRoot )
118
+ v3 , err = b3deser .AuthorizerFor ( WithSingularRootPublicKey ( publicRoot ) )
119
119
require .NoError (t , err )
120
120
v3 .AddFact (Fact {Predicate : Predicate {Name : "resource" , IDs : []Term {String ("/a/file1" )}}})
121
121
v3 .AddFact (Fact {Predicate : Predicate {Name : "operation" , IDs : []Term {String ("write" )}}})
@@ -176,7 +176,7 @@ func TestSealedBiscuit(t *testing.T) {
176
176
b2deser , err := Unmarshal (b2ser )
177
177
require .NoError (t , err )
178
178
179
- _ , err = b2deser .Authorizer ( publicRoot )
179
+ _ , err = b2deser .AuthorizerFor ( WithSingularRootPublicKey ( publicRoot ) )
180
180
require .NoError (t , err )
181
181
}
182
182
@@ -260,7 +260,7 @@ func TestBiscuitRules(t *testing.T) {
260
260
261
261
func verifyOwner (t * testing.T , b Biscuit , publicRoot ed25519.PublicKey , owners map [string ]bool ) {
262
262
for user , valid := range owners {
263
- v , err := b .Authorizer ( publicRoot )
263
+ v , err := b .AuthorizerFor ( WithSingularRootPublicKey ( publicRoot ) )
264
264
require .NoError (t , err )
265
265
266
266
t .Run (fmt .Sprintf ("verify owner %s" , user ), func (t * testing.T ) {
@@ -288,18 +288,31 @@ func verifyOwner(t *testing.T, b Biscuit, publicRoot ed25519.PublicKey, owners m
288
288
289
289
func TestCheckRootKey (t * testing.T ) {
290
290
rng := rand .Reader
291
+ const rootKeyID = 123
291
292
publicRoot , privateRoot , _ := ed25519 .GenerateKey (rng )
292
293
293
- builder := NewBuilder (privateRoot )
294
+ builder := NewBuilder (privateRoot , WithRootKeyID ( rootKeyID ) )
294
295
295
296
b , err := builder .Build ()
296
297
require .NoError (t , err )
297
298
298
- _ , err = b .Authorizer (publicRoot )
299
+ _ , err = b .AuthorizerFor (WithRootPublicKeys (map [uint32 ]ed25519.PublicKey {
300
+ rootKeyID : publicRoot ,
301
+ }, nil ))
299
302
require .NoError (t , err )
300
303
304
+ _ , err = b .AuthorizerFor (WithRootPublicKeys (map [uint32 ]ed25519.PublicKey {
305
+ rootKeyID + 1 : publicRoot ,
306
+ }, nil ))
307
+ require .ErrorIs (t , err , ErrNoPublicKeyAvailable )
308
+
309
+ _ , err = b .AuthorizerFor (WithRootPublicKeys (map [uint32 ]ed25519.PublicKey {
310
+ rootKeyID : nil ,
311
+ }, nil ))
312
+ require .ErrorIs (t , err , ErrNoPublicKeyAvailable )
313
+
301
314
publicNotRoot , _ , _ := ed25519 .GenerateKey (rng )
302
- _ , err = b .Authorizer ( publicNotRoot )
315
+ _ , err = b .AuthorizerFor ( WithSingularRootPublicKey ( publicNotRoot ) )
303
316
require .Equal (t , ErrInvalidSignature , err )
304
317
}
305
318
@@ -434,11 +447,11 @@ func TestBiscuitVerifyErrors(t *testing.T) {
434
447
b , err := builder .Build ()
435
448
require .NoError (t , err )
436
449
437
- _ , err = b .Authorizer ( publicRoot )
450
+ _ , err = b .AuthorizerFor ( WithSingularRootPublicKey ( publicRoot ) )
438
451
require .NoError (t , err )
439
452
440
453
publicTest , _ , _ := ed25519 .GenerateKey (rng )
441
- _ , err = b .Authorizer ( publicTest )
454
+ _ , err = b .AuthorizerFor ( WithSingularRootPublicKey ( publicTest ) )
442
455
require .Error (t , err )
443
456
}
444
457
@@ -465,7 +478,7 @@ func TestBiscuitSha256Sum(t *testing.T) {
465
478
b, err = b.Append(rng, root, blockBuilder.Build())
466
479
require.NoError(t, err)
467
480
require.Equal(t, 1, b.BlockCount())
468
-
481
+ p
469
482
h10, err := b.SHA256Sum(0)
470
483
require.NoError(t, err)
471
484
require.Equal(t, h0, h10)
@@ -591,7 +604,7 @@ func TestInvalidRuleGeneration(t *testing.T) {
591
604
require .NoError (t , err )
592
605
t .Log (b .String ())
593
606
594
- verifier , err := b .Authorizer ( publicRoot )
607
+ verifier , err := b .AuthorizerFor ( WithSingularRootPublicKey ( publicRoot ) )
595
608
require .NoError (t , err )
596
609
597
610
verifier .AddFact (Fact {Predicate : Predicate {
0 commit comments