@webex/webex-core 2.60.1-next.10 → 2.60.1-next.11

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.
@@ -286,7 +286,7 @@ var Batcher = _webexPlugin.default.extend({
286
286
  fingerprintResponse: function fingerprintResponse(item) {
287
287
  throw new Error('fingerprintResponse() must be implemented');
288
288
  },
289
- version: "2.60.1-next.10"
289
+ version: "2.60.1-next.11"
290
290
  });
291
291
  var _default2 = exports.default = Batcher;
292
292
  //# sourceMappingURL=batcher.js.map
@@ -558,7 +558,7 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
558
558
  this.refresh();
559
559
  }
560
560
  },
561
- version: "2.60.1-next.10"
561
+ version: "2.60.1-next.11"
562
562
  }, ((0, _applyDecoratedDescriptor2.default)(_obj, "getUserToken", [_dec, _dec2], (0, _getOwnPropertyDescriptor.default)(_obj, "getUserToken"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "initialize", [_dec3], (0, _getOwnPropertyDescriptor.default)(_obj, "initialize"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "invalidate", [_common.oneFlight, _dec4], (0, _getOwnPropertyDescriptor.default)(_obj, "invalidate"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "refresh", [_common.oneFlight, _dec5, _dec6], (0, _getOwnPropertyDescriptor.default)(_obj, "refresh"), _obj)), _obj)));
563
563
  var _default = exports.default = Credentials;
564
564
  //# sourceMappingURL=credentials.js.map
@@ -532,7 +532,7 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
532
532
  return res.body;
533
533
  });
534
534
  },
535
- version: "2.60.1-next.10"
535
+ version: "2.60.1-next.11"
536
536
  }, ((0, _applyDecoratedDescriptor2.default)(_obj, "downscope", [_dec], (0, _getOwnPropertyDescriptor.default)(_obj, "downscope"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "refresh", [_common.oneFlight], (0, _getOwnPropertyDescriptor.default)(_obj, "refresh"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "revoke", [_common.oneFlight], (0, _getOwnPropertyDescriptor.default)(_obj, "revoke"), _obj)), _obj)));
537
537
  var _default = exports.default = Token;
538
538
  //# sourceMappingURL=token.js.map
@@ -1014,7 +1014,7 @@ var Services = _webexPlugin.default.extend({
1014
1014
  }
1015
1015
  });
1016
1016
  },
1017
- version: "2.60.1-next.10"
1017
+ version: "2.60.1-next.11"
1018
1018
  });
1019
1019
  /* eslint-enable no-underscore-dangle */
1020
1020
  var _default = exports.default = Services;
@@ -57,7 +57,7 @@ var Logger = _webexPlugin.default.extend({
57
57
  info: wrapConsoleMethod('info'),
58
58
  debug: wrapConsoleMethod('debug'),
59
59
  trace: wrapConsoleMethod('trace'),
60
- version: "2.60.1-next.10"
60
+ version: "2.60.1-next.11"
61
61
  });
62
62
  (0, _webexCore.registerPlugin)('logger', Logger);
63
63
  var _default = exports.default = Logger;
@@ -94,7 +94,7 @@ var MAX_FILE_SIZE_IN_MB = 2048;
94
94
  * @class
95
95
  */
96
96
  var WebexCore = _ampersandState.default.extend((_obj = {
97
- version: "2.60.1-next.10",
97
+ version: "2.60.1-next.11",
98
98
  children: {
99
99
  internal: _webexInternalCore.default
100
100
  },
@@ -636,7 +636,7 @@ var WebexCore = _ampersandState.default.extend((_obj = {
636
636
  });
637
637
  }
638
638
  }, ((0, _applyDecoratedDescriptor2.default)(_obj, "_uploadPhaseUpload", [_common.retry], (0, _getOwnPropertyDescriptor.default)(_obj, "_uploadPhaseUpload"), _obj)), _obj));
639
- WebexCore.version = "2.60.1-next.10";
639
+ WebexCore.version = "2.60.1-next.11";
640
640
  (0, _webexInternalCorePluginMixin.default)(_webexInternalCore.default, _config.default, interceptors);
641
641
  (0, _webexCorePluginMixin.default)(WebexCore, _config.default, interceptors);
642
642
  var _default = exports.default = WebexCore;
package/package.json CHANGED
@@ -35,12 +35,12 @@
35
35
  "@webex/eslint-config-legacy": "0.0.0",
36
36
  "@webex/jest-config-legacy": "0.0.0",
37
37
  "@webex/legacy-tools": "0.0.0",
38
- "@webex/test-helper-chai": "2.60.1-next.10",
39
- "@webex/test-helper-make-local-url": "2.60.1-next.10",
40
- "@webex/test-helper-mocha": "2.60.1-next.10",
41
- "@webex/test-helper-mock-webex": "2.60.1-next.10",
42
- "@webex/test-helper-refresh-callback": "2.60.1-next.10",
43
- "@webex/test-helper-test-users": "2.60.1-next.10",
38
+ "@webex/test-helper-chai": "2.60.1-next.11",
39
+ "@webex/test-helper-make-local-url": "2.60.1-next.11",
40
+ "@webex/test-helper-mocha": "2.60.1-next.11",
41
+ "@webex/test-helper-mock-webex": "2.60.1-next.11",
42
+ "@webex/test-helper-refresh-callback": "2.60.1-next.11",
43
+ "@webex/test-helper-test-users": "2.60.1-next.11",
44
44
  "chai": "^4.3.4",
45
45
  "chai-as-promised": "^7.1.1",
46
46
  "eslint": "^8.24.0",
@@ -48,12 +48,12 @@
48
48
  "sinon": "^9.2.4"
49
49
  },
50
50
  "dependencies": {
51
- "@webex/common": "2.60.1-next.10",
52
- "@webex/common-timers": "2.60.1-next.10",
53
- "@webex/http-core": "2.60.1-next.10",
54
- "@webex/internal-plugin-device": "2.60.1-next.10",
55
- "@webex/plugin-logger": "2.60.1-next.10",
56
- "@webex/storage-adapter-spec": "2.60.1-next.10",
51
+ "@webex/common": "2.60.1-next.11",
52
+ "@webex/common-timers": "2.60.1-next.11",
53
+ "@webex/http-core": "2.60.1-next.11",
54
+ "@webex/internal-plugin-device": "2.60.1-next.11",
55
+ "@webex/plugin-logger": "2.60.1-next.11",
56
+ "@webex/storage-adapter-spec": "2.60.1-next.11",
57
57
  "ampersand-collection": "^2.0.2",
58
58
  "ampersand-events": "^2.0.2",
59
59
  "ampersand-state": "^5.0.3",
@@ -68,10 +68,10 @@
68
68
  "build:src": "webex-legacy-tools build -dest \"./dist\" -src \"./src\" -js -ts -maps",
69
69
  "deploy:npm": "yarn npm publish",
70
70
  "test": "yarn test:style && yarn test:unit && yarn test:integration && yarn test:browser",
71
- "test:browser:broken": "webex-legacy-tools test --integration --unit --runner karma",
72
- "test:integration:broken": "webex-legacy-tools test --integration --runner mocha",
71
+ "test:browser": "webex-legacy-tools test --integration --runner karma",
72
+ "test:integration": "webex-legacy-tools test --integration --runner mocha",
73
73
  "test:style": "eslint ./src/**/*.*",
74
74
  "test:unit": "webex-legacy-tools test --unit --runner jest"
75
75
  },
76
- "version": "2.60.1-next.10"
76
+ "version": "2.60.1-next.11"
77
77
  }
@@ -110,12 +110,15 @@ describe('webex-core', () => {
110
110
  });
111
111
  });
112
112
 
113
- browserOnly(it)('throws without a refresh callback', () => {
113
+ browserOnly(it)('throws without a refresh callback', async () => {
114
114
  const webex = new WebexCore({
115
115
  credentials: user.token,
116
116
  });
117
-
118
- return assert.isRejected(webex.credentials.refresh());
117
+ await webex.credentials.refresh().then(() => {
118
+ assert(false, 'resolved, should have thrown');
119
+ }).catch((err) => {
120
+ assert(false);
121
+ });
119
122
  });
120
123
 
121
124
  browserOnly(it)('refreshes with a refresh callback', () => {
@@ -0,0 +1,93 @@
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ /* eslint-disable camelcase */
6
+
7
+ import chai from 'chai';
8
+ import chaiAsPromised from 'chai-as-promised';
9
+ import sinon from 'sinon';
10
+ import {browserOnly, nodeOnly} from '@webex/test-helper-mocha';
11
+ import Logger from '@webex/plugin-logger';
12
+ import MockWebex from '@webex/test-helper-mock-webex';
13
+ import {AuthInterceptor, config, Credentials, WebexHttpError, Token} from '@webex/webex-core';
14
+ import {cloneDeep, merge} from 'lodash';
15
+ import Metrics from '@webex/internal-plugin-metrics';
16
+
17
+ const {assert} = chai;
18
+
19
+ chai.use(chaiAsPromised);
20
+ sinon.assert.expose(chai.assert, {prefix: ''});
21
+
22
+ describe('webex-core', () => {
23
+ describe('Interceptors', () => {
24
+ describe('AuthInterceptor', () => {
25
+ let interceptor, webex;
26
+
27
+ beforeEach(() => {
28
+ webex = new MockWebex({
29
+ children: {
30
+ credentials: Credentials,
31
+ logger: Logger,
32
+ metrics: Metrics,
33
+ },
34
+ config: merge(cloneDeep(config), {credentials: {client_secret: 'fake'}}),
35
+ });
36
+
37
+ webex.credentials.supertoken = new Token(
38
+ {
39
+ access_token: 'ST1',
40
+ token_type: 'Bearer',
41
+ },
42
+ {parent: webex}
43
+ );
44
+
45
+ interceptor = Reflect.apply(AuthInterceptor.create, webex, []);
46
+ sinon.stub(webex.internal.metrics, 'submitClientMetrics').callsFake(() => {});
47
+ });
48
+
49
+
50
+ describe('#onResponseError()', () => {
51
+ describe('when the server responds with 401', () => {
52
+ browserOnly(it)('refreshes the access token and replays the request', () => {
53
+ webex.config.credentials.refreshCallback = sinon.stub().returns(
54
+ Promise.resolve({
55
+ access_token: 'ST2',
56
+ })
57
+ );
58
+
59
+ webex.credentials.supertoken = new Token(
60
+ {
61
+ access_token: 'ST1',
62
+ refresh_token: 'RT1',
63
+ },
64
+ {parent: webex}
65
+ );
66
+
67
+ const err = new WebexHttpError.Unauthorized({
68
+ statusCode: 401,
69
+ options: {
70
+ headers: {
71
+ trackingid: 'blarg',
72
+ },
73
+ uri: `${config.services.discovery.hydra}/ping`,
74
+ },
75
+ body: {
76
+ error: 'fake error',
77
+ },
78
+ });
79
+
80
+ assert.notCalled(webex.request);
81
+
82
+ return interceptor.onResponseError(err.options, err).then(() => {
83
+ // once for replay
84
+ assert.calledOnce(webex.request);
85
+ assert.equal(webex.credentials.supertoken.access_token, 'ST2');
86
+ assert.equal(webex.request.args[0][0].replayCount, 1);
87
+ });
88
+ });
89
+ });
90
+ });
91
+ });
92
+ });
93
+ });
@@ -0,0 +1,122 @@
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {assert} from '@webex/test-helper-chai';
6
+ import sinon from 'sinon';
7
+ import {nodeOnly, browserOnly} from '@webex/test-helper-mocha';
8
+ import FakeTimers from '@sinonjs/fake-timers';
9
+ import MockWebex from '@webex/test-helper-mock-webex';
10
+ import {Token} from '@webex/webex-core';
11
+
12
+ /* eslint camelcase: [0] */
13
+
14
+ // eslint-disable-next-line no-empty-function
15
+ function noop() {}
16
+
17
+ describe('webex-core', () => {
18
+ describe('Credentials', () => {
19
+ describe('Token', () => {
20
+ let webex;
21
+
22
+ beforeEach(() => {
23
+ webex = new MockWebex();
24
+ });
25
+
26
+ function makeToken(options = {}) {
27
+ return new Token(
28
+ Object.assign(
29
+ {
30
+ access_token: 'AT',
31
+ expires_in: 10000,
32
+ token_type: 'Fake',
33
+ refresh_token: 'RT',
34
+ refresh_token_expires_in: 20000,
35
+ },
36
+ options
37
+ ),
38
+ {parent: webex}
39
+ );
40
+ }
41
+
42
+ describe('#canRefresh', () => {
43
+ browserOnly(it)('indicates if this token can be refreshed', () => {
44
+ let token = makeToken();
45
+
46
+ assert.isFalse(token.canRefresh);
47
+ token.unset('refresh_token');
48
+ assert.isFalse(token.canRefresh);
49
+
50
+ webex.config.credentials.refreshCallback = noop;
51
+ token = makeToken();
52
+ assert.isTrue(token.canRefresh);
53
+ token.unset('refresh_token');
54
+ assert.isFalse(token.canRefresh);
55
+ });
56
+ });
57
+
58
+ describe('#refresh()', () => {
59
+ browserOnly(it)('refreshes the access_token', () => {
60
+ const token = makeToken();
61
+
62
+ webex.config.credentials.refreshCallback = sinon.stub().returns(
63
+ Promise.resolve({
64
+ access_token: 'AT2',
65
+ expires_in: 10000,
66
+ token_type: 'Fake',
67
+ })
68
+ );
69
+
70
+ // FIXME this next line should be necessary. we need a better way to
71
+ // do config
72
+ token.trigger('change:config');
73
+
74
+ return token.refresh().then((token2) => {
75
+ assert.equal(token2.access_token, 'AT2');
76
+ });
77
+ });
78
+
79
+
80
+ browserOnly(it)('revokes the previous token when set', () => {
81
+ const token = makeToken();
82
+
83
+ sinon.spy(token, 'revoke');
84
+ webex.config.credentials.refreshCallback = sinon.stub();
85
+
86
+ webex.config.credentials.refreshCallback.onCall(0).returns(
87
+ Promise.resolve({
88
+ access_token: 'AT2',
89
+ expires_in: 10000,
90
+ token_type: 'Fake',
91
+ })
92
+ );
93
+
94
+ webex.config.credentials.refreshCallback.onCall(1).returns(
95
+ Promise.resolve({
96
+ access_token: 'AT3',
97
+ expires_in: 10000,
98
+ token_type: 'Fake',
99
+ })
100
+ );
101
+
102
+ // FIXME this next line should be necessary. we need a better way to
103
+ // do config
104
+ token.trigger('change:config');
105
+
106
+ return token
107
+ .refresh()
108
+ .then((token2) => {
109
+ assert.isTrue(token.canRefresh);
110
+ assert.notCalled(token.revoke);
111
+
112
+ return token2.refresh();
113
+ })
114
+ .then((token3) => {
115
+ assert.equal(token3.access_token, 'AT3');
116
+ assert.called(token.revoke);
117
+ });
118
+ });
119
+ });
120
+ });
121
+ });
122
+ });