@@ -17,6 +17,7 @@ import (
17
17
18
18
"github.com/cenkalti/backoff/v4"
19
19
"github.com/gruntwork-io/terratest/modules/terraform"
20
+ "github.com/hashicorp/vault/sdk/helper/pointerutil"
20
21
"github.com/stretchr/testify/assert"
21
22
"github.com/stretchr/testify/require"
22
23
corev1 "k8s.io/api/core/v1"
@@ -215,7 +216,7 @@ func TestVaultStaticSecret(t *testing.T) {
215
216
Name : "secretkv" ,
216
217
Create : false ,
217
218
},
218
- HMACSecretData : true ,
219
+ HMACSecretData : pointerutil . BoolPtr ( true ) ,
219
220
RefreshAfter : "5s" ,
220
221
RolloutRestartTargets : []secretsv1beta1.RolloutRestartTarget {
221
222
{
@@ -243,7 +244,7 @@ func TestVaultStaticSecret(t *testing.T) {
243
244
Create : false ,
244
245
},
245
246
RefreshAfter : "5s" ,
246
- HMACSecretData : false ,
247
+ HMACSecretData : pointerutil . BoolPtr ( false ) ,
247
248
},
248
249
},
249
250
}
@@ -343,8 +344,23 @@ func TestVaultStaticSecret(t *testing.T) {
343
344
assertSync := func (t * testing.T , obj * secretsv1beta1.VaultStaticSecret , expected expectedData , expectInitial bool ) {
344
345
var data map [string ]interface {}
345
346
if expectInitial {
347
+ require .Empty (t , obj .UID ,
348
+ "obj %s has UID %s, expected empty" , obj .Name , obj .UID )
349
+ var expectSpecHMACData * bool
350
+ if obj .Spec .HMACSecretData == nil {
351
+ // default value as defined in the CRD schema
352
+ expectSpecHMACData = pointerutil .BoolPtr (true )
353
+ } else if * obj .Spec .HMACSecretData {
354
+ // explicitly set to true
355
+ expectSpecHMACData = pointerutil .BoolPtr (true )
356
+ } else {
357
+ // explicitly set to false
358
+ expectSpecHMACData = pointerutil .BoolPtr (false )
359
+ }
346
360
putKV (t , obj , expected .initial )
347
361
require .NoError (t , crdClient .Create (ctx , obj ))
362
+ require .Equal (t , obj .Spec .HMACSecretData , expectSpecHMACData ,
363
+ "expected initial value for spec.hmacSecretData to be honoured after apply" )
348
364
data = expected .initial
349
365
} else {
350
366
putKV (t , obj , expected .update )
@@ -360,7 +376,7 @@ func TestVaultStaticSecret(t *testing.T) {
360
376
obj .ObjectMeta .Namespace , data )
361
377
if assert .NoError (t , err ) {
362
378
assertSyncableSecret (t , crdClient , obj , secret )
363
- if obj .Spec .HMACSecretData {
379
+ if obj .Spec .HMACSecretData != nil && * obj . Spec . HMACSecretData {
364
380
assertHMAC (t , ctx , crdClient , obj , expectInitial )
365
381
} else {
366
382
assertNoHMAC (t , obj )
@@ -444,7 +460,7 @@ func TestVaultStaticSecret(t *testing.T) {
444
460
Create : true ,
445
461
},
446
462
RefreshAfter : "5s" ,
447
- HMACSecretData : true ,
463
+ HMACSecretData : pointerutil . BoolPtr ( true ) ,
448
464
},
449
465
}
450
466
if tt .version != 0 {
0 commit comments