@webex/plugin-authorization-node 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.
@@ -1,166 +1,166 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import '@webex/plugin-authorization-node';
6
- import {nodeOnly} from '@webex/test-helper-mocha';
7
- import {assert} from '@webex/test-helper-chai';
8
- import testUsers from '@webex/test-helper-test-users';
9
- import {createUser} from '@webex/test-helper-appid';
10
- import WebexCore, {filterScope} from '@webex/webex-core';
11
- import uuid from 'uuid';
12
- import sinon from 'sinon';
13
-
14
- const apiScope = filterScope('spark:kms', process.env.WEBEX_SCOPE);
15
-
16
- nodeOnly(describe)('plugin-authorization-node', () => {
17
- describe('Authorization', () => {
18
- describe('#logout()', () => {
19
- let webex, spock;
20
-
21
- beforeEach('create authorized webex user', () =>
22
- testUsers.create({count: 1}).then(([u]) => {
23
- spock = u;
24
- webex = new WebexCore({credentials: spock.token});
25
- })
26
- );
27
-
28
- it("invalidates all of the use's tokens", () => {
29
- sinon.spy(webex.authorization, 'logout');
30
- sinon.spy(webex, 'logout');
31
-
32
- return webex.logout().then(() => {
33
- assert.called(webex.logout);
34
- assert.called(webex.authorization.logout);
35
- });
36
- });
37
- });
38
-
39
- describe('#requestAccessTokenFromJwt', () => {
40
- it('exchanges a JWT for an appid access token', () => {
41
- const userId = uuid.v4();
42
- const displayName = `test-${userId}`;
43
-
44
- return createUser({displayName, userId}).then(({jwt}) => {
45
- const webex = new WebexCore();
46
-
47
- return webex.authorization
48
- .requestAccessTokenFromJwt({jwt})
49
- .then(() => assert.isTrue(webex.canAuthorize));
50
- });
51
- });
52
-
53
- it('should call services#initServiceCatalogs()', () => {
54
- const webex = new WebexCore();
55
- const userId = uuid.v4();
56
- const displayName = `test-${userId}`;
57
-
58
- webex.internal.services.initServiceCatalogs = sinon.spy();
59
-
60
- return createUser({displayName, userId})
61
- .then(({jwt}) => webex.authorization.requestAccessTokenFromJwt({jwt}))
62
- .then(() => assert.called(webex.internal.services.initServiceCatalogs));
63
- });
64
- });
65
-
66
- describe.skip("'#refresh", () => {
67
- describe('when used with an appid access token', () => {
68
- it('refreshes the access token', () => {
69
- const userId = uuid.v4();
70
- const displayName = `test-${userId}`;
71
-
72
- return createUser({displayName, userId}).then(({jwt}) => {
73
- const webex = new WebexCore({
74
- config: {
75
- credentials: {
76
- jwtRefreshCallback() {
77
- return createUser({displayName, userId}).then(({jwt}) => jwt);
78
- },
79
- },
80
- },
81
- });
82
- let token;
83
-
84
- return webex.authorization
85
- .requestAccessTokenFromJwt({jwt})
86
- .then(() => {
87
- token = webex.credentials.supertoken.access_token;
88
- assert.isTrue(webex.canAuthorize);
89
- })
90
- .then(() => webex.refresh())
91
- .then(() => {
92
- assert.isTrue(webex.canAuthorize);
93
- assert.notEqual(webex.credentials.supertoken.access_token, token);
94
- });
95
- });
96
- });
97
- });
98
- });
99
-
100
- describe('#requestAuthorizationCodeGrant()', () => {
101
- describe('when the user has the webex entitlement', () => {
102
- let code, webex;
103
-
104
- beforeEach('create auth code only test user', () =>
105
- testUsers.create({config: {authCodeOnly: true}}).then(([u]) => {
106
- webex = new WebexCore();
107
- code = u.token.auth_code;
108
- })
109
- );
110
-
111
- it('exchanges an authorization code for an access token', () =>
112
- webex.authorization.requestAuthorizationCodeGrant({code}).then(() => {
113
- assert.isDefined(webex.credentials.supertoken);
114
-
115
- return Promise.all([
116
- webex.credentials.getUserToken(apiScope),
117
- webex.credentials.getUserToken('spark:kms'),
118
- ]);
119
- }));
120
- });
121
-
122
- describe('when the user does not have the webex entitlement', () => {
123
- let code, webex;
124
-
125
- beforeEach('create non-webex-entitled test user', () =>
126
- testUsers
127
- .create({
128
- config: {
129
- // We omit the webex entitlment so that CI gives us a token lacking
130
- // spark:* scopes
131
- entitlements: [
132
- 'squaredCallInitiation',
133
- 'squaredRoomModeration',
134
- 'squaredInviter',
135
- 'webExSquared',
136
- ],
137
- authCodeOnly: true,
138
- },
139
- })
140
- .then(([u]) => {
141
- webex = new WebexCore();
142
- code = u.token.auth_code;
143
- })
144
- );
145
-
146
- it('exchanges an authorization code for an access token', () =>
147
- webex.authorization.requestAuthorizationCodeGrant({code}).then(() => {
148
- assert.isDefined(webex.credentials.supertoken);
149
-
150
- return Promise.all([
151
- webex.credentials
152
- .getUserToken(apiScope)
153
- .then((token) =>
154
- assert.equal(token.access_token, webex.credentials.supertoken.access_token)
155
- ),
156
- webex.credentials
157
- .getUserToken('spark:kms')
158
- .then((token) =>
159
- assert.equal(token.access_token, webex.credentials.supertoken.access_token)
160
- ),
161
- ]);
162
- }));
163
- });
164
- });
165
- });
166
- });
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import '@webex/plugin-authorization-node';
6
+ import {nodeOnly} from '@webex/test-helper-mocha';
7
+ import {assert} from '@webex/test-helper-chai';
8
+ import testUsers from '@webex/test-helper-test-users';
9
+ import {createUser} from '@webex/test-helper-appid';
10
+ import WebexCore, {filterScope} from '@webex/webex-core';
11
+ import uuid from 'uuid';
12
+ import sinon from 'sinon';
13
+
14
+ const apiScope = filterScope('spark:kms', process.env.WEBEX_SCOPE);
15
+
16
+ nodeOnly(describe)('plugin-authorization-node', () => {
17
+ describe('Authorization', () => {
18
+ describe('#logout()', () => {
19
+ let webex, spock;
20
+
21
+ beforeEach('create authorized webex user', () =>
22
+ testUsers.create({count: 1}).then(([u]) => {
23
+ spock = u;
24
+ webex = new WebexCore({credentials: spock.token});
25
+ })
26
+ );
27
+
28
+ it("invalidates all of the use's tokens", () => {
29
+ sinon.spy(webex.authorization, 'logout');
30
+ sinon.spy(webex, 'logout');
31
+
32
+ return webex.logout().then(() => {
33
+ assert.called(webex.logout);
34
+ assert.called(webex.authorization.logout);
35
+ });
36
+ });
37
+ });
38
+
39
+ describe('#requestAccessTokenFromJwt', () => {
40
+ it('exchanges a JWT for an appid access token', () => {
41
+ const userId = uuid.v4();
42
+ const displayName = `test-${userId}`;
43
+
44
+ return createUser({displayName, userId}).then(({jwt}) => {
45
+ const webex = new WebexCore();
46
+
47
+ return webex.authorization
48
+ .requestAccessTokenFromJwt({jwt})
49
+ .then(() => assert.isTrue(webex.canAuthorize));
50
+ });
51
+ });
52
+
53
+ it('should call services#initServiceCatalogs()', () => {
54
+ const webex = new WebexCore();
55
+ const userId = uuid.v4();
56
+ const displayName = `test-${userId}`;
57
+
58
+ webex.internal.services.initServiceCatalogs = sinon.spy();
59
+
60
+ return createUser({displayName, userId})
61
+ .then(({jwt}) => webex.authorization.requestAccessTokenFromJwt({jwt}))
62
+ .then(() => assert.called(webex.internal.services.initServiceCatalogs));
63
+ });
64
+ });
65
+
66
+ describe.skip("'#refresh", () => {
67
+ describe('when used with an appid access token', () => {
68
+ it('refreshes the access token', () => {
69
+ const userId = uuid.v4();
70
+ const displayName = `test-${userId}`;
71
+
72
+ return createUser({displayName, userId}).then(({jwt}) => {
73
+ const webex = new WebexCore({
74
+ config: {
75
+ credentials: {
76
+ jwtRefreshCallback() {
77
+ return createUser({displayName, userId}).then(({jwt}) => jwt);
78
+ },
79
+ },
80
+ },
81
+ });
82
+ let token;
83
+
84
+ return webex.authorization
85
+ .requestAccessTokenFromJwt({jwt})
86
+ .then(() => {
87
+ token = webex.credentials.supertoken.access_token;
88
+ assert.isTrue(webex.canAuthorize);
89
+ })
90
+ .then(() => webex.refresh())
91
+ .then(() => {
92
+ assert.isTrue(webex.canAuthorize);
93
+ assert.notEqual(webex.credentials.supertoken.access_token, token);
94
+ });
95
+ });
96
+ });
97
+ });
98
+ });
99
+
100
+ describe('#requestAuthorizationCodeGrant()', () => {
101
+ describe('when the user has the webex entitlement', () => {
102
+ let code, webex;
103
+
104
+ beforeEach('create auth code only test user', () =>
105
+ testUsers.create({config: {authCodeOnly: true}}).then(([u]) => {
106
+ webex = new WebexCore();
107
+ code = u.token.auth_code;
108
+ })
109
+ );
110
+
111
+ it('exchanges an authorization code for an access token', () =>
112
+ webex.authorization.requestAuthorizationCodeGrant({code}).then(() => {
113
+ assert.isDefined(webex.credentials.supertoken);
114
+
115
+ return Promise.all([
116
+ webex.credentials.getUserToken(apiScope),
117
+ webex.credentials.getUserToken('spark:kms'),
118
+ ]);
119
+ }));
120
+ });
121
+
122
+ describe('when the user does not have the webex entitlement', () => {
123
+ let code, webex;
124
+
125
+ beforeEach('create non-webex-entitled test user', () =>
126
+ testUsers
127
+ .create({
128
+ config: {
129
+ // We omit the webex entitlment so that CI gives us a token lacking
130
+ // spark:* scopes
131
+ entitlements: [
132
+ 'squaredCallInitiation',
133
+ 'squaredRoomModeration',
134
+ 'squaredInviter',
135
+ 'webExSquared',
136
+ ],
137
+ authCodeOnly: true,
138
+ },
139
+ })
140
+ .then(([u]) => {
141
+ webex = new WebexCore();
142
+ code = u.token.auth_code;
143
+ })
144
+ );
145
+
146
+ it('exchanges an authorization code for an access token', () =>
147
+ webex.authorization.requestAuthorizationCodeGrant({code}).then(() => {
148
+ assert.isDefined(webex.credentials.supertoken);
149
+
150
+ return Promise.all([
151
+ webex.credentials
152
+ .getUserToken(apiScope)
153
+ .then((token) =>
154
+ assert.equal(token.access_token, webex.credentials.supertoken.access_token)
155
+ ),
156
+ webex.credentials
157
+ .getUserToken('spark:kms')
158
+ .then((token) =>
159
+ assert.equal(token.access_token, webex.credentials.supertoken.access_token)
160
+ ),
161
+ ]);
162
+ }));
163
+ });
164
+ });
165
+ });
166
+ });
@@ -1,69 +1,69 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- /* eslint camelcase: [0] */
6
-
7
- import {assert} from '@webex/test-helper-chai';
8
- import {browserOnly, nodeOnly} from '@webex/test-helper-mocha';
9
- import MockWebex from '@webex/test-helper-mock-webex';
10
- import Authorization from '@webex/plugin-authorization-node';
11
- import {Credentials} from '@webex/webex-core';
12
-
13
- browserOnly(describe)('hack', () => {
14
- it('prevents the suite from crashing', () => assert(true));
15
- });
16
-
17
- nodeOnly(describe)('plugin-authorization-node', () => {
18
- describe('Authorization', () => {
19
- let webex;
20
-
21
- beforeEach(() => {
22
- webex = new MockWebex({
23
- children: {
24
- authorization: Authorization,
25
- credentials: Credentials,
26
- },
27
- });
28
-
29
- webex.request.returns(
30
- Promise.resolve({
31
- statusCode: 200,
32
- body: {
33
- access_token: 'AT3',
34
- token_type: 'Fake',
35
- },
36
- })
37
- );
38
- });
39
-
40
- describe('#requestAuthorizationCodeGrant', () => {
41
- it('requires a `code`', () =>
42
- assert.isRejected(
43
- webex.authorization.requestAuthorizationCodeGrant(),
44
- /`options.code` is required/
45
- ));
46
-
47
- it('exchanges an authorization code for an access token', () =>
48
- webex.authorization
49
- .requestAuthorizationCodeGrant({code: 1})
50
- .then(() => assert.equal(webex.credentials.supertoken.access_token, 'AT3')));
51
-
52
- it('sets #isAuthenticating', () => {
53
- const promise = webex.authorization.requestAuthorizationCodeGrant({code: 5});
54
-
55
- assert.isTrue(webex.authorization.isAuthenticating);
56
-
57
- return promise.then(() => assert.isFalse(webex.authorization.isAuthenticating));
58
- });
59
-
60
- it('sets #isAuthorizing', () => {
61
- const promise = webex.authorization.requestAuthorizationCodeGrant({code: 5});
62
-
63
- assert.isTrue(webex.authorization.isAuthorizing);
64
-
65
- return promise.then(() => assert.isFalse(webex.authorization.isAuthorizing));
66
- });
67
- });
68
- });
69
- });
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ /* eslint camelcase: [0] */
6
+
7
+ import {assert} from '@webex/test-helper-chai';
8
+ import {browserOnly, nodeOnly} from '@webex/test-helper-mocha';
9
+ import MockWebex from '@webex/test-helper-mock-webex';
10
+ import Authorization from '@webex/plugin-authorization-node';
11
+ import {Credentials} from '@webex/webex-core';
12
+
13
+ browserOnly(describe)('hack', () => {
14
+ it('prevents the suite from crashing', () => assert(true));
15
+ });
16
+
17
+ nodeOnly(describe)('plugin-authorization-node', () => {
18
+ describe('Authorization', () => {
19
+ let webex;
20
+
21
+ beforeEach(() => {
22
+ webex = new MockWebex({
23
+ children: {
24
+ authorization: Authorization,
25
+ credentials: Credentials,
26
+ },
27
+ });
28
+
29
+ webex.request.returns(
30
+ Promise.resolve({
31
+ statusCode: 200,
32
+ body: {
33
+ access_token: 'AT3',
34
+ token_type: 'Fake',
35
+ },
36
+ })
37
+ );
38
+ });
39
+
40
+ describe('#requestAuthorizationCodeGrant', () => {
41
+ it('requires a `code`', () =>
42
+ assert.isRejected(
43
+ webex.authorization.requestAuthorizationCodeGrant(),
44
+ /`options.code` is required/
45
+ ));
46
+
47
+ it('exchanges an authorization code for an access token', () =>
48
+ webex.authorization
49
+ .requestAuthorizationCodeGrant({code: 1})
50
+ .then(() => assert.equal(webex.credentials.supertoken.access_token, 'AT3')));
51
+
52
+ it('sets #isAuthenticating', () => {
53
+ const promise = webex.authorization.requestAuthorizationCodeGrant({code: 5});
54
+
55
+ assert.isTrue(webex.authorization.isAuthenticating);
56
+
57
+ return promise.then(() => assert.isFalse(webex.authorization.isAuthenticating));
58
+ });
59
+
60
+ it('sets #isAuthorizing', () => {
61
+ const promise = webex.authorization.requestAuthorizationCodeGrant({code: 5});
62
+
63
+ assert.isTrue(webex.authorization.isAuthorizing);
64
+
65
+ return promise.then(() => assert.isFalse(webex.authorization.isAuthorizing));
66
+ });
67
+ });
68
+ });
69
+ });