@webex/internal-plugin-encryption 2.59.2 → 2.59.3-next.1

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 (42) hide show
  1. package/.eslintrc.js +6 -6
  2. package/README.md +42 -42
  3. package/babel.config.js +3 -3
  4. package/dist/config.js +21 -21
  5. package/dist/config.js.map +1 -1
  6. package/dist/encryption.js +57 -57
  7. package/dist/encryption.js.map +1 -1
  8. package/dist/ensure-buffer.browser.js +7 -7
  9. package/dist/ensure-buffer.browser.js.map +1 -1
  10. package/dist/ensure-buffer.js +7 -7
  11. package/dist/ensure-buffer.js.map +1 -1
  12. package/dist/index.js +2 -2
  13. package/dist/index.js.map +1 -1
  14. package/dist/kms-batcher.js +38 -38
  15. package/dist/kms-batcher.js.map +1 -1
  16. package/dist/kms-certificate-validation.js +50 -50
  17. package/dist/kms-certificate-validation.js.map +1 -1
  18. package/dist/kms-dry-error-interceptor.js +15 -15
  19. package/dist/kms-dry-error-interceptor.js.map +1 -1
  20. package/dist/kms-errors.js +16 -16
  21. package/dist/kms-errors.js.map +1 -1
  22. package/dist/kms.js +171 -171
  23. package/dist/kms.js.map +1 -1
  24. package/jest.config.js +3 -3
  25. package/package.json +20 -19
  26. package/process +1 -1
  27. package/src/config.js +50 -50
  28. package/src/encryption.js +257 -257
  29. package/src/ensure-buffer.browser.js +37 -37
  30. package/src/ensure-buffer.js +20 -20
  31. package/src/index.js +159 -159
  32. package/src/kms-batcher.js +158 -158
  33. package/src/kms-certificate-validation.js +232 -232
  34. package/src/kms-dry-error-interceptor.js +65 -65
  35. package/src/kms-errors.js +147 -147
  36. package/src/kms.js +848 -848
  37. package/test/integration/spec/encryption.js +448 -448
  38. package/test/integration/spec/kms.js +800 -800
  39. package/test/integration/spec/payload-transfom.js +97 -97
  40. package/test/unit/spec/encryption.js +82 -82
  41. package/test/unit/spec/kms-certificate-validation.js +165 -165
  42. package/test/unit/spec/kms.js +103 -103
@@ -1,97 +1,97 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import {DryError} from '@webex/internal-plugin-encryption';
6
- import {assert} from '@webex/test-helper-chai';
7
- import {base64} from '@webex/common';
8
- import WebexCore from '@webex/webex-core';
9
- import testUsers from '@webex/test-helper-test-users';
10
-
11
- describe('plugin-encryption', () => {
12
- let other, webex;
13
-
14
- before('create test user', () =>
15
- testUsers.create({count: 2}).then(([user, o]) => {
16
- other = o;
17
- console.log(o);
18
- webex = new WebexCore({
19
- credentials: {
20
- authorization: user.token,
21
- },
22
- });
23
- assert.isTrue(webex.isAuthenticated || webex.canAuthorize);
24
- })
25
- );
26
-
27
- before('register with wdm', () => webex.internal.device.register());
28
-
29
- describe('when a DRY response has an error', () => {
30
- it('decrypts the error message', () =>
31
- assert
32
- .isRejected(
33
- webex.request({
34
- method: 'POST',
35
- service: 'conversation',
36
- resource: 'conversations',
37
- body: {
38
- activities: {
39
- items: [
40
- {
41
- actor: {
42
- objectType: 'person',
43
- id: webex.internal.device.userId,
44
- },
45
- objectType: 'activity',
46
- verb: 'create',
47
- },
48
- {
49
- actor: {
50
- objectType: 'person',
51
- id: webex.internal.device.userId,
52
- },
53
- object: {
54
- objectType: 'person',
55
- id: webex.internal.device.userId,
56
- },
57
- objectType: 'activity',
58
- verb: 'add',
59
- },
60
- {
61
- actor: {
62
- objectType: 'person',
63
- id: webex.internal.device.userId,
64
- },
65
- object: {
66
- objectType: 'person',
67
- id: other.id,
68
- },
69
- objectType: 'activity',
70
- verb: 'add',
71
- },
72
- ],
73
- },
74
- defaultActivityEncryptionKeyUrl: 'kms://fakeuri',
75
- objectType: 'conversation',
76
- kmsMessage: {
77
- method: 'create',
78
- uri: '/resource',
79
- userIds: [webex.internal.device.userId, other.id],
80
- keyUris: ['kms://fakeuri'],
81
- },
82
- },
83
- })
84
- )
85
- .then((err) => {
86
- assert.statusCode(err, 400);
87
- assert.throws(() => {
88
- base64.decode(err.body.message.split('.')[0]);
89
- });
90
- assert.match(err.toString(), /POST .+\s/);
91
- assert.match(err.toString(), /WEBEX_TRACKING_ID: .+\s/);
92
- assert.match(err.toString(), /KMS_RESPONSE_STATUS: .+\s/);
93
- assert.match(err.toString(), /KMS_REQUEST_ID: .+/);
94
- assert.instanceOf(err, DryError);
95
- }));
96
- });
97
- });
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {DryError} from '@webex/internal-plugin-encryption';
6
+ import {assert} from '@webex/test-helper-chai';
7
+ import {base64} from '@webex/common';
8
+ import WebexCore from '@webex/webex-core';
9
+ import testUsers from '@webex/test-helper-test-users';
10
+
11
+ describe('plugin-encryption', () => {
12
+ let other, webex;
13
+
14
+ before('create test user', () =>
15
+ testUsers.create({count: 2}).then(([user, o]) => {
16
+ other = o;
17
+ console.log(o);
18
+ webex = new WebexCore({
19
+ credentials: {
20
+ authorization: user.token,
21
+ },
22
+ });
23
+ assert.isTrue(webex.isAuthenticated || webex.canAuthorize);
24
+ })
25
+ );
26
+
27
+ before('register with wdm', () => webex.internal.device.register());
28
+
29
+ describe('when a DRY response has an error', () => {
30
+ it('decrypts the error message', () =>
31
+ assert
32
+ .isRejected(
33
+ webex.request({
34
+ method: 'POST',
35
+ service: 'conversation',
36
+ resource: 'conversations',
37
+ body: {
38
+ activities: {
39
+ items: [
40
+ {
41
+ actor: {
42
+ objectType: 'person',
43
+ id: webex.internal.device.userId,
44
+ },
45
+ objectType: 'activity',
46
+ verb: 'create',
47
+ },
48
+ {
49
+ actor: {
50
+ objectType: 'person',
51
+ id: webex.internal.device.userId,
52
+ },
53
+ object: {
54
+ objectType: 'person',
55
+ id: webex.internal.device.userId,
56
+ },
57
+ objectType: 'activity',
58
+ verb: 'add',
59
+ },
60
+ {
61
+ actor: {
62
+ objectType: 'person',
63
+ id: webex.internal.device.userId,
64
+ },
65
+ object: {
66
+ objectType: 'person',
67
+ id: other.id,
68
+ },
69
+ objectType: 'activity',
70
+ verb: 'add',
71
+ },
72
+ ],
73
+ },
74
+ defaultActivityEncryptionKeyUrl: 'kms://fakeuri',
75
+ objectType: 'conversation',
76
+ kmsMessage: {
77
+ method: 'create',
78
+ uri: '/resource',
79
+ userIds: [webex.internal.device.userId, other.id],
80
+ keyUris: ['kms://fakeuri'],
81
+ },
82
+ },
83
+ })
84
+ )
85
+ .then((err) => {
86
+ assert.statusCode(err, 400);
87
+ assert.throws(() => {
88
+ base64.decode(err.body.message.split('.')[0]);
89
+ });
90
+ assert.match(err.toString(), /POST .+\s/);
91
+ assert.match(err.toString(), /WEBEX_TRACKING_ID: .+\s/);
92
+ assert.match(err.toString(), /KMS_RESPONSE_STATUS: .+\s/);
93
+ assert.match(err.toString(), /KMS_REQUEST_ID: .+/);
94
+ assert.instanceOf(err, DryError);
95
+ }));
96
+ });
97
+ });
@@ -1,82 +1,82 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
- /* eslint-disable no-underscore-dangle */
5
- import Url from 'url';
6
-
7
- import {assert} from '@webex/test-helper-chai';
8
- import MockWebex from '@webex/test-helper-mock-webex';
9
- import sinon from 'sinon';
10
- import Encryption from '@webex/internal-plugin-encryption';
11
-
12
- describe('internal-plugin-encryption', () => {
13
- describe('download', () => {
14
- let webex;
15
-
16
- beforeEach(() => {
17
- webex = new MockWebex({
18
- children: {
19
- encryption: Encryption,
20
- },
21
- });
22
- });
23
-
24
- describe('check _fetchDownloadUrl()', () => {
25
- const scrArray = [
26
- {
27
- loc: 'https://files-api-intb1.ciscospark.com/v1/spaces/a0cba376-fc05-4b88-af4b-cfffa7465f9a/contents/1d3931e7-9e31-46bc-8084-d766a8f72c99/versions/5fa9caf87a98410aae49e0173856a974/bytes',
28
- },
29
- {
30
- loc: 'https://files-api-intb2.ciscospark.com/v1/spaces/a0cba376-fc05-4b88-af4b-cfffa7465f9a/contents/1d3931e7-9e31-46bc-8084-d766a8f72c99/versions/5fa9caf87a98410aae49e0173856a974/bytes',
31
- },
32
- {
33
- loc: 'https://www.test-api.com/v1/spaces/test-path-name-space/contents/test-path-name-contents/versions/test-version/bytes',
34
- },
35
- {
36
- loc: 'http://www.test-api.com/v1/spaces/test-path-name-space/contents/test-path-name-contents/versions/test-version/bytes',
37
- },
38
- ];
39
- const options = undefined;
40
- let spyStub;
41
-
42
- beforeEach(() => {
43
- const returnStub = (obj) => Promise.resolve(obj);
44
-
45
- spyStub = sinon.stub(webex.internal.encryption, 'request').callsFake(returnStub);
46
-
47
- scrArray.forEach((scr) => webex.internal.encryption._fetchDownloadUrl(scr, options));
48
- });
49
-
50
- it('verifying file service uris', () => {
51
- assert.equal(
52
- spyStub.args[0][0].uri,
53
- 'https://files-api-intb1.ciscospark.com/v1/download/endpoints'
54
- );
55
- assert.equal(
56
- spyStub.args[1][0].uri,
57
- 'https://files-api-intb2.ciscospark.com/v1/download/endpoints'
58
- );
59
- assert.equal(spyStub.args[2][0].uri, 'https://www.test-api.com/v1/download/endpoints');
60
- assert.equal(spyStub.args[3][0].uri, 'https://www.test-api.com/v1/download/endpoints');
61
- });
62
-
63
- it('verifying https', () => {
64
- assert.equal(Url.parse(spyStub.args[0][0].uri).protocol, 'https:');
65
- assert.equal(Url.parse(spyStub.args[1][0].uri).protocol, 'https:');
66
- assert.equal(Url.parse(spyStub.args[2][0].uri).protocol, 'https:');
67
- assert.equal(Url.parse(spyStub.args[3][0].uri).protocol, 'https:');
68
- });
69
-
70
- it('verifying endpoints', () => {
71
- assert.equal(spyStub.args[0][0].body.endpoints[0], scrArray[0].loc);
72
- assert.equal(spyStub.args[1][0].body.endpoints[0], scrArray[1].loc);
73
- assert.equal(spyStub.args[2][0].body.endpoints[0], scrArray[2].loc);
74
- assert.equal(spyStub.args[3][0].body.endpoints[0], scrArray[3].loc);
75
- });
76
-
77
- afterEach(() => {
78
- spyStub.resetHistory();
79
- });
80
- });
81
- });
82
- });
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+ /* eslint-disable no-underscore-dangle */
5
+ import Url from 'url';
6
+
7
+ import {assert} from '@webex/test-helper-chai';
8
+ import MockWebex from '@webex/test-helper-mock-webex';
9
+ import sinon from 'sinon';
10
+ import Encryption from '@webex/internal-plugin-encryption';
11
+
12
+ describe('internal-plugin-encryption', () => {
13
+ describe('download', () => {
14
+ let webex;
15
+
16
+ beforeEach(() => {
17
+ webex = new MockWebex({
18
+ children: {
19
+ encryption: Encryption,
20
+ },
21
+ });
22
+ });
23
+
24
+ describe('check _fetchDownloadUrl()', () => {
25
+ const scrArray = [
26
+ {
27
+ loc: 'https://files-api-intb1.ciscospark.com/v1/spaces/a0cba376-fc05-4b88-af4b-cfffa7465f9a/contents/1d3931e7-9e31-46bc-8084-d766a8f72c99/versions/5fa9caf87a98410aae49e0173856a974/bytes',
28
+ },
29
+ {
30
+ loc: 'https://files-api-intb2.ciscospark.com/v1/spaces/a0cba376-fc05-4b88-af4b-cfffa7465f9a/contents/1d3931e7-9e31-46bc-8084-d766a8f72c99/versions/5fa9caf87a98410aae49e0173856a974/bytes',
31
+ },
32
+ {
33
+ loc: 'https://www.test-api.com/v1/spaces/test-path-name-space/contents/test-path-name-contents/versions/test-version/bytes',
34
+ },
35
+ {
36
+ loc: 'http://www.test-api.com/v1/spaces/test-path-name-space/contents/test-path-name-contents/versions/test-version/bytes',
37
+ },
38
+ ];
39
+ const options = undefined;
40
+ let spyStub;
41
+
42
+ beforeEach(() => {
43
+ const returnStub = (obj) => Promise.resolve(obj);
44
+
45
+ spyStub = sinon.stub(webex.internal.encryption, 'request').callsFake(returnStub);
46
+
47
+ scrArray.forEach((scr) => webex.internal.encryption._fetchDownloadUrl(scr, options));
48
+ });
49
+
50
+ it('verifying file service uris', () => {
51
+ assert.equal(
52
+ spyStub.args[0][0].uri,
53
+ 'https://files-api-intb1.ciscospark.com/v1/download/endpoints'
54
+ );
55
+ assert.equal(
56
+ spyStub.args[1][0].uri,
57
+ 'https://files-api-intb2.ciscospark.com/v1/download/endpoints'
58
+ );
59
+ assert.equal(spyStub.args[2][0].uri, 'https://www.test-api.com/v1/download/endpoints');
60
+ assert.equal(spyStub.args[3][0].uri, 'https://www.test-api.com/v1/download/endpoints');
61
+ });
62
+
63
+ it('verifying https', () => {
64
+ assert.equal(Url.parse(spyStub.args[0][0].uri).protocol, 'https:');
65
+ assert.equal(Url.parse(spyStub.args[1][0].uri).protocol, 'https:');
66
+ assert.equal(Url.parse(spyStub.args[2][0].uri).protocol, 'https:');
67
+ assert.equal(Url.parse(spyStub.args[3][0].uri).protocol, 'https:');
68
+ });
69
+
70
+ it('verifying endpoints', () => {
71
+ assert.equal(spyStub.args[0][0].body.endpoints[0], scrArray[0].loc);
72
+ assert.equal(spyStub.args[1][0].body.endpoints[0], scrArray[1].loc);
73
+ assert.equal(spyStub.args[2][0].body.endpoints[0], scrArray[2].loc);
74
+ assert.equal(spyStub.args[3][0].body.endpoints[0], scrArray[3].loc);
75
+ });
76
+
77
+ afterEach(() => {
78
+ spyStub.resetHistory();
79
+ });
80
+ });
81
+ });
82
+ });