@webex/test-users 3.0.0-beta.3 → 3.0.0-beta.30
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/README.md +3 -3
- package/dist/index.js +34 -74
- package/dist/index.js.map +1 -1
- package/dist/whistler.js +32 -39
- package/dist/whistler.js.map +1 -1
- package/package.json +4 -4
- package/src/index.js +65 -52
- package/src/whistler.js +75 -59
- package/test/integration/spec/index.js +76 -64
- package/test/integration/spec/whistler.js +4 -5
package/src/index.js
CHANGED
|
@@ -24,7 +24,7 @@ function fixToken(token) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
if (token.refresh_token_expires_in && !token.refresh_token_expires) {
|
|
27
|
-
|
|
27
|
+
/* eslint camelcase: [0] */
|
|
28
28
|
token.refresh_token_expires = now + token.refresh_token_expires_in * 1000;
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -61,14 +61,14 @@ function getClientCredentials({clientId, clientSecret, idbrokerUrl}) {
|
|
|
61
61
|
grant_type: 'client_credentials',
|
|
62
62
|
scope: 'Identity:SCIM webexsquare:get_conversation',
|
|
63
63
|
client_id: clientId,
|
|
64
|
-
client_secret: clientSecret
|
|
64
|
+
client_secret: clientSecret,
|
|
65
65
|
},
|
|
66
66
|
headers: {
|
|
67
67
|
// Note: we can't request's auth hash here because this endpoint expects
|
|
68
68
|
// us to send the auth header *without including "Basic "* before the
|
|
69
69
|
// token string
|
|
70
|
-
authorization: btoa(`${clientId}:${clientSecret}`)
|
|
71
|
-
}
|
|
70
|
+
authorization: btoa(`${clientId}:${clientSecret}`),
|
|
71
|
+
},
|
|
72
72
|
})
|
|
73
73
|
.then((res) => {
|
|
74
74
|
const token = fixToken(res.body);
|
|
@@ -93,13 +93,12 @@ function getClientCredentials({clientId, clientSecret, idbrokerUrl}) {
|
|
|
93
93
|
* @returns {Promise<HttpResponseObject>}
|
|
94
94
|
*/
|
|
95
95
|
function requestWithAuth(options) {
|
|
96
|
-
return getClientCredentials(options.body)
|
|
97
|
-
.
|
|
98
|
-
|
|
99
|
-
options.headers.authorization = authorization;
|
|
96
|
+
return getClientCredentials(options.body).then((authorization) => {
|
|
97
|
+
options.headers = options.headers || {};
|
|
98
|
+
options.headers.authorization = authorization;
|
|
100
99
|
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
return request(options);
|
|
101
|
+
});
|
|
103
102
|
}
|
|
104
103
|
|
|
105
104
|
/**
|
|
@@ -132,20 +131,20 @@ function requestWithAuth(options) {
|
|
|
132
131
|
*/
|
|
133
132
|
|
|
134
133
|
/**
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
134
|
+
* @typedef {Object} TestUserObject
|
|
135
|
+
* @property {string} password
|
|
136
|
+
* @property {string} emailAddress
|
|
137
|
+
* @property {string} displayName
|
|
138
|
+
* @property {string} id
|
|
139
|
+
* @property {string} userName
|
|
140
|
+
* @property {string} email
|
|
141
|
+
* @property {string} name
|
|
142
|
+
* @property {string} givenName
|
|
143
|
+
* @property {string} type
|
|
144
|
+
* @property {Array.<string>} entitlements
|
|
145
|
+
* @property {string} orgId
|
|
146
|
+
* @property {AccessTokenObject} token
|
|
147
|
+
*/
|
|
149
148
|
|
|
150
149
|
/**
|
|
151
150
|
* Creates a test user
|
|
@@ -156,7 +155,10 @@ export function createTestUser(options = {}) {
|
|
|
156
155
|
const clientId = options.clientId || process.env.WEBEX_CLIENT_ID;
|
|
157
156
|
const clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;
|
|
158
157
|
const idbrokerUrl = options.idbrokerUrl || process.env.IDBROKER_BASE_URL;
|
|
159
|
-
const cigServiceUrl =
|
|
158
|
+
const cigServiceUrl =
|
|
159
|
+
options.cigServiceUrl ||
|
|
160
|
+
process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL ||
|
|
161
|
+
process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;
|
|
160
162
|
|
|
161
163
|
if (!clientId) {
|
|
162
164
|
throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');
|
|
@@ -171,7 +173,9 @@ export function createTestUser(options = {}) {
|
|
|
171
173
|
}
|
|
172
174
|
|
|
173
175
|
if (!cigServiceUrl) {
|
|
174
|
-
throw new Error(
|
|
176
|
+
throw new Error(
|
|
177
|
+
'options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined'
|
|
178
|
+
);
|
|
175
179
|
}
|
|
176
180
|
|
|
177
181
|
const body = {
|
|
@@ -185,7 +189,7 @@ export function createTestUser(options = {}) {
|
|
|
185
189
|
'squaredCallInitiation',
|
|
186
190
|
'squaredRoomModeration',
|
|
187
191
|
'squaredInviter',
|
|
188
|
-
'webExSquared'
|
|
192
|
+
'webExSquared',
|
|
189
193
|
],
|
|
190
194
|
idbrokerUrl,
|
|
191
195
|
machineType: options.machineType,
|
|
@@ -194,20 +198,21 @@ export function createTestUser(options = {}) {
|
|
|
194
198
|
password: options.password || `${uuid.v4()}zAY1*`,
|
|
195
199
|
roles: options.roles || [],
|
|
196
200
|
scopes: options.scope || process.env.WEBEX_SCOPE,
|
|
197
|
-
type: options.type
|
|
201
|
+
type: options.type,
|
|
198
202
|
};
|
|
199
203
|
|
|
200
204
|
return requestWithAuth({
|
|
201
205
|
method: 'POST',
|
|
202
206
|
uri: `${cigServiceUrl}${BASE_PATH_SECURE}`,
|
|
203
207
|
json: true,
|
|
204
|
-
body
|
|
205
|
-
})
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
208
|
+
body,
|
|
209
|
+
}).then((res) => ({
|
|
210
|
+
password: body.password,
|
|
211
|
+
emailAddress: res.body.user.email,
|
|
212
|
+
displayName: res.body.user.name,
|
|
213
|
+
...res.body.user,
|
|
214
|
+
token: fixToken(res.body.token),
|
|
215
|
+
}));
|
|
211
216
|
}
|
|
212
217
|
|
|
213
218
|
/**
|
|
@@ -224,7 +229,10 @@ export function createTestUser(options = {}) {
|
|
|
224
229
|
export function loginTestUser(options) {
|
|
225
230
|
const clientId = options.clientId || process.env.WEBEX_CLIENT_ID;
|
|
226
231
|
const clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;
|
|
227
|
-
const cigServiceUrl =
|
|
232
|
+
const cigServiceUrl =
|
|
233
|
+
options.cigServiceUrl ||
|
|
234
|
+
process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL ||
|
|
235
|
+
process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;
|
|
228
236
|
|
|
229
237
|
if (!clientId) {
|
|
230
238
|
throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');
|
|
@@ -235,7 +243,9 @@ export function loginTestUser(options) {
|
|
|
235
243
|
}
|
|
236
244
|
|
|
237
245
|
if (!cigServiceUrl) {
|
|
238
|
-
throw new Error(
|
|
246
|
+
throw new Error(
|
|
247
|
+
'options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined'
|
|
248
|
+
);
|
|
239
249
|
}
|
|
240
250
|
|
|
241
251
|
return request({
|
|
@@ -244,10 +254,9 @@ export function loginTestUser(options) {
|
|
|
244
254
|
json: true,
|
|
245
255
|
body: _.defaultsDeep(options, {
|
|
246
256
|
clientId,
|
|
247
|
-
clientSecret
|
|
248
|
-
})
|
|
249
|
-
})
|
|
250
|
-
.then((res) => fixToken(res.body));
|
|
257
|
+
clientSecret,
|
|
258
|
+
}),
|
|
259
|
+
}).then((res) => fixToken(res.body));
|
|
251
260
|
}
|
|
252
261
|
|
|
253
262
|
/**
|
|
@@ -261,10 +270,15 @@ export function loginTestUser(options) {
|
|
|
261
270
|
* @returns {Promise}
|
|
262
271
|
*/
|
|
263
272
|
export function removeTestUser(options = {}) {
|
|
264
|
-
const cigServiceUrl =
|
|
273
|
+
const cigServiceUrl =
|
|
274
|
+
options.cigServiceUrl ||
|
|
275
|
+
process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL ||
|
|
276
|
+
process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;
|
|
265
277
|
|
|
266
278
|
if (!cigServiceUrl) {
|
|
267
|
-
throw new Error(
|
|
279
|
+
throw new Error(
|
|
280
|
+
'options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined'
|
|
281
|
+
);
|
|
268
282
|
}
|
|
269
283
|
|
|
270
284
|
if (!options.id) {
|
|
@@ -272,12 +286,11 @@ export function removeTestUser(options = {}) {
|
|
|
272
286
|
}
|
|
273
287
|
|
|
274
288
|
if (!options.token) {
|
|
275
|
-
return loginTestUser(options)
|
|
276
|
-
.
|
|
277
|
-
options.token = token;
|
|
289
|
+
return loginTestUser(options).then((token) => {
|
|
290
|
+
options.token = token;
|
|
278
291
|
|
|
279
|
-
|
|
280
|
-
|
|
292
|
+
return removeTestUser(options);
|
|
293
|
+
});
|
|
281
294
|
}
|
|
282
295
|
|
|
283
296
|
assert(options.token.authorization, 'options.token.authorization must be defined');
|
|
@@ -286,20 +299,20 @@ export function removeTestUser(options = {}) {
|
|
|
286
299
|
method: 'POST',
|
|
287
300
|
json: true,
|
|
288
301
|
headers: {
|
|
289
|
-
authorization: options.token.authorization
|
|
302
|
+
authorization: options.token.authorization,
|
|
290
303
|
},
|
|
291
304
|
body: {
|
|
292
305
|
/* eslint-disable camelcase */
|
|
293
306
|
user_id: options.id,
|
|
294
307
|
refresh_token: options.token.refresh_token,
|
|
295
|
-
user_type: options.userType || 'PERSON'
|
|
308
|
+
user_type: options.userType || 'PERSON',
|
|
296
309
|
/* eslint-enable camelcase */
|
|
297
310
|
},
|
|
298
|
-
uri: `${cigServiceUrl}${BASE_PATH}/delete
|
|
311
|
+
uri: `${cigServiceUrl}${BASE_PATH}/delete`,
|
|
299
312
|
});
|
|
300
313
|
}
|
|
301
314
|
|
|
302
315
|
export {
|
|
303
316
|
default as createWhistlerTestUser,
|
|
304
|
-
removeTestUser as removeWhistlerTestUser
|
|
317
|
+
removeTestUser as removeWhistlerTestUser,
|
|
305
318
|
} from './whistler';
|
package/src/whistler.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import btoa from 'btoa';
|
|
2
2
|
import {request} from '@webex/http-core';
|
|
3
|
+
import randomName from 'node-random-name';
|
|
4
|
+
import uuid from 'uuid';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Fetches credentials/access_token to talk to the whistler endpoint
|
|
@@ -20,47 +22,50 @@ const getClientCredentials = ({
|
|
|
20
22
|
orgId,
|
|
21
23
|
idbrokerUrl,
|
|
22
24
|
machineAccount,
|
|
23
|
-
machinePassword
|
|
24
|
-
}) =>
|
|
25
|
-
|
|
26
|
-
uri: `${idbrokerUrl}/idb/token/${orgId}/v2/actions/GetBearerToken/invoke`,
|
|
27
|
-
json: true,
|
|
28
|
-
body: {
|
|
29
|
-
uid: machineAccount,
|
|
30
|
-
password: machinePassword
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
.then((res) => request({
|
|
25
|
+
machinePassword,
|
|
26
|
+
}) =>
|
|
27
|
+
request({
|
|
34
28
|
method: 'POST',
|
|
35
|
-
uri: `${idbrokerUrl}/idb/
|
|
29
|
+
uri: `${idbrokerUrl}/idb/token/${orgId}/v2/actions/GetBearerToken/invoke`,
|
|
36
30
|
json: true,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
scope: 'webexsquare:get_conversation webexsquare:admin',
|
|
41
|
-
self_contained_token: true,
|
|
42
|
-
client_id: clientId,
|
|
43
|
-
client_secret: clientSecret
|
|
31
|
+
body: {
|
|
32
|
+
uid: machineAccount,
|
|
33
|
+
password: machinePassword,
|
|
44
34
|
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
35
|
+
})
|
|
36
|
+
.then((res) =>
|
|
37
|
+
request({
|
|
38
|
+
method: 'POST',
|
|
39
|
+
uri: `${idbrokerUrl}/idb/oauth2/v1/access_token`,
|
|
40
|
+
json: true,
|
|
41
|
+
form: {
|
|
42
|
+
assertion: res.body.BearerToken,
|
|
43
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:saml2-bearer',
|
|
44
|
+
scope: 'webexsquare:get_conversation webexsquare:admin',
|
|
45
|
+
self_contained_token: true,
|
|
46
|
+
client_id: clientId,
|
|
47
|
+
client_secret: clientSecret,
|
|
48
|
+
},
|
|
49
|
+
headers: {
|
|
50
|
+
// Note: we can't request's auth hash here because this endpoint expects
|
|
51
|
+
// us to send the auth header *without including "Basic "* before the
|
|
52
|
+
// token string
|
|
53
|
+
// authorization: `Basic + ${btoa(`${clientId}:${clientSecret}`)}`
|
|
54
|
+
authorization: btoa(`${clientId}:${clientSecret}`),
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
)
|
|
58
|
+
.then((res) => `${res.body.token_type} ${res.body.access_token}`);
|
|
54
59
|
|
|
55
60
|
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
* @typedef {Object} TestUserObject
|
|
62
|
+
* @property {string} password
|
|
63
|
+
* @property {string} emailAddress
|
|
64
|
+
* @property {string} displayName
|
|
65
|
+
* @property {string} token
|
|
66
|
+
* @property {string} reservationUrl
|
|
67
|
+
* @property {object} responseMetaData - whistler given properties
|
|
68
|
+
*/
|
|
64
69
|
|
|
65
70
|
/**
|
|
66
71
|
* @typedef {Object} CreateUserOptions
|
|
@@ -82,8 +87,10 @@ const getClientCredentials = ({
|
|
|
82
87
|
export default function createTestUser(options = {}) {
|
|
83
88
|
const clientId = options.clientId || process.env.WEBEX_CLIENT_ID;
|
|
84
89
|
const clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;
|
|
85
|
-
const machineAccount =
|
|
86
|
-
|
|
90
|
+
const machineAccount =
|
|
91
|
+
options.machineAccount || process.env.WHISTLER_MACHINE_ACCOUNT || randomName();
|
|
92
|
+
const machinePassword =
|
|
93
|
+
options.machinePassword || process.env.WHISTLER_MACHINE_PASSWORD || `${uuid.v4()}zAY1*`;
|
|
87
94
|
const idbrokerUrl = options.idbrokerUrl || process.env.IDBROKER_BASE_URL;
|
|
88
95
|
const orgId = options.orgId || process.env.WHISTLER_TEST_ORG_ID;
|
|
89
96
|
const whistlerServiceUrl = options.whistlerServiceUrl || process.env.WHISTLER_API_SERVICE_URL;
|
|
@@ -98,11 +105,15 @@ export default function createTestUser(options = {}) {
|
|
|
98
105
|
}
|
|
99
106
|
|
|
100
107
|
if (!machineAccount) {
|
|
101
|
-
throw new Error(
|
|
108
|
+
throw new Error(
|
|
109
|
+
'options.machineAccount or process.env.WHISTLER_MACHINE_ACCOUNT must be defined'
|
|
110
|
+
);
|
|
102
111
|
}
|
|
103
112
|
|
|
104
113
|
if (!machinePassword) {
|
|
105
|
-
throw new Error(
|
|
114
|
+
throw new Error(
|
|
115
|
+
'options.machinePassword or process.env.WHISTLER_MACHINE_PASSWORD must be defined'
|
|
116
|
+
);
|
|
106
117
|
}
|
|
107
118
|
if (!idbrokerUrl) {
|
|
108
119
|
throw new Error('options.idbrokerUrl or process.env.IDBROKER_BASE_URL must be defined');
|
|
@@ -113,7 +124,9 @@ export default function createTestUser(options = {}) {
|
|
|
113
124
|
}
|
|
114
125
|
|
|
115
126
|
if (!whistlerServiceUrl) {
|
|
116
|
-
throw new Error(
|
|
127
|
+
throw new Error(
|
|
128
|
+
'options.whistlerServiceUrl or process.env.WHISTLER_API_SERVICE_URL must be defined'
|
|
129
|
+
);
|
|
117
130
|
}
|
|
118
131
|
|
|
119
132
|
// For reservation groups and user scopes
|
|
@@ -124,27 +137,30 @@ export default function createTestUser(options = {}) {
|
|
|
124
137
|
machineAccount,
|
|
125
138
|
machinePassword,
|
|
126
139
|
idbrokerUrl,
|
|
127
|
-
orgId
|
|
140
|
+
orgId,
|
|
128
141
|
})
|
|
129
|
-
.then((authorization) =>
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
+
.then((authorization) =>
|
|
143
|
+
request({
|
|
144
|
+
method: 'GET',
|
|
145
|
+
uri: `${whistlerServiceUrl}/reservations/testUser`,
|
|
146
|
+
qs: {
|
|
147
|
+
reservationGroup,
|
|
148
|
+
userScopes,
|
|
149
|
+
isAccessTokenRequired: true,
|
|
150
|
+
},
|
|
151
|
+
headers: {
|
|
152
|
+
authorization,
|
|
153
|
+
},
|
|
154
|
+
})
|
|
155
|
+
)
|
|
156
|
+
.then((res) => ({
|
|
142
157
|
password: res.body.responseMetaData.ciPassword,
|
|
143
158
|
emailAddress: res.body.responseMetaData.name,
|
|
144
159
|
displayName: res.body.responseMetaData.webExUserName,
|
|
145
160
|
token: res.body.responseMetaData.ciAccessToken,
|
|
146
|
-
reservationUrl: res.body.reservationUrl
|
|
147
|
-
|
|
161
|
+
reservationUrl: res.body.reservationUrl,
|
|
162
|
+
...res.body.responseMetaData,
|
|
163
|
+
}));
|
|
148
164
|
}
|
|
149
165
|
|
|
150
166
|
/**
|
|
@@ -156,8 +172,8 @@ export function removeTestUser(options = {}) {
|
|
|
156
172
|
return request({
|
|
157
173
|
method: 'DELETE',
|
|
158
174
|
headers: {
|
|
159
|
-
authorization: `Bearer ${options.token}
|
|
175
|
+
authorization: `Bearer ${options.token}`,
|
|
160
176
|
},
|
|
161
|
-
uri: options.reservationUrl
|
|
177
|
+
uri: options.reservationUrl,
|
|
162
178
|
});
|
|
163
179
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
import chai from 'chai';
|
|
3
2
|
import chaiAsPromised from 'chai-as-promised';
|
|
4
3
|
import uuid from 'uuid';
|
|
@@ -15,7 +14,10 @@ assert.hasAccessToken = (user) => {
|
|
|
15
14
|
assert.isDefined(user.token.expires_in, 'user.token.expires_in is defined');
|
|
16
15
|
assert.isDefined(user.token.token_type, 'user.token.token_type is defined');
|
|
17
16
|
assert.isDefined(user.token.refresh_token, 'user.token.refresh_token is defined');
|
|
18
|
-
assert.isDefined(
|
|
17
|
+
assert.isDefined(
|
|
18
|
+
user.token.refresh_token_expires_in,
|
|
19
|
+
'user.token.refresh_token_expires_in is defined'
|
|
20
|
+
);
|
|
19
21
|
assert.isDefined(user.token.expires, 'user.token.expires is defined');
|
|
20
22
|
assert.isDefined(user.token.refresh_token_expires, 'user.token.refresh_token_expires is defined');
|
|
21
23
|
};
|
|
@@ -28,7 +30,10 @@ assert.hasAuthorizationCode = (user) => {
|
|
|
28
30
|
assert.hasRefreshToken = (user) => {
|
|
29
31
|
assert.isDefined(user.token, 'user.token is defined');
|
|
30
32
|
assert.isDefined(user.token.refresh_token, 'user.token.refresh_token is defined');
|
|
31
|
-
assert.isDefined(
|
|
33
|
+
assert.isDefined(
|
|
34
|
+
user.token.refresh_token_expires_in,
|
|
35
|
+
'user.token.refresh_token_expires_in is defined'
|
|
36
|
+
);
|
|
32
37
|
assert.isDefined(user.token.refresh_token_expires, 'user.token.refresh_token_expires is defined');
|
|
33
38
|
};
|
|
34
39
|
|
|
@@ -50,7 +55,7 @@ nodeOnly(describe)('test-users', () => {
|
|
|
50
55
|
return {
|
|
51
56
|
id: user.id,
|
|
52
57
|
email: user.emailAddress || user.email,
|
|
53
|
-
password: user.password
|
|
58
|
+
password: user.password,
|
|
54
59
|
};
|
|
55
60
|
}
|
|
56
61
|
|
|
@@ -59,51 +64,53 @@ nodeOnly(describe)('test-users', () => {
|
|
|
59
64
|
|
|
60
65
|
return request({
|
|
61
66
|
method: 'POST',
|
|
62
|
-
uri: `${
|
|
67
|
+
uri: `${
|
|
68
|
+
process.env.IDBROKER_BASE_URL || 'https://idbroker.webex.com'
|
|
69
|
+
}/idb/oauth2/v1/access_token`,
|
|
63
70
|
form: {
|
|
64
71
|
/* eslint-disable camelcase */
|
|
65
72
|
grant_type: 'refresh_token',
|
|
66
73
|
redirect_uri: process.env.WEBEX_REDIRECT_URI,
|
|
67
|
-
refresh_token: user.token.refresh_token
|
|
74
|
+
refresh_token: user.token.refresh_token,
|
|
68
75
|
/* eslint-enable */
|
|
69
76
|
},
|
|
70
77
|
auth: {
|
|
71
78
|
user: process.env.WEBEX_CLIENT_ID,
|
|
72
|
-
pass: process.env.WEBEX_CLIENT_SECRET
|
|
73
|
-
}
|
|
79
|
+
pass: process.env.WEBEX_CLIENT_SECRET,
|
|
80
|
+
},
|
|
74
81
|
});
|
|
75
82
|
}
|
|
76
83
|
|
|
77
84
|
describe('createTestUser()', () => {
|
|
78
|
-
it('creates a test user', () =>
|
|
79
|
-
.then((u) => {
|
|
85
|
+
it('creates a test user', () =>
|
|
86
|
+
createTestUser().then((u) => {
|
|
80
87
|
assert.isTestUser(u);
|
|
81
88
|
assert.hasAccessToken(u);
|
|
82
89
|
}));
|
|
83
90
|
|
|
84
|
-
it('creates a test user with a custom email address', () =>
|
|
85
|
-
.then((u) => {
|
|
91
|
+
it('creates a test user with a custom email address', () =>
|
|
92
|
+
createTestUser({emailAddress}).then((u) => {
|
|
86
93
|
assert.isTestUser(u);
|
|
87
94
|
assert.hasAccessToken(u);
|
|
88
95
|
assert.equal(u.email, emailAddress);
|
|
89
96
|
}));
|
|
90
97
|
|
|
91
|
-
it('creates a test user with a custom password', () =>
|
|
92
|
-
.then((u) => {
|
|
98
|
+
it('creates a test user with a custom password', () =>
|
|
99
|
+
createTestUser({password}).then((u) => {
|
|
93
100
|
assert.isTestUser(u);
|
|
94
101
|
assert.hasAccessToken(u);
|
|
95
102
|
assert.equal(u.password, password);
|
|
96
103
|
}));
|
|
97
104
|
|
|
98
|
-
it('creates a test user with a custom display name', () =>
|
|
99
|
-
.then((u) => {
|
|
105
|
+
it('creates a test user with a custom display name', () =>
|
|
106
|
+
createTestUser({displayName}).then((u) => {
|
|
100
107
|
assert.isTestUser(u);
|
|
101
108
|
assert.hasAccessToken(u);
|
|
102
109
|
assert.equal(u.displayName, displayName);
|
|
103
110
|
}));
|
|
104
111
|
|
|
105
|
-
it('creates a test user with a usable refresh token', () =>
|
|
106
|
-
.then(async (u) => {
|
|
112
|
+
it('creates a test user with a usable refresh token', () =>
|
|
113
|
+
createTestUser({}).then(async (u) => {
|
|
107
114
|
assert.isTestUser(u);
|
|
108
115
|
assert.hasAccessToken(u);
|
|
109
116
|
|
|
@@ -112,8 +119,8 @@ nodeOnly(describe)('test-users', () => {
|
|
|
112
119
|
assert.equal(res.statusCode, 200);
|
|
113
120
|
}));
|
|
114
121
|
|
|
115
|
-
it('creates a test user but returns an authorization code', () =>
|
|
116
|
-
.then((u) => {
|
|
122
|
+
it('creates a test user but returns an authorization code', () =>
|
|
123
|
+
createTestUser({authCodeOnly: true}).then((u) => {
|
|
117
124
|
assert.isTestUser(u);
|
|
118
125
|
assert.hasAuthorizationCode(u);
|
|
119
126
|
}));
|
|
@@ -121,70 +128,75 @@ nodeOnly(describe)('test-users', () => {
|
|
|
121
128
|
it('creates a test user in another org', async () => {
|
|
122
129
|
const u = await createTestUser({
|
|
123
130
|
orgId: 'kmsFederation',
|
|
124
|
-
entitlements: ['webExSquared']
|
|
131
|
+
entitlements: ['webExSquared'],
|
|
125
132
|
});
|
|
126
133
|
|
|
127
134
|
assert.isTestUser(u);
|
|
128
135
|
assert.hasAccessToken(u);
|
|
129
136
|
});
|
|
130
137
|
|
|
131
|
-
it('creates a machine type test user', () =>
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
138
|
+
it('creates a machine type test user', () =>
|
|
139
|
+
createTestUser({
|
|
140
|
+
machineType: 'LYRA_SPACE',
|
|
141
|
+
type: 'MACHINE',
|
|
142
|
+
}).then((u) => {
|
|
143
|
+
assert.isTestUser(u);
|
|
144
|
+
assert.equal(u.type, 'MACHINE', 'type is MACHINE');
|
|
145
|
+
assert.equal(u.machineType, 'LYRA_SPACE', 'machineType is LYRA_SPACE');
|
|
146
|
+
}));
|
|
139
147
|
});
|
|
140
148
|
|
|
141
149
|
describe('loginTestUser()', () => {
|
|
142
|
-
it('retrieves credentials for the specified user', () =>
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
150
|
+
it('retrieves credentials for the specified user', () =>
|
|
151
|
+
createTestUser()
|
|
152
|
+
.then(prune)
|
|
153
|
+
.then(loginTestUser)
|
|
154
|
+
.then((token) => {
|
|
155
|
+
assert.hasAccessToken({token});
|
|
156
|
+
}));
|
|
157
|
+
|
|
158
|
+
it('retrieves credentials with a useable refresh token', () =>
|
|
159
|
+
createTestUser()
|
|
160
|
+
.then(prune)
|
|
161
|
+
.then(loginTestUser)
|
|
162
|
+
.then(async (token) => {
|
|
163
|
+
assert.hasAccessToken({token});
|
|
164
|
+
assert.hasRefreshToken({token});
|
|
165
|
+
|
|
166
|
+
const res = await refresh({token});
|
|
167
|
+
|
|
168
|
+
assert.equal(res.statusCode, 200);
|
|
169
|
+
}));
|
|
160
170
|
});
|
|
161
171
|
|
|
162
172
|
describe('removeTestUser()', () => {
|
|
163
|
-
it('removes the specified test user', () =>
|
|
164
|
-
.then(async (u) => {
|
|
173
|
+
it('removes the specified test user', () =>
|
|
174
|
+
createTestUser().then(async (u) => {
|
|
165
175
|
const res = await removeTestUser(u);
|
|
166
176
|
|
|
167
177
|
assert.equal(res.statusCode, 204);
|
|
168
178
|
}));
|
|
169
179
|
|
|
170
|
-
it('removes a test user if no access token is available', () =>
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
180
|
+
it('removes a test user if no access token is available', () =>
|
|
181
|
+
createTestUser()
|
|
182
|
+
.then(prune)
|
|
183
|
+
.then(async (u) => {
|
|
184
|
+
const res = await removeTestUser(u);
|
|
174
185
|
|
|
175
|
-
|
|
176
|
-
|
|
186
|
+
assert.equal(res.statusCode, 204);
|
|
187
|
+
}));
|
|
177
188
|
|
|
178
|
-
it('removes a test user with an access token set to undefined', () =>
|
|
179
|
-
|
|
180
|
-
user
|
|
189
|
+
it('removes a test user with an access token set to undefined', () =>
|
|
190
|
+
createTestUser()
|
|
191
|
+
.then((user) => {
|
|
192
|
+
user.token = undefined;
|
|
181
193
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
194
|
+
return user;
|
|
195
|
+
})
|
|
196
|
+
.then(async (u) => {
|
|
197
|
+
const res = await removeTestUser(u);
|
|
186
198
|
|
|
187
|
-
|
|
188
|
-
|
|
199
|
+
assert.equal(res.statusCode, 204);
|
|
200
|
+
}));
|
|
189
201
|
});
|
|
190
202
|
});
|