@webex/internal-plugin-encryption 3.0.0-beta.42 → 3.0.0-beta.420

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.
@@ -1,6 +1,6 @@
1
1
  import {assert} from '@webex/test-helper-chai';
2
2
 
3
- import validateCert, {KMSError} from '../../../src/kms-certificate-validation';
3
+ import validateCert, {KMSError, validateCommonName, X509_SUBJECT_ALT_NAME_KEY} from '../../../src/kms-certificate-validation';
4
4
 
5
5
  const caroots = [
6
6
  'MIID6TCCAtGgAwIBAgIURmBu688C9oUIJXlykr1J3fi5H4kwDQYJKoZIhvcNAQELBQAwgYMxCzAJBgNVBAYTAlVTMREwDwYDVQQIDAhDb2xvcmFkbzEPMA0GA1UEBwwGRGVudmVyMRAwDgYDVQQKDAdFeGFtcGxlMR8wHQYDVQQDDBZodHRwczovL2NhLmV4YW1wbGUuY29tMR0wGwYJKoZIhvcNAQkBFg5jYUBleGFtcGxlLmNvbTAeFw0yMDAyMDYyMDIyMDhaFw00MDAyMDEyMDIyMDhaMIGDMQswCQYDVQQGEwJVUzERMA8GA1UECAwIQ29sb3JhZG8xDzANBgNVBAcMBkRlbnZlcjEQMA4GA1UECgwHRXhhbXBsZTEfMB0GA1UEAwwWaHR0cHM6Ly9jYS5leGFtcGxlLmNvbTEdMBsGCSqGSIb3DQEJARYOY2FAZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC7TaDWldwjU65y4fnNDIuNu4dZi3bZvaN9nJ3A8D9pwFcNx3DL5cPpafAkJuE/2ZBrsZxJWKwXLQFuNE9V3XVslv0OPgEZVfY5AKuPhVezRqEqsCdUgODMkJat6PE02r0NZRFpBiRCThh0wY5u/tiTiPgjHwEPhBEyLgcJ6FOWLn9wBsS4SvBzfppYGL5GW1G0eN9yORnKKgqkgyf0x8FvTMyVSjtkhcI/kA/8061sl4DFG6sefQmAOVvH7tp7YmN+jpQ7cOKQtjOpZS6Gp22u7LEI0/qb5n2QvjjcUQM81mN6CZ8nciWXRgjBhdAJJhmyMvcx8rnVb6vtU26fCaetAgMBAAGjUzBRMB0GA1UdDgQWBBRZiCyKaTYL94gwhxzktYg32qMOYjAfBgNVHSMEGDAWgBRZiCyKaTYL94gwhxzktYg32qMOYjAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQATa2QkTGcj8IPjItnvg23ihlRjHdFHn6lB7uYPhcDurwRlBrlC2/OB44P3dHB9tEPbV4unoF9ftEKO3nNY3HUDcPrQwRqkPftlYYr4/6z/jnmNBRgiDICVaiTZNlX54fLiPsSAbIymPWLLLNtq17vjVEcfGUXhi/F+EkN/uXZ4yH6RK0YjBRwPV9cfziz1YsF2WVYVYtQErf+NTjnYR5S4Ba2kEqhI5j7mNhiafPNODaOchHcaRMvfWcBhlHt+atwNyPxNr4NP+cDjAWg0I8xAUdbZGQiRJecjkctolLHsfZXj+ulEv3eaKw7gSo3Aekexw8aZS7soy+VM1fzmLopw',
@@ -163,3 +163,36 @@ describe('internal-plugin-encryption', () => {
163
163
  });
164
164
  });
165
165
  });
166
+
167
+ describe('validateCommonName', () => {
168
+
169
+ const checkValidate = (SAN, kidHostname) => {
170
+ validateCommonName(
171
+ [
172
+ {
173
+ extensions: [
174
+ {
175
+ extnID: X509_SUBJECT_ALT_NAME_KEY,
176
+ parsedValue: {
177
+ altNames: [{value: 'Example.com'}],
178
+ },
179
+ },
180
+ ],
181
+ },
182
+ ],
183
+ {kid: 'https://Example.com'}
184
+ );
185
+ }
186
+
187
+ it('handles mixed case SAN', () => {
188
+ checkValidate('Example.com', 'https://Example.com');
189
+ });
190
+
191
+ it('handles different case SAN', () => {
192
+ checkValidate('ExAmpLe.cOm', 'https://example.com');
193
+ });
194
+
195
+ it('handles different case kid hostname', () => {
196
+ checkValidate('example.com', 'https://ExAmpLe.cOm');
197
+ });
198
+ });
@@ -0,0 +1,70 @@
1
+ import {assert} from '@webex/test-helper-chai';
2
+ import {handleKmsKeyRevokedEncryptionFailure} from '../../../src/kms-errors'
3
+ import sinon from 'sinon';
4
+
5
+ describe('handleKmsKeyRevokedEncryptionFailure', () => {
6
+
7
+ it('triggers `event:kms:key:revoke:encryption:failure` event when correct error code is detected', () => {
8
+ const webex = {
9
+ internal: {
10
+ encryption: {
11
+ trigger: sinon.spy()
12
+ },
13
+ },
14
+ }
15
+
16
+ const item = {
17
+ status: 405,
18
+ body: {
19
+ errorCode: 405005,
20
+ }
21
+ }
22
+
23
+ handleKmsKeyRevokedEncryptionFailure(item, webex);
24
+
25
+ assert.calledOnce(webex.internal.encryption.trigger);
26
+ assert.calledWithExactly(webex.internal.encryption.trigger, `event:kms:key:revoke:encryption:failure`);
27
+ });
28
+
29
+ it('does not trigger `event:kms:key:revoke:encryption:failure` event when correct status but wrong error code is detected', () => {
30
+ const webex = {
31
+ internal: {
32
+ encryption: {
33
+ trigger: sinon.spy()
34
+ },
35
+ },
36
+ }
37
+
38
+ const item = {
39
+ status: 405,
40
+ body: {
41
+ errorCode: 405009,
42
+ }
43
+ }
44
+
45
+ handleKmsKeyRevokedEncryptionFailure(item, webex);
46
+
47
+ assert.notCalled(webex.internal.encryption.trigger);
48
+ });
49
+
50
+ it('does not trigger `event:kms:key:revoke:encryption:failure` event when wrong status but correct error code is detected', () => {
51
+ const webex = {
52
+ internal: {
53
+ encryption: {
54
+ trigger: sinon.spy()
55
+ },
56
+ },
57
+ }
58
+
59
+ const item = {
60
+ status: 403,
61
+ body: {
62
+ errorCode: 405005,
63
+ }
64
+ }
65
+
66
+ handleKmsKeyRevokedEncryptionFailure(item, webex);
67
+
68
+ assert.notCalled(webex.internal.encryption.trigger);
69
+ });
70
+ });
@@ -0,0 +1,103 @@
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
+ import {KmsError} from '../../../dist/kms-errors';
12
+
13
+ describe('internal-plugin-encryption', () => {
14
+ describe('kms', () => {
15
+ let webex;
16
+
17
+ beforeEach(() => {
18
+ webex = new MockWebex({
19
+ children: {
20
+ encryption: Encryption,
21
+ },
22
+ });
23
+ });
24
+
25
+ describe('key management', () => {
26
+ const options = undefined;
27
+ let spyStub;
28
+
29
+ beforeEach(() => {
30
+ const returnStub = (obj) => Promise.resolve(obj);
31
+
32
+ spyStub = sinon.stub(webex.internal.encryption.kms, 'request').callsFake(returnStub);
33
+ });
34
+
35
+ afterEach(() => {
36
+ spyStub.resetHistory();
37
+ });
38
+
39
+ it('listAllCustomerMasterKey', async () => {
40
+ await webex.internal.encryption.kms.listAllCustomerMasterKey({
41
+ assignedOrgId: 'xx-sds-assdf',
42
+ awsKms: false,
43
+ });
44
+
45
+ await webex.internal.encryption.kms.listAllCustomerMasterKey({
46
+ assignedOrgId: 'xx-sds-assdf',
47
+ awsKms: true,
48
+ });
49
+
50
+ assert.equal(spyStub.args[0][0].uri, '/cmk');
51
+ assert.equal(spyStub.args[1][0].uri, '/awsKmsCmk');
52
+ });
53
+
54
+ it('uploadCustomerMasterKey', async () => {
55
+ await webex.internal.encryption.kms.uploadCustomerMasterKey({
56
+ assignedOrgId: 'xx-sds-assdf',
57
+ awsKms: false,
58
+ });
59
+
60
+ await webex.internal.encryption.kms.uploadCustomerMasterKey({
61
+ assignedOrgId: 'xx-sds-assdf',
62
+ awsKms: true,
63
+ });
64
+
65
+ assert.equal(spyStub.args[0][0].uri, '/cmk');
66
+ assert.equal(spyStub.args[1][0].uri, '/awsKmsCmk');
67
+ });
68
+
69
+ it('deleteAllCustomerMasterKeys', async () => {
70
+ await webex.internal.encryption.kms.deleteAllCustomerMasterKeys({
71
+ assignedOrgId: 'xx-sds-assdf',
72
+ awsKms: false,
73
+ });
74
+
75
+ await webex.internal.encryption.kms.deleteAllCustomerMasterKeys({
76
+ assignedOrgId: 'xx-sds-assdf',
77
+ awsKms: true,
78
+ });
79
+
80
+ assert.equal(spyStub.args[0][0].uri, '/cmk');
81
+ assert.equal(spyStub.args[1][0].uri, '/awsKmsCmk');
82
+ });
83
+ });
84
+
85
+ describe('KMS error', () => {
86
+ it('KMSError', async () => {
87
+ const error = new KmsError({
88
+ status: 404,
89
+ errorCode: 30005,
90
+ reason: 'cannot fetch keys',
91
+ requestId: '3434343',
92
+ });
93
+ assert.equal(
94
+ error.toString(),
95
+ 'KmsError: cannot fetch keys\n' +
96
+ 'KMS_RESPONSE_STATUS: 404\n' +
97
+ 'KMS_REQUEST_ID: 3434343\n' +
98
+ 'KMS_ErrorCode: 30005'
99
+ );
100
+ });
101
+ });
102
+ });
103
+ });