@@ -307,7 +307,7 @@ func TestMacKMS_GetPublicKey(t *testing.T) {
307
307
308
308
// Create private keys only
309
309
r2 := createPrivateKeyOnly (t , "mackms:label=test-ecdsa" , apiv1 .ECDSAWithSHA256 )
310
- r3 := createPrivateKeyOnly (t , "mackms:label=test-rsa" , apiv1 .SHA256WithRSA )
310
+ r3 := createPrivateKeyOnly (t , "mackms:label=test-rsa;tag= " , apiv1 .SHA256WithRSA )
311
311
312
312
t .Cleanup (func () {
313
313
assert .NoError (t , kms .DeleteKey (& apiv1.DeleteKeyRequest {
@@ -334,7 +334,8 @@ func TestMacKMS_GetPublicKey(t *testing.T) {
334
334
{"ok" , & MacKMS {}, args {& apiv1.GetPublicKeyRequest {Name : r1 .Name }}, r1 .PublicKey , assert .NoError },
335
335
{"ok no tag" , & MacKMS {}, args {& apiv1.GetPublicKeyRequest {Name : "mackms:label=test-p256;tag=" }}, r1 .PublicKey , assert .NoError },
336
336
{"ok private only ECDSA " , & MacKMS {}, args {& apiv1.GetPublicKeyRequest {Name : "mackms:label=test-ecdsa" }}, r2 .PublicKey , assert .NoError },
337
- {"ok private only RSA " , & MacKMS {}, args {& apiv1.GetPublicKeyRequest {Name : r3 .Name }}, r3 .PublicKey , assert .NoError },
337
+ {"ok private only RSA" , & MacKMS {}, args {& apiv1.GetPublicKeyRequest {Name : r3 .Name }}, r3 .PublicKey , assert .NoError },
338
+ {"ok private only RSA with retry" , & MacKMS {}, args {& apiv1.GetPublicKeyRequest {Name : "mackms:label=test-rsa" }}, r3 .PublicKey , assert .NoError },
338
339
{"ok no uri" , & MacKMS {}, args {& apiv1.GetPublicKeyRequest {Name : "test-p256" }}, r1 .PublicKey , assert .NoError },
339
340
{"ok uri simple" , & MacKMS {}, args {& apiv1.GetPublicKeyRequest {Name : "mackms:test-p256" }}, r1 .PublicKey , assert .NoError },
340
341
{"ok uri label" , & MacKMS {}, args {& apiv1.GetPublicKeyRequest {Name : "mackms:label=test-p256" }}, r1 .PublicKey , assert .NoError },
@@ -541,11 +542,12 @@ func Test_parseURI(t *testing.T) {
541
542
assertion assert.ErrorAssertionFunc
542
543
}{
543
544
{"ok" , args {"mackms:label=the-label;tag=the-tag;hash=0102abcd" }, & keyAttributes {label : "the-label" , tag : "the-tag" , hash : []byte {1 , 2 , 171 , 205 }}, assert .NoError },
544
- {"ok label" , args {"the-label" }, & keyAttributes {label : "the-label" , tag : DefaultTag }, assert .NoError },
545
- {"ok label uri" , args {"mackms:label=the-label" }, & keyAttributes {label : "the-label" , tag : DefaultTag }, assert .NoError },
545
+ {"ok label" , args {"the-label" }, & keyAttributes {label : "the-label" , tag : DefaultTag , retry : true }, assert .NoError },
546
+ {"ok label uri" , args {"mackms:label=the-label" }, & keyAttributes {label : "the-label" , tag : DefaultTag , retry : true }, assert .NoError },
547
+ {"ok label uri simple" , args {"mackms:the-label" }, & keyAttributes {label : "the-label" , tag : DefaultTag , retry : true }, assert .NoError },
546
548
{"ok label empty tag" , args {"mackms:label=the-label;tag=" }, & keyAttributes {label : "the-label" , tag : "" }, assert .NoError },
547
549
{"ok label empty tag no equal" , args {"mackms:label=the-label;tag" }, & keyAttributes {label : "the-label" , tag : "" }, assert .NoError },
548
- {"fail parse" , args {"mackms::: label=the-label" }, nil , assert .Error },
550
+ {"fail parse" , args {"mackms:% label=the-label" }, nil , assert .Error },
549
551
{"fail missing label" , args {"mackms:hash=0102abcd" }, nil , assert .Error },
550
552
}
551
553
for _ , tt := range tests {
@@ -1306,3 +1308,58 @@ func TestMacKMS_SearchKeys(t *testing.T) {
1306
1308
1307
1309
assert .Equal (t , expectedHashes , hashes )
1308
1310
}
1311
+
1312
+ func Test_keyAttributes_retryAttributes (t * testing.T ) {
1313
+ type fields struct {
1314
+ label string
1315
+ tag string
1316
+ hash []byte
1317
+ retry bool
1318
+ }
1319
+
1320
+ mustFields := func (s string ) fields {
1321
+ t .Helper ()
1322
+ u , err := parseURI (s )
1323
+ require .NoError (t , err )
1324
+ return fields {
1325
+ label : u .label ,
1326
+ tag : u .tag ,
1327
+ hash : u .hash ,
1328
+ retry : u .retry ,
1329
+ }
1330
+ }
1331
+
1332
+ tests := []struct {
1333
+ name string
1334
+ fields fields
1335
+ want * keyAttributes
1336
+ }{
1337
+ {"with tag" , mustFields ("mackms:label=label;tag=tag" ), nil },
1338
+ {"with tag and hash" , mustFields ("mackms:label=label;hash=FF00;tag=tag" ), nil },
1339
+ {"with empty tag" , mustFields ("mackms:label=label;tag=" ), nil },
1340
+ {"with no tag" , mustFields ("mackms:label=label;hash=FF00" ), & keyAttributes {
1341
+ label : "label" ,
1342
+ hash : []byte {0xFF , 0x00 },
1343
+ }},
1344
+ {"legacy name only" , mustFields ("label" ), & keyAttributes {
1345
+ label : "label" ,
1346
+ }},
1347
+ {"legacy with schema" , mustFields ("mackms:label" ), & keyAttributes {
1348
+ label : "label" ,
1349
+ }},
1350
+ }
1351
+ for _ , tt := range tests {
1352
+ t .Run (tt .name , func (t * testing.T ) {
1353
+ k := & keyAttributes {
1354
+ label : tt .fields .label ,
1355
+ tag : tt .fields .tag ,
1356
+ hash : tt .fields .hash ,
1357
+ retry : tt .fields .retry ,
1358
+ }
1359
+ if tt .name == "with no tag" {
1360
+ t .Log ("foo" )
1361
+ }
1362
+ assert .Equal (t , tt .want , k .retryAttributes ())
1363
+ })
1364
+ }
1365
+ }
0 commit comments