2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
4
import { expect } from 'chai'
5
- import {
6
- KmsKeyConfig ,
7
- RegionalKmsConfig ,
8
- KmsConfig ,
9
- } from '../src/kms_config'
5
+ import { KmsKeyConfig , RegionalKmsConfig , KmsConfig } from '../src/kms_config'
10
6
11
7
function supplySrkKmsConfig ( config : KmsConfig ) : KmsKeyConfig {
12
8
return new KmsKeyConfig ( config )
@@ -29,9 +25,20 @@ export const WELL_FORMED_MRK_ALIAS_ARN =
29
25
'arn:aws:kms:us-west-2:123456789012:alias/mrk/my-mrk-alias'
30
26
31
27
describe ( 'Test KmsKeyConfig class' , ( ) => {
28
+
29
+ it ( 'Precondition: config must be a string or object' , ( ) => {
30
+ for ( const config of [ null , undefined , 0 ] ) {
31
+ expect ( ( ) => supplySrkKmsConfig ( config as any ) ) . to . throw (
32
+ 'Config must be a `discovery` or an object.'
33
+ )
34
+ }
35
+ } )
32
36
it ( 'Precondition: ARN must be a string' , ( ) => {
33
37
for ( const arn of [ null , undefined , 0 , { } ] ) {
34
- expect ( ( ) => supplySrkKmsConfig ( arn as any ) ) . to . throw (
38
+ expect ( ( ) => supplySrkKmsConfig ( { identifier : arn } as any ) ) . to . throw (
39
+ 'ARN must be a string'
40
+ )
41
+ expect ( ( ) => supplySrkKmsConfig ( { mrkIdentifier : arn } as any ) ) . to . throw (
35
42
'ARN must be a string'
36
43
)
37
44
}
@@ -67,20 +74,20 @@ describe('Test KmsKeyConfig class', () => {
67
74
} )
68
75
69
76
describe ( 'Test getCompatibleArnArn' , ( ) => {
70
-
71
77
it ( 'Returns the SRK' , ( ) => {
72
- expect ( config . getCompatibleArnArn ( WELL_FORMED_SRK_ARN ) ) . to . equal ( WELL_FORMED_SRK_ARN )
78
+ expect ( config . getCompatibleArnArn ( WELL_FORMED_SRK_ARN ) ) . to . equal (
79
+ WELL_FORMED_SRK_ARN
80
+ )
73
81
} )
74
82
75
83
it ( 'Throws for a non compatible value' , ( ) => {
76
84
expect ( ( ) => config . getCompatibleArnArn ( WELL_FORMED_MRK_ARN ) ) . to . throw ( )
77
85
} )
78
-
79
86
} )
80
87
} )
81
88
82
89
describe ( 'Given a well formed MRK arn' , ( ) => {
83
- const config = supplySrkKmsConfig ( { identifier : WELL_FORMED_MRK_ARN } )
90
+ const config = supplySrkKmsConfig ( { mrkIdentifier : WELL_FORMED_MRK_ARN } )
84
91
85
92
it ( 'Test getRegion' , ( ) => {
86
93
expect ( ( config as RegionalKmsConfig ) . getRegion ( ) ) . equals ( 'us-west-2' )
@@ -115,96 +122,110 @@ describe('Test KmsKeyConfig class', () => {
115
122
} )
116
123
117
124
describe ( 'Test getCompatibleArnArn' , ( ) => {
118
-
119
125
it ( 'Returns the MRK' , ( ) => {
120
- expect ( config . getCompatibleArnArn ( WELL_FORMED_MRK_ARN ) ) . to . equal ( WELL_FORMED_MRK_ARN )
126
+ expect ( config . getCompatibleArnArn ( WELL_FORMED_MRK_ARN ) ) . to . equal (
127
+ WELL_FORMED_MRK_ARN
128
+ )
121
129
} )
122
130
123
131
it ( 'Returns the configured MRK because it is the right region' , ( ) => {
124
- expect ( config . getCompatibleArnArn ( WELL_FORMED_MRK_ARN_DIFFERENT_REGION ) ) . to . equal ( WELL_FORMED_MRK_ARN )
132
+ expect (
133
+ config . getCompatibleArnArn ( WELL_FORMED_MRK_ARN_DIFFERENT_REGION )
134
+ ) . to . equal ( WELL_FORMED_MRK_ARN )
125
135
} )
126
136
127
137
it ( 'Throws for a non compatible value' , ( ) => {
128
138
expect ( ( ) => config . getCompatibleArnArn ( WELL_FORMED_SRK_ARN ) ) . to . throw ( )
129
139
} )
130
-
131
140
} )
132
141
} )
133
142
134
143
describe ( 'Given discovery configurations' , ( ) => {
135
-
136
144
it ( 'Discovery is compatible with ARNs' , ( ) => {
137
145
const config = supplySrkKmsConfig ( 'discovery' )
138
- expect ( config . isCompatibleWithArn ( ONE_PART_ARN ) ) . to . equal ( true )
139
146
expect ( config . isCompatibleWithArn ( WELL_FORMED_SRK_ARN ) ) . to . equal ( true )
140
147
expect ( config . isCompatibleWithArn ( WELL_FORMED_MRK_ARN ) ) . to . equal ( true )
141
148
} )
142
149
143
-
144
150
it ( 'MRDiscovery is compatible with ARNs' , ( ) => {
145
- const config = supplySrkKmsConfig ( { region : 'us-west-2' } )
146
- expect ( config . isCompatibleWithArn ( ONE_PART_ARN ) ) . to . equal ( true )
151
+ const config = supplySrkKmsConfig ( { region : 'us-west-2' } )
147
152
expect ( config . isCompatibleWithArn ( WELL_FORMED_SRK_ARN ) ) . to . equal ( true )
148
153
expect ( config . isCompatibleWithArn ( WELL_FORMED_MRK_ARN ) ) . to . equal ( true )
149
154
} )
150
155
151
156
it ( 'Discovery MUST be an ARN' , ( ) => {
152
157
const config = supplySrkKmsConfig ( 'discovery' )
153
158
expect ( ( ) => config . isCompatibleWithArn ( MALFORMED_ARN ) ) . to . throw ( )
154
- expect ( ( ) => config . isCompatibleWithArn ( WELL_FORMED_SRK_ALIAS_ARN ) ) . to . throw ( )
155
- expect ( ( ) => config . isCompatibleWithArn ( WELL_FORMED_MRK_ALIAS_ARN ) ) . to . throw ( )
159
+ expect ( ( ) =>
160
+ config . isCompatibleWithArn ( WELL_FORMED_SRK_ALIAS_ARN )
161
+ ) . to . throw ( )
162
+ expect ( ( ) =>
163
+ config . isCompatibleWithArn ( WELL_FORMED_MRK_ALIAS_ARN )
164
+ ) . to . throw ( )
156
165
} )
157
166
158
-
159
167
it ( 'MRDiscovery MUST be an ARN' , ( ) => {
160
- const config = supplySrkKmsConfig ( { region : 'us-west-2' } )
168
+ const config = supplySrkKmsConfig ( { region : 'us-west-2' } )
161
169
expect ( ( ) => config . isCompatibleWithArn ( MALFORMED_ARN ) ) . to . throw ( )
162
- expect ( ( ) => config . isCompatibleWithArn ( WELL_FORMED_SRK_ALIAS_ARN ) ) . to . throw ( )
163
- expect ( ( ) => config . isCompatibleWithArn ( WELL_FORMED_MRK_ALIAS_ARN ) ) . to . throw ( )
170
+ expect ( ( ) =>
171
+ config . isCompatibleWithArn ( WELL_FORMED_SRK_ALIAS_ARN )
172
+ ) . to . throw ( )
173
+ expect ( ( ) =>
174
+ config . isCompatibleWithArn ( WELL_FORMED_MRK_ALIAS_ARN )
175
+ ) . to . throw ( )
164
176
} )
165
177
166
178
describe ( 'Test getCompatibleArnArn for discovery' , ( ) => {
167
179
const config = supplySrkKmsConfig ( 'discovery' )
168
180
169
181
it ( 'Returns the SRK' , ( ) => {
170
- expect ( config . getCompatibleArnArn ( WELL_FORMED_SRK_ARN ) ) . to . equal ( WELL_FORMED_SRK_ARN )
182
+ expect ( config . getCompatibleArnArn ( WELL_FORMED_SRK_ARN ) ) . to . equal (
183
+ WELL_FORMED_SRK_ARN
184
+ )
171
185
} )
172
186
173
187
it ( 'Returns the MRK' , ( ) => {
174
- expect ( config . getCompatibleArnArn ( WELL_FORMED_MRK_ARN ) ) . to . equal ( WELL_FORMED_MRK_ARN )
188
+ expect ( config . getCompatibleArnArn ( WELL_FORMED_MRK_ARN ) ) . to . equal (
189
+ WELL_FORMED_MRK_ARN
190
+ )
175
191
} )
176
192
177
193
it ( 'Returns the configured MRK because it is the right region' , ( ) => {
178
- expect ( config . getCompatibleArnArn ( WELL_FORMED_MRK_ARN_DIFFERENT_REGION ) ) . to . equal ( WELL_FORMED_MRK_ARN_DIFFERENT_REGION )
194
+ expect (
195
+ config . getCompatibleArnArn ( WELL_FORMED_MRK_ARN_DIFFERENT_REGION )
196
+ ) . to . equal ( WELL_FORMED_MRK_ARN_DIFFERENT_REGION )
179
197
} )
180
198
181
199
it ( 'Throws for a non compatible value' , ( ) => {
182
- expect ( ( ) => config . getCompatibleArnArn ( WELL_FORMED_SRK_ARN ) ) . to . throw ( )
200
+ expect ( ( ) => config . getCompatibleArnArn ( ONE_PART_ARN ) ) . to . throw ( )
183
201
} )
184
-
185
202
} )
186
203
187
204
describe ( 'Test getCompatibleArnArn for MRDiscovery' , ( ) => {
188
- const config = supplySrkKmsConfig ( { region : 'us-east-1' } )
205
+ const config = supplySrkKmsConfig ( { region : 'us-east-1' } )
189
206
190
207
it ( 'Returns the SRK' , ( ) => {
191
- expect ( config . getCompatibleArnArn ( WELL_FORMED_SRK_ARN ) ) . to . equal ( WELL_FORMED_SRK_ARN )
208
+ expect ( config . getCompatibleArnArn ( WELL_FORMED_SRK_ARN ) ) . to . equal (
209
+ WELL_FORMED_SRK_ARN
210
+ )
192
211
} )
193
212
194
213
it ( 'Returns the MRK' , ( ) => {
195
- expect ( config . getCompatibleArnArn ( WELL_FORMED_MRK_ARN ) ) . to . equal ( WELL_FORMED_MRK_ARN_DIFFERENT_REGION )
214
+ expect ( config . getCompatibleArnArn ( WELL_FORMED_MRK_ARN ) ) . to . equal (
215
+ WELL_FORMED_MRK_ARN_DIFFERENT_REGION
216
+ )
196
217
} )
197
218
198
219
it ( 'Returns the configured MRK because it is the right region' , ( ) => {
199
- expect ( config . getCompatibleArnArn ( WELL_FORMED_MRK_ARN_DIFFERENT_REGION ) ) . to . equal ( WELL_FORMED_MRK_ARN_DIFFERENT_REGION )
220
+ expect (
221
+ config . getCompatibleArnArn ( WELL_FORMED_MRK_ARN_DIFFERENT_REGION )
222
+ ) . to . equal ( WELL_FORMED_MRK_ARN_DIFFERENT_REGION )
200
223
} )
201
224
202
225
it ( 'Throws for a non compatible value' , ( ) => {
203
- expect ( ( ) => config . getCompatibleArnArn ( WELL_FORMED_SRK_ARN ) ) . to . throw ( )
226
+ expect ( ( ) => config . getCompatibleArnArn ( ONE_PART_ARN ) ) . to . throw ( )
204
227
} )
205
-
206
228
} )
207
-
208
229
} )
209
230
210
231
//= aws-encryption-sdk-specification/framework/branch-key-store.md#aws-kms-configuration
0 commit comments