diff --git a/packages/core b/packages/core index 10009efb45..29318b29d3 160000 --- a/packages/core +++ b/packages/core @@ -1 +1 @@ -Subproject commit 10009efb45995dc6a01ae941e8e539e2226a115c +Subproject commit 29318b29d35ac8d8bfb137a5e739a308e01c1829 diff --git a/packages/datastores/datastores/local.js b/packages/datastores/datastores/local.js index cce031cdb8..63d3d8dc1f 100644 --- a/packages/datastores/datastores/local.js +++ b/packages/datastores/datastores/local.js @@ -56,10 +56,14 @@ const readableFileStream = root => async path => join(root, path), "utf8" ); -const writableFileStream = root => async path => - fs.createWriteStream( - join(root, path), "utf8" - ); +const writableFileStream = root => path => + new Promise((resolve, reject) => { + const stream = fs.createWriteStream( + join(root, path), + "utf8"); + stream.on("open", () => resolve(stream)); + stream.on("error", reject); + }); const getFolderContents = root => async path => await readdir( diff --git a/packages/server/.vscode/launch.json b/packages/server/.vscode/launch.json new file mode 100644 index 0000000000..1c6688a461 --- /dev/null +++ b/packages/server/.vscode/launch.json @@ -0,0 +1,38 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Jest All", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": ["--runInBand"], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest-cli/bin/jest", + } + }, + { + "type": "node", + "request": "launch", + "name": "Jest Current File", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": [ + "${fileBasenameNoExtension}", + "--config", + "jest.config.js" + ], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest/bin/jest", + } + } + ] +} \ No newline at end of file diff --git a/packages/server/appPackages/master/appDefinition.json b/packages/server/appPackages/master/appDefinition.json index 61a54212a8..9534589ba3 100644 --- a/packages/server/appPackages/master/appDefinition.json +++ b/packages/server/appPackages/master/appDefinition.json @@ -1 +1,423 @@ -{"hierarchy":{"name":"root","type":"root","children":[{"name":"application","type":"record","fields":[{"name":"name","type":"string","typeOptions":{"maxLength":500,"values":null,"allowDeclaredValuesOnly":false},"label":"Name","getInitialValue":"default","getUndefinedValue":"default"},{"name":"domain","type":"string","typeOptions":{"maxLength":500,"values":null,"allowDeclaredValuesOnly":false},"label":"domain","getInitialValue":"default","getUndefinedValue":"default"},{"name":"application_resolve_strategy","type":"string","typeOptions":{"maxLength":100,"values":["domain","path"],"allowDeclaredValuesOnly":true},"label":"Resolve Application By","getInitialValue":"default","getUndefinedValue":"default"}],"children":[{"name":"user","type":"record","fields":[{"name":"unique_name","type":"string","typeOptions":{"maxLength":200,"values":null,"allowDeclaredValuesOnly":false},"label":"Name (unique)","getInitialValue":"default","getUndefinedValue":"default"},{"name":"active","type":"bool","typeOptions":{"allowNulls":false},"label":"Is Active","getInitialValue":"default","getUndefinedValue":"default"},{"name":"instance","type":"reference","typeOptions":{"indexNodeKey":"/applications/1-{id}/allinstances","reverseIndexNodeKeys":["/applications/1-{id}/instances/2-{id}/users_on_this_instance"],"displayValue":"name"},"label":"Instance","getInitialValue":"default","getUndefinedValue":"default"}],"children":[],"validationRules":[],"nodeId":8,"indexes":[],"allidsShardFactor":"64","collectionName":"users","isSingle":false},{"name":"instance","type":"record","fields":[{"name":"name","type":"string","typeOptions":{"maxLength":1000,"values":null,"allowDeclaredValuesOnly":false},"label":"Name","getInitialValue":"default","getUndefinedValue":"default"},{"name":"active","type":"bool","typeOptions":{"allowNulls":false},"label":"Is Active","getInitialValue":"default","getUndefinedValue":"default"},{"name":"version","type":"reference","typeOptions":{"indexNodeKey":"/applications/1-{id}/all_versions","reverseIndexNodeKeys":["/applications/1-{id}/versions/3-{id}/instances_on_this_version"],"displayValue":"name"},"label":"Version","getInitialValue":"default","getUndefinedValue":"default"},{"name":"datastoreconfig","type":"string","typeOptions":{"maxLength":1000,"values":null,"allowDeclaredValuesOnly":false},"label":"Datastore Config","getInitialValue":"default","getUndefinedValue":"default"}],"children":[],"validationRules":[],"nodeId":2,"indexes":[{"name":"users_on_this_instance","type":"index","map":"return {...record};","filter":"","indexType":"reference","getShardName":"","getSortKey":"record.id","aggregateGroups":[],"allowedRecordNodeIds":[],"nodeId":15}],"allidsShardFactor":1,"collectionName":"instances","isSingle":false},{"name":"version","type":"record","fields":[{"name":"name","type":"string","typeOptions":{"maxLength":200,"values":null,"allowDeclaredValuesOnly":false},"label":"Name","getInitialValue":"default","getUndefinedValue":"default"}],"children":[],"validationRules":[],"nodeId":3,"indexes":[{"name":"instances_for_this_version","type":"index","map":"return {name:record.name};","filter":"","indexType":"ancestor","getShardName":"","getSortKey":"record.id","aggregateGroups":[],"allowedRecordNodeIds":[],"nodeId":9},{"name":"instances_on_this_version","type":"index","map":"return {...record};","filter":"","indexType":"reference","getShardName":"","getSortKey":"record.id","aggregateGroups":[],"allowedRecordNodeIds":[],"nodeId":10}],"allidsShardFactor":1,"collectionName":"versions","isSingle":false},{"name":"session","type":"record","fields":[{"name":"created","type":"number","typeOptions":{"minValue":0,"maxValue":99999999999999,"decimalPlaces":0},"label":"Created","getInitialValue":"default","getUndefinedValue":"default"},{"name":"user_json","type":"string","typeOptions":{"maxLength":null,"values":null,"allowDeclaredValuesOnly":false},"label":"User Json","getInitialValue":"default","getUndefinedValue":"default"},{"name":"instanceDatastoreConfig","type":"string","typeOptions":{"maxLength":null,"values":null,"allowDeclaredValuesOnly":false},"label":"Instance Datastore Config","getInitialValue":"default","getUndefinedValue":"default"},{"name":"username","type":"string","typeOptions":{"maxLength":null,"values":null,"allowDeclaredValuesOnly":false},"label":"User","getInitialValue":"default","getUndefinedValue":"default"}],"children":[],"validationRules":[],"nodeId":16,"indexes":[],"allidsShardFactor":1,"collectionName":"sessions","isSingle":false}],"validationRules":[],"nodeId":1,"indexes":[{"name":"allinstances","type":"index","map":"return {...record};","filter":"","indexType":"ancestor","getShardName":"","getSortKey":"record.id","aggregateGroups":[],"allowedRecordNodeIds":[2],"nodeId":23},{"name":"sessions_by_user","type":"index","map":"return {username:record.username};","filter":"","indexType":"ancestor","getShardName":"record.username.substring(0,2)","getSortKey":"record.id","aggregateGroups":[],"allowedRecordNodeIds":[16],"nodeId":24},{"name":"user_name_lookup","type":"index","map":"return {name:record.name, instanceDatastoreConfig:instance.datastoreconfig};","filter":"","indexType":"ancestor","getShardName":"record.name.substring(0,2)","getSortKey":"record.id","aggregateGroups":[],"allowedRecordNodeIds":[8],"nodeId":25},{"name":"all_versions","type":"index","map":"return {...record};","filter":"","indexType":"ancestor","getShardName":"","getSortKey":"record.id","aggregateGroups":[],"allowedRecordNodeIds":[3],"nodeId":26}],"allidsShardFactor":64,"collectionName":"applications","isSingle":false},{"name":"mastersession","type":"record","fields":[{"name":"user_json","type":"string","typeOptions":{"maxLength":10000,"values":null,"allowDeclaredValuesOnly":false},"label":"User Json","getInitialValue":"default","getUndefinedValue":"default"},{"name":"username","type":"string","typeOptions":{"maxLength":null,"values":null,"allowDeclaredValuesOnly":false},"label":"User","getInitialValue":"default","getUndefinedValue":"default"}],"children":[],"validationRules":[],"nodeId":17,"indexes":[],"allidsShardFactor":64,"collectionName":"sessions","isSingle":false}],"pathMaps":[],"indexes":[{"name":"mastersessions_by_user","type":"index","map":"return {...record};","filter":"","indexType":"ancestor","getShardName":"","getSortKey":"record.id","aggregateGroups":[],"allowedRecordNodeIds":[17],"nodeId":21},{"name":"all_applications","type":"index","map":"return {...record};","filter":"","indexType":"ancestor","getShardName":"","getSortKey":"record.id","aggregateGroups":[],"allowedRecordNodeIds":[1],"nodeId":22}],"nodeId":0},"actions":{},"triggers":[]} \ No newline at end of file +{ + "hierarchy": { + "name": "root", + "type": "root", + "children": [ + { + "name": "application", + "type": "record", + "fields": [ + { + "name": "name", + "type": "string", + "typeOptions": { + "maxLength": 500, + "values": null, + "allowDeclaredValuesOnly": false + }, + "label": "Name", + "getInitialValue": "default", + "getUndefinedValue": "default" + }, + { + "name": "domain", + "type": "string", + "typeOptions": { + "maxLength": 500, + "values": null, + "allowDeclaredValuesOnly": false + }, + "label": "domain", + "getInitialValue": "default", + "getUndefinedValue": "default" + }, + { + "name": "application_resolve_strategy", + "type": "string", + "typeOptions": { + "maxLength": 100, + "values": [ + "domain", + "path" + ], + "allowDeclaredValuesOnly": true + }, + "label": "Resolve Application By", + "getInitialValue": "default", + "getUndefinedValue": "default" + } + ], + "children": [ + { + "name": "user", + "type": "record", + "fields": [ + { + "name": "unique_name", + "type": "string", + "typeOptions": { + "maxLength": 200, + "values": null, + "allowDeclaredValuesOnly": false + }, + "label": "Name (unique)", + "getInitialValue": "default", + "getUndefinedValue": "default" + }, + { + "name": "active", + "type": "bool", + "typeOptions": { + "allowNulls": false + }, + "label": "Is Active", + "getInitialValue": "default", + "getUndefinedValue": "default" + }, + { + "name": "instance", + "type": "reference", + "typeOptions": { + "indexNodeKey": "/applications/1-{id}/allinstances", + "reverseIndexNodeKeys": [ + "/applications/1-{id}/instances/2-{id}/users_on_this_instance" + ], + "displayValue": "name" + }, + "label": "Instance", + "getInitialValue": "default", + "getUndefinedValue": "default" + } + ], + "children": [], + "validationRules": [], + "nodeId": 8, + "indexes": [], + "allidsShardFactor": "64", + "collectionName": "users", + "isSingle": false + }, + { + "name": "instance", + "type": "record", + "fields": [ + { + "name": "name", + "type": "string", + "typeOptions": { + "maxLength": 1000, + "values": null, + "allowDeclaredValuesOnly": false + }, + "label": "Name", + "getInitialValue": "default", + "getUndefinedValue": "default" + }, + { + "name": "active", + "type": "bool", + "typeOptions": { + "allowNulls": false + }, + "label": "Is Active", + "getInitialValue": "default", + "getUndefinedValue": "default" + }, + { + "name": "version", + "type": "reference", + "typeOptions": { + "indexNodeKey": "/applications/1-{id}/all_versions", + "reverseIndexNodeKeys": [ + "/applications/1-{id}/versions/3-{id}/instances_on_this_version" + ], + "displayValue": "name" + }, + "label": "Version", + "getInitialValue": "default", + "getUndefinedValue": "default" + }, + { + "name": "datastoreconfig", + "type": "string", + "typeOptions": { + "maxLength": 1000, + "values": null, + "allowDeclaredValuesOnly": false + }, + "label": "Datastore Config", + "getInitialValue": "default", + "getUndefinedValue": "default" + } + ], + "children": [], + "validationRules": [], + "nodeId": 2, + "indexes": [ + { + "name": "users_on_this_instance", + "type": "index", + "map": "return {...record};", + "filter": "", + "indexType": "reference", + "getShardName": "", + "getSortKey": "record.id", + "aggregateGroups": [], + "allowedRecordNodeIds": [], + "nodeId": 15 + } + ], + "allidsShardFactor": 1, + "collectionName": "instances", + "isSingle": false + }, + { + "name": "version", + "type": "record", + "fields": [ + { + "name": "name", + "type": "string", + "typeOptions": { + "maxLength": 200, + "values": null, + "allowDeclaredValuesOnly": false + }, + "label": "Name", + "getInitialValue": "default", + "getUndefinedValue": "default" + } + ], + "children": [], + "validationRules": [], + "nodeId": 3, + "indexes": [ + { + "name": "instances_for_this_version", + "type": "index", + "map": "return {name:record.name};", + "filter": "", + "indexType": "ancestor", + "getShardName": "", + "getSortKey": "record.id", + "aggregateGroups": [], + "allowedRecordNodeIds": [], + "nodeId": 9 + }, + { + "name": "instances_on_this_version", + "type": "index", + "map": "return {...record};", + "filter": "", + "indexType": "reference", + "getShardName": "", + "getSortKey": "record.id", + "aggregateGroups": [], + "allowedRecordNodeIds": [], + "nodeId": 10 + } + ], + "allidsShardFactor": 1, + "collectionName": "versions", + "isSingle": false + }, + { + "name": "session", + "type": "record", + "fields": [ + { + "name": "created", + "type": "number", + "typeOptions": { + "minValue": 0, + "maxValue": 99999999999999, + "decimalPlaces": 0 + }, + "label": "Created", + "getInitialValue": "default", + "getUndefinedValue": "default" + }, + { + "name": "user_json", + "type": "string", + "typeOptions": { + "maxLength": null, + "values": null, + "allowDeclaredValuesOnly": false + }, + "label": "User Json", + "getInitialValue": "default", + "getUndefinedValue": "default" + }, + { + "name": "instanceDatastoreConfig", + "type": "string", + "typeOptions": { + "maxLength": null, + "values": null, + "allowDeclaredValuesOnly": false + }, + "label": "Instance Datastore Config", + "getInitialValue": "default", + "getUndefinedValue": "default" + }, + { + "name": "username", + "type": "string", + "typeOptions": { + "maxLength": null, + "values": null, + "allowDeclaredValuesOnly": false + }, + "label": "User", + "getInitialValue": "default", + "getUndefinedValue": "default" + } + ], + "children": [], + "validationRules": [], + "nodeId": 16, + "indexes": [], + "allidsShardFactor": 1, + "collectionName": "sessions", + "isSingle": false + } + ], + "validationRules": [], + "nodeId": 1, + "indexes": [ + { + "name": "allinstances", + "type": "index", + "map": "return {...record};", + "filter": "", + "indexType": "ancestor", + "getShardName": "", + "getSortKey": "record.id", + "aggregateGroups": [], + "allowedRecordNodeIds": [ + 2 + ], + "nodeId": 23 + }, + { + "name": "sessions_by_user", + "type": "index", + "map": "return {username:record.username};", + "filter": "", + "indexType": "ancestor", + "getShardName": "return record.username.substring(0,2)", + "getSortKey": "record.id", + "aggregateGroups": [], + "allowedRecordNodeIds": [ + 16 + ], + "nodeId": 24 + }, + { + "name": "user_name_lookup", + "type": "index", + "map": "return {name:record.name, instanceDatastoreConfig:instance.datastoreconfig};", + "filter": "", + "indexType": "ancestor", + "getShardName": "return record.name.substring(0,2)", + "getSortKey": "record.id", + "aggregateGroups": [], + "allowedRecordNodeIds": [ + 8 + ], + "nodeId": 25 + }, + { + "name": "all_versions", + "type": "index", + "map": "return {...record};", + "filter": "", + "indexType": "ancestor", + "getShardName": "", + "getSortKey": "record.id", + "aggregateGroups": [], + "allowedRecordNodeIds": [ + 3 + ], + "nodeId": 26 + } + ], + "allidsShardFactor": 64, + "collectionName": "applications", + "isSingle": false + }, + { + "name": "mastersession", + "type": "record", + "fields": [ + { + "name": "user_json", + "type": "string", + "typeOptions": { + "maxLength": 10000, + "values": null, + "allowDeclaredValuesOnly": false + }, + "label": "User Json", + "getInitialValue": "default", + "getUndefinedValue": "default" + }, + { + "name": "username", + "type": "string", + "typeOptions": { + "maxLength": null, + "values": null, + "allowDeclaredValuesOnly": false + }, + "label": "User", + "getInitialValue": "default", + "getUndefinedValue": "default" + } + ], + "children": [], + "validationRules": [], + "nodeId": 17, + "indexes": [], + "allidsShardFactor": 64, + "collectionName": "sessions", + "isSingle": false + } + ], + "pathMaps": [], + "indexes": [ + { + "name": "all_applications", + "type": "index", + "map": "return {...record};", + "filter": "", + "indexType": "ancestor", + "getShardName": "", + "getSortKey": "record.id", + "aggregateGroups": [], + "allowedRecordNodeIds": [ + 1 + ], + "nodeId": 22 + }, + { + "name": "mastersessions_by_user", + "type": "index", + "map": "return {username:record.username};", + "filter": "", + "indexType": "ancestor", + "getShardName": "return record.username.substring(0,2)", + "getSortKey": "record.id", + "aggregateGroups": [], + "allowedRecordNodeIds": [ + 17 + ], + "nodeId": 27 + } + ], + "nodeId": 0 + }, + "actions": {}, + "triggers": [] +} \ No newline at end of file diff --git a/packages/server/tests/authenticate.js b/packages/server/tests/authenticate.js index 23320bdf48..b8e105eedd 100644 --- a/packages/server/tests/authenticate.js +++ b/packages/server/tests/authenticate.js @@ -107,6 +107,13 @@ module.exports = (app) => { }); it("should be able with re-authenticate when user is enabled again", async () => { + + await app.post("/_master/api/enableUser", { + username: testUserName + }) + .set("cookie", ownerCookie) + .expect(statusCodes.OK); + await app.post("/_master/api/authenticate", { username: testUserName, password: testPassword diff --git a/packages/server/utilities/masterAppInternal.js b/packages/server/utilities/masterAppInternal.js index 354cdb31ff..b9a2cec927 100644 --- a/packages/server/utilities/masterAppInternal.js +++ b/packages/server/utilities/masterAppInternal.js @@ -161,9 +161,8 @@ module.exports = async (config) => { const sessions = await bb.indexApi.listItems( "/mastersessions_by_user", { - rangeStartParams:{name:username}, - rangeEndParams:{name:username}, - searchPhrase:`username:${username}` + rangeStartParams:{username}, + rangeEndParams:{username} } );