@webex/internal-plugin-encryption 3.0.0-beta.8 → 3.0.0-bnr.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +1 -3
  2. package/dist/config.js +0 -9
  3. package/dist/config.js.map +1 -1
  4. package/dist/encryption.js +9 -60
  5. package/dist/encryption.js.map +1 -1
  6. package/dist/ensure-buffer.browser.js +0 -12
  7. package/dist/ensure-buffer.browser.js.map +1 -1
  8. package/dist/ensure-buffer.js +5 -12
  9. package/dist/ensure-buffer.js.map +1 -1
  10. package/dist/index.js +7 -33
  11. package/dist/index.js.map +1 -1
  12. package/dist/kms-batcher.js +6 -30
  13. package/dist/kms-batcher.js.map +1 -1
  14. package/dist/kms-certificate-validation.js +20 -88
  15. package/dist/kms-certificate-validation.js.map +1 -1
  16. package/dist/kms-dry-error-interceptor.js +1 -23
  17. package/dist/kms-dry-error-interceptor.js.map +1 -1
  18. package/dist/kms-errors.js +3 -50
  19. package/dist/kms-errors.js.map +1 -1
  20. package/dist/kms.js +74 -213
  21. package/dist/kms.js.map +1 -1
  22. package/dist/types/config.d.ts +16 -0
  23. package/dist/types/encryption.d.ts +2 -0
  24. package/dist/types/ensure-buffer.browser.d.ts +10 -0
  25. package/dist/types/ensure-buffer.d.ts +7 -0
  26. package/dist/types/index.d.ts +3 -0
  27. package/dist/types/kms-batcher.d.ts +6 -0
  28. package/dist/types/kms-certificate-validation.d.ts +24 -0
  29. package/dist/types/kms-dry-error-interceptor.d.ts +25 -0
  30. package/dist/types/kms-errors.d.ts +33 -0
  31. package/dist/types/kms.d.ts +5 -0
  32. package/package.json +15 -15
  33. package/src/config.js +3 -3
  34. package/src/encryption.js +66 -56
  35. package/src/ensure-buffer.browser.js +0 -1
  36. package/src/ensure-buffer.js +5 -5
  37. package/src/index.js +120 -96
  38. package/src/kms-batcher.js +50 -44
  39. package/src/kms-certificate-validation.js +45 -47
  40. package/src/kms-dry-error-interceptor.js +8 -4
  41. package/src/kms-errors.js +19 -16
  42. package/src/kms.js +210 -206
  43. package/test/integration/spec/encryption.js +311 -230
  44. package/test/integration/spec/kms.js +532 -404
  45. package/test/integration/spec/payload-transfom.js +69 -69
  46. package/test/unit/spec/encryption.js +16 -13
  47. package/test/unit/spec/kms-certificate-validation.js +41 -32
@@ -42,13 +42,13 @@ describe('Encryption', function () {
42
42
  return window.btoa(binary);
43
43
  }
44
44
 
45
- before('create test user', () => testUsers.create({count: 2, config: {roles: [{name: 'id_full_admin'}]}})
46
- .then((users) => {
45
+ before('create test user', () =>
46
+ testUsers.create({count: 2, config: {roles: [{name: 'id_full_admin'}]}}).then((users) => {
47
47
  spock = users[0];
48
48
  webex = new WebexCore({
49
49
  credentials: {
50
- authorization: spock.token
51
- }
50
+ authorization: spock.token,
51
+ },
52
52
  });
53
53
  spock.webex = webex;
54
54
  assert.isTrue(webex.canAuthorize);
@@ -56,89 +56,104 @@ describe('Encryption', function () {
56
56
  mccoy = users[1];
57
57
  mccoy.webex = new WebexCore({
58
58
  credentials: {
59
- authorization: mccoy.token
60
- }
59
+ authorization: mccoy.token,
60
+ },
61
61
  });
62
62
 
63
63
  assert.isTrue(mccoy.webex.canAuthorize);
64
64
 
65
65
  return mccoy.webex.internal.device.register();
66
- }));
66
+ })
67
+ );
67
68
 
68
69
  after(() => webex && webex.internal.mercury.disconnect());
69
70
 
70
71
  let expiredUser;
71
72
 
72
73
  // TODO: Re-enable SPARK-133280
73
- it.skip('errs using an invalid token', () => testUsers.create({count: 1})
74
- .then((users) => {
75
- [expiredUser] = users;
76
- expiredUser.webex = new WebexCore({
77
- credentials: {
78
- authorization: 'invalidToken'
79
- }
80
- });
81
- expiredUser.webex.internal.device.register();
82
- })
83
- .then(() => expiredUser.webex.internal.encryption.kms.createUnboundKeys({count: 1}))
84
- .catch((err) => {
85
- assert.equal(err.statusCode, 401);
86
- }));
74
+ it.skip('errs using an invalid token', () =>
75
+ testUsers
76
+ .create({count: 1})
77
+ .then((users) => {
78
+ [expiredUser] = users;
79
+ expiredUser.webex = new WebexCore({
80
+ credentials: {
81
+ authorization: 'invalidToken',
82
+ },
83
+ });
84
+ expiredUser.webex.internal.device.register();
85
+ })
86
+ .then(() => expiredUser.webex.internal.encryption.kms.createUnboundKeys({count: 1}))
87
+ .catch((err) => {
88
+ assert.equal(err.statusCode, 401);
89
+ }));
87
90
 
88
91
  describe('#createResource()', () => {
89
- it('creates a kms resource object', () => webex.internal.encryption.kms.createUnboundKeys({count: 1})
90
- .then(([key]) => webex.internal.encryption.kms.createResource({
91
- userIds: [webex.internal.device.userId],
92
- key
93
- })
94
- .then((kro) => {
95
- assert.property(kro, 'uri');
96
- assert.property(kro, 'keyUris');
97
- assert.lengthOf(kro.keyUris, 1);
98
- assert.include(kro.keyUris, key.uri);
99
- assert.property(kro, 'authorizationUris');
100
- assert.lengthOf(kro.authorizationUris, 1);
101
- })));
92
+ it('creates a kms resource object', () =>
93
+ webex.internal.encryption.kms.createUnboundKeys({count: 1}).then(([key]) =>
94
+ webex.internal.encryption.kms
95
+ .createResource({
96
+ userIds: [webex.internal.device.userId],
97
+ key,
98
+ })
99
+ .then((kro) => {
100
+ assert.property(kro, 'uri');
101
+ assert.property(kro, 'keyUris');
102
+ assert.lengthOf(kro.keyUris, 1);
103
+ assert.include(kro.keyUris, key.uri);
104
+ assert.property(kro, 'authorizationUris');
105
+ assert.lengthOf(kro.authorizationUris, 1);
106
+ })
107
+ ));
102
108
  });
103
109
 
104
110
  describe('#addAuthorization()', () => {
105
111
  let boundedKeyUri, kro, otherKro;
106
112
 
107
- before('create a resource', () => webex.internal.encryption.kms.createUnboundKeys({count: 1})
108
- .then(([key]) => webex.internal.encryption.kms.createResource({
109
- key
110
- }))
111
- .then((k) => {
112
- kro = k;
113
- boundedKeyUri = kro.keyUris[0];
114
- assert.lengthOf(kro.authorizationUris, 1);
115
- }));
113
+ before('create a resource', () =>
114
+ webex.internal.encryption.kms
115
+ .createUnboundKeys({count: 1})
116
+ .then(([key]) =>
117
+ webex.internal.encryption.kms.createResource({
118
+ key,
119
+ })
120
+ )
121
+ .then((k) => {
122
+ kro = k;
123
+ boundedKeyUri = kro.keyUris[0];
124
+ assert.lengthOf(kro.authorizationUris, 1);
125
+ })
126
+ );
116
127
 
117
- it('authorizes a user to a key', () => webex.internal.encryption.kms.addAuthorization({
118
- userIds: [mccoy.webex.internal.device.userId],
119
- kroUri: kro.uri
120
- })
121
- .then(([auth]) => {
122
- assert.equal(auth.resourceUri, kro.uri);
123
- assert.equal(auth.authId, mccoy.webex.internal.device.userId);
128
+ it('authorizes a user to a key', () =>
129
+ webex.internal.encryption.kms
130
+ .addAuthorization({
131
+ userIds: [mccoy.webex.internal.device.userId],
132
+ kroUri: kro.uri,
133
+ })
134
+ .then(([auth]) => {
135
+ assert.equal(auth.resourceUri, kro.uri);
136
+ assert.equal(auth.authId, mccoy.webex.internal.device.userId);
124
137
 
125
- return mccoy.webex.internal.encryption.kms.fetchKey({uri: boundedKeyUri});
126
- }));
138
+ return mccoy.webex.internal.encryption.kms.fetchKey({uri: boundedKeyUri});
139
+ }));
127
140
 
128
- it('authorizes a resource to a key', () => webex.internal.encryption.kms.createUnboundKeys({count: 1})
129
- .then(([key]) => webex.internal.encryption.kms.createResource({key}))
130
- .then((k) => {
131
- otherKro = k;
141
+ it('authorizes a resource to a key', () =>
142
+ webex.internal.encryption.kms
143
+ .createUnboundKeys({count: 1})
144
+ .then(([key]) => webex.internal.encryption.kms.createResource({key}))
145
+ .then((k) => {
146
+ otherKro = k;
132
147
 
133
- return webex.internal.encryption.kms.addAuthorization({
134
- authIds: [otherKro.uri],
135
- kro
136
- });
137
- })
138
- .then(([auth]) => {
139
- assert.equal(auth.resourceUri, kro.uri);
140
- assert.equal(auth.authId, otherKro.uri);
141
- }));
148
+ return webex.internal.encryption.kms.addAuthorization({
149
+ authIds: [otherKro.uri],
150
+ kro,
151
+ });
152
+ })
153
+ .then(([auth]) => {
154
+ assert.equal(auth.resourceUri, kro.uri);
155
+ assert.equal(auth.authId, otherKro.uri);
156
+ }));
142
157
  });
143
158
 
144
159
  /**
@@ -153,61 +168,87 @@ describe('Encryption', function () {
153
168
  let boundedKeyUri, kro, otherKro;
154
169
  let testResourceId;
155
170
 
156
- before('creates a resource', () => webex.internal.encryption.kms.createUnboundKeys({count: 1})
157
- .then(([key]) => webex.internal.encryption.kms.createResource({
158
- key
159
- }))
160
- .then((k) => {
161
- kro = k;
162
- boundedKeyUri = kro.keyUris[0];
163
- assert.lengthOf(kro.authorizationUris, 1);
164
- }));
165
-
166
- before('authorizes a user to a key', () => webex.internal.encryption.kms.addAuthorization({
167
- userIds: [mccoy.webex.internal.device.userId],
168
- kroUri: kro.uri
169
- })
170
- .then(([auth]) => {
171
- assert.equal(auth.resourceUri, kro.uri);
172
- assert.equal(auth.authId, mccoy.webex.internal.device.userId);
173
-
174
- return mccoy.webex.internal.encryption.kms.fetchKey({uri: boundedKeyUri});
175
- }));
176
-
177
- before('authorizes a resource to a key', () => webex.internal.encryption.kms.createUnboundKeys({count: 1})
178
- .then(([key]) => webex.internal.encryption.kms.createResource({key}))
179
- .then((k) => {
180
- otherKro = k;
181
- testResourceId = otherKro.uri;
171
+ before('creates a resource', () =>
172
+ webex.internal.encryption.kms
173
+ .createUnboundKeys({count: 1})
174
+ .then(([key]) =>
175
+ webex.internal.encryption.kms.createResource({
176
+ key,
177
+ })
178
+ )
179
+ .then((k) => {
180
+ kro = k;
181
+ boundedKeyUri = kro.keyUris[0];
182
+ assert.lengthOf(kro.authorizationUris, 1);
183
+ })
184
+ );
182
185
 
183
- return webex.internal.encryption.kms.addAuthorization({
184
- authIds: [testResourceId],
185
- kro
186
- });
187
- })
188
- .then(([auth]) => {
189
- assert.equal(auth.resourceUri, kro.uri);
190
- assert.equal(auth.authId, otherKro.uri);
191
- }));
186
+ before('authorizes a user to a key', () =>
187
+ webex.internal.encryption.kms
188
+ .addAuthorization({
189
+ userIds: [mccoy.webex.internal.device.userId],
190
+ kroUri: kro.uri,
191
+ })
192
+ .then(([auth]) => {
193
+ assert.equal(auth.resourceUri, kro.uri);
194
+ assert.equal(auth.authId, mccoy.webex.internal.device.userId);
192
195
 
193
- it('list authorizations', () => webex.internal.encryption.kms.listAuthorizations({kroUri: kro.uri})
194
- .then((authorizations) => {
195
- assert.equal(authorizations.length, 3);
196
- assert.include(authorizations.map((a) => a.authId), mccoy.webex.internal.device.userId);
197
- assert.include(authorizations.map((a) => a.authId), spock.id);
198
- assert.include(authorizations.map((a) => a.resourceUri), testResourceId);
199
- assert.include(authorizations.map((a) => a.resourceUri), kro.uri);
200
- }));
196
+ return mccoy.webex.internal.encryption.kms.fetchKey({uri: boundedKeyUri});
197
+ })
198
+ );
199
+
200
+ before('authorizes a resource to a key', () =>
201
+ webex.internal.encryption.kms
202
+ .createUnboundKeys({count: 1})
203
+ .then(([key]) => webex.internal.encryption.kms.createResource({key}))
204
+ .then((k) => {
205
+ otherKro = k;
206
+ testResourceId = otherKro.uri;
207
+
208
+ return webex.internal.encryption.kms.addAuthorization({
209
+ authIds: [testResourceId],
210
+ kro,
211
+ });
212
+ })
213
+ .then(([auth]) => {
214
+ assert.equal(auth.resourceUri, kro.uri);
215
+ assert.equal(auth.authId, otherKro.uri);
216
+ })
217
+ );
218
+
219
+ it('list authorizations', () =>
220
+ webex.internal.encryption.kms
221
+ .listAuthorizations({kroUri: kro.uri})
222
+ .then((authorizations) => {
223
+ assert.equal(authorizations.length, 3);
224
+ assert.include(
225
+ authorizations.map((a) => a.authId),
226
+ mccoy.webex.internal.device.userId
227
+ );
228
+ assert.include(
229
+ authorizations.map((a) => a.authId),
230
+ spock.id
231
+ );
232
+ assert.include(
233
+ authorizations.map((a) => a.resourceUri),
234
+ testResourceId
235
+ );
236
+ assert.include(
237
+ authorizations.map((a) => a.resourceUri),
238
+ kro.uri
239
+ );
240
+ }));
201
241
 
202
- it('rejects normally for users that are not authorized', () => testUsers.create({count: 1})
203
- .then(([user]) => {
242
+ it('rejects normally for users that are not authorized', () =>
243
+ testUsers.create({count: 1}).then(([user]) => {
204
244
  const us = new WebexCore({
205
245
  credentials: {
206
- authorization: user.token
207
- }
246
+ authorization: user.token,
247
+ },
208
248
  });
209
249
 
210
- return assert.isRejected(us.internal.encryption.kms.listAuthorizations({kroUri: kro.uri}))
250
+ return assert
251
+ .isRejected(us.internal.encryption.kms.listAuthorizations({kroUri: kro.uri}))
211
252
  .then((err) => {
212
253
  console.error(err);
213
254
  assert.equal(err.status, 403, 'We should get a Not Authorized response from kms');
@@ -215,119 +256,161 @@ describe('Encryption', function () {
215
256
  .then(() => us.internal.mercury.disconnect());
216
257
  }));
217
258
 
218
- it('remove the user and verify this user is not in the authorization list ', () => webex.internal.encryption.kms.removeAuthorization({
219
- userId: mccoy.webex.internal.device.userId,
220
- kroUri: kro.uri
221
- })
222
- .then(([auth]) => {
223
- assert.equal(auth.resourceUri, kro.uri);
224
- assert.equal(auth.authId, mccoy.webex.internal.device.userId);
225
-
226
- return webex.internal.encryption.kms.listAuthorizations({kro})
227
- .then((authorizations) => {
228
- assert.equal(authorizations.length, 2);
229
- assert.include(authorizations.map((a) => a.authId), spock.id);
230
- assert.include(authorizations.map((a) => a.resourceUri), testResourceId);
231
- assert.include(authorizations.map((a) => a.resourceUri), kro.uri);
232
- });
233
- }));
259
+ it('remove the user and verify this user is not in the authorization list ', () =>
260
+ webex.internal.encryption.kms
261
+ .removeAuthorization({
262
+ userId: mccoy.webex.internal.device.userId,
263
+ kroUri: kro.uri,
264
+ })
265
+ .then(([auth]) => {
266
+ assert.equal(auth.resourceUri, kro.uri);
267
+ assert.equal(auth.authId, mccoy.webex.internal.device.userId);
268
+
269
+ return webex.internal.encryption.kms
270
+ .listAuthorizations({kro})
271
+ .then((authorizations) => {
272
+ assert.equal(authorizations.length, 2);
273
+ assert.include(
274
+ authorizations.map((a) => a.authId),
275
+ spock.id
276
+ );
277
+ assert.include(
278
+ authorizations.map((a) => a.resourceUri),
279
+ testResourceId
280
+ );
281
+ assert.include(
282
+ authorizations.map((a) => a.resourceUri),
283
+ kro.uri
284
+ );
285
+ });
286
+ }));
234
287
 
235
- it('remove the resource and verify this resource is not in the authorizaiton list', () => webex.internal.encryption.kms.removeAuthorization({
236
- userId: testResourceId,
237
- kroUri: kro.uri
238
- })
239
- .then(([auth]) => {
240
- assert.equal(auth.resourceUri, kro.uri);
241
- assert.equal(auth.authId, testResourceId);
242
-
243
- return webex.internal.encryption.kms.listAuthorizations({kroUri: kro.uri})
244
- .then((authorizations) => {
245
- assert.equal(authorizations.length, 1);
246
- assert.include(authorizations.map((a) => a.authId), spock.id);
247
- assert.include(authorizations.map((a) => a.resourceUri), kro.uri);
248
- });
249
- }));
288
+ it('remove the resource and verify this resource is not in the authorizaiton list', () =>
289
+ webex.internal.encryption.kms
290
+ .removeAuthorization({
291
+ userId: testResourceId,
292
+ kroUri: kro.uri,
293
+ })
294
+ .then(([auth]) => {
295
+ assert.equal(auth.resourceUri, kro.uri);
296
+ assert.equal(auth.authId, testResourceId);
297
+
298
+ return webex.internal.encryption.kms
299
+ .listAuthorizations({kroUri: kro.uri})
300
+ .then((authorizations) => {
301
+ assert.equal(authorizations.length, 1);
302
+ assert.include(
303
+ authorizations.map((a) => a.authId),
304
+ spock.id
305
+ );
306
+ assert.include(
307
+ authorizations.map((a) => a.resourceUri),
308
+ kro.uri
309
+ );
310
+ });
311
+ }));
250
312
  });
251
313
 
252
314
  describe('#removeAuthorization()', () => {
253
315
  let boundedKeyUri, kro, otherKro;
254
316
 
255
- before('create resource', () => webex.internal.encryption.kms.createUnboundKeys({count: 1})
256
- .then(([key]) => webex.internal.encryption.kms.createResource({
257
- key
258
- }))
259
- .then((k) => {
260
- kro = k;
261
- boundedKeyUri = kro.keyUris[0];
262
- assert.lengthOf(kro.authorizationUris, 1);
263
- }));
264
-
265
- before('create another resource', () => webex.internal.encryption.kms.createUnboundKeys({count: 1})
266
- .then(([key]) => webex.internal.encryption.kms.createResource({
267
- key
268
- }))
269
- .then((k) => {
270
- otherKro = k;
271
- }));
317
+ before('create resource', () =>
318
+ webex.internal.encryption.kms
319
+ .createUnboundKeys({count: 1})
320
+ .then(([key]) =>
321
+ webex.internal.encryption.kms.createResource({
322
+ key,
323
+ })
324
+ )
325
+ .then((k) => {
326
+ kro = k;
327
+ boundedKeyUri = kro.keyUris[0];
328
+ assert.lengthOf(kro.authorizationUris, 1);
329
+ })
330
+ );
331
+
332
+ before('create another resource', () =>
333
+ webex.internal.encryption.kms
334
+ .createUnboundKeys({count: 1})
335
+ .then(([key]) =>
336
+ webex.internal.encryption.kms.createResource({
337
+ key,
338
+ })
339
+ )
340
+ .then((k) => {
341
+ otherKro = k;
342
+ })
343
+ );
272
344
 
273
- before('add auths to resource', () => webex.internal.encryption.kms.addAuthorization({
274
- authIds: [otherKro.uri, mccoy.webex.internal.device.userId],
275
- kro
276
- })
277
- .then(([kroAuth, userAuth]) => {
278
- assert.equal(kroAuth.authId, otherKro.uri);
279
- assert.equal(userAuth.authId, mccoy.webex.internal.device.userId);
280
- }));
345
+ before('add auths to resource', () =>
346
+ webex.internal.encryption.kms
347
+ .addAuthorization({
348
+ authIds: [otherKro.uri, mccoy.webex.internal.device.userId],
349
+ kro,
350
+ })
351
+ .then(([kroAuth, userAuth]) => {
352
+ assert.equal(kroAuth.authId, otherKro.uri);
353
+ assert.equal(userAuth.authId, mccoy.webex.internal.device.userId);
354
+ })
355
+ );
281
356
 
282
- it('deauthorizes a user from a key', () => webex.internal.encryption.kms.removeAuthorization({
283
- userId: mccoy.webex.internal.device.userId,
284
- kroUri: kro.uri
285
- })
286
- .then(([auth]) => {
287
- assert.equal(auth.resourceUri, kro.uri);
288
- assert.equal(auth.authId, mccoy.webex.internal.device.userId);
357
+ it('deauthorizes a user from a key', () =>
358
+ webex.internal.encryption.kms
359
+ .removeAuthorization({
360
+ userId: mccoy.webex.internal.device.userId,
361
+ kroUri: kro.uri,
362
+ })
363
+ .then(([auth]) => {
364
+ assert.equal(auth.resourceUri, kro.uri);
365
+ assert.equal(auth.authId, mccoy.webex.internal.device.userId);
289
366
 
290
- return assert.isRejected(mccoy.webex.internal.encryption.kms.fetchKey({uri: boundedKeyUri}));
291
- }));
367
+ return assert.isRejected(
368
+ mccoy.webex.internal.encryption.kms.fetchKey({uri: boundedKeyUri})
369
+ );
370
+ }));
292
371
 
293
- it('deauthorizes a resource from a key', () => webex.internal.encryption.kms.removeAuthorization({
294
- authId: otherKro.uri,
295
- kro
296
- })
297
- .then(([auth]) => {
298
- assert.equal(auth.resourceUri, kro.uri);
299
- assert.equal(auth.authId, otherKro.uri);
300
- }));
372
+ it('deauthorizes a resource from a key', () =>
373
+ webex.internal.encryption.kms
374
+ .removeAuthorization({
375
+ authId: otherKro.uri,
376
+ kro,
377
+ })
378
+ .then(([auth]) => {
379
+ assert.equal(auth.resourceUri, kro.uri);
380
+ assert.equal(auth.authId, otherKro.uri);
381
+ }));
301
382
  });
302
383
 
303
384
  describe('#bindKey()', () => {
304
385
  let key2, kro;
305
386
 
306
- it('binds a resource to a key', () => webex.internal.encryption.kms.createUnboundKeys({count: 2})
307
- .then((keys) => {
308
- key2 = keys[1];
387
+ it('binds a resource to a key', () =>
388
+ webex.internal.encryption.kms
389
+ .createUnboundKeys({count: 2})
390
+ .then((keys) => {
391
+ key2 = keys[1];
309
392
 
310
- return webex.internal.encryption.kms.createResource({
311
- userIds: [webex.internal.device.userId],
312
- key: keys[0]
313
- });
314
- })
315
- .then((k) => {
316
- kro = k;
393
+ return webex.internal.encryption.kms.createResource({
394
+ userIds: [webex.internal.device.userId],
395
+ key: keys[0],
396
+ });
397
+ })
398
+ .then((k) => {
399
+ kro = k;
317
400
 
318
- return webex.internal.encryption.kms.bindKey({kro, key: key2});
319
- })
320
- .then((key) => {
321
- assert.equal(key.uri, key2.uri);
322
- assert.property(key, 'bindDate');
323
- assert.property(key, 'resourceUri');
324
- assert.equal(key.resourceUri, kro.uri);
325
- }));
401
+ return webex.internal.encryption.kms.bindKey({kro, key: key2});
402
+ })
403
+ .then((key) => {
404
+ assert.equal(key.uri, key2.uri);
405
+ assert.property(key, 'bindDate');
406
+ assert.property(key, 'resourceUri');
407
+ assert.equal(key.resourceUri, kro.uri);
408
+ }));
326
409
  });
327
410
 
328
411
  describe('#createUnboundKeys()', () => {
329
- it('requests unbound keys from the KMS', () => webex.internal.encryption.kms.createUnboundKeys({count: 2})
330
- .then((keys) => {
412
+ it('requests unbound keys from the KMS', () =>
413
+ webex.internal.encryption.kms.createUnboundKeys({count: 2}).then((keys) => {
331
414
  assert.lengthOf(keys, 2);
332
415
 
333
416
  const [key1, key2] = keys;
@@ -343,97 +426,121 @@ describe('Encryption', function () {
343
426
  let uploadedkeyId;
344
427
 
345
428
  /* eslint-disable no-unused-expressions */
346
- skipInBrowser(it)('upload customer master key', () => (webex.internal.encryption.kms.deleteAllCustomerMasterKeys({assignedOrgId: spock.orgId})
347
- .then(() => webex.internal.encryption.kms.fetchPublicKey({assignedOrgId: spock.orgId}))
348
- .then((publicKey) => {
349
- assert.isNotEmpty(publicKey);
350
- const pemHeader = '-----BEGIN PUBLIC KEY-----';
351
- const pemFooter = '-----END PUBLIC KEY-----';
352
- const publicContent = publicKey.substring(pemHeader.length, publicKey.length - pemFooter.length);
353
- const binaryDerString = window.atob(publicContent);
354
- // convert from a binary string to an ArrayBuffer
355
- const binaryDer = str2ab(binaryDerString);
356
-
357
- return window.crypto.subtle.importKey(
358
- 'spki',
359
- binaryDer,
360
- {
361
- name: 'RSA-OAEP',
362
- hash: 'SHA-256'
363
- },
364
- true,
365
- ['encrypt']
366
- );
367
- })
368
- .then((publicKey) => {
369
- const buf = window.crypto.getRandomValues(new Uint8Array(16));
370
-
371
- return window.crypto.subtle.encrypt(
372
- {
373
- name: 'RSA-OAEP'
374
- },
375
- publicKey,
376
- buf
377
- );
378
- })
379
- .then((encryptedData) => webex.internal.encryption.kms.uploadCustomerMasterKey({assignedOrgId: spock.orgId, customerMasterKey: arrayBufferToBase64(encryptedData)}))
380
- .then((uploadRes) => {
381
- uploadedkeyId = uploadRes.customerMasterKeys[0].uri;
429
+ skipInBrowser(it)('upload customer master key', () =>
430
+ webex.internal.encryption.kms
431
+ .deleteAllCustomerMasterKeys({assignedOrgId: spock.orgId})
432
+ .then(() => webex.internal.encryption.kms.fetchPublicKey({assignedOrgId: spock.orgId}))
433
+ .then((publicKey) => {
434
+ assert.isNotEmpty(publicKey);
435
+ const pemHeader = '-----BEGIN PUBLIC KEY-----';
436
+ const pemFooter = '-----END PUBLIC KEY-----';
437
+ const publicContent = publicKey.substring(
438
+ pemHeader.length,
439
+ publicKey.length - pemFooter.length
440
+ );
441
+ const binaryDerString = window.atob(publicContent);
442
+ // convert from a binary string to an ArrayBuffer
443
+ const binaryDer = str2ab(binaryDerString);
444
+
445
+ return window.crypto.subtle.importKey(
446
+ 'spki',
447
+ binaryDer,
448
+ {
449
+ name: 'RSA-OAEP',
450
+ hash: 'SHA-256',
451
+ },
452
+ true,
453
+ ['encrypt']
454
+ );
455
+ })
456
+ .then((publicKey) => {
457
+ const buf = window.crypto.getRandomValues(new Uint8Array(16));
458
+
459
+ return window.crypto.subtle.encrypt(
460
+ {
461
+ name: 'RSA-OAEP',
462
+ },
463
+ publicKey,
464
+ buf
465
+ );
466
+ })
467
+ .then((encryptedData) =>
468
+ webex.internal.encryption.kms.uploadCustomerMasterKey({
469
+ assignedOrgId: spock.orgId,
470
+ customerMasterKey: arrayBufferToBase64(encryptedData),
471
+ })
472
+ )
473
+ .then((uploadRes) => {
474
+ uploadedkeyId = uploadRes.customerMasterKeys[0].uri;
382
475
 
383
- return webex.internal.encryption.kms.listAllCustomerMasterKey({assignedOrgId: spock.orgId});
384
- })
385
- .then((listCmksRes) => {
386
- const cmks = listCmksRes.customerMasterKeys;
387
- const uploadedCmk = cmks.find((cmk) => cmk.uri === uploadedkeyId);
476
+ return webex.internal.encryption.kms.listAllCustomerMasterKey({
477
+ assignedOrgId: spock.orgId,
478
+ });
479
+ })
480
+ .then((listCmksRes) => {
481
+ const cmks = listCmksRes.customerMasterKeys;
482
+ const uploadedCmk = cmks.find((cmk) => cmk.uri === uploadedkeyId);
388
483
 
389
- expect(uploadedCmk).to.not.be.null;
484
+ expect(uploadedCmk).to.not.be.null;
390
485
 
391
- return webex.internal.encryption.kms.changeCustomerMasterKeyState({keyId: uploadedkeyId, keyState: 'ACTIVE', assignedOrgId: spock.orgId});
392
- })
393
- .then((activeRes) => {
394
- expect(activeRes.customerMasterKeys[0].usageState).to.have.string('ACTIVE');
486
+ return webex.internal.encryption.kms.changeCustomerMasterKeyState({
487
+ keyId: uploadedkeyId,
488
+ keyState: 'ACTIVE',
489
+ assignedOrgId: spock.orgId,
490
+ });
491
+ })
492
+ .then((activeRes) => {
493
+ expect(activeRes.customerMasterKeys[0].usageState).to.have.string('ACTIVE');
395
494
 
396
- // return webex.internal.encryption.kms.useGlobalMasterKey({assignedOrgId: spock.orgId});
397
- return webex.internal.encryption.kms.deleteAllCustomerMasterKeys({assignedOrgId: spock.orgId});
398
- })));
495
+ // return webex.internal.encryption.kms.useGlobalMasterKey({assignedOrgId: spock.orgId});
496
+ return webex.internal.encryption.kms.deleteAllCustomerMasterKeys({
497
+ assignedOrgId: spock.orgId,
498
+ });
499
+ })
500
+ );
399
501
  });
400
502
 
401
503
  describe('#fetchKey()', () => {
402
504
  let key;
403
505
 
404
- it('retrieves a specific key', () => webex.internal.encryption.kms.createUnboundKeys({count: 1})
405
- .then(([k]) => {
406
- key = k;
506
+ it('retrieves a specific key', () =>
507
+ webex.internal.encryption.kms
508
+ .createUnboundKeys({count: 1})
509
+ .then(([k]) => {
510
+ key = k;
407
511
 
408
- return webex.internal.encryption.kms.fetchKey({uri: key.uri});
409
- })
410
- .then((key2) => {
411
- assert.property(key2, 'uri');
412
- assert.property(key2, 'jwk');
413
- assert.notEqual(key2, key);
414
- assert.equal(key2.uri, key.uri);
415
- }));
512
+ return webex.internal.encryption.kms.fetchKey({uri: key.uri});
513
+ })
514
+ .then((key2) => {
515
+ assert.property(key2, 'uri');
516
+ assert.property(key2, 'jwk');
517
+ assert.notEqual(key2, key);
518
+ assert.equal(key2.uri, key.uri);
519
+ }));
416
520
  });
417
521
 
418
522
  describe('#fetchKey(onBehalfOf)', () => {
419
523
  let jim;
420
524
 
421
- before('create compliance officer test user', () => testUsers.create({
422
- count: 1,
423
- config: {
424
- roles: [{name: 'spark.kms_orgagent'}]
425
- }
426
- })
427
- .then((users) => {
428
- jim = users[0];
525
+ before('create compliance officer test user', () =>
526
+ testUsers
527
+ .create({
528
+ count: 1,
529
+ config: {
530
+ roles: [{name: 'spark.kms_orgagent'}],
531
+ },
532
+ })
533
+ .then((users) => {
534
+ jim = users[0];
429
535
 
430
- jim.webex = new WebexCore({
431
- credentials: {
432
- authorization: jim.token
433
- }
434
- });
435
- assert.isTrue(jim.webex.canAuthorize);
436
- }));
536
+ jim.webex = new WebexCore({
537
+ credentials: {
538
+ authorization: jim.token,
539
+ },
540
+ });
541
+ assert.isTrue(jim.webex.canAuthorize);
542
+ })
543
+ );
437
544
 
438
545
  before('connect compliance officer to mercury', () => jim.webex.internal.mercury.connect());
439
546
 
@@ -441,62 +548,75 @@ describe('Encryption', function () {
441
548
 
442
549
  let key;
443
550
 
444
- it('retrieve key on behalf of another user', () => spock.webex.internal.encryption.kms.createUnboundKeys({count: 1})
445
- .then(([k]) => {
446
- key = k;
551
+ it('retrieve key on behalf of another user', () =>
552
+ spock.webex.internal.encryption.kms
553
+ .createUnboundKeys({count: 1})
554
+ .then(([k]) => {
555
+ key = k;
447
556
 
448
- // Compliance Officer Jim fetches a key on behalf of Spock
449
- return jim.webex.internal.encryption.kms.fetchKey({uri: key.uri, onBehalfOf: spock.id});
450
- })
451
- .then((key2) => {
452
- assert.property(key2, 'uri');
453
- assert.property(key2, 'jwk');
454
- assert.notEqual(key2, key);
455
- assert.equal(key2.uri, key.uri);
456
- }));
557
+ // Compliance Officer Jim fetches a key on behalf of Spock
558
+ return jim.webex.internal.encryption.kms.fetchKey({uri: key.uri, onBehalfOf: spock.id});
559
+ })
560
+ .then((key2) => {
561
+ assert.property(key2, 'uri');
562
+ assert.property(key2, 'jwk');
563
+ assert.notEqual(key2, key);
564
+ assert.equal(key2.uri, key.uri);
565
+ }));
457
566
 
458
- it('retrieve key on behalf of self', () => jim.webex.internal.encryption.kms.createUnboundKeys({count: 1})
459
- .then(([k]) => {
460
- key = k;
567
+ it('retrieve key on behalf of self', () =>
568
+ jim.webex.internal.encryption.kms
569
+ .createUnboundKeys({count: 1})
570
+ .then(([k]) => {
571
+ key = k;
461
572
 
462
- // Compliance Officer Jim fetches a key on behalf of himself
463
- // This covers an edge case documented by https://jira-eng-gpk2.cisco.com/jira/browse/SPARK-240862.
464
- return jim.webex.internal.encryption.kms.fetchKey({uri: key.uri, onBehalfOf: jim.id});
465
- })
466
- .then((key2) => {
467
- assert.property(key2, 'uri');
468
- assert.property(key2, 'jwk');
469
- assert.notEqual(key2, key);
470
- assert.equal(key2.uri, key.uri);
471
- }));
573
+ // Compliance Officer Jim fetches a key on behalf of himself
574
+ // This covers an edge case documented by https://jira-eng-gpk2.cisco.com/jira/browse/SPARK-240862.
575
+ return jim.webex.internal.encryption.kms.fetchKey({uri: key.uri, onBehalfOf: jim.id});
576
+ })
577
+ .then((key2) => {
578
+ assert.property(key2, 'uri');
579
+ assert.property(key2, 'jwk');
580
+ assert.notEqual(key2, key);
581
+ assert.equal(key2.uri, key.uri);
582
+ }));
472
583
 
473
584
  // Spock creates the key and Jim is not in the KRO so he should not have access
474
- it('retrieve key on behalf of self but self does not have access', () => spock.webex.internal.encryption.kms.createUnboundKeys({count: 1})
475
- .then(([k]) => {
476
- key = k;
477
-
478
- // Compliance Officer Jim fetches a key on behalf of himself but he is not in the KRO
479
- return jim.webex.internal.encryption.kms.fetchKey({uri: key.uri, onBehalfOf: jim.id});
480
- })
481
- .then(() => {
482
- expect.fail('It should not be possible to retrieve a key on behalf of another user without the spark.kms_orgagent role');
483
- })
484
- .catch((error) => {
485
- // Expect a Forbidden error
486
- expect(error.body.status).to.equal(403);
487
- }));
585
+ it('retrieve key on behalf of self but self does not have access', () =>
586
+ spock.webex.internal.encryption.kms
587
+ .createUnboundKeys({count: 1})
588
+ .then(([k]) => {
589
+ key = k;
488
590
 
591
+ // Compliance Officer Jim fetches a key on behalf of himself but he is not in the KRO
592
+ return jim.webex.internal.encryption.kms.fetchKey({uri: key.uri, onBehalfOf: jim.id});
593
+ })
594
+ .then(() => {
595
+ expect.fail(
596
+ 'It should not be possible to retrieve a key on behalf of another user without the spark.kms_orgagent role'
597
+ );
598
+ })
599
+ .catch((error) => {
600
+ // Expect a Forbidden error
601
+ expect(error.body.status).to.equal(403);
602
+ }));
489
603
 
490
- it('error retrieving key, on behalf of another user, without spark.kms_orgagent role',
491
- () => spock.webex.internal.encryption.kms.createUnboundKeys({count: 1})
604
+ it('error retrieving key, on behalf of another user, without spark.kms_orgagent role', () =>
605
+ spock.webex.internal.encryption.kms
606
+ .createUnboundKeys({count: 1})
492
607
  .then(([k]) => {
493
608
  key = k;
494
609
 
495
610
  // Normal user McCoy fails to fetch a key on behalf of Spock
496
- return mccoy.webex.internal.encryption.kms.fetchKey({uri: key.uri, onBehalfOf: spock.id});
611
+ return mccoy.webex.internal.encryption.kms.fetchKey({
612
+ uri: key.uri,
613
+ onBehalfOf: spock.id,
614
+ });
497
615
  })
498
616
  .then(() => {
499
- expect.fail('It should not be possible to retrieve a key on behalf of another user without the spark.kms_orgagent role');
617
+ expect.fail(
618
+ 'It should not be possible to retrieve a key on behalf of another user without the spark.kms_orgagent role'
619
+ );
500
620
  })
501
621
  .catch((error) => {
502
622
  // Expect a Forbidden error
@@ -508,33 +628,35 @@ describe('Encryption', function () {
508
628
 
509
629
  return Promise.all([
510
630
  spock.webex.internal.encryption.kms.createUnboundKeys({count: 1}),
511
- mccoy.webex.internal.encryption.kms.createUnboundKeys({count: 1})
512
- ]).then(([[spockK], [mccoyK]]) => {
513
- spockKey = spockK;
514
- mccoyKey = mccoyK;
515
-
516
- // Compliance Officer Jim fetches keys on behalf of users
517
- return Promise.all([
518
- jim.webex.internal.encryption.kms.fetchKey({uri: spockKey.uri, onBehalfOf: spock.id}),
519
- jim.webex.internal.encryption.kms.fetchKey({uri: mccoyKey.uri, onBehalfOf: mccoy.id})
520
- ]);
521
- }).then(([spockK, mccoyK]) => {
522
- assert.property(spockK, 'uri');
523
- assert.property(spockK, 'jwk');
524
- assert.notEqual(spockK, spockKey);
525
- assert.equal(spockK.uri, spockKey.uri);
526
-
527
- assert.property(mccoyK, 'uri');
528
- assert.property(mccoyK, 'jwk');
529
- assert.notEqual(mccoyK, mccoyKey);
530
- assert.equal(mccoyK.uri, mccoyKey.uri);
531
- });
631
+ mccoy.webex.internal.encryption.kms.createUnboundKeys({count: 1}),
632
+ ])
633
+ .then(([[spockK], [mccoyK]]) => {
634
+ spockKey = spockK;
635
+ mccoyKey = mccoyK;
636
+
637
+ // Compliance Officer Jim fetches keys on behalf of users
638
+ return Promise.all([
639
+ jim.webex.internal.encryption.kms.fetchKey({uri: spockKey.uri, onBehalfOf: spock.id}),
640
+ jim.webex.internal.encryption.kms.fetchKey({uri: mccoyKey.uri, onBehalfOf: mccoy.id}),
641
+ ]);
642
+ })
643
+ .then(([spockK, mccoyK]) => {
644
+ assert.property(spockK, 'uri');
645
+ assert.property(spockK, 'jwk');
646
+ assert.notEqual(spockK, spockKey);
647
+ assert.equal(spockK.uri, spockKey.uri);
648
+
649
+ assert.property(mccoyK, 'uri');
650
+ assert.property(mccoyK, 'jwk');
651
+ assert.notEqual(mccoyK, mccoyKey);
652
+ assert.equal(mccoyK.uri, mccoyKey.uri);
653
+ });
532
654
  });
533
655
  });
534
656
 
535
657
  describe('#ping()', () => {
536
- it('sends a ping to the kms', () => webex.internal.encryption.kms.ping()
537
- .then((res) => {
658
+ it('sends a ping to the kms', () =>
659
+ webex.internal.encryption.kms.ping().then((res) => {
538
660
  assert.property(res, 'status');
539
661
  assert.equal(res.status, 200);
540
662
  assert.property(res, 'requestId');
@@ -544,15 +666,16 @@ describe('Encryption', function () {
544
666
  describe('when ecdhe negotiation times out', () => {
545
667
  let originalKmsTimeout, webex2, spy;
546
668
 
547
- before('create test user', () => testUsers.create({count: 1})
548
- .then(([u]) => {
669
+ before('create test user', () =>
670
+ testUsers.create({count: 1}).then(([u]) => {
549
671
  webex2 = new WebexCore({
550
672
  credentials: {
551
- authorization: u.token
552
- }
673
+ authorization: u.token,
674
+ },
553
675
  });
554
676
  assert.isTrue(webex.canAuthorize);
555
- }));
677
+ })
678
+ );
556
679
 
557
680
  after(() => webex2 && webex2.internal.mercury.disconnect());
558
681
 
@@ -568,14 +691,18 @@ describe('Encryption', function () {
568
691
 
569
692
  afterEach(() => spy.restore());
570
693
 
571
- it('handles late ecdhe responses', () => webex2.internal.encryption.kms.ping()
572
- .then(() => {
694
+ it('handles late ecdhe responses', () =>
695
+ webex2.internal.encryption.kms.ping().then(() => {
573
696
  // callCount should be at least 3:
574
697
  // 1 for the initial ping message
575
698
  // 1 when the ecdh key gets renegotiated
576
699
  // 1 when the pings gets sent again
577
700
  debug(`ecdhe: spy call count: ${spy.callCount}`);
578
- assert.isAbove(spy.callCount, 2, 'If this test fails, we\'ve made previously-assumed-to-be-impossible performance gains in cloudapps; please update this test accordingly.');
701
+ assert.isAbove(
702
+ spy.callCount,
703
+ 2,
704
+ "If this test fails, we've made previously-assumed-to-be-impossible performance gains in cloudapps; please update this test accordingly."
705
+ );
579
706
  }));
580
707
 
581
708
  describe('when ecdhe is renegotiated', () => {
@@ -590,8 +717,8 @@ describe('Encryption', function () {
590
717
  webex2.config.encryption.ecdhMaxTimeout = ecdhMaxTimeout;
591
718
  });
592
719
 
593
- it('limits the number of retries', () => webex2.internal.encryption.kms.ping()
594
- .then(() => {
720
+ it('limits the number of retries', () =>
721
+ webex2.internal.encryption.kms.ping().then(() => {
595
722
  debug(`retry: spy call count: ${spy.callCount}`);
596
723
  assert.isBelow(spy.callCount, 5);
597
724
  }));
@@ -601,34 +728,37 @@ describe('Encryption', function () {
601
728
  describe('when the kms is in another org', () => {
602
729
  let fedWebex;
603
730
 
604
- before('create test user in other org', () => testUsers.create({
605
- count: 1,
606
- config: {
607
- email: `webex-js-sdk--kms-fed--${uuid.v4()}@wx2.example.com`,
608
- entitlements: ['webExSquared'],
609
- orgId: 'kmsFederation'
610
- }
611
- })
612
- .then((users) => {
613
- const fedUser = users[0];
731
+ before('create test user in other org', () =>
732
+ testUsers
733
+ .create({
734
+ count: 1,
735
+ config: {
736
+ email: `webex-js-sdk--kms-fed--${uuid.v4()}@wx2.example.com`,
737
+ entitlements: ['webExSquared'],
738
+ orgId: 'kmsFederation',
739
+ },
740
+ })
741
+ .then((users) => {
742
+ const fedUser = users[0];
614
743
 
615
- assert.equal(fedUser.orgId, '75dcf6c2-247d-4e3d-a32c-ff3ee28398eb');
616
- assert.notEqual(fedUser.orgId, spock.orgId);
744
+ assert.equal(fedUser.orgId, '75dcf6c2-247d-4e3d-a32c-ff3ee28398eb');
745
+ assert.notEqual(fedUser.orgId, spock.orgId);
617
746
 
618
- fedWebex = new WebexCore({
619
- credentials: {
620
- authorization: fedUser.token
621
- }
622
- });
623
- assert.isTrue(fedWebex.canAuthorize);
624
- }));
747
+ fedWebex = new WebexCore({
748
+ credentials: {
749
+ authorization: fedUser.token,
750
+ },
751
+ });
752
+ assert.isTrue(fedWebex.canAuthorize);
753
+ })
754
+ );
625
755
 
626
756
  before('connect federated user to mercury', () => fedWebex.internal.mercury.connect());
627
757
 
628
758
  after(() => fedWebex && fedWebex.internal.mercury.disconnect());
629
759
 
630
- it('responds to pings', () => fedWebex.internal.encryption.kms.ping()
631
- .then((res) => {
760
+ it('responds to pings', () =>
761
+ fedWebex.internal.encryption.kms.ping().then((res) => {
632
762
  assert.property(res, 'status');
633
763
  assert.equal(res.status, 200);
634
764
  assert.property(res, 'requestId');
@@ -636,37 +766,35 @@ describe('Encryption', function () {
636
766
 
637
767
  let key;
638
768
 
639
- it('lets federated users retrieve keys from the main org', () => webex.internal.encryption.kms.createUnboundKeys({count: 1})
640
- .then(([k]) => {
641
- key = k;
769
+ it('lets federated users retrieve keys from the main org', () =>
770
+ webex.internal.encryption.kms
771
+ .createUnboundKeys({count: 1})
772
+ .then(([k]) => {
773
+ key = k;
642
774
 
643
- return webex.internal.encryption.kms.createResource({
644
- userIds: [
645
- webex.internal.device.userId,
646
- fedWebex.internal.device.userId
647
- ],
648
- key
649
- });
650
- })
651
- .then(() => fedWebex.internal.encryption.kms.fetchKey({uri: key.uri}))
652
- .then((fedKey) => assert.equal(fedKey.keyUri, key.keyUri)));
775
+ return webex.internal.encryption.kms.createResource({
776
+ userIds: [webex.internal.device.userId, fedWebex.internal.device.userId],
777
+ key,
778
+ });
779
+ })
780
+ .then(() => fedWebex.internal.encryption.kms.fetchKey({uri: key.uri}))
781
+ .then((fedKey) => assert.equal(fedKey.keyUri, key.keyUri)));
653
782
 
654
783
  let fedKey;
655
784
 
656
- it('lets non-federated users retrieve keys from the federated org', () => fedWebex.internal.encryption.kms.createUnboundKeys({count: 1})
657
- .then(([k]) => {
658
- fedKey = k;
785
+ it('lets non-federated users retrieve keys from the federated org', () =>
786
+ fedWebex.internal.encryption.kms
787
+ .createUnboundKeys({count: 1})
788
+ .then(([k]) => {
789
+ fedKey = k;
659
790
 
660
- return fedWebex.internal.encryption.kms.createResource({
661
- userIds: [
662
- fedWebex.internal.device.userId,
663
- webex.internal.device.userId
664
- ],
665
- key: fedKey
666
- });
667
- })
668
- .then(() => webex.internal.encryption.kms.fetchKey({uri: fedKey.uri}))
669
- .then((key) => assert.equal(key.keyUri, fedKey.keyUri)));
791
+ return fedWebex.internal.encryption.kms.createResource({
792
+ userIds: [fedWebex.internal.device.userId, webex.internal.device.userId],
793
+ key: fedKey,
794
+ });
795
+ })
796
+ .then(() => webex.internal.encryption.kms.fetchKey({uri: fedKey.uri}))
797
+ .then((key) => assert.equal(key.keyUri, fedKey.keyUri)));
670
798
  });
671
799
  });
672
800
  });