@@ -24,35 +24,6 @@ describe('Bootstrapping values', () => {
24
24
}
25
25
const users = [ { id : 'user1' , initialPassword : 'existing-password' } , { id : 'user2' } ]
26
26
const secrets = { secret : 'true' , deep : { nested : 'secret' } }
27
- const ageKeys = { publicKey : 'agePublicKey' , privateKey : 'agePrivateKey' }
28
- const kmsValues = {
29
- kms : {
30
- sops : {
31
- provider : 'azure' ,
32
- azure : {
33
- keys : 'key1,key2' ,
34
- } ,
35
- } ,
36
- } ,
37
- }
38
- const kmsValuesWithAgeProvider = {
39
- kms : {
40
- sops : {
41
- provider : 'age' ,
42
- } ,
43
- } ,
44
- }
45
- const kmsValuesWithAgeFull = {
46
- kms : {
47
- sops : {
48
- provider : 'age' ,
49
- age : {
50
- publicKey : 'publicKey' ,
51
- privateKey : 'privateKey' ,
52
- } ,
53
- } ,
54
- } ,
55
- }
56
27
let deps
57
28
beforeEach ( ( ) => {
58
29
deps = {
@@ -103,24 +74,64 @@ describe('Bootstrapping values', () => {
103
74
const res = await getStoredClusterSecrets ( deps )
104
75
expect ( res ) . toEqual ( undefined )
105
76
} )
106
- it ( 'should not get kms values if those do not exist' , async ( ) => {
107
- const res = await getKmsValues ( values )
108
- expect ( res ) . toEqual ( undefined )
109
- } )
110
- it ( 'should get kms values if those exist' , async ( ) => {
111
- const res = await getKmsValues ( { ...values , ...kmsValues } )
112
- expect ( res ) . toEqual ( kmsValues )
113
- } )
114
- it ( 'should generate and return new age keys if provider is age and keys are missing' , async ( ) => {
115
- const kmsValuesDeps = {
116
- generateAgeKeys : jest . fn ( ) . mockResolvedValue ( ageKeys ) ,
77
+ describe ( 'getKmsValues' , ( ) => {
78
+ let kmsValuesDeps : any
79
+ const ageKeys = { publicKey : 'agePublicKey' , privateKey : 'agePrivateKey' }
80
+ const values = { someKey : 'someValue' }
81
+ const kmsValues = {
82
+ kms : {
83
+ sops : {
84
+ provider : 'azure' ,
85
+ azure : {
86
+ keys : 'key1,key2' ,
87
+ } ,
88
+ } ,
89
+ } ,
117
90
}
118
- const res = await getKmsValues ( { ...values , ...kmsValuesWithAgeProvider } , kmsValuesDeps )
119
- expect ( res ) . toEqual ( { kms : { sops : { provider : 'age' , age : ageKeys } } } )
120
- } )
121
- it ( 'should get kms values if age has public and private key' , async ( ) => {
122
- const res = await getKmsValues ( { ...values , ...kmsValuesWithAgeFull } )
123
- expect ( res ) . toEqual ( kmsValuesWithAgeFull )
91
+ const kmsValuesWithAgeProvider = {
92
+ kms : {
93
+ sops : {
94
+ provider : 'age' ,
95
+ } ,
96
+ } ,
97
+ }
98
+ const kmsValuesWithAgeFull = {
99
+ kms : {
100
+ sops : {
101
+ provider : 'age' ,
102
+ age : {
103
+ publicKey : 'publicKey' ,
104
+ privateKey : 'privateKey' ,
105
+ } ,
106
+ } ,
107
+ } ,
108
+ }
109
+ beforeEach ( ( ) => {
110
+ kmsValuesDeps = {
111
+ generateAgeKeys : jest . fn ( ) . mockResolvedValue ( ageKeys ) ,
112
+ hfValues : jest . fn ( ) ,
113
+ }
114
+ } )
115
+ it ( 'should not get kms values if those do not exist' , async ( ) => {
116
+ kmsValuesDeps . hfValues . mockReturnValue ( values )
117
+ const res = await getKmsValues ( kmsValuesDeps )
118
+ expect ( res ) . toBeUndefined ( )
119
+ } )
120
+ it ( 'should get kms values if those exist' , async ( ) => {
121
+ kmsValuesDeps . hfValues . mockReturnValue ( { ...values , ...kmsValues } )
122
+ const res = await getKmsValues ( kmsValuesDeps )
123
+ expect ( res ) . toEqual ( kmsValues )
124
+ } )
125
+ it ( 'should generate and return new age keys if provider is age and keys are missing' , async ( ) => {
126
+ kmsValuesDeps . hfValues . mockReturnValue ( { ...values , ...kmsValuesWithAgeProvider } )
127
+ const res = await getKmsValues ( kmsValuesDeps )
128
+ expect ( res ) . toEqual ( { kms : { sops : { provider : 'age' , age : ageKeys } } } )
129
+ } )
130
+ it ( 'should get kms values if age has public and private key' , async ( ) => {
131
+ kmsValuesDeps . hfValues . mockReturnValue ( { ...values , ...kmsValuesWithAgeFull } )
132
+ const res = await getKmsValues ( kmsValuesDeps )
133
+ expect ( res ) . toEqual ( kmsValuesWithAgeFull )
134
+ } )
124
135
} )
125
136
it ( 'should set k8sContext and owner if needed' , async ( ) => {
126
137
deps . processValues . mockReturnValue ( values )
0 commit comments