@webex/test-users 3.0.0-beta.41 → 3.0.0-beta.410
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/index.js +57 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/index.js +58 -0
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ _Object$defineProperty(exports, "removeWhistlerTestUser", {
|
|
|
27
27
|
return _whistler.removeTestUser;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
+
exports.setPreferredSite = setPreferredSite;
|
|
30
31
|
var _now = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/date/now"));
|
|
31
32
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
32
33
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
@@ -155,6 +156,10 @@ function requestWithAuth(options) {
|
|
|
155
156
|
* @property {string} [roles] defaults to []
|
|
156
157
|
* @property {string} [scope] defaults to WEBEX_SCOPE
|
|
157
158
|
* @property {string} [type] used to create a machine
|
|
159
|
+
* @property {boolean} [forceCreate] force creates the user, to be used in conjunction with ensureExistsInWebexSites
|
|
160
|
+
* @property {boolean} [ensureExistsInWebexSites] syncs the user in provided webexSites (syncInWebexSites)
|
|
161
|
+
* @property {Array.<string>} [syncInWebexSites] used to define in which sites account should be synced
|
|
162
|
+
* @property {string} [orgAdminAuthorization] bearer token of org admin to use syncInWebexSites
|
|
158
163
|
*/
|
|
159
164
|
|
|
160
165
|
/**
|
|
@@ -202,7 +207,7 @@ function createTestUser() {
|
|
|
202
207
|
clientSecret: clientSecret,
|
|
203
208
|
displayName: options.displayName || (0, _nodeRandomName.default)(),
|
|
204
209
|
emailTemplate: options.emailAddress,
|
|
205
|
-
entitlements: options.entitlements || ['spark', 'squaredCallInitiation', 'squaredRoomModeration', 'squaredInviter', 'webExSquared'],
|
|
210
|
+
entitlements: options.entitlements || ['spark', 'squaredCallInitiation', 'squaredRoomModeration', 'squaredInviter', 'webExSquared', 'basicMessage'],
|
|
206
211
|
idbrokerUrl: idbrokerUrl,
|
|
207
212
|
machineType: options.machineType,
|
|
208
213
|
orgId: options.orgId,
|
|
@@ -210,7 +215,11 @@ function createTestUser() {
|
|
|
210
215
|
password: options.password || "".concat(_uuid.default.v4(), "zAY1*"),
|
|
211
216
|
roles: options.roles || [],
|
|
212
217
|
scopes: options.scope || process.env.WEBEX_SCOPE,
|
|
213
|
-
type: options.type
|
|
218
|
+
type: options.type,
|
|
219
|
+
forceCreate: options.forceCreate || false,
|
|
220
|
+
ensureExistsInWebexSites: options.ensureExistsInWebexSites || false,
|
|
221
|
+
syncInWebexSites: options.syncInWebexSites,
|
|
222
|
+
orgAdminAuthorization: options.orgAdminAuthorization
|
|
214
223
|
};
|
|
215
224
|
return requestWithAuth({
|
|
216
225
|
method: 'POST',
|
|
@@ -308,4 +317,50 @@ function removeTestUser() {
|
|
|
308
317
|
uri: "".concat(cigServiceUrl).concat(BASE_PATH, "/delete")
|
|
309
318
|
});
|
|
310
319
|
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Sets the preferredWebexSite for the provided user
|
|
323
|
+
*
|
|
324
|
+
* This method should be used to ensure a created test user has the right webex site set.
|
|
325
|
+
*
|
|
326
|
+
* @param {Object} options
|
|
327
|
+
* @param {string} options.userId user id to set site
|
|
328
|
+
* @param {string} options.preferredSite new preferred webexsite
|
|
329
|
+
* @param {string} options.orgId orgId of the site
|
|
330
|
+
* @param {string} options.identityServiceUrl url of identity service
|
|
331
|
+
* @param {string} options.authorization
|
|
332
|
+
* @param {string} options.clientId
|
|
333
|
+
* @param {string} options.clientSecret
|
|
334
|
+
* @returns {Promise}
|
|
335
|
+
*/
|
|
336
|
+
function setPreferredSite() {
|
|
337
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
338
|
+
var clientId = options.clientId || process.env.WEBEX_CLIENT_ID;
|
|
339
|
+
var clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;
|
|
340
|
+
if (!clientId) {
|
|
341
|
+
throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');
|
|
342
|
+
}
|
|
343
|
+
if (!clientSecret) {
|
|
344
|
+
throw new Error('options.clientSecret or process.env.WEBEX_CLIENT_SECRET must be defined');
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/* eslint-disable no-useless-escape */
|
|
348
|
+
var body = {
|
|
349
|
+
schemas: ['urn:scim:schemas:core:1.0', 'urn:scim:schemas:extension:cisco:commonidentity:1.0'],
|
|
350
|
+
userPreferences: [{
|
|
351
|
+
value: "\"preferredWebExSite\":\"".concat(options.preferredSite, "\"")
|
|
352
|
+
}]
|
|
353
|
+
};
|
|
354
|
+
/* eslint-enable no-useless-escape */
|
|
355
|
+
|
|
356
|
+
return (0, _httpCore.request)({
|
|
357
|
+
method: 'PATCH',
|
|
358
|
+
headers: {
|
|
359
|
+
authorization: options.authorization
|
|
360
|
+
},
|
|
361
|
+
uri: "".concat(options.identityServiceUrl, "/identity/scim/").concat(options.orgId, "/v1/Users/").concat(options.userId),
|
|
362
|
+
json: true,
|
|
363
|
+
body: body
|
|
364
|
+
});
|
|
365
|
+
}
|
|
311
366
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BASE_PATH_SECURE","BASE_PATH","fixToken","token","now","expires_in","expires","refresh_token_expires_in","refresh_token_expires","token_type","access_token","authorization","clientToken","getClientCredentials","clientId","clientSecret","idbrokerUrl","resolve","request","method","uri","json","form","grant_type","scope","client_id","client_secret","headers","btoa","then","res","body","requestWithAuth","options","createTestUser","process","env","WEBEX_CLIENT_ID","WEBEX_CLIENT_SECRET","IDBROKER_BASE_URL","cigServiceUrl","WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL","WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL","Error","authCodeOnly","displayName","randomName","emailTemplate","emailAddress","entitlements","machineType","orgId","password","uuid","v4","roles","scopes","WEBEX_SCOPE","type","user","email","name","loginTestUser","removeTestUser","id","reject","assert","user_id","refresh_token","user_type","userType"],"sources":["index.js"],"sourcesContent":["import assert from 'assert';\n\nimport uuid from 'uuid';\nimport btoa from 'btoa';\nimport _ from 'lodash';\nimport randomName from 'node-random-name';\nimport {request} from '@webex/http-core';\n\nconst BASE_PATH_SECURE = '/users/test_users_s';\nconst BASE_PATH = '/users/test_users';\n\n/**\n * Computes `expires` and `refresh_token_expires` from `expires_in` and\n * `refresh_token_expires_in` and creates an `authorization` string.\n * @param {Object} token\n * @private\n * @returns {Object}\n */\nfunction fixToken(token) {\n const now = Date.now();\n\n if (token.expires_in && !token.expires) {\n token.expires = now + token.expires_in * 1000;\n }\n\n if (token.refresh_token_expires_in && !token.refresh_token_expires) {\n /* eslint camelcase: [0] */\n token.refresh_token_expires = now + token.refresh_token_expires_in * 1000;\n }\n\n if (token.token_type && token.access_token) {\n token.authorization = `${token.token_type} ${token.access_token}`;\n }\n\n return token;\n}\n\nlet clientToken;\n\n/**\n * Fetches credentials to talk to the test_users_s endpoint\n *\n * Caches result in `clientToken` variable for multiple runs\n * @param {Object} options\n * @param {string} options.clientId\n * @param {string} options.clientSecret\n * @param {string} options.idbrokerUrl\n * @private\n * @returns {String}\n */\nfunction getClientCredentials({clientId, clientSecret, idbrokerUrl}) {\n if (clientToken) {\n return Promise.resolve(clientToken);\n }\n\n return request({\n method: 'POST',\n uri: `${idbrokerUrl}/idb/oauth2/v1/access_token`,\n json: true,\n form: {\n grant_type: 'client_credentials',\n scope: 'Identity:SCIM webexsquare:get_conversation',\n client_id: clientId,\n client_secret: clientSecret,\n },\n headers: {\n // Note: we can't request's auth hash here because this endpoint expects\n // us to send the auth header *without including \"Basic \"* before the\n // token string\n authorization: btoa(`${clientId}:${clientSecret}`),\n },\n })\n .then((res) => {\n const token = fixToken(res.body);\n\n return `${token.token_type} ${token.access_token}`;\n })\n .then((token) => {\n clientToken = token;\n\n return clientToken;\n });\n}\n\n/**\n * Makes a request authorized with client credentials\n * @param {Object} options\n * @param {Object} options.body\n * @param {string} options.body.clientId\n * @param {string} options.body.clientSecret\n * @param {string} options.body.idbrokerUrl\n * @private\n * @returns {Promise<HttpResponseObject>}\n */\nfunction requestWithAuth(options) {\n return getClientCredentials(options.body).then((authorization) => {\n options.headers = options.headers || {};\n options.headers.authorization = authorization;\n\n return request(options);\n });\n}\n\n/**\n * @typedef {Object} AccessTokenObject\n * @property {string} token.access_token\n * @property {Number} token.expires_in\n * @property {string} token.token_type\n * @property {string} token.refresh_token\n * @property {Number} token.refresh_token_expires_in\n * @property {string} token.expires\n * @property {string} token.refresh_token_expires\n */\n\n/**\n * @typedef {Object} CreateUserOptions\n * @property {boolean} [authCodeOnly] generates auth_code\n * @param {string} [clientId] defaults to WEBEX_CLIENT_ID\n * @param {string} [clientSecret] defaults to WEBEX_CLIENT_SECRET\n * @param {string} [cigServiceUrl] defaults to WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL\n * @property {string} [displayName]\n * @property {string} [emailAddress]\n * @property {Array.<string>} [entitlements]\n * @param {string} [idbrokerUrl] defaults to IDBROKER_BASE_URL\n * @property {string} [machineType] used when creating a machine user/device\n * @property {string} [orgId] organization ID to create the user under\n * @property {string} [password] defaults to a random password\n * @property {string} [roles] defaults to []\n * @property {string} [scope] defaults to WEBEX_SCOPE\n * @property {string} [type] used to create a machine\n */\n\n/**\n * @typedef {Object} TestUserObject\n * @property {string} password\n * @property {string} emailAddress\n * @property {string} displayName\n * @property {string} id\n * @property {string} userName\n * @property {string} email\n * @property {string} name\n * @property {string} givenName\n * @property {string} type\n * @property {Array.<string>} entitlements\n * @property {string} orgId\n * @property {AccessTokenObject} token\n */\n\n/**\n * Creates a test user\n * @param {CreateUserOptions} options\n * @returns {Promise.<TestUserObject>}\n */\nexport function createTestUser(options = {}) {\n const clientId = options.clientId || process.env.WEBEX_CLIENT_ID;\n const clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;\n const idbrokerUrl = options.idbrokerUrl || process.env.IDBROKER_BASE_URL;\n const cigServiceUrl =\n options.cigServiceUrl ||\n process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL ||\n process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;\n\n if (!clientId) {\n throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');\n }\n\n if (!clientSecret) {\n throw new Error('options.clientSecret or process.env.WEBEX_CLIENT_SECRET must be defined');\n }\n\n if (!idbrokerUrl) {\n throw new Error('options.idbrokerUrl or process.env.IDBROKER_BASE_URL must be defined');\n }\n\n if (!cigServiceUrl) {\n throw new Error(\n 'options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined'\n );\n }\n\n const body = {\n authCodeOnly: options.authCodeOnly,\n clientId,\n clientSecret,\n displayName: options.displayName || randomName(),\n emailTemplate: options.emailAddress,\n entitlements: options.entitlements || [\n 'spark',\n 'squaredCallInitiation',\n 'squaredRoomModeration',\n 'squaredInviter',\n 'webExSquared',\n ],\n idbrokerUrl,\n machineType: options.machineType,\n orgId: options.orgId,\n // The five characters on the end are to hit all the password requirements\n password: options.password || `${uuid.v4()}zAY1*`,\n roles: options.roles || [],\n scopes: options.scope || process.env.WEBEX_SCOPE,\n type: options.type,\n };\n\n return requestWithAuth({\n method: 'POST',\n uri: `${cigServiceUrl}${BASE_PATH_SECURE}`,\n json: true,\n body,\n }).then((res) => ({\n password: body.password,\n emailAddress: res.body.user.email,\n displayName: res.body.user.name,\n ...res.body.user,\n token: fixToken(res.body.token),\n }));\n}\n\n/**\n * Exchanges a user name/password for an access token\n * @param {Object} options\n * @param {string} options.id\n * @param {string} options.email\n * @param {string} options.password\n * @param {string} options.clientId\n * @param {string} options.clientSecret\n * @param {string} options.cigServiceUrl\n * @returns {Promise.<AccessTokenObject>}\n */\nexport function loginTestUser(options) {\n const clientId = options.clientId || process.env.WEBEX_CLIENT_ID;\n const clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;\n const cigServiceUrl =\n options.cigServiceUrl ||\n process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL ||\n process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;\n\n if (!clientId) {\n throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');\n }\n\n if (!clientSecret) {\n throw new Error('options.clientSecret or process.env.WEBEX_CLIENT_SECRET must be defined');\n }\n\n if (!cigServiceUrl) {\n throw new Error(\n 'options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined'\n );\n }\n\n return request({\n method: 'POST',\n uri: `${cigServiceUrl}${BASE_PATH}/login`,\n json: true,\n body: _.defaultsDeep(options, {\n clientId,\n clientSecret,\n }),\n }).then((res) => fixToken(res.body));\n}\n\n/**\n * Removes a test user\n * @param {Object} options\n * @param {string} options.id user id to remove\n * @param {string} options.cigServiceUrl\n * @param {Object} options.token\n * @param {string} options.token.authorization\n * @param {string} [options.token.refresh_token]\n * @returns {Promise}\n */\nexport function removeTestUser(options = {}) {\n const cigServiceUrl =\n options.cigServiceUrl ||\n process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL ||\n process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;\n\n if (!cigServiceUrl) {\n throw new Error(\n 'options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined'\n );\n }\n\n if (!options.id) {\n return Promise.reject(new Error('options.id is required'));\n }\n\n if (!options.token) {\n return loginTestUser(options).then((token) => {\n options.token = token;\n\n return removeTestUser(options);\n });\n }\n\n assert(options.token.authorization, 'options.token.authorization must be defined');\n\n return request({\n method: 'POST',\n json: true,\n headers: {\n authorization: options.token.authorization,\n },\n body: {\n /* eslint-disable camelcase */\n user_id: options.id,\n refresh_token: options.token.refresh_token,\n user_type: options.userType || 'PERSON',\n /* eslint-enable camelcase */\n },\n uri: `${cigServiceUrl}${BASE_PATH}/delete`,\n });\n}\n\nexport {\n default as createWhistlerTestUser,\n removeTestUser as removeWhistlerTestUser,\n} from './whistler';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAEA;AACA;AAEA;AACA;AAoTA;AAGoB;AAAA;AAAA;AAAA;AArTpB,IAAMA,gBAAgB,GAAG,qBAAqB;AAC9C,IAAMC,SAAS,GAAG,mBAAmB;;AAErC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,QAAQ,CAACC,KAAK,EAAE;EACvB,IAAMC,GAAG,GAAG,mBAAU;EAEtB,IAAID,KAAK,CAACE,UAAU,IAAI,CAACF,KAAK,CAACG,OAAO,EAAE;IACtCH,KAAK,CAACG,OAAO,GAAGF,GAAG,GAAGD,KAAK,CAACE,UAAU,GAAG,IAAI;EAC/C;EAEA,IAAIF,KAAK,CAACI,wBAAwB,IAAI,CAACJ,KAAK,CAACK,qBAAqB,EAAE;IAClE;IACAL,KAAK,CAACK,qBAAqB,GAAGJ,GAAG,GAAGD,KAAK,CAACI,wBAAwB,GAAG,IAAI;EAC3E;EAEA,IAAIJ,KAAK,CAACM,UAAU,IAAIN,KAAK,CAACO,YAAY,EAAE;IAC1CP,KAAK,CAACQ,aAAa,aAAMR,KAAK,CAACM,UAAU,cAAIN,KAAK,CAACO,YAAY,CAAE;EACnE;EAEA,OAAOP,KAAK;AACd;AAEA,IAAIS,WAAW;;AAEf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,oBAAoB,OAAwC;EAAA,IAAtCC,QAAQ,QAARA,QAAQ;IAAEC,YAAY,QAAZA,YAAY;IAAEC,WAAW,QAAXA,WAAW;EAChE,IAAIJ,WAAW,EAAE;IACf,OAAO,iBAAQK,OAAO,CAACL,WAAW,CAAC;EACrC;EAEA,OAAO,IAAAM,iBAAO,EAAC;I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AAAiC,eAAM,EAACjC,OAAO,CAAC9B,KAAK,CAACQ,aAAa,EAAE,6CAA6C,CAAC;EAElF,OAAO,IAAAO,iBAAO,EAAC;IACbC,MAAM,EAAE,MAAM;IACdE,IAAI,EAAE,IAAI;IACVM,OAAO,EAAE;MACPhB,aAAa,EAAEsB,OAAO,CAAC9B,KAAK,CAACQ;IAC/B,CAAC;IACDoB,IAAI,EAAE;MACJ;MACAoC,OAAO,EAAElC,OAAO,CAAC+B,EAAE;MACnBI,aAAa,EAAEnC,OAAO,CAAC9B,KAAK,CAACiE,aAAa;MAC1CC,SAAS,EAAEpC,OAAO,CAACqC,QAAQ,IAAI;MAC/B;IACF,CAAC;;IACDlD,GAAG,YAAKoB,aAAa,SAAGvC,SAAS;EACnC,CAAC,CAAC;AACJ"}
|
|
1
|
+
{"version":3,"names":["BASE_PATH_SECURE","BASE_PATH","fixToken","token","now","expires_in","expires","refresh_token_expires_in","refresh_token_expires","token_type","access_token","authorization","clientToken","getClientCredentials","clientId","clientSecret","idbrokerUrl","resolve","request","method","uri","json","form","grant_type","scope","client_id","client_secret","headers","btoa","then","res","body","requestWithAuth","options","createTestUser","process","env","WEBEX_CLIENT_ID","WEBEX_CLIENT_SECRET","IDBROKER_BASE_URL","cigServiceUrl","WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL","WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL","Error","authCodeOnly","displayName","randomName","emailTemplate","emailAddress","entitlements","machineType","orgId","password","uuid","v4","roles","scopes","WEBEX_SCOPE","type","forceCreate","ensureExistsInWebexSites","syncInWebexSites","orgAdminAuthorization","user","email","name","loginTestUser","removeTestUser","id","reject","assert","user_id","refresh_token","user_type","userType","setPreferredSite","schemas","userPreferences","value","preferredSite","identityServiceUrl","userId"],"sources":["index.js"],"sourcesContent":["import assert from 'assert';\n\nimport uuid from 'uuid';\nimport btoa from 'btoa';\nimport _ from 'lodash';\nimport randomName from 'node-random-name';\nimport {request} from '@webex/http-core';\n\nconst BASE_PATH_SECURE = '/users/test_users_s';\nconst BASE_PATH = '/users/test_users';\n\n/**\n * Computes `expires` and `refresh_token_expires` from `expires_in` and\n * `refresh_token_expires_in` and creates an `authorization` string.\n * @param {Object} token\n * @private\n * @returns {Object}\n */\nfunction fixToken(token) {\n const now = Date.now();\n\n if (token.expires_in && !token.expires) {\n token.expires = now + token.expires_in * 1000;\n }\n\n if (token.refresh_token_expires_in && !token.refresh_token_expires) {\n /* eslint camelcase: [0] */\n token.refresh_token_expires = now + token.refresh_token_expires_in * 1000;\n }\n\n if (token.token_type && token.access_token) {\n token.authorization = `${token.token_type} ${token.access_token}`;\n }\n\n return token;\n}\n\nlet clientToken;\n\n/**\n * Fetches credentials to talk to the test_users_s endpoint\n *\n * Caches result in `clientToken` variable for multiple runs\n * @param {Object} options\n * @param {string} options.clientId\n * @param {string} options.clientSecret\n * @param {string} options.idbrokerUrl\n * @private\n * @returns {String}\n */\nfunction getClientCredentials({clientId, clientSecret, idbrokerUrl}) {\n if (clientToken) {\n return Promise.resolve(clientToken);\n }\n\n return request({\n method: 'POST',\n uri: `${idbrokerUrl}/idb/oauth2/v1/access_token`,\n json: true,\n form: {\n grant_type: 'client_credentials',\n scope: 'Identity:SCIM webexsquare:get_conversation',\n client_id: clientId,\n client_secret: clientSecret,\n },\n headers: {\n // Note: we can't request's auth hash here because this endpoint expects\n // us to send the auth header *without including \"Basic \"* before the\n // token string\n authorization: btoa(`${clientId}:${clientSecret}`),\n },\n })\n .then((res) => {\n const token = fixToken(res.body);\n\n return `${token.token_type} ${token.access_token}`;\n })\n .then((token) => {\n clientToken = token;\n\n return clientToken;\n });\n}\n\n/**\n * Makes a request authorized with client credentials\n * @param {Object} options\n * @param {Object} options.body\n * @param {string} options.body.clientId\n * @param {string} options.body.clientSecret\n * @param {string} options.body.idbrokerUrl\n * @private\n * @returns {Promise<HttpResponseObject>}\n */\nfunction requestWithAuth(options) {\n return getClientCredentials(options.body).then((authorization) => {\n options.headers = options.headers || {};\n options.headers.authorization = authorization;\n\n return request(options);\n });\n}\n\n/**\n * @typedef {Object} AccessTokenObject\n * @property {string} token.access_token\n * @property {Number} token.expires_in\n * @property {string} token.token_type\n * @property {string} token.refresh_token\n * @property {Number} token.refresh_token_expires_in\n * @property {string} token.expires\n * @property {string} token.refresh_token_expires\n */\n\n/**\n * @typedef {Object} CreateUserOptions\n * @property {boolean} [authCodeOnly] generates auth_code\n * @param {string} [clientId] defaults to WEBEX_CLIENT_ID\n * @param {string} [clientSecret] defaults to WEBEX_CLIENT_SECRET\n * @param {string} [cigServiceUrl] defaults to WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL\n * @property {string} [displayName]\n * @property {string} [emailAddress]\n * @property {Array.<string>} [entitlements]\n * @param {string} [idbrokerUrl] defaults to IDBROKER_BASE_URL\n * @property {string} [machineType] used when creating a machine user/device\n * @property {string} [orgId] organization ID to create the user under\n * @property {string} [password] defaults to a random password\n * @property {string} [roles] defaults to []\n * @property {string} [scope] defaults to WEBEX_SCOPE\n * @property {string} [type] used to create a machine\n * @property {boolean} [forceCreate] force creates the user, to be used in conjunction with ensureExistsInWebexSites\n * @property {boolean} [ensureExistsInWebexSites] syncs the user in provided webexSites (syncInWebexSites)\n * @property {Array.<string>} [syncInWebexSites] used to define in which sites account should be synced\n * @property {string} [orgAdminAuthorization] bearer token of org admin to use syncInWebexSites\n */\n\n/**\n * @typedef {Object} TestUserObject\n * @property {string} password\n * @property {string} emailAddress\n * @property {string} displayName\n * @property {string} id\n * @property {string} userName\n * @property {string} email\n * @property {string} name\n * @property {string} givenName\n * @property {string} type\n * @property {Array.<string>} entitlements\n * @property {string} orgId\n * @property {AccessTokenObject} token\n */\n\n/**\n * Creates a test user\n * @param {CreateUserOptions} options\n * @returns {Promise.<TestUserObject>}\n */\nexport function createTestUser(options = {}) {\n const clientId = options.clientId || process.env.WEBEX_CLIENT_ID;\n const clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;\n const idbrokerUrl = options.idbrokerUrl || process.env.IDBROKER_BASE_URL;\n const cigServiceUrl =\n options.cigServiceUrl ||\n process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL ||\n process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;\n\n if (!clientId) {\n throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');\n }\n\n if (!clientSecret) {\n throw new Error('options.clientSecret or process.env.WEBEX_CLIENT_SECRET must be defined');\n }\n\n if (!idbrokerUrl) {\n throw new Error('options.idbrokerUrl or process.env.IDBROKER_BASE_URL must be defined');\n }\n\n if (!cigServiceUrl) {\n throw new Error(\n 'options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined'\n );\n }\n\n const body = {\n authCodeOnly: options.authCodeOnly,\n clientId,\n clientSecret,\n displayName: options.displayName || randomName(),\n emailTemplate: options.emailAddress,\n entitlements: options.entitlements || [\n 'spark',\n 'squaredCallInitiation',\n 'squaredRoomModeration',\n 'squaredInviter',\n 'webExSquared',\n 'basicMessage',\n ],\n idbrokerUrl,\n machineType: options.machineType,\n orgId: options.orgId,\n // The five characters on the end are to hit all the password requirements\n password: options.password || `${uuid.v4()}zAY1*`,\n roles: options.roles || [],\n scopes: options.scope || process.env.WEBEX_SCOPE,\n type: options.type,\n forceCreate: options.forceCreate || false,\n ensureExistsInWebexSites: options.ensureExistsInWebexSites || false,\n syncInWebexSites: options.syncInWebexSites,\n orgAdminAuthorization: options.orgAdminAuthorization,\n };\n\n return requestWithAuth({\n method: 'POST',\n uri: `${cigServiceUrl}${BASE_PATH_SECURE}`,\n json: true,\n body,\n }).then((res) => ({\n password: body.password,\n emailAddress: res.body.user.email,\n displayName: res.body.user.name,\n ...res.body.user,\n token: fixToken(res.body.token),\n }));\n}\n\n/**\n * Exchanges a user name/password for an access token\n * @param {Object} options\n * @param {string} options.id\n * @param {string} options.email\n * @param {string} options.password\n * @param {string} options.clientId\n * @param {string} options.clientSecret\n * @param {string} options.cigServiceUrl\n * @returns {Promise.<AccessTokenObject>}\n */\nexport function loginTestUser(options) {\n const clientId = options.clientId || process.env.WEBEX_CLIENT_ID;\n const clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;\n const cigServiceUrl =\n options.cigServiceUrl ||\n process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL ||\n process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;\n\n if (!clientId) {\n throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');\n }\n\n if (!clientSecret) {\n throw new Error('options.clientSecret or process.env.WEBEX_CLIENT_SECRET must be defined');\n }\n\n if (!cigServiceUrl) {\n throw new Error(\n 'options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined'\n );\n }\n\n return request({\n method: 'POST',\n uri: `${cigServiceUrl}${BASE_PATH}/login`,\n json: true,\n body: _.defaultsDeep(options, {\n clientId,\n clientSecret,\n }),\n }).then((res) => fixToken(res.body));\n}\n\n/**\n * Removes a test user\n * @param {Object} options\n * @param {string} options.id user id to remove\n * @param {string} options.cigServiceUrl\n * @param {Object} options.token\n * @param {string} options.token.authorization\n * @param {string} [options.token.refresh_token]\n * @returns {Promise}\n */\nexport function removeTestUser(options = {}) {\n const cigServiceUrl =\n options.cigServiceUrl ||\n process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL ||\n process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;\n\n if (!cigServiceUrl) {\n throw new Error(\n 'options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined'\n );\n }\n\n if (!options.id) {\n return Promise.reject(new Error('options.id is required'));\n }\n\n if (!options.token) {\n return loginTestUser(options).then((token) => {\n options.token = token;\n\n return removeTestUser(options);\n });\n }\n\n assert(options.token.authorization, 'options.token.authorization must be defined');\n\n return request({\n method: 'POST',\n json: true,\n headers: {\n authorization: options.token.authorization,\n },\n body: {\n /* eslint-disable camelcase */\n user_id: options.id,\n refresh_token: options.token.refresh_token,\n user_type: options.userType || 'PERSON',\n /* eslint-enable camelcase */\n },\n uri: `${cigServiceUrl}${BASE_PATH}/delete`,\n });\n}\n\n/**\n * Sets the preferredWebexSite for the provided user\n *\n * This method should be used to ensure a created test user has the right webex site set.\n *\n * @param {Object} options\n * @param {string} options.userId user id to set site\n * @param {string} options.preferredSite new preferred webexsite\n * @param {string} options.orgId orgId of the site\n * @param {string} options.identityServiceUrl url of identity service\n * @param {string} options.authorization\n * @param {string} options.clientId\n * @param {string} options.clientSecret\n * @returns {Promise}\n */\nexport function setPreferredSite(options = {}) {\n const clientId = options.clientId || process.env.WEBEX_CLIENT_ID;\n const clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;\n\n if (!clientId) {\n throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');\n }\n\n if (!clientSecret) {\n throw new Error('options.clientSecret or process.env.WEBEX_CLIENT_SECRET must be defined');\n }\n\n /* eslint-disable no-useless-escape */\n const body = {\n schemas: ['urn:scim:schemas:core:1.0', 'urn:scim:schemas:extension:cisco:commonidentity:1.0'],\n userPreferences: [\n {\n value: `\\\"preferredWebExSite\\\":\\\"${options.preferredSite}\\\"`,\n },\n ],\n };\n /* eslint-enable no-useless-escape */\n\n return request({\n method: 'PATCH',\n headers: {\n authorization: options.authorization,\n },\n uri: `${options.identityServiceUrl}/identity/scim/${options.orgId}/v1/Users/${options.userId}`,\n json: true,\n body,\n });\n}\n\nexport {\n default as createWhistlerTestUser,\n removeTestUser as removeWhistlerTestUser,\n} from './whistler';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAEA;AACA;AAEA;AACA;AA8WA;AAGoB;AAAA;AAAA;AAAA;AA/WpB,IAAMA,gBAAgB,GAAG,qBAAqB;AAC9C,IAAMC,SAAS,GAAG,mBAAmB;;AAErC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,QA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gD,MAAM,CAAE;IAC9F5D,IAAI,EAAE,IAAI;IACVU,IAAI,EAAJA;EACF,CAAC,CAAC;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webex/test-users",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.410",
|
|
4
4
|
"description": "Cisco Webex Test Users",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"chai-as-promised": "^7.1.1"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@webex/http-core": "3.0.0-beta.
|
|
28
|
-
"@webex/test-helper-mocha": "3.0.0-beta.
|
|
29
|
-
"@webex/test-users": "3.0.0-beta.
|
|
27
|
+
"@webex/http-core": "3.0.0-beta.410",
|
|
28
|
+
"@webex/test-helper-mocha": "3.0.0-beta.410",
|
|
29
|
+
"@webex/test-users": "3.0.0-beta.410",
|
|
30
30
|
"btoa": "^1.2.1",
|
|
31
31
|
"lodash": "^4.17.21",
|
|
32
32
|
"node-random-name": "^1.0.1",
|
package/src/index.js
CHANGED
|
@@ -128,6 +128,10 @@ function requestWithAuth(options) {
|
|
|
128
128
|
* @property {string} [roles] defaults to []
|
|
129
129
|
* @property {string} [scope] defaults to WEBEX_SCOPE
|
|
130
130
|
* @property {string} [type] used to create a machine
|
|
131
|
+
* @property {boolean} [forceCreate] force creates the user, to be used in conjunction with ensureExistsInWebexSites
|
|
132
|
+
* @property {boolean} [ensureExistsInWebexSites] syncs the user in provided webexSites (syncInWebexSites)
|
|
133
|
+
* @property {Array.<string>} [syncInWebexSites] used to define in which sites account should be synced
|
|
134
|
+
* @property {string} [orgAdminAuthorization] bearer token of org admin to use syncInWebexSites
|
|
131
135
|
*/
|
|
132
136
|
|
|
133
137
|
/**
|
|
@@ -190,6 +194,7 @@ export function createTestUser(options = {}) {
|
|
|
190
194
|
'squaredRoomModeration',
|
|
191
195
|
'squaredInviter',
|
|
192
196
|
'webExSquared',
|
|
197
|
+
'basicMessage',
|
|
193
198
|
],
|
|
194
199
|
idbrokerUrl,
|
|
195
200
|
machineType: options.machineType,
|
|
@@ -199,6 +204,10 @@ export function createTestUser(options = {}) {
|
|
|
199
204
|
roles: options.roles || [],
|
|
200
205
|
scopes: options.scope || process.env.WEBEX_SCOPE,
|
|
201
206
|
type: options.type,
|
|
207
|
+
forceCreate: options.forceCreate || false,
|
|
208
|
+
ensureExistsInWebexSites: options.ensureExistsInWebexSites || false,
|
|
209
|
+
syncInWebexSites: options.syncInWebexSites,
|
|
210
|
+
orgAdminAuthorization: options.orgAdminAuthorization,
|
|
202
211
|
};
|
|
203
212
|
|
|
204
213
|
return requestWithAuth({
|
|
@@ -312,6 +321,55 @@ export function removeTestUser(options = {}) {
|
|
|
312
321
|
});
|
|
313
322
|
}
|
|
314
323
|
|
|
324
|
+
/**
|
|
325
|
+
* Sets the preferredWebexSite for the provided user
|
|
326
|
+
*
|
|
327
|
+
* This method should be used to ensure a created test user has the right webex site set.
|
|
328
|
+
*
|
|
329
|
+
* @param {Object} options
|
|
330
|
+
* @param {string} options.userId user id to set site
|
|
331
|
+
* @param {string} options.preferredSite new preferred webexsite
|
|
332
|
+
* @param {string} options.orgId orgId of the site
|
|
333
|
+
* @param {string} options.identityServiceUrl url of identity service
|
|
334
|
+
* @param {string} options.authorization
|
|
335
|
+
* @param {string} options.clientId
|
|
336
|
+
* @param {string} options.clientSecret
|
|
337
|
+
* @returns {Promise}
|
|
338
|
+
*/
|
|
339
|
+
export function setPreferredSite(options = {}) {
|
|
340
|
+
const clientId = options.clientId || process.env.WEBEX_CLIENT_ID;
|
|
341
|
+
const clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;
|
|
342
|
+
|
|
343
|
+
if (!clientId) {
|
|
344
|
+
throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (!clientSecret) {
|
|
348
|
+
throw new Error('options.clientSecret or process.env.WEBEX_CLIENT_SECRET must be defined');
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/* eslint-disable no-useless-escape */
|
|
352
|
+
const body = {
|
|
353
|
+
schemas: ['urn:scim:schemas:core:1.0', 'urn:scim:schemas:extension:cisco:commonidentity:1.0'],
|
|
354
|
+
userPreferences: [
|
|
355
|
+
{
|
|
356
|
+
value: `\"preferredWebExSite\":\"${options.preferredSite}\"`,
|
|
357
|
+
},
|
|
358
|
+
],
|
|
359
|
+
};
|
|
360
|
+
/* eslint-enable no-useless-escape */
|
|
361
|
+
|
|
362
|
+
return request({
|
|
363
|
+
method: 'PATCH',
|
|
364
|
+
headers: {
|
|
365
|
+
authorization: options.authorization,
|
|
366
|
+
},
|
|
367
|
+
uri: `${options.identityServiceUrl}/identity/scim/${options.orgId}/v1/Users/${options.userId}`,
|
|
368
|
+
json: true,
|
|
369
|
+
body,
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
|
|
315
373
|
export {
|
|
316
374
|
default as createWhistlerTestUser,
|
|
317
375
|
removeTestUser as removeWhistlerTestUser,
|