@webex/internal-plugin-encryption 3.0.0-beta.4 → 3.0.0-beta.400
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.
- package/README.md +1 -3
- package/dist/config.js +0 -9
- package/dist/config.js.map +1 -1
- package/dist/constants.js +14 -0
- package/dist/constants.js.map +1 -0
- package/dist/encryption.js +25 -74
- package/dist/encryption.js.map +1 -1
- package/dist/ensure-buffer.browser.js +0 -12
- package/dist/ensure-buffer.browser.js.map +1 -1
- package/dist/ensure-buffer.js +5 -12
- package/dist/ensure-buffer.js.map +1 -1
- package/dist/index.js +7 -33
- package/dist/index.js.map +1 -1
- package/dist/kms-batcher.js +7 -30
- package/dist/kms-batcher.js.map +1 -1
- package/dist/kms-certificate-validation.js +24 -90
- package/dist/kms-certificate-validation.js.map +1 -1
- package/dist/kms-dry-error-interceptor.js +1 -23
- package/dist/kms-dry-error-interceptor.js.map +1 -1
- package/dist/kms-errors.js +21 -51
- package/dist/kms-errors.js.map +1 -1
- package/dist/kms.js +88 -218
- package/dist/kms.js.map +1 -1
- package/package.json +15 -15
- package/src/config.js +3 -3
- package/src/constants.js +3 -0
- package/src/encryption.js +74 -57
- package/src/ensure-buffer.browser.js +0 -1
- package/src/ensure-buffer.js +5 -5
- package/src/index.js +120 -96
- package/src/kms-batcher.js +53 -45
- package/src/kms-certificate-validation.js +48 -50
- package/src/kms-dry-error-interceptor.js +8 -4
- package/src/kms-errors.js +47 -16
- package/src/kms.js +219 -212
- package/test/integration/spec/encryption.js +313 -231
- package/test/integration/spec/kms.js +532 -405
- package/test/integration/spec/payload-transfom.js +69 -69
- package/test/unit/spec/encryption.js +21 -18
- package/test/unit/spec/kms-certificate-validation.js +76 -34
- package/test/unit/spec/kms-errors.js +70 -0
- package/test/unit/spec/kms.js +103 -0
|
@@ -17,39 +17,48 @@ describe('Encryption', function () {
|
|
|
17
17
|
|
|
18
18
|
let key, user, webex;
|
|
19
19
|
|
|
20
|
-
const PLAINTEXT =
|
|
20
|
+
const PLAINTEXT =
|
|
21
|
+
'Admiral, if we go "by the book". like Lieutenant Saavik, hours could seem like days.';
|
|
21
22
|
let FILE = makeLocalUrl('/sample-image-small-one.png');
|
|
22
23
|
|
|
23
|
-
before('create test user', () =>
|
|
24
|
-
.then((users) => {
|
|
24
|
+
before('create test user', () =>
|
|
25
|
+
testUsers.create({count: 1}).then((users) => {
|
|
25
26
|
user = users[0];
|
|
26
27
|
webex = new WebexCore({
|
|
27
28
|
credentials: {
|
|
28
|
-
authorization: user.token
|
|
29
|
-
}
|
|
29
|
+
authorization: user.token,
|
|
30
|
+
},
|
|
30
31
|
});
|
|
31
32
|
assert.isTrue(webex.isAuthenticated || webex.canAuthorize);
|
|
32
|
-
})
|
|
33
|
+
})
|
|
34
|
+
);
|
|
33
35
|
|
|
34
|
-
before('create unbound key', () =>
|
|
35
|
-
.then(([k]) => {
|
|
36
|
+
before('create unbound key', () =>
|
|
37
|
+
webex.internal.encryption.kms.createUnboundKeys({count: 1}).then(([k]) => {
|
|
36
38
|
key = k;
|
|
37
|
-
})
|
|
39
|
+
})
|
|
40
|
+
);
|
|
38
41
|
|
|
39
|
-
before('fetch file fixture', () =>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
before('fetch file fixture', () =>
|
|
43
|
+
webex
|
|
44
|
+
.request({
|
|
45
|
+
uri: FILE,
|
|
46
|
+
responseType: 'buffer',
|
|
47
|
+
})
|
|
48
|
+
.then((res) => {
|
|
49
|
+
FILE = res.body;
|
|
50
|
+
})
|
|
51
|
+
);
|
|
44
52
|
|
|
45
53
|
after(() => webex && webex.internal.mercury.disconnect());
|
|
46
54
|
|
|
47
55
|
describe('#decryptBinary()', () => {
|
|
48
|
-
it('decrypts a binary file', () =>
|
|
49
|
-
.then(({scr, cdata}) => {
|
|
56
|
+
it('decrypts a binary file', () =>
|
|
57
|
+
webex.internal.encryption.encryptBinary(FILE).then(({scr, cdata}) => {
|
|
50
58
|
scr.loc = 'file:///file.enc';
|
|
51
59
|
|
|
52
|
-
return webex.internal.encryption
|
|
60
|
+
return webex.internal.encryption
|
|
61
|
+
.encryptScr(key, scr)
|
|
53
62
|
.then((cipherScr) => webex.internal.encryption.decryptScr(key, cipherScr))
|
|
54
63
|
.then((decryptedScr) => webex.internal.encryption.decryptBinary(decryptedScr, cdata))
|
|
55
64
|
.then((f) => {
|
|
@@ -61,47 +70,50 @@ describe('Encryption', function () {
|
|
|
61
70
|
});
|
|
62
71
|
|
|
63
72
|
describe('#decryptScr()', () => {
|
|
64
|
-
it('decrypts an scr', () =>
|
|
65
|
-
.then(({scr}) => {
|
|
73
|
+
it('decrypts an scr', () =>
|
|
74
|
+
webex.internal.encryption.encryptBinary(FILE).then(({scr}) => {
|
|
66
75
|
scr.loc = 'file:///file.enc';
|
|
67
76
|
|
|
68
|
-
return webex.internal.encryption
|
|
77
|
+
return webex.internal.encryption
|
|
78
|
+
.encryptScr(key, scr)
|
|
69
79
|
.then((cipherScr) => webex.internal.encryption.decryptScr(key, cipherScr))
|
|
70
80
|
.then((decryptedScr) => assert.deepEqual(decryptedScr, scr));
|
|
71
81
|
}));
|
|
72
82
|
});
|
|
73
83
|
|
|
74
84
|
describe('#decryptText()', () => {
|
|
75
|
-
it('decrypts text', () =>
|
|
76
|
-
.
|
|
77
|
-
|
|
85
|
+
it('decrypts text', () =>
|
|
86
|
+
webex.internal.encryption
|
|
87
|
+
.encryptText(key, PLAINTEXT)
|
|
88
|
+
.then((ciphertext) => {
|
|
89
|
+
assert.notEqual(ciphertext, PLAINTEXT);
|
|
78
90
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
91
|
+
return webex.internal.encryption.decryptText(key, ciphertext);
|
|
92
|
+
})
|
|
93
|
+
.then((plaintext) => assert.equal(plaintext, PLAINTEXT)));
|
|
82
94
|
});
|
|
83
95
|
|
|
84
96
|
describe('#getKey()', () => {
|
|
85
97
|
let fetchKeySpy, otherWebex, otherUser, storageGetSpy;
|
|
86
98
|
|
|
87
|
-
before('create test user', () =>
|
|
88
|
-
.then((users) => {
|
|
99
|
+
before('create test user', () =>
|
|
100
|
+
testUsers.create({count: 1}).then((users) => {
|
|
89
101
|
otherUser = users[0];
|
|
90
102
|
otherWebex = new WebexCore({
|
|
91
103
|
credentials: {
|
|
92
|
-
authorization: otherUser.token
|
|
93
|
-
}
|
|
104
|
+
authorization: otherUser.token,
|
|
105
|
+
},
|
|
94
106
|
});
|
|
95
107
|
assert.isTrue(otherWebex.canAuthorize);
|
|
96
|
-
})
|
|
108
|
+
})
|
|
109
|
+
);
|
|
97
110
|
|
|
98
|
-
before('create kms resource', () =>
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
webex.internal.device.userId,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}));
|
|
111
|
+
before('create kms resource', () =>
|
|
112
|
+
webex.internal.encryption.kms.createResource({
|
|
113
|
+
key,
|
|
114
|
+
userIds: [webex.internal.device.userId, otherUser.id],
|
|
115
|
+
})
|
|
116
|
+
);
|
|
105
117
|
|
|
106
118
|
after(() => otherWebex && otherWebex.internal.mercury.disconnect());
|
|
107
119
|
|
|
@@ -115,141 +127,174 @@ describe('Encryption', function () {
|
|
|
115
127
|
storageGetSpy.restore();
|
|
116
128
|
});
|
|
117
129
|
|
|
118
|
-
it('shortcircuits if it receives a key instead of a keyUri', () =>
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
assert.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
130
|
+
it('shortcircuits if it receives a key instead of a keyUri', () =>
|
|
131
|
+
webex.internal.encryption
|
|
132
|
+
.getKey(key)
|
|
133
|
+
// Reminder: If this starts failing after a node-jose upgrade, it probably
|
|
134
|
+
// implies node-jose stopped shortcircuiting correctly.
|
|
135
|
+
.then((k) => assert.equal(k, key)));
|
|
136
|
+
|
|
137
|
+
it('attempts to retrieve the specified key from the local cache', () =>
|
|
138
|
+
otherWebex.internal.encryption
|
|
139
|
+
.getKey(key.uri)
|
|
140
|
+
.then((k) => assert.calledWith(storageGetSpy, k.uri)));
|
|
141
|
+
|
|
142
|
+
it('fetches the key from the kms', () =>
|
|
143
|
+
otherWebex.internal.encryption.unboundedStorage
|
|
144
|
+
.del(key.uri)
|
|
145
|
+
.then(() => assert.notCalled(fetchKeySpy))
|
|
146
|
+
.then(() => otherWebex.internal.encryption.getKey(key.uri))
|
|
147
|
+
.then(() => assert.calledOnce(fetchKeySpy)));
|
|
148
|
+
|
|
149
|
+
it('stores the newly retrieved key', () =>
|
|
150
|
+
otherWebex.internal.encryption
|
|
151
|
+
.getKey(key.uri)
|
|
152
|
+
.then((k) => otherWebex.internal.encryption.unboundedStorage.get(k.uri))
|
|
153
|
+
.then((str) => JSON.parse(str))
|
|
154
|
+
.then((k2) => {
|
|
155
|
+
assert.property(k2, 'jwk');
|
|
156
|
+
assert.property(k2.jwk, 'k');
|
|
157
|
+
assert.equal(key.jwk.kid, k2.jwk.kid);
|
|
158
|
+
}));
|
|
139
159
|
});
|
|
140
160
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
161
|
+
// SPARK-413317
|
|
162
|
+
describe.skip('#download()', () => {
|
|
163
|
+
it('downloads and decrypts an encrypted file', () =>
|
|
164
|
+
webex.internal.encryption
|
|
165
|
+
.encryptBinary(FILE)
|
|
166
|
+
.then(({scr, cdata}) =>
|
|
167
|
+
webex
|
|
168
|
+
.request({
|
|
169
|
+
method: 'POST',
|
|
170
|
+
uri: makeLocalUrl('/files/upload'),
|
|
171
|
+
body: cdata,
|
|
172
|
+
})
|
|
173
|
+
.then((res) => {
|
|
174
|
+
scr.loc = makeLocalUrl(res.body.loc, {full: true});
|
|
175
|
+
|
|
176
|
+
return webex.internal.encryption.encryptScr(key, scr);
|
|
177
|
+
})
|
|
178
|
+
)
|
|
179
|
+
.then((cipherScr) => webex.internal.encryption.decryptScr(key, cipherScr))
|
|
180
|
+
.then((scr) => webex.internal.encryption.download(scr))
|
|
181
|
+
.then((f) =>
|
|
182
|
+
file.isMatchingFile(f, FILE).then((result) => assert.deepEqual(result, true))
|
|
183
|
+
));
|
|
184
|
+
|
|
185
|
+
it('downloads and decrypts an encrypted file with options param', () =>
|
|
186
|
+
webex.internal.encryption
|
|
187
|
+
.encryptBinary(FILE)
|
|
188
|
+
.then(({scr, cdata}) =>
|
|
189
|
+
webex
|
|
190
|
+
.request({
|
|
191
|
+
method: 'POST',
|
|
192
|
+
uri: makeLocalUrl('/files/upload'),
|
|
193
|
+
body: cdata,
|
|
194
|
+
})
|
|
195
|
+
.then((res) => {
|
|
196
|
+
scr.loc = makeLocalUrl(res.body.loc, {full: true});
|
|
197
|
+
|
|
198
|
+
return webex.internal.encryption.encryptScr(key, scr);
|
|
199
|
+
})
|
|
200
|
+
)
|
|
201
|
+
.then((cipherScr) => webex.internal.encryption.decryptScr(key, cipherScr))
|
|
202
|
+
.then((scr) => {
|
|
203
|
+
const options = {
|
|
204
|
+
params: {
|
|
205
|
+
allow: 'none',
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
return webex.internal.encryption.download(scr, options);
|
|
210
|
+
})
|
|
211
|
+
.then((f) => file.isMatchingFile(f, FILE))
|
|
212
|
+
.then((result) => assert.deepEqual(result, true)));
|
|
181
213
|
|
|
182
214
|
it('emits progress events', () => {
|
|
183
215
|
const spy = sinon.spy();
|
|
184
216
|
|
|
185
|
-
return webex.internal.encryption
|
|
186
|
-
.
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
217
|
+
return webex.internal.encryption
|
|
218
|
+
.encryptBinary(FILE)
|
|
219
|
+
.then(({scr, cdata}) =>
|
|
220
|
+
webex
|
|
221
|
+
.request({
|
|
222
|
+
method: 'POST',
|
|
223
|
+
uri: makeLocalUrl('/files/upload'),
|
|
224
|
+
body: cdata,
|
|
225
|
+
})
|
|
226
|
+
.then((res) => {
|
|
227
|
+
scr.loc = makeLocalUrl(res.body.loc, {full: true});
|
|
228
|
+
|
|
229
|
+
return webex.internal.encryption.encryptScr(key, scr);
|
|
230
|
+
})
|
|
231
|
+
)
|
|
196
232
|
.then((cipherScr) => webex.internal.encryption.decryptScr(key, cipherScr))
|
|
197
|
-
.then((scr) => webex.internal.encryption.download(scr)
|
|
198
|
-
.on('progress', spy))
|
|
233
|
+
.then((scr) => webex.internal.encryption.download(scr).on('progress', spy))
|
|
199
234
|
.then(() => assert.called(spy));
|
|
200
235
|
});
|
|
201
236
|
|
|
202
|
-
it('checks body of the API call /downloads/endpoints', () =>
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
237
|
+
it('checks body of the API call /downloads/endpoints', () =>
|
|
238
|
+
webex.internal.encryption
|
|
239
|
+
.encryptBinary(FILE)
|
|
240
|
+
.then(({scr, cdata}) =>
|
|
241
|
+
webex
|
|
242
|
+
.request({
|
|
243
|
+
method: 'POST',
|
|
244
|
+
uri: makeLocalUrl('/files/upload'),
|
|
245
|
+
body: cdata,
|
|
246
|
+
})
|
|
247
|
+
.then((res) => {
|
|
248
|
+
scr.loc = makeLocalUrl(res.body.loc, {full: true});
|
|
249
|
+
|
|
250
|
+
return webex.internal.encryption.encryptScr(key, scr);
|
|
251
|
+
})
|
|
252
|
+
)
|
|
253
|
+
.then((cipherScr) => webex.internal.encryption.decryptScr(key, cipherScr))
|
|
254
|
+
.then((scr) => {
|
|
255
|
+
const options = {
|
|
256
|
+
params: {
|
|
257
|
+
allow: ['unchecked', 'evaluating'],
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
return webex.internal.encryption.download(scr, options);
|
|
262
|
+
})
|
|
263
|
+
.then((f) => file.isMatchingFile(f, FILE))
|
|
264
|
+
.then((result) => assert.deepEqual(result, true)));
|
|
265
|
+
|
|
266
|
+
it('checks _fetchDownloadUrl()', () =>
|
|
267
|
+
webex.internal.encryption
|
|
268
|
+
.encryptBinary(FILE)
|
|
269
|
+
.then(({scr, cdata}) =>
|
|
270
|
+
webex
|
|
271
|
+
.request({
|
|
272
|
+
method: 'POST',
|
|
273
|
+
uri: makeLocalUrl('/files/upload'),
|
|
274
|
+
body: cdata,
|
|
275
|
+
})
|
|
276
|
+
.then((res) => {
|
|
277
|
+
scr.loc = makeLocalUrl(res.body.loc, {full: true});
|
|
278
|
+
|
|
279
|
+
return webex.internal.encryption.encryptScr(key, scr);
|
|
280
|
+
})
|
|
281
|
+
)
|
|
282
|
+
.then((cipherScr) => webex.internal.encryption.decryptScr(key, cipherScr))
|
|
283
|
+
.then((scr) => {
|
|
284
|
+
const options = {
|
|
285
|
+
params: {
|
|
286
|
+
allow: ['unchecked', 'evaluating'],
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
return webex.internal.encryption._fetchDownloadUrl(scr, options);
|
|
291
|
+
})
|
|
292
|
+
.then((result) => assert.isString(result)));
|
|
248
293
|
});
|
|
249
294
|
|
|
250
295
|
describe('#encryptBinary()', () => {
|
|
251
|
-
it('encrypts a binary file', () =>
|
|
252
|
-
.then(({scr, cdata}) => {
|
|
296
|
+
it('encrypts a binary file', () =>
|
|
297
|
+
webex.internal.encryption.encryptBinary(FILE).then(({scr, cdata}) => {
|
|
253
298
|
assert.property(scr, 'enc');
|
|
254
299
|
assert.property(scr, 'key');
|
|
255
300
|
assert.property(scr, 'iv');
|
|
@@ -262,106 +307,143 @@ describe('Encryption', function () {
|
|
|
262
307
|
});
|
|
263
308
|
|
|
264
309
|
describe('#encryptScr()', () => {
|
|
265
|
-
it('encrypts an scr', () =>
|
|
266
|
-
.
|
|
267
|
-
|
|
310
|
+
it('encrypts an scr', () =>
|
|
311
|
+
webex.internal.encryption
|
|
312
|
+
.encryptBinary(FILE)
|
|
313
|
+
.then(({scr}) => {
|
|
314
|
+
scr.loc = 'file:///file.enc';
|
|
268
315
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
316
|
+
return webex.internal.encryption.encryptScr(key, scr);
|
|
317
|
+
})
|
|
318
|
+
.then((cipherScr) => assert.isString(cipherScr)));
|
|
272
319
|
});
|
|
273
320
|
|
|
274
321
|
describe('#encryptText()', () => {
|
|
275
|
-
it('encrypts text', () =>
|
|
276
|
-
.
|
|
322
|
+
it('encrypts text', () =>
|
|
323
|
+
webex.internal.encryption
|
|
324
|
+
.encryptText(key, PLAINTEXT)
|
|
325
|
+
.then((ciphertext) => assert.notEqual(ciphertext, PLAINTEXT)));
|
|
277
326
|
});
|
|
278
327
|
|
|
279
328
|
describe('#onBehalfOf', () => {
|
|
280
329
|
let complianceUser;
|
|
281
330
|
|
|
282
|
-
before('create compliance officer test user', () =>
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
331
|
+
before('create compliance officer test user', () =>
|
|
332
|
+
testUsers
|
|
333
|
+
.create({
|
|
334
|
+
count: 1,
|
|
335
|
+
config: {
|
|
336
|
+
roles: [{name: 'spark.kms_orgagent'}],
|
|
337
|
+
},
|
|
338
|
+
})
|
|
339
|
+
.then((users) => {
|
|
340
|
+
complianceUser = users[0];
|
|
341
|
+
complianceUser.webex = new WebexCore({
|
|
342
|
+
credentials: {
|
|
343
|
+
authorization: complianceUser.token,
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
assert.isTrue(complianceUser.webex.canAuthorize);
|
|
347
|
+
})
|
|
348
|
+
);
|
|
297
349
|
|
|
298
350
|
after(() => complianceUser && complianceUser.webex.internal.mercury.disconnect());
|
|
299
351
|
|
|
300
|
-
it('decrypt text', () =>
|
|
301
|
-
.
|
|
302
|
-
|
|
352
|
+
it('decrypt text', () =>
|
|
353
|
+
webex.internal.encryption
|
|
354
|
+
.encryptText(key, PLAINTEXT)
|
|
355
|
+
.then((ciphertext) => {
|
|
356
|
+
assert.notEqual(ciphertext, PLAINTEXT);
|
|
303
357
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
358
|
+
return complianceUser.webex.internal.encryption.decryptText(key, ciphertext, {
|
|
359
|
+
onBehalfOf: user.id,
|
|
360
|
+
});
|
|
361
|
+
})
|
|
362
|
+
.then((plaintext) => assert.equal(plaintext, PLAINTEXT)));
|
|
307
363
|
|
|
308
|
-
it('encrypt and decrypt text', () =>
|
|
309
|
-
.
|
|
310
|
-
|
|
364
|
+
it('encrypt and decrypt text', () =>
|
|
365
|
+
complianceUser.webex.internal.encryption
|
|
366
|
+
.encryptText(key, PLAINTEXT, {onBehalfOf: user.id})
|
|
367
|
+
.then((ciphertext) => {
|
|
368
|
+
assert.notEqual(ciphertext, PLAINTEXT);
|
|
311
369
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
370
|
+
return complianceUser.webex.internal.encryption.decryptText(key, ciphertext, {
|
|
371
|
+
onBehalfOf: user.id,
|
|
372
|
+
});
|
|
373
|
+
})
|
|
374
|
+
.then((plaintext) => assert.equal(plaintext, PLAINTEXT)));
|
|
315
375
|
|
|
316
|
-
it('decrypt scr', () =>
|
|
317
|
-
.then(({scr}) => {
|
|
376
|
+
it('decrypt scr', () =>
|
|
377
|
+
webex.internal.encryption.encryptBinary(FILE).then(({scr}) => {
|
|
318
378
|
scr.loc = 'file:///file.enc';
|
|
319
379
|
|
|
320
|
-
return webex.internal.encryption
|
|
321
|
-
.
|
|
380
|
+
return webex.internal.encryption
|
|
381
|
+
.encryptScr(key, scr)
|
|
382
|
+
.then((cipherScr) =>
|
|
383
|
+
complianceUser.webex.internal.encryption.decryptScr(key, cipherScr, {
|
|
384
|
+
onBehalfOf: user.id,
|
|
385
|
+
})
|
|
386
|
+
)
|
|
322
387
|
.then((decryptedScr) => assert.deepEqual(decryptedScr, scr));
|
|
323
388
|
}));
|
|
324
389
|
|
|
325
|
-
it('decrypt scr', () =>
|
|
326
|
-
.then(({scr}) => {
|
|
390
|
+
it('decrypt scr', () =>
|
|
391
|
+
webex.internal.encryption.encryptBinary(FILE).then(({scr}) => {
|
|
327
392
|
scr.loc = 'file:///file.enc';
|
|
328
393
|
|
|
329
|
-
return complianceUser.webex.internal.encryption
|
|
330
|
-
.
|
|
394
|
+
return complianceUser.webex.internal.encryption
|
|
395
|
+
.encryptScr(key, scr, {onBehalfOf: user.id})
|
|
396
|
+
.then((cipherScr) =>
|
|
397
|
+
complianceUser.webex.internal.encryption.decryptScr(key, cipherScr, {
|
|
398
|
+
onBehalfOf: user.id,
|
|
399
|
+
})
|
|
400
|
+
)
|
|
331
401
|
.then((decryptedScr) => assert.deepEqual(decryptedScr, scr));
|
|
332
402
|
}));
|
|
333
403
|
|
|
334
|
-
it('getKey', () =>
|
|
335
|
-
.
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
404
|
+
it('getKey', () =>
|
|
405
|
+
complianceUser.webex.internal.encryption
|
|
406
|
+
.getKey(key.uri, {onBehalfOf: user.id})
|
|
407
|
+
.then((key2) => {
|
|
408
|
+
assert.property(key2, 'uri');
|
|
409
|
+
assert.property(key2, 'jwk');
|
|
410
|
+
assert.notEqual(key2, key);
|
|
411
|
+
assert.equal(key2.uri, key.uri);
|
|
412
|
+
}));
|
|
413
|
+
|
|
414
|
+
it('getKey forbidden as compliance officer does not have access', () =>
|
|
415
|
+
complianceUser.webex.internal.encryption.getKey(key.uri).then(
|
|
344
416
|
(value) => expect.fail(`Compliance officer has retrieved key without onBehalfOf: ${value}`),
|
|
345
417
|
(error) => expect(error.body.status).to.equal(403)
|
|
346
418
|
));
|
|
347
419
|
|
|
348
|
-
it('getKey forbidden as user does not have access', () =>
|
|
349
|
-
.
|
|
350
|
-
(
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
420
|
+
it('getKey forbidden as user does not have access', () =>
|
|
421
|
+
complianceUser.webex.internal.encryption
|
|
422
|
+
.getKey(key.uri, {onBehalfOf: '7851fe79-7c87-40cc-ac36-8b77b011b399'})
|
|
423
|
+
.then(
|
|
424
|
+
(value) =>
|
|
425
|
+
expect.fail(
|
|
426
|
+
`Should not be found as 7851fe79-7c87-40cc-ac36-8b77b011b399 does not have access ${value}`
|
|
427
|
+
),
|
|
428
|
+
(error) => expect(error.body.status).to.equal(403)
|
|
429
|
+
));
|
|
430
|
+
|
|
431
|
+
it('getKey onBehalfOf and then by compliance officer only', () =>
|
|
432
|
+
complianceUser.webex.internal.encryption
|
|
433
|
+
.getKey(key.uri, {onBehalfOf: user.id})
|
|
434
|
+
.then((key2) => {
|
|
435
|
+
assert.property(key2, 'uri');
|
|
436
|
+
assert.property(key2, 'jwk');
|
|
437
|
+
assert.notEqual(key2, key);
|
|
438
|
+
assert.equal(key2.uri, key.uri);
|
|
439
|
+
})
|
|
440
|
+
.then(() => complianceUser.webex.internal.encryption.getKey(key.uri))
|
|
441
|
+
.then(
|
|
442
|
+
(value) =>
|
|
443
|
+
expect.fail(
|
|
444
|
+
`Compliance should no longer be able to retrieve key as onBehalfOf was not set: ${value}`
|
|
445
|
+
),
|
|
446
|
+
(error) => expect(error.body.status).to.equal(403)
|
|
447
|
+
));
|
|
366
448
|
});
|
|
367
449
|
});
|