diff --git a/features-legacy/step_definitions/collections.js b/features-legacy/step_definitions/collections.js index ffaa817856..2f8e77a0e7 100644 --- a/features-legacy/step_definitions/collections.js +++ b/features-legacy/step_definitions/collections.js @@ -1,173 +1,226 @@ -'use strict'; - -const - { - When, - Then - } = require('cucumber'), - should = require('should'), - stepUtils = require('../support/stepUtils'); - -When(/^I list "([^"]*)" data collections(?: in index "([^"]*)")?$/, function (type, index, callback) { - this.api.listCollections(index, type) - .then(response => { - if (response.error) { - callback(new Error(response.error.message)); - return false; - } - - if (! response.result) { - return callback(new Error('No result provided')); - } - - this.result = response.result; - callback(); - }) - .catch(error => callback(error)); -}); +"use strict"; + +const { When, Then } = require("cucumber"), + should = require("should"), + stepUtils = require("../support/stepUtils"); + +When( + /^I list "([^"]*)" data collections(?: in index "([^"]*)")?$/, + function (type, index, callback) { + this.api + .listCollections(index, type) + .then((response) => { + if (response.error) { + callback(new Error(response.error.message)); + return false; + } + + if (!response.result) { + return callback(new Error("No result provided")); + } + + this.result = response.result; + callback(); + }) + .catch((error) => callback(error)); + } +); -When('I try to create the collection {string}', async function (collection) { +When("I try to create the collection {string}", async function (collection) { try { const response = await this.api.createCollection(null, collection); this.result = response; - } - catch (error) { + } catch (error) { this.result = { error }; } }); -When('I create a collection named {string} in index {string}', async function (collection, index) { - await this.api.createCollection(index, collection); -}); - -Then(/^I can ?(not)* find a ?(.*?) collection ?(.*)$/, function (not, type, collection, callback) { - if (! this.result.collections) { - return callback('Expected a collections list result, got: ' + this.result); +When( + "I create a collection named {string} in index {string}", + async function (collection, index) { + await this.api.createCollection(index, collection); } - - if (! collection) { - if (this.result.collections.length === 0) { - if (not) { - return callback(); - } - - return callback('Collection list is empty, expected collections to be listed'); +); + +Then( + /^I can ?(not)* find a ?(.*?) collection ?(.*)$/, + function (not, type, collection, callback) { + if (!this.result.collections) { + return callback( + "Expected a collections list result, got: " + this.result + ); } - } - if (this.result.collections.filter(item => item.type === type && item.name === collection).length !== 0) { - if (not) { - return callback('Expected collection ' + collection + ' not to appear in the collection list'); - } - - return callback(); - } + if (!collection) { + if (this.result.collections.length === 0) { + if (not) { + return callback(); + } - callback('Expected to find the collection <' + collection + '> in this collections list: ' + JSON.stringify(this.result.collections)); -}); - -Then(/^I change the mapping(?: in index "([^"]*)")?$/, function (index, callback) { - this.api.updateMapping() - .then(body => { - if (body.error !== null) { - callback(new Error(body.error.message)); - return false; + return callback( + "Collection list is empty, expected collections to be listed" + ); } + } - callback(); - }) - .catch(function (error) { - callback(new Error(error)); - }); -}); - -Then(/^I truncate the collection(?: "(.*?)")?(?: in index "([^"]*)")?$/, function (collection, index, callback) { - this.api.truncateCollection(index, collection) - .then(body => { - if (body.error !== null) { - return callback(body.error); + if ( + this.result.collections.filter( + (item) => item.type === type && item.name === collection + ).length !== 0 + ) { + if (not) { + return callback( + "Expected collection " + + collection + + " not to appear in the collection list" + ); } - callback(); - }) - .catch(error => callback(error)); -}); + return callback(); + } + + callback( + "Expected to find the collection <" + + collection + + "> in this collections list: " + + JSON.stringify(this.result.collections) + ); + } +); + +Then( + /^I change the mapping(?: in index "([^"]*)")?$/, + function (index, callback) { + this.api + .updateMapping() + .then((body) => { + if (body.error !== null) { + callback(new Error(body.error.message)); + return false; + } + + callback(); + }) + .catch(function (error) { + callback(new Error(error)); + }); + } +); + +Then( + /^I truncate the collection(?: "(.*?)")?(?: in index "([^"]*)")?$/, + function (collection, index, callback) { + this.api + .truncateCollection(index, collection) + .then((body) => { + if (body.error !== null) { + return callback(body.error); + } + + callback(); + }) + .catch((error) => callback(error)); + } +); Then(/I refresh the collection( "(.*?)")?/, function (indexCollection) { indexCollection = indexCollection ? indexCollection - : this.fakeIndex + ':' + this.fakeCollection; + : this.fakeIndex + ":" + this.fakeCollection; - const [index, collection] = indexCollection.split(':'); + const [index, collection] = indexCollection.split(":"); return this.api.refreshCollection(index, collection); }); When(/^I check if index "(.*?)" exists$/, function (index, cb) { - return stepUtils.getReturn.call(this, 'indexExists', index, cb); + return stepUtils.getReturn.call(this, "indexExists", index, cb); }); -When(/I check if collection "(.*?)" exists on index "(.*?)"$/, function (collection, index, cb) { - return stepUtils.getReturn.call(this, 'collectionExists', index, collection, cb); -}); +When( + /I check if collection "(.*?)" exists on index "(.*?)"$/, + function (collection, index, cb) { + return stepUtils.getReturn.call( + this, + "collectionExists", + index, + collection, + cb + ); + } +); -When(/I create a collection "([\w-]+)":"([\w-]+)"( with "([\d]+)" documents)?/, function (index, collection, countRaw) { - return this.api.createCollection(index, collection) - .then(() => { - const - promises = [], +When( + /I create a collection "([\w-]+)":"([\w-]+)"( with "([\d]+)" documents)?/, + function (index, collection, countRaw) { + return this.api.createCollection(index, collection).then(() => { + const promises = [], count = parseInt(countRaw); for (let i = 0; i < count; ++i) { - promises.push(this.api.create({ number: `doc-${i}` }, index, collection)); + promises.push( + this.api.create({ number: `doc-${i}` }, index, collection) + ); } return Promise.all(promises); }); -}); - -Then('The mapping dynamic field of {string}:{string} is {string}', function (index, collection, dynamicValue) { - return this.api.getCollectionMapping(index, collection) - .then(({ result }) => { - const expectedValue = dynamicValue === 'the default value' - ? 'true' // we set the default value to true in the environment for tests - : dynamicValue; - - should(result.dynamic) - .not.be.undefined() - .be.eql(expectedValue); - }); -}); - -When('I update the mapping of {string}:{string} with {string}', function (index, collection, rawMapping) { - const mapping = JSON.parse(rawMapping); - - return this.api.updateMapping(index, collection, mapping); -}); - -Then('The mapping properties field of {string}:{string} is {string}', function (index, collection, rawMapping) { - const includeKuzzleMeta = rawMapping === 'the default value'; - - return this.api.getCollectionMapping(index, collection, includeKuzzleMeta) - .then(({ result }) => { - const expectedValue = rawMapping === 'the default value' - ? this.kuzzleConfig.services.storageEngine.commonMapping.properties - : JSON.parse(rawMapping); - - should(result.properties) - .be.eql(expectedValue); - }); -}); - -Then('The mapping _meta field of {string}:{string} is {string}', function (index, collection, rawMapping) { - const mapping = JSON.parse(rawMapping); + } +); + +Then( + "The mapping dynamic field of {string}:{string} is {string}", + function (index, collection, dynamicValue) { + return this.api + .getCollectionMapping(index, collection) + .then(({ result }) => { + const expectedValue = + dynamicValue === "the default value" + ? "true" // we set the default value to true in the environment for tests + : dynamicValue; + + should(result.dynamic).not.be.undefined().be.eql(expectedValue); + }); + } +); - return this.api.getCollectionMapping(index, collection) - .then(({ result }) => { +When( + "I update the mapping of {string}:{string} with {string}", + function (index, collection, rawMapping) { + const mapping = JSON.parse(rawMapping); - should(result._meta) - .not.be.undefined() - .be.eql(mapping._meta); - }); -}); + return this.api.updateMapping(index, collection, mapping); + } +); + +Then( + "The mapping properties field of {string}:{string} is {string}", + function (index, collection, rawMapping) { + const includeKuzzleMeta = rawMapping === "the default value"; + + return this.api + .getCollectionMapping(index, collection, includeKuzzleMeta) + .then(({ result }) => { + const expectedValue = + rawMapping === "the default value" + ? this.kuzzleConfig.services.storageEngine.commonMapping.properties + : JSON.parse(rawMapping); + + should(result.properties).be.eql(expectedValue); + }); + } +); + +Then( + "The mapping _meta field of {string}:{string} is {string}", + function (index, collection, rawMapping) { + const mapping = JSON.parse(rawMapping); + + return this.api + .getCollectionMapping(index, collection) + .then(({ result }) => { + should(result._meta).not.be.undefined().be.eql(mapping._meta); + }); + } +); diff --git a/features-legacy/step_definitions/profiles.js b/features-legacy/step_definitions/profiles.js index 9acc88e316..321afcd9cd 100644 --- a/features-legacy/step_definitions/profiles.js +++ b/features-legacy/step_definitions/profiles.js @@ -352,15 +352,17 @@ Given(/^A scrolled search on profiles$/, function () { this.scrollId = null; return this.api.searchProfiles([], { scroll: "2s" }).then((response) => { + console.log("response", response); + if (response.error) { throw new Error(response.error.message); } - if (!response.result.scroll_id) { + if (!response.result.scrollId) { throw new Error("No scrollId returned by the searchProfile query"); } - this.scrollId = response.result.scroll_id; + this.scrollId = response.result.scrollId; }); }); diff --git a/features-legacy/support/api/apiBase.js b/features-legacy/support/api/apiBase.js index 0d09032012..50051941af 100644 --- a/features-legacy/support/api/apiBase.js +++ b/features-legacy/support/api/apiBase.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; /** * This file contains the main API method for real-time protocols. @@ -7,12 +7,11 @@ * NOTE: must be added in api HTTP because the apiHttp file doesn't extend this ApiRT */ -const - _ = require('lodash'), - Bluebird = require('bluebird'); +const _ = require("lodash"), + Bluebird = require("bluebird"); class ApiBase { - constructor (world) { + constructor(world) { this.world = world; this.clientId = null; @@ -22,93 +21,89 @@ class ApiBase { this.isRealTimeCapable = true; } - send () { - throw new Error('not implemented'); + send() { + throw new Error("not implemented"); } - sendAndListen () { - throw new Error('not implemented'); + sendAndListen() { + throw new Error("not implemented"); } - adminResetDatabase () { + adminResetDatabase() { const msg = { - controller: 'admin', - action: 'resetDatabase' + controller: "admin", + action: "resetDatabase", }; return this.send(msg); } - serverPublicApi () { + serverPublicApi() { const msg = { - controller: 'server', - action: 'publicApi' + controller: "server", + action: "publicApi", }; return this.send(msg); } - bulkImport (bulk, index, collection) { - const - msg = { - controller: 'bulk', - collection: collection || this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'import', - body: { bulkData: bulk } - }; + bulkImport(bulk, index, collection) { + const msg = { + controller: "bulk", + collection: collection || this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "import", + body: { bulkData: bulk }, + }; return this.send(msg); } - bulkMWrite (index, collection, body) { - const - msg = { - controller: 'bulk', - collection: collection || this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'mWrite', - body - }; + bulkMWrite(index, collection, body) { + const msg = { + controller: "bulk", + collection: collection || this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "mWrite", + body, + }; return this.send(msg); } - bulkWrite (index, collection, body, _id = null) { - const - msg = { - controller: 'bulk', - collection: collection || this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'write', - _id, - body - }; + bulkWrite(index, collection, body, _id = null) { + const msg = { + controller: "bulk", + collection: collection || this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "write", + _id, + body, + }; return this.send(msg); } - collectionExists (index, collection) { + collectionExists(index, collection) { return this.send({ index, collection, - controller: 'collection', - action: 'exists' + controller: "collection", + action: "exists", }); } - callMemoryStorage (command, args) { + callMemoryStorage(command, args) { const msg = { - controller: 'ms', - action: command + controller: "ms", + action: command, }; _.forEach(args, (value, prop) => { - if (prop === 'args') { + if (prop === "args") { _.forEach(value, (item, k) => { msg[k] = item; }); - } - else { + } else { msg[prop] = value; } }); @@ -116,7 +111,7 @@ class ApiBase { return this.send(msg); } - checkToken (token) { + checkToken(token) { let _token = null; if (this.world.currentUser && this.world.currentUser.token) { @@ -124,15 +119,19 @@ class ApiBase { this.world.currentUser.token = null; } - return this.send({ controller: 'auth', action: 'checkToken', body: { token } }) - .then(response => { + return this.send({ + controller: "auth", + action: "checkToken", + body: { token }, + }) + .then((response) => { if (_token !== null) { this.world.currentUser.token = _token; } return response; }) - .catch(error => { + .catch((error) => { if (_token !== null) { this.world.currentUser.token = _token; } @@ -141,46 +140,43 @@ class ApiBase { }); } - count (query, index, collection) { - const - msg = { - controller: 'document', - collection: collection || this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'count', - body: query - }; + count(query, index, collection) { + const msg = { + controller: "document", + collection: collection || this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "count", + body: query, + }; return this.send(msg); } - countSubscription () { - const - clients = Object.keys(this.subscribedRooms), + countSubscription() { + const clients = Object.keys(this.subscribedRooms), rooms = Object.keys(this.subscribedRooms[clients[0]]), msg = { - controller: 'realtime', + controller: "realtime", collection: this.world.fakeCollection, index: this.world.fakeIndex, - action: 'count', + action: "count", body: { - roomId: rooms[0] - } + roomId: rooms[0], + }, }; return this.send(msg); } - create (body, index, collection, jwtToken, id) { - const - msg = { - controller: 'document', - collection: collection || this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'create', - body, - refresh: 'wait_for' - }; + create(body, index, collection, jwtToken, id) { + const msg = { + controller: "document", + collection: collection || this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "create", + body, + refresh: "wait_for", + }; if (id) { msg._id = id; @@ -188,78 +184,74 @@ class ApiBase { if (jwtToken !== undefined) { msg.headers = { - authorization: 'Bearer ' + jwtToken + authorization: "Bearer " + jwtToken, }; } return this.send(msg); } - createIndex (index) { - const - msg = { - controller: 'index', - action: 'create', - index: index - }; + createIndex(index) { + const msg = { + controller: "index", + action: "create", + index: index, + }; return this.send(msg); } - createCollection (index, collection, mappings) { - const - msg = { - controller: 'collection', - action: 'create', - index: index || this.world.fakeIndex, - collection, - body: mappings - }; + createCollection(index, collection, mappings) { + const msg = { + controller: "collection", + action: "create", + index: index || this.world.fakeIndex, + collection, + body: mappings, + }; return this.send(msg); } - getCollectionMapping (index, collection, includeKuzzleMeta = false) { - const - msg = { - includeKuzzleMeta, - controller: 'collection', - action: 'getMapping', - index, - collection - }; + getCollectionMapping(index, collection, includeKuzzleMeta = false) { + const msg = { + includeKuzzleMeta, + controller: "collection", + action: "getMapping", + index, + collection, + }; return this.send(msg); } - createCredentials (strategy, userId, body) { + createCredentials(strategy, userId, body) { return this.send({ - controller: 'security', - action: 'createCredentials', + controller: "security", + action: "createCredentials", strategy, body, - _id: userId + _id: userId, }); } - createMyCredentials (strategy, body) { + createMyCredentials(strategy, body) { return this.send({ - controller: 'auth', - action: 'createMyCredentials', + controller: "auth", + action: "createMyCredentials", strategy, - body + body, }); } - createOrReplace (body, index, collection) { - const - msg = { - controller: 'document', - collection: collection || this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'createOrReplace', - body: body - }; + createOrReplace(body, index, collection) { + const msg = { + controller: "document", + collection: collection || this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "createOrReplace", + body: body, + }; if (body._id) { msg._id = body._id; @@ -269,35 +261,33 @@ class ApiBase { return this.send(msg); } - createOrReplaceProfile (id, body) { - const - msg = { - controller: 'security', - action: 'createOrReplaceProfile', - _id: id, - body: body - }; + createOrReplaceProfile(id, body) { + const msg = { + controller: "security", + action: "createOrReplaceProfile", + _id: id, + body: body, + }; return this.send(msg); } - createOrReplaceRole (id, body) { - const - msg = { - controller: 'security', - action: 'createOrReplaceRole', - _id: id, - body: body - }; + createOrReplaceRole(id, body) { + const msg = { + controller: "security", + action: "createOrReplaceRole", + _id: id, + body: body, + }; return this.send(msg); } - createRestrictedUser (body, id) { + createRestrictedUser(body, id) { const msg = { - controller: 'security', - action: 'createRestrictedUser', - body: body + controller: "security", + action: "createRestrictedUser", + body: body, }; if (id !== undefined) { msg._id = id; @@ -306,12 +296,12 @@ class ApiBase { return this.send(msg); } - createUser (body, id) { + createUser(body, id) { const msg = { - controller: 'security', - action: 'createUser', - refresh: 'wait_for', - body + controller: "security", + action: "createUser", + refresh: "wait_for", + body, }; if (id !== undefined) { @@ -321,11 +311,11 @@ class ApiBase { return this.send(msg); } - createFirstAdmin (body, id, reset) { + createFirstAdmin(body, id, reset) { const msg = { - controller: 'security', - action: 'createFirstAdmin', - body: body + controller: "security", + action: "createFirstAdmin", + body: body, }; if (id !== undefined) { @@ -339,457 +329,436 @@ class ApiBase { return this.send(msg); } - credentialsExist (strategy, body) { + credentialsExist(strategy, body) { return this.send({ - controller: 'auth', - action: 'credentialsExist', + controller: "auth", + action: "credentialsExist", strategy, - body + body, }); } - deleteById (id, index) { - const - msg = { - controller: 'document', - collection: this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'delete', - _id: id - }; + deleteById(id, index) { + const msg = { + controller: "document", + collection: this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "delete", + _id: id, + }; return this.send(msg); } - deleteByQuery (query, index, collection) { - const - msg = { - controller: 'document', - collection: collection || this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'deleteByQuery', - body: query - }; + deleteByQuery(query, index, collection) { + const msg = { + controller: "document", + collection: collection || this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "deleteByQuery", + body: query, + }; return this.send(msg); } - deleteCredentials (strategy, userId) { + deleteCredentials(strategy, userId) { return this.send({ - controller: 'security', - action: 'deleteCredentials', + controller: "security", + action: "deleteCredentials", strategy, - _id: userId + _id: userId, }); } - deleteIndex (index) { - const - msg = { - controller: 'index', - action: 'delete', - index: index - }; + deleteIndex(index) { + const msg = { + controller: "index", + action: "delete", + index: index, + }; return this.send(msg); } - deleteIndexes () { - const - msg = { - controller: 'index', - action: 'mdelete' - }; + deleteIndexes() { + const msg = { + controller: "index", + action: "mdelete", + }; return this.send(msg); } - deleteMyCredentials (strategy) { + deleteMyCredentials(strategy) { return this.send({ - controller: 'auth', - action: 'deleteMyCredentials', - strategy + controller: "auth", + action: "deleteMyCredentials", + strategy, }); } - deleteProfile (id, waitFor = false) { + deleteProfile(id, waitFor = false) { const msg = { - controller: 'security', - action: 'deleteProfile', - _id: id + controller: "security", + action: "deleteProfile", + _id: id, }; if (waitFor) { - msg.refresh = 'wait_for'; + msg.refresh = "wait_for"; } return this.send(msg); } - deleteProfiles (ids, waitFor = false) { + deleteProfiles(ids, waitFor = false) { const msg = { - controller: 'security', - action: 'mDeleteProfiles', + controller: "security", + action: "mDeleteProfiles", body: { - ids - } + ids, + }, }; if (waitFor) { - msg.refresh = 'wait_for'; + msg.refresh = "wait_for"; } return this.send(msg); } - deleteRole (id, waitFor = false) { + deleteRole(id, waitFor = false) { const msg = { - controller: 'security', - action: 'deleteRole', - _id: id + controller: "security", + action: "deleteRole", + _id: id, }; if (waitFor) { - msg.refresh = 'wait_for'; + msg.refresh = "wait_for"; } return this.send(msg); } - deleteRoles (ids, waitFor = false) { + deleteRoles(ids, waitFor = false) { const msg = { - controller: 'security', - action: 'mDeleteRoles', + controller: "security", + action: "mDeleteRoles", body: { - ids - } + ids, + }, }; if (waitFor) { - msg.refresh = 'wait_for'; + msg.refresh = "wait_for"; } return this.send(msg); } - deleteSpecifications (index, collection) { + deleteSpecifications(index, collection) { return this.send({ index: index, collection: collection, - controller: 'collection', - action: 'deleteSpecifications', - body: null + controller: "collection", + action: "deleteSpecifications", + body: null, }); } - deleteUser (id, waitFor = false) { + deleteUser(id, waitFor = false) { const msg = { - controller: 'security', - action: 'deleteUser', - _id: id + controller: "security", + action: "deleteUser", + _id: id, }; if (waitFor) { - msg.refresh = 'wait_for'; + msg.refresh = "wait_for"; } return this.send(msg); } - deleteUsers (ids, waitFor = false) { + deleteUsers(ids, waitFor = false) { const msg = { - controller: 'security', - action: 'mDeleteUsers', + controller: "security", + action: "mDeleteUsers", body: { - ids - } + ids, + }, }; if (waitFor) { - msg.refresh = 'wait_for'; + msg.refresh = "wait_for"; } return this.send(msg); } - exists (id, index) { - const - msg = { - controller: 'document', - collection: this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'exists', - _id: id - }; + exists(id, index) { + const msg = { + controller: "document", + collection: this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "exists", + _id: id, + }; return this.send(msg); } - get (id, index, collection) { - const - msg = { - controller: 'document', - collection: collection || this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'get', - _id: id - }; + get(id, index, collection) { + const msg = { + controller: "document", + collection: collection || this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "get", + _id: id, + }; return this.send(msg); } - getAllStats () { - const - msg = { - controller: 'server', - action: 'getAllStats' - }; + getAllStats() { + const msg = { + controller: "server", + action: "getAllStats", + }; return this.send(msg); } - getAuthenticationStrategies () { + getAuthenticationStrategies() { return this.send({ - controller: 'auth', - action: 'getStrategies', - body: {} + controller: "auth", + action: "getStrategies", + body: {}, }); } - getCredentials (strategy, userId) { + getCredentials(strategy, userId) { return this.send({ - controller: 'security', - action: 'getCredentials', + controller: "security", + action: "getCredentials", strategy, - _id: userId + _id: userId, }); } - getCredentialsById (strategy, userId) { + getCredentialsById(strategy, userId) { return this.send({ - controller: 'security', - action: 'getCredentialsById', + controller: "security", + action: "getCredentialsById", strategy, - _id: userId + _id: userId, }); } - getCurrentUser () { + getCurrentUser() { return this.send({ - controller: 'auth', - action: 'getCurrentUser' + controller: "auth", + action: "getCurrentUser", }); } - getLastStats () { - const - msg = { - controller: 'server', - action: 'getLastStats' - }; + getLastStats() { + const msg = { + controller: "server", + action: "getLastStats", + }; return this.send(msg); } - getMyCredentials (strategy) { + getMyCredentials(strategy) { return this.send({ - controller: 'auth', - action: 'getMyCredentials', - strategy + controller: "auth", + action: "getMyCredentials", + strategy, }); } - getMyRights (id) { + getMyRights(id) { return this.send({ - controller: 'auth', - action: 'getMyRights', - _id: id + controller: "auth", + action: "getMyRights", + _id: id, }); } - getProfile (id) { - const - msg = { - controller: 'security', - action: 'getProfile', - _id: id - }; + getProfile(id) { + const msg = { + controller: "security", + action: "getProfile", + _id: id, + }; return this.send(msg); } - getProfileMapping () { - const - msg = { - controller: 'security', - action: 'getProfileMapping' - }; + getProfileMapping() { + const msg = { + controller: "security", + action: "getProfileMapping", + }; return this.send(msg); } - getProfileRights (id) { - const - msg = { - controller: 'security', - action: 'getProfileRights', - _id: id - }; + getProfileRights(id) { + const msg = { + controller: "security", + action: "getProfileRights", + _id: id, + }; return this.send(msg); } - getRole (id) { - const - msg = { - controller: 'security', - action: 'getRole', - _id: id - }; + getRole(id) { + const msg = { + controller: "security", + action: "getRole", + _id: id, + }; return this.send(msg); } - getRoleMapping () { - const - msg = { - controller: 'security', - action: 'getRoleMapping' - }; + getRoleMapping() { + const msg = { + controller: "security", + action: "getRoleMapping", + }; return this.send(msg); } - getSpecifications (index, collection) { + getSpecifications(index, collection) { return this.send({ index: index, collection: collection, - controller: 'collection', - action: 'getSpecifications' + controller: "collection", + action: "getSpecifications", }); } - getStats (dates) { - const - msg = { - controller: 'server', - action: 'getStats', - body: dates - }; + getStats(dates) { + const msg = { + controller: "server", + action: "getStats", + body: dates, + }; return this.send(msg); } - getUser (id) { + getUser(id) { return this.send({ - controller: 'security', - action: 'getUser', - _id: id + controller: "security", + action: "getUser", + _id: id, }); } - getUserMapping () { - const - msg = { - controller: 'security', - action: 'getUserMapping' - }; + getUserMapping() { + const msg = { + controller: "security", + action: "getUserMapping", + }; return this.send(msg); } - getUserRights (id) { + getUserRights(id) { return this.send({ - controller: 'security', - action: 'getUserRights', - _id: id + controller: "security", + action: "getUserRights", + _id: id, }); } - hasCredentials (strategy, userId) { + hasCredentials(strategy, userId) { return this.send({ - controller: 'security', - action: 'hasCredentials', + controller: "security", + action: "hasCredentials", strategy, - _id: userId + _id: userId, }); } - indexExists (index) { + indexExists(index) { return this.send({ index, - controller: 'index', - action: 'exists' + controller: "index", + action: "exists", }); } - refreshCollection (index, collection) { - const - msg = { - controller: 'collection', - action: 'refresh', - index: index || this.world.fakeIndex, - collection: collection || this.world.fakeCollection - }; + refreshCollection(index, collection) { + const msg = { + controller: "collection", + action: "refresh", + index: index || this.world.fakeIndex, + collection: collection || this.world.fakeCollection, + }; return this.send(msg); } - listCollections (index, type) { - const - msg = { - controller: 'collection', - index: index || this.world.fakeIndex, - action: 'list', - body: { type } - }; + listCollections(index, type) { + const msg = { + controller: "collection", + index: index || this.world.fakeIndex, + action: "list", + body: { type }, + }; return this.send(msg); } - listIndexes () { - const - msg = { - controller: 'index', - action: 'list' - }; + listIndexes() { + const msg = { + controller: "index", + action: "list", + }; return this.send(msg); } - listSubscriptions () { - const - msg = { - controller: 'realtime', - action: 'list' - }; + listSubscriptions() { + const msg = { + controller: "realtime", + action: "list", + }; return this.send(msg); } - login (strategy, credentials) { - const - msg = { - controller: 'auth', - action: 'login', - strategy: strategy, - expiresIn: credentials.expiresIn, - body: { - username: credentials.username, - password: credentials.password - } - }; + login(strategy, credentials) { + const msg = { + controller: "auth", + action: "login", + strategy: strategy, + expiresIn: credentials.expiresIn, + body: { + username: credentials.username, + password: credentials.password, + }, + }; return this.send(msg); } - logout (jwtToken, global = false) { - const - msg = { - controller: 'auth', - action: 'logout', - jwt: jwtToken - }; + logout(jwtToken, global = false) { + const msg = { + controller: "auth", + action: "logout", + jwt: jwtToken, + }; if (global) { msg.global = true; @@ -797,161 +766,150 @@ class ApiBase { return this.send(msg); } - mCreate (body, index, collection, jwtToken) { - const - msg = { - controller: 'document', - collection: collection || this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'mCreate', - body - }; + mCreate(body, index, collection, jwtToken) { + const msg = { + controller: "document", + collection: collection || this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "mCreate", + body, + }; if (jwtToken !== undefined) { msg.headers = { - authorization: 'Bearer ' + jwtToken + authorization: "Bearer " + jwtToken, }; } return this.send(msg); } - mCreateOrReplace (body, index, collection) { - const - msg = { - controller: 'document', - collection: collection || this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'mCreateOrReplace', - body: body - }; + mCreateOrReplace(body, index, collection) { + const msg = { + controller: "document", + collection: collection || this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "mCreateOrReplace", + body: body, + }; return this.send(msg); } - mDelete (body, index, collection) { - const - msg = { - controller: 'document', - collection: collection || this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'mDelete', - body - }; + mDelete(body, index, collection) { + const msg = { + controller: "document", + collection: collection || this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "mDelete", + body, + }; return this.send(msg); } - mGet (body, index, collection) { - const - msg = { - controller: 'document', - collection: collection || this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'mGet', - body - }; + mGet(body, index, collection) { + const msg = { + controller: "document", + collection: collection || this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "mGet", + body, + }; return this.send(msg); } - mGetProfiles (body) { - const - msg = { - controller: 'security', - action: 'mGetProfiles', - body: body - }; + mGetProfiles(body) { + const msg = { + controller: "security", + action: "mGetProfiles", + body: body, + }; return this.send(msg); } - mGetRoles (body) { - const - msg = { - controller: 'security', - action: 'mGetRoles', - body: body - }; + mGetRoles(body) { + const msg = { + controller: "security", + action: "mGetRoles", + body: body, + }; return this.send(msg); } - mReplace (body, index, collection) { - const - msg = { - controller: 'document', - collection: collection || this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'mReplace', - body: body - }; + mReplace(body, index, collection) { + const msg = { + controller: "document", + collection: collection || this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "mReplace", + body: body, + }; return this.send(msg); } - mUpdate (body, index, collection) { - const - msg = { - controller: 'document', - collection: collection || this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'mUpdate', - body: body - }; + mUpdate(body, index, collection) { + const msg = { + controller: "document", + collection: collection || this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "mUpdate", + body: body, + }; return this.send(msg); } - now () { - const - msg = { - controller: 'server', - action: 'now' - }; + now() { + const msg = { + controller: "server", + action: "now", + }; return this.send(msg); } - postDocument (index, collection, document) { + postDocument(index, collection, document) { return this.send({ index, collection, - controller: 'document', - action: 'create', - body: document + controller: "document", + action: "create", + body: document, }); } - publish (body, index) { - const - msg = { - controller: 'realtime', - collection: this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'publish', - body: body - }; + publish(body, index) { + const msg = { + controller: "realtime", + collection: this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "publish", + body: body, + }; return this.send(msg); } - refreshToken () { + refreshToken() { return this.send({ - controller: 'auth', - action: 'refreshToken' + controller: "auth", + action: "refreshToken", }); } - replace (body, index, collection) { - const - msg = { - controller: 'document', - collection: collection || this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'replace', - body: body - }; + replace(body, index, collection) { + const msg = { + controller: "document", + collection: collection || this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "replace", + body: body, + }; if (body._id) { msg._id = body._id; @@ -961,68 +919,66 @@ class ApiBase { return this.send(msg); } - replaceUser (id, body) { + replaceUser(id, body) { return this.send({ - controller: 'security', - action: 'replaceUser', + controller: "security", + action: "replaceUser", _id: id, - body + body, }); } - revokeTokens (id) { + revokeTokens(id) { return this.send({ - controller: 'security', - action: 'revokeTokens', - _id: id + controller: "security", + action: "revokeTokens", + _id: id, }); } - scroll (scrollId, scroll) { - const - msg = { - controller: 'document', - action: 'scroll', - scrollId, - scroll - }; + scroll(scrollId, scroll) { + const msg = { + controller: "document", + action: "scroll", + scrollId, + scroll, + }; return this.send(msg); } - scrollProfiles (scrollId) { + scrollProfiles(scrollId) { return this.send({ - controller: 'security', - action: 'scrollProfiles', - scrollId + controller: "security", + action: "scrollProfiles", + scrollId, }); } - scrollSpecifications (scrollId) { + scrollSpecifications(scrollId) { return this.send({ - controller: 'collection', - action: 'scrollSpecifications', - scrollId + controller: "collection", + action: "scrollSpecifications", + scrollId, }); } - scrollUsers (scrollId) { + scrollUsers(scrollId) { return this.send({ - controller: 'security', - action: 'scrollUsers', - scrollId + controller: "security", + action: "scrollUsers", + scrollId, }); } - search (query, index, collection, args) { - const - msg = { - controller: 'document', - collection: collection || this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'search', - body: query - }; + search(query, index, collection, args) { + const msg = { + controller: "document", + collection: collection || this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "search", + body: query, + }; _.forEach(args, (item, k) => { msg[k] = item; @@ -1031,15 +987,14 @@ class ApiBase { return this.send(msg); } - searchProfiles (roles, args) { - const - msg = { - controller: 'security', - action: 'searchProfiles', - body: { - roles - } - }; + searchProfiles(roles, args) { + const msg = { + controller: "security", + action: "searchProfiles", + body: { + roles, + }, + }; _.forEach(args, (item, k) => { msg[k] = item; @@ -1048,13 +1003,12 @@ class ApiBase { return this.send(msg); } - searchRoles (body, args) { - const - msg = { - controller: 'security', - action: 'searchRoles', - body - }; + searchRoles(body, args) { + const msg = { + controller: "security", + action: "searchRoles", + body, + }; _.forEach(args, (item, k) => { msg[k] = item; @@ -1063,11 +1017,11 @@ class ApiBase { return this.send(msg); } - searchSpecifications (body, args) { + searchSpecifications(body, args) { let msg = { - controller: 'collection', - action: 'searchSpecifications', - body: body + controller: "collection", + action: "searchSpecifications", + body: body, }; if (args) { @@ -1077,13 +1031,13 @@ class ApiBase { return this.send(msg); } - searchUsers (query, args) { + searchUsers(query, args) { const msg = { - controller: 'security', - action: 'searchUsers', + controller: "security", + action: "searchUsers", body: { - query - } + query, + }, }; if (args) { @@ -1093,16 +1047,15 @@ class ApiBase { return this.send(msg); } - subscribe (filters, client, authentified = false) { - const - msg = { - controller: 'realtime', - collection: this.world.fakeCollection, - index: this.world.fakeIndex, - action: 'subscribe', - users: 'all', - body: null - }; + subscribe(filters, client, authentified = false) { + const msg = { + controller: "realtime", + collection: this.world.fakeCollection, + index: this.world.fakeIndex, + action: "subscribe", + users: "all", + body: null, + }; if (authentified) { msg.jwt = this.world.currentUser.token; @@ -1115,28 +1068,26 @@ class ApiBase { return this.sendAndListen(msg, client); } - truncateCollection (index, collection) { - const - msg = { - controller: 'collection', - collection: collection || this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'truncate' - }; + truncateCollection(index, collection) { + const msg = { + controller: "collection", + collection: collection || this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "truncate", + }; return this.send(msg); } - unsubscribe (room, clientId) { - const - msg = { - clientId: clientId, - controller: 'realtime', - collection: this.world.fakeCollection, - index: this.world.fakeIndex, - action: 'unsubscribe', - body: { roomId: room } - }; + unsubscribe(room, clientId) { + const msg = { + clientId: clientId, + controller: "realtime", + collection: this.world.fakeCollection, + index: this.world.fakeIndex, + action: "unsubscribe", + body: { roomId: room }, + }; this.subscribedRooms[clientId][room].close(); delete this.subscribedRooms[clientId]; @@ -1144,193 +1095,187 @@ class ApiBase { return this.send(msg, false); } - update (id, body, index, collection) { - const - msg = { - controller: 'document', - collection: collection || this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'update', - _id: id, - body: body - }; + update(id, body, index, collection) { + const msg = { + controller: "document", + collection: collection || this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "update", + _id: id, + body: body, + }; return this.send(msg); } - updateCredentials (strategy, userId, body) { + updateCredentials(strategy, userId, body) { return this.send({ - controller: 'security', - action: 'updateCredentials', + controller: "security", + action: "updateCredentials", strategy, body, - _id: userId + _id: userId, }); } - updateMapping (index, collection, mapping) { - const - msg = { - controller: 'collection', - collection: collection || this.world.fakeCollection, - index: index || this.world.fakeIndex, - action: 'updateMapping', - body: mapping || this.world.mapping - }; + updateMapping(index, collection, mapping) { + const msg = { + controller: "collection", + collection: collection || this.world.fakeCollection, + index: index || this.world.fakeIndex, + action: "updateMapping", + body: mapping || this.world.mapping, + }; return this.send(msg); } - updateMyCredentials (strategy, body) { + updateMyCredentials(strategy, body) { return this.send({ - controller: 'auth', - action: 'updateMyCredentials', + controller: "auth", + action: "updateMyCredentials", strategy, - body + body, }); } - updateProfileMapping () { - const - msg = { - controller: 'security', - action: 'updateProfileMapping', - body: this.world.securitymapping - }; + updateProfileMapping() { + const msg = { + controller: "security", + action: "updateProfileMapping", + body: this.world.securitymapping, + }; return this.send(msg); } - updateRoleMapping () { - const - msg = { - controller: 'security', - action: 'updateRoleMapping', - body: this.world.securitymapping - }; + updateRoleMapping() { + const msg = { + controller: "security", + action: "updateRoleMapping", + body: this.world.securitymapping, + }; return this.send(msg); } - updateSelf (body) { + updateSelf(body) { return this.send({ - controller: 'auth', - action: 'updateSelf', - body: body + controller: "auth", + action: "updateSelf", + body: body, }); } - updateSpecifications (index, collection, specifications) { + updateSpecifications(index, collection, specifications) { return this.send({ index, collection, - controller: 'collection', - action: 'updateSpecifications', - body: specifications + controller: "collection", + action: "updateSpecifications", + body: specifications, }); } - updateUserMapping () { - const - msg = { - controller: 'security', - action: 'updateUserMapping', - body: this.world.securitymapping - }; + updateUserMapping() { + const msg = { + controller: "security", + action: "updateUserMapping", + body: this.world.securitymapping, + }; return this.send(msg); } - validateCredentials (strategy, userId, body) { + validateCredentials(strategy, userId, body) { return this.send({ - controller: 'security', - action: 'validateCredentials', + controller: "security", + action: "validateCredentials", strategy, body, - _id: userId + _id: userId, }); } - validateDocument (index, collection, document) { + validateDocument(index, collection, document) { return this.create(document, index, collection); } - validateMyCredentials (strategy, body) { + validateMyCredentials(strategy, body) { return this.send({ - controller: 'auth', - action: 'validateMyCredentials', + controller: "auth", + action: "validateMyCredentials", strategy, - body + body, }); } - validateSpecifications (index, collection, specifications) { + validateSpecifications(index, collection, specifications) { return this.send({ index, collection, - controller: 'collection', - action: 'validateSpecifications', - body: specifications + controller: "collection", + action: "validateSpecifications", + body: specifications, }); } - resetCache (database) { + resetCache(database) { return this.send({ - controller: 'admin', - action: 'resetCache', - database + controller: "admin", + action: "resetCache", + database, }); } - resetKuzzleData () { + resetKuzzleData() { return this.send({ - controller: 'admin', - action: 'resetKuzzleData' + controller: "admin", + action: "resetKuzzleData", }); } - resetSecurity () { + resetSecurity() { return this.send({ - controller: 'admin', - action: 'resetSecurity', - refresh: 'wait_for' + controller: "admin", + action: "resetSecurity", + refresh: "wait_for", }); } - resetDatabase () { + resetDatabase() { return this.send({ - controller: 'admin', - action: 'resetDatabase' + controller: "admin", + action: "resetDatabase", }); } - loadMappings (body) { + loadMappings(body) { return this.send({ body, - controller: 'admin', - action: 'loadMappings', - refresh: 'wait_for' + controller: "admin", + action: "loadMappings", + refresh: "wait_for", }); } - loadFixtures (body) { + loadFixtures(body) { return this.send({ body, - controller: 'admin', - action: 'loadFixtures', - refresh: 'wait_for' + controller: "admin", + action: "loadFixtures", + refresh: "wait_for", }); } - loadSecurities (body) { + loadSecurities(body) { return this.send({ body, - controller: 'admin', - action: 'loadSecurities', - refresh: 'wait_for' + controller: "admin", + action: "loadSecurities", + refresh: "wait_for", }); } } - module.exports = ApiBase; diff --git a/features-legacy/support/api/http.js b/features-legacy/support/api/http.js index 79bbf31b6b..a20eb11f86 100644 --- a/features-legacy/support/api/http.js +++ b/features-legacy/support/api/http.js @@ -1,61 +1,60 @@ -'use strict'; +"use strict"; -const zlib = require('zlib'); +const zlib = require("zlib"); -const _ = require('lodash'); -const rp = require('request-promise'); +const _ = require("lodash"); +const rp = require("request-promise"); -const routes = require('../../../lib/api/httpRoutes'); +const routes = require("../../../lib/api/httpRoutes"); -function checkAlgorithm (algorithm) { - const - supported = ['identity', 'gzip', 'deflate'], - list = algorithm.split(',').map(a => a.trim().toLowerCase()); +function checkAlgorithm(algorithm) { + const supported = ["identity", "gzip", "deflate"], + list = algorithm.split(",").map((a) => a.trim().toLowerCase()); for (const l of list) { - if (! supported.some(a => a === l)) { + if (!supported.some((a) => a === l)) { throw new Error(`Unsupported compression algorithm: ${l}`); } } } class HttpApi { - constructor (world) { + constructor(world) { this.world = world; this.baseUri = `http://${world.config.host}:${world.config.port}`; this.util = { - getIndex: index => typeof index !== 'string' ? this.world.fakeIndex : index, - getCollection: collection => typeof collection !== 'string' ? this.world.fakeCollection : collection + getIndex: (index) => + typeof index !== "string" ? this.world.fakeIndex : index, + getCollection: (collection) => + typeof collection !== "string" ? this.world.fakeCollection : collection, }; this.isRealtimeCapable = false; - this.encoding = 'identity'; - this.expectedEncoding = 'identity'; + this.encoding = "identity"; + this.expectedEncoding = "identity"; } - _getRequest (index, collection, controller, action, args) { - let - url = '', + _getRequest(index, collection, controller, action, args) { + let url = "", queryString = [], - verb = 'GET', + verb = "GET", result; - if (! args) { + if (!args) { args = {}; } - if (! args.body) { + if (!args.body) { if (args.args) { args.body = args.args; - } - else { + } else { args.body = {}; } } - routes.some(route => { + routes.some((route) => { const hits = []; // Try / Catch mechanism avoids to match routes that have not all @@ -64,67 +63,65 @@ class HttpApi { if (route.controller === controller && route.action === action) { verb = route.verb.toUpperCase(); - url = route.url.replace(/(:[^/]+)/g, function (match) { - hits.push(match.substring(1)); + url = route.url + .replace(/(:[^/]+)/g, function (match) { + hits.push(match.substring(1)); - if (match === ':index') { - if (! index) { - throw new Error('No index provided'); + if (match === ":index") { + if (!index) { + throw new Error("No index provided"); + } + return index; } - return index; - } - if (match === ':collection') { - if (! collection) { - throw new Error('No collection provided'); + if (match === ":collection") { + if (!collection) { + throw new Error("No collection provided"); + } + return collection; } - return collection; - } - if (match === ':_id') { - if (args._id) { - return args._id; - } - if (args.body._id) { - return args.body._id; + if (match === ":_id") { + if (args._id) { + return args._id; + } + if (args.body._id) { + return args.body._id; + } + throw new Error("No _id provided"); } - throw new Error('No _id provided'); - } - if (args.body[match.substring(1)] !== undefined) { - return args.body[match.substring(1)]; - } + if (args.body[match.substring(1)] !== undefined) { + return args.body[match.substring(1)]; + } - return ''; - }).substring(1); + return ""; + }) + .substring(1); // add extra aguments in the query string - if (verb === 'GET') { - _.difference(Object.keys(args.body), hits).forEach(key => { + if (verb === "GET") { + _.difference(Object.keys(args.body), hits).forEach((key) => { const value = args.body[key]; if (value !== undefined) { if (Array.isArray(value)) { - queryString.push(...value.map(v => `${key}=${v}`)); - } - else { + queryString.push(...value.map((v) => `${key}=${v}`)); + } else { queryString.push(`${key}=${value}`); } } }); if (queryString.length) { - url += '?' + queryString.join('&'); + url += "?" + queryString.join("&"); } } - url = url - .replace(/\/\//g, '/') - .replace(/\/$/, ''); + url = url.replace(/\/\//g, "/").replace(/\/$/, ""); return true; } - } - catch (error) { + } catch (error) { return false; } @@ -133,66 +130,75 @@ class HttpApi { result = { url: this.apiPath(url), - method: verb + method: verb, }; - if (verb !== 'GET') { + if (verb !== "GET") { result.body = args.body; } return result; } - apiBasePath (path) { + apiBasePath(path) { return this.apiPath(path); } - apiPath (path) { - return path.startsWith('/') + apiPath(path) { + return path.startsWith("/") ? encodeURI(`${this.baseUri}${path}`) : encodeURI(`${this.baseUri}/${path}`); } - adminResetDatabase () { + adminResetDatabase() { const options = { - url: this.apiPath('/admin/_resetDatabase/'), - method: 'POST' + url: this.apiPath("/admin/_resetDatabase/"), + method: "POST", }; return this.callApi(options); } - serverPublicApi () { + serverPublicApi() { const options = { - url: this.apiPath('/_publicApi'), - method: 'GET' + url: this.apiPath("/_publicApi"), + method: "GET", }; return this.callApi(options); } - bulkImport (bulk, index) { + bulkImport(bulk, index) { const options = { - url: this.apiPath(this.util.getIndex(index) + '/' + this.world.fakeCollection + '/_bulk'), - method: 'POST', - body: { bulkData: bulk } + url: this.apiPath( + this.util.getIndex(index) + "/" + this.world.fakeCollection + "/_bulk" + ), + method: "POST", + body: { bulkData: bulk }, }; return this.callApi(options); } - bulkMWrite (index, collection, body) { + bulkMWrite(index, collection, body) { const options = { - url: this.apiPath(this.util.getIndex(index) + '/' + this.util.getCollection(collection) + '/_mWrite'), - method: 'POST', - body + url: this.apiPath( + this.util.getIndex(index) + + "/" + + this.util.getCollection(collection) + + "/_mWrite" + ), + method: "POST", + body, }; return this.callApi(options); } - bulkWrite (index, collection, body, _id = null) { - let url = `${this.util.getIndex(index)}/${this.util.getCollection(collection)}/_write`; + bulkWrite(index, collection, body, _id = null) { + let url = `${this.util.getIndex(index)}/${this.util.getCollection( + collection + )}/_write`; if (_id) { url += `?_id=${_id}`; @@ -200,8 +206,8 @@ class HttpApi { const options = { url: this.apiPath(url), - method: 'POST', - body + method: "POST", + body, }; return this.callApi(options); @@ -211,8 +217,8 @@ class HttpApi { * @param options * @returns {Promise.} */ - async callApi (options) { - if (! options.headers) { + async callApi(options) { + if (!options.headers) { options.headers = {}; } @@ -222,27 +228,27 @@ class HttpApi { }); } - if (options.body && this.encoding !== 'identity') { + if (options.body && this.encoding !== "identity") { options.body = JSON.stringify(options.body); - options.headers['content-encoding'] = this.encoding; + options.headers["content-encoding"] = this.encoding; - const algorithms = this.encoding.split(',').map(a => a.trim().toLowerCase()); + const algorithms = this.encoding + .split(",") + .map((a) => a.trim().toLowerCase()); for (const algorithm of algorithms) { - if (algorithm === 'gzip') { + if (algorithm === "gzip") { options.body = zlib.gzipSync(options.body); - } - else if (algorithm === 'deflate') { + } else if (algorithm === "deflate") { options.body = zlib.deflateSync(options.body); } } - } - else { + } else { options.json = true; } - if (this.expectedEncoding !== 'identity') { - options.headers['accept-encoding'] = this.expectedEncoding; + if (this.expectedEncoding !== "identity") { + options.headers["accept-encoding"] = this.expectedEncoding; // despite the name, that options asks "request" to handle // both gzip or deflate compressed responses @@ -255,23 +261,23 @@ class HttpApi { // we need to manually parse the stringified json if // we sent a compressed buffer through the request module - if (options.body && this.encoding !== 'identity') { + if (options.body && this.encoding !== "identity") { return JSON.parse(response); } return response; } - callMemoryStorage (command, args) { - return this.callApi(this._getRequest(null, null, 'ms', command, args)); + callMemoryStorage(command, args) { + return this.callApi(this._getRequest(null, null, "ms", command, args)); } - checkToken (token) { + checkToken(token) { let _token = null; const request = { - url: this.apiPath('_checkToken'), - method: 'POST', - body: { token } + url: this.apiPath("_checkToken"), + method: "POST", + body: { token }, }; if (this.world.currentUser && this.world.currentUser.token) { @@ -280,14 +286,14 @@ class HttpApi { } return this.callApi(request) - .then(response => { + .then((response) => { if (_token !== null) { this.world.currentUser.token = _token; } return response; }) - .catch(error => { + .catch((error) => { if (_token !== null) { this.world.currentUser.token = _token; } @@ -296,78 +302,98 @@ class HttpApi { }); } - collectionExists (index, collection) { - return this.callApi(this._getRequest(index, collection, 'collection', 'exists')); + collectionExists(index, collection) { + return this.callApi( + this._getRequest(index, collection, "collection", "exists") + ); } - count (query, index, collection) { + count(query, index, collection) { const options = { - url: this.apiPath(this.util.getIndex(index) + '/' + this.util.getCollection(collection) + '/_count'), - method: 'POST', - body: query + url: this.apiPath( + this.util.getIndex(index) + + "/" + + this.util.getCollection(collection) + + "/_count" + ), + method: "POST", + body: query, }; return this.callApi(options); } - create (body, index, collection, jwtToken, id) { - const - url = id - ? this.apiPath(this.util.getIndex(index) + '/' + this.util.getCollection(collection) + '/' + id + '/_create') - : this.apiPath(this.util.getIndex(index) + '/' + this.util.getCollection(collection) + '/_create'), + create(body, index, collection, jwtToken, id) { + const url = id + ? this.apiPath( + this.util.getIndex(index) + + "/" + + this.util.getCollection(collection) + + "/" + + id + + "/_create" + ) + : this.apiPath( + this.util.getIndex(index) + + "/" + + this.util.getCollection(collection) + + "/_create" + ), options = { url: url, - method: 'POST', - body + method: "POST", + body, }; if (jwtToken) { options.headers = { - authorization: 'Bearer ' + jwtToken + authorization: "Bearer " + jwtToken, }; } return this.callApi(options); } - createCollection (index, collection, mappings) { + createCollection(index, collection, mappings) { index = index || this.world.fakeIndex; const options = { url: this.apiPath(`${index}/${collection}`), - method: 'PUT', - body: mappings + method: "PUT", + body: mappings, }; return this.callApi(options); } - getCollectionMapping (index, collection, includeKuzzleMeta = false) { - const url = `${index}/${collection}/_mapping${includeKuzzleMeta ? '?includeKuzzleMeta' : ''}`; + getCollectionMapping(index, collection, includeKuzzleMeta = false) { + const url = `${index}/${collection}/_mapping${ + includeKuzzleMeta ? "?includeKuzzleMeta" : "" + }`; const options = { url: this.apiPath(url), - method: 'GET' + method: "GET", }; return this.callApi(options); } - createCredentials (strategy, userId, body) { + createCredentials(strategy, userId, body) { const options = { - url: this.apiPath('credentials/' + strategy + '/' + userId + '/_create'), - method: 'POST', - body + url: this.apiPath("credentials/" + strategy + "/" + userId + "/_create"), + method: "POST", + body, }; return this.callApi(options); } - createFirstAdmin (body, id, reset) { + createFirstAdmin(body, id, reset) { const options = { - url: this.apiPath('_createFirstAdmin'), - method: 'POST', - body + url: this.apiPath("_createFirstAdmin"), + method: "POST", + body, }; if (id !== undefined) { @@ -375,36 +401,42 @@ class HttpApi { } if (reset) { - options.url += '?reset=1'; + options.url += "?reset=1"; } return this.callApi(options); } - createIndex (index) { + createIndex(index) { const options = { - url: this.apiPath(index + '/_create'), - method: 'POST' + url: this.apiPath(index + "/_create"), + method: "POST", }; return this.callApi(options); } - createMyCredentials (strategy, body) { + createMyCredentials(strategy, body) { const options = { - url: this.apiPath('credentials/' + strategy + '/_me/_create'), - method: 'POST', - body + url: this.apiPath("credentials/" + strategy + "/_me/_create"), + method: "POST", + body, }; return this.callApi(options); } - createOrReplace (body, index, collection) { + createOrReplace(body, index, collection) { const options = { - url: this.apiPath(this.util.getIndex(index) + '/' + this.util.getCollection(collection) + '/' + body._id), - method: 'PUT', - body + url: this.apiPath( + this.util.getIndex(index) + + "/" + + this.util.getCollection(collection) + + "/" + + body._id + ), + method: "PUT", + body, }; delete body._id; @@ -412,543 +444,610 @@ class HttpApi { return this.callApi(options); } - createOrReplaceProfile (id, body) { + createOrReplaceProfile(id, body) { const options = { - url: this.apiPath('profiles/' + id), - method: 'PUT', - body + url: this.apiPath("profiles/" + id), + method: "PUT", + body, }; return this.callApi(options); } - createOrReplaceRole (id, body) { + createOrReplaceRole(id, body) { const options = { - url: this.apiPath('roles/' + id), - method: 'PUT', - body + url: this.apiPath("roles/" + id), + method: "PUT", + body, }; return this.callApi(options); } - createRestrictedUser (body, id) { + createRestrictedUser(body, id) { const options = { - url: this.apiPath('users/' + id + '/_createRestricted'), - method: 'POST', - body + url: this.apiPath("users/" + id + "/_createRestricted"), + method: "POST", + body, }; return this.callApi(options); } - createUser (body, id) { + createUser(body, id) { const options = { - url: this.apiPath('users/' + id + '/_create' + '?refresh=wait_for'), - method: 'POST', - body + url: this.apiPath("users/" + id + "/_create" + "?refresh=wait_for"), + method: "POST", + body, }; return this.callApi(options); } - credentialsExist (strategy) { + credentialsExist(strategy) { const options = { - url: this.apiPath('credentials/' + strategy + '/_me/_exists'), - method: 'GET' + url: this.apiPath("credentials/" + strategy + "/_me/_exists"), + method: "GET", }; return this.callApi(options); } - deleteById (id, index) { + deleteById(id, index) { const options = { - url: this.apiPath(this.util.getIndex(index) + '/' + this.world.fakeCollection + '/' + id), - method: 'DELETE' + url: this.apiPath( + this.util.getIndex(index) + "/" + this.world.fakeCollection + "/" + id + ), + method: "DELETE", }; return this.callApi(options); } - deleteByQuery (query, index, collection) { + deleteByQuery(query, index, collection) { const options = { - url: this.apiPath(this.util.getIndex(index) + '/' + this.util.getCollection(collection) + '/_query'), - method: 'DELETE', - body: query + url: this.apiPath( + this.util.getIndex(index) + + "/" + + this.util.getCollection(collection) + + "/_query" + ), + method: "DELETE", + body: query, }; return this.callApi(options); } - deleteCredentials (strategy, userId) { + deleteCredentials(strategy, userId) { const options = { - url: this.apiPath('credentials/' + strategy + '/' + userId), - method: 'DELETE' + url: this.apiPath("credentials/" + strategy + "/" + userId), + method: "DELETE", }; return this.callApi(options); } - deleteIndex (index) { + deleteIndex(index) { const options = { url: this.apiPath(index), - method: 'DELETE' + method: "DELETE", }; return this.callApi(options); } - deleteIndexes () { + deleteIndexes() { const options = { - url: this.apiPath('_mDelete'), - method: 'DELETE' + url: this.apiPath("_mDelete"), + method: "DELETE", }; return this.callApi(options); } - deleteMyCredentials (strategy) { + deleteMyCredentials(strategy) { const options = { - url: this.apiPath('credentials/' + strategy + '/_me'), - method: 'DELETE' + url: this.apiPath("credentials/" + strategy + "/_me"), + method: "DELETE", }; return this.callApi(options); } - deleteProfile (id, waitFor = false) { + deleteProfile(id, waitFor = false) { return this.callApi({ - url: this.apiPath('profiles/' + id + (waitFor ? '?refresh=wait_for' : '')), - method: 'DELETE' + url: this.apiPath( + "profiles/" + id + (waitFor ? "?refresh=wait_for" : "") + ), + method: "DELETE", }); } - deleteProfiles (ids, waitFor = false) { + deleteProfiles(ids, waitFor = false) { return this.callApi({ - url: this.apiPath('profiles/_mDelete' + (waitFor ? '?refresh=wait_for' : '')), - method: 'POST', + url: this.apiPath( + "profiles/_mDelete" + (waitFor ? "?refresh=wait_for" : "") + ), + method: "POST", body: { - ids - } + ids, + }, }); } - deleteRole (id, waitFor = false) { + deleteRole(id, waitFor = false) { return this.callApi({ - url: this.apiPath('roles/' + id + (waitFor ? '?refresh=wait_for' : '')), - method: 'DELETE' + url: this.apiPath("roles/" + id + (waitFor ? "?refresh=wait_for" : "")), + method: "DELETE", }); } - deleteRoles (ids, waitFor = false) { + deleteRoles(ids, waitFor = false) { return this.callApi({ - url: this.apiPath('roles/_mDelete' + (waitFor ? '?refresh=wait_for' : '')), - method: 'POST', + url: this.apiPath( + "roles/_mDelete" + (waitFor ? "?refresh=wait_for" : "") + ), + method: "POST", body: { - ids - } + ids, + }, }); } - deleteSpecifications (index, collection) { + deleteSpecifications(index, collection) { const options = { - url: this.apiPath(index + '/' + collection + '/_specifications'), - method: 'DELETE' + url: this.apiPath(index + "/" + collection + "/_specifications"), + method: "DELETE", }; return this.callApi(options); } - deleteUser (id, waitFor = false) { + deleteUser(id, waitFor = false) { return this.callApi({ - url: this.apiPath('users/' + id + (waitFor ? '?refresh=wait_for' : '')), - method: 'DELETE' + url: this.apiPath("users/" + id + (waitFor ? "?refresh=wait_for" : "")), + method: "DELETE", }); } - deleteUsers (ids, waitFor = false) { + deleteUsers(ids, waitFor = false) { return this.callApi({ - url: this.apiPath('users/_mDelete' + (waitFor ? '?refresh=wait_for' : '')), - method: 'POST', + url: this.apiPath( + "users/_mDelete" + (waitFor ? "?refresh=wait_for" : "") + ), + method: "POST", body: { - ids - } + ids, + }, }); } - disconnect () {} + disconnect() {} - exists (id, index) { + exists(id, index) { const options = { - url: this.apiPath(this.util.getIndex(index) + '/' + this.world.fakeCollection + '/' + id + '/_exists'), - method: 'GET' + url: this.apiPath( + this.util.getIndex(index) + + "/" + + this.world.fakeCollection + + "/" + + id + + "/_exists" + ), + method: "GET", }; return this.callApi(options); } - get (id, index) { + get(id, index) { const options = { - url: this.apiPath(this.util.getIndex(index) + '/' + this.world.fakeCollection + '/' + id), - method: 'GET' + url: this.apiPath( + this.util.getIndex(index) + "/" + this.world.fakeCollection + "/" + id + ), + method: "GET", }; return this.callApi(options); } - getAllStats () { + getAllStats() { const options = { - url: this.apiPath('_getAllStats'), - method: 'GET' + url: this.apiPath("_getAllStats"), + method: "GET", }; return this.callApi(options); } - getAuthenticationStrategies () { + getAuthenticationStrategies() { const options = { - url: this.apiPath('strategies'), - method: 'GET' + url: this.apiPath("strategies"), + method: "GET", }; return this.callApi(options); } - getCredentials (strategy, userId) { + getCredentials(strategy, userId) { const options = { - url: this.apiPath('credentials/' + strategy + '/' + userId), - method: 'GET' + url: this.apiPath("credentials/" + strategy + "/" + userId), + method: "GET", }; return this.callApi(options); } - getCredentialsById (strategy, userId) { + getCredentialsById(strategy, userId) { const options = { - url: this.apiPath('credentials/' + strategy + '/' + userId + '/_byId'), - method: 'GET' + url: this.apiPath("credentials/" + strategy + "/" + userId + "/_byId"), + method: "GET", }; return this.callApi(options); } - getCurrentUser () { + getCurrentUser() { return this.callApi({ - url: this.apiPath('users/_me'), - method: 'GET' + url: this.apiPath("users/_me"), + method: "GET", }); } - getLastStats () { + getLastStats() { const options = { - url: this.apiPath('_getLastStats'), - method: 'GET' + url: this.apiPath("_getLastStats"), + method: "GET", }; return this.callApi(options); } - getMyCredentials (strategy) { + getMyCredentials(strategy) { const options = { - url: this.apiPath('credentials/' + strategy + '/_me'), - method: 'GET' + url: this.apiPath("credentials/" + strategy + "/_me"), + method: "GET", }; return this.callApi(options); } - getMyRights () { + getMyRights() { const options = { - url: this.apiPath('users/_me/_rights'), - method: 'GET' + url: this.apiPath("users/_me/_rights"), + method: "GET", }; return this.callApi(options); } - getProfile (id) { + getProfile(id) { const options = { - url: this.apiPath('profiles/' + id), - method: 'GET' + url: this.apiPath("profiles/" + id), + method: "GET", }; return this.callApi(options); } - getProfileMapping () { + getProfileMapping() { const options = { - url: this.apiPath('/profiles/_mapping'), - method: 'GET' + url: this.apiPath("/profiles/_mapping"), + method: "GET", }; return this.callApi(options); } - getProfileRights (id) { + getProfileRights(id) { const options = { - url: this.apiPath('profiles/' + id + '/_rights'), - method: 'GET' + url: this.apiPath("profiles/" + id + "/_rights"), + method: "GET", }; return this.callApi(options); } - getRole (id) { + getRole(id) { const options = { - url: this.apiPath('roles/' + id), - method: 'GET' + url: this.apiPath("roles/" + id), + method: "GET", }; return this.callApi(options); } - getRoleMapping () { + getRoleMapping() { const options = { - url: this.apiPath('/roles/_mapping'), - method: 'GET' + url: this.apiPath("/roles/_mapping"), + method: "GET", }; return this.callApi(options); } - getSpecifications (index, collection) { + getSpecifications(index, collection) { const options = { - url: this.apiPath(index + '/' + collection + '/_specifications'), - method: 'GET' + url: this.apiPath(index + "/" + collection + "/_specifications"), + method: "GET", }; return this.callApi(options); } - getStats (dates) { - return this.callApi(this._getRequest(null, null, 'server', 'getStats', { body: dates })); + getStats(dates) { + return this.callApi( + this._getRequest(null, null, "server", "getStats", { body: dates }) + ); } - getUser (id) { + getUser(id) { const options = { - url: this.apiPath('users/' + id), - method: 'GET' + url: this.apiPath("users/" + id), + method: "GET", }; return this.callApi(options); } - getUserMapping () { + getUserMapping() { const options = { - url: this.apiPath('/users/_mapping'), - method: 'GET' + url: this.apiPath("/users/_mapping"), + method: "GET", }; return this.callApi(options); } - getUserRights (id) { + getUserRights(id) { const options = { - url: this.apiPath('users/' + id + '/_rights'), - method: 'GET' + url: this.apiPath("users/" + id + "/_rights"), + method: "GET", }; return this.callApi(options); } - hasCredentials (strategy, userId) { + hasCredentials(strategy, userId) { const options = { - url: this.apiPath('credentials/' + strategy + '/' + userId + '/_exists'), - method: 'GET' + url: this.apiPath("credentials/" + strategy + "/" + userId + "/_exists"), + method: "GET", }; return this.callApi(options); } - indexExists (index) { - return this.callApi(this._getRequest(index, null, 'index', 'exists')); + indexExists(index) { + return this.callApi(this._getRequest(index, null, "index", "exists")); } - refreshCollection (index, collection) { - const - _index = index || this.world.fakeIndex, + refreshCollection(index, collection) { + const _index = index || this.world.fakeIndex, _collection = collection || this.world.fakeCollection, options = { url: this.apiPath(`${_index}/${_collection}/_refresh`), - method: 'POST' + method: "POST", }; return this.callApi(options); } - listCollections (index, type) { + listCollections(index, type) { const options = { url: this.apiPath(`${index || this.world.fakeIndex}/_list`), - method: 'GET' + method: "GET", }; if (type) { - options.url += '?type=' + type; + options.url += "?type=" + type; } return this.callApi(options); } - listIndexes () { + listIndexes() { const options = { - url: this.apiPath('_list'), - method: 'GET' + url: this.apiPath("_list"), + method: "GET", }; return this.callApi(options); } - login (strategy, credentials) { + login(strategy, credentials) { const options = { url: this.apiPath(`_login/${strategy}`), - method: 'POST', + method: "POST", body: { username: credentials.username, - password: credentials.password - } + password: credentials.password, + }, }; return this.callApi(options); } - logout (jwtToken) { + logout(jwtToken) { const options = { - url: this.apiPath('_logout'), - method: 'POST', + url: this.apiPath("_logout"), + method: "POST", headers: { - authorization: 'Bearer ' + jwtToken - } + authorization: "Bearer " + jwtToken, + }, }; return this.callApi(options); } - mCreate (body, index, collection, jwtToken) { + mCreate(body, index, collection, jwtToken) { const options = { - url: this.apiPath(this.util.getIndex(index) + '/' + this.util.getCollection(collection) + '/_mCreate'), - method: 'POST', - body + url: this.apiPath( + this.util.getIndex(index) + + "/" + + this.util.getCollection(collection) + + "/_mCreate" + ), + method: "POST", + body, }; if (jwtToken) { options.headers = { - authorization: 'Bearer ' + jwtToken + authorization: "Bearer " + jwtToken, }; } return this.callApi(options); } - mCreateOrReplace (body, index, collection) { + mCreateOrReplace(body, index, collection) { const options = { - url: this.apiPath(this.util.getIndex(index) + '/' + this.util.getCollection(collection) + '/_mCreateOrReplace'), - method: 'PUT', - body + url: this.apiPath( + this.util.getIndex(index) + + "/" + + this.util.getCollection(collection) + + "/_mCreateOrReplace" + ), + method: "PUT", + body, }; return this.callApi(options); } - mDelete (body, index, collection) { + mDelete(body, index, collection) { const options = { - url: this.apiPath(this.util.getIndex(index) + '/' + this.util.getCollection(collection) + '/_mDelete'), - method: 'DELETE', - body + url: this.apiPath( + this.util.getIndex(index) + + "/" + + this.util.getCollection(collection) + + "/_mDelete" + ), + method: "DELETE", + body, }; return this.callApi(options); } - mGet (body, index, collection) { + mGet(body, index, collection) { const options = { - url: this.apiPath(this.util.getIndex(index) + '/' + this.util.getCollection(collection) + '/_mGet'), - method: 'POST', - body + url: this.apiPath( + this.util.getIndex(index) + + "/" + + this.util.getCollection(collection) + + "/_mGet" + ), + method: "POST", + body, }; return this.callApi(options); } - mGetProfiles (body) { + mGetProfiles(body) { const options = { - url: this.apiPath('profiles/_mGet'), - method: 'POST', - body + url: this.apiPath("profiles/_mGet"), + method: "POST", + body, }; return this.callApi(options); } - mGetRoles (body) { + mGetRoles(body) { const options = { - url: this.apiPath('roles/_mGet'), - method: 'POST', - body + url: this.apiPath("roles/_mGet"), + method: "POST", + body, }; return this.callApi(options); } - mReplace (body, index, collection) { + mReplace(body, index, collection) { const options = { - url: this.apiPath(this.util.getIndex(index) + '/' + this.util.getCollection(collection) + '/_mReplace'), - method: 'PUT', - body + url: this.apiPath( + this.util.getIndex(index) + + "/" + + this.util.getCollection(collection) + + "/_mReplace" + ), + method: "PUT", + body, }; return this.callApi(options); } - mUpdate (body, index, collection) { + mUpdate(body, index, collection) { const options = { - url: this.apiPath(this.util.getIndex(index) + '/' + this.util.getCollection(collection) + '/_mUpdate'), - method: 'PUT', - body + url: this.apiPath( + this.util.getIndex(index) + + "/" + + this.util.getCollection(collection) + + "/_mUpdate" + ), + method: "PUT", + body, }; return this.callApi(options); } - now () { + now() { const options = { - url: this.apiPath('_now'), - method: 'GET' + url: this.apiPath("_now"), + method: "GET", }; return this.callApi(options); } - postDocument (index, collection, document) { + postDocument(index, collection, document) { const options = { - url: this.apiPath(index + '/' + collection + '/_create'), - method: 'POST', - body: document + url: this.apiPath(index + "/" + collection + "/_create"), + method: "POST", + body: document, }; return this.callApi(options); } - publish (body, index) { + publish(body, index) { const options = { - url: this.apiPath(this.util.getIndex(index) + '/' + this.world.fakeCollection + '/_publish'), - method: 'POST', - body + url: this.apiPath( + this.util.getIndex(index) + + "/" + + this.world.fakeCollection + + "/_publish" + ), + method: "POST", + body, }; return this.callApi(options); } - refreshToken () { + refreshToken() { return this.callApi({ - url: this.apiPath('_refreshToken'), - method: 'POST' + url: this.apiPath("_refreshToken"), + method: "POST", }); } - replace (body, index, collection) { + replace(body, index, collection) { const options = { - url: this.apiPath(this.util.getIndex(index) + '/' + this.util.getCollection(collection) + '/' + body._id + '/_replace'), - method: 'PUT', - body + url: this.apiPath( + this.util.getIndex(index) + + "/" + + this.util.getCollection(collection) + + "/" + + body._id + + "/_replace" + ), + method: "PUT", + body, }; delete body._id; @@ -956,102 +1055,106 @@ class HttpApi { return this.callApi(options); } - replaceUser (id, body) { + replaceUser(id, body) { return this.callApi({ - url: this.apiPath('users/' + id + '/_replace'), - method: 'PUT', - body + url: this.apiPath("users/" + id + "/_replace"), + method: "PUT", + body, }); } - revokeTokens (id) { + revokeTokens(id) { return this.callApi({ url: this.apiPath(`users/${id}/tokens`), - method: 'DELETE' + method: "DELETE", }); } - scroll (scrollId, scroll) { + scroll(scrollId, scroll) { const options = { url: this.apiPath(`_scroll/${scrollId}`), - method: 'GET' + method: "GET", }; if (scroll) { - options.url += '?scroll=' + scroll; + options.url += "?scroll=" + scroll; } return this.callApi(options); } - scrollProfiles (scrollId) { + scrollProfiles(scrollId) { const options = { - url: this.apiPath('profiles/_scroll/' + scrollId), - method: 'GET' + url: this.apiPath("profiles/_scroll/" + scrollId), + method: "GET", }; return this.callApi(options); } - scrollSpecifications (scrollId) { + scrollSpecifications(scrollId) { const options = { - url: this.apiPath('validations/_scroll/' + scrollId), - method: 'GET' + url: this.apiPath("validations/_scroll/" + scrollId), + method: "GET", }; return this.callApi(options); } - scrollUsers (scrollId) { + scrollUsers(scrollId) { const options = { - url: this.apiPath('users/_scroll/' + scrollId), - method: 'GET' + url: this.apiPath("users/_scroll/" + scrollId), + method: "GET", }; return this.callApi(options); } - search (query, index, collection, args) { - const - options = { - url: this.apiPath(this.util.getIndex(index) + '/' + this.util.getCollection(collection) + '/_search'), - method: 'POST', - body: query - }; + search(query, index, collection, args) { + const options = { + url: this.apiPath( + this.util.getIndex(index) + + "/" + + this.util.getCollection(collection) + + "/_search" + ), + method: "POST", + body: query, + }; if (args) { let qs = []; - options.url += '?'; + options.url += "?"; if (args.scroll) { - qs.push('scroll=' + args.scroll); + qs.push("scroll=" + args.scroll); } if (args.from) { - qs.push('from=' + args.from); + qs.push("from=" + args.from); } if (args.size) { - qs.push('size=' + args.size); + qs.push("size=" + args.size); } - options.url += qs.join('&'); + options.url += qs.join("&"); } return this.callApi(options); } - searchProfiles (roles, args) { + searchProfiles(roles, args) { const options = { - url: this.apiPath('profiles/_search'), - method: 'POST', + url: this.apiPath("profiles/_search"), + method: "POST", body: { - roles - } + roles, + }, }; if (args) { let first = true; - Object.keys(args).forEach(arg => { - options.url += (first ? '?' : '&') + `${arg}=${args[arg]}`; + Object.keys(args).forEach((arg) => { + options.url += (first ? "?" : "&") + `${arg}=${args[arg]}`; first = false; }); } @@ -1059,41 +1162,41 @@ class HttpApi { return this.callApi(options); } - searchRoles (body, args) { + searchRoles(body, args) { const options = { - url: this.apiPath('roles/_search'), - method: 'POST', - body + url: this.apiPath("roles/_search"), + method: "POST", + body, }; if (args) { let qs = []; - options.url += '?'; + options.url += "?"; if (args.from) { - qs.push('from=' + args.from); + qs.push("from=" + args.from); } if (args.size) { - qs.push('size=' + args.size); + qs.push("size=" + args.size); } - options.url += qs.join('&'); + options.url += qs.join("&"); } return this.callApi(options); } - searchSpecifications (body, args) { + searchSpecifications(body, args) { const options = { - url: this.apiPath('validations/_search'), - method: 'POST', - body + url: this.apiPath("validations/_search"), + method: "POST", + body, }; if (args) { let first = true; - Object.keys(args).forEach(arg => { - options.url += (first ? '?' : '&') + `${arg}=${args[arg]}`; + Object.keys(args).forEach((arg) => { + options.url += (first ? "?" : "&") + `${arg}=${args[arg]}`; first = false; }); } @@ -1101,19 +1204,19 @@ class HttpApi { return this.callApi(options); } - searchUsers (query, args) { + searchUsers(query, args) { const options = { - url: this.apiPath('users/_search'), - method: 'POST', + url: this.apiPath("users/_search"), + method: "POST", body: { - query - } + query, + }, }; if (args) { let first = true; - Object.keys(args).forEach(arg => { - options.url += (first ? '?' : '&') + `${arg}=${args[arg]}`; + Object.keys(args).forEach((arg) => { + options.url += (first ? "?" : "&") + `${arg}=${args[arg]}`; first = false; }); } @@ -1121,22 +1224,28 @@ class HttpApi { return this.callApi(options); } - truncateCollection (index, collection) { + truncateCollection(index, collection) { const options = { - url: this.apiPath(this.util.getIndex(index) + '/' + this.util.getCollection(collection) + '/_truncate'), - method: 'DELETE' + url: this.apiPath( + this.util.getIndex(index) + + "/" + + this.util.getCollection(collection) + + "/_truncate" + ), + method: "DELETE", }; return this.callApi(options); } - update (id, body, index, collection) { - const - _collection = collection || this.world.fakeCollection, + update(id, body, index, collection) { + const _collection = collection || this.world.fakeCollection, options = { - url: this.apiPath(`${this.util.getIndex(index)}/${_collection}/${id}/_update`), - method: 'PUT', - body + url: this.apiPath( + `${this.util.getIndex(index)}/${_collection}/${id}/_update` + ), + method: "PUT", + body, }; delete body._id; @@ -1144,218 +1253,230 @@ class HttpApi { return this.callApi(options); } - updateCredentials (strategy, userId, body) { + updateCredentials(strategy, userId, body) { const options = { - url: this.apiPath('credentials/' + strategy + '/' + userId + '/_update'), - method: 'PUT', - body + url: this.apiPath("credentials/" + strategy + "/" + userId + "/_update"), + method: "PUT", + body, }; return this.callApi(options); } - updateProfileMapping () { + updateProfileMapping() { const options = { - url: this.apiPath('/profiles/_mapping'), - method: 'PUT', - body: this.world.securitymapping + url: this.apiPath("/profiles/_mapping"), + method: "PUT", + body: this.world.securitymapping, }; return this.callApi(options); } - updateMapping (index, collection, mapping) { + updateMapping(index, collection, mapping) { const options = { - url: `${this.apiPath(this.util.getIndex(index))}/${collection || this.world.fakeCollection}/_mapping`, - method: 'PUT', - body: mapping || this.world.mapping + url: `${this.apiPath(this.util.getIndex(index))}/${ + collection || this.world.fakeCollection + }/_mapping`, + method: "PUT", + body: mapping || this.world.mapping, }; return this.callApi(options); } - updateMyCredentials (strategy, body) { + updateMyCredentials(strategy, body) { const options = { - url: this.apiPath('credentials/' + strategy + '/_me/_update'), - method: 'PUT', - body + url: this.apiPath("credentials/" + strategy + "/_me/_update"), + method: "PUT", + body, }; return this.callApi(options); } - updateRoleMapping () { + updateRoleMapping() { const options = { - url: this.apiPath('/roles/_mapping'), - method: 'PUT', - body: this.world.securitymapping + url: this.apiPath("/roles/_mapping"), + method: "PUT", + body: this.world.securitymapping, }; return this.callApi(options); } - updateSelf (body) { + updateSelf(body) { const options = { - url: this.apiPath('_updateSelf'), - method: 'PUT', - body + url: this.apiPath("_updateSelf"), + method: "PUT", + body, }; return this.callApi(options); } - updateSpecifications (index, collection, specifications) { + updateSpecifications(index, collection, specifications) { const options = { url: this.apiPath(`${index}/${collection}/_specifications`), - method: 'PUT', - body: specifications + method: "PUT", + body: specifications, }; return this.callApi(options); } - updateUserMapping () { + updateUserMapping() { const options = { - url: this.apiPath('/users/_mapping'), - method: 'PUT', - body: this.world.securitymapping + url: this.apiPath("/users/_mapping"), + method: "PUT", + body: this.world.securitymapping, }; return this.callApi(options); } - validateCredentials (strategy, userId, body) { + validateCredentials(strategy, userId, body) { const options = { - url: this.apiPath('credentials/' + strategy + '/' + userId + '/_validate'), - method: 'POST', - body + url: this.apiPath( + "credentials/" + strategy + "/" + userId + "/_validate" + ), + method: "POST", + body, }; return this.callApi(options); } - validateDocument (index, collection, document) { + validateDocument(index, collection, document) { const options = { - url: this.apiPath(index + '/' + collection + '/_validate'), - method: 'POST', - body: document + url: this.apiPath(index + "/" + collection + "/_validate"), + method: "POST", + body: document, }; return this.callApi(options); } - validateMyCredentials (strategy, body) { + validateMyCredentials(strategy, body) { const options = { - url: this.apiPath('credentials/' + strategy + '/_me/_validate'), - method: 'POST', - body + url: this.apiPath("credentials/" + strategy + "/_me/_validate"), + method: "POST", + body, }; return this.callApi(options); } - validateSpecifications (index, collection, specifications) { + validateSpecifications(index, collection, specifications) { const options = { - url: this.apiPath(index ? `${index}/${collection}/_validateSpecifications` : '_validateSpecifications'), - method: 'POST', - body: specifications + url: this.apiPath( + index + ? `${index}/${collection}/_validateSpecifications` + : "_validateSpecifications" + ), + method: "POST", + body: specifications, }; return this.callApi(options); } - resetCache (database) { + resetCache(database) { const options = { url: this.apiPath(`admin/_resetCache/${database}`), - method: 'POST' + method: "POST", }; return this.callApi(options); } - resetKuzzleData () { + resetKuzzleData() { const options = { - url: this.apiPath('admin/_resetKuzzleData'), - method: 'POST' + url: this.apiPath("admin/_resetKuzzleData"), + method: "POST", }; return this.callApi(options); } - resetSecurity () { + resetSecurity() { const options = { - url: this.apiPath('admin/_resetSecurity'), - method: 'POST', + url: this.apiPath("admin/_resetSecurity"), + method: "POST", body: { - refresh: 'wait_for' - } + refresh: "wait_for", + }, }; return this.callApi(options); } - resetDatabase () { + resetDatabase() { const options = { - url: this.apiPath('admin/_resetDatabase'), - method: 'POST' + url: this.apiPath("admin/_resetDatabase"), + method: "POST", }; return this.callApi(options); } - loadMappings (body) { + loadMappings(body) { const options = { - url: this.apiPath('admin/_loadMappings?refresh=wait_for'), - method: 'POST', - body + url: this.apiPath("admin/_loadMappings?refresh=wait_for"), + method: "POST", + body, }; return this.callApi(options); } - loadFixtures (body) { + loadFixtures(body) { const options = { - url: this.apiPath('admin/_loadFixtures?refresh=wait_for'), - method: 'POST', - body + url: this.apiPath("admin/_loadFixtures?refresh=wait_for"), + method: "POST", + body, }; return this.callApi(options); } - loadSecurities (body) { + loadSecurities(body) { const options = { - url: this.apiPath('admin/_loadSecurities?refresh=wait_for'), - method: 'POST', - body + url: this.apiPath("admin/_loadSecurities?refresh=wait_for"), + method: "POST", + body, }; return this.callApi(options); } - encode (algorithm) { + encode(algorithm) { checkAlgorithm(algorithm); this.encoding = algorithm; } - decode (algorithm) { + decode(algorithm) { checkAlgorithm(algorithm); this.expectedEncoding = algorithm; } - urlEncodedCreate (form) { + urlEncodedCreate(form) { return this.callApi({ form, - method: 'POST', - url: this.apiPath(`${this.world.fakeIndex}/${this.world.fakeCollection}/_create`), + method: "POST", + url: this.apiPath( + `${this.world.fakeIndex}/${this.world.fakeCollection}/_create` + ), }); } - multipartCreate (formData) { + multipartCreate(formData) { return this.callApi({ formData, - method: 'POST', - url: this.apiPath(`${this.world.fakeIndex}/${this.world.fakeCollection}/_create`), + method: "POST", + url: this.apiPath( + `${this.world.fakeIndex}/${this.world.fakeCollection}/_create` + ), }); } } diff --git a/features-legacy/support/api/mqtt.js b/features-legacy/support/api/mqtt.js index 891aa34aac..2cbccfac5c 100644 --- a/features-legacy/support/api/mqtt.js +++ b/features-legacy/support/api/mqtt.js @@ -1,13 +1,12 @@ -'use strict'; +"use strict"; -const - Bluebird = require('bluebird'), - ApiBase = require('./apiBase'), - mqtt = require('mqtt'), - uuid = require('uuid'); +const Bluebird = require("bluebird"), + ApiBase = require("./apiBase"), + mqtt = require("mqtt"), + uuid = require("uuid"); class MqttApi extends ApiBase { - constructor (world) { + constructor(world) { super(world); this.clients = {}; @@ -15,14 +14,14 @@ class MqttApi extends ApiBase { this.subscribedRooms = {}; } - disconnect () { + disconnect() { for (const k of Object.keys(this.clients)) { this.clients[k].end(); } } - send (msg, getAnswer = true, clientName = 'client1') { - if (! msg.requestId) { + send(msg, getAnswer = true, clientName = "client1") { + if (!msg.requestId) { msg.requestId = uuid.v4(); } @@ -32,75 +31,75 @@ class MqttApi extends ApiBase { msg.jwt = this.world.currentUser.token; } - return this._getClient(clientName) - .then(client => { - let promise = Bluebird.resolve({}); - if (getAnswer) { - promise = new Bluebird((resolve, reject) => { - this.requests[msg.requestId] = result => { - if (! result) { - const error = new Error('Returned result is null'); - return reject(Object.assign(error, msg)); - } - - if (result.error && result.status !== 206) { - const error = new Error(result.error.stack); - Object.assign(error, result); - - // used to fit with rest api (used with request-promise) - error.details = result.error._source || {}; - error.statusCode = result.status; - return reject(error); - } - - resolve(result); - }; - }); - } + return this._getClient(clientName).then((client) => { + let promise = Bluebird.resolve({}); + if (getAnswer) { + promise = new Bluebird((resolve, reject) => { + this.requests[msg.requestId] = (result) => { + if (!result) { + const error = new Error("Returned result is null"); + return reject(Object.assign(error, msg)); + } - client.publish('Kuzzle/request', JSON.stringify(msg)); + if (result.error && result.status !== 206) { + const error = new Error(result.error.stack); + Object.assign(error, result); - return promise; - }); + // used to fit with rest api (used with request-promise) + error.details = result.error._source || {}; + error.statusCode = result.status; + return reject(error); + } + resolve(result); + }; + }); + } + + client.publish("Kuzzle/request", JSON.stringify(msg)); + + return promise; + }); } - sendAndListen (msg, clientName = 'client1') { - if (! msg.requestId) { + sendAndListen(msg, clientName = "client1") { + if (!msg.requestId) { msg.requestId = uuid.v4(); } msg.volatile = this.world.volatile; - return this._getClient(clientName) - .then(client => { - const promise = new Bluebird((resolve, reject) => { - this.requests[msg.requestId] = response => { - const listener = document => { - this.responses = document; - }; - - if (response.error) { - return reject(response.error.message); - } + return this._getClient(clientName).then((client) => { + const promise = new Bluebird((resolve, reject) => { + this.requests[msg.requestId] = (response) => { + const listener = (document) => { + this.responses = document; + }; - if (! this.subscribedRooms[clientName]) { - this.subscribedRooms[clientName] = {}; - } - this.subscribedRooms[clientName][response.result.roomId] = { channel: response.result.channel, listener }; - client.subscribe(response.result.channel); + if (response.error) { + return reject(response.error.message); + } - resolve(response); + if (!this.subscribedRooms[clientName]) { + this.subscribedRooms[clientName] = {}; + } + this.subscribedRooms[clientName][response.result.roomId] = { + channel: response.result.channel, + listener, }; - }); + client.subscribe(response.result.channel); - client.publish('Kuzzle/request', JSON.stringify(msg)); - - return promise; + resolve(response); + }; }); + + client.publish("Kuzzle/request", JSON.stringify(msg)); + + return promise; + }); } - _getClient (name) { + _getClient(name) { if (this.clients[name]) { return Bluebird.resolve(this.clients[name]); } @@ -109,31 +108,32 @@ class MqttApi extends ApiBase { const client = mqtt.connect({ host: this.world.config.host }); this.clients[name] = client; - client.on('error', reject); - client.on('connect', () => resolve(client)); - client.on('message', (topic, raw) => { + client.on("error", reject); + client.on("connect", () => resolve(client)); + client.on("message", (topic, raw) => { const message = JSON.parse(Buffer.from(raw)); - if (topic === 'Kuzzle/response') { + if (topic === "Kuzzle/response") { if (this.requests[message.requestId]) { this.requests[message.requestId](message); } - } - else { - if (message.type === 'TokenExpired') { + } else { + if (message.type === "TokenExpired") { this.responses = message; } // notification const channel = topic; - const roomId = topic.split('-')[0]; + const roomId = topic.split("-")[0]; - if (this.subscribedRooms[name] && this.subscribedRooms[name][roomId]) { + if ( + this.subscribedRooms[name] && + this.subscribedRooms[name][roomId] + ) { const room = this.subscribedRooms[name][roomId]; if (room.channel === channel) { room.listener(message); - } - else { - throw new Error('Channels do not match'); + } else { + throw new Error("Channels do not match"); } } } @@ -141,9 +141,9 @@ class MqttApi extends ApiBase { }); } - unsubscribe (roomId, clientName, waitForResponse = false) { + unsubscribe(roomId, clientName, waitForResponse = false) { const client = this.clients[clientName]; - if (! client) { + if (!client) { return; } @@ -151,17 +151,20 @@ class MqttApi extends ApiBase { client.unsubscribe(room.channel); delete this.subscribedRooms[clientName][roomId]; - return this.send({ - controller: 'realtime', - action: 'unsubscribe', - collection: this.world.fakeCollection, - index: this.world.fakeIndex, - body: { roomId } - }, waitForResponse, clientName); - + return this.send( + { + controller: "realtime", + action: "unsubscribe", + collection: this.world.fakeCollection, + index: this.world.fakeIndex, + body: { roomId }, + }, + waitForResponse, + clientName + ); } - unsubscribeAll () { + unsubscribeAll() { const promises = []; for (const clientName of Object.keys(this.subscribedRooms)) { @@ -172,8 +175,6 @@ class MqttApi extends ApiBase { return Bluebird.all(promises); } - } module.exports = MqttApi; - diff --git a/features-legacy/support/api/websocket.js b/features-legacy/support/api/websocket.js index 910d117422..10c89b2815 100644 --- a/features-legacy/support/api/websocket.js +++ b/features-legacy/support/api/websocket.js @@ -1,13 +1,11 @@ -'use strict'; +"use strict"; -const - Bluebird = require('bluebird'), - WsApiBase = require('./websocketBase'), - Ws = require('ws'); +const Bluebird = require("bluebird"), + WsApiBase = require("./websocketBase"), + Ws = require("ws"); class WebSocketApi extends WsApiBase { - - constructor (world) { + constructor(world) { super(world); this.responses = null; @@ -17,52 +15,60 @@ class WebSocketApi extends WsApiBase { this.requests = {}; } - get socket () { + get socket() { return this.socket.client1; } - _initSocket (name = 'client1') { + _initSocket(name = "client1") { if (this.sockets[name]) { return Bluebird.resolve(); } return new Bluebird((resolve, reject) => { - this.sockets[name] = new Ws(`ws://${this.world.config.host}:${this.world.config.port}`, { - perMessageDeflate: false - }); + this.sockets[name] = new Ws( + `ws://${this.world.config.host}:${this.world.config.port}`, + { + perMessageDeflate: false, + } + ); - this.sockets[name].on('message', message => { + this.sockets[name].on("message", (message) => { const data = JSON.parse(message); - if (data.scope || data.type === 'user' || data.type === 'TokenExpired') { - if (data.type === 'TokenExpired') { + if ( + data.scope || + data.type === "user" || + data.type === "TokenExpired" + ) { + if (data.type === "TokenExpired") { this.responses = data; } // notification const channel = data.room; - const roomId = channel.split('-')[0]; + const roomId = channel.split("-")[0]; - if (this.subscribedRooms[name] && this.subscribedRooms[name][roomId]) { + if ( + this.subscribedRooms[name] && + this.subscribedRooms[name][roomId] + ) { const room = this.subscribedRooms[name][roomId]; if (room.channel === channel) { room.listener(data); - } - else { - throw new Error('Channels do not match'); + } else { + throw new Error("Channels do not match"); } } - } - else if (this.requests[data.requestId]) { + } else if (this.requests[data.requestId]) { // response this.requests[data.requestId](data); } }); - this.sockets[name].on('error', reject); - this.sockets[name].on('open', resolve); + this.sockets[name].on("error", reject); + this.sockets[name].on("open", resolve); }); } - _socketOn () { + _socketOn() { // do nothing } @@ -74,11 +80,11 @@ class WebSocketApi extends WsApiBase { * @returns {*} * @private */ - _socketOnce (socket, requestId, cb) { + _socketOnce(socket, requestId, cb) { this.requests[requestId] = cb; } - _socketRemoveListener () { + _socketRemoveListener() { // do nothing } @@ -89,21 +95,20 @@ class WebSocketApi extends WsApiBase { * @returns {*} * @private */ - _socketSend (socket, msg) { - return socket.send(JSON.stringify(msg), err => { + _socketSend(socket, msg) { + return socket.send(JSON.stringify(msg), (err) => { if (err) { throw err; } }); } - disconnect () { + disconnect() { for (const socketKey of Object.keys(this.sockets)) { this.sockets[socketKey].terminate(); delete this.sockets[socketKey]; } } - } module.exports = WebSocketApi; diff --git a/features-legacy/support/api/websocketBase.js b/features-legacy/support/api/websocketBase.js index 01788cc512..24b73f7e55 100644 --- a/features-legacy/support/api/websocketBase.js +++ b/features-legacy/support/api/websocketBase.js @@ -1,23 +1,20 @@ -'use strict'; - -const - Bluebird = require('bluebird'), - ApiBase = require('./apiBase'), - uuid = require('uuid'); +"use strict"; +const Bluebird = require("bluebird"), + ApiBase = require("./apiBase"), + uuid = require("uuid"); class WebSocketApiBase extends ApiBase { - - _socketOnce () { - throw new Error('not implemented'); + _socketOnce() { + throw new Error("not implemented"); } - _socketSend () { - throw new Error('not implemented'); + _socketSend() { + throw new Error("not implemented"); } - send (msg, getAnswer = true, socketName = 'client1') { - if (! msg.requestId) { + send(msg, getAnswer = true, socketName = "client1") { + if (!msg.requestId) { msg.requestId = uuid.v4(); } @@ -27,42 +24,41 @@ class WebSocketApiBase extends ApiBase { msg.jwt = this.world.currentUser.token; } - return this._initSocket(socketName) - .then(() => { - const socket = this.sockets[socketName]; - - let promise = Bluebird.resolve({}); - if (getAnswer) { - promise = new Bluebird((resolve, reject) => { - this._socketOnce(socket, msg.requestId, result => { - if (! result) { - const error = new Error('Returned result is null'); - return reject(Object.assign(error, msg)); - } - - if (result.error && result.status !== 206) { - const error = new Error(result.error.stack); - Object.assign(error, result); - - // used to fit with rest api (used with request-promise) - error.details = result.error._source || {}; - error.statusCode = result.status; - return reject(error); - } - - resolve(result); - }); + return this._initSocket(socketName).then(() => { + const socket = this.sockets[socketName]; + + let promise = Bluebird.resolve({}); + if (getAnswer) { + promise = new Bluebird((resolve, reject) => { + this._socketOnce(socket, msg.requestId, (result) => { + if (!result) { + const error = new Error("Returned result is null"); + return reject(Object.assign(error, msg)); + } + + if (result.error && result.status !== 206) { + const error = new Error(result.error.stack); + Object.assign(error, result); + + // used to fit with rest api (used with request-promise) + error.details = result.error._source || {}; + error.statusCode = result.status; + return reject(error); + } + + resolve(result); }); - } + }); + } - this._socketSend(socket, msg); + this._socketSend(socket, msg); - return promise; - }); + return promise; + }); } - sendAndListen (msg, socketName = 'client1') { - if (! msg.requestId) { + sendAndListen(msg, socketName = "client1") { + if (!msg.requestId) { msg.requestId = uuid.v4(); } @@ -72,48 +68,51 @@ class WebSocketApiBase extends ApiBase { msg.jwt = this.world.currentUser.token; } - return this._initSocket(socketName) - .then(() => { - const socket = this.sockets[socketName]; - - let promise = new Bluebird((resolve, reject) => { - this._socketOnce(socket, msg.requestId, response => { - const listener = document => { - this.responses = document; - }; - - if (response.error) { - return reject(response.error.message); - } - - if (! this.subscribedRooms[socketName]) { - this.subscribedRooms[socketName] = {}; - } - - this.subscribedRooms[socketName][response.result.roomId] = { channel: response.result.channel, listener }; - this._socketOn(socket, response.result.channel, document => listener(document)); - resolve(response); - }); + return this._initSocket(socketName).then(() => { + const socket = this.sockets[socketName]; + + let promise = new Bluebird((resolve, reject) => { + this._socketOnce(socket, msg.requestId, (response) => { + const listener = (document) => { + this.responses = document; + }; + + if (response.error) { + return reject(response.error.message); + } + + if (!this.subscribedRooms[socketName]) { + this.subscribedRooms[socketName] = {}; + } + + this.subscribedRooms[socketName][response.result.roomId] = { + channel: response.result.channel, + listener, + }; + this._socketOn(socket, response.result.channel, (document) => + listener(document) + ); + resolve(response); }); + }); - this._socketSend(socket, msg); + this._socketSend(socket, msg); - return promise; - }); + return promise; + }); } - unsubscribe (roomId, socketName, waitForResponse = false) { - const - msg = { - controller: 'realtime', - action: 'unsubscribe', - collection: this.world.fakeCollection, - index: this.world.fakeIndex, - body: { roomId: roomId } - }; + unsubscribe(roomId, socketName, waitForResponse = false) { + const msg = { + controller: "realtime", + action: "unsubscribe", + collection: this.world.fakeCollection, + index: this.world.fakeIndex, + body: { roomId: roomId }, + }; const socket = this.sockets[socketName]; - if (! socket) { + if (!socket) { return; } @@ -126,7 +125,7 @@ class WebSocketApiBase extends ApiBase { return this.send(msg, waitForResponse, socketName); } - unsubscribeAll () { + unsubscribeAll() { const promises = []; for (const socketName of Object.keys(this.subscribedRooms)) { diff --git a/features-legacy/support/config.js b/features-legacy/support/config.js index 8fbc6496f8..2c00ff527d 100644 --- a/features-legacy/support/config.js +++ b/features-legacy/support/config.js @@ -1,16 +1,17 @@ -'use strict'; +"use strict"; -const rc = require('rc'); +const rc = require("rc"); -const kuzzleConfig = require('../../lib/config'); +const kuzzleConfig = require("../../lib/config"); -module.exports = rc('kuzzle', { - scheme: 'http', - host: 'localhost', +module.exports = rc("kuzzle", { + scheme: "http", + host: "localhost", port: 7512, services: { storageEngine: { - commonMapping: kuzzleConfig.loadConfig().services.storageEngine.commonMapping - } - } + commonMapping: + kuzzleConfig.loadConfig().services.storageEngine.commonMapping, + }, + }, }); diff --git a/features-legacy/support/env.js b/features-legacy/support/env.js index b3e80174b9..e35c50bd4c 100644 --- a/features-legacy/support/env.js +++ b/features-legacy/support/env.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; var configure = function () { this.setDefaultTimeout(30 * 1000); diff --git a/features-legacy/support/hooks.js b/features-legacy/support/hooks.js index 3ced86225f..941774e578 100644 --- a/features-legacy/support/hooks.js +++ b/features-legacy/support/hooks.js @@ -1,39 +1,47 @@ -'use strict'; +"use strict"; -const _ = require('lodash'); -const { After, Before, BeforeAll } = require('cucumber'); -const Bluebird = require('bluebird'); +const _ = require("lodash"); +const { After, Before, BeforeAll } = require("cucumber"); +const Bluebird = require("bluebird"); -const Http = require('./api/http'); -const World = require('./world'); +const Http = require("./api/http"); +const World = require("./world"); -function bootstrapDatabase () { - const - fixtures = require('../fixtures/functionalTestsFixtures.json'), +function bootstrapDatabase() { + const fixtures = require("../fixtures/functionalTestsFixtures.json"), promises = [], world = new World({ parameters: parseWorldParameters() }), http = new Http(world); for (const index of Object.keys(fixtures)) { - promises.push(() => http.deleteIndex(index) - .catch(() => true)); + promises.push(() => http.deleteIndex(index).catch(() => true)); } - const mappings = { dynamic: 'true', properties: { foo: { type: 'keyword' } } }; + const mappings = { + dynamic: "true", + properties: { foo: { type: "keyword" } }, + }; promises.push(() => http.createIndex(world.fakeIndex)); - promises.push(() => http.createCollection(world.fakeIndex, world.fakeCollection, mappings)); - promises.push(() => http.createCollection(world.fakeIndex, world.fakeAltCollection, mappings)); + promises.push(() => + http.createCollection(world.fakeIndex, world.fakeCollection, mappings) + ); + promises.push(() => + http.createCollection(world.fakeIndex, world.fakeAltCollection, mappings) + ); promises.push(() => http.createIndex(world.fakeAltIndex)); - promises.push(() => http.createCollection(world.fakeAltIndex, world.fakeCollection, mappings)); - promises.push(() => http.createCollection(world.fakeAltIndex, world.fakeAltCollection, mappings)); - - return Bluebird.each(promises, promise => promise()); + promises.push(() => + http.createCollection(world.fakeAltIndex, world.fakeCollection, mappings) + ); + promises.push(() => + http.createCollection(world.fakeAltIndex, world.fakeAltCollection, mappings) + ); + + return Bluebird.each(promises, (promise) => promise()); } -function cleanDatabase () { - const - promises = [], +function cleanDatabase() { + const promises = [], world = new World({ parameters: parseWorldParameters() }), http = new Http(world); @@ -41,10 +49,9 @@ function cleanDatabase () { world.fakeIndex, world.fakeAltIndex, world.fakeNewIndex, - 'tolkien' + "tolkien", ]) { - promises.push(http.deleteIndex(index) - .catch(() => true)); + promises.push(http.deleteIndex(index).catch(() => true)); } return Bluebird.all(promises); @@ -52,21 +59,23 @@ function cleanDatabase () { // before first BeforeAll(function () { - return cleanDatabase() - .then(() => bootstrapDatabase()); + return cleanDatabase().then(() => bootstrapDatabase()); }); Before({ timeout: 10 * 2000 }, function () { const world = new World({ parameters: parseWorldParameters() }); - return this.api.truncateCollection(world.fakeIndex, world.fakeCollection) + return this.api + .truncateCollection(world.fakeIndex, world.fakeCollection) .catch(() => {}) - .then(() => this.api.truncateCollection(world.fakeAltIndex, world.fakeAltCollection)) + .then(() => + this.api.truncateCollection(world.fakeAltIndex, world.fakeAltCollection) + ) .catch(() => {}) .then(() => this.api.resetSecurity()); }); -Before({ timeout: 10 * 2000, tags: '@resetDatabase' }, async function () { +Before({ timeout: 10 * 2000, tags: "@resetDatabase" }, async function () { await cleanDatabase(); await bootstrapDatabase(); }); @@ -75,45 +84,44 @@ After(function () { return this.api.disconnect(); }); -After({ tags: '@realtime' }, function () { - return this.api.unsubscribeAll() - .catch(() => true); +After({ tags: "@realtime" }, function () { + return this.api.unsubscribeAll().catch(() => true); }); -Before({ tags: '@security' }, function () { +Before({ tags: "@security" }, function () { return cleanSecurity.call(this); }); -Before({ tags: '@firstAdmin' }, function () { +Before({ tags: "@firstAdmin" }, function () { return cleanSecurity.call(this); }); -After({ tags: '@firstAdmin' }, function () { +After({ tags: "@firstAdmin" }, function () { return grantDefaultRoles.call(this).then(() => cleanSecurity.call(this)); }); -Before({ tags: '@redis' }, function () { +Before({ tags: "@redis" }, function () { return cleanRedis.call(this); }); -After({ tags: '@redis' }, function () { +After({ tags: "@redis" }, function () { return cleanRedis.call(this); }); -Before({ tags: '@validation' }, function () { +Before({ tags: "@validation" }, function () { return cleanValidations.call(this); }); -After({ tags: '@validation' }, function () { +After({ tags: "@validation" }, function () { return cleanValidations.call(this); }); -After({ tags: '@http' }, function () { - this.api.encode('identity'); - this.api.decode('identity'); +After({ tags: "@http" }, function () { + this.api.encode("identity"); + this.api.decode("identity"); }); -function cleanSecurity () { +function cleanSecurity() { if (this.currentUser) { delete this.currentUser; } @@ -121,19 +129,20 @@ function cleanSecurity () { return this.api.resetSecurity(); } -function grantDefaultRoles () { - return this.api.login('local', this.users.useradmin.credentials.local) - .then(body => { +function grantDefaultRoles() { + return this.api + .login("local", this.users.useradmin.credentials.local) + .then((body) => { if (body.error) { return Promise.reject(new Error(body.error.message)); } - if (! body.result) { - return Promise.reject(new Error('No result provided')); + if (!body.result) { + return Promise.reject(new Error("No result provided")); } - if (! body.result.jwt) { - return Promise.reject(new Error('No token received')); + if (!body.result.jwt) { + return Promise.reject(new Error("No token received")); } if (this.currentUser === null || this.currentUser === undefined) { @@ -143,47 +152,71 @@ function grantDefaultRoles () { this.currentToken = { jwt: body.result.jwt }; this.currentUser.token = body.result.jwt; - return this.api.createOrReplaceRole('anonymous', { controllers: { '*': { actions: { '*': true } } } }); + return this.api.createOrReplaceRole("anonymous", { + controllers: { "*": { actions: { "*": true } } }, + }); }) - .then(() => this.api.createOrReplaceRole('default', { controllers: { '*': { actions: { '*': true } } } })) - .then(() => this.api.createOrReplaceRole('admin', { controllers: { '*': { actions: { '*': true } } } })); + .then(() => + this.api.createOrReplaceRole("default", { + controllers: { "*": { actions: { "*": true } } }, + }) + ) + .then(() => + this.api.createOrReplaceRole("admin", { + controllers: { "*": { actions: { "*": true } } }, + }) + ); } -function cleanRedis () { - return this.api.callMemoryStorage('keys', { args: { pattern: this.idPrefix + '*' } }) - .then(response => { +function cleanRedis() { + return this.api + .callMemoryStorage("keys", { args: { pattern: this.idPrefix + "*" } }) + .then((response) => { if (_.isArray(response.result) && response.result.length) { - return this.api.callMemoryStorage('del', { body: { keys: response.result } }); + return this.api.callMemoryStorage("del", { + body: { keys: response.result }, + }); } return null; }); } -function cleanValidations () { - return this.api.searchSpecifications({ - query: { - match_all: { boost: 1 } - } - }) - .then(body => Bluebird.all(body.result.hits - .filter(r => r._id.match(/^kuzzle-test-/)) - .map(r => this.api.deleteSpecifications(r._id.split('#')[0], r._id.split('#')[1])) - )); +function cleanValidations() { + return this.api + .searchSpecifications({ + query: { + match_all: { boost: 1 }, + }, + }) + .then((body) => + Bluebird.all( + body.result.hits + .filter((r) => r._id.match(/^kuzzle-test-/)) + .map((r) => + this.api.deleteSpecifications( + r._id.split("#")[0], + r._id.split("#")[1] + ) + ) + ) + ); } -function parseWorldParameters () { - const worldParamIndex = process.argv.indexOf('--world-parameters'); - const worldParam = worldParamIndex > -1 - ? JSON.parse(process.argv[worldParamIndex + 1]) - : {}; - - const parameters = Object.assign({ - host: 'localhost', - port: 7512, - protocol: 'websocket', - silent: true, - }, worldParam); +function parseWorldParameters() { + const worldParamIndex = process.argv.indexOf("--world-parameters"); + const worldParam = + worldParamIndex > -1 ? JSON.parse(process.argv[worldParamIndex + 1]) : {}; + + const parameters = Object.assign( + { + host: "localhost", + port: 7512, + protocol: "websocket", + silent: true, + }, + worldParam + ); return parameters; } diff --git a/features-legacy/support/stepUtils.js b/features-legacy/support/stepUtils.js index b34b67a070..cb7d47b339 100644 --- a/features-legacy/support/stepUtils.js +++ b/features-legacy/support/stepUtils.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; exports.getReturn = function () { - var - args = Array.prototype.slice.call(arguments), + var args = Array.prototype.slice.call(arguments), action = args.shift(), cb = args.pop(); - this.api[action].apply(this.api, args) - .then(response => { + this.api[action] + .apply(this.api, args) + .then((response) => { if (response.error) { this.result = response; return cb(); @@ -16,7 +16,7 @@ exports.getReturn = function () { this.result = response; cb(); }) - .catch(error => { + .catch((error) => { this.result = error; cb(); }); diff --git a/features-legacy/support/world.js b/features-legacy/support/world.js index fd87033938..cf4876a135 100644 --- a/features-legacy/support/world.js +++ b/features-legacy/support/world.js @@ -1,189 +1,192 @@ -'use strict'; +"use strict"; -const - { setWorldConstructor } = require('cucumber'), - HttpApi = require('./api/http'), - MqttApi = require('./api/mqtt'), - WebSocketApi = require('./api/websocket'); +const { setWorldConstructor } = require("cucumber"), + HttpApi = require("./api/http"), + MqttApi = require("./api/mqtt"), + WebSocketApi = require("./api/websocket"); -let - _init; +let _init; class KWorld { - constructor (config) { - this.config = Object.assign({ - protocol: 'websocket', - host: 'localhost', - port: 7512 - }, config.parameters); + constructor(config) { + this.config = Object.assign( + { + protocol: "websocket", + host: "localhost", + port: 7512, + }, + config.parameters + ); switch (this.config.protocol) { - case 'http': + case "http": this.api = new HttpApi(this); break; - case 'mqtt': + case "mqtt": this.api = new MqttApi(this); break; default: // websocket this.api = new WebSocketApi(this); - this.config.protocol = 'websocket'; + this.config.protocol = "websocket"; } - if (! _init && ! this.config.silent) { - console.log(`[${this.config.protocol}] ${this.config.host}:${this.config.port}`); + if (!_init && !this.config.silent) { + console.log( + `[${this.config.protocol}] ${this.config.host}:${this.config.port}` + ); _init = true; } - this.kuzzleConfig = require('../../lib/config').loadConfig(); - this.idPrefix = 'kuzzle-functional-tests-'; + this.kuzzleConfig = require("../../lib/config").loadConfig(); + this.idPrefix = "kuzzle-functional-tests-"; this.currentUser = null; // Fake values for test - this.fakeIndex = 'kuzzle-test-index'; - this.fakeAltIndex = 'kuzzle-test-index-alt'; - this.fakeNewIndex = 'kuzzle-test-index-new'; - this.fakeCollection = 'kuzzle-collection-test'; - this.fakeAltCollection = 'kuzzle-collection-test-alt'; + this.fakeIndex = "kuzzle-test-index"; + this.fakeAltIndex = "kuzzle-test-index-alt"; + this.fakeNewIndex = "kuzzle-test-index-new"; + this.fakeCollection = "kuzzle-collection-test"; + this.fakeAltCollection = "kuzzle-collection-test-alt"; this.documentGrace = { - firstName: 'Grace', - lastName: 'Hopper', + firstName: "Grace", + lastName: "Hopper", info: { age: 85, - city: 'NYC', - hobby: 'computer' + city: "NYC", + hobby: "computer", }, location: { lat: 32.692742, - lon: -97.114127 - } + lon: -97.114127, + }, }; this.documentAda = { - firstName: 'Ada', - lastName: 'Lovelace', + firstName: "Ada", + lastName: "Lovelace", info: { age: 36, - city: 'London', - hobby: 'computer' + city: "London", + hobby: "computer", }, location: { lat: 51.519291, - lon: -0.149817 - } + lon: -0.149817, + }, }; this.bulk = [ { index: { _id: 1 } }, - { title: 'foo' }, + { title: "foo" }, { index: { _id: 2 } }, - { title: 'bar' }, + { title: "bar" }, { update: { _id: 1 } }, - { doc: { title: 'foobar' } }, - { delete: { _id: 2 } } + { doc: { title: "foobar" } }, + { delete: { _id: 2 } }, ]; this.mapping = { properties: { firstName: { - type: 'text', - copy_to: 'newFirstName' + type: "text", + copy_to: "newFirstName", }, newFirstName: { - type: 'keyword', - store: true - } - } + type: "keyword", + store: true, + }, + }, }; this.securitymapping = { properties: { foo: { - type: 'text', - copy_to: 'bar' + type: "text", + copy_to: "bar", }, bar: { - type: 'keyword', - store: true - } - } + type: "keyword", + store: true, + }, + }, }; this.volatile = { - iwant: 'to break free', - we: ['will', 'rock', 'you'] + iwant: "to break free", + we: ["will", "rock", "you"], }; this.roles = { role1: { controllers: { - '*': { + "*": { actions: { - '*': true - } - } - } + "*": true, + }, + }, + }, }, role2: { controllers: { - 'document': { + document: { actions: { - '*': true - } + "*": true, + }, }, - 'auth': { actions: { logout: true } } - } + auth: { actions: { logout: true } }, + }, }, role3: { controllers: { - 'document': { + document: { actions: { - 'search': true - } + search: true, + }, }, - 'auth': { actions: { logout: true } } - } + auth: { actions: { logout: true } }, + }, }, foo: { controllers: { - 'foo': { + foo: { actions: { - '*': true - } - } - } + "*": true, + }, + }, + }, }, bar: { controllers: { - 'bar': { + bar: { actions: { - '*': true - } - } - } + "*": true, + }, + }, + }, }, foobar: { controllers: { - 'foo': { + foo: { actions: { - '*': true - } + "*": true, + }, }, - 'bar': { + bar: { actions: { - '*': true - } - } - } + "*": true, + }, + }, + }, }, admin: { controllers: { - '*': { + "*": { actions: { - '*': true - } - } - } + "*": true, + }, + }, + }, }, default: { controllers: { @@ -193,15 +196,15 @@ class KWorld { getCurrentUser: true, getMyRights: true, logout: true, - updateSelf: true - } + updateSelf: true, + }, }, server: { actions: { - info: true - } - } - } + info: true, + }, + }, + }, }, anonymous: { controllers: { @@ -210,230 +213,266 @@ class KWorld { checkToken: true, getCurrentUser: true, getMyRights: true, - login: true - } + login: true, + }, }, server: { actions: { - info: true - } - } - } - } + info: true, + }, + }, + }, + }, }; this.policies = { profile1: [ - { controller: '*', action: '*', index: '*', collection: '*', value: 'allowed' } + { + controller: "*", + action: "*", + index: "*", + collection: "*", + value: "allowed", + }, ], profile2: [ - { controller: '*', action: '*', index: this.fakeIndex, collection: '*', value: 'allowed' }, - { controller: 'document', action: '*', index: '*', collection: '*', value: 'allowed' }, - { controller: 'auth', action: 'logout', index: '*', collection: '*', value: 'allowed' } - ] + { + controller: "*", + action: "*", + index: this.fakeIndex, + collection: "*", + value: "allowed", + }, + { + controller: "document", + action: "*", + index: "*", + collection: "*", + value: "allowed", + }, + { + controller: "auth", + action: "logout", + index: "*", + collection: "*", + value: "allowed", + }, + ], }; this.profiles = { profile1: { - policies: [{ roleId: this.idPrefix + 'role1' }] + policies: [{ roleId: this.idPrefix + "role1" }], }, profile2: { policies: [ { - roleId: this.idPrefix + 'role1', - restrictedTo: [{ index: this.fakeIndex }] + roleId: this.idPrefix + "role1", + restrictedTo: [{ index: this.fakeIndex }], }, { - roleId: this.idPrefix + 'role2' - } - ] + roleId: this.idPrefix + "role2", + }, + ], }, profile3: { - policies: [{ - roleId: this.idPrefix + 'role2', - restrictedTo: [{ index: this.fakeAltIndex, collections: [this.fakeCollection] }] - }] + policies: [ + { + roleId: this.idPrefix + "role2", + restrictedTo: [ + { index: this.fakeAltIndex, collections: [this.fakeCollection] }, + ], + }, + ], }, profile4: { - policies: [{ - roleId: this.idPrefix + 'role3' - }] + policies: [ + { + roleId: this.idPrefix + "role3", + }, + ], }, profile5: { - policies: [{ - roleId: this.idPrefix + 'role3', - restrictedTo: [{ index: this.fakeIndex }] - }] + policies: [ + { + roleId: this.idPrefix + "role3", + restrictedTo: [{ index: this.fakeIndex }], + }, + ], }, profile6: { - policies: [{ - roleId: this.idPrefix + 'role3', - restrictedTo: [{ index: this.fakeIndex, collections: [this.fakeCollection] }] - }] + policies: [ + { + roleId: this.idPrefix + "role3", + restrictedTo: [ + { index: this.fakeIndex, collections: [this.fakeCollection] }, + ], + }, + ], }, invalidProfile: { - policies: [{ roleId: 'unexisting-role' }] + policies: [{ roleId: "unexisting-role" }], }, emptyProfile: { - policies: [] + policies: [], }, admin: { - policies: [{ roleId: 'admin' }] + policies: [{ roleId: "admin" }], }, adminfoo: { - policies: [{ roleId: 'admin' }, { roleId: this.idPrefix + 'foo' }] + policies: [{ roleId: "admin" }, { roleId: this.idPrefix + "foo" }], }, default: { - policies: [{ roleId: 'default' }] + policies: [{ roleId: "default" }], }, defaultfoo: { - policies: [{ roleId: 'default' }, { roleId: this.idPrefix + 'foo' }] + policies: [{ roleId: "default" }, { roleId: this.idPrefix + "foo" }], }, anonymous: { - policies: [{ roleId: 'anonymous' }] + policies: [{ roleId: "anonymous" }], }, anonymousfoo: { - policies: [{ roleId: 'anonymous' }, { roleId: this.idPrefix + 'foo' }] - } + policies: [{ roleId: "anonymous" }, { roleId: this.idPrefix + "foo" }], + }, }; this.users = { useradmin: { content: { name: { - first: 'David', - last: 'Bowie', - real: 'David Robert Jones' + first: "David", + last: "Bowie", + real: "David Robert Jones", }, - profileIds: ['admin'] + profileIds: ["admin"], }, credentials: { local: { - username: this.idPrefix + 'useradmin', - password: 'testpwd' - } - } + username: this.idPrefix + "useradmin", + password: "testpwd", + }, + }, }, user1: { content: { - profileIds: [this.idPrefix + 'profile1'] + profileIds: [this.idPrefix + "profile1"], }, credentials: { local: { - username: this.idPrefix + 'user1', - password: 'testpwd1' - } - } + username: this.idPrefix + "user1", + password: "testpwd1", + }, + }, }, user2: { content: { name: { - first: 'Steve', - last: 'Wozniak' + first: "Steve", + last: "Wozniak", }, - hobby: 'Segway Polo', - profileIds: [this.idPrefix + 'profile2'] + hobby: "Segway Polo", + profileIds: [this.idPrefix + "profile2"], }, credentials: { local: { - username: this.idPrefix + 'user2', - password: 'testpwd2' - } - } + username: this.idPrefix + "user2", + password: "testpwd2", + }, + }, }, user3: { content: { - profileIds: [this.idPrefix + 'profile3'] + profileIds: [this.idPrefix + "profile3"], }, credentials: { local: { - username: this.idPrefix + 'user3', - password: 'testpwd3' - } - } + username: this.idPrefix + "user3", + password: "testpwd3", + }, + }, }, user4: { content: { - profileIds: [this.idPrefix + 'profile4'] + profileIds: [this.idPrefix + "profile4"], }, credentials: { local: { - username: this.idPrefix + 'user4', - password: 'testpwd4' - } - } + username: this.idPrefix + "user4", + password: "testpwd4", + }, + }, }, user5: { content: { - profileIds: [this.idPrefix + 'profile5'] + profileIds: [this.idPrefix + "profile5"], }, - password: 'testpwd5', + password: "testpwd5", credentials: { local: { - username: this.idPrefix + 'user5', - password: 'testpwd5' - } - } + username: this.idPrefix + "user5", + password: "testpwd5", + }, + }, }, user6: { content: { - profileIds: [this.idPrefix + 'profile6'] + profileIds: [this.idPrefix + "profile6"], }, credentials: { local: { - username: this.idPrefix + 'user6', - password: 'testpwd6' - } - } + username: this.idPrefix + "user6", + password: "testpwd6", + }, + }, }, restricteduser1: { content: { name: { - first: 'Restricted', - last: 'User' - } + first: "Restricted", + last: "User", + }, }, credentials: { local: { - username: this.idPrefix + 'restricteduser1', - password: 'testpwd1' - } - } + username: this.idPrefix + "restricteduser1", + password: "testpwd1", + }, + }, }, nocredentialuser: { content: { name: { - first: 'Non Connectable', - last: 'User' + first: "Non Connectable", + last: "User", }, - profileIds: ['admin'] - } + profileIds: ["admin"], + }, }, unexistingprofile: { content: { name: { - first: 'John', - last: 'Doe' + first: "John", + last: "Doe", }, - profileIds: [this.idPrefix + 'i-dont-exist'] - } + profileIds: [this.idPrefix + "i-dont-exist"], + }, }, invalidprofileType: { content: { name: { - first: 'John', - last: 'Doe' + first: "John", + last: "Doe", }, - profileIds: [null] - } - } + profileIds: [null], + }, + }, }; this.credentials = { nocredentialuser: { - username: this.idPrefix + 'nocredentialuser', - password: 'testpwd1' - } + username: this.idPrefix + "nocredentialuser", + password: "testpwd1", + }, }; this.memoryStorageResult = null;