@@ -59,17 +59,14 @@ func withKey(name string) newSimulatedTPMOption {
59
59
}
60
60
}
61
61
62
- func newSimulatedTPM (t * testing.T , caps * tpmp. Capabilities , opts ... newSimulatedTPMOption ) * tpmp.TPM {
62
+ func newSimulatedTPM (t * testing.T , opts ... newSimulatedTPMOption ) * tpmp.TPM {
63
63
t .Helper ()
64
64
tmpDir := t .TempDir ()
65
65
tpmOpts := []tpmp.NewTPMOption {
66
66
withSimulator (t ),
67
67
tpmp .WithStore (storage .NewDirstore (tmpDir )),
68
68
}
69
69
70
- if caps != nil {
71
- tpmOpts = append (tpmOpts , tpmp .WithCapabilities (caps ))
72
- }
73
70
tpm , err := tpmp .New (tpmOpts ... )
74
71
75
72
require .NoError (t , err )
@@ -97,7 +94,7 @@ func withSimulator(t *testing.T) tpmp.NewTPMOption {
97
94
}
98
95
99
96
func TestTPMKMS_CreateKey (t * testing.T ) {
100
- tpmWithAK := newSimulatedTPM (t , nil , withAK ("ak1" ))
97
+ tpmWithAK := newSimulatedTPM (t , withAK ("ak1" ))
101
98
type fields struct {
102
99
tpm * tpmp.TPM
103
100
}
@@ -442,62 +439,8 @@ func TestTPMKMS_CreateKey(t *testing.T) {
442
439
}
443
440
}
444
441
445
- func TestTPMKMS_CreateKey_Capabilities (t * testing.T ) {
446
- tpmWithNoCaps := newSimulatedTPM (t , & tpmp.Capabilities {}, withAK ("ak1" ))
447
- type fields struct {
448
- tpm * tpmp.TPM
449
- }
450
- type args struct {
451
- req * apiv1.CreateKeyRequest
452
- }
453
- tests := []struct {
454
- name string
455
- fields fields
456
- args args
457
- assertFunc assert.ValueAssertionFunc
458
- expErr error
459
- }{
460
- {
461
- name : "fail/unsupported-algorithm" ,
462
- fields : fields {
463
- tpm : tpmWithNoCaps ,
464
- },
465
- args : args {
466
- req : & apiv1.CreateKeyRequest {
467
- Name : "tpmkms:name=key1" ,
468
- SignatureAlgorithm : apiv1 .SHA256WithRSA ,
469
- Bits : 2048 ,
470
- },
471
- },
472
- assertFunc : func (tt assert.TestingT , i1 interface {}, i2 ... interface {}) bool {
473
- if assert .IsType (t , & apiv1.CreateKeyResponse {}, i1 ) {
474
- r , _ := i1 .(* apiv1.CreateKeyResponse )
475
- return assert .Nil (t , r )
476
- }
477
- return false
478
- },
479
- expErr : errors .New (`signature algorithm "SHA256-RSA" not supported by the TPM device` ),
480
- },
481
- }
482
- for _ , tt := range tests {
483
- t .Run (tt .name , func (t * testing.T ) {
484
- k := & TPMKMS {
485
- tpm : tt .fields .tpm ,
486
- }
487
- got , err := k .CreateKey (tt .args .req )
488
- if tt .expErr != nil {
489
- assert .EqualError (t , err , tt .expErr .Error ())
490
- return
491
- }
492
-
493
- assert .NoError (t , err )
494
- assert .True (t , tt .assertFunc (t , got ))
495
- })
496
- }
497
- }
498
-
499
442
func TestTPMKMS_DeleteKey (t * testing.T ) {
500
- okTPM := newSimulatedTPM (t , nil ,
443
+ okTPM := newSimulatedTPM (t ,
501
444
withAK ("ak1" ), withAK ("ak2" ),
502
445
withKey ("key1" ), withKey ("key2" ),
503
446
)
@@ -564,7 +507,7 @@ func TestTPMKMS_DeleteKey(t *testing.T) {
564
507
}
565
508
566
509
func TestTPMKMS_CreateSigner (t * testing.T ) {
567
- tpmWithKey := newSimulatedTPM (t , nil , withKey ("key1" ))
510
+ tpmWithKey := newSimulatedTPM (t , withKey ("key1" ))
568
511
569
512
key , err := tpmWithKey .GetKey (context .Background (), "key1" )
570
513
require .NoError (t , err )
@@ -725,7 +668,7 @@ func TestTPMKMS_CreateSigner(t *testing.T) {
725
668
}
726
669
727
670
func TestTPMKMS_GetPublicKey (t * testing.T ) {
728
- tpmWithKey := newSimulatedTPM (t , nil , withKey ("key1" ))
671
+ tpmWithKey := newSimulatedTPM (t , withKey ("key1" ))
729
672
_ , err := tpmWithKey .CreateAK (context .Background (), "ak1" )
730
673
require .NoError (t , err )
731
674
type fields struct {
@@ -866,7 +809,7 @@ func TestTPMKMS_GetPublicKey(t *testing.T) {
866
809
867
810
func TestTPMKMS_LoadCertificate (t * testing.T ) {
868
811
ctx := context .Background ()
869
- tpm := newSimulatedTPM (t , nil )
812
+ tpm := newSimulatedTPM (t )
870
813
config := tpmp.CreateKeyConfig {
871
814
Algorithm : "RSA" ,
872
815
Size : 1024 ,
@@ -1031,7 +974,7 @@ func TestTPMKMS_LoadCertificate(t *testing.T) {
1031
974
1032
975
func TestTPMKMS_LoadCertificateChain (t * testing.T ) {
1033
976
ctx := context .Background ()
1034
- tpm := newSimulatedTPM (t , nil )
977
+ tpm := newSimulatedTPM (t )
1035
978
config := tpmp.CreateKeyConfig {
1036
979
Algorithm : "RSA" ,
1037
980
Size : 1024 ,
@@ -1202,7 +1145,7 @@ func TestTPMKMS_LoadCertificateChain(t *testing.T) {
1202
1145
1203
1146
func TestTPMKMS_StoreCertificate (t * testing.T ) {
1204
1147
ctx := context .Background ()
1205
- tpm := newSimulatedTPM (t , nil )
1148
+ tpm := newSimulatedTPM (t )
1206
1149
config := tpmp.CreateKeyConfig {
1207
1150
Algorithm : "RSA" ,
1208
1151
Size : 1024 ,
@@ -1372,7 +1315,7 @@ func TestTPMKMS_StoreCertificate(t *testing.T) {
1372
1315
1373
1316
func TestTPMKMS_StoreCertificateChain (t * testing.T ) {
1374
1317
ctx := context .Background ()
1375
- tpm := newSimulatedTPM (t , nil )
1318
+ tpm := newSimulatedTPM (t )
1376
1319
config := tpmp.CreateKeyConfig {
1377
1320
Algorithm : "RSA" ,
1378
1321
Size : 1024 ,
@@ -1601,7 +1544,7 @@ func (c *customAttestationClient) Attest(context.Context) ([]*x509.Certificate,
1601
1544
1602
1545
func TestTPMKMS_CreateAttestation (t * testing.T ) {
1603
1546
ctx := context .Background ()
1604
- tpm := newSimulatedTPM (t , nil )
1547
+ tpm := newSimulatedTPM (t )
1605
1548
eks , err := tpm .GetEKs (ctx )
1606
1549
require .NoError (t , err )
1607
1550
ek := getPreferredEK (eks )
@@ -2192,7 +2135,7 @@ func Test_hasValidIdentity(t *testing.T) {
2192
2135
identityRenewalPeriodPercentage : 60 ,
2193
2136
}
2194
2137
ctx := context .Background ()
2195
- tpm := newSimulatedTPM (t , nil )
2138
+ tpm := newSimulatedTPM (t )
2196
2139
eks , err := tpm .GetEKs (ctx )
2197
2140
require .NoError (t , err )
2198
2141
ek := getPreferredEK (eks )
0 commit comments