@webex/webex-core 3.0.0-beta.414 → 3.0.0-beta.416
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/dist/lib/batcher.js +1 -1
- package/dist/lib/credentials/credentials.js +1 -1
- package/dist/lib/credentials/token.js +1 -1
- package/dist/lib/services/services.js +1 -1
- package/dist/plugins/logger.js +1 -1
- package/dist/webex-core.js +2 -2
- package/package.json +14 -14
- package/test/integration/spec/unit-browser/auth.js +93 -0
- package/test/integration/spec/unit-browser/token.js +122 -0
package/dist/lib/batcher.js
CHANGED
|
@@ -282,7 +282,7 @@ var Batcher = _webexPlugin.default.extend({
|
|
|
282
282
|
fingerprintResponse: function fingerprintResponse(item) {
|
|
283
283
|
throw new Error('fingerprintResponse() must be implemented');
|
|
284
284
|
},
|
|
285
|
-
version: "3.0.0-beta.
|
|
285
|
+
version: "3.0.0-beta.416"
|
|
286
286
|
});
|
|
287
287
|
var _default2 = Batcher;
|
|
288
288
|
exports.default = _default2;
|
|
@@ -558,7 +558,7 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
558
558
|
this.refresh();
|
|
559
559
|
}
|
|
560
560
|
},
|
|
561
|
-
version: "3.0.0-beta.
|
|
561
|
+
version: "3.0.0-beta.416"
|
|
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 = Credentials;
|
|
564
564
|
exports.default = _default;
|
|
@@ -530,7 +530,7 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
530
530
|
return res.body;
|
|
531
531
|
});
|
|
532
532
|
},
|
|
533
|
-
version: "3.0.0-beta.
|
|
533
|
+
version: "3.0.0-beta.416"
|
|
534
534
|
}, ((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)));
|
|
535
535
|
var _default = Token;
|
|
536
536
|
exports.default = _default;
|
package/dist/plugins/logger.js
CHANGED
|
@@ -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: "3.0.0-beta.
|
|
60
|
+
version: "3.0.0-beta.416"
|
|
61
61
|
});
|
|
62
62
|
(0, _webexCore.registerPlugin)('logger', Logger);
|
|
63
63
|
var _default = Logger;
|
package/dist/webex-core.js
CHANGED
|
@@ -99,7 +99,7 @@ var MAX_FILE_SIZE_IN_MB = 2048;
|
|
|
99
99
|
* @class
|
|
100
100
|
*/
|
|
101
101
|
var WebexCore = _ampersandState.default.extend((_obj = {
|
|
102
|
-
version: "3.0.0-beta.
|
|
102
|
+
version: "3.0.0-beta.416",
|
|
103
103
|
children: {
|
|
104
104
|
internal: _webexInternalCore.default
|
|
105
105
|
},
|
|
@@ -641,7 +641,7 @@ var WebexCore = _ampersandState.default.extend((_obj = {
|
|
|
641
641
|
});
|
|
642
642
|
}
|
|
643
643
|
}, ((0, _applyDecoratedDescriptor2.default)(_obj, "_uploadPhaseUpload", [_common.retry], (0, _getOwnPropertyDescriptor.default)(_obj, "_uploadPhaseUpload"), _obj)), _obj));
|
|
644
|
-
WebexCore.version = "3.0.0-beta.
|
|
644
|
+
WebexCore.version = "3.0.0-beta.416";
|
|
645
645
|
(0, _webexInternalCorePluginMixin.default)(_webexInternalCore.default, _config.default, interceptors);
|
|
646
646
|
(0, _webexCorePluginMixin.default)(WebexCore, _config.default, interceptors);
|
|
647
647
|
var _default = WebexCore;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webex/webex-core",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.416",
|
|
4
4
|
"description": "Plugin handling for Cisco Webex",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"contributors": [
|
|
@@ -31,24 +31,24 @@
|
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@sinonjs/fake-timers": "^6.0.1",
|
|
34
|
-
"@webex/test-helper-chai": "3.0.0-beta.
|
|
35
|
-
"@webex/test-helper-make-local-url": "3.0.0-beta.
|
|
36
|
-
"@webex/test-helper-mocha": "3.0.0-beta.
|
|
37
|
-
"@webex/test-helper-mock-webex": "3.0.0-beta.
|
|
38
|
-
"@webex/test-helper-refresh-callback": "3.0.0-beta.
|
|
39
|
-
"@webex/test-helper-test-users": "3.0.0-beta.
|
|
34
|
+
"@webex/test-helper-chai": "3.0.0-beta.416",
|
|
35
|
+
"@webex/test-helper-make-local-url": "3.0.0-beta.416",
|
|
36
|
+
"@webex/test-helper-mocha": "3.0.0-beta.416",
|
|
37
|
+
"@webex/test-helper-mock-webex": "3.0.0-beta.416",
|
|
38
|
+
"@webex/test-helper-refresh-callback": "3.0.0-beta.416",
|
|
39
|
+
"@webex/test-helper-test-users": "3.0.0-beta.416",
|
|
40
40
|
"chai": "^4.3.4",
|
|
41
41
|
"chai-as-promised": "^7.1.1",
|
|
42
42
|
"sinon": "^9.2.4"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@webex/common": "3.0.0-beta.
|
|
46
|
-
"@webex/common-timers": "3.0.0-beta.
|
|
47
|
-
"@webex/http-core": "3.0.0-beta.
|
|
48
|
-
"@webex/internal-plugin-device": "3.0.0-beta.
|
|
49
|
-
"@webex/plugin-logger": "3.0.0-beta.
|
|
50
|
-
"@webex/storage-adapter-spec": "3.0.0-beta.
|
|
51
|
-
"@webex/webex-core": "3.0.0-beta.
|
|
45
|
+
"@webex/common": "3.0.0-beta.416",
|
|
46
|
+
"@webex/common-timers": "3.0.0-beta.416",
|
|
47
|
+
"@webex/http-core": "3.0.0-beta.416",
|
|
48
|
+
"@webex/internal-plugin-device": "3.0.0-beta.416",
|
|
49
|
+
"@webex/plugin-logger": "3.0.0-beta.416",
|
|
50
|
+
"@webex/storage-adapter-spec": "3.0.0-beta.416",
|
|
51
|
+
"@webex/webex-core": "3.0.0-beta.416",
|
|
52
52
|
"ampersand-collection": "^2.0.2",
|
|
53
53
|
"ampersand-events": "^2.0.2",
|
|
54
54
|
"ampersand-state": "^5.0.3",
|
|
@@ -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
|
+
});
|