@@ -49,7 +49,7 @@ func recordFromJSON(data string) *ksm.Record {
49
49
50
50
func TestKeeperSecretsManager_GetSecrets (t * testing.T ) {
51
51
type args struct {
52
- data string
52
+ records [] string
53
53
}
54
54
tests := []struct {
55
55
name string
@@ -60,7 +60,8 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
60
60
{
61
61
name : "should handle a secret of type login" ,
62
62
args : args {
63
- data : `{
63
+ records : []string {`
64
+ {
64
65
"uid": "some-uid",
65
66
"title": "some-title",
66
67
"type": "login",
@@ -98,6 +99,7 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
98
99
"custom": [],
99
100
"files": []
100
101
}` ,
102
+ },
101
103
},
102
104
want : map [string ]interface {}{
103
105
"login" : "some-secret-username" ,
@@ -107,7 +109,7 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
107
109
{
108
110
name : "should handle a secret of type databaseCredentials" ,
109
111
args : args {
110
- data : `
112
+ records : [] string { `
111
113
{
112
114
"uid": "some-uid",
113
115
"title": "some-title",
@@ -153,6 +155,7 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
153
155
"custom": [],
154
156
"files": []
155
157
}` ,
158
+ },
156
159
},
157
160
want : map [string ]interface {}{
158
161
"host" : map [string ]interface {}{
@@ -167,7 +170,7 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
167
170
{
168
171
name : "should handle a secret of type encryptedNotes" ,
169
172
args : args {
170
- data : `
173
+ records : [] string { `
171
174
{
172
175
"uid": "some-uid",
173
176
"title": "some-title",
@@ -194,6 +197,7 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
194
197
"custom": [],
195
198
"files": []
196
199
}` ,
200
+ },
197
201
},
198
202
want : map [string ]interface {}{
199
203
"note" : "some-value" ,
@@ -202,7 +206,7 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
202
206
{
203
207
name : "should handle a secret with custom fields" ,
204
208
args : args {
205
- data : `
209
+ records : [] string { `
206
210
{
207
211
"uid": "some-uid",
208
212
"title": "some-title",
@@ -237,6 +241,7 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
237
241
],
238
242
"files": []
239
243
}` ,
244
+ },
240
245
},
241
246
want : map [string ]interface {}{
242
247
"note" : "some-value" ,
@@ -246,7 +251,7 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
246
251
{
247
252
name : "should not overwrite a built in field when a custom field of the same label exists" ,
248
253
args : args {
249
- data : `
254
+ records : [] string { `
250
255
{
251
256
"uid": "some-uid",
252
257
"title": "some-title",
@@ -281,6 +286,7 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
281
286
],
282
287
"files": []
283
288
}` ,
289
+ },
284
290
},
285
291
want : map [string ]interface {}{
286
292
"note" : "some-value" ,
@@ -289,7 +295,7 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
289
295
{
290
296
name : "should omit fields that have multiple values" ,
291
297
args : args {
292
- data : `
298
+ records : [] string { `
293
299
{
294
300
"uid": "some-uid",
295
301
"title": "some-title",
@@ -324,6 +330,7 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
324
330
"custom": [],
325
331
"files": []
326
332
}` ,
333
+ },
327
334
},
328
335
want : map [string ]interface {}{
329
336
"note" : "some-value" ,
@@ -333,7 +340,7 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
333
340
{
334
341
name : "should omit fields that don't have a value" ,
335
342
args : args {
336
- data : `
343
+ records : [] string { `
337
344
{
338
345
"uid": "some-uid",
339
346
"title": "some-title",
@@ -364,6 +371,7 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
364
371
"custom": [],
365
372
"files": []
366
373
}` ,
374
+ },
367
375
},
368
376
want : map [string ]interface {}{
369
377
"note" : "some-value" ,
@@ -372,7 +380,7 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
372
380
{
373
381
name : "should omit fields that don't have a type" ,
374
382
args : args {
375
- data : `
383
+ records : [] string { `
376
384
{
377
385
"uid": "some-uid",
378
386
"title": "some-title",
@@ -405,6 +413,7 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
405
413
"custom": [],
406
414
"files": []
407
415
}` ,
416
+ },
408
417
},
409
418
want : map [string ]interface {}{
410
419
"note" : "some-value" ,
@@ -413,7 +422,7 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
413
422
{
414
423
name : "should omit fields that don't have a label or type" ,
415
424
args : args {
416
- data : `
425
+ records : [] string { `
417
426
{
418
427
"uid": "some-uid",
419
428
"title": "some-title",
@@ -445,6 +454,7 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
445
454
"custom": [],
446
455
"files": []
447
456
}` ,
457
+ },
448
458
},
449
459
want : map [string ]interface {}{
450
460
"note" : "some-value" ,
@@ -453,7 +463,7 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
453
463
{
454
464
name : "should omit fields that don't have a value that is not a slice" ,
455
465
args : args {
456
- data : `
466
+ records : [] string { `
457
467
{
458
468
"uid": "some-uid",
459
469
"title": "some-title",
@@ -485,21 +495,113 @@ func TestKeeperSecretsManager_GetSecrets(t *testing.T) {
485
495
"custom": [],
486
496
"files": []
487
497
}` ,
498
+ },
488
499
},
489
500
want : map [string ]interface {}{
490
501
"note" : "some-value" ,
491
502
},
492
503
},
504
+
505
+ {
506
+ name : "should handle multiple records with the same uid" ,
507
+ args : args {
508
+ records : []string {`
509
+ {
510
+ "uid": "some-uid",
511
+ "title": "some-title",
512
+ "type": "login",
513
+ "fields": [
514
+ {
515
+ "label": "login",
516
+ "type": "login",
517
+ "value": [
518
+ "some-secret-username"
519
+ ]
520
+ },
521
+ {
522
+ "label": "password",
523
+ "type": "password",
524
+ "value": [
525
+ "some-secret-password"
526
+ ]
527
+ },
528
+ {
529
+ "label": "url",
530
+ "type": "url",
531
+ "value": []
532
+ },
533
+ {
534
+ "label": "fileRef",
535
+ "type": "fileRef",
536
+ "value": []
537
+ },
538
+ {
539
+ "label": "oneTimeCode",
540
+ "type": "oneTimeCode",
541
+ "value": []
542
+ }
543
+ ],
544
+ "custom": [],
545
+ "files": []
546
+ }` , `
547
+ {
548
+ "uid": "some-uid",
549
+ "title": "some-title",
550
+ "type": "login",
551
+ "fields": [
552
+ {
553
+ "label": "login",
554
+ "type": "login",
555
+ "value": [
556
+ "some-secret-username"
557
+ ]
558
+ },
559
+ {
560
+ "label": "password",
561
+ "type": "password",
562
+ "value": [
563
+ "some-secret-password"
564
+ ]
565
+ },
566
+ {
567
+ "label": "url",
568
+ "type": "url",
569
+ "value": []
570
+ },
571
+ {
572
+ "label": "fileRef",
573
+ "type": "fileRef",
574
+ "value": []
575
+ },
576
+ {
577
+ "label": "oneTimeCode",
578
+ "type": "oneTimeCode",
579
+ "value": []
580
+ }
581
+ ],
582
+ "custom": [],
583
+ "files": []
584
+ }` ,
585
+ },
586
+ },
587
+ want : map [string ]interface {}{
588
+ "login" : "some-secret-username" ,
589
+ "password" : "some-secret-password" ,
590
+ },
591
+ },
493
592
}
494
593
for _ , tt := range tests {
495
594
t .Run (tt .name , func (t * testing.T ) {
595
+ records := make ([]* ksm.Record , len (tt .args .records ))
596
+ for i , recordStr := range tt .args .records {
597
+ records [i ] = recordFromJSON (recordStr )
598
+ }
599
+
496
600
a := backends .NewKeeperSecretsManagerBackend (
497
601
MockKeeperClient {
498
602
mocks : map [string ]mockResults {
499
603
"path" : {
500
- Records : []* ksm.Record {
501
- recordFromJSON (tt .args .data ),
502
- },
604
+ Records : records ,
503
605
},
504
606
},
505
607
},
0 commit comments