From c7ad172fd04dbab5c6f230c39495599c0f83dcc8 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Fri, 13 Jul 2018 13:01:23 -0700 Subject: [PATCH 01/72] GPII-2966 In progress work for prefsSafe CRUD --- ...preferencesServer.standalone.pouchdb.json5 | 25 +++++++++ .../gpii-db-operation/src/DbDataStore.js | 43 ++++++++++++++ .../src/preferencesGetHandler.js | 56 +++++++++++++++++++ .../src/preferencesPostHandler.js | 35 +++++++++++- .../src/preferencesPutHandler.js | 15 +++++ .../src/preferencesServer.js | 31 ++++++++++ testData/dbData/views.json | 9 +++ 7 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 gpii/configs/gpii.config.preferencesServer.standalone.pouchdb.json5 diff --git a/gpii/configs/gpii.config.preferencesServer.standalone.pouchdb.json5 b/gpii/configs/gpii.config.preferencesServer.standalone.pouchdb.json5 new file mode 100644 index 000000000..8d1a911e5 --- /dev/null +++ b/gpii/configs/gpii.config.preferencesServer.standalone.pouchdb.json5 @@ -0,0 +1,25 @@ +/** + * Preferences server running standalone on the server (incl. dependencies). + * It will expect a couchDB to be running on the local host using the default port 5984. + */ +{ + "type": "gpii.config.preferencesServer.standalone.production", + "options": { + /* "dbServerPort": 5984, */ + /* "dataSourceConfigProductionEnv": { */ + /* "baseUrl": "http://localhost", //"@expand:kettle.resolvers.env(GPII_DATASOURCE_HOSTNAME)", */ + /* "port": "5984" //"@expand:kettle.resolvers.env(GPII_DATASOURCE_PORT)" */ + /* }, */ + /* "distributeOptions": { */ + /* "preferencesServer.dataStore.production": { */ + /* "source": "{that}.options.dataSourceConfigProductionEnv", */ + /* "target": "{that preferencesServer dataStore}.options.dataSourceConfig", */ + /* "priority": "after:preferencesServer.base.dataStore" */ + /* } */ + /* } */ + }, + "mergeConfigs": [ + "%preferencesServer/configs/gpii.preferencesServer.config.production.json5", + "%pouchManager/configs/gpii.pouchManager.config.base.json5" + ] +} diff --git a/gpii/node_modules/gpii-db-operation/src/DbDataStore.js b/gpii/node_modules/gpii-db-operation/src/DbDataStore.js index fc4198fd5..b66348154 100644 --- a/gpii/node_modules/gpii-db-operation/src/DbDataStore.js +++ b/gpii/node_modules/gpii-db-operation/src/DbDataStore.js @@ -97,6 +97,34 @@ fluid.defaults("gpii.dbOperation.dbDataStore", { } } }, + listPrefsSafesDataSource: { + type: "gpii.dbOperation.dbDataSource", + options: { + requestUrl: "/_design/views/_view/listPrefsSafes", + termMap: { + // gpiiKey: "%gpiiKey" + }, + rules: { + readPayload: { + "": "rows" + } + } + } + }, + listKeysForPrefsSafeDataSource: { + type: "gpii.dbOperation.dbDataSource", + options: { + requestUrl: "/_design/views/_view/listKeysForPrefsSafe?include_docs=true&key=%22%prefsSafeId%22", + termMap: { + prefsSafeId: "%prefsSafeId" + }, + rules: { + readPayload: { + "": "rows" + } + } + } + }, findPrefsSafeByGpiiKeyDataSource: { type: "gpii.dbOperation.dbDataSource", options: { @@ -111,6 +139,21 @@ fluid.defaults("gpii.dbOperation.dbDataStore", { } } }, + findPrefsSafeByNameDataSource: { + type: "gpii.dbOperation.dbDataSource", + options: { + requestUrl: "/_design/views/_view/findPrefsSafeByName?key=%22%name%22&include_docs=true", + termMap: { + name: "%name" + }, + rules: { + // TODO: Blow up if there is more than one record + readPayload: { + "": "rows.0.doc" + } + } + } + }, findClientByOauth2ClientIdDataSource: { type: "gpii.dbOperation.dbDataSource", options: { diff --git a/gpii/node_modules/preferencesServer/src/preferencesGetHandler.js b/gpii/node_modules/preferencesServer/src/preferencesGetHandler.js index de6d74302..37511bc13 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesGetHandler.js +++ b/gpii/node_modules/preferencesServer/src/preferencesGetHandler.js @@ -33,3 +33,59 @@ gpii.preferencesServer.get.handler.getPreferences = function (preferencesServer, var prefsPromise = preferencesServer.getPreferences(gpiiKey, view); prefsPromise.then(request.events.onSuccess.fire, request.events.onError.fire); }; + +fluid.defaults("gpii.preferencesServer.prefsSafeGet.handler", { + gradeNames: ["kettle.request.http"], + invokers: { + handleRequest: { + funcName: "gpii.preferencesServer.prefsSafeGet.handler.getPrefsSafe", + args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.query.view"] + } + } +}); + +gpii.preferencesServer.prefsSafeGet.handler.getPrefsSafe = function (prefsService, preferencesServer, request, gpiiKey, view) { + var prefsPromise = prefsService.dataStore.findById(gpiiKey); + prefsPromise.then(request.events.onSuccess.fire, request.events.onError.fire); +}; + +fluid.defaults("gpii.preferencesServer.prefsSafeList.handler", { + gradeNames: ["kettle.request.http"], + invokers: { + handleRequest: { + funcName: "gpii.preferencesServer.prefsSafeList.handler.getPrefsSafeList", + args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.query.view"] + } + } +}); + +gpii.preferencesServer.prefsSafeList.handler.getPrefsSafeList = function (prefsService, preferencesServer, request, view) { + var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.listPrefsSafesDataSource.options.directModel, {}); + var prefsPromise = prefsService.dataStore.listPrefsSafesDataSource.get(finalDirectModel); + prefsPromise.then(function (data) { + var togo = []; + // TODO this should probably be done in a couchview for efficiency and eventual paging? + fluid.each(data, function(item) { + item.value.prefsSafeId = item.key; + togo.push(item.value); + }); + request.events.onSuccess.fire(togo); + }, request.events.onError.fire); +}; + +fluid.defaults("gpii.preferencesServer.listKeysForPrefsSafe.handler", { + gradeNames: ["kettle.request.http"], + invokers: { + handleRequest: { + funcName: "gpii.preferencesServer.listKeysForPrefsSafe.handler.getKeysForPrefsSafe", + args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.query.view"] + } + } +}); + +gpii.preferencesServer.listKeysForPrefsSafe.handler.getKeysForPrefsSafe = function (prefsService, preferencesServer, request, prefsSafeId, view) { + var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.listKeysForPrefsSafeDataSource.options.directModel, { + prefsSafeId: prefsSafeId}); + var prefsPromise = prefsService.dataStore.listKeysForPrefsSafeDataSource.get(finalDirectModel); + prefsPromise.then(request.events.onSuccess.fire, request.events.onError.fire); +}; diff --git a/gpii/node_modules/preferencesServer/src/preferencesPostHandler.js b/gpii/node_modules/preferencesServer/src/preferencesPostHandler.js index 9e5271e42..880816a87 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesPostHandler.js +++ b/gpii/node_modules/preferencesServer/src/preferencesPostHandler.js @@ -31,5 +31,38 @@ fluid.defaults("gpii.preferencesServer.post.handler", { gpii.preferencesServer.post.handler.createPreferences = function (preferencesServer, request, preferences, view) { var prefsPromise = preferencesServer.createPreferences(preferences, view); - prefsPromise.then(request.events.onSuccess.fire, request.events.onError.fire); + prefsPromise.then(function (data) { request.events.onSuccess.fire(data); }, request.events.onError.fire); +}; + +fluid.defaults("gpii.preferencesServer.unlockCloudSafe.handler", { + gradeNames: ["kettle.request.http"], + invokers: { + handleRequest: { + funcName: "gpii.preferencesServer.unlockCloudSafe.handler.unlock", + args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.body", "{that}.req.query.view"] + } + } +}); + +/** + * takes CloudSafe Name rather than ID + * post params: + * name + * password + */ +gpii.preferencesServer.unlockCloudSafe.handler.unlock = function (prefsService, preferencesServer, request, body, view) { + var username = body.username; + var password = body.password; + var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.listPrefsSafesDataSource.options.directModel, { + name: username}); + var prom = prefsService.dataStore.findPrefsSafeByNameDataSource.get(finalDirectModel); + prom.then(function (data) { + // Let's assume it unlocked + data.id = data._id; //TODO Use our utils + var keysDirectModel = fluid.extend(true, {}, prefsService.dataStore.listPrefsSafesDataSource.options.directModel, { + prefsSafeId: data.id + }); + // var keyProm = + request.events.onSuccess.fire(data); + }); }; diff --git a/gpii/node_modules/preferencesServer/src/preferencesPutHandler.js b/gpii/node_modules/preferencesServer/src/preferencesPutHandler.js index eed849513..cbd6e8f12 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesPutHandler.js +++ b/gpii/node_modules/preferencesServer/src/preferencesPutHandler.js @@ -34,3 +34,18 @@ gpii.preferencesServer.post.handler.updatePreferences = function (preferencesSer var prefsPromise = preferencesServer.updatePreferences(gpiiKey, preferences, view, merge); prefsPromise.then(request.events.onSuccess.fire, request.events.onError.fire); }; + +fluid.defaults("gpii.preferencesServer.prefsSafePut.handler", { + gradeNames: ["kettle.request.http"], + invokers: { + handleRequest: { + funcName: "gpii.preferencesServer.prefsSafePut.handler.savePrefsSafe", + args: ["{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.body", "{that}.req.query.view",] + } + } +}); + +gpii.preferencesServer.prefsSafePut.handler.savePrefsSafe = function (preferencesServer, request, prefsSafeId, prefsSafe, view) { + var updatePrefsSafePromise = preferencesServer.dataStore.updatePrefsSafe(prefsSafeId, prefsSafeData); + updatePrefsSafePromise.then(request.events.onSuccess.fire, request.events.onError.fire); +}; diff --git a/gpii/node_modules/preferencesServer/src/preferencesServer.js b/gpii/node_modules/preferencesServer/src/preferencesServer.js index 95e1bb276..86766153f 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesServer.js +++ b/gpii/node_modules/preferencesServer/src/preferencesServer.js @@ -40,7 +40,38 @@ fluid.defaults("gpii.preferencesServer", { route: "/preferences/:gpiiKey", method: "put", type: "gpii.preferencesServer.put.handler" + }, + // GPII-2966 + prefsSafeGet: { + route: "/prefssafe/:prefsSafeId", + method: "get", + type: "gpii.preferencesServer.prefsSafeGet.handler" + }, + prefsSafeSave: { + route: "/prefssafe/:prefsSafeId", + method: "put", + type: "gpii.preferencesServer.prefsSafePut.handler" + }, + listPrefsSafes: { + route: "/prefssafes", + method: "get", + type: "gpii.preferencesServer.prefsSafeList.handler" + }, + listKeysForPrefsSafe: { + route: "/prefssafe-keys/:prefsSafeId", + method: "get", + type: "gpii.preferencesServer.listKeysForPrefsSafe.handler" + }, + unlockCloudSafe: { + route: "/unlock-cloudsafe", + method: "post", + type: "gpii.preferencesServer.unlockCloudSafe.handler" } + // prefsSafePut + // prefsSafeKeysGet + // prefsKeyGet + // prefsKeyPut + }, invokers: { getPreferences: { diff --git a/testData/dbData/views.json b/testData/dbData/views.json index 9c538651e..7021bbd82 100644 --- a/testData/dbData/views.json +++ b/testData/dbData/views.json @@ -10,6 +10,15 @@ }, "findAuthorizationByAccessToken": { "map": "function(doc) {if (doc.type === 'gpiiAppInstallationAuthorization' && doc.revoked === false) {emit(doc.accessToken, {'_id': doc.clientId, 'authorization': doc})}}" + }, + "listKeysForPrefsSafe": { + "map": "function(doc) {if (doc.type === 'gpiiKey') emit(doc.prefsSafeId, null) }" + }, + "listPrefsSafes": { + "map": "function(doc) { if (doc.type === 'prefsSafe') emit(doc._id, { 'name': doc.name, 'email': doc.email, 'created': doc.timestampCreated, 'updated': doc.timestampUpdated })}" + }, + "findPrefsSafeByName": { + "map": "function(doc) {if (doc.type === 'prefsSafe') emit(doc.name, null)}" } } } From 9cb199de785c912e8933e5cc84ed86d63c908989 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Wed, 18 Jul 2018 16:13:58 -0700 Subject: [PATCH 02/72] GPII-2966 Removing prototype safe password unlocking which will be handled by gpii-express-user going forward. --- .../src/preferencesPostHandler.js | 33 ------------------- .../src/preferencesServer.js | 10 ------ 2 files changed, 43 deletions(-) diff --git a/gpii/node_modules/preferencesServer/src/preferencesPostHandler.js b/gpii/node_modules/preferencesServer/src/preferencesPostHandler.js index 880816a87..d5a4c7d86 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesPostHandler.js +++ b/gpii/node_modules/preferencesServer/src/preferencesPostHandler.js @@ -33,36 +33,3 @@ gpii.preferencesServer.post.handler.createPreferences = function (preferencesSer var prefsPromise = preferencesServer.createPreferences(preferences, view); prefsPromise.then(function (data) { request.events.onSuccess.fire(data); }, request.events.onError.fire); }; - -fluid.defaults("gpii.preferencesServer.unlockCloudSafe.handler", { - gradeNames: ["kettle.request.http"], - invokers: { - handleRequest: { - funcName: "gpii.preferencesServer.unlockCloudSafe.handler.unlock", - args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.body", "{that}.req.query.view"] - } - } -}); - -/** - * takes CloudSafe Name rather than ID - * post params: - * name - * password - */ -gpii.preferencesServer.unlockCloudSafe.handler.unlock = function (prefsService, preferencesServer, request, body, view) { - var username = body.username; - var password = body.password; - var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.listPrefsSafesDataSource.options.directModel, { - name: username}); - var prom = prefsService.dataStore.findPrefsSafeByNameDataSource.get(finalDirectModel); - prom.then(function (data) { - // Let's assume it unlocked - data.id = data._id; //TODO Use our utils - var keysDirectModel = fluid.extend(true, {}, prefsService.dataStore.listPrefsSafesDataSource.options.directModel, { - prefsSafeId: data.id - }); - // var keyProm = - request.events.onSuccess.fire(data); - }); -}; diff --git a/gpii/node_modules/preferencesServer/src/preferencesServer.js b/gpii/node_modules/preferencesServer/src/preferencesServer.js index 1a4270428..50b2ab1dd 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesServer.js +++ b/gpii/node_modules/preferencesServer/src/preferencesServer.js @@ -61,17 +61,7 @@ fluid.defaults("gpii.preferencesServer", { route: "/prefssafe-keys/:prefsSafeId", method: "get", type: "gpii.preferencesServer.listKeysForPrefsSafe.handler" - }, - unlockCloudSafe: { - route: "/unlock-cloudsafe", - method: "post", - type: "gpii.preferencesServer.unlockCloudSafe.handler" } - // prefsSafePut - // prefsSafeKeysGet - // prefsKeyGet - // prefsKeyPut - }, invokers: { getPreferences: { From 897e41ceb29cdaa1eb6968de8175128915942929 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Thu, 19 Jul 2018 10:46:33 -0700 Subject: [PATCH 03/72] GPII-2966 Removing pouchdb prefs server config, Cindy has added an oficial one in master. --- ...preferencesServer.standalone.pouchdb.json5 | 25 ------------------- 1 file changed, 25 deletions(-) delete mode 100644 gpii/configs/gpii.config.preferencesServer.standalone.pouchdb.json5 diff --git a/gpii/configs/gpii.config.preferencesServer.standalone.pouchdb.json5 b/gpii/configs/gpii.config.preferencesServer.standalone.pouchdb.json5 deleted file mode 100644 index 8d1a911e5..000000000 --- a/gpii/configs/gpii.config.preferencesServer.standalone.pouchdb.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Preferences server running standalone on the server (incl. dependencies). - * It will expect a couchDB to be running on the local host using the default port 5984. - */ -{ - "type": "gpii.config.preferencesServer.standalone.production", - "options": { - /* "dbServerPort": 5984, */ - /* "dataSourceConfigProductionEnv": { */ - /* "baseUrl": "http://localhost", //"@expand:kettle.resolvers.env(GPII_DATASOURCE_HOSTNAME)", */ - /* "port": "5984" //"@expand:kettle.resolvers.env(GPII_DATASOURCE_PORT)" */ - /* }, */ - /* "distributeOptions": { */ - /* "preferencesServer.dataStore.production": { */ - /* "source": "{that}.options.dataSourceConfigProductionEnv", */ - /* "target": "{that preferencesServer dataStore}.options.dataSourceConfig", */ - /* "priority": "after:preferencesServer.base.dataStore" */ - /* } */ - /* } */ - }, - "mergeConfigs": [ - "%preferencesServer/configs/gpii.preferencesServer.config.production.json5", - "%pouchManager/configs/gpii.pouchManager.config.base.json5" - ] -} From 61d906f27e7a88ece0f90a8838ba7a7e0aef7c61 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Thu, 19 Jul 2018 18:52:54 -0700 Subject: [PATCH 04/72] GPII-2966 Seperating Prefs Safes endpoints from Prefs Sets Endpoints --- gpii/node_modules/preferencesServer/index.js | 1 + .../src/preferencesGetHandler.js | 56 -------- .../src/preferencesPutHandler.js | 15 -- .../src/preferencesServer.js | 5 + .../src/prefsSafesHandlers.js | 133 ++++++++++++++++++ 5 files changed, 139 insertions(+), 71 deletions(-) create mode 100644 gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js diff --git a/gpii/node_modules/preferencesServer/index.js b/gpii/node_modules/preferencesServer/index.js index 116ba63d1..5ce9612e2 100644 --- a/gpii/node_modules/preferencesServer/index.js +++ b/gpii/node_modules/preferencesServer/index.js @@ -11,3 +11,4 @@ require("./src/preferencesPutHandler.js"); require("./src/preferencesService.js"); require("./src/preferencesServerConst.js"); require("./src/preferencesServer.js"); +require("./src/prefsSafesHandlers.js"); diff --git a/gpii/node_modules/preferencesServer/src/preferencesGetHandler.js b/gpii/node_modules/preferencesServer/src/preferencesGetHandler.js index 37511bc13..de6d74302 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesGetHandler.js +++ b/gpii/node_modules/preferencesServer/src/preferencesGetHandler.js @@ -33,59 +33,3 @@ gpii.preferencesServer.get.handler.getPreferences = function (preferencesServer, var prefsPromise = preferencesServer.getPreferences(gpiiKey, view); prefsPromise.then(request.events.onSuccess.fire, request.events.onError.fire); }; - -fluid.defaults("gpii.preferencesServer.prefsSafeGet.handler", { - gradeNames: ["kettle.request.http"], - invokers: { - handleRequest: { - funcName: "gpii.preferencesServer.prefsSafeGet.handler.getPrefsSafe", - args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.query.view"] - } - } -}); - -gpii.preferencesServer.prefsSafeGet.handler.getPrefsSafe = function (prefsService, preferencesServer, request, gpiiKey, view) { - var prefsPromise = prefsService.dataStore.findById(gpiiKey); - prefsPromise.then(request.events.onSuccess.fire, request.events.onError.fire); -}; - -fluid.defaults("gpii.preferencesServer.prefsSafeList.handler", { - gradeNames: ["kettle.request.http"], - invokers: { - handleRequest: { - funcName: "gpii.preferencesServer.prefsSafeList.handler.getPrefsSafeList", - args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.query.view"] - } - } -}); - -gpii.preferencesServer.prefsSafeList.handler.getPrefsSafeList = function (prefsService, preferencesServer, request, view) { - var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.listPrefsSafesDataSource.options.directModel, {}); - var prefsPromise = prefsService.dataStore.listPrefsSafesDataSource.get(finalDirectModel); - prefsPromise.then(function (data) { - var togo = []; - // TODO this should probably be done in a couchview for efficiency and eventual paging? - fluid.each(data, function(item) { - item.value.prefsSafeId = item.key; - togo.push(item.value); - }); - request.events.onSuccess.fire(togo); - }, request.events.onError.fire); -}; - -fluid.defaults("gpii.preferencesServer.listKeysForPrefsSafe.handler", { - gradeNames: ["kettle.request.http"], - invokers: { - handleRequest: { - funcName: "gpii.preferencesServer.listKeysForPrefsSafe.handler.getKeysForPrefsSafe", - args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.query.view"] - } - } -}); - -gpii.preferencesServer.listKeysForPrefsSafe.handler.getKeysForPrefsSafe = function (prefsService, preferencesServer, request, prefsSafeId, view) { - var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.listKeysForPrefsSafeDataSource.options.directModel, { - prefsSafeId: prefsSafeId}); - var prefsPromise = prefsService.dataStore.listKeysForPrefsSafeDataSource.get(finalDirectModel); - prefsPromise.then(request.events.onSuccess.fire, request.events.onError.fire); -}; diff --git a/gpii/node_modules/preferencesServer/src/preferencesPutHandler.js b/gpii/node_modules/preferencesServer/src/preferencesPutHandler.js index cbd6e8f12..eed849513 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesPutHandler.js +++ b/gpii/node_modules/preferencesServer/src/preferencesPutHandler.js @@ -34,18 +34,3 @@ gpii.preferencesServer.post.handler.updatePreferences = function (preferencesSer var prefsPromise = preferencesServer.updatePreferences(gpiiKey, preferences, view, merge); prefsPromise.then(request.events.onSuccess.fire, request.events.onError.fire); }; - -fluid.defaults("gpii.preferencesServer.prefsSafePut.handler", { - gradeNames: ["kettle.request.http"], - invokers: { - handleRequest: { - funcName: "gpii.preferencesServer.prefsSafePut.handler.savePrefsSafe", - args: ["{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.body", "{that}.req.query.view",] - } - } -}); - -gpii.preferencesServer.prefsSafePut.handler.savePrefsSafe = function (preferencesServer, request, prefsSafeId, prefsSafe, view) { - var updatePrefsSafePromise = preferencesServer.dataStore.updatePrefsSafe(prefsSafeId, prefsSafeData); - updatePrefsSafePromise.then(request.events.onSuccess.fire, request.events.onError.fire); -}; diff --git a/gpii/node_modules/preferencesServer/src/preferencesServer.js b/gpii/node_modules/preferencesServer/src/preferencesServer.js index 50b2ab1dd..cd3df1f5a 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesServer.js +++ b/gpii/node_modules/preferencesServer/src/preferencesServer.js @@ -47,6 +47,11 @@ fluid.defaults("gpii.preferencesServer", { method: "get", type: "gpii.preferencesServer.prefsSafeGet.handler" }, + prefsSafeWithKeysGet: { + route: "/prefssafe-with-keys/:prefsSafeId", + method: "get", + type: "gpii.preferencesServer.prefsSafeWithKeysGet.handler" + }, prefsSafeSave: { route: "/prefssafe/:prefsSafeId", method: "put", diff --git a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js new file mode 100644 index 000000000..5f746bcb0 --- /dev/null +++ b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js @@ -0,0 +1,133 @@ +/*! +GPII Preferences Server GET Handler + +Copyright 2014 Raising the Floor - International +Copyright 2018 OCAD University + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +The research leading to these results has received funding from the European Union's +Seventh Framework Programme (FP7/2007-2013) under grant agreement no. 289016. + +You may obtain a copy of the License at +https://github.com/GPII/universal/blob/master/LICENSE.txt +*/ + +"use strict"; + +var fluid = require("infusion"), + gpii = fluid.registerNamespace("gpii"); + +fluid.defaults("gpii.preferencesServer.prefsSafeGet.handler", { + gradeNames: ["kettle.request.http"], + invokers: { + handleRequest: { + funcName: "gpii.preferencesServer.prefsSafeGet.handler.getPrefsSafe", + args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.query.view"] + } + } +}); + +gpii.preferencesServer.prefsSafeGet.handler.getPrefsSafe = function (prefsService, preferencesServer, request, gpiiKey, view) { + var prefsPromise = prefsService.dataStore.findById(gpiiKey); + prefsPromise.then(request.events.onSuccess.fire, request.events.onError.fire); +}; + +fluid.defaults("gpii.preferencesServer.prefsSafeList.handler", { + gradeNames: ["kettle.request.http"], + invokers: { + handleRequest: { + funcName: "gpii.preferencesServer.prefsSafeList.handler.getPrefsSafeList", + args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.query.view"] + } + } +}); + +gpii.preferencesServer.prefsSafeList.handler.getPrefsSafeList = function (prefsService, preferencesServer, request, view) { + var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.listPrefsSafesDataSource.options.directModel, {}); + var prefsPromise = prefsService.dataStore.listPrefsSafesDataSource.get(finalDirectModel); + prefsPromise.then(function (data) { + var togo = []; + // TODO this should probably be done in a couchview for efficiency and eventual paging? + fluid.each(data, function(item) { + item.value.prefsSafeId = item.key; + togo.push(item.value); + }); + request.events.onSuccess.fire(togo); + }, request.events.onError.fire); +}; + +fluid.defaults("gpii.preferencesServer.listKeysForPrefsSafe.handler", { + gradeNames: ["kettle.request.http"], + invokers: { + handleRequest: { + funcName: "gpii.preferencesServer.listKeysForPrefsSafe.handler.getKeysForPrefsSafe", + args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.query.view"] + } + } +}); + +gpii.preferencesServer.listKeysForPrefsSafe.handler.getKeysForPrefsSafe = function (prefsService, preferencesServer, request, prefsSafeId, view) { + var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.listKeysForPrefsSafeDataSource.options.directModel, { + prefsSafeId: prefsSafeId}); + var prefsPromise = prefsService.dataStore.listKeysForPrefsSafeDataSource.get(finalDirectModel); + prefsPromise.then(function (data) { + var togo = []; + fluid.each(data, function (i) { + var next = i.doc; + next.id = next._id; + delete next._id; + delete next._rev; + togo.push(next); + }); + request.events.onSuccess.fire(togo); + }, request.events.onError.fire); +}; + +fluid.defaults("gpii.preferencesServer.prefsSafeWithKeysGet.handler", { + gradeNames: ["kettle.request.http"], + invokers: { + handleRequest: { + funcName: "gpii.preferencesServer.prefsSafeWithKeysGet.handler.get", + args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.query.view"] + } + } +}); + +gpii.preferencesServer.prefsSafeWithKeysGet.handler.get = function (prefsService, preferencesServer, request, prefsSafeId, view) { + // TODO Refactor from above, copied/pasted + var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.listKeysForPrefsSafeDataSource.options.directModel, { + prefsSafeId: prefsSafeId}); + var prefsPromise = prefsService.dataStore.listKeysForPrefsSafeDataSource.get(finalDirectModel); + prefsPromise.then(function (data) { + var togo = []; + fluid.each(data, function (i) { + var next = i.doc; + next.id = next._id; + delete next._id; + delete next._rev; + togo.push(next); + }); + var prefsSafePromise = prefsService.dataStore.findById(prefsSafeId); + prefsSafePromise.then(function (prefsSafeData) { + prefsSafeData.keys = togo; + request.events.onSuccess.fire(prefsSafeData); + }, request.events.onError.fire); + }, request.events.onError.fire); +}; + +fluid.defaults("gpii.preferencesServer.prefsSafePut.handler", { + gradeNames: ["kettle.request.http"], + invokers: { + handleRequest: { + funcName: "gpii.preferencesServer.prefsSafePut.handler.savePrefsSafe", + args: ["{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.body", "{that}.req.query.view",] + } + } +}); + +gpii.preferencesServer.prefsSafePut.handler.savePrefsSafe = function (preferencesServer, request, prefsSafeId, prefsSafe, view) { + var updatePrefsSafePromise = preferencesServer.dataStore.updatePrefsSafe(prefsSafeId, prefsSafeData); + updatePrefsSafePromise.then(request.events.onSuccess.fire, request.events.onError.fire); +}; From abae292d2cf0232b06505670158be70fe136de25 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Thu, 19 Jul 2018 19:06:49 -0700 Subject: [PATCH 05/72] GPII-2966 Using dbstoreutils cleandoc function. --- .../preferencesServer/src/prefsSafesHandlers.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js index 5f746bcb0..ea37948bc 100644 --- a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js +++ b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js @@ -76,9 +76,7 @@ gpii.preferencesServer.listKeysForPrefsSafe.handler.getKeysForPrefsSafe = functi var togo = []; fluid.each(data, function (i) { var next = i.doc; - next.id = next._id; - delete next._id; - delete next._rev; + gpii.dbOperation.dbDataStore.cleanUpDoc(next); togo.push(next); }); request.events.onSuccess.fire(togo); @@ -104,9 +102,7 @@ gpii.preferencesServer.prefsSafeWithKeysGet.handler.get = function (prefsService var togo = []; fluid.each(data, function (i) { var next = i.doc; - next.id = next._id; - delete next._id; - delete next._rev; + gpii.dbOperation.dbDataStore.cleanUpDoc(next); togo.push(next); }); var prefsSafePromise = prefsService.dataStore.findById(prefsSafeId); From 49adad74f282c734a1c5b2b50e561bf4b04ec9fd Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Thu, 19 Jul 2018 19:14:46 -0700 Subject: [PATCH 06/72] GPII-2966 Removing changes from prefs post handler --- .../preferencesServer/src/preferencesPostHandler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpii/node_modules/preferencesServer/src/preferencesPostHandler.js b/gpii/node_modules/preferencesServer/src/preferencesPostHandler.js index d5a4c7d86..9e5271e42 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesPostHandler.js +++ b/gpii/node_modules/preferencesServer/src/preferencesPostHandler.js @@ -31,5 +31,5 @@ fluid.defaults("gpii.preferencesServer.post.handler", { gpii.preferencesServer.post.handler.createPreferences = function (preferencesServer, request, preferences, view) { var prefsPromise = preferencesServer.createPreferences(preferences, view); - prefsPromise.then(function (data) { request.events.onSuccess.fire(data); }, request.events.onError.fire); + prefsPromise.then(request.events.onSuccess.fire, request.events.onError.fire); }; From 56da240530fd55b102c7616d06c0959ad22d62e1 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Sun, 12 Aug 2018 16:54:43 -0700 Subject: [PATCH 07/72] GPII-2966 Code for creating keys and minor fixes for saving prefsSafes. --- .../preferencesServer/src/preferencesServer.js | 5 +++++ .../src/prefsSafesHandlers.js | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/gpii/node_modules/preferencesServer/src/preferencesServer.js b/gpii/node_modules/preferencesServer/src/preferencesServer.js index cd3df1f5a..9b6789488 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesServer.js +++ b/gpii/node_modules/preferencesServer/src/preferencesServer.js @@ -66,6 +66,11 @@ fluid.defaults("gpii.preferencesServer", { route: "/prefssafe-keys/:prefsSafeId", method: "get", type: "gpii.preferencesServer.listKeysForPrefsSafe.handler" + }, + prefsSafeKeyCreate: { + route: "/prefssafe-key-create", + method: "post", + type: "gpii.preferencesServer.prefsSafeKeyCreate.handler" } }, invokers: { diff --git a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js index ea37948bc..571846d78 100644 --- a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js +++ b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js @@ -124,6 +124,22 @@ fluid.defaults("gpii.preferencesServer.prefsSafePut.handler", { }); gpii.preferencesServer.prefsSafePut.handler.savePrefsSafe = function (preferencesServer, request, prefsSafeId, prefsSafe, view) { - var updatePrefsSafePromise = preferencesServer.dataStore.updatePrefsSafe(prefsSafeId, prefsSafeData); + var updatePrefsSafePromise = preferencesServer.dataStore.updatePrefsSafe(prefsSafeId, prefsSafe); updatePrefsSafePromise.then(request.events.onSuccess.fire, request.events.onError.fire); }; + + +fluid.defaults("gpii.preferencesServer.prefsSafeKeyCreate.handler", { + gradeNames: ["kettle.request.http"], + invokers: { + handleRequest: { + funcName: "gpii.preferencesServer.prefsSafeKeyCreate.handler", + args: ["{gpii.preferencesServer.preferencesService}.dataStore", "{that}.req.body", "{that}"] + } + } +}); + +gpii.preferencesServer.prefsSafeKeyCreate.handler = function (dataStore, body, request) { + var prom = dataStore.addGpiiKey(body); + prom.then(request.events.onSuccess.fire, request.events.onError.fire); +}; From dd187de85b776f4d0daa51f82f04139b0c330094 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Sun, 26 Aug 2018 10:17:46 -0700 Subject: [PATCH 08/72] GPII-2966 Next sprint of accounts work - Adding in unit tests - Adding in usage of gpii-express-user - Adding endpoints for creating and unlocking cloud safe credentials. --- .../gpii-db-operation/src/DbConst.js | 2 + .../gpii-db-operation/src/DbDataStore.js | 24 ++ gpii/node_modules/preferencesServer/index.js | 1 + .../src/cloudSafeCredHandlers.js | 67 ++++ .../src/preferencesServer.js | 10 + .../src/preferencesService.js | 166 ++++++++ .../src/prefsSafesHandlers.js | 36 +- .../test/cloudSafeCredTests.js | 224 +++++++++++ .../test/data/gpiiCloudSafeCred.json | 23 ++ .../test/preferencesServerTestsUtils.js | 7 +- .../preferencesServer/test/prefsSafesTests.js | 365 ++++++++++++++++++ package.json | 1 + testData/dbData/views.json | 5 +- 13 files changed, 912 insertions(+), 19 deletions(-) create mode 100644 gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js create mode 100644 gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js create mode 100644 gpii/node_modules/preferencesServer/test/data/gpiiCloudSafeCred.json create mode 100644 gpii/node_modules/preferencesServer/test/prefsSafesTests.js diff --git a/gpii/node_modules/gpii-db-operation/src/DbConst.js b/gpii/node_modules/gpii-db-operation/src/DbConst.js index d891cd021..a95f2af29 100644 --- a/gpii/node_modules/gpii-db-operation/src/DbConst.js +++ b/gpii/node_modules/gpii-db-operation/src/DbConst.js @@ -22,6 +22,8 @@ gpii.dbOperation.schemaVersion = "0.1"; // regarding accepted fields for each document type. gpii.dbOperation.docTypes = fluid.freezeRecursive({ gpiiKey: "gpiiKey", + user: "user", + gpiiCloudSafeCredential: "gpiiCloudSafeCredential", prefsSafe: "prefsSafe", clientCredential: "clientCredential", gpiiAppInstallationClient: "gpiiAppInstallationClient", diff --git a/gpii/node_modules/gpii-db-operation/src/DbDataStore.js b/gpii/node_modules/gpii-db-operation/src/DbDataStore.js index b66348154..0dd8a3ff2 100644 --- a/gpii/node_modules/gpii-db-operation/src/DbDataStore.js +++ b/gpii/node_modules/gpii-db-operation/src/DbDataStore.js @@ -97,6 +97,20 @@ fluid.defaults("gpii.dbOperation.dbDataStore", { } } }, + expressUserSafeLoginLookup: { + type: "gpii.dbOperation.dbDataSource", + options: { + requestUrl: "/_design/views/_view/expressUserSafeLoginLookup?include_docs=true&key=%22%userRecordId%22", + termMap: { + userRecordId: "%userRecordId" + }, + rules: { + readPayload: { + "": "rows.0.doc" + } + } + } + }, listPrefsSafesDataSource: { type: "gpii.dbOperation.dbDataSource", options: { @@ -228,6 +242,16 @@ fluid.defaults("gpii.dbOperation.dbDataStore", { ] // gpiiKey }, + findSafeByExpressUserLookup: { + funcName: "gpii.dbOperation.dbDataStore.findRecord", + args: [ + "{that}.expressUserSafeLoginLookup", + { + userRecordId: "{arguments}.0" + }, + "userRecordId" + ] + }, findClientByOauth2ClientId: { funcName: "gpii.dbOperation.dbDataStore.findRecord", args: [ diff --git a/gpii/node_modules/preferencesServer/index.js b/gpii/node_modules/preferencesServer/index.js index 5ce9612e2..875f7503c 100644 --- a/gpii/node_modules/preferencesServer/index.js +++ b/gpii/node_modules/preferencesServer/index.js @@ -12,3 +12,4 @@ require("./src/preferencesService.js"); require("./src/preferencesServerConst.js"); require("./src/preferencesServer.js"); require("./src/prefsSafesHandlers.js"); +require("./src/cloudSafeCredHandlers.js"); diff --git a/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js b/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js new file mode 100644 index 000000000..e95ff40e0 --- /dev/null +++ b/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js @@ -0,0 +1,67 @@ +/*! +GPII Preferences Server Cloud Safe Credentials Handler + +Copyright 2014 Raising the Floor - International +Copyright 2018 OCAD University + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +The research leading to these results has received funding from the European Union's +Seventh Framework Programme (FP7/2007-2013) under grant agreement no. 289016. + +You may obtain a copy of the License at +https://github.com/GPII/universal/blob/master/LICENSE.txt +*/ + +"use strict"; + +var fluid = require("infusion"), + gpii = fluid.registerNamespace("gpii"); + +fluid.defaults("gpii.preferencesServer.cloudSafeCredCreate.handler", { + gradeNames: ["kettle.request.http"], + invokers: { + handleRequest: { + funcName: "gpii.preferencesServer.cloudSafeCredCreate.handler.put", + args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.body"] + } + } +}); + +gpii.preferencesServer.cloudSafeCredCreate.handler.put = function (prefsService, prefsServer, request, prefsSafeId /*, body */) { + prefsService.cloudSafeCredCreate({ + // TODO pass in username/password from request + prefsSafeId: prefsSafeId + }).then(function (data) { + request.events.onSuccess.fire(data); + }); +}; + +fluid.defaults("gpii.preferencesServer.cloudSafeUnlockPost.handler", { + gradeNames: ["kettle.request.http"], + invokers: { + handleRequest: { + funcName: "gpii.preferencesServer.cloudSafeUnlockPost.handler.post", + args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.body"] + } + } +}); + +gpii.preferencesServer.cloudSafeUnlockPost.handler.post = function (prefsService, prefsServer, request, prefsSafeId, body) { + prefsService.cloudSafeUnlock({ + username: body.username, + password: body.password + }).then( + function (data) { + request.events.onSuccess.fire(data); + }, + function (/* err */) { + request.res.status(401); + request.events.onSuccess.fire({ + statusCode: 401, + message: "Unable to unlock a Preferences Safe with the supplied credentials." + }); + } + ); +}; diff --git a/gpii/node_modules/preferencesServer/src/preferencesServer.js b/gpii/node_modules/preferencesServer/src/preferencesServer.js index 9b6789488..ab5ec19fe 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesServer.js +++ b/gpii/node_modules/preferencesServer/src/preferencesServer.js @@ -71,6 +71,16 @@ fluid.defaults("gpii.preferencesServer", { route: "/prefssafe-key-create", method: "post", type: "gpii.preferencesServer.prefsSafeKeyCreate.handler" + }, + cloudSafeCredCreate: { + route: "/add-cloud-credentials/:prefsSafeId", + method: "put", + type: "gpii.preferencesServer.cloudSafeCredCreate.handler" + }, + cloudSafeUnlockPost: { + route: "/unlock-cloud-safe", + method: "post", + type: "gpii.preferencesServer.cloudSafeUnlockPost.handler" } }, invokers: { diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index c430b4b6f..5bc363485 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -12,6 +12,7 @@ https://github.com/GPII/universal/blob/master/LICENSE.txt /* eslint strict: ["error", "function"] */ var fluid = fluid || require("infusion"); +require("gpii-express-user"); (function () { "use strict"; @@ -23,6 +24,14 @@ var fluid = fluid || require("infusion"); components: { dataStore: { type: "gpii.dbOperation.dataStore" + }, + expressUserUtils: { + type: "gpii.express.user.utils", + options: { + couch: { + userDbUrl: "http://127.0.0.1:8058/gpii" + } + } } }, invokers: { @@ -41,6 +50,15 @@ var fluid = fluid || require("infusion"); funcName: "gpii.preferencesServer.preferencesService.updatePreferences", args: ["{that}", "{arguments}.0", "{arguments}.1", "{arguments}.2"] // preferences, gpiiKey, merge + }, + cloudSafeCredCreate: { + funcName: "gpii.preferencesServer.preferencesService.cloudSafeCredCreate", + args: ["{dataStore}", "{gpii.express.user.utils}", "{arguments}.0"] + // options map with keys prefsSafeId, username, password + }, + cloudSafeUnlock: { + funcName: "gpii.preferencesServer.preferencesService.cloudSafeUnlock", + args: ["{dataStore}", "{gpii.express.user.utils}", "{arguments}.0"] } }, events: { @@ -81,6 +99,154 @@ var fluid = fluid || require("infusion"); // APIs for Preferences and Preferences Safes + /** + * Handler for creating cloud safe credentials. + * + * This handler will first fetch the preferences safe to make sure it + * exists and it active. It will then take the username and password and + * create a new gpii-express-user entry. With that we will then create + * the cloudsafe credential document that will contain the ID's of both + * the prefssafe and the user record. + * + * @param {Object} dbDataStore - Instance of `gpii.dbOperation.dbDataStore`, usually + * from the `preferencesService`. + * @param {Object} userUtils - Instance of `gpii.express.user.utils`. + * @param {Object} options - Data used to create the new credentials. + * @param {Object} options.prefsSafeId - Id for the preferences safe we are adding + * credentials to. + * @param {Object} options.username - Login username for these credentials. + * @param {Object} options.password - Password for these new credentials. + * @return {Promise} Promise containing the new cloud credentials document. + */ + gpii.preferencesServer.preferencesService.cloudSafeCredCreate = function (dbDataStore, userUtils, options) { + var finalPromise = fluid.promise(); + // #1 Get the prefs Safe + var prefsSafeProm = dbDataStore.findById(options.prefsSafeId); + console.log("SGITHENS OPTS: ", options); + prefsSafeProm.then(function (data) { + console.log("SGITHENS STEP1: ", data); + + // #2 Create a new gpii-express-user + var userProm = userUtils.createNewUser({ + username: "testUsername", + email: "test@gpii.org", + password: "testPassword" + }); + + userProm.then(function (userRecord) { + console.log("SGITHENS STEP2: ", userRecord); + + // #3 Create a new type of credentials document linking the + // safe and the gpii-express-user record + var cloudCredDoc = { + type: "gpiiCloudSafeCredential", + schemaVersion: "0.1", + prefsSafeId: options.prefsSafeId, + gpiiExpressUserId: userRecord._id + }; + var cloudCredProm = gpii.dbOperation.dbDataStore.addRecord(dbDataStore.saveDataSource, + "gpiiCloudSafeCredential", "id", cloudCredDoc); + cloudCredProm.then(function (cloudCredRecord) { + console.log("SGITHENS STEP3: ", cloudCredRecord); + finalPromise.resolve(cloudCredRecord); + }, + function (err, cloudCredRecord) { + console.log("SGITHENS STEP3 ERR: ", err, cloudCredRecord); + }); + + }, + function (err, data) { + console.log("SGITHENS STEP2 ERR: ", err, data); + }); + }, + function (err, data) { + console.log("SGITHENS STEP1 ERR: ", err, data); + }); + return finalPromise; + }; + + /** + * Handler for unlocking a prefs safe. + * + * Steps: + * 1. Try to unlock a gpii-express-user acct using the username/password. + * 2. If successful, take the gpii-express-user.id and look up a cloud credentials doc for it. + * 3. Fetch the Safe for that and return it. + * + * In the future the number of couch calls may by optimized. + * + * @param {Object} dbDataStore - Instance of `gpii.dbOperation.dbDataStore`, usually + * from the `preferencesService`. + * @param {Object} userUtils - Instance of `gpii.express.user.utils`. + * @param {Object} options - Data used to unlock the safe. + * @param {Object} options.username - Username to unlock the Preferences Safe. + * @param {Object} options.password - Password to unlock the Preferences Safe. + * @return {Promise} Returns a promise containing either the unlocked Preferences Safe + * record, or an error payload with a message. + */ + gpii.preferencesServer.preferencesService.cloudSafeUnlock = function (dbDataStore, userUtils, options) { + // return fluid.promise.sequence([ + // function () { + // return userUtils.unlockUser(options.username, options.password); + // }, + // function (userRecord) { + // // Currently we're getting SGITHENS ARGUMENTS!: { '0': undefined } + // // so it looks like the first promise in the sequence isn't completing... + // console.log("SGITHENS ARGUMENTS!: ", arguments); + // return dbDataStore.findSafeByExpressUserLookup(userRecord._id); + // }, + // function (lookupData) { + // return dbDataStore.findById(lookupData.prefsSafeId); + // } + // ]); + + // #1 Try and unlock the user + var finalProm = fluid.promise(); + + var unlockProm = userUtils.unlockUser(options.username, options.password); + unlockProm.then(function (userRecord) { + console.log("UNLOCK STEP1: ", userRecord); + + var userRecordId = userRecord._id; + console.log("UNLOCK STEP1.5: ", userRecordId); + dbDataStore.findSafeByExpressUserLookup(userRecordId).then( + function (lookupData) { + console.log("UNLOCK STEP2: ", lookupData); + + var prefsSafeId = lookupData.prefsSafeId; + dbDataStore.findById(prefsSafeId).then( + function (prefsSafe) { + console.log("UNLOCK STEP3: ", prefsSafe); + finalProm.resolve(prefsSafe); + }, + function (err, data) { + console.log("UNLOCK STEP3: ERR", err, data); + finalProm.reject({ + isError: true, + message: "1. Unable to unlock a Preferences Safe with the supplied credentials." + }); + } + ); + }, + function (err, lookupData) { + console.log("UNLOCK STEP2 ERR: ", err, lookupData); + finalProm.reject({ + isError: true, + message: "2. Unable to unlock a Preferences Safe with the supplied credentials." + }); + }); + + }, + function (err) { + console.log("UNLOCK STEP1 ERR: ", err); + finalProm.reject({ + isError: true, + message: "3. Unable to unlock a Preferences Safe with the supplied credentials." + }); + }); + return finalProm; + }; + /** * Grant an authorization for the give GPII app installation. The gpii key will be verified before the access token is returned. * @param {Component} findPrefsSafeByGpiiKey - An instance of gpii.preferencesServer.preferencesService. diff --git a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js index 571846d78..5d3068917 100644 --- a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js +++ b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js @@ -24,12 +24,12 @@ fluid.defaults("gpii.preferencesServer.prefsSafeGet.handler", { invokers: { handleRequest: { funcName: "gpii.preferencesServer.prefsSafeGet.handler.getPrefsSafe", - args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.query.view"] + args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId"] } } }); -gpii.preferencesServer.prefsSafeGet.handler.getPrefsSafe = function (prefsService, preferencesServer, request, gpiiKey, view) { +gpii.preferencesServer.prefsSafeGet.handler.getPrefsSafe = function (prefsService, preferencesServer, request, gpiiKey) { var prefsPromise = prefsService.dataStore.findById(gpiiKey); prefsPromise.then(request.events.onSuccess.fire, request.events.onError.fire); }; @@ -39,18 +39,18 @@ fluid.defaults("gpii.preferencesServer.prefsSafeList.handler", { invokers: { handleRequest: { funcName: "gpii.preferencesServer.prefsSafeList.handler.getPrefsSafeList", - args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.query.view"] + args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}"] } } }); -gpii.preferencesServer.prefsSafeList.handler.getPrefsSafeList = function (prefsService, preferencesServer, request, view) { +gpii.preferencesServer.prefsSafeList.handler.getPrefsSafeList = function (prefsService, preferencesServer, request) { var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.listPrefsSafesDataSource.options.directModel, {}); var prefsPromise = prefsService.dataStore.listPrefsSafesDataSource.get(finalDirectModel); prefsPromise.then(function (data) { var togo = []; // TODO this should probably be done in a couchview for efficiency and eventual paging? - fluid.each(data, function(item) { + fluid.each(data, function (item) { item.value.prefsSafeId = item.key; togo.push(item.value); }); @@ -63,18 +63,18 @@ fluid.defaults("gpii.preferencesServer.listKeysForPrefsSafe.handler", { invokers: { handleRequest: { funcName: "gpii.preferencesServer.listKeysForPrefsSafe.handler.getKeysForPrefsSafe", - args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.query.view"] + args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId"] } } }); -gpii.preferencesServer.listKeysForPrefsSafe.handler.getKeysForPrefsSafe = function (prefsService, preferencesServer, request, prefsSafeId, view) { +gpii.preferencesServer.listKeysForPrefsSafe.handler.getKeysForPrefsSafe = function (prefsService, preferencesServer, request, prefsSafeId) { var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.listKeysForPrefsSafeDataSource.options.directModel, { prefsSafeId: prefsSafeId}); var prefsPromise = prefsService.dataStore.listKeysForPrefsSafeDataSource.get(finalDirectModel); prefsPromise.then(function (data) { var togo = []; - fluid.each(data, function (i) { + fluid.each(data, function (i) { var next = i.doc; gpii.dbOperation.dbDataStore.cleanUpDoc(next); togo.push(next); @@ -88,27 +88,29 @@ fluid.defaults("gpii.preferencesServer.prefsSafeWithKeysGet.handler", { invokers: { handleRequest: { funcName: "gpii.preferencesServer.prefsSafeWithKeysGet.handler.get", - args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.query.view"] + args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId"] } } }); -gpii.preferencesServer.prefsSafeWithKeysGet.handler.get = function (prefsService, preferencesServer, request, prefsSafeId, view) { +gpii.preferencesServer.prefsSafeWithKeysGet.handler.get = function (prefsService, preferencesServer, request, prefsSafeId) { // TODO Refactor from above, copied/pasted var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.listKeysForPrefsSafeDataSource.options.directModel, { prefsSafeId: prefsSafeId}); var prefsPromise = prefsService.dataStore.listKeysForPrefsSafeDataSource.get(finalDirectModel); prefsPromise.then(function (data) { - var togo = []; - fluid.each(data, function (i) { + var keys = []; + fluid.each(data, function (i) { var next = i.doc; gpii.dbOperation.dbDataStore.cleanUpDoc(next); - togo.push(next); + keys.push(next); }); var prefsSafePromise = prefsService.dataStore.findById(prefsSafeId); prefsSafePromise.then(function (prefsSafeData) { - prefsSafeData.keys = togo; - request.events.onSuccess.fire(prefsSafeData); + request.events.onSuccess.fire({ + prefsSafe: prefsSafeData, + keys: keys + }); }, request.events.onError.fire); }, request.events.onError.fire); }; @@ -118,12 +120,12 @@ fluid.defaults("gpii.preferencesServer.prefsSafePut.handler", { invokers: { handleRequest: { funcName: "gpii.preferencesServer.prefsSafePut.handler.savePrefsSafe", - args: ["{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.body", "{that}.req.query.view",] + args: ["{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.body"] } } }); -gpii.preferencesServer.prefsSafePut.handler.savePrefsSafe = function (preferencesServer, request, prefsSafeId, prefsSafe, view) { +gpii.preferencesServer.prefsSafePut.handler.savePrefsSafe = function (preferencesServer, request, prefsSafeId, prefsSafe) { var updatePrefsSafePromise = preferencesServer.dataStore.updatePrefsSafe(prefsSafeId, prefsSafe); updatePrefsSafePromise.then(request.events.onSuccess.fire, request.events.onError.fire); }; diff --git a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js new file mode 100644 index 000000000..b6698b333 --- /dev/null +++ b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js @@ -0,0 +1,224 @@ +/** +GPII Preferences Server Tests + +Copyright 2018 Raising the Floor - International + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +The research leading to these results has received funding from the European Union's +Seventh Framework Programme (FP7/2007-2013) under grant agreement no. 289016. + +You may obtain a copy of the License at +https://github.com/GPII/universal/blob/master/LICENSE.txt +*/ + +"use strict"; + +var fluid = require("infusion"), + jqUnit = fluid.require("node-jqunit", require, "jqUnit"), + gpii = fluid.registerNamespace("gpii"); + +require("./preferencesServerTestsUtils.js"); +require("./preferencesServerTests.js"); + +fluid.require("%gpii-universal"); +gpii.loadTestingSupport(); + +fluid.registerNamespace("gpii.tests.preferencesServer.cloudSafeCred"); + +gpii.tests.preferencesServer.config = { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" +}; + +/////////////// TEST Creating a Cloud Safe Login ///////////////// +// +// Steps 1: Send the POST to create a cloudSafeCred for an existing prefset +// Step 2: Verify that the Cloud Safe Cred Document is correct +// Step 3: Verify that the gpii-express-user document is correct +// Step 4: Verify that this is included in the list keys endpoint +// Step 5: Verify that this is included in the prefssafe with keys endpoint +fluid.registerNamespace("gpii.tests.preferencesServer.cloudSafeCred.put"); + +/* + * Make sure we got a non-error response from the original create call. + */ +gpii.tests.preferencesServer.cloudSafeCred.testCloudSafeCreatePut = function (response /*, expected, receivedStatusCode, expectedStatusCode*/) { + var data = JSON.parse(response); + jqUnit.assertEquals("Should be ok/true", data.ok, true); + jqUnit.assertNotUndefined("Should have an id", data.id); + jqUnit.assertNotUndefined("Should have a revision", data.rev); +}; + + + +/* + * Check and see if the prefs safe that came back has our new credentials doc. + */ +gpii.tests.preferencesServer.cloudSafeCred.testCloudSafeCred = function (response /*, expected, receivedStatusCode, expectedStatusCode */) { + var data = JSON.parse(response); + jqUnit.assertEquals("There should be a prefsSafe", data.prefsSafe.type, "prefsSafe"); + jqUnit.assertEquals("There should be a cloud cred", data.keys[0].type, "gpiiCloudSafeCredential"); + jqUnit.assertEquals("There should be a gpii key", data.keys[1].type, "gpiiKey"); +}; + +gpii.tests.preferencesServer.cloudSafeCred.put.buildSuccessTestDef = function (fixture) { + var expectedStatusCode = fixture.expectedStatusCode || 200; + return { + name: fixture.name, + expect: 6, + config: gpii.tests.preferencesServer.config, + components: { + putCloudCred: { + type: "kettle.test.request.http", + options: { + path: "/add-cloud-credentials/" + fixture.url, + method: "PUT", + port: 8081, + termMap: { + prefsSafeId: fixture.prefsSafeId + } + } + }, + getFullSafe: { + type: "kettle.test.request.http", + options: { + path: "/prefssafe-with-keys/" + fixture.url, + method: "GET", + port: 8081, + termMap: { + prefsSafeId: fixture.prefsSafeId + } + } + } + }, + sequence: [{ + func: "{putCloudCred}.send", + args: fixture.putCloudCredBody + }, { + event: "{putCloudCred}.events.onComplete", + listener: "gpii.tests.preferencesServer.cloudSafeCred.testCloudSafeCreatePut", + args: ["{arguments}.0", fixture.putCloudCredBodyExpected, "{putCloudCred}.nativeResponse.statusCode", expectedStatusCode] + }, { + func: "{getFullSafe}.send" + }, { + event: "{getFullSafe}.events.onComplete", + listener: "gpii.tests.preferencesServer.cloudSafeCred.testCloudSafeCred", + args: ["{arguments}.0", fixture.getCloudCredFullSafeExpected, "{getFullSafe}.nativeResponse.statusCode", expectedStatusCode] + }] + }; +}; + +gpii.tests.preferencesServer.cloudSafeCred.put.successFixtures = [ + { + name: "PUT: Add a cloudsafe credential to an existing prefssafe", + prefsSafeId: "prefsSafe-1", + url: "%prefsSafeId", + putCloudCredBodyExpected: { + + }, + getCloudCredFullSafeExpected: { + } + } +]; + +/////////////// TEST Unlocking a Prefs Safe using a Cloud Safe Login ///////////// +fluid.registerNamespace("gpii.tests.preferencesServer.cloudSafeCred.unlock"); + +gpii.tests.preferencesServer.cloudSafeCred.unlock.buildSuccessTestDef = function (fixture) { + var expectedStatusCode = fixture.expectedStatusCode || 200; + return { + name: fixture.name, + expect: 2, + config: gpii.tests.preferencesServer.config, + components: { + unlockCloudSafe: { + type: "kettle.test.request.http", + options: { + path: "/unlock-cloud-safe", + method: "POST", + port: 8081 + } + } + }, + sequence: [{ + func: "{unlockCloudSafe}.send", + args: fixture.unlockCloudSafePost + }, { + event: "{unlockCloudSafe}.events.onComplete", + listener: "gpii.tests.preferencesServer.testResponse", + args: ["{arguments}.0", fixture.unlockCloudSafeExpected, "{unlockCloudSafe}.nativeResponse.statusCode", expectedStatusCode] + }] + }; +}; + +gpii.tests.preferencesServer.cloudSafeCred.unlock.successFixtures = [ + { + name: "POST: Unlock Prefs Safe 7 using it's attached credentials", + unlockCloudSafePost: { + username: "prefs7user", + password: "testPassword" + }, + unlockCloudSafeExpected: { + "id": "prefsSafe-7", + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": null, + "password": null, + "email": null, + "preferences": { + "flat": { + "name": "bit of stuff", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/onScreenKeyboard/enabled": true + }, + "metadata": [] + } + }, + "metadata": [] + } + }, + "timestampCreated": "2017-12-14T19:55:11.641Z", + "timestampUpdated": null + } + }, + { + name: "POST: Fail to Unlock Prefs Safe 7 using bad credentials", + expectedStatusCode: 401, + unlockCloudSafePost: { + username: "prefs7user", + password: "notThePassword" + }, + unlockCloudSafeExpected: { + statusCode: 401, + message: "Unable to unlock a Preferences Safe with the supplied credentials." + } + } +]; + +/////////////// Test Aggregation and Setup below /////////////// +gpii.tests.preferencesServer.cloudSafeCred.testMap = [ { + build: gpii.tests.preferencesServer.cloudSafeCred.put.buildSuccessTestDef, + fixtures: gpii.tests.preferencesServer.cloudSafeCred.put.successFixtures +}, { + build: gpii.tests.preferencesServer.cloudSafeCred.unlock.buildSuccessTestDef, + fixtures: gpii.tests.preferencesServer.cloudSafeCred.unlock.successFixtures +}]; + +gpii.tests.preferencesServer.cloudSafeCred.testDefs = fluid.flatten(fluid.transform(gpii.tests.preferencesServer.cloudSafeCred.testMap, function (mapEl) { + return fluid.transform(mapEl.fixtures, mapEl.build, function (fixture) { + var common = { + config: gpii.tests.preferencesServer.config, + pouchTestCaseHolder: "gpii.tests.preferencesServer.pouchTestCaseHolder" + }; + + return fluid.extend({}, common, fixture); + }); +})); + +gpii.test.bootstrapServer(gpii.tests.preferencesServer.cloudSafeCred.testDefs); diff --git a/gpii/node_modules/preferencesServer/test/data/gpiiCloudSafeCred.json b/gpii/node_modules/preferencesServer/test/data/gpiiCloudSafeCred.json new file mode 100644 index 000000000..f783b24a3 --- /dev/null +++ b/gpii/node_modules/preferencesServer/test/data/gpiiCloudSafeCred.json @@ -0,0 +1,23 @@ +[ + { + "name": "prefs7user", + "type": "user", + "email": "prefs7user@gpii.org", + "roles": [], + "username": "prefs7user", + "verified": true, + "iterations": 10, + "password_scheme": "pbkdf2", + "salt": "7cf6961e6ded3bd25732e5466512d116bf9908ba9629d4ed060a03a965e5341d", + "derived_key": "e8bd265e7d82fd0f662e9ddaaf2e75acb294da1b", + "verification_code": "618fa72aa62af282704b556e34957a79", + "_id": "org.couch.db.user:prefs7user" + }, + { + "type": "gpiiCloudSafeCredential", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-7", + "gpiiExpressUserId": "org.couch.db.user:prefs7user", + "_id": "8f3085a7-b65b-4648-9a78-8ac7de766997" + } +] diff --git a/gpii/node_modules/preferencesServer/test/preferencesServerTestsUtils.js b/gpii/node_modules/preferencesServer/test/preferencesServerTestsUtils.js index c5bbe4d13..7d778b58e 100644 --- a/gpii/node_modules/preferencesServer/test/preferencesServerTestsUtils.js +++ b/gpii/node_modules/preferencesServer/test/preferencesServerTestsUtils.js @@ -45,13 +45,18 @@ gpii.tests.preferencesServer.rawGet.handler.getRawPreferences = function (prefer // The pouchTestCaseHolder for the preferences server that loads specific data files fluid.defaults("gpii.tests.preferencesServer.pouchTestCaseHolder", { gradeNames: ["gpii.test.pouch.pouchTestCaseHolder"], + mergePolicy: { + "pouchConfig.databases.gpii.data": "replace" + }, pouchConfig: { databases: { gpii: { data: [ "%preferencesServer/test/data/gpiiKeys.json", + "%preferencesServer/test/data/gpiiCloudSafeCred.json", "%preferencesServer/test/data/prefsSafes.json", - "%gpii-universal/testData/dbData/views.json" + "%gpii-universal/testData/dbData/views.json", + "%gpii-universal/node_modules/gpii-express-user/src/views/lookup.json" ] } } diff --git a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js new file mode 100644 index 000000000..5c71ab481 --- /dev/null +++ b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js @@ -0,0 +1,365 @@ +/** +GPII Preferences Server Tests + +Copyright 2018 Raising the Floor - International + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +The research leading to these results has received funding from the European Union's +Seventh Framework Programme (FP7/2007-2013) under grant agreement no. 289016. + +You may obtain a copy of the License at +https://github.com/GPII/universal/blob/master/LICENSE.txt +*/ + +"use strict"; + +var fluid = require("infusion"), + gpii = fluid.registerNamespace("gpii"); + +require("./preferencesServerTestsUtils.js"); +require("./preferencesServerTests.js"); + +fluid.require("%gpii-universal"); +gpii.loadTestingSupport(); + +fluid.registerNamespace("gpii.tests.preferencesServer.prefsSafes"); + +gpii.tests.preferencesServer.config = { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" +}; + +/////////////////////// TESTING prefsSafes GET /prefsafe/:prefsSafeId //////////////////////////// +fluid.registerNamespace("gpii.tests.preferencesServer.prefsSafes.get"); + +gpii.tests.preferencesServer.prefsSafes.get.buildTestDef = function (fixture) { + var expectedStatusCode = fixture.expectedStatusCode || 200; + return { + name: fixture.name, + expect: 2, + components: { + getRequest: { + type: "kettle.test.request.http", + options: { + path: "/prefssafe/" + fixture.url, + method: "GET", + port: 8081, + termMap: { + prefsSafeId: fixture.prefsSafeId + } + } + } + }, + sequence: [{ + func: "{getRequest}.send" + }, { + event: "{getRequest}.events.onComplete", + listener: "gpii.tests.preferencesServer.testResponse", + args: ["{arguments}.0", fixture.expected, "{getRequest}.nativeResponse.statusCode", expectedStatusCode] + }] + }; +}; + +gpii.tests.preferencesServer.prefsSafes.get.successFixtures = [ + { + name: "GET: Basic retrieval of a prefs safe", + prefsSafeId: "prefsSafe-7", + url: "%prefsSafeId", + expected: { + "id": "prefsSafe-7", + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": null, + "password": null, + "email": null, + "preferences": { + "flat": { + "name": "bit of stuff", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/onScreenKeyboard/enabled": true + }, + "metadata": [] + } + }, + "metadata": [] + } + }, + "timestampCreated": "2017-12-14T19:55:11.641Z", + "timestampUpdated": null + } + } +]; + +/////////////////////// TESTING prefsSafes with keys GET //////////////////////////// +fluid.registerNamespace("gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys"); + +gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.buildTestDef = function (fixture) { + var expectedStatusCode = fixture.expectedStatusCode || 200; + return { + name: fixture.name, + expect: 2, + components: { + getRequest: { + type: "kettle.test.request.http", + options: { + path: "/prefssafe-with-keys/" + fixture.url, + method: "GET", + port: 8081, + termMap: { + prefsSafeId: fixture.prefsSafeId + } + } + } + }, + sequence: [{ + func: "{getRequest}.send" + }, { + event: "{getRequest}.events.onComplete", + listener: "gpii.tests.preferencesServer.testResponse", + args: ["{arguments}.0", fixture.expected, "{getRequest}.nativeResponse.statusCode", expectedStatusCode] + }] + }; +}; +fluid.logObjectRenderChars = 2048; +gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.successFixtures = [ + { + name: "GET: Retieve a payload containing the prefs-safes and all it's associated key/credential records", + prefsSafeId: "prefsSafe-7", + url: "%prefsSafeId", + expected: { + prefsSafe: { + "id": "prefsSafe-7", + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": null, + "password": null, + "email": null, + "preferences": { + "flat": { + "name": "bit of stuff", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/onScreenKeyboard/enabled": true + }, + "metadata": [] + } + }, + "metadata": [] + } + }, + "timestampCreated": "2017-12-14T19:55:11.641Z", + "timestampUpdated": null + }, + keys: [ + { + "type": "gpiiCloudSafeCredential", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-7", + "gpiiExpressUserId": "org.couch.db.user:prefs7user", + "id": "8f3085a7-b65b-4648-9a78-8ac7de766997" + }, + { + "id": "np_tiny", + "type": "gpiiKey", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-7", + "prefsSetId": "gpii-default", + "revoked": false, + "revokedReason": null, + "timestampCreated": "2017-12-14T19:55:11.641Z", + "timestampUpdated": null + } + ] + } + } +]; + + + +/////////////////////// TESTING prefsSafes PUT (Save) //////////////////////////// + +/////////////////////// TESTING prefsSafes List (GET) //////////////////////////// +fluid.registerNamespace("gpii.tests.preferencesServer.prefsSafes.list"); + +gpii.tests.preferencesServer.prefsSafes.list.buildTestDef = function (fixture) { + var expectedStatusCode = fixture.expectedStatusCode || 200; + return { + name: fixture.name, + expect: 2, + components: { + getRequest: { + type: "kettle.test.request.http", + options: { + path: "/prefssafes", + method: "GET", + port: 8081 + } + } + }, + sequence: [{ + func: "{getRequest}.send" + }, { + event: "{getRequest}.events.onComplete", + listener: "gpii.tests.preferencesServer.testResponse", + args: ["{arguments}.0", fixture.expected, "{getRequest}.nativeResponse.statusCode", expectedStatusCode] + }] + }; +}; + +gpii.tests.preferencesServer.prefsSafes.list.successFixtures = [ + { + name: "GET: List Preference Safes", + // prefsSafeId: "prefsSafe-7", + // url: "%prefsSafeId", + expected: [ + { + "name": null, + "email": null, + "created": "2017-12-14T19:55:11.640Z", + "updated": null, + "prefsSafeId": "prefsSafe-1" + }, + { + "name": null, + "email": null, + "created": "2017-12-14T19:55:11.640Z", + "updated": null, + "prefsSafeId": "prefsSafe-2" + }, + { + "name": null, + "email": null, + "created": "2017-12-14T19:55:11.641Z", + "updated": null, + "prefsSafeId": "prefsSafe-3" + }, + { + "name": null, + "email": null, + "created": "2017-12-14T19:55:11.641Z", + "updated": null, + "prefsSafeId": "prefsSafe-4" + }, + { + "name": null, + "email": null, + "created": "2017-12-14T19:55:11.641Z", + "updated": null, + "prefsSafeId": "prefsSafe-5" + }, + { + "name": null, + "email": null, + "created": "2017-12-14T19:55:11.641Z", + "updated": null, + "prefsSafeId": "prefsSafe-6" + }, + { + "name": null, + "email": null, + "created": "2017-12-14T19:55:11.641Z", + "updated": null, + "prefsSafeId": "prefsSafe-7" + } + ] + } +]; + +/////////////////////// TESTING prefsSafes List Keys for Safe (GET) //////////////////////////// +fluid.registerNamespace("gpii.tests.preferencesServer.prefsSafes.listKeysForSafe"); + +gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.buildTestDef = function (fixture) { + var expectedStatusCode = fixture.expectedStatusCode || 200; + return { + name: fixture.name, + expect: 2, + components: { + getRequest: { + type: "kettle.test.request.http", + options: { + path: "/prefssafe-keys/" + fixture.url, + method: "GET", + port: 8081, + termMap: { + prefsSafeId: fixture.prefsSafeId + } + } + } + }, + sequence: [{ + func: "{getRequest}.send" + }, { + event: "{getRequest}.events.onComplete", + listener: "gpii.tests.preferencesServer.testResponse", + args: ["{arguments}.0", fixture.expected, "{getRequest}.nativeResponse.statusCode", expectedStatusCode] + }] + }; +}; + +gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.successFixtures = [ + { + name: "GET: Basic listing of keys for a prefssafe", + prefsSafeId: "prefsSafe-7", + url: "%prefsSafeId", + expected: [ + { + "type": "gpiiCloudSafeCredential", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-7", + "gpiiExpressUserId": "org.couch.db.user:prefs7user", + "id": "8f3085a7-b65b-4648-9a78-8ac7de766997" + }, + { + "id": "np_tiny", + "type": "gpiiKey", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-7", + "prefsSetId": "gpii-default", + "revoked": false, + "revokedReason": null, + "timestampCreated": "2017-12-14T19:55:11.641Z", + "timestampUpdated": null + } + ] + } +]; + +/////////////////////// TESTING prefsSafes Create (POST) //////////////////////////// + +/////////////////////// TESTING prefsSafes PUT (Save) //////////////////////////// + +gpii.tests.preferencesServer.prefsSafes.testMap = [ { + build: gpii.tests.preferencesServer.prefsSafes.get.buildTestDef, + fixtures: gpii.tests.preferencesServer.prefsSafes.get.successFixtures +}, { + build: gpii.tests.preferencesServer.prefsSafes.list.buildTestDef, + fixtures: gpii.tests.preferencesServer.prefsSafes.list.successFixtures +}, { + build: gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.buildTestDef, + fixtures: gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.successFixtures +}, { + build: gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.buildTestDef, + fixtures: gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.successFixtures +}]; + +gpii.tests.preferencesServer.prefsSafes.testDefs = fluid.flatten(fluid.transform(gpii.tests.preferencesServer.prefsSafes.testMap, function (mapEl) { + return fluid.transform(mapEl.fixtures, mapEl.build, function (fixture) { + var common = { + config: gpii.tests.preferencesServer.config, + pouchTestCaseHolder: "gpii.tests.preferencesServer.pouchTestCaseHolder" + }; + + return fluid.extend({}, common, fixture); + }); +})); + +gpii.test.bootstrapServer(gpii.tests.preferencesServer.prefsSafes.testDefs); diff --git a/package.json b/package.json index 5944c677f..713db91a1 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "glob": "7.1.2", "gpii-pouchdb": "1.0.12", "infusion": "3.0.0-dev.20180222T160835Z.6e1311a", + "gpii-express-user": "https://github.com/sgithens/gpii-express-user.git#a6014a987c03fc6674121e4348d7264ca85d2dd9", "json5": "1.0.1", "kettle": "1.7.3", "mkdirp": "0.5.1", diff --git a/testData/dbData/views.json b/testData/dbData/views.json index 7021bbd82..f02b1f5d0 100644 --- a/testData/dbData/views.json +++ b/testData/dbData/views.json @@ -12,13 +12,16 @@ "map": "function(doc) {if (doc.type === 'gpiiAppInstallationAuthorization' && doc.revoked === false) {emit(doc.accessToken, {'_id': doc.clientId, 'authorization': doc})}}" }, "listKeysForPrefsSafe": { - "map": "function(doc) {if (doc.type === 'gpiiKey') emit(doc.prefsSafeId, null) }" + "map": "function(doc) {if (doc.type === 'gpiiKey' || doc.type === 'gpiiCloudSafeCredential') emit(doc.prefsSafeId, null) }" }, "listPrefsSafes": { "map": "function(doc) { if (doc.type === 'prefsSafe') emit(doc._id, { 'name': doc.name, 'email': doc.email, 'created': doc.timestampCreated, 'updated': doc.timestampUpdated })}" }, "findPrefsSafeByName": { "map": "function(doc) {if (doc.type === 'prefsSafe') emit(doc.name, null)}" + }, + "expressUserSafeLoginLookup": { + "map": "function(doc) { if (doc.type === 'gpiiCloudSafeCredential') { emit(doc.gpiiExpressUserId, null); } }" } } } From 39160ce04d844ab5b9317577aee9246274fe07aa Mon Sep 17 00:00:00 2001 From: Cindy Qi Li Date: Thu, 2 Aug 2018 19:21:45 -0400 Subject: [PATCH 09/72] GPII-3193: Fixed the issue with saving supporting tool dictionary which is caused by the wrong merge handling on arrays. --- gpii/node_modules/preferencesServer/src/preferencesService.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index 5bc363485..73717d9fb 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -455,8 +455,9 @@ require("gpii-express-user"); }); updatePromise.reject({message: noUpdateOnSnapsetMsg}); } else { + var newPrefs = {preferences: preferences}; // The merge flag determines whether to merge the new preferences with the existing preferences - var prefsSafeData = fluid.extend(merge, {}, data.prefsSafe, {preferences: preferences}); + var prefsSafeData = merge ? fluid.extend({}, data.prefsSafe, newPrefs) : newPrefs; // Update the associated prefs safe var updatePrefsSafePromise = that.dataStore.updatePrefsSafe(prefsSafeId, prefsSafeData); var mapper = function () { From ecd08b8697146f53667b73e65ee4a73cd7ddaa2e Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Fri, 31 Aug 2018 10:20:35 -0700 Subject: [PATCH 10/72] GPII-2966 GPII-3193 Temporary removing the patch needed for QSS save to pass unit tests. --- .../preferencesServer/src/preferencesService.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index 73717d9fb..a7c152668 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -455,9 +455,14 @@ require("gpii-express-user"); }); updatePromise.reject({message: noUpdateOnSnapsetMsg}); } else { - var newPrefs = {preferences: preferences}; + // SGITHENS var newPrefs = {preferences: preferences}; + // The temporary patch Cindy had for the audit demo, GPII-3193 commit 39160ce04d844ab5b9317577aee9246274fe07aa + // causes the current unit tests to fail. + // END + // The merge flag determines whether to merge the new preferences with the existing preferences - var prefsSafeData = merge ? fluid.extend({}, data.prefsSafe, newPrefs) : newPrefs; + var prefsSafeData = fluid.extend(merge, {}, data.prefsSafe, {preferences: preferences}); + // SGITHENS var prefsSafeData = merge ? fluid.extend({}, data.prefsSafe, newPrefs) : newPrefs; // Update the associated prefs safe var updatePrefsSafePromise = that.dataStore.updatePrefsSafe(prefsSafeId, prefsSafeData); var mapper = function () { From d3c5caf1e99d596bb6441db80ff4b6f034cca471 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Fri, 31 Aug 2018 10:46:52 -0700 Subject: [PATCH 11/72] GPII-2966 Rename listKeysForPrefsSafe - Rename listKeysForPrefsSafe to findKeysForPrefsSafe per review --- .../gpii-db-operation/src/DbDataStore.js | 4 ++-- .../preferencesServer/src/preferencesServer.js | 4 ++-- .../preferencesServer/src/prefsSafesHandlers.js | 14 +++++++------- testData/dbData/views.json | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gpii/node_modules/gpii-db-operation/src/DbDataStore.js b/gpii/node_modules/gpii-db-operation/src/DbDataStore.js index 0dd8a3ff2..4685c80a4 100644 --- a/gpii/node_modules/gpii-db-operation/src/DbDataStore.js +++ b/gpii/node_modules/gpii-db-operation/src/DbDataStore.js @@ -125,10 +125,10 @@ fluid.defaults("gpii.dbOperation.dbDataStore", { } } }, - listKeysForPrefsSafeDataSource: { + findKeysForPrefsSafeDataSource: { type: "gpii.dbOperation.dbDataSource", options: { - requestUrl: "/_design/views/_view/listKeysForPrefsSafe?include_docs=true&key=%22%prefsSafeId%22", + requestUrl: "/_design/views/_view/findKeysForPrefsSafe?include_docs=true&key=%22%prefsSafeId%22", termMap: { prefsSafeId: "%prefsSafeId" }, diff --git a/gpii/node_modules/preferencesServer/src/preferencesServer.js b/gpii/node_modules/preferencesServer/src/preferencesServer.js index ab5ec19fe..cf1f185f3 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesServer.js +++ b/gpii/node_modules/preferencesServer/src/preferencesServer.js @@ -62,10 +62,10 @@ fluid.defaults("gpii.preferencesServer", { method: "get", type: "gpii.preferencesServer.prefsSafeList.handler" }, - listKeysForPrefsSafe: { + findKeysForPrefsSafe: { route: "/prefssafe-keys/:prefsSafeId", method: "get", - type: "gpii.preferencesServer.listKeysForPrefsSafe.handler" + type: "gpii.preferencesServer.findKeysForPrefsSafe.handler" }, prefsSafeKeyCreate: { route: "/prefssafe-key-create", diff --git a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js index 5d3068917..35519c318 100644 --- a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js +++ b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js @@ -58,20 +58,20 @@ gpii.preferencesServer.prefsSafeList.handler.getPrefsSafeList = function (prefsS }, request.events.onError.fire); }; -fluid.defaults("gpii.preferencesServer.listKeysForPrefsSafe.handler", { +fluid.defaults("gpii.preferencesServer.findKeysForPrefsSafe.handler", { gradeNames: ["kettle.request.http"], invokers: { handleRequest: { - funcName: "gpii.preferencesServer.listKeysForPrefsSafe.handler.getKeysForPrefsSafe", + funcName: "gpii.preferencesServer.findKeysForPrefsSafe.handler.getKeysForPrefsSafe", args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId"] } } }); -gpii.preferencesServer.listKeysForPrefsSafe.handler.getKeysForPrefsSafe = function (prefsService, preferencesServer, request, prefsSafeId) { - var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.listKeysForPrefsSafeDataSource.options.directModel, { +gpii.preferencesServer.findKeysForPrefsSafe.handler.getKeysForPrefsSafe = function (prefsService, preferencesServer, request, prefsSafeId) { + var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.findKeysForPrefsSafeDataSource.options.directModel, { prefsSafeId: prefsSafeId}); - var prefsPromise = prefsService.dataStore.listKeysForPrefsSafeDataSource.get(finalDirectModel); + var prefsPromise = prefsService.dataStore.findKeysForPrefsSafeDataSource.get(finalDirectModel); prefsPromise.then(function (data) { var togo = []; fluid.each(data, function (i) { @@ -95,9 +95,9 @@ fluid.defaults("gpii.preferencesServer.prefsSafeWithKeysGet.handler", { gpii.preferencesServer.prefsSafeWithKeysGet.handler.get = function (prefsService, preferencesServer, request, prefsSafeId) { // TODO Refactor from above, copied/pasted - var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.listKeysForPrefsSafeDataSource.options.directModel, { + var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.findKeysForPrefsSafeDataSource.options.directModel, { prefsSafeId: prefsSafeId}); - var prefsPromise = prefsService.dataStore.listKeysForPrefsSafeDataSource.get(finalDirectModel); + var prefsPromise = prefsService.dataStore.findKeysForPrefsSafeDataSource.get(finalDirectModel); prefsPromise.then(function (data) { var keys = []; fluid.each(data, function (i) { diff --git a/testData/dbData/views.json b/testData/dbData/views.json index f02b1f5d0..9a2f3d9b6 100644 --- a/testData/dbData/views.json +++ b/testData/dbData/views.json @@ -11,7 +11,7 @@ "findAuthorizationByAccessToken": { "map": "function(doc) {if (doc.type === 'gpiiAppInstallationAuthorization' && doc.revoked === false) {emit(doc.accessToken, {'_id': doc.clientId, 'authorization': doc})}}" }, - "listKeysForPrefsSafe": { + "findKeysForPrefsSafe": { "map": "function(doc) {if (doc.type === 'gpiiKey' || doc.type === 'gpiiCloudSafeCredential') emit(doc.prefsSafeId, null) }" }, "listPrefsSafes": { From b1c3693effc0cfa4357164de8a3c17821b84cfb1 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Fri, 31 Aug 2018 10:56:53 -0700 Subject: [PATCH 12/72] GPII-2966 Removing extra white space --- testData/dbData/views.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testData/dbData/views.json b/testData/dbData/views.json index 9a2f3d9b6..2ddc2005f 100644 --- a/testData/dbData/views.json +++ b/testData/dbData/views.json @@ -12,16 +12,16 @@ "map": "function(doc) {if (doc.type === 'gpiiAppInstallationAuthorization' && doc.revoked === false) {emit(doc.accessToken, {'_id': doc.clientId, 'authorization': doc})}}" }, "findKeysForPrefsSafe": { - "map": "function(doc) {if (doc.type === 'gpiiKey' || doc.type === 'gpiiCloudSafeCredential') emit(doc.prefsSafeId, null) }" + "map": "function(doc) {if (doc.type === 'gpiiKey' || doc.type === 'gpiiCloudSafeCredential') emit(doc.prefsSafeId, null)}" }, "listPrefsSafes": { - "map": "function(doc) { if (doc.type === 'prefsSafe') emit(doc._id, { 'name': doc.name, 'email': doc.email, 'created': doc.timestampCreated, 'updated': doc.timestampUpdated })}" + "map": "function(doc) {if (doc.type === 'prefsSafe') emit(doc._id, {'name': doc.name, 'email': doc.email, 'created': doc.timestampCreated, 'updated': doc.timestampUpdated})}" }, "findPrefsSafeByName": { "map": "function(doc) {if (doc.type === 'prefsSafe') emit(doc.name, null)}" }, "expressUserSafeLoginLookup": { - "map": "function(doc) { if (doc.type === 'gpiiCloudSafeCredential') { emit(doc.gpiiExpressUserId, null); } }" + "map": "function(doc) {if (doc.type === 'gpiiCloudSafeCredential') {emit(doc.gpiiExpressUserId, null);}}" } } } From fbe91e46620da4a595aae460456186fd3491913f Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Tue, 18 Sep 2018 11:42:22 -0700 Subject: [PATCH 13/72] GPII-2966 Cleanup based on PR Review --- .../gpii-db-operation/src/DbDataStore.js | 20 ++- .../gpii-db-operation/src/DbDataStoreUtils.js | 50 ++++++++ .../src/preferencesService.js | 9 +- .../src/prefsSafesHandlers.js | 51 ++------ .../preferencesServer/test/prefsSafesTests.js | 118 ++++++++++-------- 5 files changed, 146 insertions(+), 102 deletions(-) diff --git a/gpii/node_modules/gpii-db-operation/src/DbDataStore.js b/gpii/node_modules/gpii-db-operation/src/DbDataStore.js index 4685c80a4..31a59b5ab 100644 --- a/gpii/node_modules/gpii-db-operation/src/DbDataStore.js +++ b/gpii/node_modules/gpii-db-operation/src/DbDataStore.js @@ -120,7 +120,7 @@ fluid.defaults("gpii.dbOperation.dbDataStore", { }, rules: { readPayload: { - "": "rows" + "": "" } } } @@ -134,7 +134,7 @@ fluid.defaults("gpii.dbOperation.dbDataStore", { }, rules: { readPayload: { - "": "rows" + "": "" } } } @@ -218,6 +218,22 @@ fluid.defaults("gpii.dbOperation.dbDataStore", { ] // id }, + findPrefsSafeList: { + funcName: "gpii.dbOperation.dbDataStore.findRecordList", + args: [ + "{that}.listPrefsSafesDataSource", + {} + ] + }, + findKeysForPrefsSafe: { + funcName: "gpii.dbOperation.dbDataStore.findRecordList", + args: [ + "{that}.findKeysForPrefsSafeDataSource", + { + prefsSafeId: "{arguments}.0" + } + ] + }, findGpiiKey: { func: "{that}.findById" // gpiiKey diff --git a/gpii/node_modules/gpii-db-operation/src/DbDataStoreUtils.js b/gpii/node_modules/gpii-db-operation/src/DbDataStoreUtils.js index 8cd3e9220..0e13122cc 100644 --- a/gpii/node_modules/gpii-db-operation/src/DbDataStoreUtils.js +++ b/gpii/node_modules/gpii-db-operation/src/DbDataStoreUtils.js @@ -74,6 +74,37 @@ gpii.dbOperation.dbDataStore.findRecord = function (dataSource, directModel, val return promiseTogo; }; +/** + * Similar to `gpii.dbOperation.dbDataStore.findRecord` but for CouchDB dataSources meant to return + * a list of records. + * + * Eventually this method, and the related CouchDB dataSources will take a standard set of options + * for paging and sorting. Because the dataProcessFunc can be operating on each record, ideally this + * should always return a reasonable amount of records you'd want to display say, on a page. + * + * @param {Component} dataSource - An instance of gpii.dbOperation.dbDataSource. + * @param {Object} directModel - The direct model expressing the "coordinates" of the model to be fetched. + * @param {Function} dataProcessFunc - The function to further process the retrieved record when the returned + * record is not empty. + * @return {Promise} A promise for the retrieved record. + */ +gpii.dbOperation.dbDataStore.findRecordList = function (dataSource, directModel, dataProcessFunc) { + dataProcessFunc = dataProcessFunc || gpii.dbOperation.dbDataStore.cleanUpDocList; + var promiseTogo = fluid.promise(); + + var finalDirectModel = fluid.extend(true, {}, dataSource.options.directModel, directModel); + var promise = dataSource.get(finalDirectModel); + promise.then(function (data) { + dataProcessFunc(data); + promiseTogo.resolve(data); + }, function (error) { + fluid.log("gpii-db-operation, findRecordList(), error occurs: ", error); + promiseTogo.reject(error); + }); + + return promiseTogo; +}; + /** * Filter the given array valueNotEmpty to return elements that satisfy: * 1. the element isn't used as a path name in the object; @@ -113,6 +144,25 @@ gpii.dbOperation.dbDataStore.cleanUpDoc = function (data) { return data; }; +gpii.dbOperation.dbDataStore.cleanUpDocList = function (data) { + if (data.rows) { + fluid.each(data.rows, function (item, idx) { + var toProcess; + if (item.value && item.value !== null) { + toProcess = item.value; + } + else if (item.doc) { + toProcess = item.doc; + } + toProcess.id = item.id; + delete toProcess._id; + delete toProcess._rev; + data.rows[idx] = toProcess; + }); + } + return data; +}; + /** Use the kettle dataSource `set` method to create a new record. Before sending the input data to * CouchDB/PouchDB, it is modified by adding an unique _id field and a proper document type. * @param {Component} dataSource - An instance of gpii.dbOperation.dbDataSource that handles the record creation. diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index a7c152668..f00bb519e 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -35,7 +35,14 @@ require("gpii-express-user"); } }, invokers: { + // TODO check type == prefsSafe + getPrefsSafe: "{dataStore}.findById", + getPrefsSafeList: { + func: "{dataStore}.findPrefsSafeList", + args: ["{arguments}.0"] + }, getPrefsSafeByGpiiKey: "{dataStore}.findPrefsSafeByGpiiKey", + getKeysForPrefsSafe: "{dataStore}.findKeysForPrefsSafe", getPreferencesByGpiiKey: { funcName: "gpii.preferencesServer.preferencesService.getPreferencesByGpiiKey", args: ["{dataStore}.findPrefsSafeByGpiiKey", "{arguments}.0"] @@ -97,8 +104,6 @@ require("gpii-express-user"); noUpdateOnSnapset: "Cannot update: GPII key \"%gpiiKey\" is a snapset" }); - // APIs for Preferences and Preferences Safes - /** * Handler for creating cloud safe credentials. * diff --git a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js index 35519c318..294cf4b97 100644 --- a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js +++ b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js @@ -30,8 +30,7 @@ fluid.defaults("gpii.preferencesServer.prefsSafeGet.handler", { }); gpii.preferencesServer.prefsSafeGet.handler.getPrefsSafe = function (prefsService, preferencesServer, request, gpiiKey) { - var prefsPromise = prefsService.dataStore.findById(gpiiKey); - prefsPromise.then(request.events.onSuccess.fire, request.events.onError.fire); + prefsService.getPrefsSafe(gpiiKey).then(request.events.onSuccess.fire, request.events.onError.fire); }; fluid.defaults("gpii.preferencesServer.prefsSafeList.handler", { @@ -45,17 +44,7 @@ fluid.defaults("gpii.preferencesServer.prefsSafeList.handler", { }); gpii.preferencesServer.prefsSafeList.handler.getPrefsSafeList = function (prefsService, preferencesServer, request) { - var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.listPrefsSafesDataSource.options.directModel, {}); - var prefsPromise = prefsService.dataStore.listPrefsSafesDataSource.get(finalDirectModel); - prefsPromise.then(function (data) { - var togo = []; - // TODO this should probably be done in a couchview for efficiency and eventual paging? - fluid.each(data, function (item) { - item.value.prefsSafeId = item.key; - togo.push(item.value); - }); - request.events.onSuccess.fire(togo); - }, request.events.onError.fire); + prefsService.getPrefsSafeList().then(request.events.onSuccess.fire, request.events.onError.fire); }; fluid.defaults("gpii.preferencesServer.findKeysForPrefsSafe.handler", { @@ -69,18 +58,7 @@ fluid.defaults("gpii.preferencesServer.findKeysForPrefsSafe.handler", { }); gpii.preferencesServer.findKeysForPrefsSafe.handler.getKeysForPrefsSafe = function (prefsService, preferencesServer, request, prefsSafeId) { - var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.findKeysForPrefsSafeDataSource.options.directModel, { - prefsSafeId: prefsSafeId}); - var prefsPromise = prefsService.dataStore.findKeysForPrefsSafeDataSource.get(finalDirectModel); - prefsPromise.then(function (data) { - var togo = []; - fluid.each(data, function (i) { - var next = i.doc; - gpii.dbOperation.dbDataStore.cleanUpDoc(next); - togo.push(next); - }); - request.events.onSuccess.fire(togo); - }, request.events.onError.fire); + prefsService.getKeysForPrefsSafe(prefsSafeId).then(request.events.onSuccess.fire, request.events.onError.fire); }; fluid.defaults("gpii.preferencesServer.prefsSafeWithKeysGet.handler", { @@ -94,22 +72,11 @@ fluid.defaults("gpii.preferencesServer.prefsSafeWithKeysGet.handler", { }); gpii.preferencesServer.prefsSafeWithKeysGet.handler.get = function (prefsService, preferencesServer, request, prefsSafeId) { - // TODO Refactor from above, copied/pasted - var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.findKeysForPrefsSafeDataSource.options.directModel, { - prefsSafeId: prefsSafeId}); - var prefsPromise = prefsService.dataStore.findKeysForPrefsSafeDataSource.get(finalDirectModel); - prefsPromise.then(function (data) { - var keys = []; - fluid.each(data, function (i) { - var next = i.doc; - gpii.dbOperation.dbDataStore.cleanUpDoc(next); - keys.push(next); - }); - var prefsSafePromise = prefsService.dataStore.findById(prefsSafeId); - prefsSafePromise.then(function (prefsSafeData) { + prefsService.getKeysForPrefsSafe(prefsSafeId).then(function (data) { + prefsService.dataStore.findById(prefsSafeId).then(function (prefsSafeData) { request.events.onSuccess.fire({ prefsSafe: prefsSafeData, - keys: keys + keys: data.rows }); }, request.events.onError.fire); }, request.events.onError.fire); @@ -126,8 +93,7 @@ fluid.defaults("gpii.preferencesServer.prefsSafePut.handler", { }); gpii.preferencesServer.prefsSafePut.handler.savePrefsSafe = function (preferencesServer, request, prefsSafeId, prefsSafe) { - var updatePrefsSafePromise = preferencesServer.dataStore.updatePrefsSafe(prefsSafeId, prefsSafe); - updatePrefsSafePromise.then(request.events.onSuccess.fire, request.events.onError.fire); + preferencesServer.dataStore.updatePrefsSafe(prefsSafeId, prefsSafe).then(request.events.onSuccess.fire, request.events.onError.fire); }; @@ -142,6 +108,5 @@ fluid.defaults("gpii.preferencesServer.prefsSafeKeyCreate.handler", { }); gpii.preferencesServer.prefsSafeKeyCreate.handler = function (dataStore, body, request) { - var prom = dataStore.addGpiiKey(body); - prom.then(request.events.onSuccess.fire, request.events.onError.fire); + dataStore.addGpiiKey(body).then(request.events.onSuccess.fire, request.events.onError.fire); }; diff --git a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js index 5c71ab481..277f002b8 100644 --- a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js +++ b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js @@ -220,57 +220,61 @@ gpii.tests.preferencesServer.prefsSafes.list.successFixtures = [ name: "GET: List Preference Safes", // prefsSafeId: "prefsSafe-7", // url: "%prefsSafeId", - expected: [ - { - "name": null, - "email": null, - "created": "2017-12-14T19:55:11.640Z", - "updated": null, - "prefsSafeId": "prefsSafe-1" - }, - { - "name": null, - "email": null, - "created": "2017-12-14T19:55:11.640Z", - "updated": null, - "prefsSafeId": "prefsSafe-2" - }, - { - "name": null, - "email": null, - "created": "2017-12-14T19:55:11.641Z", - "updated": null, - "prefsSafeId": "prefsSafe-3" - }, - { - "name": null, - "email": null, - "created": "2017-12-14T19:55:11.641Z", - "updated": null, - "prefsSafeId": "prefsSafe-4" - }, - { - "name": null, - "email": null, - "created": "2017-12-14T19:55:11.641Z", - "updated": null, - "prefsSafeId": "prefsSafe-5" - }, - { - "name": null, - "email": null, - "created": "2017-12-14T19:55:11.641Z", - "updated": null, - "prefsSafeId": "prefsSafe-6" - }, - { - "name": null, - "email": null, - "created": "2017-12-14T19:55:11.641Z", - "updated": null, - "prefsSafeId": "prefsSafe-7" - } - ] + expected: { + total_rows: 7, + offset: 0, + rows: [ + { + "name": null, + "email": null, + "created": "2017-12-14T19:55:11.640Z", + "updated": null, + "id": "prefsSafe-1" + }, + { + "name": null, + "email": null, + "created": "2017-12-14T19:55:11.640Z", + "updated": null, + "id": "prefsSafe-2" + }, + { + "name": null, + "email": null, + "created": "2017-12-14T19:55:11.641Z", + "updated": null, + "id": "prefsSafe-3" + }, + { + "name": null, + "email": null, + "created": "2017-12-14T19:55:11.641Z", + "updated": null, + "id": "prefsSafe-4" + }, + { + "name": null, + "email": null, + "created": "2017-12-14T19:55:11.641Z", + "updated": null, + "id": "prefsSafe-5" + }, + { + "name": null, + "email": null, + "created": "2017-12-14T19:55:11.641Z", + "updated": null, + "id": "prefsSafe-6" + }, + { + "name": null, + "email": null, + "created": "2017-12-14T19:55:11.641Z", + "updated": null, + "id": "prefsSafe-7" + } + ] + } } ]; @@ -310,8 +314,12 @@ gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.successFixtures = [ name: "GET: Basic listing of keys for a prefssafe", prefsSafeId: "prefsSafe-7", url: "%prefsSafeId", - expected: [ - { + expected: { + // TODO sgithens, this CouchDB query needs to be fixed so that the total_rows + // is the actual number returned from the query, in this case 2 + "total_rows": 9, + "offset": 0, + rows: [{ "type": "gpiiCloudSafeCredential", "schemaVersion": "0.1", "prefsSafeId": "prefsSafe-7", @@ -328,8 +336,8 @@ gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.successFixtures = [ "revokedReason": null, "timestampCreated": "2017-12-14T19:55:11.641Z", "timestampUpdated": null - } - ] + }] + } } ]; From db02d36978f9c41915bcd73f200b6ac231356e84 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Wed, 19 Sep 2018 12:46:36 -0700 Subject: [PATCH 14/72] GPII-2966 Clean up and safe creation work - More cleanup from PR review - Fixed passing in username/password on safe credentials creation --- .../gpii-db-operation/src/DbConst.js | 2 +- .../gpii-db-operation/src/DbDataStoreUtils.js | 14 ++++ .../src/cloudSafeCredHandlers.js | 8 +- .../src/preferencesService.js | 7 +- .../test/cloudSafeCredTests.js | 84 ++++++++++++++++++- 5 files changed, 104 insertions(+), 11 deletions(-) diff --git a/gpii/node_modules/gpii-db-operation/src/DbConst.js b/gpii/node_modules/gpii-db-operation/src/DbConst.js index a95f2af29..9cd3c674c 100644 --- a/gpii/node_modules/gpii-db-operation/src/DbConst.js +++ b/gpii/node_modules/gpii-db-operation/src/DbConst.js @@ -22,7 +22,7 @@ gpii.dbOperation.schemaVersion = "0.1"; // regarding accepted fields for each document type. gpii.dbOperation.docTypes = fluid.freezeRecursive({ gpiiKey: "gpiiKey", - user: "user", + user: "user", // This is the CouchDB compatible record type gpii-express-user creates gpiiCloudSafeCredential: "gpiiCloudSafeCredential", prefsSafe: "prefsSafe", clientCredential: "clientCredential", diff --git a/gpii/node_modules/gpii-db-operation/src/DbDataStoreUtils.js b/gpii/node_modules/gpii-db-operation/src/DbDataStoreUtils.js index 0e13122cc..c6116f5a3 100644 --- a/gpii/node_modules/gpii-db-operation/src/DbDataStoreUtils.js +++ b/gpii/node_modules/gpii-db-operation/src/DbDataStoreUtils.js @@ -144,6 +144,17 @@ gpii.dbOperation.dbDataStore.cleanUpDoc = function (data) { return data; }; +/** + * Modifies a list of records from CouchDB, such that the rows entry will now + * contain a list of the regular documents, rather than a key/id/doc entry. + * This will look for both options from a view, using first the `value` entry + * if it's available, and then checking for the `doc` entry on each item. The + * `doc` is what is available when your map view emits a `null` reference but + * the query is run to retrieve the document references. + * + * @param {Object} data - A CouchDB record list to transform. + * @return {Object} An object with CouchDB/PouchDB specific internal fields being transformed. + */ gpii.dbOperation.dbDataStore.cleanUpDocList = function (data) { if (data.rows) { fluid.each(data.rows, function (item, idx) { @@ -154,6 +165,9 @@ gpii.dbOperation.dbDataStore.cleanUpDocList = function (data) { else if (item.doc) { toProcess = item.doc; } + else { + fluid.fail("Missing both the value or doc for record: ", item.key); + } toProcess.id = item.id; delete toProcess._id; delete toProcess._rev; diff --git a/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js b/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js index e95ff40e0..2b0454487 100644 --- a/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js +++ b/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js @@ -24,15 +24,17 @@ fluid.defaults("gpii.preferencesServer.cloudSafeCredCreate.handler", { invokers: { handleRequest: { funcName: "gpii.preferencesServer.cloudSafeCredCreate.handler.put", - args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.body"] + args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params", "{that}.req.body"] } } }); -gpii.preferencesServer.cloudSafeCredCreate.handler.put = function (prefsService, prefsServer, request, prefsSafeId /*, body */) { +gpii.preferencesServer.cloudSafeCredCreate.handler.put = function (prefsService, prefsServer, request, params, body) { prefsService.cloudSafeCredCreate({ // TODO pass in username/password from request - prefsSafeId: prefsSafeId + prefsSafeId: params.prefsSafeId, + username: body.username, + password: body.password }).then(function (data) { request.events.onSuccess.fire(data); }); diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index f00bb519e..faf0cf552 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -133,9 +133,10 @@ require("gpii-express-user"); // #2 Create a new gpii-express-user var userProm = userUtils.createNewUser({ - username: "testUsername", - email: "test@gpii.org", - password: "testPassword" + username: options.username, + // TODO, if this password string isn't recreated, gpii-express-user errors out + // during it's hashing/encryption functions saying that it must be a Buffer + password: options.password + "" }); userProm.then(function (userRecord) { diff --git a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js index b6698b333..f6215316d 100644 --- a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js +++ b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js @@ -44,15 +44,13 @@ fluid.registerNamespace("gpii.tests.preferencesServer.cloudSafeCred.put"); /* * Make sure we got a non-error response from the original create call. */ -gpii.tests.preferencesServer.cloudSafeCred.testCloudSafeCreatePut = function (response /*, expected, receivedStatusCode, expectedStatusCode*/) { +gpii.tests.preferencesServer.cloudSafeCred.testCloudSafeCreatePut = function (response /*, expected, receivedStatusCode, expectedStatusCode */) { var data = JSON.parse(response); jqUnit.assertEquals("Should be ok/true", data.ok, true); jqUnit.assertNotUndefined("Should have an id", data.id); jqUnit.assertNotUndefined("Should have a revision", data.rev); }; - - /* * Check and see if the prefs safe that came back has our new credentials doc. */ @@ -67,7 +65,7 @@ gpii.tests.preferencesServer.cloudSafeCred.put.buildSuccessTestDef = function (f var expectedStatusCode = fixture.expectedStatusCode || 200; return { name: fixture.name, - expect: 6, + expect: 8, config: gpii.tests.preferencesServer.config, components: { putCloudCred: { @@ -91,6 +89,14 @@ gpii.tests.preferencesServer.cloudSafeCred.put.buildSuccessTestDef = function (f prefsSafeId: fixture.prefsSafeId } } + }, + unlockCloudSafe: { + type: "kettle.test.request.http", + options: { + path: "/unlock-cloud-safe", + method: "POST", + port: 8081 + } } }, sequence: [{ @@ -106,6 +112,13 @@ gpii.tests.preferencesServer.cloudSafeCred.put.buildSuccessTestDef = function (f event: "{getFullSafe}.events.onComplete", listener: "gpii.tests.preferencesServer.cloudSafeCred.testCloudSafeCred", args: ["{arguments}.0", fixture.getCloudCredFullSafeExpected, "{getFullSafe}.nativeResponse.statusCode", expectedStatusCode] + }, { + func: "{unlockCloudSafe}.send", + args: fixture.unlockCloudSafePost + }, { + event: "{unlockCloudSafe}.events.onComplete", + listener: "gpii.tests.preferencesServer.testResponse", + args: ["{arguments}.0", fixture.unlockCloudSafeExpected, "{unlockCloudSafe}.nativeResponse.statusCode", expectedStatusCode] }] }; }; @@ -115,10 +128,73 @@ gpii.tests.preferencesServer.cloudSafeCred.put.successFixtures = [ name: "PUT: Add a cloudsafe credential to an existing prefssafe", prefsSafeId: "prefsSafe-1", url: "%prefsSafeId", + putCloudCredBody: { + username: "prefsTestUsername", + password: "testPassword" + }, putCloudCredBodyExpected: { }, getCloudCredFullSafeExpected: { + }, + unlockCloudSafePost: { + username: "prefsTestUsername", + password: "testPassword" + }, + unlockCloudSafeExpected: { + "id": "prefsSafe-1", + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": null, + "password": null, + "email": null, + "preferences": { + "ISO24751": { + "name": "ISO24751 set", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "control": { + "onscreenKeyboard": true, + "mouseEmulation": { + "-provisional-initDelay": 0.120, + "cursorSpeed": 0.850, + "cursorAcceleration": 0.800, + "-provisional-mouseEmulation/enabled": true + } + }, + "unknown": true, + "applications": { + "org.alsa-project": { + "id": "org.alsa-project", + "parameters": { + "volume": 14, + "pitch": 100 + } + } + } + }, + "metadata": [ + { + "type": "provenance", + "scope": ["applications.org\\.alsa-project.parameters"], + "source": "snapshotter" + } + ] + } + }, + "metadata": [ + { + "type": "doNotShare", + "scope": [ "display.screenEnhancement.fontSize"] + } + ] + } + }, + "timestampCreated": "2017-12-14T19:55:11.640Z", + "timestampUpdated": null } } ]; From 0f07b8a01a870ca3e48c40e24b2d025f643cff92 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Wed, 19 Sep 2018 13:41:32 -0700 Subject: [PATCH 15/72] GPII-2966 Branch cleanup - Fixing hardcoded couchdb url for gpii-express-user utils - Cleanup of handler methods --- .../preferencesServer/src/cloudSafeCredHandlers.js | 5 +---- .../preferencesServer/src/preferencesService.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js b/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js index 2b0454487..3e5f772fb 100644 --- a/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js +++ b/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js @@ -31,13 +31,10 @@ fluid.defaults("gpii.preferencesServer.cloudSafeCredCreate.handler", { gpii.preferencesServer.cloudSafeCredCreate.handler.put = function (prefsService, prefsServer, request, params, body) { prefsService.cloudSafeCredCreate({ - // TODO pass in username/password from request prefsSafeId: params.prefsSafeId, username: body.username, password: body.password - }).then(function (data) { - request.events.onSuccess.fire(data); - }); + }).then(request.events.onSuccess.fire, request.events.onError.fire); }; fluid.defaults("gpii.preferencesServer.cloudSafeUnlockPost.handler", { diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index faf0cf552..8952c9ca0 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -29,7 +29,16 @@ require("gpii-express-user"); type: "gpii.express.user.utils", options: { couch: { - userDbUrl: "http://127.0.0.1:8058/gpii" + userDbUrl: { + expander: { + funcName: "fluid.stringTemplate", + args: ["%baseUrl:%port/%dbName", { + baseUrl: "{dataStore}.options.dataSourceConfig.baseUrl", + port: "{dataStore}.options.dataSourceConfig.port", + dbName: "{dataStore}.options.dataSourceConfig.dbName" + }] + } + } } } } From a55a043d3d20642bcae0501f3b461ee42c314c4d Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Thu, 20 Sep 2018 12:09:51 -0700 Subject: [PATCH 16/72] GPII-2966 Clean up of cloud safe promise sequences. --- .../src/preferencesService.js | 165 ++++++++---------- 1 file changed, 73 insertions(+), 92 deletions(-) diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index 8952c9ca0..4c499da5a 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -113,6 +113,30 @@ require("gpii-express-user"); noUpdateOnSnapset: "Cannot update: GPII key \"%gpiiKey\" is a snapset" }); + gpii.preferencesServer.preferencesService.sequenceTransform = function (promArray) { + var finalProm = fluid.promise(); + + var currentPromIdx = 0; + + var resolveFunc = function (data) { + currentPromIdx++; + if (currentPromIdx === promArray.length) { + finalProm.resolve(data); + } + else { + promArray[currentPromIdx](data).then(resolveFunc, rejectFunc); + } + }; + + var rejectFunc = function (err) { + finalProm.reject(err); + }; + + promArray[currentPromIdx]().then(resolveFunc, rejectFunc); + + return finalProm; + }; + /** * Handler for creating cloud safe credentials. * @@ -133,51 +157,38 @@ require("gpii-express-user"); * @return {Promise} Promise containing the new cloud credentials document. */ gpii.preferencesServer.preferencesService.cloudSafeCredCreate = function (dbDataStore, userUtils, options) { - var finalPromise = fluid.promise(); - // #1 Get the prefs Safe - var prefsSafeProm = dbDataStore.findById(options.prefsSafeId); - console.log("SGITHENS OPTS: ", options); - prefsSafeProm.then(function (data) { - console.log("SGITHENS STEP1: ", data); - - // #2 Create a new gpii-express-user - var userProm = userUtils.createNewUser({ - username: options.username, - // TODO, if this password string isn't recreated, gpii-express-user errors out - // during it's hashing/encryption functions saying that it must be a Buffer - password: options.password + "" - }); + var promArray = [ + // #1 This merely ensures that a prefssafe exists with this id, and if it + // fails this will be rejected. + function () { + return dbDataStore.findById(options.prefsSafeId); + }, - userProm.then(function (userRecord) { - console.log("SGITHENS STEP2: ", userRecord); + // #2 Create the gpii-express-user entry + function () { + return userUtils.createNewUser({ + username: options.username, + // TODO, if this password string isn't recreated, gpii-express-user errors out + // during it's hashing/encryption functions saying that it must be a Buffer + password: options.password + "" + }); + }, - // #3 Create a new type of credentials document linking the - // safe and the gpii-express-user record + // #3 Create a new type of credentials document linking the + // safe and the gpii-express-user record + function (userRecord) { var cloudCredDoc = { type: "gpiiCloudSafeCredential", schemaVersion: "0.1", prefsSafeId: options.prefsSafeId, gpiiExpressUserId: userRecord._id }; - var cloudCredProm = gpii.dbOperation.dbDataStore.addRecord(dbDataStore.saveDataSource, + return gpii.dbOperation.dbDataStore.addRecord(dbDataStore.saveDataSource, "gpiiCloudSafeCredential", "id", cloudCredDoc); - cloudCredProm.then(function (cloudCredRecord) { - console.log("SGITHENS STEP3: ", cloudCredRecord); - finalPromise.resolve(cloudCredRecord); - }, - function (err, cloudCredRecord) { - console.log("SGITHENS STEP3 ERR: ", err, cloudCredRecord); - }); + } + ]; - }, - function (err, data) { - console.log("SGITHENS STEP2 ERR: ", err, data); - }); - }, - function (err, data) { - console.log("SGITHENS STEP1 ERR: ", err, data); - }); - return finalPromise; + return gpii.preferencesServer.preferencesService.sequenceTransform(promArray); }; /** @@ -200,66 +211,36 @@ require("gpii-express-user"); * record, or an error payload with a message. */ gpii.preferencesServer.preferencesService.cloudSafeUnlock = function (dbDataStore, userUtils, options) { - // return fluid.promise.sequence([ - // function () { - // return userUtils.unlockUser(options.username, options.password); - // }, - // function (userRecord) { - // // Currently we're getting SGITHENS ARGUMENTS!: { '0': undefined } - // // so it looks like the first promise in the sequence isn't completing... - // console.log("SGITHENS ARGUMENTS!: ", arguments); - // return dbDataStore.findSafeByExpressUserLookup(userRecord._id); - // }, - // function (lookupData) { - // return dbDataStore.findById(lookupData.prefsSafeId); - // } - // ]); - - // #1 Try and unlock the user - var finalProm = fluid.promise(); + var promiseTogo = fluid.promise(); - var unlockProm = userUtils.unlockUser(options.username, options.password); - unlockProm.then(function (userRecord) { - console.log("UNLOCK STEP1: ", userRecord); - - var userRecordId = userRecord._id; - console.log("UNLOCK STEP1.5: ", userRecordId); - dbDataStore.findSafeByExpressUserLookup(userRecordId).then( - function (lookupData) { - console.log("UNLOCK STEP2: ", lookupData); - - var prefsSafeId = lookupData.prefsSafeId; - dbDataStore.findById(prefsSafeId).then( - function (prefsSafe) { - console.log("UNLOCK STEP3: ", prefsSafe); - finalProm.resolve(prefsSafe); - }, - function (err, data) { - console.log("UNLOCK STEP3: ERR", err, data); - finalProm.reject({ - isError: true, - message: "1. Unable to unlock a Preferences Safe with the supplied credentials." - }); - } - ); - }, - function (err, lookupData) { - console.log("UNLOCK STEP2 ERR: ", err, lookupData); - finalProm.reject({ - isError: true, - message: "2. Unable to unlock a Preferences Safe with the supplied credentials." - }); - }); + var promArray = [ + // #1 Unlock User + function () { + return userUtils.unlockUser(options.username, options.password); + }, - }, - function (err) { - console.log("UNLOCK STEP1 ERR: ", err); - finalProm.reject({ - isError: true, - message: "3. Unable to unlock a Preferences Safe with the supplied credentials." + // #2 Look up Cloud Credentials + function (userRecord) { + return dbDataStore.findSafeByExpressUserLookup(userRecord._id); + }, + + // #3 Fetch and Return the Safe + function (lookupData) { + return dbDataStore.findById(lookupData.prefsSafeId); + } + ]; + + gpii.preferencesServer.preferencesService.sequenceTransform(promArray).then( + promiseTogo.resolve, + function (err) { + fluid.log(err); + promiseTogo.reject({ + isError: true, + message: "Unable to unlock a Preferences Safe with the supplied credentials." + }); }); - }); - return finalProm; + + return promiseTogo; }; /** From 1808d3b49c389068419778bc34002d6f6b23da96 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Thu, 20 Sep 2018 19:20:34 -0700 Subject: [PATCH 17/72] GPII-2966 Doco --- .../preferencesServer/src/preferencesService.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index 4c499da5a..a5ffd44a7 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -113,6 +113,18 @@ require("gpii-express-user"); noUpdateOnSnapset: "Cannot update: GPII key \"%gpiiKey\" is a snapset" }); + /** + * A sequence transform pipeline inspired by `fluid.promise.sequence` and + * `fluid.promise.fireTransformEvent`. + * + * https://issues.fluidproject.org/browse/FLUID-6342 + * + * @param {Array} promArray An array of functions that return promises. Each function + * accepts one argument, which is the result from the last payload. + * @return {Promise} Promise resolving with the payload from the last + * promise in the chain. If any of the promises in the `promArray` reject, then the + * pipeline will stop, and the returned promise will reject with the error. + */ gpii.preferencesServer.preferencesService.sequenceTransform = function (promArray) { var finalProm = fluid.promise(); @@ -128,9 +140,7 @@ require("gpii-express-user"); } }; - var rejectFunc = function (err) { - finalProm.reject(err); - }; + var rejectFunc = finalProm.reject; promArray[currentPromIdx]().then(resolveFunc, rejectFunc); From e30021df22b38400ff5ed38183c1a82e1540b0d5 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Thu, 20 Sep 2018 19:25:07 -0700 Subject: [PATCH 18/72] GPII-2966 Removing audit-demo patch --- .../preferencesServer/src/preferencesService.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index a5ffd44a7..e6c34694e 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -461,14 +461,8 @@ require("gpii-express-user"); }); updatePromise.reject({message: noUpdateOnSnapsetMsg}); } else { - // SGITHENS var newPrefs = {preferences: preferences}; - // The temporary patch Cindy had for the audit demo, GPII-3193 commit 39160ce04d844ab5b9317577aee9246274fe07aa - // causes the current unit tests to fail. - // END - // The merge flag determines whether to merge the new preferences with the existing preferences var prefsSafeData = fluid.extend(merge, {}, data.prefsSafe, {preferences: preferences}); - // SGITHENS var prefsSafeData = merge ? fluid.extend({}, data.prefsSafe, newPrefs) : newPrefs; // Update the associated prefs safe var updatePrefsSafePromise = that.dataStore.updatePrefsSafe(prefsSafeId, prefsSafeData); var mapper = function () { From 34eccda796416a16b9199018ceee5d64089f713f Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Fri, 21 Sep 2018 16:03:43 -0700 Subject: [PATCH 19/72] GPII-2966 Document types Doco --- documentation/DataModel.md | 120 +++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/documentation/DataModel.md b/documentation/DataModel.md index 7f22cf3da..52348752e 100644 --- a/documentation/DataModel.md +++ b/documentation/DataModel.md @@ -6,3 +6,123 @@ configuration, CouchDB-compatible PouchDB is used for the data storage. The two GPII components that read and write data from the data storage are Preferences Server and Authorization Server. The details of the GPII data model can be found [here](https://wiki.gpii.net/w/Keys,_KeyTokens,_and_Preferences). + +## Preference Safes Overview + +In this section we discuss the CouchDB documents for all the data associated with a users preferences safe. This +includes their preference sets, keys, full login credentials, and a minimal amount of metadata for the user, +such as name and email. Currently, this consists of three document types: `prefsSafe`, `gpiiKey`, +`gpiiCloudSafeCredential`. + +### Overview of Preference Safes + +Preference Safes consist of a single primary document of type `prefsSafe`. These contain some optional metadata such +as `name` and `email`, and the `preferences` section which contains the users preference sets. This is the central +document for a safe, any documents relating to a safe should have a property `prefsSafeId` which contains the id of +the preferences safe. + +An example document: + +```json + { + "_id": "prefsSafe-7", + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": null, + "password": null, + "email": null, + "preferences": { + "flat": { + "name": "bit of stuff", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/onScreenKeyboard/enabled": true + }, + "metadata": [] + } + }, + "metadata": [] + } + }, + "timestampCreated": "2017-12-14T19:55:11.641Z", + "timestampUpdated": null + } +``` + +### Key-in Documents + +When users key-in to the GPII using a USB stick, NFC card, or other mechanism, the unique `gpiiKey` on the device will +be matched to the CouchDB `id` on a document with type `gpiiKey`. This document contains the important fields `prefsSafeId` +and `prefsSetId` linking it to the safe, and to a specific preference set within that safe to key in with. + +An example document: + +```json + { + "_id": "np_tiny", + "type": "gpiiKey", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-7", + "prefsSetId": "gpii-default", + "revoked": false, + "revokedReason": null, + "timestampCreated": "2017-12-14T19:55:11.641Z", + "timestampUpdated": null + } +``` + +### Login Documents + +In order to have full permissions to edit all aspects of their preferences safe, users must login to their safe using a +username and password. The current implementation of this is backed by the `gpii-express-user` library which creates +records in the same format as native CouchDB accounts and manages password hashing, unlocking, etc. In order to avoid +making changes to this external library, we introduce a document type 'gpiiCloudSafeCredential' which tracks the native +record that is created by `gpii-express-user`. + +An example document: + +```json + { + "type": "gpiiCloudSafeCredential", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-7", + "gpiiExpressUserId": "org.couch.db.user:prefs7user", + "_id": "8f3085a7-b65b-4648-9a78-8ac7de766997" + } +``` + +For reference, the internal account record for the above looks as follows: + +```json +{ + "name": "prefs7user", + "type": "user", + "email": null, + "roles": [], + "username": "prefs7user", + "verified": true, + "iterations": 10, + "password_scheme": "pbkdf2", + "salt": "7cf6961e6ded3bd25732e5466512d116bf9908ba9629d4ed060a03a965e5341d", + "derived_key": "e8bd265e7d82fd0f662e9ddaaf2e75acb294da1b", + "verification_code": "618fa72aa62af282704b556e34957a79", + "_id": "org.couch.db.user:prefs7user" + } +``` + +`gpii-express-user` handles the lookup of unique names when attempting to unlock a user with a password. +This means that in the above example, the login username for preferences safe `prefsSafe-7` would be `prefs7user`. +This also means that it could be possible for a preferences safe to have more than one `gpiiCloudSafeCredential` +similar to how it can have more than one `gpiiKey`. This allows flexibility for the addition, management, and revokation +of key-in and log-in methods. + +### Future Document Types + +In the future we may add additional document types, or sub-types for other features such as CAS or single sign-on +authentication. For any documents that add information to a preferences safe, the most important thing is that they +have a `prefsSafeId` attribute. In general, we want to avoid having documents several linkages away from the primary +preferences safe document. In the case of `gpii-express-user` above we have 1 extra hop to avoid modifying the external +library, but in general, the document relations should be kept as simple as possible. \ No newline at end of file From 65e173219dc0f31c65a29a1b13f6b3c815fc1823 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Fri, 21 Sep 2018 16:07:45 -0700 Subject: [PATCH 20/72] GPII-2966 Minor doco formatting --- documentation/DataModel.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/documentation/DataModel.md b/documentation/DataModel.md index 52348752e..f0e784131 100644 --- a/documentation/DataModel.md +++ b/documentation/DataModel.md @@ -14,7 +14,7 @@ includes their preference sets, keys, full login credentials, and a minimal amou such as name and email. Currently, this consists of three document types: `prefsSafe`, `gpiiKey`, `gpiiCloudSafeCredential`. -### Overview of Preference Safes +### Preference Safes Preference Safes consist of a single primary document of type `prefsSafe`. These contain some optional metadata such as `name` and `email`, and the `preferences` section which contains the users preference sets. This is the central @@ -97,19 +97,19 @@ An example document: For reference, the internal account record for the above looks as follows: ```json -{ - "name": "prefs7user", - "type": "user", - "email": null, - "roles": [], - "username": "prefs7user", - "verified": true, - "iterations": 10, - "password_scheme": "pbkdf2", - "salt": "7cf6961e6ded3bd25732e5466512d116bf9908ba9629d4ed060a03a965e5341d", - "derived_key": "e8bd265e7d82fd0f662e9ddaaf2e75acb294da1b", - "verification_code": "618fa72aa62af282704b556e34957a79", - "_id": "org.couch.db.user:prefs7user" + { + "name": "prefs7user", + "type": "user", + "email": null, + "roles": [], + "username": "prefs7user", + "verified": true, + "iterations": 10, + "password_scheme": "pbkdf2", + "salt": "7cf6961e6ded3bd25732e5466512d116bf9908ba9629d4ed060a03a965e5341d", + "derived_key": "e8bd265e7d82fd0f662e9ddaaf2e75acb294da1b", + "verification_code": "618fa72aa62af282704b556e34957a79", + "_id": "org.couch.db.user:prefs7user" } ``` From 4cf8eed9a608b4576919f358832a07f104dbac4f Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Sun, 7 Oct 2018 16:18:10 -0700 Subject: [PATCH 21/72] GPII-2966 Event chains for Cloudsafe operations - Create tranform promise event chains for cloudsafe operations - Minor lint cleanup - Added test files to all-tests --- documentation/DataModel.md | 2 +- .../src/preferencesService.js | 151 ++++++------------ tests/all-tests.js | 2 + 3 files changed, 54 insertions(+), 101 deletions(-) diff --git a/documentation/DataModel.md b/documentation/DataModel.md index f0e784131..be480612f 100644 --- a/documentation/DataModel.md +++ b/documentation/DataModel.md @@ -125,4 +125,4 @@ In the future we may add additional document types, or sub-types for other featu authentication. For any documents that add information to a preferences safe, the most important thing is that they have a `prefsSafeId` attribute. In general, we want to avoid having documents several linkages away from the primary preferences safe document. In the case of `gpii-express-user` above we have 1 extra hop to avoid modifying the external -library, but in general, the document relations should be kept as simple as possible. \ No newline at end of file +library, but in general, the document relations should be kept as simple as possible. diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index e6c34694e..c95aab899 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -69,17 +69,18 @@ require("gpii-express-user"); }, cloudSafeCredCreate: { funcName: "gpii.preferencesServer.preferencesService.cloudSafeCredCreate", - args: ["{dataStore}", "{gpii.express.user.utils}", "{arguments}.0"] - // options map with keys prefsSafeId, username, password + args: ["{that}", "{arguments}.0"] }, cloudSafeUnlock: { funcName: "gpii.preferencesServer.preferencesService.cloudSafeUnlock", - args: ["{dataStore}", "{gpii.express.user.utils}", "{arguments}.0"] + args: ["{that}", "{arguments}.0"] } }, events: { onCreatePreferences: null, - onAssociatePreferences: null + onAssociatePreferences: null, + onCloudSafeCredCreate: null, + onCloudSafeUnlock: null }, listeners: { onCreatePreferences: [{ @@ -103,6 +104,41 @@ require("gpii-express-user"); listener: "gpii.preferencesServer.preferencesService.updateGpiiKey", args: ["{dataStore}.updateGpiiKey", "{arguments}.0"], namespace: "updateGpiiKey" + }], + onCloudSafeCredCreate: [{ + func: "{dataStore}.findById", + args: ["{arguments}.0"], + namespace: "findById" + }, + { + func: "{expressUserUtils}.createNewUser", + args: [{username: "{arguments}.1.username", password: "{arguments}.1.password"}], + namespace: "createNewUser" + }, + { + funcName: "gpii.dbOperation.dbDataStore.addRecord", + args: ["{dbDataStore}.saveDataSource", + "gpiiCloudSafeCredential", + "id", { + type: "gpiiCloudSafeCredential", + schemaVersion: "0.1", + prefsSafeId: "{arguments}.1.prefsSafeId", + gpiiExpressUserId: "{arguments}.0._id" + }], + namespace: "addRecord" + }], + onCloudSafeUnlock: [{ + func: "{expressUserUtils}.unlockUser", + args: ["{arguments}.0.username", "{arguments}.0.password"], // username, password + namespace: "unlockUser" + }, { + func: "{dataStore}.findSafeByExpressUserLookup", + args: ["{arguments}.0._id"], + namespace: "findSafeByExpressUserLookup" + }, { + func: "{dataStore}.findById", + args: ["{arguments}.0.prefsSafeId"], + namespace: "findById" }] } }); @@ -113,40 +149,6 @@ require("gpii-express-user"); noUpdateOnSnapset: "Cannot update: GPII key \"%gpiiKey\" is a snapset" }); - /** - * A sequence transform pipeline inspired by `fluid.promise.sequence` and - * `fluid.promise.fireTransformEvent`. - * - * https://issues.fluidproject.org/browse/FLUID-6342 - * - * @param {Array} promArray An array of functions that return promises. Each function - * accepts one argument, which is the result from the last payload. - * @return {Promise} Promise resolving with the payload from the last - * promise in the chain. If any of the promises in the `promArray` reject, then the - * pipeline will stop, and the returned promise will reject with the error. - */ - gpii.preferencesServer.preferencesService.sequenceTransform = function (promArray) { - var finalProm = fluid.promise(); - - var currentPromIdx = 0; - - var resolveFunc = function (data) { - currentPromIdx++; - if (currentPromIdx === promArray.length) { - finalProm.resolve(data); - } - else { - promArray[currentPromIdx](data).then(resolveFunc, rejectFunc); - } - }; - - var rejectFunc = finalProm.reject; - - promArray[currentPromIdx]().then(resolveFunc, rejectFunc); - - return finalProm; - }; - /** * Handler for creating cloud safe credentials. * @@ -156,9 +158,7 @@ require("gpii-express-user"); * the cloudsafe credential document that will contain the ID's of both * the prefssafe and the user record. * - * @param {Object} dbDataStore - Instance of `gpii.dbOperation.dbDataStore`, usually - * from the `preferencesService`. - * @param {Object} userUtils - Instance of `gpii.express.user.utils`. + * @param {Object} that - Instance of `gpii.preferencesServer.preferencesService`. * @param {Object} options - Data used to create the new credentials. * @param {Object} options.prefsSafeId - Id for the preferences safe we are adding * credentials to. @@ -166,39 +166,8 @@ require("gpii-express-user"); * @param {Object} options.password - Password for these new credentials. * @return {Promise} Promise containing the new cloud credentials document. */ - gpii.preferencesServer.preferencesService.cloudSafeCredCreate = function (dbDataStore, userUtils, options) { - var promArray = [ - // #1 This merely ensures that a prefssafe exists with this id, and if it - // fails this will be rejected. - function () { - return dbDataStore.findById(options.prefsSafeId); - }, - - // #2 Create the gpii-express-user entry - function () { - return userUtils.createNewUser({ - username: options.username, - // TODO, if this password string isn't recreated, gpii-express-user errors out - // during it's hashing/encryption functions saying that it must be a Buffer - password: options.password + "" - }); - }, - - // #3 Create a new type of credentials document linking the - // safe and the gpii-express-user record - function (userRecord) { - var cloudCredDoc = { - type: "gpiiCloudSafeCredential", - schemaVersion: "0.1", - prefsSafeId: options.prefsSafeId, - gpiiExpressUserId: userRecord._id - }; - return gpii.dbOperation.dbDataStore.addRecord(dbDataStore.saveDataSource, - "gpiiCloudSafeCredential", "id", cloudCredDoc); - } - ]; - - return gpii.preferencesServer.preferencesService.sequenceTransform(promArray); + gpii.preferencesServer.preferencesService.cloudSafeCredCreate = function (that, options) { + return fluid.promise.fireTransformEvent(that.events.onCloudSafeCredCreate, options.prefsSafeId, options); }; /** @@ -211,45 +180,27 @@ require("gpii-express-user"); * * In the future the number of couch calls may by optimized. * - * @param {Object} dbDataStore - Instance of `gpii.dbOperation.dbDataStore`, usually - * from the `preferencesService`. - * @param {Object} userUtils - Instance of `gpii.express.user.utils`. + * @param {Object} that - Instance of `gpii.preferencesServer.preferencesService`. * @param {Object} options - Data used to unlock the safe. * @param {Object} options.username - Username to unlock the Preferences Safe. * @param {Object} options.password - Password to unlock the Preferences Safe. * @return {Promise} Returns a promise containing either the unlocked Preferences Safe * record, or an error payload with a message. */ - gpii.preferencesServer.preferencesService.cloudSafeUnlock = function (dbDataStore, userUtils, options) { + gpii.preferencesServer.preferencesService.cloudSafeUnlock = function (that, options) { var promiseTogo = fluid.promise(); - - var promArray = [ - // #1 Unlock User - function () { - return userUtils.unlockUser(options.username, options.password); - }, - - // #2 Look up Cloud Credentials - function (userRecord) { - return dbDataStore.findSafeByExpressUserLookup(userRecord._id); - }, - - // #3 Fetch and Return the Safe - function (lookupData) { - return dbDataStore.findById(lookupData.prefsSafeId); - } - ]; - - gpii.preferencesServer.preferencesService.sequenceTransform(promArray).then( - promiseTogo.resolve, + fluid.promise.fireTransformEvent(that.events.onCloudSafeUnlock, { + username: options.username, + password: options.password + }).then(promiseTogo.resolve, function (err) { fluid.log(err); promiseTogo.reject({ isError: true, message: "Unable to unlock a Preferences Safe with the supplied credentials." }); - }); - + } + ); return promiseTogo; }; diff --git a/tests/all-tests.js b/tests/all-tests.js index e326c32ba..599083a6c 100644 --- a/tests/all-tests.js +++ b/tests/all-tests.js @@ -65,6 +65,8 @@ var testIncludes = [ "../gpii/node_modules/ontologyHandler/test/node/OntologyHandlerTests.js", "../gpii/node_modules/pouchManager/test/pouchManagerTests.js", "../gpii/node_modules/preferencesServer/test/preferencesServerTests.js", + "../gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js", + "../gpii/node_modules/preferencesServer/test/prefsSafesTests.js", "../gpii/node_modules/settingsHandlers/test/JSONSettingsHandlerTests.js", "../gpii/node_modules/settingsHandlers/test/XMLSettingsHandlerTests.js", "../gpii/node_modules/settingsHandlers/test/INISettingsHandlerTests.js", From 9dcab0c3f4e30ef0cdbc61e1a2530c7ec98eca97 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Tue, 9 Oct 2018 11:42:22 -0700 Subject: [PATCH 22/72] GPII-2966 Adding user lookup views to testdata - Until we resolve the larger issue of loading couchdb views across projects, I am adding the gpii-express-user views to the preferences server test data, as they are duplicated even in the gpii-express-user project itself in order to be loaded. --- .../preferencesServer/test/data/userLookup.json | 16 ++++++++++++++++ .../test/preferencesServerTestsUtils.js | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 gpii/node_modules/preferencesServer/test/data/userLookup.json diff --git a/gpii/node_modules/preferencesServer/test/data/userLookup.json b/gpii/node_modules/preferencesServer/test/data/userLookup.json new file mode 100644 index 000000000..396968632 --- /dev/null +++ b/gpii/node_modules/preferencesServer/test/data/userLookup.json @@ -0,0 +1,16 @@ +[ + { + "_id": "_design/lookup", + "views": { + "byUsernameOrEmail": { + "map": "function (doc) {\n if (doc.type === 'user') { emit(doc.username, doc); \n emit(doc.email, doc); \n } \n}" + }, + "byVerificationCode": { + "map": "function (doc) {\n if (doc.verification_code) { emit(doc.verification_code, doc); \n } \n}" + }, + "byResetCode": { + "map": "function (doc) {\n if (doc.reset_code) { emit(doc.reset_code, doc); \n } \n}" + } + } + } +] diff --git a/gpii/node_modules/preferencesServer/test/preferencesServerTestsUtils.js b/gpii/node_modules/preferencesServer/test/preferencesServerTestsUtils.js index 7d778b58e..1f0b4f879 100644 --- a/gpii/node_modules/preferencesServer/test/preferencesServerTestsUtils.js +++ b/gpii/node_modules/preferencesServer/test/preferencesServerTestsUtils.js @@ -55,8 +55,8 @@ fluid.defaults("gpii.tests.preferencesServer.pouchTestCaseHolder", { "%preferencesServer/test/data/gpiiKeys.json", "%preferencesServer/test/data/gpiiCloudSafeCred.json", "%preferencesServer/test/data/prefsSafes.json", - "%gpii-universal/testData/dbData/views.json", - "%gpii-universal/node_modules/gpii-express-user/src/views/lookup.json" + "%preferencesServer/test/data/userLookup.json", + "%gpii-universal/testData/dbData/views.json" ] } } From 5810582a3ade69735624e4a438cc476d65527bb8 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Wed, 24 Oct 2018 08:47:29 -0700 Subject: [PATCH 23/72] GPII-2966 Adding prefsafe id to return payload. --- gpii/node_modules/preferencesServer/src/preferencesService.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index c95aab899..c86af060f 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -375,7 +375,8 @@ require("gpii-express-user"); fluid.log("Preferences Service, created a new GPII key with id: ", addGpiiKeyResponse.id); return { gpiiKey: addGpiiKeyResponse.id, - preferences: input.prefsSafeDataAdded.preferences + preferences: input.prefsSafeDataAdded.preferences, + prefsSafeId: input.prefsSafeId }; }; return fluid.promise.map(addGpiiKeyPromise, mapper); From ff232fb7c9dd22ddc6f2cd099a95a2deba95b425 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Mon, 5 Nov 2018 16:45:15 -0800 Subject: [PATCH 24/72] GPII-2966 Unit tests updates - Moved preference service tests from browser to node to allow prefs service to use other node based gpii modules. - Minor lint and doco cleanup. --- .../src/preferencesService.js | 5 +- .../test/data/preferencesServiceUsers.json | 80 ++++ .../test/html/PreferencesServiceTests.html | 102 ---- .../test/js/PreferencesServiceTests.js | 425 ----------------- .../test/preferencesServiceTests.js | 437 ++++++++++++++++++ tests/web/html/all-tests.html | 1 - 6 files changed, 519 insertions(+), 531 deletions(-) create mode 100644 gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json delete mode 100644 gpii/node_modules/preferencesServer/test/html/PreferencesServiceTests.html delete mode 100644 gpii/node_modules/preferencesServer/test/js/PreferencesServiceTests.js create mode 100644 gpii/node_modules/preferencesServer/test/preferencesServiceTests.js diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index c86af060f..8813666f1 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -12,12 +12,12 @@ https://github.com/GPII/universal/blob/master/LICENSE.txt /* eslint strict: ["error", "function"] */ var fluid = fluid || require("infusion"); -require("gpii-express-user"); (function () { "use strict"; var gpii = fluid.registerNamespace("gpii"); + require("gpii-express-user"); fluid.defaults("gpii.preferencesServer.preferencesService", { gradeNames: ["fluid.component"], @@ -375,8 +375,7 @@ require("gpii-express-user"); fluid.log("Preferences Service, created a new GPII key with id: ", addGpiiKeyResponse.id); return { gpiiKey: addGpiiKeyResponse.id, - preferences: input.prefsSafeDataAdded.preferences, - prefsSafeId: input.prefsSafeId + preferences: input.prefsSafeDataAdded.preferences }; }; return fluid.promise.map(addGpiiKeyPromise, mapper); diff --git a/gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json b/gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json new file mode 100644 index 000000000..6fa2aa7dd --- /dev/null +++ b/gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json @@ -0,0 +1,80 @@ +[ + { + "_id": "alice_gpii_key", + "type": "gpiiKey", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-1", + "prefsSetId": "gpii-default", + "revoked": false, + "revokedReason": null, + "timestampCreated": "2017-11-21T18:11:22.101Z", + "timestampUpdated": null + }, { + "_id": "bob_gpii_key", + "type": "gpiiKey", + "schemaVersion": "0.1", + "prefsSafeId": null, + "prefsSetId": null, + "revoked": false, + "revokedReason": null, + "timestampCreated": "2017-11-21T18:11:22.101Z", + "timestampUpdated": null + }, { + "_id": "snapset1", + "type": "gpiiKey", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-snapset1", + "prefsSetId": "gpii-default", + "revoked": false, + "revokedReason": null, + "timestampCreated": "2017-11-21T18:11:22.101Z", + "timestampUpdated": null + }, { + "_id": "prefsSafe-1", + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": null, + "password": null, + "email": null, + "preferences": { + "flat": { + "name": "Default context", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/matchMakerType": "ruleBased", + "http://registry.gpii.net/common/fontSize": 24, + "http://registry.gpii.net/common/foregroundColor": "white" + } + } + } + } + }, + "timestampCreated": "2017-12-01T18:43:32.889Z", + "timestampUpdated": null + }, { + "_id": "prefsSafe-snapset1", + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "snapset", + "name": null, + "password": null, + "email": null, + "preferences": { + "flat": { + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/foregroundColor": "white" + } + } + } + } + }, + "timestampCreated": "2017-12-01T18:43:32.889Z", + "timestampUpdated": null + } +] diff --git a/gpii/node_modules/preferencesServer/test/html/PreferencesServiceTests.html b/gpii/node_modules/preferencesServer/test/html/PreferencesServiceTests.html deleted file mode 100644 index 32db513d9..000000000 --- a/gpii/node_modules/preferencesServer/test/html/PreferencesServiceTests.html +++ /dev/null @@ -1,102 +0,0 @@ - - - - - Preferences Service Tests - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Preferences Service Tests

-

-
-

-
    - - - - diff --git a/gpii/node_modules/preferencesServer/test/js/PreferencesServiceTests.js b/gpii/node_modules/preferencesServer/test/js/PreferencesServiceTests.js deleted file mode 100644 index b0f1e4f07..000000000 --- a/gpii/node_modules/preferencesServer/test/js/PreferencesServiceTests.js +++ /dev/null @@ -1,425 +0,0 @@ -/*! -Copyright 2017-2018 OCAD university - -Licensed under the New BSD license. You may not use this file except in -compliance with this License. - -You may obtain a copy of the License at -https://github.com/GPII/universal/blob/master/LICENSE.txt -*/ - -/* global fluid, jqUnit */ - -"use strict"; - -(function () { - - var gpii = fluid.registerNamespace("gpii"); - - // The base test enviornment without any pouch data being imported - fluid.defaults("gpii.tests.preferencesServer.preferencesService.testEnvironment", { - gradeNames: ["gpii.tests.dbOperation.pouchBackedTestEnvironment"], - // Use a module-relative path when https://issues.gpii.net/browse/GPII-3030 is addressed - dbViewsLocation: "../../../../../testData/dbData/views.json", - dbName: "gpii", - components: { - preferencesService: { - type: "gpii.preferencesServer.preferencesService", - createOnEvent: "onFixturesConstructed", - options: { - gradeNames: ["gpii.tests.dbOperation.dbDataStore.base"], - dbViews: "{arguments}.0", - components: { - dataStore: { - type: "gpii.dbOperation.dbDataStore" - } - } - } - }, - caseHolder: { - type: "gpii.tests.inBrowserPouchDB.baseTestCaseHolder" - } - } - }); - - // All input test data - gpii.tests.preferencesServer.preferencesService.testData = { - preferencesToCreate: { - "http://registry.gpii.net/common/matchMakerType": "ruleBased", - "http://registry.gpii.net/common/fontSize": 24 - }, - preferencesToUpdate: { - "flat": { - "contexts": { - "gpii-default": { - "name": "an updated name", - "preferences": { - "http://registry.gpii.net/common/fontSize": 20 - } - } - } - }, - "newKey": { - "nested": "nested-value" - } - } - }; - - // All expected results - gpii.tests.preferencesServer.preferencesService.expected = { - // for testing getPreferencesByGpiiKey() - receivedPrefs: { - "flat": { - "name": "Default context", - "contexts": { - "gpii-default": { - "name": "Default preferences", - "preferences": { - "http://registry.gpii.net/common/matchMakerType": "ruleBased", - "http://registry.gpii.net/common/fontSize": 24, - "http://registry.gpii.net/common/foregroundColor": "white" - } - } - } - } - }, - updatedPrefs: { - "flat": { - "name": "Default context", - "contexts": { - "gpii-default": { - "name": "an updated name", - "preferences": { - "http://registry.gpii.net/common/fontSize": 20, - "http://registry.gpii.net/common/foregroundColor": "white", - "http://registry.gpii.net/common/matchMakerType": "ruleBased" - } - } - } - }, - "newKey": { - "nested": "nested-value" - } - }, - unauthorized: { - message: "Unauthorized", - statusCode: 401, - isError: true - }, - missingGpiiKey: { - message: "GPII key \"non-existent-gpii-key\" does not exist" - }, - noUpdateOnSnapset: { - message: "Cannot update: GPII key \"snapset1\" is a snapset" - }, - // for testing createPreferences() - preferencesToCreate_prefsOnly: { - prefsSafeType: "user", - name: null, - password: null, - email: null, - preferences: { - "http://registry.gpii.net/common/cursorSize": 24 - } - }, - gpiiKeyExisted: "GPII key \"alice_gpii_key\" already exists" - }; - - gpii.tests.preferencesServer.preferencesService.pouchData = [{ - "_id": "alice_gpii_key", - "type": "gpiiKey", - "schemaVersion": "0.1", - "prefsSafeId": "prefsSafe-1", - "prefsSetId": "gpii-default", - "revoked": false, - "revokedReason": null, - "timestampCreated": "2017-11-21T18:11:22.101Z", - "timestampUpdated": null - }, { - "_id": "bob_gpii_key", - "type": "gpiiKey", - "schemaVersion": "0.1", - "prefsSafeId": null, - "prefsSetId": null, - "revoked": false, - "revokedReason": null, - "timestampCreated": "2017-11-21T18:11:22.101Z", - "timestampUpdated": null - }, { - "_id": "snapset1", - "type": "gpiiKey", - "schemaVersion": "0.1", - "prefsSafeId": "prefsSafe-snapset1", - "prefsSetId": "gpii-default", - "revoked": false, - "revokedReason": null, - "timestampCreated": "2017-11-21T18:11:22.101Z", - "timestampUpdated": null - }, { - "_id": "prefsSafe-1", - "type": "prefsSafe", - "schemaVersion": "0.1", - "prefsSafeType": "user", - "name": null, - "password": null, - "email": null, - "preferences": { - "flat": { - "name": "Default context", - "contexts": { - "gpii-default": { - "name": "Default preferences", - "preferences": { - "http://registry.gpii.net/common/matchMakerType": "ruleBased", - "http://registry.gpii.net/common/fontSize": 24, - "http://registry.gpii.net/common/foregroundColor": "white" - } - } - } - } - }, - "timestampCreated": "2017-12-01T18:43:32.889Z", - "timestampUpdated": null - }, { - "_id": "prefsSafe-snapset1", - "type": "prefsSafe", - "schemaVersion": "0.1", - "prefsSafeType": "snapset", - "name": null, - "password": null, - "email": null, - "preferences": { - "flat": { - "contexts": { - "gpii-default": { - "name": "Default preferences", - "preferences": { - "http://registry.gpii.net/common/foregroundColor": "white" - } - } - } - } - }, - "timestampCreated": "2017-12-01T18:43:32.889Z", - "timestampUpdated": null - }]; - - fluid.defaults("gpii.tests.preferencesServer.preferencesService.getPreferencesByGpiiKey", { - gradeNames: ["gpii.tests.preferencesServer.preferencesService.testEnvironment"], - pouchData: gpii.tests.preferencesServer.preferencesService.pouchData, - rawModules: [{ - name: "Test getPreferencesByGpiiKey()", - tests: [{ - name: "getPreferencesByGpiiKey() returns preferences - a successful workflow", - sequence: [{ - func: "gpii.tests.invokePromiseProducer", - args: ["{preferencesService}.getPreferencesByGpiiKey", ["alice_gpii_key"], "{that}"] - }, { - listener: "jqUnit.assertDeepEq", - args: ["The access token should be received in an expected format", gpii.tests.preferencesServer.preferencesService.expected.receivedPrefs, "{arguments}.0"], - event: "{that}.events.onResponse" - }] - }, { - name: "getPreferencesByGpiiKey() returns undefined when the GPII key has no preferences defined", - sequence: [{ - func: "gpii.tests.invokePromiseProducer", - args: ["{preferencesService}.getPreferencesByGpiiKey", ["bob_gpii_key"], "{that}"] - }, { - listener: "jqUnit.assertUndefined", - args: ["undefined is returned when the gpii key has no preferences defined", "{arguments}.0"], - event: "{that}.events.onResponse" - }] - }, { - name: "getPreferencesByGpiiKey() returns error when a gpii key is not provided in the argument list", - sequence: [{ - func: "gpii.tests.invokePromiseProducer", - args: ["{preferencesService}.getPreferencesByGpiiKey", ["non-existent-gpii-key"], "{that}"] - }, { - listener: "jqUnit.assertDeepEq", - args: ["The error is returned when a gpii key is not found", gpii.tests.preferencesServer.preferencesService.expected.missingGpiiKey, "{arguments}.0"], - event: "{that}.events.onError" - }] - }] - }] - }); - - fluid.defaults("gpii.tests.preferencesServer.preferencesService.createPreferences", { - gradeNames: ["gpii.tests.preferencesServer.preferencesService.testEnvironment"], - pouchData: gpii.tests.preferencesServer.preferencesService.pouchData, - rawModules: [{ - name: "Test createPreferences()", - tests: [{ - name: "createPreferences() creates a prefs safe and an auto generated GPII key - a successful workflow", - sequence: [{ - func: "gpii.tests.invokePromiseProducer", - args: ["{preferencesService}.createPreferences", [gpii.tests.preferencesServer.preferencesService.testData.preferencesToCreate], "{that}"] - }, { - listener: "gpii.tests.invokePromiseProducer", - args: ["{preferencesService}.getPrefsSafeByGpiiKey", ["{arguments}.0.gpiiKey"], "{that}"], - event: "{that}.events.onResponse" - }, { - listener: "gpii.tests.preferencesServer.preferencesService.verifyFetchedPrefsSafe", - args: [gpii.tests.preferencesServer.preferencesService.testData.preferencesToCreate, "{arguments}.0"], - event: "{that}.events.onResponse" - }] - }, { - name: "createPreferences() creates a prefs safe and an GPII key with the provided key value - a successful workflow", - sequence: [{ - func: "gpii.tests.invokePromiseProducer", - args: ["{preferencesService}.createPreferences", [gpii.tests.preferencesServer.preferencesService.testData.preferencesToCreate, "a-new-gpii-key-by-preferences-service"], "{that}"] - }, { - listener: "gpii.tests.invokePromiseProducer", - args: ["{preferencesService}.getPrefsSafeByGpiiKey", ["{arguments}.0.gpiiKey"], "{that}"], - event: "{that}.events.onResponse" - }, { - listener: "gpii.tests.preferencesServer.preferencesService.verifyFetchedPrefsSafe", - args: [gpii.tests.preferencesServer.preferencesService.testData.preferencesToCreate, "{arguments}.0", "a-new-gpii-key-by-preferences-service"], - event: "{that}.events.onResponse" - }] - }, { - name: "createPreferences() returns error when the provided GPII key already exists", - sequence: [{ - func: "gpii.tests.invokePromiseProducer", - args: ["{preferencesService}.createPreferences", [gpii.tests.preferencesServer.preferencesService.testData.preferencesToCreate, "alice_gpii_key"], "{that}"] - }, { - listener: "jqUnit.assertDeepEq", - args: ["The error is returned when the provided GPII key already exists", gpii.tests.preferencesServer.preferencesService.expected.gpiiKeyExisted, "{arguments}.0"], - event: "{that}.events.onError" - }] - }] - }] - }); - - gpii.tests.preferencesServer.preferencesService.verifyFetchedPrefsSafe = function (preferencesToCreate, response, expectedGpiiKey) { - if (expectedGpiiKey) { - jqUnit.assertEquals("The created GPII key matches the input GPII key", expectedGpiiKey, response.gpiiKey); - jqUnit.assertEquals("The GPII key in the key record matches the input GPII key", expectedGpiiKey, response.gpiiKeyDetails.id); - } else { - jqUnit.assertNotUndefined("The GPII key is auto generated", response.gpiiKey); - } - - var gpiiKeyDetails = response.gpiiKeyDetails; - jqUnit.assertEquals("The value of \"schemaVersion\" has been set correctly", gpii.dbOperation.schemaVersion, gpiiKeyDetails.schemaVersion); - jqUnit.assertNotUndefined("The value of \"prefsSafeId\" has been set to default", gpiiKeyDetails.prefsSafeId); - jqUnit.assertEquals("The value of \"prefsSetId\" has been set to default", gpii.preferencesServer.defaultprefsSetId, gpiiKeyDetails.prefsSetId); - jqUnit.assertFalse("The value of \"revoked\" has been set to false", gpiiKeyDetails.revoked); - jqUnit.assertNull("The value of \"revokedReason\" has been set to null", gpiiKeyDetails.revokedReason); - jqUnit.assertNotUndefined("The value of \"timestampCreated\" has been set", gpiiKeyDetails.timestampCreated); - jqUnit.assertNull("The value of \"timestampUpdated\" has been set", gpiiKeyDetails.timestampUpdated); - - var prefsSafe = response.prefsSafe; - jqUnit.assertLeftHand("The data is saved successfully", preferencesToCreate, prefsSafe.preferences); - }; - - fluid.defaults("gpii.tests.preferencesServer.preferencesService.updatePreferences", { - gradeNames: ["gpii.tests.preferencesServer.preferencesService.testEnvironment"], - pouchData: gpii.tests.preferencesServer.preferencesService.pouchData, - rawModules: [{ - name: "Test updatePreferences()", - tests: [{ - name: "updatePreferences() updates the associated prefs safe with merged preferences - a successful workflow", - sequence: [{ - func: "gpii.tests.invokePromiseProducer", - args: ["{preferencesService}.getPrefsSafeByGpiiKey", ["alice_gpii_key"], "{that}"] - }, { - // save the original GPII key and prefs safe records to compare after the update - listener: "fluid.set", - args: ["{that}", ["originalData"], "{arguments}.0"], - event: "{that}.events.onResponse" - }, { - func: "gpii.tests.invokePromiseProducer", - args: ["{preferencesService}.updatePreferences", [gpii.tests.preferencesServer.preferencesService.testData.preferencesToUpdate, "alice_gpii_key", true], "{that}"] - }, { - listener: "gpii.tests.invokePromiseProducer", - args: ["{preferencesService}.getPrefsSafeByGpiiKey", ["{arguments}.0.gpiiKey"], "{that}"], - event: "{that}.events.onResponse" - }, { - listener: "gpii.tests.preferencesServer.preferencesService.verifyUpdatedPrefsSafe", - args: ["{that}", gpii.tests.preferencesServer.preferencesService.expected.updatedPrefs, "alice_gpii_key", "{arguments}.0"], - event: "{that}.events.onResponse" - }] - }, { - name: "updatePreferences() updates the associated prefs safe without merging with existing preferences - a successful workflow", - sequence: [{ - func: "gpii.tests.invokePromiseProducer", - args: ["{preferencesService}.getPrefsSafeByGpiiKey", ["alice_gpii_key"], "{that}"] - }, { - // save the original GPII key and prefs safe records to compare after the update - listener: "fluid.set", - args: ["{that}", ["originalData"], "{arguments}.0"], - event: "{that}.events.onResponse" - }, { - func: "gpii.tests.invokePromiseProducer", - args: ["{preferencesService}.updatePreferences", [gpii.tests.preferencesServer.preferencesService.testData.preferencesToUpdate, "alice_gpii_key"], "{that}"] - }, { - listener: "gpii.tests.invokePromiseProducer", - args: ["{preferencesService}.getPrefsSafeByGpiiKey", ["{arguments}.0.gpiiKey"], "{that}"], - event: "{that}.events.onResponse" - }, { - listener: "gpii.tests.preferencesServer.preferencesService.verifyUpdatedPrefsSafe", - args: ["{that}", gpii.tests.preferencesServer.preferencesService.testData.preferencesToUpdate, "alice_gpii_key", "{arguments}.0"], - event: "{that}.events.onResponse" - }] - }, { - name: "updatePreferences() creates a new prefs safe when the GPII key is not associates with a prefs safe - a successful workflow", - sequence: [{ - func: "gpii.tests.invokePromiseProducer", - args: ["{preferencesService}.getPrefsSafeByGpiiKey", ["bob_gpii_key"], "{that}"] - }, { - // save the original GPII key and prefs safe records to compare after the update - listener: "fluid.set", - args: ["{that}", ["originalData"], "{arguments}.0"], - event: "{that}.events.onResponse" - }, { - func: "gpii.tests.invokePromiseProducer", - args: ["{preferencesService}.updatePreferences", [gpii.tests.preferencesServer.preferencesService.testData.preferencesToUpdate, "bob_gpii_key"], "{that}"] - }, { - listener: "gpii.tests.invokePromiseProducer", - args: ["{preferencesService}.getPrefsSafeByGpiiKey", ["{arguments}.0.gpiiKey"], "{that}"], - event: "{that}.events.onResponse" - }, { - listener: "gpii.tests.preferencesServer.preferencesService.verifyNewPrefsSafeForUpdate", - args: ["{that}", gpii.tests.preferencesServer.preferencesService.testData.preferencesToUpdate, "bob_gpii_key", "{arguments}.0"], - event: "{that}.events.onResponse" - }] - }, { - name: "updatePreferences() returns error when updating a snapset", - sequence: [{ - func: "gpii.tests.invokePromiseProducer", - args: ["{preferencesService}.updatePreferences", [gpii.tests.preferencesServer.preferencesService.testData.preferencesToUpdate, "snapset1"], "{that}"] - }, { - listener: "jqUnit.assertDeepEq", - args: ["The error is returned when updating a snapset", gpii.tests.preferencesServer.preferencesService.expected.noUpdateOnSnapset, "{arguments}.0"], - event: "{that}.events.onError" - }] - }] - }] - }); - - gpii.tests.preferencesServer.preferencesService.verifyUpdatedPrefsSafe = function (that, updatedPreferences, gpiiKey, response) { - jqUnit.assertDeepEq("The GPII key in the response is expected", gpiiKey, response.gpiiKey); - jqUnit.assertDeepEq("The GPII key record is unchanged", that.originalData.gpiiKeyDetails, response.gpiiKeyDetails); - jqUnit.assertDeepEq("The preferences has been updated", updatedPreferences, response.prefsSafe.preferences); - jqUnit.assertNotEquals("The prefs safe timestampUpdated has been updated", that.originalData.prefsSafe.timestampUpdated, response.prefsSafe.timestampUpdated); - - var unchangedOrigPrefsSafeFields = fluid.censorKeys(that.originalData.prefsSafe, ["preferences", "timestampUpdated"]); - var unchangedPrefsSafeFields = fluid.censorKeys(response.prefsSafe, ["preferences", "timestampUpdated"]); - jqUnit.assertDeepEq("Other prefs safe values are unchanged", unchangedOrigPrefsSafeFields, unchangedPrefsSafeFields); - }; - - gpii.tests.preferencesServer.preferencesService.verifyNewPrefsSafeForUpdate = function (that, updatedPreferences, gpiiKey, response) { - // verify before update status - jqUnit.assertNull("The GPII key originally has no prefs safe associated", that.originalData.gpiiKeyDetails.prefsSafeId); - - // verify after update status - jqUnit.assertDeepEq("The GPII key in the response is expected", gpiiKey, response.gpiiKey); - jqUnit.assertNotUndefined("A prefs safe has been created", response.prefsSafe); - jqUnit.assertNull("The timestampUpdated of the prefs safe is null", response.prefsSafe.timestampUpdated); - jqUnit.assertDeepEq("The preferences in the prefs safe is expected", updatedPreferences, response.prefsSafe.preferences); - jqUnit.assertEquals("The prefs safe has been associated with the GPII key", response.gpiiKeyDetails.prefsSafeId, response.prefsSafe.id); - - var unchangedOrigGpiiKeyFields = fluid.censorKeys(that.originalData.gpiiKeyDetails, ["prefsSafeId", "prefsSetId", "timestampUpdated"]); - var unchangedGpiiKeyFields = fluid.censorKeys(response.gpiiKeyDetails, ["prefsSafeId", "prefsSetId", "timestampUpdated"]); - jqUnit.assertDeepEq("Other GPII key values are unchanged", unchangedOrigGpiiKeyFields, unchangedGpiiKeyFields); - }; -})(); diff --git a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js new file mode 100644 index 000000000..d5bc0bf28 --- /dev/null +++ b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js @@ -0,0 +1,437 @@ +/*! +Copyright 2017-2018 OCAD university + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +You may obtain a copy of the License at +https://github.com/GPII/universal/blob/master/LICENSE.txt +*/ +use "strict"; + +var fluid = require("infusion"), + jqUnit = fluid.require("node-jqunit", require, "jqUnit"), + gpii = fluid.registerNamespace("gpii"); + +require("./preferencesServerTestsUtils.js"); +require("./preferencesServerTests.js"); + +fluid.require("%gpii-universal"); +gpii.loadTestingSupport(); + +fluid.registerNamespace("gpii.tests.preferencesServer.preferencesService"); + +// All input test data +gpii.tests.preferencesServer.preferencesService.testData = { + preferencesToCreate: { + "http://registry.gpii.net/common/matchMakerType": "ruleBased", + "http://registry.gpii.net/common/fontSize": 24 + }, + preferencesToUpdate: { + "flat": { + "contexts": { + "gpii-default": { + "name": "an updated name", + "preferences": { + "http://registry.gpii.net/common/fontSize": 20 + } + } + } + }, + "newKey": { + "nested": "nested-value" + } + } +}; + +// All expected results +gpii.tests.preferencesServer.preferencesService.expected = { + // for testing getPreferencesByGpiiKey() + receivedPrefs: { + "flat": { + "name": "Default context", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/matchMakerType": "ruleBased", + "http://registry.gpii.net/common/fontSize": 24, + "http://registry.gpii.net/common/foregroundColor": "white" + } + } + } + } + }, + updatedPrefs: { + "flat": { + "name": "Default context", + "contexts": { + "gpii-default": { + "name": "an updated name", + "preferences": { + "http://registry.gpii.net/common/fontSize": 20, + "http://registry.gpii.net/common/foregroundColor": "white", + "http://registry.gpii.net/common/matchMakerType": "ruleBased" + } + } + } + }, + "newKey": { + "nested": "nested-value" + } + }, + unauthorized: { + message: "Unauthorized", + statusCode: 401, + isError: true + }, + missingGpiiKey: { + message: "GPII key \"non-existent-gpii-key\" does not exist" + }, + noUpdateOnSnapset: { + message: "Cannot update: GPII key \"snapset1\" is a snapset" + }, + // for testing createPreferences() + preferencesToCreate_prefsOnly: { + prefsSafeType: "user", + name: null, + password: null, + email: null, + preferences: { + "http://registry.gpii.net/common/cursorSize": 24 + } + }, + gpiiKeyExisted: "GPII key \"alice_gpii_key\" already exists" +}; + +/** + * Utility for calling the preferences service duing the test sequences. + * + * Calls an invoker on the `preferencesService` that returns a promise. + * If only the first 2 arguments are used, this function returns the + * actual promise. If an event is provided as the optional third argument, + * that event is fired using the promises resolve data, and nothing + * is returned from the function. + * + * It's interesting to note in the tests below, that if the argument + * provided to a `task` is an IoC preference to the `{preferencesService}` + * that it is injected as `undefined`. This may be due to the order of test + * creation. ie. These bootstrap tests are perhaps wired before the + * preferences service is created for each test. This is partially the + * reason for this function, but also because we do need the option to just + * fire the event in order to sequence some of the listeners between tasks. + * + * ie: + * task: "gpii.tests.preferencesServer.preferencesService.fetch", + * args: ["{preferencesService}.getPreferencesByGpiiKey", "alice_gpii_key"], + * // The first argument will be undefined. + * + * @param {String} prefsServiceInvoker - Name of the invoker to call on the preferences service. + * @param {Array} args - List of arguments to pass to the invoker. + * @param {Event} eventToFire - Optional. Event to be fired with promise resolve data if + * supplied. + * @return {fluid.promise|undefined} If an event to fire is not included this function + * returns the promise from the preferences service. If an event is provided this function + * returns nothing, but fires the event with the resolved data. + */ +gpii.tests.preferencesServer.preferencesService.promise = function (prefsServiceInvoker, args, eventToFire) { + var prefsService = fluid.queryIoCSelector(fluid.rootComponent, "gpii.preferencesServer.preferencesService")[0]; + var promTogo = prefsService[prefsServiceInvoker].apply(null, args); + if (eventToFire) { + promTogo.then(function (data) { + eventToFire.fire(data); + }, function (err) { + eventToFire.fire(err); + }); + } + else { + return promTogo; + } +}; + +// The pouchTestCaseHolder for the preferences server that loads specific data files +// These tests use their own sets of users in `preferencesServiceUsers.json` +fluid.defaults("gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", { + gradeNames: ["gpii.test.pouch.pouchTestCaseHolder"], + mergePolicy: { + "pouchConfig.databases.gpii.data": "replace" + }, + pouchConfig: { + databases: { + gpii: { + data: [ + "%preferencesServer/test/data/gpiiKeys.json", + "%preferencesServer/test/data/gpiiCloudSafeCred.json", + "%preferencesServer/test/data/userLookup.json", + "%preferencesServer/test/data/preferencesServiceUsers.json", + "%gpii-universal/testData/dbData/views.json" + ] + } + } + } +}); + +gpii.tests.preferencesServer.preferencesService.getPreferencesByGpiiKey = [ + { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", + name: "getPreferencesByGpiiKey() returns preferences - a successful workflow", + expect: 1, + sequence: [{ + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["getPreferencesByGpiiKey", ["alice_gpii_key"]], + resolve: "jqUnit.assertDeepEq", + resolveArgs: ["The access token should be received in an expected format", gpii.tests.preferencesServer.preferencesService.expected.receivedPrefs, "{arguments}.0"] + }] + }, { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", + expect: 1, + name: "getPreferencesByGpiiKey() returns undefined when the GPII key has no preferences defined", + sequence: [{ + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["getPreferencesByGpiiKey", ["bob_gpii_key"]], + resolve: "jqUnit.assertUndefined", + resolveArgs: ["undefined is returned when the gpii key has no preferences defined", "{arguments}.0"] + }] + }, { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", + expect: 1, + name: "getPreferencesByGpiiKey() returns error when a gpii key is not provided in the argument list", + sequence: [{ + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["getPreferencesByGpiiKey", ["non-existent-gpii-key"]], + reject: "jqUnit.assertDeepEq", + rejectArgs: ["The error is returned when a gpii key is not found", gpii.tests.preferencesServer.preferencesService.expected.missingGpiiKey, "{arguments}.0"] + }] + } +]; + +gpii.test.bootstrapServer(gpii.tests.preferencesServer.preferencesService.getPreferencesByGpiiKey); + +gpii.tests.preferencesServer.preferencesService.createPreferences = [ + { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", + name: "createPreferences() creates a prefs safe and an auto generated GPII key - a successful workflow", + events: { + onFinishedCreate: null, + onFinishedLookup: null + }, + sequence: [{ + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["createPreferences", [gpii.tests.preferencesServer.preferencesService.testData.preferencesToCreate]], + resolve: "{that}.events.onFinishedCreate.fire", + resolveArgs: ["{arguments}.0"] + }, { + listener: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["getPrefsSafeByGpiiKey", ["{arguments}.0.gpiiKey"], "{that}.events.onFinishedLookup"], + event: "{that}.events.onFinishedCreate" + }, { + listener: "gpii.tests.preferencesServer.preferencesService.verifyFetchedPrefsSafe", + args: [gpii.tests.preferencesServer.preferencesService.testData.preferencesToCreate, "{arguments}.0"], + event: "{that}.events.onFinishedLookup" + }] + }, + { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", + name: "createPreferences() creates a prefs safe and an GPII key with the provided key value - a successful workflow", + events: { + onFinishedCreate: null, + onFinishedLookup: null + }, + sequence: [{ + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["createPreferences", [gpii.tests.preferencesServer.preferencesService.testData.preferencesToCreate, "a-new-gpii-key-by-preferences-service"]], + resolve: "{that}.events.onFinishedCreate.fire", + resolveArgs: ["{arguments}.0"] + }, { + listener: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["getPrefsSafeByGpiiKey", ["{arguments}.0.gpiiKey"], "{that}.events.onFinishedLookup"], + event: "{that}.events.onFinishedCreate" + }, { + listener: "gpii.tests.preferencesServer.preferencesService.verifyFetchedPrefsSafe", + args: [gpii.tests.preferencesServer.preferencesService.testData.preferencesToCreate, "{arguments}.0", "a-new-gpii-key-by-preferences-service"], + event: "{that}.events.onFinishedLookup" + }] + }, + { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", + name: "createPreferences() returns error when the provided GPII key already exists", + sequence: [{ + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["createPreferences", [gpii.tests.preferencesServer.preferencesService.testData.preferencesToCreate, "alice_gpii_key"]], + reject: "jqUnit.assertDeepEq", + rejectArgs: ["The error is returned when the provided GPII key already exists", gpii.tests.preferencesServer.preferencesService.expected.gpiiKeyExisted, "{arguments}.0"] + }] + } +]; + +gpii.test.bootstrapServer(gpii.tests.preferencesServer.preferencesService.createPreferences); + +gpii.tests.preferencesServer.preferencesService.verifyFetchedPrefsSafe = function (preferencesToCreate, response, expectedGpiiKey) { + if (expectedGpiiKey) { + jqUnit.assertEquals("The created GPII key matches the input GPII key", expectedGpiiKey, response.gpiiKey); + jqUnit.assertEquals("The GPII key in the key record matches the input GPII key", expectedGpiiKey, response.gpiiKeyDetails.id); + } else { + jqUnit.assertNotUndefined("The GPII key is auto generated", response.gpiiKey); + } + + var gpiiKeyDetails = response.gpiiKeyDetails; + jqUnit.assertEquals("The value of \"schemaVersion\" has been set correctly", gpii.dbOperation.schemaVersion, gpiiKeyDetails.schemaVersion); + jqUnit.assertNotUndefined("The value of \"prefsSafeId\" has been set to default", gpiiKeyDetails.prefsSafeId); + jqUnit.assertEquals("The value of \"prefsSetId\" has been set to default", gpii.preferencesServer.defaultprefsSetId, gpiiKeyDetails.prefsSetId); + jqUnit.assertFalse("The value of \"revoked\" has been set to false", gpiiKeyDetails.revoked); + jqUnit.assertNull("The value of \"revokedReason\" has been set to null", gpiiKeyDetails.revokedReason); + jqUnit.assertNotUndefined("The value of \"timestampCreated\" has been set", gpiiKeyDetails.timestampCreated); + jqUnit.assertNull("The value of \"timestampUpdated\" has been set", gpiiKeyDetails.timestampUpdated); + + var prefsSafe = response.prefsSafe; + jqUnit.assertLeftHand("The data is saved successfully", preferencesToCreate, prefsSafe.preferences); +}; + +gpii.tests.preferencesServer.preferencesService.updatePreferences = [ + { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", + name: "updatePreferences() updates the associated prefs safe with merged preferences - a successful workflow", + events: { + onFetchUpdatedPrefs: null + }, + sequence: [{ + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["getPrefsSafeByGpiiKey", ["alice_gpii_key"]], + // save the original GPII key and prefs safe records to compare after the update + resolve: "fluid.set", + resolveArgs: ["{that}", ["originalData"], "{arguments}.0"] + }, { + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["updatePreferences", [gpii.tests.preferencesServer.preferencesService.testData.preferencesToUpdate, "alice_gpii_key", true]], + resolve: "gpii.tests.preferencesServer.preferencesService.promise", + resolveArgs: ["getPrefsSafeByGpiiKey", ["{arguments}.0.gpiiKey"], "{that}.events.onFetchUpdatedPrefs"] + }, { + listener: "gpii.tests.preferencesServer.preferencesService.verifyUpdatedPrefsSafe", + args: ["{that}", gpii.tests.preferencesServer.preferencesService.expected.updatedPrefs, "alice_gpii_key", "{arguments}.0"], + event: "{that}.events.onFetchUpdatedPrefs" + }] + }, + { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", + name: "updatePreferences() updates the associated prefs safe without merging with existing preferences - a successful workflow", + events: { + onFetchUpdatedPrefs: null + }, + sequence: [{ + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["getPrefsSafeByGpiiKey", ["alice_gpii_key"]], + resolve: "fluid.set", + resolveArgs: ["{that}", ["originalData"], "{arguments}.0"] + }, { + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["updatePreferences", [gpii.tests.preferencesServer.preferencesService.testData.preferencesToUpdate, "alice_gpii_key"]], + resolve: "gpii.tests.preferencesServer.preferencesService.promise", + resolveArgs: ["getPrefsSafeByGpiiKey", ["{arguments}.0.gpiiKey"], "{that}.events.onFetchUpdatedPrefs"] + }, { + listener: "gpii.tests.preferencesServer.preferencesService.verifyUpdatedPrefsSafe", + args: ["{that}", gpii.tests.preferencesServer.preferencesService.testData.preferencesToUpdate, "alice_gpii_key", "{arguments}.0"], + event: "{that}.events.onFetchUpdatedPrefs" + }] + }, + { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", + name: "updatePreferences() creates a new prefs safe when the GPII key is not associates with a prefs safe - a successful workflow", + events: { + onFetchUpdatedPrefs: null + }, + sequence: [{ + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["getPrefsSafeByGpiiKey", ["bob_gpii_key"]], + resolve: "fluid.set", + resolveArgs: ["{that}", ["originalData"], "{arguments}.0"] + }, { + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["updatePreferences", [gpii.tests.preferencesServer.preferencesService.testData.preferencesToUpdate, "bob_gpii_key"]], + resolve: "gpii.tests.preferencesServer.preferencesService.promise", + resolveArgs: ["getPrefsSafeByGpiiKey", ["{arguments}.0.gpiiKey"], "{that}.events.onFetchUpdatedPrefs"] + }, { + listener: "gpii.tests.preferencesServer.preferencesService.verifyNewPrefsSafeForUpdate", + args: ["{that}", gpii.tests.preferencesServer.preferencesService.testData.preferencesToUpdate, "bob_gpii_key", "{arguments}.0"], + event: "{that}.events.onFetchUpdatedPrefs" + }] + }, + { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", + name: "updatePreferences() returns error when updating a snapset", + sequence: [{ + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["updatePreferences", [gpii.tests.preferencesServer.preferencesService.testData.preferencesToUpdate, "snapset1"]], + reject: "jqUnit.assertDeepEq", + rejectArgs: ["The error is returned when updating a snapset", gpii.tests.preferencesServer.preferencesService.expected.noUpdateOnSnapset, "{arguments}.0"] + }] + } +]; + +gpii.test.bootstrapServer(gpii.tests.preferencesServer.preferencesService.updatePreferences); + +gpii.tests.preferencesServer.preferencesService.verifyUpdatedPrefsSafe = function (that, updatedPreferences, gpiiKey, response) { + jqUnit.assertDeepEq("The GPII key in the response is expected", gpiiKey, response.gpiiKey); + jqUnit.assertDeepEq("The GPII key record is unchanged", that.originalData.gpiiKeyDetails, response.gpiiKeyDetails); + jqUnit.assertDeepEq("The preferences has been updated", updatedPreferences, response.prefsSafe.preferences); + jqUnit.assertNotEquals("The prefs safe timestampUpdated has been updated", that.originalData.prefsSafe.timestampUpdated, response.prefsSafe.timestampUpdated); + + var unchangedOrigPrefsSafeFields = fluid.censorKeys(that.originalData.prefsSafe, ["preferences", "timestampUpdated"]); + var unchangedPrefsSafeFields = fluid.censorKeys(response.prefsSafe, ["preferences", "timestampUpdated"]); + jqUnit.assertDeepEq("Other prefs safe values are unchanged", unchangedOrigPrefsSafeFields, unchangedPrefsSafeFields); +}; + +gpii.tests.preferencesServer.preferencesService.verifyNewPrefsSafeForUpdate = function (that, updatedPreferences, gpiiKey, response) { + // verify before update status + jqUnit.assertNull("The GPII key originally has no prefs safe associated", that.originalData.gpiiKeyDetails.prefsSafeId); + + // verify after update status + jqUnit.assertDeepEq("The GPII key in the response is expected", gpiiKey, response.gpiiKey); + jqUnit.assertNotUndefined("A prefs safe has been created", response.prefsSafe); + jqUnit.assertNull("The timestampUpdated of the prefs safe is null", response.prefsSafe.timestampUpdated); + jqUnit.assertDeepEq("The preferences in the prefs safe is expected", updatedPreferences, response.prefsSafe.preferences); + jqUnit.assertEquals("The prefs safe has been associated with the GPII key", response.gpiiKeyDetails.prefsSafeId, response.prefsSafe.id); + + var unchangedOrigGpiiKeyFields = fluid.censorKeys(that.originalData.gpiiKeyDetails, ["prefsSafeId", "prefsSetId", "timestampUpdated"]); + var unchangedGpiiKeyFields = fluid.censorKeys(response.gpiiKeyDetails, ["prefsSafeId", "prefsSetId", "timestampUpdated"]); + jqUnit.assertDeepEq("Other GPII key values are unchanged", unchangedOrigGpiiKeyFields, unchangedGpiiKeyFields); +}; diff --git a/tests/web/html/all-tests.html b/tests/web/html/all-tests.html index bc8437a9e..ba535b02c 100644 --- a/tests/web/html/all-tests.html +++ b/tests/web/html/all-tests.html @@ -24,7 +24,6 @@ "/gpii/node_modules/matchMakerFramework/test/html/MatchMakerUtilitiesTest.html", "/gpii/node_modules/matchMakerFramework/test/html/InverseCapabilitiesTest.html", "/gpii/node_modules/ontologyHandler/test/html/OntologyHandlerUtilitiesTest.html", - "/gpii/node_modules/preferencesServer/test/html/PreferencesServiceTests.html", "/gpii/node_modules/processReporter/test/web/html/ProcessesBridgeTest.html", "/gpii/node_modules/processReporter/test/web/html/ProcessReporterTest.html", "/gpii/node_modules/settingsHandlers/test/web/html/LaunchHandlerTest.html", From 2f8b396121c5f539be7a1c58fe0b167b86aaf40e Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Tue, 6 Nov 2018 10:33:08 -0800 Subject: [PATCH 25/72] GPII-2966 Minor fix to use strict and upping gpii-pouchdb --- .../preferencesServer/test/preferencesServiceTests.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js index d5bc0bf28..d6ead4f91 100644 --- a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js +++ b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js @@ -7,7 +7,7 @@ compliance with this License. You may obtain a copy of the License at https://github.com/GPII/universal/blob/master/LICENSE.txt */ -use "strict"; +"use strict"; var fluid = require("infusion"), jqUnit = fluid.require("node-jqunit", require, "jqUnit"), diff --git a/package.json b/package.json index 68e463426..1cdbd75f3 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "fluid-resolve": "1.3.0", "glob": "7.1.3", "@google-cloud/trace-agent": "3.2.1", - "gpii-pouchdb": "1.0.12", + "gpii-pouchdb": "1.0.13-dev.20181102T155124Z.9120d82", "gpii-express-user": "https://github.com/sgithens/gpii-express-user.git#a6014a987c03fc6674121e4348d7264ca85d2dd9", "infusion": "3.0.0-dev.20181017T162149Z.787f7d5e5", "json5": "2.1.0", From 203a62f521f374f974d41af91b33d76e58d22a9e Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Tue, 6 Nov 2018 17:58:33 -0800 Subject: [PATCH 26/72] GPII-2966 Backing gpii-pouchdb back to 1.0.12 for now --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1cdbd75f3..68e463426 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "fluid-resolve": "1.3.0", "glob": "7.1.3", "@google-cloud/trace-agent": "3.2.1", - "gpii-pouchdb": "1.0.13-dev.20181102T155124Z.9120d82", + "gpii-pouchdb": "1.0.12", "gpii-express-user": "https://github.com/sgithens/gpii-express-user.git#a6014a987c03fc6674121e4348d7264ca85d2dd9", "infusion": "3.0.0-dev.20181017T162149Z.787f7d5e5", "json5": "2.1.0", From 9fa93fd39d6cd931ac812db1118d97f72efb1ca3 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Thu, 15 Nov 2018 11:08:04 -0800 Subject: [PATCH 27/72] GPII-2966 Minor changes from PR Review --- documentation/DataModel.md | 6 +++--- .../gpii-db-operation/src/DbDataStore.js | 11 ++++------- .../preferencesServer/src/preferencesService.js | 12 ++++++------ 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/documentation/DataModel.md b/documentation/DataModel.md index be480612f..7090508a3 100644 --- a/documentation/DataModel.md +++ b/documentation/DataModel.md @@ -30,7 +30,6 @@ An example document: "schemaVersion": "0.1", "prefsSafeType": "user", "name": null, - "password": null, "email": null, "preferences": { "flat": { @@ -55,7 +54,7 @@ An example document: ### Key-in Documents When users key-in to the GPII using a USB stick, NFC card, or other mechanism, the unique `gpiiKey` on the device will -be matched to the CouchDB `id` on a document with type `gpiiKey`. This document contains the important fields `prefsSafeId` +be matched to the CouchDB `_id` on a document with type `gpiiKey`. This document contains the important fields `prefsSafeId` and `prefsSetId` linking it to the safe, and to a specific preference set within that safe to key in with. An example document: @@ -80,7 +79,8 @@ In order to have full permissions to edit all aspects of their preferences safe, username and password. The current implementation of this is backed by the `gpii-express-user` library which creates records in the same format as native CouchDB accounts and manages password hashing, unlocking, etc. In order to avoid making changes to this external library, we introduce a document type 'gpiiCloudSafeCredential' which tracks the native -record that is created by `gpii-express-user`. +record that is created by `gpii-express-user`. Note that the `gpiiExpressuserId` entries are prefixed with `org.couch.db.user:` +which is the convention for both internal CouchDB users and users created with gpii-express-user. An example document: diff --git a/gpii/node_modules/gpii-db-operation/src/DbDataStore.js b/gpii/node_modules/gpii-db-operation/src/DbDataStore.js index 2b22b68f1..308388857 100644 --- a/gpii/node_modules/gpii-db-operation/src/DbDataStore.js +++ b/gpii/node_modules/gpii-db-operation/src/DbDataStore.js @@ -100,9 +100,9 @@ fluid.defaults("gpii.dbOperation.dbDataStore", { expressUserSafeLoginLookup: { type: "gpii.dbOperation.dbDataSource", options: { - requestUrl: "/_design/views/_view/expressUserSafeLoginLookup?include_docs=true&key=%22%userRecordId%22", + requestUrl: "/_design/views/_view/expressUserSafeLoginLookup?include_docs=true&key=%22%gpiiExpressUserId%22", termMap: { - userRecordId: "%userRecordId" + gpiiExpressUserId: "%gpiiExpressUserId" }, rules: { readPayload: { @@ -115,9 +115,6 @@ fluid.defaults("gpii.dbOperation.dbDataStore", { type: "gpii.dbOperation.dbDataSource", options: { requestUrl: "/_design/views/_view/listPrefsSafes", - termMap: { - // gpiiKey: "%gpiiKey" - }, rules: { readPayload: { "": "" @@ -263,9 +260,9 @@ fluid.defaults("gpii.dbOperation.dbDataStore", { args: [ "{that}.expressUserSafeLoginLookup", { - userRecordId: "{arguments}.0" + expressUserSafeLoginLookup: "{arguments}.0" }, - "userRecordId" + "expressUserSafeLoginLookup" ] }, findClientByOauth2ClientId: { diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index 380ac7ed7..94d8e7476 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -164,10 +164,10 @@ var fluid = fluid || require("infusion"); * * @param {Object} that - Instance of `gpii.preferencesServer.preferencesService`. * @param {Object} options - Data used to create the new credentials. - * @param {Object} options.prefsSafeId - Id for the preferences safe we are adding + * @param {String} options.prefsSafeId - Id for the preferences safe we are adding * credentials to. - * @param {Object} options.username - Login username for these credentials. - * @param {Object} options.password - Password for these new credentials. + * @param {String} options.username - Login username for these credentials. + * @param {String} options.password - Password for these new credentials. * @return {Promise} Promise containing the new cloud credentials document. */ gpii.preferencesServer.preferencesService.cloudSafeCredCreate = function (that, options) { @@ -182,12 +182,12 @@ var fluid = fluid || require("infusion"); * 2. If successful, take the gpii-express-user.id and look up a cloud credentials doc for it. * 3. Fetch the Safe for that and return it. * - * In the future the number of couch calls may by optimized. + * TODO: In the future the number of couch calls may by optimized. * * @param {Object} that - Instance of `gpii.preferencesServer.preferencesService`. * @param {Object} options - Data used to unlock the safe. - * @param {Object} options.username - Username to unlock the Preferences Safe. - * @param {Object} options.password - Password to unlock the Preferences Safe. + * @param {String} options.username - Username to unlock the Preferences Safe. + * @param {String} options.password - Password to unlock the Preferences Safe. * @return {Promise} Returns a promise containing either the unlocked Preferences Safe * record, or an error payload with a message. */ From ff1a8bdf7fd4b22776c3955efc368caa8aa75d50 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Thu, 15 Nov 2018 12:01:51 -0800 Subject: [PATCH 28/72] GPII-2966 Updated version of gpii-express-user --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ee63d676e..34e13ffd6 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "fluid-resolve": "1.3.0", "glob": "7.1.3", "@google-cloud/trace-agent": "3.2.1", - "gpii-express-user": "https://github.com/sgithens/gpii-express-user.git#a6014a987c03fc6674121e4348d7264ca85d2dd9", + "gpii-express-user": "1.0.1", "gpii-pouchdb": "1.0.13-dev.20181102T155124Z.9120d82", "infusion": "3.0.0-dev.20181017T162149Z.787f7d5e5", "json5": "2.1.0", From 33b28aa9a8e243ed43862eb9c6455e5e4c71f113 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Thu, 15 Nov 2018 12:08:05 -0800 Subject: [PATCH 29/72] GPII-2966 Adding preferencesServiceTests to all-tests --- tests/all-tests.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/all-tests.js b/tests/all-tests.js index 0b910a1ee..b55926def 100644 --- a/tests/all-tests.js +++ b/tests/all-tests.js @@ -71,6 +71,7 @@ var testIncludes = [ "../gpii/node_modules/preferencesServer/test/preferencesServerTests.js", "../gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js", "../gpii/node_modules/preferencesServer/test/prefsSafesTests.js", + "../gpii/node_modules/preferencesServer/test/preferencesServiceTests.js", "../gpii/node_modules/settingsHandlers/test/JSONSettingsHandlerTests.js", "../gpii/node_modules/settingsHandlers/test/XMLSettingsHandlerTests.js", "../gpii/node_modules/settingsHandlers/test/INISettingsHandlerTests.js", From 604b2a1a0f4dd2531d24fed7c66860ac0a369e89 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Sat, 17 Nov 2018 07:35:59 -0800 Subject: [PATCH 30/72] GPII-2966 Fixed termmap param name --- gpii/node_modules/gpii-db-operation/src/DbDataStore.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gpii/node_modules/gpii-db-operation/src/DbDataStore.js b/gpii/node_modules/gpii-db-operation/src/DbDataStore.js index 308388857..03114a97b 100644 --- a/gpii/node_modules/gpii-db-operation/src/DbDataStore.js +++ b/gpii/node_modules/gpii-db-operation/src/DbDataStore.js @@ -260,9 +260,9 @@ fluid.defaults("gpii.dbOperation.dbDataStore", { args: [ "{that}.expressUserSafeLoginLookup", { - expressUserSafeLoginLookup: "{arguments}.0" + gpiiExpressUserId: "{arguments}.0" }, - "expressUserSafeLoginLookup" + "gpiiExpressUserId" ] }, findClientByOauth2ClientId: { From 74015c5623d6aebfbf23d979e2f3dcd80f198337 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Mon, 19 Nov 2018 13:38:11 -0800 Subject: [PATCH 31/72] GPII-2966 Fixing error style for return payload --- .../preferencesServer/src/cloudSafeCredHandlers.js | 8 ++++---- .../preferencesServer/test/cloudSafeCredTests.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js b/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js index 3e5f772fb..09bee7b29 100644 --- a/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js +++ b/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js @@ -56,10 +56,10 @@ gpii.preferencesServer.cloudSafeUnlockPost.handler.post = function (prefsService request.events.onSuccess.fire(data); }, function (/* err */) { - request.res.status(401); - request.events.onSuccess.fire({ - statusCode: 401, - message: "Unable to unlock a Preferences Safe with the supplied credentials." + request.events.onError.fire({ + isError: true, + message: "Unable to unlock a Preferences Safe with the supplied credentials.", + statusCode: 401 }); } ); diff --git a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js index f6215316d..ea53f4566 100644 --- a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js +++ b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js @@ -271,7 +271,7 @@ gpii.tests.preferencesServer.cloudSafeCred.unlock.successFixtures = [ password: "notThePassword" }, unlockCloudSafeExpected: { - statusCode: 401, + isError: true, message: "Unable to unlock a Preferences Safe with the supplied credentials." } } From 753b52fecbe50ddf07689cd4b06fa3a5c846dee0 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Mon, 19 Nov 2018 13:44:04 -0800 Subject: [PATCH 32/72] GPII-2966 Minor doco typo --- gpii/node_modules/preferencesServer/src/preferencesService.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index 94d8e7476..6d79a230e 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -157,7 +157,7 @@ var fluid = fluid || require("infusion"); * Handler for creating cloud safe credentials. * * This handler will first fetch the preferences safe to make sure it - * exists and it active. It will then take the username and password and + * exists and is active. It will then take the username and password and * create a new gpii-express-user entry. With that we will then create * the cloudsafe credential document that will contain the ID's of both * the prefssafe and the user record. From e0935e75f139f688296ca26fee47770dd04f64e1 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Tue, 20 Nov 2018 16:01:29 -0800 Subject: [PATCH 33/72] GPII-2966 More tests - Adding test for cloud safe credentials PUT to fail when the cloud safe doesn't exist. - Also fixing the code so this newly added test passes. --- .../gpii-db-operation/src/DbUtils.js | 35 ++++++++++++ .../src/preferencesService.js | 4 ++ .../test/cloudSafeCredTests.js | 53 +++++++++++++++++-- 3 files changed, 87 insertions(+), 5 deletions(-) diff --git a/gpii/node_modules/gpii-db-operation/src/DbUtils.js b/gpii/node_modules/gpii-db-operation/src/DbUtils.js index 4113d1bc7..60d4a392b 100644 --- a/gpii/node_modules/gpii-db-operation/src/DbUtils.js +++ b/gpii/node_modules/gpii-db-operation/src/DbUtils.js @@ -36,3 +36,38 @@ gpii.dbOperation.composeError = function (error, termMap) { gpii.dbOperation.getCurrentTimestamp = function () { return new Date().toISOString(); }; + +/** + * This function looks at an item to make sure it exists properly, useful for + * looking at the results of a `{dataStore}.findById` or similar operation. If + * the item exists as it should, a promise resolved with the item is + * returned, otherwise a rejected promise is returned with the supplied `errorMessage`. + * + * The current criteria for validity is that the item is not undefined and has + * the `type` that is supplied in the arguments. + * + * @param {Object} item Item, mostly a return from another API or CouchDB call + * that we are checking to make sure it's of the appropriate type. + * @param {String} type The `type` that the item should be of. This is to + * follow the convention we have for CouchDB records where each record has a `type` + * member. + * @param {String} errorMessage If this isn't the appropriate type, this message will be + * included in the promise rejection payload. + * @return {fluid.promise} Promise, when the item is valid is resolves with the + * original item. When the item is not valid, it rejects with an error payload including + * the supplied `errorMessage`. + */ +gpii.dbOperation.verifyExists = function (item, type, errorMessage) { + var togo = fluid.promise(); + if (item && item.type === type) { + togo.resolve(item); + } + else { + togo.reject({ + isError: true, + message: errorMessage, + statusCode: 404 + }); + } + return togo; +}; diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index 6d79a230e..d60a5a816 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -114,6 +114,10 @@ var fluid = fluid || require("infusion"); args: ["{arguments}.0"], namespace: "findById" }, + { + func: "gpii.dbOperation.verifyExists", + args: ["{arguments}.0", "prefsSafe", "The prefs safe does not exist"] + }, { func: "{expressUserUtils}.createNewUser", args: [{username: "{arguments}.1.username", password: "{arguments}.1.password"}], diff --git a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js index ea53f4566..735160984 100644 --- a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js +++ b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js @@ -132,11 +132,6 @@ gpii.tests.preferencesServer.cloudSafeCred.put.successFixtures = [ username: "prefsTestUsername", password: "testPassword" }, - putCloudCredBodyExpected: { - - }, - getCloudCredFullSafeExpected: { - }, unlockCloudSafePost: { username: "prefsTestUsername", password: "testPassword" @@ -199,6 +194,51 @@ gpii.tests.preferencesServer.cloudSafeCred.put.successFixtures = [ } ]; +gpii.tests.preferencesServer.cloudSafeCred.put.buildFailureTestDef = function (fixture) { + return { + name: fixture.name, + config: gpii.tests.preferencesServer.config, + components: { + putCloudCred: { + type: "kettle.test.request.http", + options: { + path: "/add-cloud-credentials/" + fixture.url, + method: "PUT", + port: 8081, + termMap: { + prefsSafeId: fixture.prefsSafeId + } + } + } + }, + sequence: [{ + func: "{putCloudCred}.send", + args: fixture.putCloudCredBody + }, { + event: "{putCloudCred}.events.onComplete", + listener: "gpii.tests.preferencesServer.testResponse", + args: ["{arguments}.0", fixture.failedCreateExpected, "{putCloudCred}.nativeResponse.statusCode", fixture.expectedStatusCode] + }] + }; +}; + +gpii.tests.preferencesServer.cloudSafeCred.put.failureFixtures = [ + { + name: "PUT FAIL: Cannot add a cloudSafe credential to a safe that doesn't exist", + expectedStatusCode: 404, + prefsSafeId: "prefsSafe-1000", + url: "%prefsSafeId", + putCloudCredBody: { + username: "prefsTestUsername", + password: "testPassword" + }, + failedCreateExpected: { + isError: true, + message: "The prefs safe does not exist" + } + } +]; + /////////////// TEST Unlocking a Prefs Safe using a Cloud Safe Login ///////////// fluid.registerNamespace("gpii.tests.preferencesServer.cloudSafeCred.unlock"); @@ -284,6 +324,9 @@ gpii.tests.preferencesServer.cloudSafeCred.testMap = [ { }, { build: gpii.tests.preferencesServer.cloudSafeCred.unlock.buildSuccessTestDef, fixtures: gpii.tests.preferencesServer.cloudSafeCred.unlock.successFixtures +}, { + build: gpii.tests.preferencesServer.cloudSafeCred.put.buildFailureTestDef, + fixtures: gpii.tests.preferencesServer.cloudSafeCred.put.failureFixtures }]; gpii.tests.preferencesServer.cloudSafeCred.testDefs = fluid.flatten(fluid.transform(gpii.tests.preferencesServer.cloudSafeCred.testMap, function (mapEl) { From fed80675a8c883ec0cc08c903779bcd9cae7da43 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Wed, 21 Nov 2018 10:48:39 -0800 Subject: [PATCH 34/72] GPII-2966 Tests for already used login name --- .../src/preferencesService.js | 27 ++++++++++++++++++- .../test/cloudSafeCredTests.js | 14 ++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index d60a5a816..829ea60a7 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -175,7 +175,32 @@ var fluid = fluid || require("infusion"); * @return {Promise} Promise containing the new cloud credentials document. */ gpii.preferencesServer.preferencesService.cloudSafeCredCreate = function (that, options) { - return fluid.promise.fireTransformEvent(that.events.onCloudSafeCredCreate, options.prefsSafeId, options); + var promiseTogo = fluid.promise(); + fluid.promise.fireTransformEvent(that.events.onCloudSafeCredCreate, options.prefsSafeId, options).then( + promiseTogo.resolve, + function (err) { + // Create a slightly more meaningful error message for the gpii-express-user reject when + // the username is already used. + // { + // "isError": true, + // "message": { + // "error": "conflict", + // "reason": "Document update conflict" + // } + // } + if (err.message && err.message.error === "conflict") { + fluid.log("Error adding cloud safe credential", err); + promiseTogo.reject({ + isError: true, + message: "Unable to create credentials with that username and password combination", + statusCode: 404 + }); + } + else { + promiseTogo.reject(err); + } + }); + return promiseTogo; }; /** diff --git a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js index 735160984..5765a63b4 100644 --- a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js +++ b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js @@ -236,6 +236,20 @@ gpii.tests.preferencesServer.cloudSafeCred.put.failureFixtures = [ isError: true, message: "The prefs safe does not exist" } + }, + { + name: "PUT FAIL: Cannot add a cloudSafe credential with an existing name", + expectedStatusCode: 404, + prefsSafeId: "prefsSafe-1", + url: "%prefsSafeId", + putCloudCredBody: { + username: "prefs7user", + password: "testPassword" + }, + failedCreateExpected: { + isError: true, + message: "Unable to create credentials with that username and password combination" + } } ]; From eac31957f8f2dc0b33ecc329819aaf4189bafe91 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Tue, 27 Nov 2018 11:27:32 -0800 Subject: [PATCH 35/72] GPII-2966 Filling in tests for invokers added to preferences service. --- .../src/preferencesService.js | 12 +-- .../test/cloudSafeCredTests.js | 20 ++-- .../test/data/preferencesServiceUsers.json | 26 +++++ .../test/preferencesServiceTests.js | 100 ++++++++++++++++++ 4 files changed, 143 insertions(+), 15 deletions(-) diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index 829ea60a7..7592461aa 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -113,17 +113,14 @@ var fluid = fluid || require("infusion"); func: "{dataStore}.findById", args: ["{arguments}.0"], namespace: "findById" - }, - { + }, { func: "gpii.dbOperation.verifyExists", args: ["{arguments}.0", "prefsSafe", "The prefs safe does not exist"] - }, - { + }, { func: "{expressUserUtils}.createNewUser", args: [{username: "{arguments}.1.username", password: "{arguments}.1.password"}], namespace: "createNewUser" - }, - { + }, { funcName: "gpii.dbOperation.dbDataStore.addRecord", args: ["{dbDataStore}.saveDataSource", "gpiiCloudSafeCredential", @@ -134,6 +131,9 @@ var fluid = fluid || require("infusion"); gpiiExpressUserId: "{arguments}.0._id" }], namespace: "addRecord" + }, { + funcName: "{dataStore}.findById", + args: ["{arguments}.0.id"] }], onCloudSafeUnlock: [{ func: "{expressUserUtils}.unlockUser", diff --git a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js index 5765a63b4..ab363bd81 100644 --- a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js +++ b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js @@ -42,13 +42,11 @@ gpii.tests.preferencesServer.config = { fluid.registerNamespace("gpii.tests.preferencesServer.cloudSafeCred.put"); /* - * Make sure we got a non-error response from the original create call. + * Test response payload against a subset of a gpiiCloudSafeCred document. */ -gpii.tests.preferencesServer.cloudSafeCred.testCloudSafeCreatePut = function (response /*, expected, receivedStatusCode, expectedStatusCode */) { +gpii.tests.preferencesServer.cloudSafeCred.testCloudSafeCreatePut = function (cloudCredSubset, response) { var data = JSON.parse(response); - jqUnit.assertEquals("Should be ok/true", data.ok, true); - jqUnit.assertNotUndefined("Should have an id", data.id); - jqUnit.assertNotUndefined("Should have a revision", data.rev); + jqUnit.assertLeftHand("Returned cred document should have the following: ", cloudCredSubset, data); }; /* @@ -65,7 +63,6 @@ gpii.tests.preferencesServer.cloudSafeCred.put.buildSuccessTestDef = function (f var expectedStatusCode = fixture.expectedStatusCode || 200; return { name: fixture.name, - expect: 8, config: gpii.tests.preferencesServer.config, components: { putCloudCred: { @@ -105,7 +102,7 @@ gpii.tests.preferencesServer.cloudSafeCred.put.buildSuccessTestDef = function (f }, { event: "{putCloudCred}.events.onComplete", listener: "gpii.tests.preferencesServer.cloudSafeCred.testCloudSafeCreatePut", - args: ["{arguments}.0", fixture.putCloudCredBodyExpected, "{putCloudCred}.nativeResponse.statusCode", expectedStatusCode] + args: [fixture.cloudCredSubset, "{arguments}.0"] }, { func: "{getFullSafe}.send" }, { @@ -132,6 +129,11 @@ gpii.tests.preferencesServer.cloudSafeCred.put.successFixtures = [ username: "prefsTestUsername", password: "testPassword" }, + cloudCredSubset: { + type: "gpiiCloudSafeCredential", + prefsSafeId: "prefsSafe-1", + gpiiExpressUserId: "org.couch.db.user:prefsTestUsername" + }, unlockCloudSafePost: { username: "prefsTestUsername", password: "testPassword" @@ -224,7 +226,7 @@ gpii.tests.preferencesServer.cloudSafeCred.put.buildFailureTestDef = function (f gpii.tests.preferencesServer.cloudSafeCred.put.failureFixtures = [ { - name: "PUT FAIL: Cannot add a cloudSafe credential to a safe that doesn't exist", + name: "Unsuccessful PUT: Cannot add a cloudSafe credential to a safe that doesn't exist", expectedStatusCode: 404, prefsSafeId: "prefsSafe-1000", url: "%prefsSafeId", @@ -238,7 +240,7 @@ gpii.tests.preferencesServer.cloudSafeCred.put.failureFixtures = [ } }, { - name: "PUT FAIL: Cannot add a cloudSafe credential with an existing name", + name: "Unsuccessful PUT: Cannot add a cloudSafe credential with an existing name", expectedStatusCode: 404, prefsSafeId: "prefsSafe-1", url: "%prefsSafeId", diff --git a/gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json b/gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json index 6fa2aa7dd..98d412537 100644 --- a/gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json +++ b/gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json @@ -76,5 +76,31 @@ }, "timestampCreated": "2017-12-01T18:43:32.889Z", "timestampUpdated": null + }, + { + "_id": "prefsSafe-7", + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": null, + "password": null, + "email": null, + "preferences": { + "flat": { + "name": "bit of stuff", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/onScreenKeyboard/enabled": true + }, + "metadata": [] + } + }, + "metadata": [] + } + }, + "timestampCreated": "2017-12-14T19:55:11.641Z", + "timestampUpdated": null } ] diff --git a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js index d6ead4f91..4e5302da1 100644 --- a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js +++ b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js @@ -435,3 +435,103 @@ gpii.tests.preferencesServer.preferencesService.verifyNewPrefsSafeForUpdate = fu var unchangedGpiiKeyFields = fluid.censorKeys(response.gpiiKeyDetails, ["prefsSafeId", "prefsSetId", "timestampUpdated"]); jqUnit.assertDeepEq("Other GPII key values are unchanged", unchangedOrigGpiiKeyFields, unchangedGpiiKeyFields); }; + +// Tests for cloudSafeCredCreate +gpii.tests.preferencesServer.preferencesService.cloudSafeCredCreate = [ + // Successful create + { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", + name: "cloudSafeCredCreate: Successful create", + sequence: [{ + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["cloudSafeCredCreate", [{prefsSafeId: "prefsSafe-1", username: "myUserName", password: "supersecret"}]], + resolve: "jqUnit.assertLeftHand", + resolveArgs: ["Newly created credentials document", { + prefsSafeId: "prefsSafe-1", + gpiiExpressUserId: "org.couch.db.user:myUserName", + type: "gpiiCloudSafeCredential" + }, "{arguments}.0"] + }, { + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["cloudSafeUnlock", [{username: "myUserName", password: "supersecret"}]], + resolve: "jqUnit.assertDeepEq", + resolveArgs: ["Should have returned prefsSafe-1: ", "prefsSafe-1", "{arguments}.0.id"] + }] + }, + // Error: Prefs Safe doesn't exist + { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", + name: "cloudSafeUnlock: Error: Prefs Safe doesn't exist", + sequence: [{ + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["cloudSafeCredCreate", [{prefsSafeId: "prefsSafe-1999", username: "myUserName", password: "supersecret"}]], + reject: "jqUnit.assertLeftHand", + rejectArgs: ["Error message saying the prefs safe does not exist.", { + "isError": true, + "message": "The prefs safe does not exist" + }, "{arguments}.0"] + }] + }, + // Error: Name already used + { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", + name: "cloudSafeUnlock: Error: Name already used", + sequence: [{ + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["cloudSafeCredCreate", [{prefsSafeId: "prefsSafe-1", username: "prefs7user", password: "supersecret"}]], + reject: "jqUnit.assertLeftHand", + rejectArgs: ["Error indicating bad username and password for new credentials.", { + "isError": true, + "message": "Unable to create credentials with that username and password combination" + }, "{arguments}.0"] + }] + } +]; + +gpii.test.bootstrapServer(gpii.tests.preferencesServer.preferencesService.cloudSafeCredCreate); + +// Tests for cloudSafeUnlock +gpii.tests.preferencesServer.preferencesService.cloudSafeUnlock = [ + { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", + name: "cloudSafeUnlock: Unlock a safe successfully", + sequence: [{ + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["cloudSafeUnlock", [{username: "prefs7user", password: "testPassword"}]], + resolve: "jqUnit.assertDeepEq", + resolveArgs: ["Should have returned prefsSafe-7: ", "prefsSafe-7", "{arguments}.0.id"] + }] + }, + { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", + name: "cloudSafeUnlock: Fail to unlock with a bad username/password", + sequence: [{ + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["cloudSafeUnlock", [{username: "prefs7user", password: "wrongPassword"}]], + reject: "jqUnit.assertDeepEq", + rejectArgs: ["Should fail with message", "Unable to unlock a Preferences Safe with the supplied credentials.", "{arguments}.0.message"] + }] + } +]; + +gpii.test.bootstrapServer(gpii.tests.preferencesServer.preferencesService.cloudSafeUnlock); From 4a5aaaebfba7c53d6395212773af860925a30bd9 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Thu, 13 Dec 2018 20:18:11 -0800 Subject: [PATCH 36/72] GPII-2966 Changes from PR and more RESTful PrefsSafe Endpoints --- .../src/preferencesServer.js | 7 +- .../src/preferencesService.js | 108 ++++++- .../src/prefsSafesHandlers.js | 48 +++- .../test/preferencesServerTests.js | 6 + .../test/preferencesServiceTests.js | 111 ++++++++ .../preferencesServer/test/prefsSafesTests.js | 268 +++++++++++++++++- 6 files changed, 526 insertions(+), 22 deletions(-) diff --git a/gpii/node_modules/preferencesServer/src/preferencesServer.js b/gpii/node_modules/preferencesServer/src/preferencesServer.js index 52277e862..d11b1ce6a 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesServer.js +++ b/gpii/node_modules/preferencesServer/src/preferencesServer.js @@ -64,7 +64,12 @@ fluid.defaults("gpii.preferencesServer", { method: "get", type: "gpii.preferencesServer.prefsSafeWithKeysGet.handler" }, - prefsSafeSave: { + createPrefsSafe: { + route: "/prefssafe", + method: "post", + type: "gpii.preferencesServer.prefsSafePost.handler" + }, + updatePrefsSafe: { route: "/prefssafe/:prefsSafeId", method: "put", type: "gpii.preferencesServer.prefsSafePut.handler" diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index 7592461aa..ce9384224 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -16,7 +16,8 @@ var fluid = fluid || require("infusion"); (function () { "use strict"; - var gpii = fluid.registerNamespace("gpii"); + var gpii = fluid.registerNamespace("gpii"), + $ = fluid.registerNamespace("jQuery"); require("gpii-express-user"); fluid.defaults("gpii.preferencesServer.preferencesService", { @@ -45,7 +46,10 @@ var fluid = fluid || require("infusion"); }, invokers: { // TODO check type == prefsSafe - getPrefsSafe: "{dataStore}.findById", + getPrefsSafe: { + funcName: "gpii.preferencesServer.preferencesService.getPrefsSafe", + args: ["{dataStore}", "{arguments}.0"] + }, getPrefsSafeList: { func: "{dataStore}.findPrefsSafeList", args: ["{arguments}.0"] @@ -57,6 +61,14 @@ var fluid = fluid || require("infusion"); args: ["{dataStore}.findPrefsSafeByGpiiKey", "{arguments}.0"] // gpiiKey }, + addPrefsSafe: { + funcName: "gpii.preferencesServer.preferencesService.addPrefsSafe", + args: ["{that}", "{dataStore}", "{arguments}.0"] + }, + updatePrefsSafe: { + funcName: "gpii.preferencesServer.preferencesService.updatePrefsSafe", + args: ["{that}", "{dataStore}", "{arguments}.0"] + }, createPreferences: { funcName: "gpii.preferencesServer.preferencesService.createPreferences", args: ["{that}", "{arguments}.0", "{arguments}.1"] @@ -157,6 +169,98 @@ var fluid = fluid || require("infusion"); noUpdateOnSnapset: "Cannot update: GPII key \"%gpiiKey\" is a snapset" }); + /** + * Returns a preferences safe using it's id. If the safe is not found an error object + * is returned. + * + * @param {Object} dataStore - Instance of `gpii.dbOperation.dataStore` + * @param {String} prefsSafeId Prefs Safe ID + * @return {Promise} Returns a promise resolving with the preferences safe, + * or rejecting with an error payload containing an error `message`. + */ + gpii.preferencesServer.preferencesService.getPrefsSafe = function (dataStore, prefsSafeId) { + var promiseTogo = fluid.promise(); + dataStore.findById(prefsSafeId).then( + function (data) { + if ($.isEmptyObject(data) || data.type !== "prefsSafe") { + promiseTogo.reject({ + isError: true, + message: "Cannot lookup prefsSafe", + statusCode: 404 + }) + } + else { + promiseTogo.resolve(data); + } + }, + function (err) { + fluid.log("Error looking up prefsSafe: ", err); + promiseTogo.reject({ + isError: true, + message: "Error fetching prefsSafe", + statusCode: 500 + }) + } + ); + return promiseTogo; + } + + /** + * Adds a new preferences safe to CouchDB using the preferences safe format + * minus the `id`, `timestampCreated`, and `timestampUpdated` properties. + * + * @param {Object} that - Instance of `gpii.preferencesServer.preferencesService`. + * @param {Object} dataStore - Instance of `gpii.dbOperation.dataStore` + * @return {Promise} Returns a promise resolving with the newly created + * preferences safe, or rejecting with an error payload containing an error `message`. + */ + gpii.preferencesServer.preferencesService.addPrefsSafe = function (that, dataStore, prefsSafeData) { + var promiseTogo = fluid.promise(); + if (prefsSafeData.type !== "prefsSafe") { + promiseTogo.reject({ + isError: true, + message: "Payload needs to have a type of `prefsSafe`." + }); + } + else { + dataStore.addPrefsSafe(prefsSafeData).then( + function (updatedReturn) { + that.getPrefsSafe(updatedReturn.id).then(promiseTogo.resolve, promiseTogo.reject); + }, + promiseTogo.reject); + }; + return promiseTogo; + }; + + /** + * Updates a preferences safe in CouchDB. + * + * @param {Object} that - Instance of `gpii.preferencesServer.preferencesService`. + * @param {Object} dataStore Instance of `gpii.dbOperation.dataStore` + * @return {Promise} Returns a promise resolving with the newly created + * preferences safe, or rejecting with an error payload containing an error `message`. + */ + gpii.preferencesServer.preferencesService.updatePrefsSafe = function (that, dataStore, prefsSafeData) { + var promiseTogo = fluid.promise(); + if (!prefsSafeData.id || prefsSafeData.type !== "prefsSafe") { + promiseTogo.reject({ + isError: true, + message: "Payload needs to have an id and type of `prefsSafe`." + }) + } + else { + dataStore.updatePrefsSafe(prefsSafeData.id, prefsSafeData).then( + function (updatedReturn) { + that.getPrefsSafe(prefsSafeData.id).then( + function (finalData) { + promiseTogo.resolve(finalData); + }, promiseTogo.reject); + }, + promiseTogo.reject); + } + return promiseTogo; + }; + /** * Handler for creating cloud safe credentials. * diff --git a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js index 294cf4b97..06cc70eb1 100644 --- a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js +++ b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js @@ -58,7 +58,10 @@ fluid.defaults("gpii.preferencesServer.findKeysForPrefsSafe.handler", { }); gpii.preferencesServer.findKeysForPrefsSafe.handler.getKeysForPrefsSafe = function (prefsService, preferencesServer, request, prefsSafeId) { - prefsService.getKeysForPrefsSafe(prefsSafeId).then(request.events.onSuccess.fire, request.events.onError.fire); + prefsService.getPrefsSafe(prefsSafeId).then( + function (prefsSafeData) { + prefsService.getKeysForPrefsSafe(prefsSafeId).then(request.events.onSuccess.fire, request.events.onError.fire); + }, request.events.onError.fire); }; fluid.defaults("gpii.preferencesServer.prefsSafeWithKeysGet.handler", { @@ -72,28 +75,49 @@ fluid.defaults("gpii.preferencesServer.prefsSafeWithKeysGet.handler", { }); gpii.preferencesServer.prefsSafeWithKeysGet.handler.get = function (prefsService, preferencesServer, request, prefsSafeId) { - prefsService.getKeysForPrefsSafe(prefsSafeId).then(function (data) { - prefsService.dataStore.findById(prefsSafeId).then(function (prefsSafeData) { - request.events.onSuccess.fire({ - prefsSafe: prefsSafeData, - keys: data.rows - }); + prefsService.getPrefsSafe(prefsSafeId).then( + function (prefsSafeData) { + prefsService.getKeysForPrefsSafe(prefsSafeId).then( + function (keysData) { + request.events.onSuccess.fire({ + prefsSafe: prefsSafeData, + keys: keysData.rows + }); + }, + request.events.onError.fire); }, request.events.onError.fire); - }, request.events.onError.fire); +}; + +fluid.defaults("gpii.preferencesServer.prefsSafePost.handler", { + gradeNames: ["kettle.request.http"], + invokers: { + handleRequest: { + funcName: "gpii.preferencesServer.prefsSafePost.handler.updatePrefsSafe", + args: ["{preferencesService}", "{that}", "{that}.req.body"] + } + } +}); + +gpii.preferencesServer.prefsSafePost.handler.updatePrefsSafe = function (preferencesService, request, prefsSafe) { + preferencesService.addPrefsSafe(prefsSafe).then( + request.events.onSuccess.fire, + request.events.onError.fire); }; fluid.defaults("gpii.preferencesServer.prefsSafePut.handler", { gradeNames: ["kettle.request.http"], invokers: { handleRequest: { - funcName: "gpii.preferencesServer.prefsSafePut.handler.savePrefsSafe", - args: ["{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.body"] + funcName: "gpii.preferencesServer.prefsSafePut.handler.updatePrefsSafe", + args: ["{preferencesService}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.body"] } } }); -gpii.preferencesServer.prefsSafePut.handler.savePrefsSafe = function (preferencesServer, request, prefsSafeId, prefsSafe) { - preferencesServer.dataStore.updatePrefsSafe(prefsSafeId, prefsSafe).then(request.events.onSuccess.fire, request.events.onError.fire); +gpii.preferencesServer.prefsSafePut.handler.updatePrefsSafe = function (preferencesService, request, prefsSafeId, prefsSafe) { + preferencesService.updatePrefsSafe(prefsSafe).then( + request.events.onSuccess.fire, + request.events.onError.fire); }; diff --git a/gpii/node_modules/preferencesServer/test/preferencesServerTests.js b/gpii/node_modules/preferencesServer/test/preferencesServerTests.js index 646e1b977..02871af26 100644 --- a/gpii/node_modules/preferencesServer/test/preferencesServerTests.js +++ b/gpii/node_modules/preferencesServer/test/preferencesServerTests.js @@ -38,6 +38,12 @@ gpii.tests.preferencesServer.testResponse = function (response, expected, receiv jqUnit.assertDeepEq("Response is correct", expected, retrievedData); }; +gpii.tests.preferencesServer.testResponseLeftHand = function (response, expected, receivedStatusCode, expectedStatusCode) { + var retrievedData = JSON.parse(response); + jqUnit.assertEquals("Response status code is expected", expectedStatusCode, receivedStatusCode); + jqUnit.assertLeftHand("Response is correct", expected, retrievedData); +}; + // TESTING preferencesServer GET functionality fluid.registerNamespace("gpii.tests.preferencesServer.get"); diff --git a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js index 4e5302da1..1eb33e9a6 100644 --- a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js +++ b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js @@ -171,6 +171,27 @@ fluid.defaults("gpii.tests.preferencesServer.preferencesService.pouchTestCaseHol } }); +// A pouch testcase holder for tests that depend on zero preference safes and keys +fluid.defaults("gpii.tests.preferencesServer.preferencesService.emptySet.pouchTestCaseHolder", { + gradeNames: ["gpii.test.pouch.pouchTestCaseHolder"], + mergePolicy: { + "pouchConfig.databases.gpii.data": "replace" + }, + pouchConfig: { + databases: { + gpii: { + data: [ + // "%preferencesServer/test/data/gpiiKeys.json", + // "%preferencesServer/test/data/gpiiCloudSafeCred.json", + "%preferencesServer/test/data/userLookup.json", + // "%preferencesServer/test/data/preferencesServiceUsers.json", + "%gpii-universal/testData/dbData/views.json" + ] + } + } + } +}); + gpii.tests.preferencesServer.preferencesService.getPreferencesByGpiiKey = [ { config: { @@ -535,3 +556,93 @@ gpii.tests.preferencesServer.preferencesService.cloudSafeUnlock = [ ]; gpii.test.bootstrapServer(gpii.tests.preferencesServer.preferencesService.cloudSafeUnlock); + +// Tests for creating and updating prefs safes +gpii.tests.preferencesServer.preferencesService.createUpdatePrefsSafeData = { + newPrefsSafe: { + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": "User 200", + "preferences": { + "flat": { + "name": "200 bits of stuff", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/onScreenKeyboard/enabled": true + }, + "metadata": [] + } + }, + "metadata": [] + } + } + }, + updatedPrefsSafe7: { + "id": "prefsSafe-7", + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": "Prefs Seven", + "password": null, + "email": null, + "preferences": { + "flat": { + "name": "bit of stuff", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/onScreenKeyboard/enabled": true + }, + "metadata": [] + } + }, + "metadata": [] + } + }, + "timestampCreated": "2017-12-14T19:55:11.641Z", + // This value will be different "timestampUpdated": null + } +}; + +gpii.tests.preferencesServer.preferencesService.createSavePrefsSafe = [ + { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", + name: "createSavePrefsSafe: Add a new safe.", + sequence: [{ + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["addPrefsSafe", + [gpii.tests.preferencesServer.preferencesService.createUpdatePrefsSafeData.newPrefsSafe]], + resolve: "jqUnit.assertLeftHand", + resolveArgs: ["Should have same structure as created: ", + gpii.tests.preferencesServer.preferencesService.createUpdatePrefsSafeData.newPrefsSafe, + "{arguments}.0"] + }] + }, + { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", + name: "updateExistingSafe: Change the name of prefsSafe 7", + sequence: [{ + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["updatePrefsSafe", + [gpii.tests.preferencesServer.preferencesService.createUpdatePrefsSafeData.updatedPrefsSafe7]], + resolve: "jqUnit.assertLeftHand", + resolveArgs: ["Should have same structure as created: ", + gpii.tests.preferencesServer.preferencesService.createUpdatePrefsSafeData.updatedPrefsSafe7, + "{arguments}.0"] + }] + } +]; + +gpii.test.bootstrapServer(gpii.tests.preferencesServer.preferencesService.createSavePrefsSafe); diff --git a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js index 277f002b8..88b968f28 100644 --- a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js +++ b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js @@ -96,6 +96,19 @@ gpii.tests.preferencesServer.prefsSafes.get.successFixtures = [ } ]; +gpii.tests.preferencesServer.prefsSafes.get.failFixtures = [ + { + name: "GET error: Fetching a safe that does not exist returns an error payload.", + prefsSafeId: "prefsSafe-2999", + url: "%prefsSafeId", + expectedStatusCode: 404, + expected: { + "isError": true, + "message": "Cannot lookup prefsSafe" + } + } +]; + /////////////////////// TESTING prefsSafes with keys GET //////////////////////////// fluid.registerNamespace("gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys"); @@ -126,7 +139,7 @@ gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.buildTestDef = function }] }; }; -fluid.logObjectRenderChars = 2048; + gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.successFixtures = [ { name: "GET: Retieve a payload containing the prefs-safes and all it's associated key/credential records", @@ -183,9 +196,192 @@ gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.successFixtures = [ } ]; - +gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.failFixtures = [ + { + name: "GET: Failure message for a prefs safe that does not exist.", + prefsSafeId: "prefsSafe-3999", + url: "%prefsSafeId", + expectedStatusCode: 404, + expected: { + "isError": true, + "message": "Cannot lookup prefsSafe" + } + } +]; /////////////////////// TESTING prefsSafes PUT (Save) //////////////////////////// +fluid.registerNamespace("gpii.tests.preferencesServer.prefsSafes.putSafe"); + +gpii.tests.preferencesServer.prefsSafes.putSafe.buildTestDef = function (fixture) { + var expectedStatusCode = fixture.expectedStatusCode || 200; + return { + name: fixture.name, + expect: 2, + components: { + getRequest: { + type: "kettle.test.request.http", + options: { + path: "/prefssafe/" + fixture.url, + method: "PUT", + port: 8081, + termMap: { + prefsSafeId: fixture.prefsSafeId + } + } + } + }, + sequence: [{ + func: "{getRequest}.send", + args: fixture.putBody + }, { + event: "{getRequest}.events.onComplete", + listener: "gpii.tests.preferencesServer.testResponseLeftHand", + args: ["{arguments}.0", fixture.expected, "{getRequest}.nativeResponse.statusCode", expectedStatusCode] + }] + }; +}; + +gpii.tests.preferencesServer.prefsSafes.putSafe.successFixtures = [ + { + name: "PUT: Basic update of an existing safe.", + prefsSafeId: "prefsSafe-7", + url: "%prefsSafeId", + putBody: { + "id": "prefsSafe-7", + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": "Prefs Seven", + "password": null, + "email": null, + "preferences": { + "flat": { + "name": "bit of stuff", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/onScreenKeyboard/enabled": false + }, + "metadata": [] + } + }, + "metadata": [] + } + }, + "timestampCreated": "2017-12-14T19:55:11.641Z", + "timestampUpdated": null + }, + expected: { + "id": "prefsSafe-7", + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": "Prefs Seven", + "password": null, + "email": null, + "preferences": { + "flat": { + "name": "bit of stuff", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/onScreenKeyboard/enabled": false + }, + "metadata": [] + } + }, + "metadata": [] + } + }, + "timestampCreated": "2017-12-14T19:55:11.641Z", + // This will be updated "timestampUpdated": null + } + } +]; + +/////////////////////// TESTING prefsSafes Create (POST) //////////////////////////// +fluid.registerNamespace("gpii.tests.preferencesServer.prefsSafes.postSafe"); + +gpii.tests.preferencesServer.prefsSafes.postSafe.buildTestDef = function (fixture) { + var expectedStatusCode = fixture.expectedStatusCode || 200; + return { + name: fixture.name, + expect: 2, + components: { + getRequest: { + type: "kettle.test.request.http", + options: { + path: "/prefssafe", + method: "POST", + port: 8081 + } + } + }, + sequence: [{ + func: "{getRequest}.send", + args: fixture.putBody + }, { + event: "{getRequest}.events.onComplete", + listener: "gpii.tests.preferencesServer.testResponseLeftHand", + args: ["{arguments}.0", fixture.expected, "{getRequest}.nativeResponse.statusCode", expectedStatusCode] + }] + }; +}; + +gpii.tests.preferencesServer.prefsSafes.postSafe.successFixtures = [ + { + name: "POST: Create a new preferences safe.", + url: "%prefsSafeId", + putBody: { + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": "Prefs Three Thousand", + "password": null, + "email": null, + "preferences": { + "flat": { + "name": "bit of stuff", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/onScreenKeyboard/enabled": false + }, + "metadata": [] + } + }, + "metadata": [] + } + } + }, + expected: { + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": "Prefs Three Thousand", + "password": null, + "email": null, + "preferences": { + "flat": { + "name": "bit of stuff", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/onScreenKeyboard/enabled": false + }, + "metadata": [] + } + }, + "metadata": [] + } + } + } + } +]; /////////////////////// TESTING prefsSafes List (GET) //////////////////////////// fluid.registerNamespace("gpii.tests.preferencesServer.prefsSafes.list"); @@ -218,8 +414,6 @@ gpii.tests.preferencesServer.prefsSafes.list.buildTestDef = function (fixture) { gpii.tests.preferencesServer.prefsSafes.list.successFixtures = [ { name: "GET: List Preference Safes", - // prefsSafeId: "prefsSafe-7", - // url: "%prefsSafeId", expected: { total_rows: 7, offset: 0, @@ -278,6 +472,42 @@ gpii.tests.preferencesServer.prefsSafes.list.successFixtures = [ } ]; +// There aren't really any failure scenerios yet for the bare bones prefsSafe list, +// but we can test the case where there are zero safes. +gpii.tests.preferencesServer.prefsSafes.list.emptyDatabase = [ + { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.emptySet.pouchTestCaseHolder", + name: "List the empty set of preference safes", + components: { + getRequest: { + type: "kettle.test.request.http", + options: { + path: "/prefssafes", + method: "GET", + port: 8081 + } + } + }, + sequence: [{ + func: "{getRequest}.send" + }, { + event: "{getRequest}.events.onComplete", + listener: "gpii.tests.preferencesServer.testResponse", + args: ["{arguments}.0", { + "total_rows": 0, + "offset": 0, + "rows": [] + }, "{getRequest}.nativeResponse.statusCode", 200] + }] + } +]; + +gpii.test.bootstrapServer(gpii.tests.preferencesServer.prefsSafes.list.emptyDatabase); + /////////////////////// TESTING prefsSafes List Keys for Safe (GET) //////////////////////////// fluid.registerNamespace("gpii.tests.preferencesServer.prefsSafes.listKeysForSafe"); @@ -341,22 +571,46 @@ gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.successFixtures = [ } ]; -/////////////////////// TESTING prefsSafes Create (POST) //////////////////////////// - -/////////////////////// TESTING prefsSafes PUT (Save) //////////////////////////// +gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.failFixtures = [ + { + name: "GET: Cannot list keys for a safe that doesn't exist.", + prefsSafeId: "prefsSafe-5999", + url: "%prefsSafeId", + expectedStatusCode: 404, + expected: { + "isError": true, + "message": "Cannot lookup prefsSafe" + } + } +]; gpii.tests.preferencesServer.prefsSafes.testMap = [ { build: gpii.tests.preferencesServer.prefsSafes.get.buildTestDef, fixtures: gpii.tests.preferencesServer.prefsSafes.get.successFixtures +}, { + build: gpii.tests.preferencesServer.prefsSafes.get.buildTestDef, + fixtures: gpii.tests.preferencesServer.prefsSafes.get.failFixtures +}, { + build: gpii.tests.preferencesServer.prefsSafes.putSafe.buildTestDef, + fixtures: gpii.tests.preferencesServer.prefsSafes.putSafe.successFixtures +}, { + build: gpii.tests.preferencesServer.prefsSafes.postSafe.buildTestDef, + fixtures: gpii.tests.preferencesServer.prefsSafes.postSafe.successFixtures }, { build: gpii.tests.preferencesServer.prefsSafes.list.buildTestDef, fixtures: gpii.tests.preferencesServer.prefsSafes.list.successFixtures }, { build: gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.buildTestDef, fixtures: gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.successFixtures +}, { + build: gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.buildTestDef, + fixtures: gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.failFixtures }, { build: gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.buildTestDef, fixtures: gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.successFixtures +}, { + build: gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.buildTestDef, + fixtures: gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.failFixtures }]; gpii.tests.preferencesServer.prefsSafes.testDefs = fluid.flatten(fluid.transform(gpii.tests.preferencesServer.prefsSafes.testMap, function (mapEl) { From e6baad47c019e56fa7de85573690b98c6f48f5ad Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Sun, 20 Jan 2019 17:03:31 -0800 Subject: [PATCH 37/72] GPII-2966 Another round of PR updates. Doco, tests, minor idiom updates --- documentation/DataModel.md | 11 +- documentation/PreferencesServer.md | 196 ++++++++++++++++++ .../gpii-db-operation/src/DbUtils.js | 8 +- .../src/preferencesService.js | 62 +++++- .../src/prefsSafesHandlers.js | 12 +- .../test/preferencesServiceTests.js | 50 ++--- .../preferencesServer/test/prefsSafesTests.js | 74 ++++++- 7 files changed, 365 insertions(+), 48 deletions(-) diff --git a/documentation/DataModel.md b/documentation/DataModel.md index 7090508a3..cc76a3e3a 100644 --- a/documentation/DataModel.md +++ b/documentation/DataModel.md @@ -69,7 +69,8 @@ An example document: "revoked": false, "revokedReason": null, "timestampCreated": "2017-12-14T19:55:11.641Z", - "timestampUpdated": null + "timestampUpdated": null, + "timestampRevoked": null } ``` @@ -86,11 +87,11 @@ An example document: ```json { + "_id": "8f3085a7-b65b-4648-9a78-8ac7de766997", "type": "gpiiCloudSafeCredential", "schemaVersion": "0.1", "prefsSafeId": "prefsSafe-7", - "gpiiExpressUserId": "org.couch.db.user:prefs7user", - "_id": "8f3085a7-b65b-4648-9a78-8ac7de766997" + "gpiiExpressUserId": "org.couch.db.user:prefs7user" } ``` @@ -98,6 +99,7 @@ For reference, the internal account record for the above looks as follows: ```json { + "_id": "org.couch.db.user:prefs7user", "name": "prefs7user", "type": "user", "email": null, @@ -108,8 +110,7 @@ For reference, the internal account record for the above looks as follows: "password_scheme": "pbkdf2", "salt": "7cf6961e6ded3bd25732e5466512d116bf9908ba9629d4ed060a03a965e5341d", "derived_key": "e8bd265e7d82fd0f662e9ddaaf2e75acb294da1b", - "verification_code": "618fa72aa62af282704b556e34957a79", - "_id": "org.couch.db.user:prefs7user" + "verification_code": "618fa72aa62af282704b556e34957a79" } ``` diff --git a/documentation/PreferencesServer.md b/documentation/PreferencesServer.md index 384f676a0..3017456a4 100644 --- a/documentation/PreferencesServer.md +++ b/documentation/PreferencesServer.md @@ -349,6 +349,202 @@ There are two important things to note here: to `http://registry.gpii.net/common/fontSize`. Since we do not allow the same setting to be present multiple times in the NP set, the fontSize has been stored in the flat ontology and removed from the ISO24751 block. +### GET /prefssafe/:prefsSafeId + +This end point will return the entire preferences safe, including the embedded preference sets. The URL param is the +`id` of the preferences safe. This will not return any attached keys, credentials, or other records. + +### GET /prefssafe-with-keys/:prefsSafeId + +This endpoint will return the entire preferences safe structure, along with records directory related to it, such +as keys and credentials. A top level object will contain the preferences safe under key `prefsSafe`, and the related +documents under key `keys`. + +Example returned item: + +```json +{ + "prefsSafe": { + "id": "prefsSafeId", + "type": "prefsSafe", + "preferences": { + "etc etc": "..." + }, + "etc etc": "..." + }, + "keys": [ + { + "type": "gpiiCloudSafeCredential", + "etc etc": "..." + }, + { + "type": "gpiiKey", + "etc etc": "..." + } + ] +} +``` + +### POST /prefssafe + +Creates a new preferences safe in the system. Takes a full preferences safe JSON payload, albiet without a `id`. +The returned payload will include the entire preferences safe, including the updated `timestampCreated` field, +and a newly provisioned `id`. + +### PUT /prefssafe/:prefsSafeId + +Updates an existing preferences safe in the database, using the full preferences safe format. Will return the +updated safe, which should include an updated `timestampUpdated` field. + +### GET /prefssafes + +Returns a list of preferences safes, including only basic information about each one. Ideal for building a table +or listing of preferences safes. Each item in the list representing a preferences safe will include `id`, `name`, +`email`, `created`, and `updated`. This endpoint will likely have more options in the future, such as sorting, +paging, etc. + +Example return payload: + +```json +{ + "total_rows": 2, + "offset": 0, + "rows": [ + { + "name": "Alice", + "email": "alice@gpii.net", + "created": "2017-12-14T19:55:11.640Z", + "updated": null, + "id": "prefsSafe-1" + }, + { + "name": null, + "email": null, + "created": "2017-12-14T19:55:11.640Z", + "updated": null, + "id": "prefsSafe-2" + } + ] +} +``` + +### GET /prefssafe-keys/:prefsSafeId + +This will return the associated keys and credentials documents for a given preferences safe, in a `rows` field. +Also included is a `total_rows` and `offset` field, but do note that the `total_rows` field is not accurate as +of the time of writing, and should be ignored. + +An example payload for a particlar safe may be: + +```json +{ + "total_rows": 2, + "offset": 0, + "rows": [{ + "type": "gpiiCloudSafeCredential", + "etc etc": "..." + }, + { + "type": "gpiiKey", + "etc etc": "..." + }] +} +``` + +### POST /prefssafe-key-create + +This endpoint will add a new `gpiiKey` document to the system. There are no URL parameters, but the JSON body takes +3 fields, one of them option. Required are the `prefsSafeId` and `prefsSetId`. These indicate the preferences safe, +and the respective preferences set that this key and token will operate upon. Optionally you can pass in a unique +unused `gpiiKey` to use, otherwise a new one will be generated as part of the process. The new document is returned +upon success. In event of a failure, a standard error document is returned with `isError` true, and a message +detailing the failure. + +#### Example POST + +```json +{ + "prefsSafeId": "prefsSafe-1", + "prefsSetId": "gpii-default", + "gpiiKey": "3B3D3003-9F5F-4B66-98C1-1380EC86DDB1" +} +``` + +Successful return payload: + +```json +{ + "type": "gpiiKey", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-1", + "prefsSetId": "gpii-default", + "revoked": false, + "revokedReason": null, + "timestampCreated": "2017-12-14T19:55:11.640Z", + "timestampUpdated": null +} +``` + +### PUT /add-cloud-credential/:prefsSafeId + +This endpoint will add a new username and password credential set to the preferences safe whose id is specified +in the URL parameter `prefsSafeId`. The body is a JSON payload containing the username and password for the new +credential set. + +#### Example PUT + +URL: `http://preferences.gpii.net/add-cloud-credential/prefsSafe-1` + +The above indicates that the credentials will be added to preferences safe with `id` `prefsSafe-1`. + +putBody: + +```json +{ + "username": "NewLoginUsername", + "password": "v3ry$ecu4e" +} +``` + +### POST /unlock-cloud-safe + +This endpoint allows you to verify if a username and password combination will unclock a preferences safe that +has a matching cloud credential. It requires a username and password, but not a preferences safe ID. If the +unique combination unlocks a particular safe, that preferences safes `prefsSafe` document will be returned. + +#### Example post + +Using the `http://preferences.gpii.net/unlock-cloud-safe` with no parameters we can pass in the username and +password via the body. + +postBody: + +```json +{ + "username": "NewLoginUsername", + "password": "v3ry$ecu4e" +} +``` + +If successful this will return the preferences safe: + +```json +{ + "id": "prefsSafe-1", + "type": "prefsSafe", + "etc etc": "..." +} +``` + +If the username and password do not match a record the following error is returned: + +```json +{ + "isError": true, + "message": "Unable to unlock a Preferences Safe with the supplied credentials." +} +``` + ## Other relevant documentation: * [The Preferences Server Framework](PreferencesServerFramework.md) diff --git a/gpii/node_modules/gpii-db-operation/src/DbUtils.js b/gpii/node_modules/gpii-db-operation/src/DbUtils.js index 60d4a392b..c3c3ce846 100644 --- a/gpii/node_modules/gpii-db-operation/src/DbUtils.js +++ b/gpii/node_modules/gpii-db-operation/src/DbUtils.js @@ -46,14 +46,14 @@ gpii.dbOperation.getCurrentTimestamp = function () { * The current criteria for validity is that the item is not undefined and has * the `type` that is supplied in the arguments. * - * @param {Object} item Item, mostly a return from another API or CouchDB call + * @param {Object} item - Item, mostly a return from another API or CouchDB call * that we are checking to make sure it's of the appropriate type. - * @param {String} type The `type` that the item should be of. This is to + * @param {String} type - The `type` that the item should be of. This is to * follow the convention we have for CouchDB records where each record has a `type` * member. - * @param {String} errorMessage If this isn't the appropriate type, this message will be + * @param {String} errorMessage - If this isn't the appropriate type, this message will be * included in the promise rejection payload. - * @return {fluid.promise} Promise, when the item is valid is resolves with the + * @return {fluid.promise} Promise, when the item is valid is resolves with the * original item. When the item is not valid, it rejects with an error payload including * the supplied `errorMessage`. */ diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index 126205243..d86166ca2 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -79,6 +79,11 @@ var fluid = fluid || require("infusion"); args: ["{that}", "{arguments}.0", "{arguments}.1", "{arguments}.2"] // preferences, gpiiKey, merge }, + // Add a GPII Key to an existing preferences safe + addGpiiKey: { + funcName: "gpii.preferencesServer.preferencesService.addGpiiKey", + args: ["{that}", "{dataStore}", "{arguments}.0"] + }, cloudSafeCredCreate: { funcName: "gpii.preferencesServer.preferencesService.cloudSafeCredCreate", args: ["{that}", "{arguments}.0"] @@ -187,7 +192,7 @@ var fluid = fluid || require("infusion"); isError: true, message: "Cannot lookup prefsSafe", statusCode: 404 - }) + }); } else { promiseTogo.resolve(data); @@ -199,11 +204,11 @@ var fluid = fluid || require("infusion"); isError: true, message: "Error fetching prefsSafe", statusCode: 500 - }) + }); } ); return promiseTogo; - } + }; /** * Adds a new preferences safe to CouchDB using the preferences safe format @@ -211,6 +216,7 @@ var fluid = fluid || require("infusion"); * * @param {Object} that - Instance of `gpii.preferencesServer.preferencesService`. * @param {Object} dataStore - Instance of `gpii.dbOperation.dataStore` + * @param {Object} prefsSafeData - Preferences safe to add to system. * @return {Promise} Returns a promise resolving with the newly created * preferences safe, or rejecting with an error payload containing an error `message`. */ @@ -236,8 +242,9 @@ var fluid = fluid || require("infusion"); * Updates a preferences safe in CouchDB. * * @param {Object} that - Instance of `gpii.preferencesServer.preferencesService`. - * @param {Object} dataStore Instance of `gpii.dbOperation.dataStore` - * @return {Promise} Returns a promise resolving with the newly created + * @param {Object} dataStore - Instance of `gpii.dbOperation.dataStore` + * @param {Object} prefsSafeData - Preferences safe to add to system. + * @return {Promise} Returns a promise resolving with the newly created * preferences safe, or rejecting with an error payload containing an error `message`. */ gpii.preferencesServer.preferencesService.updatePrefsSafe = function (that, dataStore, prefsSafeData) { @@ -246,11 +253,11 @@ var fluid = fluid || require("infusion"); promiseTogo.reject({ isError: true, message: "Payload needs to have an id and type of `prefsSafe`." - }) + }); } else { dataStore.updatePrefsSafe(prefsSafeData.id, prefsSafeData).then( - function (updatedReturn) { + function (/* updatedReturn */) { that.getPrefsSafe(prefsSafeData.id).then( function (finalData) { promiseTogo.resolve(finalData); @@ -479,6 +486,47 @@ var fluid = fluid || require("infusion"); return promiseTogo; }; + /** + * Stand alone method to add a `gpiiKey` document in the system. `prefsSafeId` and `prefSetId` are + * required fields. Optionally you can specify the `gpiiKey` otherwise a new one will be generated. + * This key must not exist yet. + * @param {Object} that - Instance of `gpii.preferencesServer.preferencesService`. + * @param {Object} dataStore - Instance of `gpii.dbOperation.dataStore` + * @param {Object} keyData - Data for the new `gpiiKey` document. + * @return {Promise} A promise object that resolves to the new saved document, or rejects with a + * standard error payload. + */ + gpii.preferencesServer.preferencesService.addGpiiKey = function (that, dataStore, keyData) { + var promTogo = fluid.promise(); + + if (!keyData.prefsSafeId || !keyData.prefsSetId) { + promTogo.reject({ + isError: true, + message: "Unable to add GPII Key to Preferences Safe. `prefsSafeId` and `prefsSetId` are required fields." + }); + } + else { + dataStore.addGpiiKey({ + gpiiKey: keyData.gpiiKey, // Can be undefined + prefsSafeId: keyData.prefsSafeId, + prefsSetId: keyData.prefsSetId + }).then( + function (newKeyData) { + dataStore.findById(newKeyData.id).then(promTogo.resolve, promTogo.reject); + }, + function (error) { + fluid.error("Error adding key to preferences safe: ", keyData, error); + promTogo.reject({ + isError: true, + message: "Unable to add GPII Key to Preferences Safe." + }); + } + ); + } + + return promTogo; + }; + /** * The last step in the promise transforming chain for implementing createPreferences() API. * Create a gpiiKey record with the provided input. diff --git a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js index 06cc70eb1..87ac46787 100644 --- a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js +++ b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js @@ -59,9 +59,9 @@ fluid.defaults("gpii.preferencesServer.findKeysForPrefsSafe.handler", { gpii.preferencesServer.findKeysForPrefsSafe.handler.getKeysForPrefsSafe = function (prefsService, preferencesServer, request, prefsSafeId) { prefsService.getPrefsSafe(prefsSafeId).then( - function (prefsSafeData) { + function (/* prefsSafeData */) { prefsService.getKeysForPrefsSafe(prefsSafeId).then(request.events.onSuccess.fire, request.events.onError.fire); - }, request.events.onError.fire); + }, request.events.onError.fire); }; fluid.defaults("gpii.preferencesServer.prefsSafeWithKeysGet.handler", { @@ -125,12 +125,12 @@ fluid.defaults("gpii.preferencesServer.prefsSafeKeyCreate.handler", { gradeNames: ["kettle.request.http"], invokers: { handleRequest: { - funcName: "gpii.preferencesServer.prefsSafeKeyCreate.handler", - args: ["{gpii.preferencesServer.preferencesService}.dataStore", "{that}.req.body", "{that}"] + funcName: "gpii.preferencesServer.prefsSafeKeyCreate.handler.addGpiiKey", + args: ["{preferencesService}", "{that}.req.body", "{that}"] } } }); -gpii.preferencesServer.prefsSafeKeyCreate.handler = function (dataStore, body, request) { - dataStore.addGpiiKey(body).then(request.events.onSuccess.fire, request.events.onError.fire); +gpii.preferencesServer.prefsSafeKeyCreate.handler.addGpiiKey = function (preferencesService, body, request) { + preferencesService.addGpiiKey(body).then(request.events.onSuccess.fire, request.events.onError.fire); }; diff --git a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js index 1eb33e9a6..09a61d79e 100644 --- a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js +++ b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js @@ -322,7 +322,7 @@ gpii.tests.preferencesServer.preferencesService.verifyFetchedPrefsSafe = functio var gpiiKeyDetails = response.gpiiKeyDetails; jqUnit.assertEquals("The value of \"schemaVersion\" has been set correctly", gpii.dbOperation.schemaVersion, gpiiKeyDetails.schemaVersion); jqUnit.assertNotUndefined("The value of \"prefsSafeId\" has been set to default", gpiiKeyDetails.prefsSafeId); - jqUnit.assertEquals("The value of \"prefsSetId\" has been set to default", gpii.preferencesServer.defaultprefsSetId, gpiiKeyDetails.prefsSetId); + jqUnit.assertEquals("The value of \"prefsSetId\" has been set to default", gpii.preferencesServer.defaultPrefsSetId, gpiiKeyDetails.prefsSetId); jqUnit.assertFalse("The value of \"revoked\" has been set to false", gpiiKeyDetails.revoked); jqUnit.assertNull("The value of \"revokedReason\" has been set to null", gpiiKeyDetails.revokedReason); jqUnit.assertNotUndefined("The value of \"timestampCreated\" has been set", gpiiKeyDetails.timestampCreated); @@ -581,30 +581,30 @@ gpii.tests.preferencesServer.preferencesService.createUpdatePrefsSafeData = { } }, updatedPrefsSafe7: { - "id": "prefsSafe-7", - "type": "prefsSafe", - "schemaVersion": "0.1", - "prefsSafeType": "user", - "name": "Prefs Seven", - "password": null, - "email": null, - "preferences": { - "flat": { - "name": "bit of stuff", - "contexts": { - "gpii-default": { - "name": "Default preferences", - "preferences": { - "http://registry.gpii.net/common/onScreenKeyboard/enabled": true - }, - "metadata": [] - } - }, - "metadata": [] - } - }, - "timestampCreated": "2017-12-14T19:55:11.641Z", - // This value will be different "timestampUpdated": null + "id": "prefsSafe-7", + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": "Prefs Seven", + "password": null, + "email": null, + "preferences": { + "flat": { + "name": "bit of stuff", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/onScreenKeyboard/enabled": true + }, + "metadata": [] + } + }, + "metadata": [] + } + }, + "timestampCreated": "2017-12-14T19:55:11.641Z" + // This value will be different "timestampUpdated": null } }; diff --git a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js index 88b968f28..116c1ec74 100644 --- a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js +++ b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js @@ -295,7 +295,7 @@ gpii.tests.preferencesServer.prefsSafes.putSafe.successFixtures = [ "metadata": [] } }, - "timestampCreated": "2017-12-14T19:55:11.641Z", + "timestampCreated": "2017-12-14T19:55:11.641Z" // This will be updated "timestampUpdated": null } } @@ -584,6 +584,72 @@ gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.failFixtures = [ } ]; +/////////////////////// TESTING prefsSafesKeyCreate (POST) //////////////////////////// +fluid.registerNamespace("gpii.tests.preferencesServer.prefsSafes.prefsSafeKeyCreate"); + +gpii.tests.preferencesServer.prefsSafes.prefsSafeKeyCreate.buildTestDef = function (fixture) { + var expectedStatusCode = fixture.expectedStatusCode || 200; + return { + name: fixture.name, + expect: 2, + components: { + getRequest: { + type: "kettle.test.request.http", + options: { + path: "/prefssafe-key-create", + method: "POST", + port: 8081 + } + } + }, + sequence: [{ + func: "{getRequest}.send", + args: fixture.postBody + }, { + event: "{getRequest}.events.onComplete", + listener: "gpii.tests.preferencesServer.testResponseLeftHand", + args: ["{arguments}.0", fixture.expected, "{getRequest}.nativeResponse.statusCode", expectedStatusCode] + }] + }; +}; + +gpii.tests.preferencesServer.prefsSafes.prefsSafeKeyCreate.successFixtures = [ + { + name: "POST: Add a new GPII Key to a preferences set", + postBody: { + "prefsSafeId": "prefsSafe-1", + "prefsSetId": "gpii-lowlight" + }, + expected: { + "type": "gpiiKey", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-1", + "prefsSetId": "gpii-lowlight", + "revoked": false, + "revokedReason": null, + // "timestampCreated": "2017-12-14T19:55:11.640Z", + "timestampUpdated": null + } + } +]; + +gpii.tests.preferencesServer.prefsSafes.prefsSafeKeyCreate.failFixtures = [ + { + name: "POST: Failure expected when not including the safe id and prefset id", + expectedStatusCode: 500, + postBody: { + // "prefsSafeId": "prefsSafe-1", + "prefsSetId": "gpii-lowlight" + }, + expected: { + isError: true, + message: "Unable to add GPII Key to Preferences Safe. `prefsSafeId` and `prefsSetId` are required fields." + } + } +]; + +//////////////////////// Prefs Test Map /////////////////////////// + gpii.tests.preferencesServer.prefsSafes.testMap = [ { build: gpii.tests.preferencesServer.prefsSafes.get.buildTestDef, fixtures: gpii.tests.preferencesServer.prefsSafes.get.successFixtures @@ -611,6 +677,12 @@ gpii.tests.preferencesServer.prefsSafes.testMap = [ { }, { build: gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.buildTestDef, fixtures: gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.failFixtures +}, { + build: gpii.tests.preferencesServer.prefsSafes.prefsSafeKeyCreate.buildTestDef, + fixtures: gpii.tests.preferencesServer.prefsSafes.prefsSafeKeyCreate.successFixtures +}, { + build: gpii.tests.preferencesServer.prefsSafes.prefsSafeKeyCreate.buildTestDef, + fixtures: gpii.tests.preferencesServer.prefsSafes.prefsSafeKeyCreate.failFixtures }]; gpii.tests.preferencesServer.prefsSafes.testDefs = fluid.flatten(fluid.transform(gpii.tests.preferencesServer.prefsSafes.testMap, function (mapEl) { From b8c76458e6da7db8b15204bf93decee681f48004 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Mon, 21 Jan 2019 13:01:20 -0800 Subject: [PATCH 38/72] GPII-2966 Removing unused findPrefsSafeByName view --- .../gpii-db-operation/src/DbDataStore.js | 15 --------------- testData/dbData/views.json | 3 --- 2 files changed, 18 deletions(-) diff --git a/gpii/node_modules/gpii-db-operation/src/DbDataStore.js b/gpii/node_modules/gpii-db-operation/src/DbDataStore.js index 55f4be102..1e71c1470 100644 --- a/gpii/node_modules/gpii-db-operation/src/DbDataStore.js +++ b/gpii/node_modules/gpii-db-operation/src/DbDataStore.js @@ -150,21 +150,6 @@ fluid.defaults("gpii.dbOperation.dbDataStore", { } } }, - findPrefsSafeByNameDataSource: { - type: "gpii.dbOperation.dbDataSource", - options: { - requestUrl: "/_design/views/_view/findPrefsSafeByName?key=%22%name%22&include_docs=true", - termMap: { - name: "%name" - }, - rules: { - // TODO: Blow up if there is more than one record - readPayload: { - "": "rows.0.doc" - } - } - } - }, findClientByOauth2ClientIdDataSource: { type: "gpii.dbOperation.dbDataSource", options: { diff --git a/testData/dbData/views.json b/testData/dbData/views.json index d3468b6d7..24849930b 100644 --- a/testData/dbData/views.json +++ b/testData/dbData/views.json @@ -17,9 +17,6 @@ "listPrefsSafes": { "map": "function(doc) {if (doc.type === 'prefsSafe') emit(doc._id, {'name': doc.name, 'email': doc.email, 'created': doc.timestampCreated, 'updated': doc.timestampUpdated})}" }, - "findPrefsSafeByName": { - "map": "function(doc) {if (doc.type === 'prefsSafe') emit(doc.name, null)}" - }, "expressUserSafeLoginLookup": { "map": "function(doc) {if (doc.type === 'gpiiCloudSafeCredential') {emit(doc.gpiiExpressUserId, null);}}" }, From 7d3a1e930c85c12659d15c6275e06efe99b54ab4 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Mon, 21 Jan 2019 13:55:35 -0800 Subject: [PATCH 39/72] GPII-2966 Adding tests for remaining dbstore methods. --- .../test/DbDataStoreTests.js | 59 ++++++++++++++++++- .../test/DbDataStoreTestsUtils.js | 43 ++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTests.js b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTests.js index e20388a30..40c4259cd 100644 --- a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTests.js +++ b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTests.js @@ -565,6 +565,60 @@ fluid.defaults("gpii.tests.dbDataStore.addAuthorization", { }] }); +fluid.defaults("gpii.tests.dbDataStore.findPrefsSafeList", { + gradeNames: ["gpii.tests.dbDataStore.environment"], + rawModules: [{ + name: "Test findPrefsSafeList()", + tests: [{ + name: "List prefs safes", + sequence: [{ + func: "gpii.tests.invokePromiseProducer", + args: ["{dbDataStore}.findPrefsSafeList", [], "{that}"] + }, { + listener: "jqUnit.assertDeepEq", + args: ["Expecing a list of all the safes.", gpii.tests.dbDataStore.testData.findPrefsSafeList_listing, "{arguments}.0"], + event: "{that}.events.onResponse" + }] + }] + }] +}); + +fluid.defaults("gpii.tests.dbDataStore.findKeysForPrefsSafe", { + gradeNames: ["gpii.tests.dbDataStore.environment"], + rawModules: [{ + name: "Test findKeysForPrefsSafe()", + tests: [{ + name: "List prefs safes", + sequence: [{ + func: "gpii.tests.invokePromiseProducer", + args: ["{dbDataStore}.findKeysForPrefsSafe", ["prefsSafe-1"], "{that}"] + }, { + listener: "jqUnit.assertLeftHand", + args: ["Expecing a list of keys for prefsSafe-1.", gpii.tests.dbDataStore.testData.findKeysForPrefsSafe_prefsSafe1, "{arguments}.0"], + event: "{that}.events.onResponse" + }] + }] + }] +}); + +fluid.defaults("gpii.tests.dbDataStore.findSafeByExpressUserLookup", { + gradeNames: ["gpii.tests.dbDataStore.environment"], + rawModules: [{ + name: "Test findSafeByExpressUserLookup()", + tests: [{ + name: "List prefs safes", + sequence: [{ + func: "gpii.tests.invokePromiseProducer", + args: ["{dbDataStore}.findSafeByExpressUserLookup", ["org.couch.db.user:prefs1user"], "{that}"] + }, { + listener: "jqUnit.assertDeepEq", + args: ["Expecing a safe from the express lookup.", gpii.tests.dbDataStore.testData.findSafeByExpressUserLookup_credential, "{arguments}.0"], + event: "{that}.events.onResponse" + }] + }] + }] +}); + fluid.test.runTests([ "gpii.tests.dbDataStore.findGpiiKey", "gpii.tests.dbDataStore.findClientById", @@ -577,5 +631,8 @@ fluid.test.runTests([ "gpii.tests.dbDataStore.updateGpiiKey", "gpii.tests.dbDataStore.addPrefsSafe", "gpii.tests.dbDataStore.updatePrefsSafe", - "gpii.tests.dbDataStore.addAuthorization" + "gpii.tests.dbDataStore.addAuthorization", + "gpii.tests.dbDataStore.findPrefsSafeList", + "gpii.tests.dbDataStore.findKeysForPrefsSafe", + "gpii.tests.dbDataStore.findSafeByExpressUserLookup" ]); diff --git a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js index 7fe436b73..cd7df0327 100644 --- a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js +++ b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js @@ -28,6 +28,7 @@ fluid.defaults("gpii.tests.dbDataStore.environment", { "%gpii-db-operation/test/data/clientCredentials.json", "%gpii-db-operation/test/data/gpiiAppInstallationAuthorizations.json", "%gpii-db-operation/test/data/gpiiAppInstallationClients.json", + "%gpii-db-operation/test/data/gpiiCloudSafeCred.json", "%gpii-db-operation/test/data/gpiiKeys.json", "%gpii-db-operation/test/data/prefsSafes.json", "%gpii-universal/testData/dbData/views.json" @@ -320,5 +321,47 @@ gpii.tests.dbDataStore.testData = { "timestampExpires": "3020-05-30T17:54:00.000Z", "id": "gpiiAppInstallationAuthorization-1" } + }, + findPrefsSafeList_listing: { + "total_rows": 1, + "offset": 0, + "rows": [ + { + "name": null, + "email": null, + "created": "2017-12-01T18:43:32.889Z", + "updated": null, + "id": "prefsSafe-1" + } + ] + }, + findKeysForPrefsSafe_prefsSafe1: { + "rows": [ + { + "type": "gpiiCloudSafeCredential", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-1", + "gpiiExpressUserId": "org.couch.db.user:prefs1user", + "id": "8f3085a7-b65b-4648-9a78-8ac7de766997" + }, + { + "type": "gpiiKey", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-1", + "prefsSetId": "gpii-default", + "revoked": false, + "revokedReason": null, + "timestampCreated": "2017-11-21T18:11:22.101Z", + "timestampUpdated": null, + "id": "chrome_high_contrast" + } + ] + }, + findSafeByExpressUserLookup_credential: { + "type": "gpiiCloudSafeCredential", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-1", + "gpiiExpressUserId": "org.couch.db.user:prefs1user", + "id": "8f3085a7-b65b-4648-9a78-8ac7de766997" } }; From ead61fffb1f472dcb4631c9bbb0da4b5cb196611 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Mon, 21 Jan 2019 13:55:47 -0800 Subject: [PATCH 40/72] GPII-2966 Adding tests for remaining dbstore methods. --- .../test/data/gpiiCloudSafeCred.json | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 gpii/node_modules/gpii-db-operation/test/data/gpiiCloudSafeCred.json diff --git a/gpii/node_modules/gpii-db-operation/test/data/gpiiCloudSafeCred.json b/gpii/node_modules/gpii-db-operation/test/data/gpiiCloudSafeCred.json new file mode 100644 index 000000000..bed344b4c --- /dev/null +++ b/gpii/node_modules/gpii-db-operation/test/data/gpiiCloudSafeCred.json @@ -0,0 +1,23 @@ +[ + { + "name": "prefs1user", + "type": "user", + "email": "prefs1user@gpii.org", + "roles": [], + "username": "prefs1user", + "verified": true, + "iterations": 10, + "password_scheme": "pbkdf2", + "salt": "7cf6961e6ded3bd25732e5466512d116bf9908ba9629d4ed060a03a965e5341d", + "derived_key": "e8bd265e7d82fd0f662e9ddaaf2e75acb294da1b", + "verification_code": "618fa72aa62af282704b556e34957a79", + "_id": "org.couch.db.user:prefs7user" + }, + { + "type": "gpiiCloudSafeCredential", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-1", + "gpiiExpressUserId": "org.couch.db.user:prefs1user", + "_id": "8f3085a7-b65b-4648-9a78-8ac7de766997" + } +] From e3073c06d395fd723047baaba365a94d0b341d4b Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Mon, 21 Jan 2019 14:14:25 -0800 Subject: [PATCH 41/72] GPII-2966 Changing findKeys to findRelatedDocs since we also return the new username/password credentials, and ideally want this to return any future document types that contain a prefsSafeId in them --- gpii/node_modules/gpii-db-operation/src/DbDataStore.js | 8 ++++---- .../gpii-db-operation/test/DbDataStoreTests.js | 10 +++++----- .../gpii-db-operation/test/DbDataStoreTestsUtils.js | 2 +- .../preferencesServer/src/preferencesServer.js | 4 ++-- .../preferencesServer/src/preferencesService.js | 2 +- .../preferencesServer/src/prefsSafesHandlers.js | 6 +++--- testData/dbData/views.json | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/gpii/node_modules/gpii-db-operation/src/DbDataStore.js b/gpii/node_modules/gpii-db-operation/src/DbDataStore.js index 1e71c1470..afac88a2b 100644 --- a/gpii/node_modules/gpii-db-operation/src/DbDataStore.js +++ b/gpii/node_modules/gpii-db-operation/src/DbDataStore.js @@ -122,10 +122,10 @@ fluid.defaults("gpii.dbOperation.dbDataStore", { } } }, - findKeysForPrefsSafeDataSource: { + findRelatedDocsForPrefsSafeDataSource: { type: "gpii.dbOperation.dbDataSource", options: { - requestUrl: "/_design/views/_view/findKeysForPrefsSafe?include_docs=true&key=%22%prefsSafeId%22", + requestUrl: "/_design/views/_view/findRelatedDocsForPrefsSafe?include_docs=true&key=%22%prefsSafeId%22", termMap: { prefsSafeId: "%prefsSafeId" }, @@ -213,10 +213,10 @@ fluid.defaults("gpii.dbOperation.dbDataStore", { {} ] }, - findKeysForPrefsSafe: { + findRelatedDocsForPrefsSafe: { funcName: "gpii.dbOperation.dbDataStore.findRecordList", args: [ - "{that}.findKeysForPrefsSafeDataSource", + "{that}.findRelatedDocsForPrefsSafeDataSource", { prefsSafeId: "{arguments}.0" } diff --git a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTests.js b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTests.js index 40c4259cd..332fdad55 100644 --- a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTests.js +++ b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTests.js @@ -583,18 +583,18 @@ fluid.defaults("gpii.tests.dbDataStore.findPrefsSafeList", { }] }); -fluid.defaults("gpii.tests.dbDataStore.findKeysForPrefsSafe", { +fluid.defaults("gpii.tests.dbDataStore.findRelatedDocsForPrefsSafe", { gradeNames: ["gpii.tests.dbDataStore.environment"], rawModules: [{ - name: "Test findKeysForPrefsSafe()", + name: "Test findRelatedDocsForPrefsSafe()", tests: [{ name: "List prefs safes", sequence: [{ func: "gpii.tests.invokePromiseProducer", - args: ["{dbDataStore}.findKeysForPrefsSafe", ["prefsSafe-1"], "{that}"] + args: ["{dbDataStore}.findRelatedDocsForPrefsSafe", ["prefsSafe-1"], "{that}"] }, { listener: "jqUnit.assertLeftHand", - args: ["Expecing a list of keys for prefsSafe-1.", gpii.tests.dbDataStore.testData.findKeysForPrefsSafe_prefsSafe1, "{arguments}.0"], + args: ["Expecing a list of keys for prefsSafe-1.", gpii.tests.dbDataStore.testData.findRelatedDocsForPrefsSafe_prefsSafe1, "{arguments}.0"], event: "{that}.events.onResponse" }] }] @@ -633,6 +633,6 @@ fluid.test.runTests([ "gpii.tests.dbDataStore.updatePrefsSafe", "gpii.tests.dbDataStore.addAuthorization", "gpii.tests.dbDataStore.findPrefsSafeList", - "gpii.tests.dbDataStore.findKeysForPrefsSafe", + "gpii.tests.dbDataStore.findRelatedDocsForPrefsSafe", "gpii.tests.dbDataStore.findSafeByExpressUserLookup" ]); diff --git a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js index cd7df0327..57de8902d 100644 --- a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js +++ b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js @@ -335,7 +335,7 @@ gpii.tests.dbDataStore.testData = { } ] }, - findKeysForPrefsSafe_prefsSafe1: { + findRelatedDocsForPrefsSafe_prefsSafe1: { "rows": [ { "type": "gpiiCloudSafeCredential", diff --git a/gpii/node_modules/preferencesServer/src/preferencesServer.js b/gpii/node_modules/preferencesServer/src/preferencesServer.js index d11b1ce6a..2b3d405bd 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesServer.js +++ b/gpii/node_modules/preferencesServer/src/preferencesServer.js @@ -79,10 +79,10 @@ fluid.defaults("gpii.preferencesServer", { method: "get", type: "gpii.preferencesServer.prefsSafeList.handler" }, - findKeysForPrefsSafe: { + findRelatedDocsForPrefsSafe: { route: "/prefssafe-keys/:prefsSafeId", method: "get", - type: "gpii.preferencesServer.findKeysForPrefsSafe.handler" + type: "gpii.preferencesServer.findRelatedDocsForPrefsSafe.handler" }, prefsSafeKeyCreate: { route: "/prefssafe-key-create", diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index d86166ca2..38d11f451 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -55,7 +55,7 @@ var fluid = fluid || require("infusion"); args: ["{arguments}.0"] }, getPrefsSafeByGpiiKey: "{dataStore}.findPrefsSafeByGpiiKey", - getKeysForPrefsSafe: "{dataStore}.findKeysForPrefsSafe", + getKeysForPrefsSafe: "{dataStore}.findRelatedDocsForPrefsSafe", getPreferencesByGpiiKey: { funcName: "gpii.preferencesServer.preferencesService.getPreferencesByGpiiKey", args: ["{dataStore}.findPrefsSafeByGpiiKey", "{arguments}.0"] diff --git a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js index 87ac46787..20b3aef13 100644 --- a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js +++ b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js @@ -47,17 +47,17 @@ gpii.preferencesServer.prefsSafeList.handler.getPrefsSafeList = function (prefsS prefsService.getPrefsSafeList().then(request.events.onSuccess.fire, request.events.onError.fire); }; -fluid.defaults("gpii.preferencesServer.findKeysForPrefsSafe.handler", { +fluid.defaults("gpii.preferencesServer.findRelatedDocsForPrefsSafe.handler", { gradeNames: ["kettle.request.http"], invokers: { handleRequest: { - funcName: "gpii.preferencesServer.findKeysForPrefsSafe.handler.getKeysForPrefsSafe", + funcName: "gpii.preferencesServer.findRelatedDocsForPrefsSafe.handler.getKeysForPrefsSafe", args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId"] } } }); -gpii.preferencesServer.findKeysForPrefsSafe.handler.getKeysForPrefsSafe = function (prefsService, preferencesServer, request, prefsSafeId) { +gpii.preferencesServer.findRelatedDocsForPrefsSafe.handler.getKeysForPrefsSafe = function (prefsService, preferencesServer, request, prefsSafeId) { prefsService.getPrefsSafe(prefsSafeId).then( function (/* prefsSafeData */) { prefsService.getKeysForPrefsSafe(prefsSafeId).then(request.events.onSuccess.fire, request.events.onError.fire); diff --git a/testData/dbData/views.json b/testData/dbData/views.json index 24849930b..c945bb897 100644 --- a/testData/dbData/views.json +++ b/testData/dbData/views.json @@ -11,7 +11,7 @@ "findAuthorizationByAccessToken": { "map": "function(doc) {if (doc.type === 'gpiiAppInstallationAuthorization' && doc.revoked === false) {emit(doc.accessToken, {'_id': doc.clientId, 'authorization': doc})}}" }, - "findKeysForPrefsSafe": { + "findRelatedDocsForPrefsSafe": { "map": "function(doc) {if (doc.type === 'gpiiKey' || doc.type === 'gpiiCloudSafeCredential') emit(doc.prefsSafeId, null)}" }, "listPrefsSafes": { From e52e42688bc8eb34a6714682795d057182c0d898 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Thu, 31 Jan 2019 13:37:09 -1000 Subject: [PATCH 42/72] GPII-2966 Updates to doco from PR comments. --- documentation/PreferencesServer.md | 252 ++++++++++++++++-- .../preferencesServer/test/prefsSafesTests.js | 4 +- 2 files changed, 232 insertions(+), 24 deletions(-) diff --git a/documentation/PreferencesServer.md b/documentation/PreferencesServer.md index 3017456a4..19b1d4714 100644 --- a/documentation/PreferencesServer.md +++ b/documentation/PreferencesServer.md @@ -354,48 +354,217 @@ There are two important things to note here: This end point will return the entire preferences safe, including the embedded preference sets. The URL param is the `id` of the preferences safe. This will not return any attached keys, credentials, or other records. +#### Example GET + +URL: `http://preferences.gpii.net/prefssafe/prefsSafe-alice` + +Example Success Payload: + +```json +{ + "id": "prefsSafe-alice", + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": "alice", + "password": null, + "email": null, + "preferences": { + "flat": { + "name": "Alice", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/applications/com.microsoft.windows.onscreenKeyboard": {} + } + } + } + } + }, + "timestampCreated": "2019-01-14T23:48:03.221Z", + "timestampUpdated": null +} +``` + +If the preferences safe with the `prefsSafeId` does not exist, the following error payload will be +returned: + +```json +{ + "isError": true, + "message": "Cannot lookup prefsSafe" +} +``` + ### GET /prefssafe-with-keys/:prefsSafeId This endpoint will return the entire preferences safe structure, along with records directory related to it, such as keys and credentials. A top level object will contain the preferences safe under key `prefsSafe`, and the related documents under key `keys`. +#### Example GET + +URL: `http://preferences.gpii.net/prefssafe-with-keys/prefsSafe-alice` + Example returned item: ```json { "prefsSafe": { - "id": "prefsSafeId", + "id": "prefsSafe-alice", "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": "alice", + "password": null, + "email": null, "preferences": { - "etc etc": "..." + "flat": { + "name": "Alice", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/applications/com.microsoft.windows.onscreenKeyboard": {} + } + } + } + } }, - "etc etc": "..." + "timestampCreated": "2019-01-14T23:48:03.221Z", + "timestampUpdated": null }, "keys": [ { + "id": "8f3085a7-b65b-4648-9a78-8ac7de766997", "type": "gpiiCloudSafeCredential", - "etc etc": "..." + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-alice", + "gpiiExpressUserId": "org.couch.db.user:alice" }, { + "id": "57A68E84-03A9-4ADD-9365-11C75E4F1B0E", "type": "gpiiKey", - "etc etc": "..." + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-alice", + "prefsSetId": "gpii-default", + "revoked": false, + "revokedReason": null, + "timestampCreated": "2017-12-14T19:55:11.640Z", + "timestampUpdated": null } ] } ``` +If the safe with the specified `prefsSafeId` does not exist, the following error payload will be returned: + +```json +{ + "isError": true, + "message": "Cannot lookup prefsSafe" +} +``` + ### POST /prefssafe Creates a new preferences safe in the system. Takes a full preferences safe JSON payload, albiet without a `id`. The returned payload will include the entire preferences safe, including the updated `timestampCreated` field, and a newly provisioned `id`. +#### Example POST + +URL: `http://preferences.gpii.net/prefssafe` + +The POST payload should be a full preferences safe without an `id`: + +```json +{ + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": "Steve", + "password": null, + "email": null, + "preferences": { + "flat": { + "name": "bit of stuff", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/onScreenKeyboard/enabled": false + }, + "metadata": [] + } + }, + "metadata": [] + } + } +} +``` + +A successful return payload will consist of the same payload with the addition of timestamps and a +freshly generated `id` field. In the event of an error a payload similar to the following will be returned +with the contents of the system error: + +```json +{ + "isError": true, + "message": "System error described here." +} +``` + ### PUT /prefssafe/:prefsSafeId Updates an existing preferences safe in the database, using the full preferences safe format. Will return the updated safe, which should include an updated `timestampUpdated` field. +#### Example PUT + +URL: `http://preferences.gpii.net/prefssafe/prefsSafe-alice` + +Example PUT body: + +```json +{ + "id": "prefsSafe-alice", + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": "alice", + "password": null, + "email": null, + "preferences": { + "flat": { + "name": "Alice", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/applications/com.microsoft.windows.onscreenKeyboard": {} + } + } + } + } + }, + "timestampCreated": "2019-01-14T23:48:03.221Z", + "timestampUpdated": null +} +``` + +On a successfull save, the same payload from the PUT operation will be returned, with an updated +`timestampUpdated` field with the time of save. In the event of a failed save an error payload with a +suitable message will be returned. + +```json +{ + "isError": true, + "message": "System error described here." +} +``` + ### GET /prefssafes Returns a list of preferences safes, including only basic information about each one. Ideal for building a table @@ -403,6 +572,10 @@ or listing of preferences safes. Each item in the list representing a preference `email`, `created`, and `updated`. This endpoint will likely have more options in the future, such as sorting, paging, etc. +#### Example GET + +URL: `http://preferences.gpii.net/prefssafes` + Example return payload: ```json @@ -428,56 +601,79 @@ Example return payload: } ``` +There should never be an error payload for this endpoint. In the situation where there are no preferences +safes stored in the system it will merely contain zero rows. + ### GET /prefssafe-keys/:prefsSafeId This will return the associated keys and credentials documents for a given preferences safe, in a `rows` field. Also included is a `total_rows` and `offset` field, but do note that the `total_rows` field is not accurate as of the time of writing, and should be ignored. +#### Example GET + +URL: `http://preferences.gpii.net/prefssafe-keys/prefsSafe-alice` + An example payload for a particlar safe may be: ```json { "total_rows": 2, "offset": 0, - "rows": [{ - "type": "gpiiCloudSafeCredential", - "etc etc": "..." - }, - { - "type": "gpiiKey", - "etc etc": "..." - }] + "rows": [ + { + "id": "8f3085a7-b65b-4648-9a78-8ac7de766997", + "type": "gpiiCloudSafeCredential", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-alice", + "gpiiExpressUserId": "org.couch.db.user:alice" + }, + { + "id": "57A68E84-03A9-4ADD-9365-11C75E4F1B0E", + "type": "gpiiKey", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-alice", + "prefsSetId": "gpii-default", + "revoked": false, + "revokedReason": null, + "timestampCreated": "2017-12-14T19:55:11.640Z", + "timestampUpdated": null + } + ] } ``` ### POST /prefssafe-key-create This endpoint will add a new `gpiiKey` document to the system. There are no URL parameters, but the JSON body takes -3 fields, one of them option. Required are the `prefsSafeId` and `prefsSetId`. These indicate the preferences safe, +3 fields, one of them optional. Required are the `prefsSafeId` and `prefsSetId`. These indicate the preferences safe, and the respective preferences set that this key and token will operate upon. Optionally you can pass in a unique unused `gpiiKey` to use, otherwise a new one will be generated as part of the process. The new document is returned upon success. In event of a failure, a standard error document is returned with `isError` true, and a message detailing the failure. -#### Example POST +#### Example POST: + +URL: `http://preferences.gpii.net/prefssafe-key-create` + +Example POST Body: ```json { - "prefsSafeId": "prefsSafe-1", - "prefsSetId": "gpii-default", - "gpiiKey": "3B3D3003-9F5F-4B66-98C1-1380EC86DDB1" + "prefsSafeId": "prefsSafe-alice", + "prefsSetId": "gpii-lowlight" } ``` -Successful return payload: +Example successful return payload: ```json { + "id": "3B3D3003-9F5F-4B66-98C1-1380EC86DDB1", "type": "gpiiKey", "schemaVersion": "0.1", - "prefsSafeId": "prefsSafe-1", - "prefsSetId": "gpii-default", + "prefsSafeId": "prefsSafe-alice", + "prefsSetId": "gpii-lowlight", "revoked": false, "revokedReason": null, "timestampCreated": "2017-12-14T19:55:11.640Z", @@ -485,6 +681,15 @@ Successful return payload: } ``` +In the event of any system error, an error payload with a suitable `message` is returned. + +```json +{ + "isError": true, + "message": "System error described here." +} +``` + ### PUT /add-cloud-credential/:prefsSafeId This endpoint will add a new username and password credential set to the preferences safe whose id is specified @@ -517,7 +722,7 @@ unique combination unlocks a particular safe, that preferences safes `prefsSafe` Using the `http://preferences.gpii.net/unlock-cloud-safe` with no parameters we can pass in the username and password via the body. -postBody: +Example POST body: ```json { @@ -545,6 +750,9 @@ If the username and password do not match a record the following error is return } ``` +Any other system errors will return a similar `isError` payload with a suitable message for the failure +condition. + ## Other relevant documentation: * [The Preferences Server Framework](PreferencesServerFramework.md) diff --git a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js index 116c1ec74..4a515d6d6 100644 --- a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js +++ b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js @@ -321,7 +321,7 @@ gpii.tests.preferencesServer.prefsSafes.postSafe.buildTestDef = function (fixtur }, sequence: [{ func: "{getRequest}.send", - args: fixture.putBody + args: fixture.postBody }, { event: "{getRequest}.events.onComplete", listener: "gpii.tests.preferencesServer.testResponseLeftHand", @@ -334,7 +334,7 @@ gpii.tests.preferencesServer.prefsSafes.postSafe.successFixtures = [ { name: "POST: Create a new preferences safe.", url: "%prefsSafeId", - putBody: { + postBody: { "type": "prefsSafe", "schemaVersion": "0.1", "prefsSafeType": "user", From 66ac6c25e1cfb2be82ce30e1ff2e7f20df58a842 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Tue, 12 Mar 2019 11:41:34 -0700 Subject: [PATCH 43/72] GPII-2966 Added check for addGpiiKey to make sure prefsSafe exists. --- .../src/preferencesService.js | 44 ++++++++----- .../test/preferencesServiceTests.js | 62 +++++++++++++++++++ 2 files changed, 90 insertions(+), 16 deletions(-) diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index 38d11f451..927d0ad62 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -506,22 +506,34 @@ var fluid = fluid || require("infusion"); }); } else { - dataStore.addGpiiKey({ - gpiiKey: keyData.gpiiKey, // Can be undefined - prefsSafeId: keyData.prefsSafeId, - prefsSetId: keyData.prefsSetId - }).then( - function (newKeyData) { - dataStore.findById(newKeyData.id).then(promTogo.resolve, promTogo.reject); - }, - function (error) { - fluid.error("Error adding key to preferences safe: ", keyData, error); - promTogo.reject({ - isError: true, - message: "Unable to add GPII Key to Preferences Safe." - }); - } - ); + // Preferences Safe must exist to add this key + that.getPrefsSafe(keyData.prefsSafeId).then(function () { + // Add the new key... + dataStore.addGpiiKey({ + gpiiKey: keyData.gpiiKey, // Can be undefined + prefsSafeId: keyData.prefsSafeId, + prefsSetId: keyData.prefsSetId + }).then( + // ...and then fetch the newly added key and return it. + function (newKeyData) { + dataStore.findById(newKeyData.id).then(promTogo.resolve, promTogo.reject); + }, + function (error) { + fluid.log("Error adding key to preferences safe: ", keyData, error); + promTogo.reject({ + isError: true, + message: "Unable to add GPII Key to Preferences Safe." + }); + } + ); + }, + function (error) { + fluid.log("Error in addGpiiKey prefSafe Lookup", error); + promTogo.reject({ + "isError": true, + "message": "The prefs safe does not exist" + }); + }); } return promTogo; diff --git a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js index 09a61d79e..0c4634bea 100644 --- a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js +++ b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js @@ -457,6 +457,68 @@ gpii.tests.preferencesServer.preferencesService.verifyNewPrefsSafeForUpdate = fu jqUnit.assertDeepEq("Other GPII key values are unchanged", unchangedOrigGpiiKeyFields, unchangedGpiiKeyFields); }; +// Tests for addGpiiKey +gpii.tests.preferencesServer.preferencesService.addGpiiKey = [ + // Successful create + { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", + name: "addGpiiKey: Successful create", + sequence: [{ + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["addGpiiKey", [{ + "type": "gpiiKey", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-1", + "prefsSetId": "gpii-default", + "revoked": false, + "revokedReason": null + }]], + resolve: "jqUnit.assertLeftHand", + resolveArgs: ["Newly created gpiiKey", { + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-1", + "prefsSetId": "gpii-default", + "revoked": false, + "revokedReason": null, + "timestampUpdated": null, + "type": "gpiiKey" + // "id": "0c2e153a-fb5a-4356-b8f4-131810c71cc1" + }, "{arguments}.0"] + }] + }, + // Error creating new key if prefsSafe does not exist + { + config: { + configName: "gpii.tests.preferencesServer.config", + configPath: "%preferencesServer/test/configs" + }, + pouchTestCaseHolder: "gpii.tests.preferencesServer.preferencesService.pouchTestCaseHolder", + name: "addGpiiKey: Error: Prefs Safe does not exist", + sequence: [{ + task: "gpii.tests.preferencesServer.preferencesService.promise", + args: ["addGpiiKey", [{ + "type": "gpiiKey", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-2020", + "prefsSetId": "gpii-default", + "revoked": false, + "revokedReason": null + }]], + reject: "jqUnit.assertLeftHand", + rejectArgs: ["Preference safe doesn't exist, can't create key", { + "isError": true, + "message": "The prefs safe does not exist" + }, "{arguments}.0"] + }] + } +]; + +gpii.test.bootstrapServer(gpii.tests.preferencesServer.preferencesService.addGpiiKey); + // Tests for cloudSafeCredCreate gpii.tests.preferencesServer.preferencesService.cloudSafeCredCreate = [ // Successful create From 8f3026d9ca31bbacc69715aa6756a6f6ba77902b Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Tue, 12 Mar 2019 12:18:38 -0700 Subject: [PATCH 44/72] GPII-2966 Removing old password prefsSafe field. --- documentation/PreferencesServer.md | 4 ---- .../node_modules/gpii-db-operation/src/DbDataStoreUtils.js | 5 ----- .../gpii-db-operation/test/DbDataStoreTestsUtils.js | 3 --- .../gpii-db-operation/test/data/prefsSafes.json | 1 - .../preferencesServer/src/preferencesService.js | 6 ------ .../preferencesServer/test/cloudSafeCredTests.js | 2 -- .../test/data/preferencesServiceUsers.json | 3 --- .../preferencesServer/test/data/prefsSafes.json | 7 ------- .../preferencesServer/test/preferencesServiceTests.js | 2 -- .../node_modules/preferencesServer/test/prefsSafesTests.js | 6 ------ scripts/shared/prefsSetsDbUtils.js | 1 - 11 files changed, 40 deletions(-) diff --git a/documentation/PreferencesServer.md b/documentation/PreferencesServer.md index 19b1d4714..f017ef0ab 100644 --- a/documentation/PreferencesServer.md +++ b/documentation/PreferencesServer.md @@ -367,7 +367,6 @@ Example Success Payload: "schemaVersion": "0.1", "prefsSafeType": "user", "name": "alice", - "password": null, "email": null, "preferences": { "flat": { @@ -417,7 +416,6 @@ Example returned item: "schemaVersion": "0.1", "prefsSafeType": "user", "name": "alice", - "password": null, "email": null, "preferences": { "flat": { @@ -485,7 +483,6 @@ The POST payload should be a full preferences safe without an `id`: "schemaVersion": "0.1", "prefsSafeType": "user", "name": "Steve", - "password": null, "email": null, "preferences": { "flat": { @@ -534,7 +531,6 @@ Example PUT body: "schemaVersion": "0.1", "prefsSafeType": "user", "name": "alice", - "password": null, "email": null, "preferences": { "flat": { diff --git a/gpii/node_modules/gpii-db-operation/src/DbDataStoreUtils.js b/gpii/node_modules/gpii-db-operation/src/DbDataStoreUtils.js index 4e9f9c438..340a6ac40 100644 --- a/gpii/node_modules/gpii-db-operation/src/DbDataStoreUtils.js +++ b/gpii/node_modules/gpii-db-operation/src/DbDataStoreUtils.js @@ -352,7 +352,6 @@ gpii.dbOperation.dbDataStore.updateGpiiKey = function (saveDataSource, gpiiKey, * type: {String}, * schemaVersion: {String}, * name: {String}, - * password: {String}, * email: {String}, * preferences: {Object}, * timestampCreated: {Date}, @@ -389,7 +388,6 @@ gpii.dbOperation.dbDataStore.findPrefsSafeByGpiiKeyPostProcess = function (data) * { * prefsSafeType: {String}, * name: {String}, - * password: {String}, * email: {String}, * preferences: {Object} * } @@ -409,7 +407,6 @@ gpii.dbOperation.dbDataStore.addPrefsSafe = function (saveDataSource, prefsSafeD schemaVersion: gpii.dbOperation.schemaVersion, prefsSafeType: prefsSafeData.prefsSafeType, name: prefsSafeData.name, - password: prefsSafeData.password, email: prefsSafeData.email, preferences: prefsSafeData.preferences, timestampCreated: gpii.dbOperation.getCurrentTimestamp(), @@ -431,7 +428,6 @@ gpii.dbOperation.dbDataStore.addPrefsSafe = function (saveDataSource, prefsSafeD * schemaVersion: {String}, * prefsSafeType: {String}, * name: {String}, - * password: {String}, * email: {String}, * preferences: {Object}, * timestampCreated: {Date} @@ -456,7 +452,6 @@ gpii.dbOperation.dbDataStore.updatePrefsSafe = function (saveDataSource, prefsSa schemaVersion: prefsSafeData.schemaVersion, prefsSafeType: prefsSafeData.prefsSafeType, name: prefsSafeData.name || null, - password: prefsSafeData.password || null, email: prefsSafeData.email || null, preferences: prefsSafeData.preferences, timestampCreated: prefsSafeData.timestampCreated, diff --git a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js index 57de8902d..e1f19787a 100644 --- a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js +++ b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js @@ -184,7 +184,6 @@ gpii.tests.dbDataStore.testData = { "schemaVersion": "0.1", "prefsSafeType": "user", "name": null, - "password": null, "email": null, "preferences": { "flat": { @@ -271,7 +270,6 @@ gpii.tests.dbDataStore.testData = { prefsSafeToCreate: { "prefsSafeType": "user", "name": null, - "password": null, "email": null, "preferences": { "test": "test" @@ -282,7 +280,6 @@ gpii.tests.dbDataStore.testData = { "schemaVersion": "0.1", "prefsSafeType": "snapset", "name": "updated_name", - "password": "updated_password", "email": "updated_email", "preferences": { "test": "test" diff --git a/gpii/node_modules/gpii-db-operation/test/data/prefsSafes.json b/gpii/node_modules/gpii-db-operation/test/data/prefsSafes.json index 7c4b214fc..b403a6487 100644 --- a/gpii/node_modules/gpii-db-operation/test/data/prefsSafes.json +++ b/gpii/node_modules/gpii-db-operation/test/data/prefsSafes.json @@ -5,7 +5,6 @@ "schemaVersion": "0.1", "prefsSafeType": "user", "name": null, - "password": null, "email": null, "preferences": { "flat": { diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index 927d0ad62..e1e5fc698 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -385,7 +385,6 @@ var fluid = fluid || require("infusion"); * { * prefsSafeType: {String} * name: {String} - * password: {String} * email: {String} * preferences: {Object} // must be provided * } @@ -411,7 +410,6 @@ var fluid = fluid || require("infusion"); * prefsSafeData: { * prefsSafeType: {String} * name: {String} - * password: {String} * email: {String} * preferences: {Object} // must be provided * } @@ -454,7 +452,6 @@ var fluid = fluid || require("infusion"); * prefsSafeData: { * prefsSafeType: {String}, // optional * name: {String}, // optional - * password: {String}, // optional * email: {String}, // optional * preferences: {Object} // must be provided * } @@ -467,7 +464,6 @@ var fluid = fluid || require("infusion"); var prefsSafeDataAdded = { prefsSafeType: prefsSafeData.prefsSafeType || gpii.preferencesServer.prefsSafeType.user, name: prefsSafeData.name || null, - password: prefsSafeData.password || null, email: prefsSafeData.email || null, preferences: prefsSafeData.preferences }; @@ -550,7 +546,6 @@ var fluid = fluid || require("infusion"); * prefsSafeDataAdded: { * prefsSafeType: {String} * name: {String} - * password: {String} * email: {String} * preferences: {Object} // must be provided * } @@ -648,7 +643,6 @@ var fluid = fluid || require("infusion"); * prefsSafeDataAdded: { * prefsSafeType: {String} * name: {String} - * password: {String} * email: {String} * preferences: {Object} // must be provided * } diff --git a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js index ab363bd81..8a86fd2c4 100644 --- a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js +++ b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js @@ -144,7 +144,6 @@ gpii.tests.preferencesServer.cloudSafeCred.put.successFixtures = [ "schemaVersion": "0.1", "prefsSafeType": "user", "name": null, - "password": null, "email": null, "preferences": { "ISO24751": { @@ -298,7 +297,6 @@ gpii.tests.preferencesServer.cloudSafeCred.unlock.successFixtures = [ "schemaVersion": "0.1", "prefsSafeType": "user", "name": null, - "password": null, "email": null, "preferences": { "flat": { diff --git a/gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json b/gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json index 98d412537..acebb88b9 100644 --- a/gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json +++ b/gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json @@ -35,7 +35,6 @@ "schemaVersion": "0.1", "prefsSafeType": "user", "name": null, - "password": null, "email": null, "preferences": { "flat": { @@ -60,7 +59,6 @@ "schemaVersion": "0.1", "prefsSafeType": "snapset", "name": null, - "password": null, "email": null, "preferences": { "flat": { @@ -83,7 +81,6 @@ "schemaVersion": "0.1", "prefsSafeType": "user", "name": null, - "password": null, "email": null, "preferences": { "flat": { diff --git a/gpii/node_modules/preferencesServer/test/data/prefsSafes.json b/gpii/node_modules/preferencesServer/test/data/prefsSafes.json index 13d76eff1..d81f89163 100644 --- a/gpii/node_modules/preferencesServer/test/data/prefsSafes.json +++ b/gpii/node_modules/preferencesServer/test/data/prefsSafes.json @@ -5,7 +5,6 @@ "schemaVersion": "0.1", "prefsSafeType": "user", "name": null, - "password": null, "email": null, "preferences": { "ISO24751": { @@ -60,7 +59,6 @@ "schemaVersion": "0.1", "prefsSafeType": "user", "name": null, - "password": null, "email": null, "preferences": { "ISO24751": { @@ -115,7 +113,6 @@ "schemaVersion": "0.1", "prefsSafeType": "user", "name": null, - "password": null, "email": null, "preferences": { "flat": { @@ -177,7 +174,6 @@ "schemaVersion": "0.1", "prefsSafeType": "user", "name": null, - "password": null, "email": null, "preferences": { "flat": { @@ -226,7 +222,6 @@ "schemaVersion": "0.1", "prefsSafeType": "user", "name": null, - "password": null, "email": null, "preferences": { "flat": { @@ -326,7 +321,6 @@ "schemaVersion": "0.1", "prefsSafeType": "user", "name": null, - "password": null, "email": null, "preferences": { "flat": { @@ -390,7 +384,6 @@ "schemaVersion": "0.1", "prefsSafeType": "user", "name": null, - "password": null, "email": null, "preferences": { "flat": { diff --git a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js index 0c4634bea..59cce93de 100644 --- a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js +++ b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js @@ -95,7 +95,6 @@ gpii.tests.preferencesServer.preferencesService.expected = { preferencesToCreate_prefsOnly: { prefsSafeType: "user", name: null, - password: null, email: null, preferences: { "http://registry.gpii.net/common/cursorSize": 24 @@ -648,7 +647,6 @@ gpii.tests.preferencesServer.preferencesService.createUpdatePrefsSafeData = { "schemaVersion": "0.1", "prefsSafeType": "user", "name": "Prefs Seven", - "password": null, "email": null, "preferences": { "flat": { diff --git a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js index 4a515d6d6..5d8d54aba 100644 --- a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js +++ b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js @@ -73,7 +73,6 @@ gpii.tests.preferencesServer.prefsSafes.get.successFixtures = [ "schemaVersion": "0.1", "prefsSafeType": "user", "name": null, - "password": null, "email": null, "preferences": { "flat": { @@ -152,7 +151,6 @@ gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.successFixtures = [ "schemaVersion": "0.1", "prefsSafeType": "user", "name": null, - "password": null, "email": null, "preferences": { "flat": { @@ -252,7 +250,6 @@ gpii.tests.preferencesServer.prefsSafes.putSafe.successFixtures = [ "schemaVersion": "0.1", "prefsSafeType": "user", "name": "Prefs Seven", - "password": null, "email": null, "preferences": { "flat": { @@ -278,7 +275,6 @@ gpii.tests.preferencesServer.prefsSafes.putSafe.successFixtures = [ "schemaVersion": "0.1", "prefsSafeType": "user", "name": "Prefs Seven", - "password": null, "email": null, "preferences": { "flat": { @@ -339,7 +335,6 @@ gpii.tests.preferencesServer.prefsSafes.postSafe.successFixtures = [ "schemaVersion": "0.1", "prefsSafeType": "user", "name": "Prefs Three Thousand", - "password": null, "email": null, "preferences": { "flat": { @@ -362,7 +357,6 @@ gpii.tests.preferencesServer.prefsSafes.postSafe.successFixtures = [ "schemaVersion": "0.1", "prefsSafeType": "user", "name": "Prefs Three Thousand", - "password": null, "email": null, "preferences": { "flat": { diff --git a/scripts/shared/prefsSetsDbUtils.js b/scripts/shared/prefsSetsDbUtils.js index c31c670a0..f2d28b4ef 100644 --- a/scripts/shared/prefsSetsDbUtils.js +++ b/scripts/shared/prefsSetsDbUtils.js @@ -70,7 +70,6 @@ gpii.prefsSetsDbUtils.generateKeyData = function (gpiiKeyId, preferences, prefsS "schemaVersion": "0.1", "prefsSafeType": prefsSafeType || "user", "name": gpiiKeyId, - "password": null, "email": null, "preferences": preferences || gpii.prefsSetsDbUtils.emptyPreferencesBlock, "timestampCreated": currentTime, From a1bf6aa51978b480a292101e5cd2ac3ad8cf623b Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Wed, 13 Mar 2019 19:46:30 -0700 Subject: [PATCH 45/72] GPII-2966 Removing a few more occurances of `old` password field. --- .../test/data/prefsSafes-preferencesServiceTests.json | 2 -- gpii/node_modules/preferencesServer/test/data/prefsSafes.json | 1 - 2 files changed, 3 deletions(-) diff --git a/gpii/node_modules/preferencesServer/test/data/prefsSafes-preferencesServiceTests.json b/gpii/node_modules/preferencesServer/test/data/prefsSafes-preferencesServiceTests.json index dd091329f..8f46b6dcc 100644 --- a/gpii/node_modules/preferencesServer/test/data/prefsSafes-preferencesServiceTests.json +++ b/gpii/node_modules/preferencesServer/test/data/prefsSafes-preferencesServiceTests.json @@ -5,7 +5,6 @@ "schemaVersion": "0.1", "prefsSafeType": "user", "name": null, - "password": null, "email": null, "preferences": { "flat": { @@ -31,7 +30,6 @@ "schemaVersion": "0.1", "prefsSafeType": "snapset", "name": null, - "password": null, "email": null, "preferences": { "flat": { diff --git a/gpii/node_modules/preferencesServer/test/data/prefsSafes.json b/gpii/node_modules/preferencesServer/test/data/prefsSafes.json index 19000b652..68e93bceb 100644 --- a/gpii/node_modules/preferencesServer/test/data/prefsSafes.json +++ b/gpii/node_modules/preferencesServer/test/data/prefsSafes.json @@ -409,7 +409,6 @@ "schemaVersion": "0.1", "prefsSafeType": "snapset", "name": null, - "password": null, "email": null, "preferences": { "flat": { From fcfcdb2eec95e8c9b63a0f7fcb37f5a68ff86a90 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Wed, 13 Mar 2019 21:05:30 -0700 Subject: [PATCH 46/72] GPII-2966 Converts prefsSafes tests to couch testing. --- .../preferencesServer/test/prefsSafesTests.js | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js index 5d8d54aba..2b802792f 100644 --- a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js +++ b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js @@ -409,7 +409,7 @@ gpii.tests.preferencesServer.prefsSafes.list.successFixtures = [ { name: "GET: List Preference Safes", expected: { - total_rows: 7, + total_rows: 8, offset: 0, rows: [ { @@ -460,6 +460,13 @@ gpii.tests.preferencesServer.prefsSafes.list.successFixtures = [ "created": "2017-12-14T19:55:11.641Z", "updated": null, "id": "prefsSafe-7" + }, + { + "name": null, + "email": null, + "created": "2017-12-01T18:43:32.889Z", + "updated": null, + "id": "prefsSafe-snapset1" } ] } @@ -500,8 +507,6 @@ gpii.tests.preferencesServer.prefsSafes.list.emptyDatabase = [ } ]; -gpii.test.bootstrapServer(gpii.tests.preferencesServer.prefsSafes.list.emptyDatabase); - /////////////////////// TESTING prefsSafes List Keys for Safe (GET) //////////////////////////// fluid.registerNamespace("gpii.tests.preferencesServer.prefsSafes.listKeysForSafe"); @@ -541,8 +546,8 @@ gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.successFixtures = [ expected: { // TODO sgithens, this CouchDB query needs to be fixed so that the total_rows // is the actual number returned from the query, in this case 2 - "total_rows": 9, - "offset": 0, + "total_rows": 11, + "offset": 9, rows: [{ "type": "gpiiCloudSafeCredential", "schemaVersion": "0.1", @@ -679,15 +684,32 @@ gpii.tests.preferencesServer.prefsSafes.testMap = [ { fixtures: gpii.tests.preferencesServer.prefsSafes.prefsSafeKeyCreate.failFixtures }]; +fluid.defaults("gpii.tests.preferencesServer.prefsSafes.testEnvironment", { + gradeNames: ["gpii.test.couchdb.environment.base", "gpii.test.serverEnvironment"], + databases: { + gpii: { + data: [ + "%gpii-universal/gpii/node_modules/preferencesServer/test/data/gpiiKeys.json", + "%gpii-universal/gpii/node_modules/preferencesServer/test/data/prefsSafes.json", + "%gpii-universal/gpii/node_modules/preferencesServer/test/data/gpiiCloudSafeCred.json", + "%gpii-universal/testData/dbData/views.json" + ] + } + } +}); + gpii.tests.preferencesServer.prefsSafes.testDefs = fluid.flatten(fluid.transform(gpii.tests.preferencesServer.prefsSafes.testMap, function (mapEl) { return fluid.transform(mapEl.fixtures, mapEl.build, function (fixture) { var common = { config: gpii.tests.preferencesServer.config, - pouchTestCaseHolder: "gpii.tests.preferencesServer.pouchTestCaseHolder" }; return fluid.extend({}, common, fixture); }); })); -gpii.test.bootstrapServer(gpii.tests.preferencesServer.prefsSafes.testDefs); +gpii.tests.preferencesServer.prefsSafes.testDefToEnvironment = function (testDef) { + return gpii.test.testDefToEnvironment(testDef, "gpii.tests.preferencesServer.prefsSafes.testEnvironment", "gpii.test.couchSequenceGrade"); +}; + +gpii.test.runTestDefs(gpii.tests.preferencesServer.prefsSafes.testDefs, gpii.tests.preferencesServer.prefsSafes.testDefToEnvironment); From 82491ed9bba0341c1ee703469b15fe737d5b75e9 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Wed, 13 Mar 2019 21:19:13 -0700 Subject: [PATCH 47/72] GPII-2966 Converts cloudSafeCred tests to couch testing. --- .../test/cloudSafeCredTests.js | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js index 8a86fd2c4..fd649e2f1 100644 --- a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js +++ b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js @@ -343,15 +343,34 @@ gpii.tests.preferencesServer.cloudSafeCred.testMap = [ { fixtures: gpii.tests.preferencesServer.cloudSafeCred.put.failureFixtures }]; +fluid.defaults("gpii.tests.preferencesServer.cloudSafeCred.testEnvironment", { + gradeNames: ["gpii.test.couchdb.environment.base", "gpii.test.serverEnvironment"], + databases: { + gpii: { + data: [ + "%gpii-universal/gpii/node_modules/preferencesServer/test/data/gpiiKeys.json", + "%gpii-universal/gpii/node_modules/preferencesServer/test/data/prefsSafes.json", + "%gpii-universal/gpii/node_modules/preferencesServer/test/data/gpiiCloudSafeCred.json", + "%gpii-universal/gpii/node_modules/preferencesServer/test/data/userLookup.json", + "%gpii-universal/testData/dbData/views.json" + ] + } + } +}); + gpii.tests.preferencesServer.cloudSafeCred.testDefs = fluid.flatten(fluid.transform(gpii.tests.preferencesServer.cloudSafeCred.testMap, function (mapEl) { return fluid.transform(mapEl.fixtures, mapEl.build, function (fixture) { var common = { config: gpii.tests.preferencesServer.config, - pouchTestCaseHolder: "gpii.tests.preferencesServer.pouchTestCaseHolder" }; return fluid.extend({}, common, fixture); }); })); -gpii.test.bootstrapServer(gpii.tests.preferencesServer.cloudSafeCred.testDefs); +// gpii.test.bootstrapServer(gpii.tests.preferencesServer.cloudSafeCred.testDefs); +gpii.tests.preferencesServer.cloudSafeCred.testDefToEnvironment = function (testDef) { + return gpii.test.testDefToEnvironment(testDef, "gpii.tests.preferencesServer.cloudSafeCred.testEnvironment", "gpii.test.couchSequenceGrade"); +}; + +gpii.test.runTestDefs(gpii.tests.preferencesServer.cloudSafeCred.testDefs, gpii.tests.preferencesServer.cloudSafeCred.testDefToEnvironment); From f18084857eb02d16e985c4755e1f69c0565e555a Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Wed, 13 Mar 2019 21:49:36 -0700 Subject: [PATCH 48/72] GPII-2966 Convert leftover DbDataStore tests to couch testing. --- .../test/DbDataStoreTests.js | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTests.js b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTests.js index ec153a357..2c88f4559 100644 --- a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTests.js +++ b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTests.js @@ -517,12 +517,10 @@ fluid.defaults("gpii.tests.dbDataStore.findPrefsSafeList", { tests: [{ name: "List prefs safes", sequence: [{ - func: "gpii.tests.invokePromiseProducer", - args: ["{dbDataStore}.findPrefsSafeList", [], "{that}"] - }, { - listener: "jqUnit.assertDeepEq", - args: ["Expecing a list of all the safes.", gpii.tests.dbDataStore.testData.findPrefsSafeList_listing, "{arguments}.0"], - event: "{that}.events.onResponse" + task: "{dbDataStore}.findPrefsSafeList", + args: [undefined], + resolve: "jqUnit.assertDeepEq", + resolveArgs: ["Expecing a list of all the safes.", gpii.tests.dbDataStore.testData.findPrefsSafeList_listing, "{arguments}.0"] }] }] }] @@ -535,12 +533,10 @@ fluid.defaults("gpii.tests.dbDataStore.findRelatedDocsForPrefsSafe", { tests: [{ name: "List prefs safes", sequence: [{ - func: "gpii.tests.invokePromiseProducer", - args: ["{dbDataStore}.findRelatedDocsForPrefsSafe", ["prefsSafe-1"], "{that}"] - }, { - listener: "jqUnit.assertLeftHand", - args: ["Expecing a list of keys for prefsSafe-1.", gpii.tests.dbDataStore.testData.findRelatedDocsForPrefsSafe_prefsSafe1, "{arguments}.0"], - event: "{that}.events.onResponse" + task: "{dbDataStore}.findRelatedDocsForPrefsSafe", + args: ["prefsSafe-1"], + resolve: "jqUnit.assertLeftHand", + resolveArgs: ["Expecing a list of keys for prefsSafe-1.", gpii.tests.dbDataStore.testData.findRelatedDocsForPrefsSafe_prefsSafe1, "{arguments}.0"] }] }] }] @@ -553,12 +549,10 @@ fluid.defaults("gpii.tests.dbDataStore.findSafeByExpressUserLookup", { tests: [{ name: "List prefs safes", sequence: [{ - func: "gpii.tests.invokePromiseProducer", - args: ["{dbDataStore}.findSafeByExpressUserLookup", ["org.couch.db.user:prefs1user"], "{that}"] - }, { - listener: "jqUnit.assertDeepEq", - args: ["Expecing a safe from the express lookup.", gpii.tests.dbDataStore.testData.findSafeByExpressUserLookup_credential, "{arguments}.0"], - event: "{that}.events.onResponse" + task: "{dbDataStore}.findSafeByExpressUserLookup", + args: ["org.couch.db.user:prefs1user"], + resolve: "jqUnit.assertDeepEq", + resolveArgs: ["Expecing a safe from the express lookup.", gpii.tests.dbDataStore.testData.findSafeByExpressUserLookup_credential, "{arguments}.0"] }] }] }] From 34a15351585f8cd251c0b35d5a420ef469aabff6 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Thu, 14 Mar 2019 12:36:23 -0700 Subject: [PATCH 49/72] GPII-2966 Minor lint cleanup --- gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js | 3 +-- .../preferencesServer/test/preferencesServiceTests.js | 2 +- gpii/node_modules/preferencesServer/test/prefsSafesTests.js | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js index fd649e2f1..248de40e5 100644 --- a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js +++ b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js @@ -361,14 +361,13 @@ fluid.defaults("gpii.tests.preferencesServer.cloudSafeCred.testEnvironment", { gpii.tests.preferencesServer.cloudSafeCred.testDefs = fluid.flatten(fluid.transform(gpii.tests.preferencesServer.cloudSafeCred.testMap, function (mapEl) { return fluid.transform(mapEl.fixtures, mapEl.build, function (fixture) { var common = { - config: gpii.tests.preferencesServer.config, + config: gpii.tests.preferencesServer.config }; return fluid.extend({}, common, fixture); }); })); -// gpii.test.bootstrapServer(gpii.tests.preferencesServer.cloudSafeCred.testDefs); gpii.tests.preferencesServer.cloudSafeCred.testDefToEnvironment = function (testDef) { return gpii.test.testDefToEnvironment(testDef, "gpii.tests.preferencesServer.cloudSafeCred.testEnvironment", "gpii.test.couchSequenceGrade"); }; diff --git a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js index 2592e52e4..710179d04 100644 --- a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js +++ b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js @@ -208,7 +208,7 @@ gpii.tests.preferencesServer.preferencesService.expected = { preferences: { "http://registry.gpii.net/common/cursorSize": 24 } - }, + } }; fluid.defaults("gpii.tests.preferencesServer.preferencesService.getPreferencesByGpiiKey", { diff --git a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js index 2b802792f..ab5e4789e 100644 --- a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js +++ b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js @@ -701,7 +701,7 @@ fluid.defaults("gpii.tests.preferencesServer.prefsSafes.testEnvironment", { gpii.tests.preferencesServer.prefsSafes.testDefs = fluid.flatten(fluid.transform(gpii.tests.preferencesServer.prefsSafes.testMap, function (mapEl) { return fluid.transform(mapEl.fixtures, mapEl.build, function (fixture) { var common = { - config: gpii.tests.preferencesServer.config, + config: gpii.tests.preferencesServer.config }; return fluid.extend({}, common, fixture); From 7d1becf63d66a589a7f7c42b3eefdeb05b890838 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Tue, 19 Mar 2019 15:41:32 -0700 Subject: [PATCH 50/72] GPII-2966 Moving statusCode population to handler methods. --- .../src/cloudSafeCredHandlers.js | 10 ++++- .../src/preferencesService.js | 3 -- .../src/prefsSafesHandlers.js | 40 +++++++++++++++++-- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js b/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js index 09bee7b29..ca0d60eca 100644 --- a/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js +++ b/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js @@ -34,7 +34,15 @@ gpii.preferencesServer.cloudSafeCredCreate.handler.put = function (prefsService, prefsSafeId: params.prefsSafeId, username: body.username, password: body.password - }).then(request.events.onSuccess.fire, request.events.onError.fire); + }).then(request.events.onSuccess.fire, + function (err) { + request.events.onError.fire({ + isError: true, + message: err.message, + statusCode: 404 + }) + } + ); }; fluid.defaults("gpii.preferencesServer.cloudSafeUnlockPost.handler", { diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index 8a88e85a5..c213309b4 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -193,7 +193,6 @@ var fluid = fluid || require("infusion"); promiseTogo.reject({ isError: true, message: "Cannot lookup prefsSafe", - statusCode: 404 }); } else { @@ -205,7 +204,6 @@ var fluid = fluid || require("infusion"); promiseTogo.reject({ isError: true, message: "Error fetching prefsSafe", - statusCode: 500 }); } ); @@ -306,7 +304,6 @@ var fluid = fluid || require("infusion"); promiseTogo.reject({ isError: true, message: "Unable to create credentials with that username and password combination", - statusCode: 404 }); } else { diff --git a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js index 20b3aef13..a19ea72f0 100644 --- a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js +++ b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js @@ -30,7 +30,15 @@ fluid.defaults("gpii.preferencesServer.prefsSafeGet.handler", { }); gpii.preferencesServer.prefsSafeGet.handler.getPrefsSafe = function (prefsService, preferencesServer, request, gpiiKey) { - prefsService.getPrefsSafe(gpiiKey).then(request.events.onSuccess.fire, request.events.onError.fire); + prefsService.getPrefsSafe(gpiiKey).then(request.events.onSuccess.fire, + function (err) { + request.events.onError.fire({ + isError: true, + message: err.message, + statusCode: 404 + }) + } + ); }; fluid.defaults("gpii.preferencesServer.prefsSafeList.handler", { @@ -44,7 +52,15 @@ fluid.defaults("gpii.preferencesServer.prefsSafeList.handler", { }); gpii.preferencesServer.prefsSafeList.handler.getPrefsSafeList = function (prefsService, preferencesServer, request) { - prefsService.getPrefsSafeList().then(request.events.onSuccess.fire, request.events.onError.fire); + prefsService.getPrefsSafeList().then(request.events.onSuccess.fire, + function (err) { + request.events.onError.fire({ + isError: true, + message: err.message, + statusCode: 404 + }) + } + ); }; fluid.defaults("gpii.preferencesServer.findRelatedDocsForPrefsSafe.handler", { @@ -61,7 +77,15 @@ gpii.preferencesServer.findRelatedDocsForPrefsSafe.handler.getKeysForPrefsSafe = prefsService.getPrefsSafe(prefsSafeId).then( function (/* prefsSafeData */) { prefsService.getKeysForPrefsSafe(prefsSafeId).then(request.events.onSuccess.fire, request.events.onError.fire); - }, request.events.onError.fire); + }, + function (err) { + request.events.onError.fire({ + isError: true, + message: err.message, + statusCode: 404 + }); + } + ); }; fluid.defaults("gpii.preferencesServer.prefsSafeWithKeysGet.handler", { @@ -85,7 +109,15 @@ gpii.preferencesServer.prefsSafeWithKeysGet.handler.get = function (prefsService }); }, request.events.onError.fire); - }, request.events.onError.fire); + }, + function (err) { + request.events.onError.fire({ + isError: true, + message: err.message, + statusCode: 404 + }); + } + ); }; fluid.defaults("gpii.preferencesServer.prefsSafePost.handler", { From 1dbdb28bdab7f821d84f6ecdcb2271ca24b34c4e Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Tue, 19 Mar 2019 20:14:15 -0700 Subject: [PATCH 51/72] GPII-2966 Moving error messages and codes to preferencesServerConst --- documentation/PreferencesServer.md | 6 ++-- .../src/cloudSafeCredHandlers.js | 6 ++-- .../src/preferencesServerConst.js | 30 +++++++++++++++++++ .../src/preferencesService.js | 26 ++++++++++------ .../src/prefsSafesHandlers.js | 4 +++ .../test/cloudSafeCredTests.js | 10 ++++--- .../test/preferencesServiceTests.js | 8 +++-- .../preferencesServer/test/prefsSafesTests.js | 9 ++++-- 8 files changed, 76 insertions(+), 23 deletions(-) diff --git a/documentation/PreferencesServer.md b/documentation/PreferencesServer.md index 32acff667..98b578883 100644 --- a/documentation/PreferencesServer.md +++ b/documentation/PreferencesServer.md @@ -393,7 +393,8 @@ returned: ```json { "isError": true, - "message": "Cannot lookup prefsSafe" + "errorCode": "GPII_ERR_NO_PREFSSAFE", + "message": "Missing prefssafe" } ``` @@ -462,7 +463,8 @@ If the safe with the specified `prefsSafeId` does not exist, the following error ```json { "isError": true, - "message": "Cannot lookup prefsSafe" + "errorCode": "GPII_ERR_NO_PREFSSAFE", + "message": "Missing prefssafe" } ``` diff --git a/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js b/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js index ca0d60eca..fcbd5e47f 100644 --- a/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js +++ b/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js @@ -38,6 +38,7 @@ gpii.preferencesServer.cloudSafeCredCreate.handler.put = function (prefsService, function (err) { request.events.onError.fire({ isError: true, + errorCode: err.errorCode, message: err.message, statusCode: 404 }) @@ -63,10 +64,11 @@ gpii.preferencesServer.cloudSafeUnlockPost.handler.post = function (prefsService function (data) { request.events.onSuccess.fire(data); }, - function (/* err */) { + function (err) { request.events.onError.fire({ isError: true, - message: "Unable to unlock a Preferences Safe with the supplied credentials.", + errorCode: err.errorCode, + message: err.message, statusCode: 401 }); } diff --git a/gpii/node_modules/preferencesServer/src/preferencesServerConst.js b/gpii/node_modules/preferencesServer/src/preferencesServerConst.js index 33146c600..04a976fc0 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesServerConst.js +++ b/gpii/node_modules/preferencesServer/src/preferencesServerConst.js @@ -39,5 +39,35 @@ gpii.preferencesServer.errors = fluid.freezeRecursive({ missingPreferences: { errorCode: "GPII_ERR_NO_PREFS", message: "Missing preferences" + }, + missingPrefsSafe: { + errorCode: "GPII_ERR_NO_PREFSSAFE", + message: "Missing prefssafe" + }, + // Catch all error for unaccepted errors + errorAccessingPrefsSafe: { + errorCode: "GPII_ERR_ACCESSING_PREFSSAFE", + message: "Error accessing prefssafe" + }, + errorNotPrefsSafe: { + errorCode: "GPII_ERR_NOT_PREFSSAFE", + message: "Payload is not of type `prefsSafe`" + }, + errorNotPrefsSafeMissingId: { + errorCode: "GPII_ERR_NOT_PREFSSAFE_MISSING_ID", + message: "Payload requires an `id` and type of `prefsSafe`." + }, + errorCreateCredBadUsernamePassword: { + errorCode: "GPII_ERR_CREATE_CRED_BAD_USERNAME_PASSWORD", + message: "Unable to create credentials with this username and password combination" + }, + errorUnlockingPrefsSafeCredentials: { + errorCode: "GPII_ERR_UNLOCKING_PREFSSAFE_CREDENTIALS", + message: "Unable to unlock Preferences Safe with the supplied credentials." + }, + // Catch all error for unknown issues adding keys + errorAddingGpiiKey: { + errorCode: "GPII_ERR_ADDING_GPIIKEY", + message: "Unable to add GPII Key to Preferences Safe." } }); diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index c213309b4..49d90c8d2 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -192,7 +192,8 @@ var fluid = fluid || require("infusion"); if ($.isEmptyObject(data) || data.type !== "prefsSafe") { promiseTogo.reject({ isError: true, - message: "Cannot lookup prefsSafe", + errorCode: gpii.preferencesServer.errors.missingPrefsSafe.errorCode, + message: gpii.preferencesServer.errors.missingPrefsSafe.message }); } else { @@ -203,7 +204,8 @@ var fluid = fluid || require("infusion"); fluid.log("Error looking up prefsSafe: ", err); promiseTogo.reject({ isError: true, - message: "Error fetching prefsSafe", + errorCode: gpii.preferencesServer.errors.errorAccessingPrefsSafe.errorCode, + message: gpii.preferencesServer.errors.errorAccessingPrefsSafe.message }); } ); @@ -225,7 +227,8 @@ var fluid = fluid || require("infusion"); if (prefsSafeData.type !== "prefsSafe") { promiseTogo.reject({ isError: true, - message: "Payload needs to have a type of `prefsSafe`." + errorCode: gpii.preferencesServer.errors.errorNotPrefsSafe.errorCode, + message: gpii.preferencesServer.errors.errorNotPrefsSafe.message }); } else { @@ -252,7 +255,8 @@ var fluid = fluid || require("infusion"); if (!prefsSafeData.id || prefsSafeData.type !== "prefsSafe") { promiseTogo.reject({ isError: true, - message: "Payload needs to have an id and type of `prefsSafe`." + errorCode: gpii.preferencesServer.errors.errorNotPrefsSafeMissingId.errorCode, + message: gpii.preferencesServer.errors.errorNotPrefsSafeMissingId.message }); } else { @@ -303,7 +307,8 @@ var fluid = fluid || require("infusion"); fluid.log("Error adding cloud safe credential", err); promiseTogo.reject({ isError: true, - message: "Unable to create credentials with that username and password combination", + errorCode: gpii.preferencesServer.errors.errorCreateCredBadUsernamePassword.errorCode, + message: gpii.preferencesServer.errors.errorCreateCredBadUsernamePassword.message }); } else { @@ -340,7 +345,8 @@ var fluid = fluid || require("infusion"); fluid.log(err); promiseTogo.reject({ isError: true, - message: "Unable to unlock a Preferences Safe with the supplied credentials." + errorCode: gpii.preferencesServer.errors.errorUnlockingPrefsSafeCredentials.errorCode, + message: gpii.preferencesServer.errors.errorUnlockingPrefsSafeCredentials.message }); } ); @@ -519,7 +525,8 @@ var fluid = fluid || require("infusion"); fluid.log("Error adding key to preferences safe: ", keyData, error); promTogo.reject({ isError: true, - message: "Unable to add GPII Key to Preferences Safe." + errorCode: gpii.preferencesServer.errors.errorAddingGpiiKey.errorCode, + message: gpii.preferencesServer.errors.errorAddingGpiiKey.message }); } ); @@ -527,8 +534,9 @@ var fluid = fluid || require("infusion"); function (error) { fluid.log("Error in addGpiiKey prefSafe Lookup", error); promTogo.reject({ - "isError": true, - "message": "The prefs safe does not exist" + isError: true, + errorCode: gpii.preferencesServer.errors.missingPrefsSafe.errorCode, + message: gpii.preferencesServer.errors.missingPrefsSafe.message }); }); } diff --git a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js index a19ea72f0..fc45d369e 100644 --- a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js +++ b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js @@ -35,6 +35,7 @@ gpii.preferencesServer.prefsSafeGet.handler.getPrefsSafe = function (prefsServic request.events.onError.fire({ isError: true, message: err.message, + errorCode: err.errorCode, statusCode: 404 }) } @@ -57,6 +58,7 @@ gpii.preferencesServer.prefsSafeList.handler.getPrefsSafeList = function (prefsS request.events.onError.fire({ isError: true, message: err.message, + errorCode: err.errorCode, statusCode: 404 }) } @@ -82,6 +84,7 @@ gpii.preferencesServer.findRelatedDocsForPrefsSafe.handler.getKeysForPrefsSafe = request.events.onError.fire({ isError: true, message: err.message, + errorCode: err.errorCode, statusCode: 404 }); } @@ -114,6 +117,7 @@ gpii.preferencesServer.prefsSafeWithKeysGet.handler.get = function (prefsService request.events.onError.fire({ isError: true, message: err.message, + errorCode: err.errorCode, statusCode: 404 }); } diff --git a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js index 248de40e5..b5a3edec0 100644 --- a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js +++ b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js @@ -248,8 +248,9 @@ gpii.tests.preferencesServer.cloudSafeCred.put.failureFixtures = [ password: "testPassword" }, failedCreateExpected: { - isError: true, - message: "Unable to create credentials with that username and password combination" + "isError": true, + "message": "Unable to create credentials with this username and password combination", + "errorCode": "GPII_ERR_CREATE_CRED_BAD_USERNAME_PASSWORD" } } ]; @@ -325,8 +326,9 @@ gpii.tests.preferencesServer.cloudSafeCred.unlock.successFixtures = [ password: "notThePassword" }, unlockCloudSafeExpected: { - isError: true, - message: "Unable to unlock a Preferences Safe with the supplied credentials." + "isError": true, + "message": "Unable to unlock Preferences Safe with the supplied credentials.", + "errorCode": "GPII_ERR_UNLOCKING_PREFSSAFE_CREDENTIALS" } } ]; diff --git a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js index 710179d04..4c5dd9b51 100644 --- a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js +++ b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js @@ -480,7 +480,8 @@ fluid.defaults("gpii.tests.preferencesServer.preferencesService.addGpiiKey", { reject: "jqUnit.assertLeftHand", rejectArgs: ["Preference safe doesn't exist, can't create key", { "isError": true, - "message": "The prefs safe does not exist" + "message": "Missing prefssafe", + "errorCode": "GPII_ERR_NO_PREFSSAFE" }, "{arguments}.0"] }] } @@ -540,7 +541,8 @@ fluid.defaults("gpii.tests.preferencesServer.preferencesService.cloudSafeCredCre reject: "jqUnit.assertLeftHand", rejectArgs: ["Error indicating bad username and password for new credentials.", { "isError": true, - "message": "Unable to create credentials with that username and password combination" + "errorCode": "GPII_ERR_CREATE_CRED_BAD_USERNAME_PASSWORD", + "message": "Unable to create credentials with this username and password combination" }, "{arguments}.0"] }] } @@ -577,7 +579,7 @@ fluid.defaults("gpii.tests.preferencesServer.preferencesService.cloudSafeUnlock" task: "{preferencesService}.cloudSafeUnlock", args: [{username: "prefs7user", password: "wrongPassword"}], reject: "jqUnit.assertDeepEq", - rejectArgs: ["Should fail with message", "Unable to unlock a Preferences Safe with the supplied credentials.", "{arguments}.0.message"] + rejectArgs: ["Should fail with message", "Unable to unlock Preferences Safe with the supplied credentials.", "{arguments}.0.message"] }] } ] diff --git a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js index ab5e4789e..1ff5f406b 100644 --- a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js +++ b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js @@ -103,7 +103,8 @@ gpii.tests.preferencesServer.prefsSafes.get.failFixtures = [ expectedStatusCode: 404, expected: { "isError": true, - "message": "Cannot lookup prefsSafe" + "errorCode": "GPII_ERR_NO_PREFSSAFE", + "message": "Missing prefssafe" } } ]; @@ -202,7 +203,8 @@ gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.failFixtures = [ expectedStatusCode: 404, expected: { "isError": true, - "message": "Cannot lookup prefsSafe" + "errorCode": "GPII_ERR_NO_PREFSSAFE", + "message": "Missing prefssafe" } } ]; @@ -578,7 +580,8 @@ gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.failFixtures = [ expectedStatusCode: 404, expected: { "isError": true, - "message": "Cannot lookup prefsSafe" + "errorCode": "GPII_ERR_NO_PREFSSAFE", + "message": "Missing prefssafe" } } ]; From 82c1137e8cccf5129620a59c643e2ba5661e1ebc Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Tue, 19 Mar 2019 20:24:56 -0700 Subject: [PATCH 52/72] GPII-2966 Updating .nycrc with new source parts --- .nycrc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.nycrc b/.nycrc index 640be7eb6..a8b1707f8 100644 --- a/.nycrc +++ b/.nycrc @@ -78,12 +78,14 @@ "!**/gpii/node_modules/ontologyHandler/src/ontologyHandler.js", "!**/gpii/node_modules/ontologyHandler/src/ontologyHandlerUtilities.js", "!**/gpii/node_modules/preferencesServer/index.js", + "!**/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js" "!**/gpii/node_modules/preferencesServer/src/preferencesGetHandler.js", "!**/gpii/node_modules/preferencesServer/src/preferencesPostHandler.js", "!**/gpii/node_modules/preferencesServer/src/preferencesPutHandler.js", "!**/gpii/node_modules/preferencesServer/src/preferencesServer.js", "!**/gpii/node_modules/preferencesServer/src/preferencesServerConst.js", "!**/gpii/node_modules/preferencesServer/src/preferencesService.js", + "!**/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js", "!**/gpii/node_modules/preferencesServer/src/readyGetHandler.js", "!**/gpii/node_modules/processReporter/index.js", "!**/gpii/node_modules/processReporter/src/ProcessReporter.js", From 52f15b4aa629b653346182e9391f3f51dc06d320 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Tue, 26 Mar 2019 12:22:51 -0700 Subject: [PATCH 53/72] GPII-2966 Adding error message and codes, linting, adding more tests and payload checks. --- .nycrc | 2 +- documentation/PreferencesServer.md | 1 + .../src/cloudSafeCredHandlers.js | 2 +- .../src/preferencesServerConst.js | 8 ++ .../src/preferencesService.js | 36 +++++--- .../src/prefsSafesHandlers.js | 45 ++++++++-- .../preferencesServer/test/prefsSafesTests.js | 83 ++++++++++++++++++- 7 files changed, 157 insertions(+), 20 deletions(-) diff --git a/.nycrc b/.nycrc index a8b1707f8..35b2c3cee 100644 --- a/.nycrc +++ b/.nycrc @@ -78,7 +78,7 @@ "!**/gpii/node_modules/ontologyHandler/src/ontologyHandler.js", "!**/gpii/node_modules/ontologyHandler/src/ontologyHandlerUtilities.js", "!**/gpii/node_modules/preferencesServer/index.js", - "!**/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js" + "!**/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js", "!**/gpii/node_modules/preferencesServer/src/preferencesGetHandler.js", "!**/gpii/node_modules/preferencesServer/src/preferencesPostHandler.js", "!**/gpii/node_modules/preferencesServer/src/preferencesPutHandler.js", diff --git a/documentation/PreferencesServer.md b/documentation/PreferencesServer.md index 98b578883..e59b42cb1 100644 --- a/documentation/PreferencesServer.md +++ b/documentation/PreferencesServer.md @@ -560,6 +560,7 @@ suitable message will be returned. ```json { "isError": true, + "errorCode": "APPROPRIATE_ERROR_CODE", "message": "System error described here." } ``` diff --git a/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js b/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js index fcbd5e47f..474782cc2 100644 --- a/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js +++ b/gpii/node_modules/preferencesServer/src/cloudSafeCredHandlers.js @@ -41,7 +41,7 @@ gpii.preferencesServer.cloudSafeCredCreate.handler.put = function (prefsService, errorCode: err.errorCode, message: err.message, statusCode: 404 - }) + }); } ); }; diff --git a/gpii/node_modules/preferencesServer/src/preferencesServerConst.js b/gpii/node_modules/preferencesServer/src/preferencesServerConst.js index 04a976fc0..67ac6bcd8 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesServerConst.js +++ b/gpii/node_modules/preferencesServer/src/preferencesServerConst.js @@ -57,6 +57,14 @@ gpii.preferencesServer.errors = fluid.freezeRecursive({ errorCode: "GPII_ERR_NOT_PREFSSAFE_MISSING_ID", message: "Payload requires an `id` and type of `prefsSafe`." }, + errorUrlPayloadIdMismatch: { + errorCode: "GPII_ERR_URL_PAYLOAD_ID_MISMATCH", + message: "The ID parameter in the URL does not match the ID in the payload." + }, + errorMissingPrefsSafeAndSetId: { + errorCode: "GPII_ERR_MISSING_PREFSAFE_PREFSET_IDS", + message: "Unable to process. `prefsSafeId` and `prefsSetId` are required fields." + }, errorCreateCredBadUsernamePassword: { errorCode: "GPII_ERR_CREATE_CRED_BAD_USERNAME_PASSWORD", message: "Unable to create credentials with this username and password combination" diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index 49d90c8d2..bc5c92a43 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -45,7 +45,6 @@ var fluid = fluid || require("infusion"); } }, invokers: { - // TODO check type == prefsSafe getPrefsSafe: { funcName: "gpii.preferencesServer.preferencesService.getPrefsSafe", args: ["{dataStore}", "{arguments}.0"] @@ -260,14 +259,30 @@ var fluid = fluid || require("infusion"); }); } else { - dataStore.updatePrefsSafe(prefsSafeData.id, prefsSafeData).then( - function (/* updatedReturn */) { - that.getPrefsSafe(prefsSafeData.id).then( - function (finalData) { - promiseTogo.resolve(finalData); - }, promiseTogo.reject); - }, - promiseTogo.reject); + that.getPrefsSafe(prefsSafeData.id).then(function () { + dataStore.updatePrefsSafe(prefsSafeData.id, prefsSafeData).then( + function (/* updatedReturn */) { + that.getPrefsSafe(prefsSafeData.id).then( + function (finalData) { + promiseTogo.resolve(finalData); + }, + function (err) { + promiseTogo.reject(err); + } + ); + }, + function (err) { + promiseTogo.reject(err); + } + ); + }, function (err) { + fluid.log(err); + promiseTogo.reject({ + isError: true, + errorCode: gpii.preferencesServer.errors.missingPrefsSafe.errorCode, + message: gpii.preferencesServer.errors.missingPrefsSafe.message + }); + }); } return promiseTogo; }; @@ -505,7 +520,8 @@ var fluid = fluid || require("infusion"); if (!keyData.prefsSafeId || !keyData.prefsSetId) { promTogo.reject({ isError: true, - message: "Unable to add GPII Key to Preferences Safe. `prefsSafeId` and `prefsSetId` are required fields." + errorCode: gpii.preferencesServer.errors.errorMissingPrefsSafeAndSetId.errorCode, + message: gpii.preferencesServer.errors.errorMissingPrefsSafeAndSetId.message }); } else { diff --git a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js index fc45d369e..48e8d3c9c 100644 --- a/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js +++ b/gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js @@ -37,7 +37,7 @@ gpii.preferencesServer.prefsSafeGet.handler.getPrefsSafe = function (prefsServic message: err.message, errorCode: err.errorCode, statusCode: 404 - }) + }); } ); }; @@ -60,7 +60,7 @@ gpii.preferencesServer.prefsSafeList.handler.getPrefsSafeList = function (prefsS message: err.message, errorCode: err.errorCode, statusCode: 404 - }) + }); } ); }; @@ -137,7 +137,15 @@ fluid.defaults("gpii.preferencesServer.prefsSafePost.handler", { gpii.preferencesServer.prefsSafePost.handler.updatePrefsSafe = function (preferencesService, request, prefsSafe) { preferencesService.addPrefsSafe(prefsSafe).then( request.events.onSuccess.fire, - request.events.onError.fire); + function (err) { + request.events.onError.fire({ + isError: true, + message: err.message, + errorCode: err.errorCode, + statusCode: 404 + }); + } + ); }; fluid.defaults("gpii.preferencesServer.prefsSafePut.handler", { @@ -151,12 +159,28 @@ fluid.defaults("gpii.preferencesServer.prefsSafePut.handler", { }); gpii.preferencesServer.prefsSafePut.handler.updatePrefsSafe = function (preferencesService, request, prefsSafeId, prefsSafe) { + if (prefsSafeId !== prefsSafe.id) { + request.events.onError.fire({ + isError: true, + message: gpii.preferencesServer.errors.errorUrlPayloadIdMismatch.message, + errorCode: gpii.preferencesServer.errors.errorUrlPayloadIdMismatch.errorCode, + statusCode: 404 + }); + }; + preferencesService.updatePrefsSafe(prefsSafe).then( request.events.onSuccess.fire, - request.events.onError.fire); + function (err) { + request.events.onError.fire({ + isError: true, + message: err.message, + errorCode: err.errorCode, + statusCode: 404 + }); + } + ); }; - fluid.defaults("gpii.preferencesServer.prefsSafeKeyCreate.handler", { gradeNames: ["kettle.request.http"], invokers: { @@ -168,5 +192,14 @@ fluid.defaults("gpii.preferencesServer.prefsSafeKeyCreate.handler", { }); gpii.preferencesServer.prefsSafeKeyCreate.handler.addGpiiKey = function (preferencesService, body, request) { - preferencesService.addGpiiKey(body).then(request.events.onSuccess.fire, request.events.onError.fire); + preferencesService.addGpiiKey(body).then(request.events.onSuccess.fire, + function (err) { + request.events.onError.fire({ + isError: true, + message: err.message, + errorCode: err.errorCode, + statusCode: 404 + }); + } + ); }; diff --git a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js index 1ff5f406b..bfd5c5269 100644 --- a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js +++ b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js @@ -299,6 +299,81 @@ gpii.tests.preferencesServer.prefsSafes.putSafe.successFixtures = [ } ]; +gpii.tests.preferencesServer.prefsSafes.putSafe.failFixtures = [ + { + name: "PUT: Failure to put a safe that doesn't exist yet.", + expectedStatusCode: 404, + prefsSafeId: "prefsSafe-4000", + url: "%prefsSafeId", + putBody: { + "id": "prefsSafe-4000", + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": "Prefs Seven", + "email": null, + "preferences": { + "flat": { + "name": "bit of stuff", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/onScreenKeyboard/enabled": false + }, + "metadata": [] + } + }, + "metadata": [] + } + }, + "timestampCreated": "2017-12-14T19:55:11.641Z", + "timestampUpdated": null + }, + expected: { + isError: true, + errorCode: "GPII_ERR_NO_PREFSSAFE", + message: "Missing prefssafe" + } + }, + { + name: "PUT: Failure to put a safe whose URL ID does not match the payload ID", + expectedStatusCode: 404, + prefsSafeId: "prefsSafe-1", + url: "%prefsSafeId", + putBody: { + "id": "prefsSafe-7", + "type": "prefsSafe", + "schemaVersion": "0.1", + "prefsSafeType": "user", + "name": "Prefs Seven", + "email": null, + "preferences": { + "flat": { + "name": "bit of stuff", + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/onScreenKeyboard/enabled": false + }, + "metadata": [] + } + }, + "metadata": [] + } + }, + "timestampCreated": "2017-12-14T19:55:11.641Z", + "timestampUpdated": null + }, + expected: { + isError: true, + errorCode: "GPII_ERR_URL_PAYLOAD_ID_MISMATCH", + message: "The ID parameter in the URL does not match the ID in the payload." + } + } +]; + /////////////////////// TESTING prefsSafes Create (POST) //////////////////////////// fluid.registerNamespace("gpii.tests.preferencesServer.prefsSafes.postSafe"); @@ -638,14 +713,15 @@ gpii.tests.preferencesServer.prefsSafes.prefsSafeKeyCreate.successFixtures = [ gpii.tests.preferencesServer.prefsSafes.prefsSafeKeyCreate.failFixtures = [ { name: "POST: Failure expected when not including the safe id and prefset id", - expectedStatusCode: 500, + expectedStatusCode: 404, postBody: { // "prefsSafeId": "prefsSafe-1", "prefsSetId": "gpii-lowlight" }, expected: { isError: true, - message: "Unable to add GPII Key to Preferences Safe. `prefsSafeId` and `prefsSetId` are required fields." + errorCode: "GPII_ERR_MISSING_PREFSAFE_PREFSET_IDS", + message: "Unable to process. `prefsSafeId` and `prefsSetId` are required fields." } } ]; @@ -661,6 +737,9 @@ gpii.tests.preferencesServer.prefsSafes.testMap = [ { }, { build: gpii.tests.preferencesServer.prefsSafes.putSafe.buildTestDef, fixtures: gpii.tests.preferencesServer.prefsSafes.putSafe.successFixtures +}, { + build: gpii.tests.preferencesServer.prefsSafes.putSafe.buildTestDef, + fixtures: gpii.tests.preferencesServer.prefsSafes.putSafe.failFixtures }, { build: gpii.tests.preferencesServer.prefsSafes.postSafe.buildTestDef, fixtures: gpii.tests.preferencesServer.prefsSafes.postSafe.successFixtures From 0c56fe9f356f5154702a4024c3c55f53fe386612 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Tue, 26 Mar 2019 14:53:38 -0700 Subject: [PATCH 54/72] GPII-2966 Minimal validation for usernames and passwords. --- .../src/preferencesService.js | 14 +++++ .../test/cloudSafeCredTests.js | 58 +++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index bc5c92a43..b586d5053 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -296,6 +296,10 @@ var fluid = fluid || require("infusion"); * the cloudsafe credential document that will contain the ID's of both * the prefssafe and the user record. * + * Currently this method does only a small amount of validation on the username + * and password, requiring that both fields are included and of length greater than + * length zero. + * * @param {Object} that - Instance of `gpii.preferencesServer.preferencesService`. * @param {Object} options - Data used to create the new credentials. * @param {String} options.prefsSafeId - Id for the preferences safe we are adding @@ -306,6 +310,16 @@ var fluid = fluid || require("infusion"); */ gpii.preferencesServer.preferencesService.cloudSafeCredCreate = function (that, options) { var promiseTogo = fluid.promise(); + + if (!options.username || !options.password) { + promiseTogo.reject({ + isError: true, + errorCode: gpii.preferencesServer.errors.errorCreateCredBadUsernamePassword.errorCode, + message: gpii.preferencesServer.errors.errorCreateCredBadUsernamePassword.message + }); + return promiseTogo; + } + fluid.promise.fireTransformEvent(that.events.onCloudSafeCredCreate, options.prefsSafeId, options).then( promiseTogo.resolve, function (err) { diff --git a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js index b5a3edec0..e1dfe2ace 100644 --- a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js +++ b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js @@ -252,6 +252,64 @@ gpii.tests.preferencesServer.cloudSafeCred.put.failureFixtures = [ "message": "Unable to create credentials with this username and password combination", "errorCode": "GPII_ERR_CREATE_CRED_BAD_USERNAME_PASSWORD" } + }, + { + name: "Unsuccessful PUT: Missing username", + expectedStatusCode: 404, + prefsSafeId: "prefsSafe-1", + url: "%prefsSafeId", + putCloudCredBody: { + password: "testPassword" + }, + failedCreateExpected: { + "isError": true, + "message": "Unable to create credentials with this username and password combination", + "errorCode": "GPII_ERR_CREATE_CRED_BAD_USERNAME_PASSWORD" + } + }, + { + name: "Unsuccessful PUT: Missing password", + expectedStatusCode: 404, + prefsSafeId: "prefsSafe-1", + url: "%prefsSafeId", + putCloudCredBody: { + username: "spectacularUsername" + }, + failedCreateExpected: { + "isError": true, + "message": "Unable to create credentials with this username and password combination", + "errorCode": "GPII_ERR_CREATE_CRED_BAD_USERNAME_PASSWORD" + } + }, + { + name: "Unsuccessful PUT: Empty password", + expectedStatusCode: 404, + prefsSafeId: "prefsSafe-1", + url: "%prefsSafeId", + putCloudCredBody: { + username: "spectacularUsername", + password: "" + }, + failedCreateExpected: { + "isError": true, + "message": "Unable to create credentials with this username and password combination", + "errorCode": "GPII_ERR_CREATE_CRED_BAD_USERNAME_PASSWORD" + } + }, + { + name: "Unsuccessful PUT: Empty username", + expectedStatusCode: 404, + prefsSafeId: "prefsSafe-1", + url: "%prefsSafeId", + putCloudCredBody: { + username: "", + password: "s3cret" + }, + failedCreateExpected: { + "isError": true, + "message": "Unable to create credentials with this username and password combination", + "errorCode": "GPII_ERR_CREATE_CRED_BAD_USERNAME_PASSWORD" + } } ]; From c614c318b0b44b35954a86d40cf3c09c39d89f83 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Tue, 26 Mar 2019 17:16:02 -0700 Subject: [PATCH 55/72] GPII-2966 Updated docs for adding credentials endpoint. --- documentation/PreferencesServer.md | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/documentation/PreferencesServer.md b/documentation/PreferencesServer.md index e59b42cb1..08ccb1d82 100644 --- a/documentation/PreferencesServer.md +++ b/documentation/PreferencesServer.md @@ -512,6 +512,7 @@ with the contents of the system error: ```json { "isError": true, + "errorCode": "GPII_ERR_APPLICABLE_MESSAGE", "message": "System error described here." } ``` @@ -686,11 +687,12 @@ In the event of any system error, an error payload with a suitable `message` is ```json { "isError": true, + "errorCode": "GPII_ERR_APPLICABLE_MESSAGE", "message": "System error described here." } ``` -### PUT /add-cloud-credential/:prefsSafeId +### PUT /add-cloud-credentials/:prefsSafeId This endpoint will add a new username and password credential set to the preferences safe whose id is specified in the URL parameter `prefsSafeId`. The body is a JSON payload containing the username and password for the new @@ -698,7 +700,7 @@ credential set. #### Example PUT -URL: `http://preferences.gpii.net/add-cloud-credential/prefsSafe-1` +URL: `http://preferences.gpii.net/add-cloud-credentials/prefsSafe-1` The above indicates that the credentials will be added to preferences safe with `id` `prefsSafe-1`. @@ -711,6 +713,28 @@ putBody: } ``` +Example successful return payload: + +```json +{ + "_id": "8f3085a7-b65b-4648-9a78-8ac7de766997" + "type": "gpiiCloudSafeCredential", + "schemaVersion": "0.1", + "prefsSafeId": "prefsSafe-1", + "gpiiExpressUserId": "org.couch.db.user:prefs1user", +} +``` + +In the event of any system error, an error payload with a suitable `message` is returned. + +```json +{ + "isError": true, + "errorCode": "GPII_ERR_APPLICABLE_MESSAGE", + "message": "System error described here." +} +``` + ### POST /unlock-cloud-safe This endpoint allows you to verify if a username and password combination will unclock a preferences safe that @@ -746,6 +770,7 @@ If the username and password do not match a record the following error is return ```json { "isError": true, + "errorCode": "GPII_ERR_UNLOCKING_PREFSSAFE_CREDENTIALS", "message": "Unable to unlock a Preferences Safe with the supplied credentials." } ``` From f2a2d156de9720f639321d99ab6af07920ebd4f4 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Tue, 26 Mar 2019 19:23:33 -0700 Subject: [PATCH 56/72] GPII-2966 More cleanup for reject promise messages and errorCodes. --- documentation/PreferencesServer.md | 4 ++-- gpii/node_modules/gpii-db-operation/src/DbUtils.js | 8 +++++--- gpii/node_modules/preferencesServer/index.js | 2 +- .../preferencesServer/src/preferencesService.js | 10 ++++++++-- .../preferencesServer/test/cloudSafeCredTests.js | 3 ++- .../preferencesServer/test/preferencesServiceTests.js | 3 ++- 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/documentation/PreferencesServer.md b/documentation/PreferencesServer.md index 08ccb1d82..d7fe83ef0 100644 --- a/documentation/PreferencesServer.md +++ b/documentation/PreferencesServer.md @@ -717,11 +717,11 @@ Example successful return payload: ```json { - "_id": "8f3085a7-b65b-4648-9a78-8ac7de766997" + "_id": "8f3085a7-b65b-4648-9a78-8ac7de766997", "type": "gpiiCloudSafeCredential", "schemaVersion": "0.1", "prefsSafeId": "prefsSafe-1", - "gpiiExpressUserId": "org.couch.db.user:prefs1user", + "gpiiExpressUserId": "org.couch.db.user:prefs1user" } ``` diff --git a/gpii/node_modules/gpii-db-operation/src/DbUtils.js b/gpii/node_modules/gpii-db-operation/src/DbUtils.js index c3c3ce846..d23c02ad4 100644 --- a/gpii/node_modules/gpii-db-operation/src/DbUtils.js +++ b/gpii/node_modules/gpii-db-operation/src/DbUtils.js @@ -53,11 +53,13 @@ gpii.dbOperation.getCurrentTimestamp = function () { * member. * @param {String} errorMessage - If this isn't the appropriate type, this message will be * included in the promise rejection payload. + * @param {String} errorCode - If this isn't the appropriate type, this error code will be + * included in the promise rejection payload. * @return {fluid.promise} Promise, when the item is valid is resolves with the * original item. When the item is not valid, it rejects with an error payload including * the supplied `errorMessage`. */ -gpii.dbOperation.verifyExists = function (item, type, errorMessage) { +gpii.dbOperation.verifyExists = function (item, type, errorMessage, errorCode) { var togo = fluid.promise(); if (item && item.type === type) { togo.resolve(item); @@ -65,8 +67,8 @@ gpii.dbOperation.verifyExists = function (item, type, errorMessage) { else { togo.reject({ isError: true, - message: errorMessage, - statusCode: 404 + errorCode: errorCode, + message: errorMessage }); } return togo; diff --git a/gpii/node_modules/preferencesServer/index.js b/gpii/node_modules/preferencesServer/index.js index 2be7eda08..b9126f2f6 100644 --- a/gpii/node_modules/preferencesServer/index.js +++ b/gpii/node_modules/preferencesServer/index.js @@ -10,8 +10,8 @@ require("./src/preferencesPostHandler.js"); require("./src/preferencesPutHandler.js"); require("./src/readyGetHandler.js"); require("../flowManager/src/HealthGetHandler.js"); -require("./src/preferencesService.js"); require("./src/preferencesServerConst.js"); +require("./src/preferencesService.js"); require("./src/preferencesServer.js"); require("./src/prefsSafesHandlers.js"); require("./src/cloudSafeCredHandlers.js"); diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index b586d5053..6d5d53108 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -131,7 +131,8 @@ var fluid = fluid || require("infusion"); namespace: "findById" }, { func: "gpii.dbOperation.verifyExists", - args: ["{arguments}.0", "prefsSafe", "The prefs safe does not exist"] + args: ["{arguments}.0", "prefsSafe", gpii.preferencesServer.errors.missingPrefsSafe.message, + gpii.preferencesServer.errors.missingPrefsSafe.errorCode] }, { func: "{expressUserUtils}.createNewUser", args: [{username: "{arguments}.1.username", password: "{arguments}.1.password"}], @@ -267,7 +268,12 @@ var fluid = fluid || require("infusion"); promiseTogo.resolve(finalData); }, function (err) { - promiseTogo.reject(err); + fluid.log(err); + promiseTogo.reject({ + isError: true, + errorCode: gpii.preferencesServer.errors.missingPrefsSafe.errorCode, + message: gpii.preferencesServer.errors.missingPrefsSafe.message + }); } ); }, diff --git a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js index e1dfe2ace..313d12aef 100644 --- a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js +++ b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js @@ -235,7 +235,8 @@ gpii.tests.preferencesServer.cloudSafeCred.put.failureFixtures = [ }, failedCreateExpected: { isError: true, - message: "The prefs safe does not exist" + errorCode: "GPII_ERR_NO_PREFSSAFE", + message: "Missing prefssafe" } }, { diff --git a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js index 4c5dd9b51..bae93e802 100644 --- a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js +++ b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js @@ -529,7 +529,8 @@ fluid.defaults("gpii.tests.preferencesServer.preferencesService.cloudSafeCredCre reject: "jqUnit.assertLeftHand", rejectArgs: ["Error message saying the prefs safe does not exist.", { "isError": true, - "message": "The prefs safe does not exist" + "message": "Missing prefssafe", + "errorCode": "GPII_ERR_NO_PREFSSAFE" }, "{arguments}.0"] }] }, From c98ea65bbfbf4a8416e71eb79cf4576a842e2938 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Wed, 27 Mar 2019 12:08:22 -0700 Subject: [PATCH 57/72] GPII-2966 Minor fix to tests to compensate for unpredictable array ordering of keys. --- .../preferencesServer/test/cloudSafeCredTests.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js index 313d12aef..67b224d47 100644 --- a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js +++ b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js @@ -55,8 +55,9 @@ gpii.tests.preferencesServer.cloudSafeCred.testCloudSafeCreatePut = function (cl gpii.tests.preferencesServer.cloudSafeCred.testCloudSafeCred = function (response /*, expected, receivedStatusCode, expectedStatusCode */) { var data = JSON.parse(response); jqUnit.assertEquals("There should be a prefsSafe", data.prefsSafe.type, "prefsSafe"); - jqUnit.assertEquals("There should be a cloud cred", data.keys[0].type, "gpiiCloudSafeCredential"); - jqUnit.assertEquals("There should be a gpii key", data.keys[1].type, "gpiiKey"); + var keyTypes = fluid.getMembers(data.keys, "type"); + jqUnit.assertTrue("There should be a cloud cred", fluid.contains(keyTypes, "gpiiCloudSafeCredential")); + jqUnit.assertTrue("There should be a gpii key", fluid.contains(keyTypes, "gpiiKey")); }; gpii.tests.preferencesServer.cloudSafeCred.put.buildSuccessTestDef = function (fixture) { From 2ff8f59d56845e117c6b1b68c3cf79804645d231 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Wed, 10 Apr 2019 10:20:48 -0700 Subject: [PATCH 58/72] GPII-2966 Minor typo and comment updates based on PR. --- documentation/PreferencesServer.md | 2 +- .../gpii-db-operation/src/DbUtils.js | 10 +++++----- .../gpii-db-operation/test/DbDataStoreTests.js | 4 ++-- .../preferencesServer/src/preferencesService.js | 16 ++++++++++------ 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/documentation/PreferencesServer.md b/documentation/PreferencesServer.md index d7fe83ef0..66bcee595 100644 --- a/documentation/PreferencesServer.md +++ b/documentation/PreferencesServer.md @@ -506,7 +506,7 @@ The POST payload should be a full preferences safe without an `id`: ``` A successful return payload will consist of the same payload with the addition of timestamps and a -freshly generated `id` field. In the event of an error a payload similar to the following will be returned +freshly generated `id` field. In the event of an error, a payload similar to the following will be returned with the contents of the system error: ```json diff --git a/gpii/node_modules/gpii-db-operation/src/DbUtils.js b/gpii/node_modules/gpii-db-operation/src/DbUtils.js index d23c02ad4..44f918251 100644 --- a/gpii/node_modules/gpii-db-operation/src/DbUtils.js +++ b/gpii/node_modules/gpii-db-operation/src/DbUtils.js @@ -46,16 +46,16 @@ gpii.dbOperation.getCurrentTimestamp = function () { * The current criteria for validity is that the item is not undefined and has * the `type` that is supplied in the arguments. * - * @param {Object} item - Item, mostly a return from another API or CouchDB call + * @param {Object} item - Item, mostly a return from another API or CouchDB call * that we are checking to make sure it's of the appropriate type. - * @param {String} type - The `type` that the item should be of. This is to + * @param {String} type - The `type` that the item should be of. This is to * follow the convention we have for CouchDB records where each record has a `type` * member. - * @param {String} errorMessage - If this isn't the appropriate type, this message will be + * @param {String} errorMessage - If this isn't the appropriate type, this message will be * included in the promise rejection payload. - * @param {String} errorCode - If this isn't the appropriate type, this error code will be + * @param {String} errorCode - If this isn't the appropriate type, this error code will be * included in the promise rejection payload. - * @return {fluid.promise} Promise, when the item is valid is resolves with the + * @return {fluid.promise} Promise, when the item is valid it resolves with the * original item. When the item is not valid, it rejects with an error payload including * the supplied `errorMessage`. */ diff --git a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTests.js b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTests.js index 2c88f4559..d16842ef5 100644 --- a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTests.js +++ b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTests.js @@ -536,7 +536,7 @@ fluid.defaults("gpii.tests.dbDataStore.findRelatedDocsForPrefsSafe", { task: "{dbDataStore}.findRelatedDocsForPrefsSafe", args: ["prefsSafe-1"], resolve: "jqUnit.assertLeftHand", - resolveArgs: ["Expecing a list of keys for prefsSafe-1.", gpii.tests.dbDataStore.testData.findRelatedDocsForPrefsSafe_prefsSafe1, "{arguments}.0"] + resolveArgs: ["Expecting a list of keys for prefsSafe-1.", gpii.tests.dbDataStore.testData.findRelatedDocsForPrefsSafe_prefsSafe1, "{arguments}.0"] }] }] }] @@ -552,7 +552,7 @@ fluid.defaults("gpii.tests.dbDataStore.findSafeByExpressUserLookup", { task: "{dbDataStore}.findSafeByExpressUserLookup", args: ["org.couch.db.user:prefs1user"], resolve: "jqUnit.assertDeepEq", - resolveArgs: ["Expecing a safe from the express lookup.", gpii.tests.dbDataStore.testData.findSafeByExpressUserLookup_credential, "{arguments}.0"] + resolveArgs: ["Expecting a safe from the express lookup.", gpii.tests.dbDataStore.testData.findSafeByExpressUserLookup_credential, "{arguments}.0"] }] }] }] diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index 6d5d53108..13aa8966e 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -180,9 +180,9 @@ var fluid = fluid || require("infusion"); * Returns a preferences safe using it's id. If the safe is not found an error object * is returned. * - * @param {Object} dataStore - Instance of `gpii.dbOperation.dataStore` - * @param {String} prefsSafeId Prefs Safe ID - * @return {Promise} Returns a promise resolving with the preferences safe, + * @param {Object} dataStore - Instance of `gpii.dbOperation.dataStore` + * @param {String} prefsSafeId - Prefs Safe ID + * @return {Promise} Returns a promise resolving with the preferences safe, * or rejecting with an error payload containing an error `message`. */ gpii.preferencesServer.preferencesService.getPrefsSafe = function (dataStore, prefsSafeId) { @@ -213,12 +213,13 @@ var fluid = fluid || require("infusion"); }; /** - * Adds a new preferences safe to CouchDB using the preferences safe format - * minus the `id`, `timestampCreated`, and `timestampUpdated` properties. + * Adds a new preferences safe to CouchDB using the preferences safe format. * * @param {Object} that - Instance of `gpii.preferencesServer.preferencesService`. * @param {Object} dataStore - Instance of `gpii.dbOperation.dataStore` - * @param {Object} prefsSafeData - Preferences safe to add to system. + * @param {Object} prefsSafeData - Preferences safe to add to system. The following fields + * are not required as part of this payload, and will be automatically created upon add: + * `id`, `timestampCreated`, and `timestampUpdated` properties. * @return {Promise} Returns a promise resolving with the newly created * preferences safe, or rejecting with an error payload containing an error `message`. */ @@ -232,6 +233,7 @@ var fluid = fluid || require("infusion"); }); } else { + // TODO This will have json schema validation when the scaffolding is all in. dataStore.addPrefsSafe(prefsSafeData).then( function (updatedReturn) { that.getPrefsSafe(updatedReturn.id).then(promiseTogo.resolve, promiseTogo.reject); @@ -261,6 +263,7 @@ var fluid = fluid || require("infusion"); } else { that.getPrefsSafe(prefsSafeData.id).then(function () { + // TODO This will have json schema validation when the scaffolding is all in. dataStore.updatePrefsSafe(prefsSafeData.id, prefsSafeData).then( function (/* updatedReturn */) { that.getPrefsSafe(prefsSafeData.id).then( @@ -547,6 +550,7 @@ var fluid = fluid || require("infusion"); else { // Preferences Safe must exist to add this key that.getPrefsSafe(keyData.prefsSafeId).then(function () { + // TODO This will have json schema validation when the scaffolding is all in. // Add the new key... dataStore.addGpiiKey({ gpiiKey: keyData.gpiiKey, // Can be undefined From bdac5f59d911c4d533be9b4a0c3a7fd2a131199e Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Wed, 10 Apr 2019 11:45:24 -0700 Subject: [PATCH 59/72] GPII-2966 Swapping out token terminology with key --- documentation/PreferencesServer.md | 2 +- .../preferencesServer/test/preferencesServerTests.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/PreferencesServer.md b/documentation/PreferencesServer.md index 66bcee595..2d50137f8 100644 --- a/documentation/PreferencesServer.md +++ b/documentation/PreferencesServer.md @@ -648,7 +648,7 @@ An example payload for a particlar safe may be: This endpoint will add a new `gpiiKey` document to the system. There are no URL parameters, but the JSON body takes 3 fields, one of them optional. Required are the `prefsSafeId` and `prefsSetId`. These indicate the preferences safe, -and the respective preferences set that this key and token will operate upon. Optionally you can pass in a unique +and the respective preferences set that this key will operate upon. Optionally you can pass in a unique unused `gpiiKey` to use, otherwise a new one will be generated as part of the process. The new document is returned upon success. In event of a failure, a standard error document is returned with `isError` true, and a message detailing the failure. diff --git a/gpii/node_modules/preferencesServer/test/preferencesServerTests.js b/gpii/node_modules/preferencesServer/test/preferencesServerTests.js index 3cee02215..25c6a9515 100644 --- a/gpii/node_modules/preferencesServer/test/preferencesServerTests.js +++ b/gpii/node_modules/preferencesServer/test/preferencesServerTests.js @@ -718,7 +718,7 @@ fluid.registerNamespace("gpii.tests.preferencesServer.put"); gpii.tests.preferencesServer.put.testRequestResponse = function (response, prefs, gpiiKey) { var retrievedData = JSON.parse(response); - // expect preferences without ontology info - any generated user token is fine + // expect preferences without ontology info - any generated GPII key is fine var expected = { preferences: prefs, gpiiKey: gpiiKey From 8b2b97b964cce3e63d49248dd56fbe5659f673d9 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Thu, 27 Jun 2019 12:36:08 -0700 Subject: [PATCH 60/72] GPII-2966 Bumping dev release of gpii-express-user - Brings kettle, infusion, and gpii-json-schema to same versions as universal --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b1648c0e6..2e86c016d 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "express-session": "1.15.6", "fluid-resolve": "1.3.0", "glob": "7.1.3", - "gpii-express-user": "1.0.1", + "gpii-express-user": "1.0.2-dev.20190627T120852Z.015bb40.GPII-3921", "@google-cloud/trace-agent": "3.4.0", "gpii-couchdb-test-harness": "1.0.0-dev.20190627T080736Z.0e3a1fd.GPII-3531", "gpii-json-schema": "2.1.0", From d0904d4649b2f48529f2e9edf3cde4ede10827b6 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Wed, 18 Dec 2019 19:42:44 -0800 Subject: [PATCH 61/72] GPII-2966 Updating prefSafe and gpiiKey schema versions in test data --- .../test/DbDataStoreTestsUtils.js | 2 +- .../preferencesServer/test/cloudSafeCredTests.js | 4 ++-- .../test/preferencesServiceTests.js | 8 ++++---- .../preferencesServer/test/prefsSafesTests.js | 14 +++++++------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js index 41abb7e88..f884e44cd 100644 --- a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js +++ b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js @@ -345,7 +345,7 @@ gpii.tests.dbDataStore.testData = { }, { "type": "gpiiKey", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-1", "prefsSetId": "gpii-default", "revoked": false, diff --git a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js index 67b224d47..419a3506c 100644 --- a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js +++ b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js @@ -142,7 +142,7 @@ gpii.tests.preferencesServer.cloudSafeCred.put.successFixtures = [ unlockCloudSafeExpected: { "id": "prefsSafe-1", "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "user", "name": null, "email": null, @@ -355,7 +355,7 @@ gpii.tests.preferencesServer.cloudSafeCred.unlock.successFixtures = [ unlockCloudSafeExpected: { "id": "prefsSafe-7", "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "user", "name": null, "email": null, diff --git a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js index bae93e802..37179bf84 100644 --- a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js +++ b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js @@ -446,7 +446,7 @@ fluid.defaults("gpii.tests.preferencesServer.preferencesService.addGpiiKey", { task: "{preferencesService}.addGpiiKey", args: [{ "type": "gpiiKey", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-1", "prefsSetId": "gpii-default", "revoked": false, @@ -454,7 +454,7 @@ fluid.defaults("gpii.tests.preferencesServer.preferencesService.addGpiiKey", { }], resolve: "jqUnit.assertLeftHand", resolveArgs: ["Newly created gpiiKey", { - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-1", "prefsSetId": "gpii-default", "revoked": false, @@ -594,7 +594,7 @@ fluid.defaults("gpii.tests.preferencesServer.preferencesService.cloudSafeUnlock" gpii.tests.preferencesServer.preferencesService.createUpdatePrefsSafeData = { newPrefsSafe: { "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "user", "name": "User 200", "preferences": { @@ -616,7 +616,7 @@ gpii.tests.preferencesServer.preferencesService.createUpdatePrefsSafeData = { updatedPrefsSafe7: { "id": "prefsSafe-7", "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "user", "name": "Prefs Seven", "email": null, diff --git a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js index bfd5c5269..b3f954e82 100644 --- a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js +++ b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js @@ -70,7 +70,7 @@ gpii.tests.preferencesServer.prefsSafes.get.successFixtures = [ expected: { "id": "prefsSafe-7", "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "user", "name": null, "email": null, @@ -149,7 +149,7 @@ gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.successFixtures = [ prefsSafe: { "id": "prefsSafe-7", "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "user", "name": null, "email": null, @@ -182,7 +182,7 @@ gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.successFixtures = [ { "id": "np_tiny", "type": "gpiiKey", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-7", "prefsSetId": "gpii-default", "revoked": false, @@ -409,7 +409,7 @@ gpii.tests.preferencesServer.prefsSafes.postSafe.successFixtures = [ url: "%prefsSafeId", postBody: { "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "user", "name": "Prefs Three Thousand", "email": null, @@ -431,7 +431,7 @@ gpii.tests.preferencesServer.prefsSafes.postSafe.successFixtures = [ }, expected: { "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "user", "name": "Prefs Three Thousand", "email": null, @@ -635,7 +635,7 @@ gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.successFixtures = [ { "id": "np_tiny", "type": "gpiiKey", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-7", "prefsSetId": "gpii-default", "revoked": false, @@ -699,7 +699,7 @@ gpii.tests.preferencesServer.prefsSafes.prefsSafeKeyCreate.successFixtures = [ }, expected: { "type": "gpiiKey", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-1", "prefsSetId": "gpii-lowlight", "revoked": false, From b3eccbafa313d6a79e92b96e088463e0a15d2db1 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Wed, 18 Dec 2019 20:12:03 -0800 Subject: [PATCH 62/72] GPII-2966 Minor updates to test data --- .../preferencesServer/test/cloudSafeCredTests.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js index 419a3506c..27dbab750 100644 --- a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js +++ b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js @@ -140,7 +140,6 @@ gpii.tests.preferencesServer.cloudSafeCred.put.successFixtures = [ password: "testPassword" }, unlockCloudSafeExpected: { - "id": "prefsSafe-1", "type": "prefsSafe", "schemaVersion": "0.2", "prefsSafeType": "user", @@ -156,7 +155,7 @@ gpii.tests.preferencesServer.cloudSafeCred.put.successFixtures = [ "control": { "onscreenKeyboard": true, "mouseEmulation": { - "-provisional-initDelay": 0.120, + "-provisional-initDelay": 120, "cursorSpeed": 0.850, "cursorAcceleration": 0.800, "-provisional-mouseEmulation/enabled": true @@ -191,7 +190,8 @@ gpii.tests.preferencesServer.cloudSafeCred.put.successFixtures = [ } }, "timestampCreated": "2017-12-14T19:55:11.640Z", - "timestampUpdated": null + "timestampUpdated": null, + "id": "prefsSafe-1" } } ]; From e4956ff9147b6c9afb514f40954f613a7faf2783 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Thu, 19 Dec 2019 19:44:19 -0800 Subject: [PATCH 63/72] GPII-2966 Moving existing work up to schemaVersion 0.3 before adding migration --- documentation/DataModel.md | 6 +++--- documentation/PreferencesServer.md | 20 +++++++++---------- .../test/DbDataStoreTestsUtils.js | 4 ++-- .../test/data/gpiiCloudSafeCred.json | 2 +- .../test/data/gpiiCloudSafeCred.json | 2 +- .../test/data/preferencesServiceUsers.json | 12 +++++------ .../test/preferencesServiceTests.js | 2 +- .../preferencesServer/test/prefsSafesTests.js | 12 +++++------ 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/documentation/DataModel.md b/documentation/DataModel.md index 5209da3cc..df2731489 100644 --- a/documentation/DataModel.md +++ b/documentation/DataModel.md @@ -25,7 +25,7 @@ An example document: { "_id": "prefsSafe-7", "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "user", "name": null, "email": null, @@ -61,7 +61,7 @@ An example document: { "_id": "np_tiny", "type": "gpiiKey", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-7", "prefsSetId": "gpii-default", "revoked": false, @@ -87,7 +87,7 @@ An example document: { "_id": "8f3085a7-b65b-4648-9a78-8ac7de766997", "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-7", "gpiiExpressUserId": "org.couch.db.user:prefs7user" } diff --git a/documentation/PreferencesServer.md b/documentation/PreferencesServer.md index 6fc089e4f..a491afd40 100644 --- a/documentation/PreferencesServer.md +++ b/documentation/PreferencesServer.md @@ -365,7 +365,7 @@ Example Success Payload: { "id": "prefsSafe-alice", "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "user", "name": "alice", "email": null, @@ -415,7 +415,7 @@ Example returned item: "prefsSafe": { "id": "prefsSafe-alice", "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "user", "name": "alice", "email": null, @@ -439,14 +439,14 @@ Example returned item: { "id": "8f3085a7-b65b-4648-9a78-8ac7de766997", "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-alice", "gpiiExpressUserId": "org.couch.db.user:alice" }, { "id": "57A68E84-03A9-4ADD-9365-11C75E4F1B0E", "type": "gpiiKey", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-alice", "prefsSetId": "gpii-default", "revoked": false, @@ -483,7 +483,7 @@ The POST payload should be a full preferences safe without an `id`: ```json { "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "user", "name": "Steve", "email": null, @@ -532,7 +532,7 @@ Example PUT body: { "id": "prefsSafe-alice", "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "user", "name": "alice", "email": null, @@ -625,14 +625,14 @@ An example payload for a particlar safe may be: { "id": "8f3085a7-b65b-4648-9a78-8ac7de766997", "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-alice", "gpiiExpressUserId": "org.couch.db.user:alice" }, { "id": "57A68E84-03A9-4ADD-9365-11C75E4F1B0E", "type": "gpiiKey", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-alice", "prefsSetId": "gpii-default", "revoked": false, @@ -672,7 +672,7 @@ Example successful return payload: { "id": "3B3D3003-9F5F-4B66-98C1-1380EC86DDB1", "type": "gpiiKey", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-alice", "prefsSetId": "gpii-lowlight", "revoked": false, @@ -719,7 +719,7 @@ Example successful return payload: { "_id": "8f3085a7-b65b-4648-9a78-8ac7de766997", "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-1", "gpiiExpressUserId": "org.couch.db.user:prefs1user" } diff --git a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js index f884e44cd..a4462451d 100644 --- a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js +++ b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js @@ -338,7 +338,7 @@ gpii.tests.dbDataStore.testData = { "rows": [ { "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-1", "gpiiExpressUserId": "org.couch.db.user:prefs1user", "id": "8f3085a7-b65b-4648-9a78-8ac7de766997" @@ -358,7 +358,7 @@ gpii.tests.dbDataStore.testData = { }, findSafeByExpressUserLookup_credential: { "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-1", "gpiiExpressUserId": "org.couch.db.user:prefs1user", "id": "8f3085a7-b65b-4648-9a78-8ac7de766997" diff --git a/gpii/node_modules/gpii-db-operation/test/data/gpiiCloudSafeCred.json b/gpii/node_modules/gpii-db-operation/test/data/gpiiCloudSafeCred.json index bed344b4c..ac59d3d22 100644 --- a/gpii/node_modules/gpii-db-operation/test/data/gpiiCloudSafeCred.json +++ b/gpii/node_modules/gpii-db-operation/test/data/gpiiCloudSafeCred.json @@ -15,7 +15,7 @@ }, { "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-1", "gpiiExpressUserId": "org.couch.db.user:prefs1user", "_id": "8f3085a7-b65b-4648-9a78-8ac7de766997" diff --git a/gpii/node_modules/preferencesServer/test/data/gpiiCloudSafeCred.json b/gpii/node_modules/preferencesServer/test/data/gpiiCloudSafeCred.json index f783b24a3..fff57ebc4 100644 --- a/gpii/node_modules/preferencesServer/test/data/gpiiCloudSafeCred.json +++ b/gpii/node_modules/preferencesServer/test/data/gpiiCloudSafeCred.json @@ -15,7 +15,7 @@ }, { "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-7", "gpiiExpressUserId": "org.couch.db.user:prefs7user", "_id": "8f3085a7-b65b-4648-9a78-8ac7de766997" diff --git a/gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json b/gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json index acebb88b9..b52fe19d0 100644 --- a/gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json +++ b/gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json @@ -2,7 +2,7 @@ { "_id": "alice_gpii_key", "type": "gpiiKey", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-1", "prefsSetId": "gpii-default", "revoked": false, @@ -12,7 +12,7 @@ }, { "_id": "bob_gpii_key", "type": "gpiiKey", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": null, "prefsSetId": null, "revoked": false, @@ -22,7 +22,7 @@ }, { "_id": "snapset1", "type": "gpiiKey", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-snapset1", "prefsSetId": "gpii-default", "revoked": false, @@ -32,7 +32,7 @@ }, { "_id": "prefsSafe-1", "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "user", "name": null, "email": null, @@ -56,7 +56,7 @@ }, { "_id": "prefsSafe-snapset1", "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "snapset", "name": null, "email": null, @@ -78,7 +78,7 @@ { "_id": "prefsSafe-7", "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "user", "name": null, "email": null, diff --git a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js index 37179bf84..1b1818d85 100644 --- a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js +++ b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js @@ -471,7 +471,7 @@ fluid.defaults("gpii.tests.preferencesServer.preferencesService.addGpiiKey", { task: "{preferencesService}.addGpiiKey", args: [{ "type": "gpiiKey", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-2020", "prefsSetId": "gpii-default", "revoked": false, diff --git a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js index b3f954e82..a3c6b1440 100644 --- a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js +++ b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js @@ -174,7 +174,7 @@ gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.successFixtures = [ keys: [ { "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-7", "gpiiExpressUserId": "org.couch.db.user:prefs7user", "id": "8f3085a7-b65b-4648-9a78-8ac7de766997" @@ -249,7 +249,7 @@ gpii.tests.preferencesServer.prefsSafes.putSafe.successFixtures = [ putBody: { "id": "prefsSafe-7", "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "user", "name": "Prefs Seven", "email": null, @@ -274,7 +274,7 @@ gpii.tests.preferencesServer.prefsSafes.putSafe.successFixtures = [ expected: { "id": "prefsSafe-7", "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "user", "name": "Prefs Seven", "email": null, @@ -308,7 +308,7 @@ gpii.tests.preferencesServer.prefsSafes.putSafe.failFixtures = [ putBody: { "id": "prefsSafe-4000", "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "user", "name": "Prefs Seven", "email": null, @@ -344,7 +344,7 @@ gpii.tests.preferencesServer.prefsSafes.putSafe.failFixtures = [ putBody: { "id": "prefsSafe-7", "type": "prefsSafe", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeType": "user", "name": "Prefs Seven", "email": null, @@ -627,7 +627,7 @@ gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.successFixtures = [ "offset": 9, rows: [{ "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.1", + "schemaVersion": "0.2", "prefsSafeId": "prefsSafe-7", "gpiiExpressUserId": "org.couch.db.user:prefs7user", "id": "8f3085a7-b65b-4648-9a78-8ac7de766997" From f4a1e68aa3f3c50b55ec6e3381fd6fa912ca9d37 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Fri, 27 Dec 2019 11:40:31 -0800 Subject: [PATCH 64/72] GPII-2966 Migrations - These are largely copy and paste from the GPII-4014 migrations. They could be refactored more, but given we will shortly be migrating from Couch to something I'm not sure if it's worth the time. --- .../migration/schema-0.3-GPII-2966/README.md | 46 +++++ .../createSimulatedGpiiKeys.js | 186 ++++++++++++++++++ .../schema-0.3-GPII-2966/migration-step1.js | 163 +++++++++++++++ .../schema-0.3-GPII-2966/migration-step2.js | 183 +++++++++++++++++ .../shared/migratedValues.js | 24 +++ .../migration/schema-0.3-GPII-2966/verify.js | 152 ++++++++++++++ 6 files changed, 754 insertions(+) create mode 100644 scripts/migration/schema-0.3-GPII-2966/README.md create mode 100644 scripts/migration/schema-0.3-GPII-2966/createSimulatedGpiiKeys.js create mode 100644 scripts/migration/schema-0.3-GPII-2966/migration-step1.js create mode 100644 scripts/migration/schema-0.3-GPII-2966/migration-step2.js create mode 100644 scripts/migration/schema-0.3-GPII-2966/shared/migratedValues.js create mode 100644 scripts/migration/schema-0.3-GPII-2966/verify.js diff --git a/scripts/migration/schema-0.3-GPII-2966/README.md b/scripts/migration/schema-0.3-GPII-2966/README.md new file mode 100644 index 000000000..7ac2b3e47 --- /dev/null +++ b/scripts/migration/schema-0.3-GPII-2966/README.md @@ -0,0 +1,46 @@ +# Data Migration and Verification for GPII-2966 Deployment + +This directory contains the data migration for GPII-2966. This migration is not required +for operation, but removes a now unused field. (for current and future use). That field is +the `password` field on `prefsSafe` document types. At the time of writing, this field +should most likely be `null` throughout the database given it was never exercised by any +code. + +## Scripts for testing + +1. createSimulatedGpiiKeys.js + + This script creates simulated GPII keys and their corresponding prefs safes in schema version 0.1 format. It + creates documents in batches of a given number. For example, for creating 1000 GPII keys in batches of 100, this + script will generate 100 new GPII keys and their corresponding prefs safes each time to send to CouchDB /_bulk_docs + to create. This is to avoid the potential memory overflow at creating a large number of GPII keys in one shot. An example to create 50K GPII keys in batches of 50: + ``` + node scripts/migration/schema-0.3-GPII-2966/createSimulatedGpiiKeys.js http://localhost:25984 50000 50 + ``` + +## Scripts for deployment + +1. migration-step1.js + + Run this script **before** deploying the new universal docker image from the universal root directory. Removes the + `password` field from preference safes.. An example: + ``` + node scripts/migration/schema-0.3-GPII-2966/migration-step1.js http://localhost:25984 + ``` + +2. migration-step2.js + + Run this script **after** deploying the new universal docker image from the universal root directory. + Updates the `schemaVersion` of all documents in the database to 0.3 and touches the `timestampUpdated` + value. + ``` + node scripts/migration/schema-0.3-GPII-2966/migration-step2.js http://localhost:25984 5000 + ``` + +3. verify.js + + Run this script **after** the data migration completes. It checks if all documents have been migrated. An example of verifying + in batches of 5000 documents in one batch: + ``` + node scripts/migration/schema-0.3-GPII-2966/verify.js http://localhost:25984 5000 + ``` diff --git a/scripts/migration/schema-0.3-GPII-2966/createSimulatedGpiiKeys.js b/scripts/migration/schema-0.3-GPII-2966/createSimulatedGpiiKeys.js new file mode 100644 index 000000000..4f02d879b --- /dev/null +++ b/scripts/migration/schema-0.3-GPII-2966/createSimulatedGpiiKeys.js @@ -0,0 +1,186 @@ +/*! +Copyright 2019 OCAD University + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +You may obtain a copy of the License at +https://github.com/GPII/universal/blob/master/LICENSE.txt +*/ + +// This script creates simulated GPII keys and their corresponding prefs safes in schema version 0.2 format. +// It creates new documents in batches of a given number. Note that creating number n of GPII keys will end up +// with creating n * 2 documents in the database since each key has a corresponding prefs safe document created. + +// Usage: node scripts/migration/schema-0.3-GPII-2966/createSimulatedGpiiKeys.js CouchDB-url numOfKeysToCreate maxDocsInBatchPerRequest +// @param {String} CouchDB-url - The url to the CouchDB where docoments should be created. +// @param {Number} numOfKeysToCreate - The number of GPII keys to be created. +// @param {Number} maxDocsInBatchPerRequest - [optional] Limit the number of documents to be created in a batch. +// Default to 100 if not provided. + +// A sample command that runs this script in the universal root directory: +// node scripts/migration/schema-0.3-GPII-2966/createSimulatedGpiiKeys.js http://localhost:25984 100000 300 + +"use strict"; + +var fluid = require("infusion"), + gpii = fluid.registerNamespace("gpii"), + url = require("url"), + uuid = uuid || require("node-uuid"); + +fluid.registerNamespace("gpii.migration.GPII2966"); + +require("./shared/migratedValues.js"); +require("../../shared/dbRequestUtils.js"); +require("../../../gpii/node_modules/gpii-db-operation/src/DbUtils.js"); + +// Handle command line +if (process.argv.length < 4) { + console.log("Usage: node createSimulatedGpiiKeys.js COUCHDB_URL numOfKeysToCreate [maxDocsInBatchPerRequest]"); + process.exit(1); +} + +gpii.migration.GPII2966.defaultMaxDocsInBatchPerRequest = 100; + +/** + * Create a set of options for this script. + * The options are based on the command line parameters and a set of database constants. + * @param {Array} processArgv - The command line arguments. + * @return {Object} - The options. + */ +gpii.migration.GPII2966.initOptions = function (processArgv) { + var options = {}; + options.couchDbUrl = processArgv[2] + "/gpii"; + options.numOfKeysToCreate = Number(processArgv[3]); + options.maxDocsInBatchPerRequest = Number(processArgv[4]) || gpii.migration.GPII2966.defaultMaxDocsInBatchPerRequest; + + // Set up database specific options + options.newDocs = []; + options.numOfCreatedKeys = 0; + options.parsedCouchDbUrl = url.parse(options.couchDbUrl); + options.postOptions = { + hostname: options.parsedCouchDbUrl.hostname, + port: options.parsedCouchDbUrl.port, + path: "/gpii/_bulk_docs", + auth: options.parsedCouchDbUrl.auth, + method: "POST", + headers: { + "Accept": "application/json", + "Content-Length": 0, // IMPORTANT: FILL IN PER REQUEST + "Content-Type": "application/json" + } + }; + console.log("COUCHDB_URL: '" + + options.parsedCouchDbUrl.protocol + "//" + + options.parsedCouchDbUrl.hostname + ":" + + options.parsedCouchDbUrl.port + + options.parsedCouchDbUrl.pathname + "'" + ); + return options; +}; + +/** + * Generate an array of new documents to create. + * @param {Number} numOfKeys - The number of new GPII keys to create + * @return {Array} - An array of GPII keys and corresponding prefs safe documents to create. + */ +gpii.migration.GPII2966.generateKeyData = function (numOfKeys) { + var newDocs = []; + for (var i = 0; i < numOfKeys; i++) { + var currentTime = new Date().toISOString(); + var gpiiKeyId = uuid.v4(); + var prefsSafeId = "prefsSafe-" + gpiiKeyId; + var prefs = { + "flat": { + "contexts": { + "gpii-default": { + "name": "Default preferences", + "preferences": { + "http://registry.gpii.net/common/language": "en-US" + } + } + } + } + }; + + var newGpiiKey = { + "_id": gpiiKeyId, + "type": "gpiiKey", + "schemaVersion": "0.2", + "prefsSafeId": prefsSafeId, + "prefsSetId": "gpii-default", + "revoked": false, + "revokedReason": null, + "timestampCreated": currentTime, + "timestampUpdated": null + }; + + var newPrefsSafe = { + "_id": prefsSafeId, + "type": "prefsSafe", + "schemaVersion": "0.2", + "prefsSafeType": "user", + "name": gpiiKeyId, + "password": null, + "email": null, + "preferences": prefs, + "timestampCreated": currentTime, + "timestampUpdated": null + }; + newDocs.push(newGpiiKey); + newDocs.push(newPrefsSafe); + }; + return newDocs; +}; + +/** + * Log how many GPII documents were updated. + * @param {String} responseString - Response from the database (ignored) + * @param {Object} options - Object containing the set of documents: + * @param {Number} options.numOfKeysToCreate - Total number of GPII keys to create. + * @param {Number} options.numOfCreatedKeys - Total number of GPII keys that have been created. + * @return {Promise} - The resolved value is options.numOfCreatedKeys, or 0 when all has been created. + */ +gpii.migration.GPII2966.logUpdateDB = function (responseString, options) { + var togo = fluid.promise(); + options.numOfCreatedKeys = options.numOfCreatedKeys + options.numToCreateInThisBatch; + console.log("Created " + options.numOfCreatedKeys + " of requested " + options.numOfKeysToCreate + " GPII keys."); + togo.resolve(options.numOfCreatedKeys < options.numOfKeysToCreate ? options.numOfCreatedKeys : 0); + return togo; +}; + +/** + * Configure one batch of creation. + * @param {Object} options - Object containing the set of documents: + * @param {Array} options.newDocs - The documents to create. + * @param {Number} options.numOfKeysToCreate - Total number of GPII keys to create. + * @param {Number} options.numOfCreatedKeys - Total number of GPII keys that have been created. This option will be + * written by a call to this function. + * @return {Promise} - A promise whose resolved value is the number of created documents, or 0 when all has been created. + */ +gpii.migration.GPII2966.createOneBatch = function (options) { + var numOfNeeded = options.numOfKeysToCreate - options.numOfCreatedKeys; + options.numToCreateInThisBatch = numOfNeeded > options.maxDocsInBatchPerRequest ? options.maxDocsInBatchPerRequest : numOfNeeded; + + options.newDocs = gpii.migration.GPII2966.generateKeyData(options.numToCreateInThisBatch); + + var details = { + dataToPost: options.newDocs, + responseDataHandler: gpii.migration.GPII2966.logUpdateDB + }; + return gpii.dbRequest.configureStep(details, options); +}; + +/** + * Create and execute the steps to create GPII keys. + */ +gpii.migration.GPII2966.createKeys = function () { + var options = gpii.migration.GPII2966.initOptions(process.argv); + var finalPromise = gpii.dbRequest.processRecursive(options, gpii.migration.GPII2966.createOneBatch); + + finalPromise.then(function () { + console.log("Done: " + options.numOfCreatedKeys + " GPII keys have been created."); + }, console.log); +}; + +gpii.migration.GPII2966.createKeys(); diff --git a/scripts/migration/schema-0.3-GPII-2966/migration-step1.js b/scripts/migration/schema-0.3-GPII-2966/migration-step1.js new file mode 100644 index 000000000..b2d4573ca --- /dev/null +++ b/scripts/migration/schema-0.3-GPII-2966/migration-step1.js @@ -0,0 +1,163 @@ +/*! +Copyright 2019 OCAD University + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +You may obtain a copy of the License at +https://github.com/GPII/universal/blob/master/LICENSE.txt +*/ + +// This script performs the first step of the data migration for GPII-2966 deployment. +// It removes the `password` field from all `prefsSafe` documents. + +// Usage: node scripts/migration/schema-0.3-GPII-2966/migration-step1.js CouchDB-url clientCredentialId-for-NOVA ... +// @param {String} CouchDB-url - The url to the CouchDB where docoments should be migrated. +// @param {Strings} clientCredentialIds-for-NOVA - The "_id" value of the NOVA client credential. There could be any +// number of client credential parameters from here onwards. + +// A sample command that runs this script in the universal root directory: +// node scripts/migration/schema-0.3-GPII-2966/migration-step1.js http://localhost:25984 + +"use strict"; + +var fluid = require("infusion"), + gpii = fluid.registerNamespace("gpii"), + url = require("url"); + +fluid.registerNamespace("gpii.migration.GPII2966"); + +require("./shared/migratedValues.js"); +require("../../shared/dbRequestUtils.js"); +require("../../../gpii/node_modules/gpii-db-operation/src/DbUtils.js"); + +/** + * Create a set of options for this script. + * The options are based on the command line parameters and a set of database constants. + * @param {Array} processArgv - The command line arguments. + * @return {Object} - The options. + */ +gpii.migration.GPII2966.initOptions = function (processArgv) { + var options = {}; + options.couchDbUrl = processArgv[2] + "/gpii"; + options.novaClientCredentials = process.argv.splice(3); + + // Set up database specific options + options.allDocsUrl = options.couchDbUrl + "/_all_docs?include_docs=true"; + options.clientCredentials = []; + options.parsedCouchDbUrl = url.parse(options.couchDbUrl); + options.postOptions = { + hostname: options.parsedCouchDbUrl.hostname, + port: options.parsedCouchDbUrl.port, + path: "/gpii/_bulk_docs", + auth: options.parsedCouchDbUrl.auth, + method: "POST", + headers: { + "Accept": "application/json", + "Content-Length": 0, // IMPORTANT: FILL IN PER REQUEST + "Content-Type": "application/json" + } + }; + console.log("COUCHDB_URL: '" + + options.parsedCouchDbUrl.protocol + "//" + + options.parsedCouchDbUrl.hostname + ":" + + options.parsedCouchDbUrl.port + + options.parsedCouchDbUrl.pathname + "'" + ); + return options; +}; + +/** + * Create the step that retrieves all documents from the database + * @param {Object} options - All docs URL and whether to filter: + * @param {Array} options.allDocsUrl - The url for retrieving all documents in the database. + * @return {Promise} - A promise that resolves retrieved documents. + */ +gpii.migration.GPII2966.retrieveAllDocs = function (options) { + var details = { + requestUrl: options.allDocsUrl, + requestErrMsg: "Error retrieving documents from the database: ", + responseDataHandler: gpii.migration.GPII2966.updateDocsData, + responseErrMsg: "Error retrieving documents from database: " + }; + + return gpii.dbRequest.configureStep(details, options); +}; + +/** + * Given all the documents from the database, update their data according to the new data model. + * @param {String} responseString - the response from the request to get all documents. + * @param {Object} options - Where to store the to-be-updated documents: + * @return {Array} - The updated documents in the new data structure with the new schema version. + */ +gpii.migration.GPII2966.updateDocsData = function (responseString, options) { + var allDocs = JSON.parse(responseString); + var updatedDocs = []; + options.totalNumOfDocs = allDocs.total_rows; + if (allDocs.rows) { + fluid.each(allDocs.rows, function (aRow) { + var aDoc = aRow.doc; + // To filter out the "_design/views" doc that doesn't have the "schemaVersion" field + if (aDoc.type === "prefsSafe") { + aDoc.schemaVersion = gpii.migration.GPII2966.newSchemaVersion; + aDoc.timestampUpdated = gpii.dbOperation.getCurrentTimestamp(); + if (aDoc.password !== undefined) { + delete aDoc.password; + } + console.log("Updating the prefsSafe ID: ", aDoc._id); + updatedDocs.push(aDoc); + } + }); + options.updatedDocs = updatedDocs; + } + return updatedDocs; +}; + +/** + * Log how many GPII documents were updated. + * @param {String} responseString - Response from the database (ignored) + * @param {Object} options - Object containing the set of documents: + * @param {Array} options.updatedDocs - The documents to update. + * @return {Number} - the number of documents updated. + */ +gpii.migration.GPII2966.logUpdateDB = function (responseString, options) { + console.log("Updated ", options.updatedDocs.length, " of ", options.totalNumOfDocs, " GPII documents."); + return options.updatedDocs.length; +}; + +/** + * Configure update, in batch, of the documents. + * @param {Object} options - The documents to be updated: + * @param {Array} options.updatedDocs - The documents to update. + * @return {Promise} - The promise that resolves the update. + */ +gpii.migration.GPII2966.updateDB = function (options) { + var details = { + dataToPost: options.updatedDocs, + responseDataHandler: gpii.migration.GPII2966.logUpdateDB + }; + return gpii.dbRequest.configureStep(details, options); +}; + +/** + * Create and execute the steps to migrate documents. + */ +gpii.migration.GPII2966.migrateStep1 = function () { + var options = gpii.migration.GPII2966.initOptions(process.argv); + var sequence = [ + gpii.migration.GPII2966.retrieveAllDocs, + gpii.migration.GPII2966.updateDB + ]; + fluid.promise.sequence(sequence, options).then( + function (/*result*/) { + console.log("Done."); + process.exit(0); + }, + function (error) { + console.log(error); + process.exit(1); + } + ); +}; + +gpii.migration.GPII2966.migrateStep1(); diff --git a/scripts/migration/schema-0.3-GPII-2966/migration-step2.js b/scripts/migration/schema-0.3-GPII-2966/migration-step2.js new file mode 100644 index 000000000..b587c69e5 --- /dev/null +++ b/scripts/migration/schema-0.3-GPII-2966/migration-step2.js @@ -0,0 +1,183 @@ +/*! +Copyright 2019 OCAD University + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +You may obtain a copy of the License at +https://github.com/GPII/universal/blob/master/LICENSE.txt +*/ + +// This script performs the second step of the data migration for GPII-2966 deployment. It includes: +// 1. Bump schemaVersion value from 0.2 to 0.3 for all documents that have schemaVersion field. +// Note that "_design/views" doc doesn't have this field. +// 2. if the document has "timestampUpdated" field, set it to the time that the migration runs. +// Note that this script migrates documents in batches. Each batch will migrate a limited number of documents +// to avoid hitting the out-of-memory issue when migrating a large number of documents. + +// Usage: node scripts/migration/schema-0.3-GPII-2966/migration-step2.js CouchDB-url [maxDocsInBatchPerRequest] +// @param {String} CouchDB-url - The url to the CouchDB where docoments should be migrated. +// @param {Number} maxDocsInBatchPerRequest - [optional] Limit the number of documents to be migrated in a batch. +// Default to 100 if not provided. + +// A sample command that runs this script in the universal root directory: +// node scripts/migration/schema-0.3-GPII-2966/migration-step2.js http://localhost:25984 10 + +"use strict"; + +var fluid = require("infusion"), + gpii = fluid.registerNamespace("gpii"), + url = require("url"); + +fluid.registerNamespace("gpii.migration.GPII2966"); + +require("./shared/migratedValues.js"); +require("../../shared/dbRequestUtils.js"); +require("../../../gpii/node_modules/gpii-db-operation/src/DbUtils.js"); + +gpii.migration.GPII2966.defaultMaxDocsInBatchPerRequest = 100; + +/** + * Create a set of options for this script. + * The options are based on the command line parameters and a set of database constants. + * @param {Array} processArgv - The command line arguments. + * @return {Object} - The options. + */ +gpii.migration.GPII2966.initOptions = function (processArgv) { + var options = {}; + options.couchDbUrl = processArgv[2] + "/gpii"; + options.maxDocsInBatchPerRequest = Number(processArgv[3]) || gpii.migration.GPII2966.defaultMaxDocsInBatchPerRequest; + options.numOfUpdated = 0; + + // Set up database specific options + options.allDocsUrl = options.couchDbUrl + "/_design/views/_view/findDocsBySchemaVersion?key=%22" + gpii.migration.GPII2966.oldSchemaVersion + "%22&limit=" + options.maxDocsInBatchPerRequest; + options.allDocs = []; + options.parsedCouchDbUrl = url.parse(options.couchDbUrl); + options.postOptions = { + hostname: options.parsedCouchDbUrl.hostname, + port: options.parsedCouchDbUrl.port, + path: "/gpii/_bulk_docs", + auth: options.parsedCouchDbUrl.auth, + method: "POST", + headers: { + "Accept": "application/json", + "Content-Length": 0, // IMPORTANT: FILL IN PER REQUEST + "Content-Type": "application/json" + } + }; + console.log("COUCHDB_URL: '" + + options.parsedCouchDbUrl.protocol + "//" + + options.parsedCouchDbUrl.hostname + ":" + + options.parsedCouchDbUrl.port + + options.parsedCouchDbUrl.pathname + "'" + ); + return options; +}; + +/** + * Create the step that retrieves all documents from the database + * @param {Object} options - All docs URL and whether to filter: + * @param {String} options.allDocsUrl - The url for retrieving all documents in the database. + * @return {Promise} - A promise that resolves retrieved documents. + */ +gpii.migration.GPII2966.retrieveAllDocs = function (options) { + var details = { + requestUrl: options.allDocsUrl, + requestErrMsg: "Error retrieving documents from the database: ", + responseDataHandler: gpii.migration.GPII2966.updateDocsData, + responseErrMsg: "Error retrieving documents from database: " + }; + return gpii.dbRequest.configureStep(details, options); +}; + +/** + * Given all the documents from the database, update their data according to the new data model. + * @param {String} responseString - the response from the request to get all documents. + * @param {Object} options - Where to store the to-be-updated documents: + * @param {Array} options.allDocs - Accumulated documents. + * @return {Promise} - The resolved value contains an array of documents to be migrated, or 0 + * when no more document to migrate. + */ +gpii.migration.GPII2966.updateDocsData = function (responseString, options) { + var allDocs = JSON.parse(responseString); + var updatedDocs = []; + var togo = fluid.promise(); + + options.totalNumOfDocs = allDocs.total_rows; + + if (allDocs.rows.length === 0) { + options.updatedDocs = 0; + } else { + fluid.each(allDocs.rows, function (aRow) { + var aDoc = aRow.value; + // To filter out the "_design/views" doc that doesn't have the "schemaVersion" field + if (aDoc.schemaVersion) { + aDoc.schemaVersion = gpii.migration.GPII2966.newSchemaVersion; + if (aDoc.timestampUpdated === null) { + aDoc.timestampUpdated = gpii.dbOperation.getCurrentTimestamp(); + } + updatedDocs.push(aDoc); + } + }); + options.updatedDocs = updatedDocs; + } + togo.resolve(options.updatedDocs); + + return togo; +}; + +/** + * Log how many GPII documents were updated. + * @param {String} responseString - Response from the database (ignored) + * @param {Object} options - Object containing the set of documents: + * @param {Array} options.updatedDocs - The documents to update. + * @param {Number} options.numOfUpdated - The total number of migrated documents. + * @return {Number} - the number of documents updated. + */ +gpii.migration.GPII2966.logUpdateDB = function (responseString, options) { + options.numOfUpdated = options.numOfUpdated + options.updatedDocs.length; + console.log("Updated ", options.numOfUpdated, " of ", options.totalNumOfDocs, " GPII documents."); + return options.updatedDocs.length; +}; + +/** + * Configure update, in batch, of the documents. + * @param {Object} options - The documents to be updated: + * @param {Array} options.updatedDocs - The documents to update. + * @return {Promise} - A promise whose resolved value is the number of migrated documents, + * or 0 when all has been migrated. + */ +gpii.migration.GPII2966.updateDB = function (options) { + var togo = fluid.promise(); + if (options.updatedDocs === 0) { + togo.resolve(0); + } else { + var details = { + dataToPost: options.updatedDocs, + responseDataHandler: gpii.migration.GPII2966.logUpdateDB + }; + togo = gpii.dbRequest.configureStep(details, options); + } + return togo; +}; + +/** + * Create and execute the steps to migrate documents. + */ +gpii.migration.GPII2966.migrateStep2 = function () { + var options = gpii.migration.GPII2966.initOptions(process.argv); + var actionFunc = function (options) { + return fluid.promise.sequence([ + gpii.migration.GPII2966.retrieveAllDocs, + gpii.migration.GPII2966.updateDB + ], options); + }; + + var finalPromise = gpii.dbRequest.processRecursive(options, actionFunc); + + finalPromise.then(function () { + console.log("Done: Migrated " + options.numOfUpdated + " documents in total."); + }, console.log); +}; + +gpii.migration.GPII2966.migrateStep2(); diff --git a/scripts/migration/schema-0.3-GPII-2966/shared/migratedValues.js b/scripts/migration/schema-0.3-GPII-2966/shared/migratedValues.js new file mode 100644 index 000000000..b8cbb8790 --- /dev/null +++ b/scripts/migration/schema-0.3-GPII-2966/shared/migratedValues.js @@ -0,0 +1,24 @@ +/*! +Copyright 2019 Raising the Floor - US + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +You may obtain a copy of the License at +https://github.com/GPII/universal/blob/master/LICENSE.txt +*/ + +// This shared script defines migrated values for the GPII-4014 deployment. + +"use strict"; + +var fluid = require("infusion"), + gpii = fluid.registerNamespace("gpii"); + +fluid.registerNamespace("gpii.migration.GPII2966"); + +// Migrated values +gpii.migration.GPII2966.oldSchemaVersion = "0.2"; +gpii.migration.GPII2966.newSchemaVersion = "0.3"; + +gpii.migration.GPII2966.passwordFieldName = "password"; diff --git a/scripts/migration/schema-0.3-GPII-2966/verify.js b/scripts/migration/schema-0.3-GPII-2966/verify.js new file mode 100644 index 000000000..d78a5d4da --- /dev/null +++ b/scripts/migration/schema-0.3-GPII-2966/verify.js @@ -0,0 +1,152 @@ +/*! +Copyright 2019 OCAD University + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +You may obtain a copy of the License at +https://github.com/GPII/universal/blob/master/LICENSE.txt +*/ + +// This script verifies updated CouchDB documents after the GPII-2966 deployment. It includes: +// 1. Password field has been removed from `prefsSafe` documents. +// 2. All "schemaVersion" in documents have been set to 0.3. Note that "_design/views" doc doesn't have this field. +// 3. All "timestampUpdated" have been set. + +// Usage: node scripts/migration/schema-0.3-GPII-2966/verify.js CouchDB-url maxDocsInBatchPerRequest clientCredentialId-for-NOVA ... +// @param {String} CouchDB-url - The url to the CouchDB where docoments should be verified. +// @param {Number} maxDocsInBatchPerRequest - Limit the number of documents to be verified in a batch. + +// A sample command that runs this script in the universal root directory: +// node scripts/migration/schema-0.3-GPII-2966/verify.js http://localhost:25984 100 + +"use strict"; + +var fluid = require("infusion"), + gpii = fluid.registerNamespace("gpii"), + url = require("url"); + +fluid.registerNamespace("gpii.migration.GPII2966"); + +require("./shared/migratedValues.js"); +require("../../shared/dbRequestUtils.js"); +require("../../../gpii/node_modules/gpii-db-operation/src/DbUtils.js"); + +/** + * Create a set of options for this script. + * The options are based on the command line parameters and a set of database constants. + * @param {Array} processArgv - The command line arguments. + * @return {Object} - The options. + */ +gpii.migration.GPII2966.initOptions = function (processArgv) { + var options = {}; + options.couchDbUrl = processArgv[2] + "/gpii"; + options.maxDocsInBatchPerRequest = Number(processArgv[3]); + options.numOfVerified = 0; + options.numOfErrorDocs = 0; + + // Set up database specific options + options.allDocsUrl = options.couchDbUrl + "/_all_docs?include_docs=true&descending=true&limit=" + options.maxDocsInBatchPerRequest; + options.allDocs = []; + options.parsedCouchDbUrl = url.parse(options.couchDbUrl); + options.postOptions = { + hostname: options.parsedCouchDbUrl.hostname, + port: options.parsedCouchDbUrl.port, + path: "/gpii/_bulk_docs", + auth: options.parsedCouchDbUrl.auth, + method: "POST", + headers: { + "Accept": "application/json", + "Content-Length": 0, // IMPORTANT: FILL IN PER REQUEST + "Content-Type": "application/json" + } + }; + console.log("COUCHDB_URL: '" + + options.parsedCouchDbUrl.protocol + "//" + + options.parsedCouchDbUrl.hostname + ":" + + options.parsedCouchDbUrl.port + + options.parsedCouchDbUrl.pathname + "'" + ); + return options; +}; + +/** + * Create the step that retrieves all documents from the database + * @param {Object} options - All docs URL and whether to filter: + * @param {String} options.allDocsUrl - The url for retrieving all documents in the database. + * @return {Promise} - A promise whose resolved value is the verification result. + */ +gpii.migration.GPII2966.verifyDocsInBatch = function (options) { + var details = { + requestUrl: options.allDocsUrl, + requestErrMsg: "Error retrieving documents from the database: ", + responseDataHandler: gpii.migration.GPII2966.verifyDocsData, + responseErrMsg: "Error verifying documents from database: " + }; + return gpii.dbRequest.configureStep(details, options); +}; + +/** + * Given all the documents from the database, update their data according to the new data model. + * @param {String} responseString - the response from the request to get all documents. + * @param {Object} options - Where to store the to-be-updated documents: + * @param {Number} options.numOfVerified - The number of verified documents. + * @param {Number} options.numOfErrorDocs - The number of verified documents that have verification errors. + * @return {Promise} - A promise whose resolved value is the number of verified documents, or 0 when all has been verified. + */ +gpii.migration.GPII2966.verifyDocsData = function (responseString, options) { + var allDocs = JSON.parse(responseString); + options.totalNumOfDocs = allDocs.total_rows; + var togo = fluid.promise(); + + if (allDocs.rows.length === 0) { + togo.resolve(0); + } else { + fluid.each(allDocs.rows, function (aRow) { + var hasError = false; + var aDoc = aRow.doc; + // To filter out the "_design/views" doc that doesn't have the "schemaVersion" field + if (aDoc.schemaVersion) { + if (aDoc.schemaVersion !== gpii.migration.GPII2966.newSchemaVersion) { + console.log("Error with the document _id \"" + aDoc._id + "\": schema version is ", aDoc.schemaVersion, ", not ", gpii.migration.GPII2966.newSchemaVersion); + hasError = true; + } + if (aDoc.timestampUpdated === null) { + console.log("Error with the document _id \"" + aDoc._id + "\": the value of timestampUpdated is empty"); + hasError = true; + } + if (aDoc.type === "prefsSafe" && aDoc.password !== undefined) { + console.log("Error with the document _id \"" + aDoc._id + "\": password field not removed from prefsSafe."); + hasError = true; + } + } + if (hasError) { + options.numOfErrorDocs++; + } + }); + options.numOfVerified = options.numOfVerified + allDocs.rows.length; + console.log("Verified " + options.numOfVerified + " of " + options.totalNumOfDocs + " documents."); + options.allDocsUrl = options.couchDbUrl + "/_all_docs?include_docs=true&descending=true&skip=" + options.numOfVerified + "&limit=" + options.maxDocsInBatchPerRequest; + togo.resolve(allDocs.rows.length); + } + return togo; +}; + +/** + * Create and execute the steps to verify documents. + */ +gpii.migration.GPII2966.verify = function () { + var options = gpii.migration.GPII2966.initOptions(process.argv); + var finalPromise = gpii.dbRequest.processRecursive(options, gpii.migration.GPII2966.verifyDocsInBatch); + + finalPromise.then(function () { + if (options.numOfErrorDocs > 0) { + console.log("Fail: " + options.numOfErrorDocs + " documents have errors."); + } else { + console.log("All passed."); + } + console.log("Done: Verified " + options.totalNumOfDocs + " documents in total."); + }, console.log); +}; + +gpii.migration.GPII2966.verify(); From 1ee531f254fc727f67cc8387cb1ff5b8984c62d4 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Fri, 27 Dec 2019 12:02:10 -0800 Subject: [PATCH 65/72] GPII-2966 Bumping schemaVersion from 0.2 to 0.3 --- documentation/AuthorizationService.md | 4 +-- documentation/DataModel.md | 6 ++-- documentation/PreferencesServer.md | 20 ++++++------- .../test/DbDataStoreTestsUtils.js | 30 +++++++++---------- .../test/data/clientCredentials.json | 4 +-- .../gpiiAppInstallationAuthorizations.json | 6 ++-- .../test/data/gpiiAppInstallationClients.json | 4 +-- .../test/data/gpiiCloudSafeCred.json | 2 +- .../gpii-db-operation/test/data/gpiiKeys.json | 4 +-- .../test/data/prefsSafes.json | 2 +- .../data/authorizationServiceTests-data.json | 12 ++++---- .../test/cloudSafeCredTests.js | 4 +-- .../test/data/gpiiCloudSafeCred.json | 2 +- .../data/gpiiKeys-preferenceServiceTests.json | 6 ++-- .../preferencesServer/test/data/gpiiKeys.json | 20 ++++++------- .../test/data/preferencesServiceUsers.json | 12 ++++---- .../prefsSafes-preferencesServiceTests.json | 4 +-- .../test/data/prefsSafes.json | 16 +++++----- .../test/preferencesServiceTests.js | 10 +++---- .../preferencesServer/test/prefsSafesTests.js | 26 ++++++++-------- scripts/generateCredentials.js | 8 ++--- scripts/shared/prefsSetsDbUtils.js | 4 +-- testData/dbData/clientCredentials.json | 2 +- .../dbData/gpiiAppInstallationClients.json | 2 +- tests/data/dbData/clientCredentials.json | 10 +++---- .../dbData/gpiiAppInstallationClients.json | 10 +++---- tests/data/dbData/gpiiKeys.json | 2 +- 27 files changed, 116 insertions(+), 116 deletions(-) diff --git a/documentation/AuthorizationService.md b/documentation/AuthorizationService.md index 4709486c5..112f0fc29 100644 --- a/documentation/AuthorizationService.md +++ b/documentation/AuthorizationService.md @@ -21,7 +21,7 @@ Grant](https://wiki.gpii.net/w/GPII_OAuth_2_Guide#Resource_Owner_GPII_Key_Grant) "accessToken": "gpii-app-installation-accessToken-1", "clientCredential": { "type": "clientCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-1", "oauth2ClientId": "net.gpii.ajc.bakersfield", "oauth2ClientSecret": "client_secret_ajc_bakersfield", @@ -37,7 +37,7 @@ Grant](https://wiki.gpii.net/w/GPII_OAuth_2_Guide#Resource_Owner_GPII_Key_Grant) }, "authorization": { "type": "gpiiAppInstallationAuthorization", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-1", "gpiiKey": "chrome_high_contrast", "accessToken": "gpii-app-installation-accessToken-1", diff --git a/documentation/DataModel.md b/documentation/DataModel.md index df2731489..3ed8e0228 100644 --- a/documentation/DataModel.md +++ b/documentation/DataModel.md @@ -25,7 +25,7 @@ An example document: { "_id": "prefsSafe-7", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": null, "email": null, @@ -61,7 +61,7 @@ An example document: { "_id": "np_tiny", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-7", "prefsSetId": "gpii-default", "revoked": false, @@ -87,7 +87,7 @@ An example document: { "_id": "8f3085a7-b65b-4648-9a78-8ac7de766997", "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-7", "gpiiExpressUserId": "org.couch.db.user:prefs7user" } diff --git a/documentation/PreferencesServer.md b/documentation/PreferencesServer.md index a491afd40..a36491a6e 100644 --- a/documentation/PreferencesServer.md +++ b/documentation/PreferencesServer.md @@ -365,7 +365,7 @@ Example Success Payload: { "id": "prefsSafe-alice", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": "alice", "email": null, @@ -415,7 +415,7 @@ Example returned item: "prefsSafe": { "id": "prefsSafe-alice", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": "alice", "email": null, @@ -439,14 +439,14 @@ Example returned item: { "id": "8f3085a7-b65b-4648-9a78-8ac7de766997", "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-alice", "gpiiExpressUserId": "org.couch.db.user:alice" }, { "id": "57A68E84-03A9-4ADD-9365-11C75E4F1B0E", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-alice", "prefsSetId": "gpii-default", "revoked": false, @@ -483,7 +483,7 @@ The POST payload should be a full preferences safe without an `id`: ```json { "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": "Steve", "email": null, @@ -532,7 +532,7 @@ Example PUT body: { "id": "prefsSafe-alice", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": "alice", "email": null, @@ -625,14 +625,14 @@ An example payload for a particlar safe may be: { "id": "8f3085a7-b65b-4648-9a78-8ac7de766997", "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-alice", "gpiiExpressUserId": "org.couch.db.user:alice" }, { "id": "57A68E84-03A9-4ADD-9365-11C75E4F1B0E", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-alice", "prefsSetId": "gpii-default", "revoked": false, @@ -672,7 +672,7 @@ Example successful return payload: { "id": "3B3D3003-9F5F-4B66-98C1-1380EC86DDB1", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-alice", "prefsSetId": "gpii-lowlight", "revoked": false, @@ -719,7 +719,7 @@ Example successful return payload: { "_id": "8f3085a7-b65b-4648-9a78-8ac7de766997", "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-1", "gpiiExpressUserId": "org.couch.db.user:prefs1user" } diff --git a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js index a4462451d..ba019ad0c 100644 --- a/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js +++ b/gpii/node_modules/gpii-db-operation/test/DbDataStoreTestsUtils.js @@ -135,7 +135,7 @@ gpii.tests.dbDataStore.testData = { gpiiKeyChromehcDefault: { "id": "chrome_high_contrast", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-1", "prefsSetId": "gpii-default", "revoked": false, @@ -146,7 +146,7 @@ gpii.tests.dbDataStore.testData = { client1: { "id": "gpiiAppInstallationClient-1", "type": "gpiiAppInstallationClient", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "name": "AJC-Bakersfield", "computerType": "public", "timestampCreated": "2017-11-21T18:11:22.101Z", @@ -155,7 +155,7 @@ gpii.tests.dbDataStore.testData = { clientCredential1: { "id": "clientCredential-1", "type": "clientCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-1", "oauth2ClientId": "net.gpii.ajc.bakersfield", "oauth2ClientSecret": "client_secret_ajc_bakersfield", @@ -169,7 +169,7 @@ gpii.tests.dbDataStore.testData = { "gpiiKeyDetails": { "id": "chrome_high_contrast", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-1", "prefsSetId": "gpii-default", "revoked": false, @@ -180,7 +180,7 @@ gpii.tests.dbDataStore.testData = { "prefsSafe": { "id": "prefsSafe-1", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": null, "email": null, @@ -213,7 +213,7 @@ gpii.tests.dbDataStore.testData = { "gpiiKeyDetails": { "id": "chrome_high_contrast_dark", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": null, "prefsSetId": null, "revoked": false, @@ -227,7 +227,7 @@ gpii.tests.dbDataStore.testData = { "oauth2ClientId": "net.gpii.ajc.bakersfield", "client": { "type": "gpiiAppInstallationClient", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "name": "AJC-Bakersfield", "computerType": "public", "timestampCreated": "2017-11-21T18:11:22.101Z", @@ -236,7 +236,7 @@ gpii.tests.dbDataStore.testData = { }, "clientCredential": { "type": "clientCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-1", "oauth2ClientId": "net.gpii.ajc.bakersfield", "oauth2ClientSecret": "client_secret_ajc_bakersfield", @@ -258,7 +258,7 @@ gpii.tests.dbDataStore.testData = { }, gpiiKeyToUpdate: { "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-1", "prefsSetId": "updated_name", "revoked": false, @@ -276,7 +276,7 @@ gpii.tests.dbDataStore.testData = { }, prefsSafeToUpdate: { "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "snapset", "name": "updated_name", "email": "updated_email", @@ -296,7 +296,7 @@ gpii.tests.dbDataStore.testData = { "accessToken": "gpii-app-installation-accessToken-1", "clientCredential": { "type": "clientCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-1", "oauth2ClientId": "net.gpii.ajc.bakersfield", "oauth2ClientSecret": "client_secret_ajc_bakersfield", @@ -308,7 +308,7 @@ gpii.tests.dbDataStore.testData = { }, "authorization": { "type": "gpiiAppInstallationAuthorization", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-1", "gpiiKey": "chrome_high_contrast", "clientCredentialId": "clientCredential-1", @@ -338,14 +338,14 @@ gpii.tests.dbDataStore.testData = { "rows": [ { "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-1", "gpiiExpressUserId": "org.couch.db.user:prefs1user", "id": "8f3085a7-b65b-4648-9a78-8ac7de766997" }, { "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-1", "prefsSetId": "gpii-default", "revoked": false, @@ -358,7 +358,7 @@ gpii.tests.dbDataStore.testData = { }, findSafeByExpressUserLookup_credential: { "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-1", "gpiiExpressUserId": "org.couch.db.user:prefs1user", "id": "8f3085a7-b65b-4648-9a78-8ac7de766997" diff --git a/gpii/node_modules/gpii-db-operation/test/data/clientCredentials.json b/gpii/node_modules/gpii-db-operation/test/data/clientCredentials.json index 312503480..642176f6d 100644 --- a/gpii/node_modules/gpii-db-operation/test/data/clientCredentials.json +++ b/gpii/node_modules/gpii-db-operation/test/data/clientCredentials.json @@ -2,7 +2,7 @@ { "_id": "clientCredential-1", "type": "clientCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-1", "oauth2ClientId": "net.gpii.ajc.bakersfield", "oauth2ClientSecret": "client_secret_ajc_bakersfield", @@ -14,7 +14,7 @@ { "_id": "clientCredential-2", "type": "clientCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-2", "oauth2ClientId": "net.gpii.ajc.richmond", "oauth2ClientSecret": "client_secret_ajc_richmond", diff --git a/gpii/node_modules/gpii-db-operation/test/data/gpiiAppInstallationAuthorizations.json b/gpii/node_modules/gpii-db-operation/test/data/gpiiAppInstallationAuthorizations.json index 2a2453459..b9ce8228e 100644 --- a/gpii/node_modules/gpii-db-operation/test/data/gpiiAppInstallationAuthorizations.json +++ b/gpii/node_modules/gpii-db-operation/test/data/gpiiAppInstallationAuthorizations.json @@ -2,7 +2,7 @@ { "_id": "gpiiAppInstallationAuthorization-1", "type": "gpiiAppInstallationAuthorization", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-1", "gpiiKey": "chrome_high_contrast", "clientCredentialId": "clientCredential-1", @@ -16,7 +16,7 @@ { "_id": "gpiiAppInstallationAuthorization-2", "type": "gpiiAppInstallationAuthorization", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-2", "gpiiKey": "chrome_high_contrast", "clientCredentialId": "clientCredential-2", @@ -30,7 +30,7 @@ { "_id": "gpiiAppInstallationAuthorization-3", "type": "gpiiAppInstallationAuthorization", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-2", "gpiiKey": "chrome_high_contrast", "clientCredentialId": "clientCredential-2", diff --git a/gpii/node_modules/gpii-db-operation/test/data/gpiiAppInstallationClients.json b/gpii/node_modules/gpii-db-operation/test/data/gpiiAppInstallationClients.json index adf2efc56..18024d6c4 100644 --- a/gpii/node_modules/gpii-db-operation/test/data/gpiiAppInstallationClients.json +++ b/gpii/node_modules/gpii-db-operation/test/data/gpiiAppInstallationClients.json @@ -2,7 +2,7 @@ { "_id": "gpiiAppInstallationClient-1", "type": "gpiiAppInstallationClient", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "name": "AJC-Bakersfield", "computerType": "public", "timestampCreated": "2017-11-21T18:11:22.101Z", @@ -11,7 +11,7 @@ { "_id": "gpiiAppInstallationClient-2", "type": "gpiiAppInstallationClient", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "name": "AJC-Richmond", "computerType": "public", "timestampCreated": "2017-11-21T18:11:22.101Z", diff --git a/gpii/node_modules/gpii-db-operation/test/data/gpiiCloudSafeCred.json b/gpii/node_modules/gpii-db-operation/test/data/gpiiCloudSafeCred.json index ac59d3d22..826148920 100644 --- a/gpii/node_modules/gpii-db-operation/test/data/gpiiCloudSafeCred.json +++ b/gpii/node_modules/gpii-db-operation/test/data/gpiiCloudSafeCred.json @@ -15,7 +15,7 @@ }, { "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-1", "gpiiExpressUserId": "org.couch.db.user:prefs1user", "_id": "8f3085a7-b65b-4648-9a78-8ac7de766997" diff --git a/gpii/node_modules/gpii-db-operation/test/data/gpiiKeys.json b/gpii/node_modules/gpii-db-operation/test/data/gpiiKeys.json index 3b318f739..50cbba643 100644 --- a/gpii/node_modules/gpii-db-operation/test/data/gpiiKeys.json +++ b/gpii/node_modules/gpii-db-operation/test/data/gpiiKeys.json @@ -2,7 +2,7 @@ { "_id": "chrome_high_contrast", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-1", "prefsSetId": "gpii-default", "revoked": false, @@ -13,7 +13,7 @@ { "_id": "chrome_high_contrast_dark", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": null, "prefsSetId": null, "revoked": false, diff --git a/gpii/node_modules/gpii-db-operation/test/data/prefsSafes.json b/gpii/node_modules/gpii-db-operation/test/data/prefsSafes.json index 9b8609e35..e82a56b67 100644 --- a/gpii/node_modules/gpii-db-operation/test/data/prefsSafes.json +++ b/gpii/node_modules/gpii-db-operation/test/data/prefsSafes.json @@ -2,7 +2,7 @@ { "_id": "prefsSafe-1", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": null, "email": null, diff --git a/gpii/node_modules/gpii-oauth2/gpii-oauth2-authz-server/test/data/authorizationServiceTests-data.json b/gpii/node_modules/gpii-oauth2/gpii-oauth2-authz-server/test/data/authorizationServiceTests-data.json index 476d31065..202d605b1 100644 --- a/gpii/node_modules/gpii-oauth2/gpii-oauth2-authz-server/test/data/authorizationServiceTests-data.json +++ b/gpii/node_modules/gpii-oauth2/gpii-oauth2-authz-server/test/data/authorizationServiceTests-data.json @@ -2,7 +2,7 @@ { "_id": "alice_gpii_key", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-1", "prefsSetId": "gpii-default", "revoked": false, @@ -13,7 +13,7 @@ { "_id": "gpiiAppInstallationClient-1", "type": "gpiiAppInstallationClient", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "name": "AJC1", "computerType": "public", "timestampCreated": "2017-11-21T18:11:22.101Z", @@ -22,7 +22,7 @@ { "_id": "clientCredential-1", "type": "clientCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-1", "oauth2ClientId": "client_id_AJC1", "oauth2ClientSecret": "client_secret_AJC1", @@ -34,7 +34,7 @@ { "_id": "gpiiAppInstallationClient-2", "type": "unknownClient", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "name": "test", "computerType": "public", "timestampCreated": "2017-11-21T18:11:22.101Z", @@ -43,7 +43,7 @@ { "_id": "clientCredential-2", "type": "clientCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-2", "oauth2ClientId": "client_id_test", "oauth2ClientSecret": "client_secret_test", @@ -55,7 +55,7 @@ { "_id": "clientCredential-3", "type": "unknownClientCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-2", "oauth2ClientId": "client_id_test-3", "oauth2ClientSecret": "client_secret_test-3", diff --git a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js index 27dbab750..8daca71f7 100644 --- a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js +++ b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js @@ -141,7 +141,7 @@ gpii.tests.preferencesServer.cloudSafeCred.put.successFixtures = [ }, unlockCloudSafeExpected: { "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": null, "email": null, @@ -355,7 +355,7 @@ gpii.tests.preferencesServer.cloudSafeCred.unlock.successFixtures = [ unlockCloudSafeExpected: { "id": "prefsSafe-7", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": null, "email": null, diff --git a/gpii/node_modules/preferencesServer/test/data/gpiiCloudSafeCred.json b/gpii/node_modules/preferencesServer/test/data/gpiiCloudSafeCred.json index fff57ebc4..a69d680fa 100644 --- a/gpii/node_modules/preferencesServer/test/data/gpiiCloudSafeCred.json +++ b/gpii/node_modules/preferencesServer/test/data/gpiiCloudSafeCred.json @@ -15,7 +15,7 @@ }, { "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-7", "gpiiExpressUserId": "org.couch.db.user:prefs7user", "_id": "8f3085a7-b65b-4648-9a78-8ac7de766997" diff --git a/gpii/node_modules/preferencesServer/test/data/gpiiKeys-preferenceServiceTests.json b/gpii/node_modules/preferencesServer/test/data/gpiiKeys-preferenceServiceTests.json index 0160df644..33bbb46e6 100644 --- a/gpii/node_modules/preferencesServer/test/data/gpiiKeys-preferenceServiceTests.json +++ b/gpii/node_modules/preferencesServer/test/data/gpiiKeys-preferenceServiceTests.json @@ -2,7 +2,7 @@ { "_id": "alice_gpii_key", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-1", "prefsSetId": "gpii-default", "revoked": false, @@ -13,7 +13,7 @@ { "_id": "bob_gpii_key", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": null, "prefsSetId": null, "revoked": false, @@ -24,7 +24,7 @@ { "_id": "snapset1", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-snapset1", "prefsSetId": "gpii-default", "revoked": false, diff --git a/gpii/node_modules/preferencesServer/test/data/gpiiKeys.json b/gpii/node_modules/preferencesServer/test/data/gpiiKeys.json index 99182ad45..66efcc87f 100644 --- a/gpii/node_modules/preferencesServer/test/data/gpiiKeys.json +++ b/gpii/node_modules/preferencesServer/test/data/gpiiKeys.json @@ -2,7 +2,7 @@ { "_id": "alice_gpii_key", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-1", "prefsSetId": "gpii-default", "revoked": false, @@ -13,7 +13,7 @@ { "_id": "bob_gpii_key", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": null, "prefsSetId": null, "revoked": false, @@ -24,7 +24,7 @@ { "_id": "np_ISO24751Only_singleContext", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-1", "prefsSetId": "gpii-default", "revoked": false, @@ -35,7 +35,7 @@ { "_id": "np_ISO24751Only_singleContext_wildcardMetadata", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-2", "prefsSetId": "gpii-default", "revoked": false, @@ -46,7 +46,7 @@ { "_id": "np_flatOnly_multiContext", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-3", "prefsSetId": "gpii-default", "revoked": false, @@ -57,7 +57,7 @@ { "_id": "np_flatOnly_singleContext", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-4", "prefsSetId": "gpii-default", "revoked": false, @@ -68,7 +68,7 @@ { "_id": "np_mixed_multiContext", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-5", "prefsSetId": "gpii-default", "revoked": false, @@ -79,7 +79,7 @@ { "_id": "np_mixed_singleContext", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-6", "prefsSetId": "gpii-default", "revoked": false, @@ -90,7 +90,7 @@ { "_id": "np_tiny", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-7", "prefsSetId": "gpii-default", "revoked": false, @@ -101,7 +101,7 @@ { "_id": "undefined_preferences", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": null, "prefsSetId": null, "revoked": false, diff --git a/gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json b/gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json index b52fe19d0..f522af6db 100644 --- a/gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json +++ b/gpii/node_modules/preferencesServer/test/data/preferencesServiceUsers.json @@ -2,7 +2,7 @@ { "_id": "alice_gpii_key", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-1", "prefsSetId": "gpii-default", "revoked": false, @@ -12,7 +12,7 @@ }, { "_id": "bob_gpii_key", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": null, "prefsSetId": null, "revoked": false, @@ -22,7 +22,7 @@ }, { "_id": "snapset1", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-snapset1", "prefsSetId": "gpii-default", "revoked": false, @@ -32,7 +32,7 @@ }, { "_id": "prefsSafe-1", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": null, "email": null, @@ -56,7 +56,7 @@ }, { "_id": "prefsSafe-snapset1", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "snapset", "name": null, "email": null, @@ -78,7 +78,7 @@ { "_id": "prefsSafe-7", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": null, "email": null, diff --git a/gpii/node_modules/preferencesServer/test/data/prefsSafes-preferencesServiceTests.json b/gpii/node_modules/preferencesServer/test/data/prefsSafes-preferencesServiceTests.json index 2fe8234eb..111b13616 100644 --- a/gpii/node_modules/preferencesServer/test/data/prefsSafes-preferencesServiceTests.json +++ b/gpii/node_modules/preferencesServer/test/data/prefsSafes-preferencesServiceTests.json @@ -2,7 +2,7 @@ { "_id": "prefsSafe-1", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": null, "email": null, @@ -27,7 +27,7 @@ { "_id": "prefsSafe-snapset1", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "snapset", "name": null, "email": null, diff --git a/gpii/node_modules/preferencesServer/test/data/prefsSafes.json b/gpii/node_modules/preferencesServer/test/data/prefsSafes.json index 2706ccec1..f05dc5a90 100644 --- a/gpii/node_modules/preferencesServer/test/data/prefsSafes.json +++ b/gpii/node_modules/preferencesServer/test/data/prefsSafes.json @@ -2,7 +2,7 @@ { "_id": "prefsSafe-1", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": null, "email": null, @@ -56,7 +56,7 @@ { "_id": "prefsSafe-2", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": null, "email": null, @@ -110,7 +110,7 @@ { "_id": "prefsSafe-3", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": null, "email": null, @@ -161,7 +161,7 @@ { "_id": "prefsSafe-4", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": null, "email": null, @@ -209,7 +209,7 @@ { "_id": "prefsSafe-5", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": null, "email": null, @@ -298,7 +298,7 @@ { "_id": "prefsSafe-6", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": null, "email": null, @@ -361,7 +361,7 @@ { "_id": "prefsSafe-7", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": null, "email": null, @@ -386,7 +386,7 @@ { "_id": "prefsSafe-snapset1", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "snapset", "name": null, "email": null, diff --git a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js index 1b1818d85..b1404fcaf 100644 --- a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js +++ b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js @@ -446,7 +446,7 @@ fluid.defaults("gpii.tests.preferencesServer.preferencesService.addGpiiKey", { task: "{preferencesService}.addGpiiKey", args: [{ "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-1", "prefsSetId": "gpii-default", "revoked": false, @@ -454,7 +454,7 @@ fluid.defaults("gpii.tests.preferencesServer.preferencesService.addGpiiKey", { }], resolve: "jqUnit.assertLeftHand", resolveArgs: ["Newly created gpiiKey", { - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-1", "prefsSetId": "gpii-default", "revoked": false, @@ -471,7 +471,7 @@ fluid.defaults("gpii.tests.preferencesServer.preferencesService.addGpiiKey", { task: "{preferencesService}.addGpiiKey", args: [{ "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-2020", "prefsSetId": "gpii-default", "revoked": false, @@ -594,7 +594,7 @@ fluid.defaults("gpii.tests.preferencesServer.preferencesService.cloudSafeUnlock" gpii.tests.preferencesServer.preferencesService.createUpdatePrefsSafeData = { newPrefsSafe: { "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": "User 200", "preferences": { @@ -616,7 +616,7 @@ gpii.tests.preferencesServer.preferencesService.createUpdatePrefsSafeData = { updatedPrefsSafe7: { "id": "prefsSafe-7", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": "Prefs Seven", "email": null, diff --git a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js index a3c6b1440..7a4fd6ebe 100644 --- a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js +++ b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js @@ -70,7 +70,7 @@ gpii.tests.preferencesServer.prefsSafes.get.successFixtures = [ expected: { "id": "prefsSafe-7", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": null, "email": null, @@ -149,7 +149,7 @@ gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.successFixtures = [ prefsSafe: { "id": "prefsSafe-7", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": null, "email": null, @@ -174,7 +174,7 @@ gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.successFixtures = [ keys: [ { "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-7", "gpiiExpressUserId": "org.couch.db.user:prefs7user", "id": "8f3085a7-b65b-4648-9a78-8ac7de766997" @@ -182,7 +182,7 @@ gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.successFixtures = [ { "id": "np_tiny", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-7", "prefsSetId": "gpii-default", "revoked": false, @@ -249,7 +249,7 @@ gpii.tests.preferencesServer.prefsSafes.putSafe.successFixtures = [ putBody: { "id": "prefsSafe-7", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": "Prefs Seven", "email": null, @@ -274,7 +274,7 @@ gpii.tests.preferencesServer.prefsSafes.putSafe.successFixtures = [ expected: { "id": "prefsSafe-7", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": "Prefs Seven", "email": null, @@ -308,7 +308,7 @@ gpii.tests.preferencesServer.prefsSafes.putSafe.failFixtures = [ putBody: { "id": "prefsSafe-4000", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": "Prefs Seven", "email": null, @@ -344,7 +344,7 @@ gpii.tests.preferencesServer.prefsSafes.putSafe.failFixtures = [ putBody: { "id": "prefsSafe-7", "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": "Prefs Seven", "email": null, @@ -409,7 +409,7 @@ gpii.tests.preferencesServer.prefsSafes.postSafe.successFixtures = [ url: "%prefsSafeId", postBody: { "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": "Prefs Three Thousand", "email": null, @@ -431,7 +431,7 @@ gpii.tests.preferencesServer.prefsSafes.postSafe.successFixtures = [ }, expected: { "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": "user", "name": "Prefs Three Thousand", "email": null, @@ -627,7 +627,7 @@ gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.successFixtures = [ "offset": 9, rows: [{ "type": "gpiiCloudSafeCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-7", "gpiiExpressUserId": "org.couch.db.user:prefs7user", "id": "8f3085a7-b65b-4648-9a78-8ac7de766997" @@ -635,7 +635,7 @@ gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.successFixtures = [ { "id": "np_tiny", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-7", "prefsSetId": "gpii-default", "revoked": false, @@ -699,7 +699,7 @@ gpii.tests.preferencesServer.prefsSafes.prefsSafeKeyCreate.successFixtures = [ }, expected: { "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": "prefsSafe-1", "prefsSetId": "gpii-lowlight", "revoked": false, diff --git a/scripts/generateCredentials.js b/scripts/generateCredentials.js index e67de274f..3f4a472fa 100644 --- a/scripts/generateCredentials.js +++ b/scripts/generateCredentials.js @@ -30,7 +30,7 @@ These credentials consist in: { "_id": "UUID-clientCredentials", "type": "clientCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "UUID-gpiiAppInstallationClient", "oauth2ClientId": "UUID-pilot-computer", "oauth2ClientSecret": "UUID-pilot-computer-secret", @@ -49,7 +49,7 @@ These credentials consist in: { "_id": "UUID-gpiiAppInstallationClient", "type": "gpiiAppInstallationClient", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "name": "Pilot Computers", "computerType": "public", "timestampCreated": "2017-11-21T18:11:22.101Z", @@ -118,7 +118,7 @@ var generateCredentials = function () { var clientCredential = { "_id": clientCredentialsId, "type": "clientCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": gpiiAppInstallationClientId, "oauth2ClientId": clientId, "oauth2ClientSecret": clientSecret, @@ -135,7 +135,7 @@ var generateCredentials = function () { var gpiiAppInstallationClient = { "_id": gpiiAppInstallationClientId, "type": "gpiiAppInstallationClient", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "name": credentialsName, "computerType": "public", "timestampCreated": currentTime, diff --git a/scripts/shared/prefsSetsDbUtils.js b/scripts/shared/prefsSetsDbUtils.js index 169b929a0..3bff76947 100644 --- a/scripts/shared/prefsSetsDbUtils.js +++ b/scripts/shared/prefsSetsDbUtils.js @@ -55,7 +55,7 @@ gpii.prefsSetsDbUtils.generateKeyData = function (gpiiKeyId, preferences, prefsS var newGpiiKey = { "_id": gpiiKeyId, "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": prefsSafeId, "prefsSetId": "gpii-default", "revoked": false, @@ -67,7 +67,7 @@ gpii.prefsSetsDbUtils.generateKeyData = function (gpiiKeyId, preferences, prefsS var newPrefsSafe = { "_id": prefsSafeId, "type": "prefsSafe", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeType": prefsSafeType || "user", "name": gpiiKeyId, "email": null, diff --git a/testData/dbData/clientCredentials.json b/testData/dbData/clientCredentials.json index f66e408de..c5910dc28 100644 --- a/testData/dbData/clientCredentials.json +++ b/testData/dbData/clientCredentials.json @@ -2,7 +2,7 @@ { "_id": "clientCredential-1", "type": "clientCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-1", "oauth2ClientId": "pilot-computer", "oauth2ClientSecret": "pilot-computer-secret", diff --git a/testData/dbData/gpiiAppInstallationClients.json b/testData/dbData/gpiiAppInstallationClients.json index 4c6e76f4b..3ba6ae80d 100644 --- a/testData/dbData/gpiiAppInstallationClients.json +++ b/testData/dbData/gpiiAppInstallationClients.json @@ -2,7 +2,7 @@ { "_id": "gpiiAppInstallationClient-1", "type": "gpiiAppInstallationClient", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "name": "Pilot Computers", "computerType": "public", "timestampCreated": "2017-11-21T18:11:22.101Z", diff --git a/tests/data/dbData/clientCredentials.json b/tests/data/dbData/clientCredentials.json index eab0c69ae..e428d06c8 100644 --- a/tests/data/dbData/clientCredentials.json +++ b/tests/data/dbData/clientCredentials.json @@ -2,7 +2,7 @@ { "_id": "clientCredential-1", "type": "clientCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-1", "oauth2ClientId": "pilot-computer", "oauth2ClientSecret": "pilot-computer-secret", @@ -18,7 +18,7 @@ { "_id": "clientCredential-schemaV0.1", "type": "clientCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-schemaV0.1", "oauth2ClientId": "pilot-computer-schemaV0.1", "oauth2ClientSecret": "pilot-computer-secret-schemaV0.1", @@ -30,7 +30,7 @@ { "_id": "clientCredential-nova", "type": "clientCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-nova", "oauth2ClientId": "nova-computer", "oauth2ClientSecret": "nova-computer-secret", @@ -53,7 +53,7 @@ { "_id": "clientCredential-failInIpVerification", "type": "clientCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-nova-failInIpVerification", "oauth2ClientId": "nova-computer-failInIpVerification", "oauth2ClientSecret": "nova-computer-secret-failInIpVerification", @@ -69,7 +69,7 @@ { "_id": "clientCredential-failInAllowedPrefsToWrite", "type": "clientCredential", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "clientId": "gpiiAppInstallationClient-nova-failInAllowedPrefsToWrite", "oauth2ClientId": "nova-computer-failInAllowedPrefsToWrite", "oauth2ClientSecret": "nova-computer-secret-failInAllowedPrefsToWrite", diff --git a/tests/data/dbData/gpiiAppInstallationClients.json b/tests/data/dbData/gpiiAppInstallationClients.json index d7db029ca..5465019b6 100644 --- a/tests/data/dbData/gpiiAppInstallationClients.json +++ b/tests/data/dbData/gpiiAppInstallationClients.json @@ -2,7 +2,7 @@ { "_id": "gpiiAppInstallationClient-1", "type": "gpiiAppInstallationClient", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "name": "Pilot Computers", "computerType": "public", "timestampCreated": "2017-11-21T18:11:22.101Z", @@ -11,7 +11,7 @@ { "_id": "gpiiAppInstallationClient-schemaV0.1", "type": "gpiiAppInstallationClient", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "name": "To match the client credential data structure that is in the old schema version 0.1", "computerType": "public", "timestampCreated": "2017-11-21T18:11:22.101Z", @@ -20,7 +20,7 @@ { "_id": "gpiiAppInstallationClient-nova", "type": "gpiiAppInstallationClient", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "name": "NOVA - success workflow tests", "computerType": "public", "timestampCreated": "2019-05-28T18:11:22.101Z", @@ -29,7 +29,7 @@ { "_id": "gpiiAppInstallationClient-nova-failInIpVerification", "type": "gpiiAppInstallationClient", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "name": "NOVA - erroneous workflow test for the ip verification", "computerType": "public", "timestampCreated": "2019-05-28T18:11:22.101Z", @@ -38,7 +38,7 @@ { "_id": "gpiiAppInstallationClient-nova-failInAllowedPrefsToWrite", "type": "gpiiAppInstallationClient", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "name": "NOVA - erroneous workflow test for the allowed preferences to write", "computerType": "public", "timestampCreated": "2019-05-28T18:11:22.101Z", diff --git a/tests/data/dbData/gpiiKeys.json b/tests/data/dbData/gpiiKeys.json index 7fe1d60ab..52d20280a 100644 --- a/tests/data/dbData/gpiiKeys.json +++ b/tests/data/dbData/gpiiKeys.json @@ -2,7 +2,7 @@ { "_id": "gpii_key_no_prefs_safe", "type": "gpiiKey", - "schemaVersion": "0.2", + "schemaVersion": "0.3", "prefsSafeId": null, "prefsSetId": null, "revoked": false, From 2f365c4149f45cd484db929cc01ffc25228fd1ee Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Fri, 27 Dec 2019 13:31:40 -0800 Subject: [PATCH 66/72] GPII-2966 Incrementing gpii.dbOperation.schemaVersion --- gpii/node_modules/gpii-db-operation/src/DbConst.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpii/node_modules/gpii-db-operation/src/DbConst.js b/gpii/node_modules/gpii-db-operation/src/DbConst.js index 32a9c2e18..563cb73c8 100644 --- a/gpii/node_modules/gpii-db-operation/src/DbConst.js +++ b/gpii/node_modules/gpii-db-operation/src/DbConst.js @@ -15,7 +15,7 @@ var gpii = fluid.registerNamespace("gpii"); fluid.registerNamespace("gpii.dbOperation"); // The current version of schemas that document structures correspond with. -gpii.dbOperation.schemaVersion = "0.2"; +gpii.dbOperation.schemaVersion = "0.3"; // All doc types used for saving different documents into CouchDB // See [GPII Data Model](https://wiki.gpii.net/w/Keys,_KeyTokens,_and_Preferences#Data_Model) From 2045391b5ecb820669cfbef12e78439886b38f16 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Thu, 23 Jan 2020 13:14:52 -0800 Subject: [PATCH 67/72] GPII-2966 Eliminating separate userLookup.json views file and adding them to existing views.json --- .../preferencesServer/test/cloudSafeCredTests.js | 1 - .../preferencesServer/test/data/userLookup.json | 16 ---------------- .../test/preferencesServiceTests.js | 1 - testData/dbData/views.json | 14 ++++++++++++++ 4 files changed, 14 insertions(+), 18 deletions(-) delete mode 100644 gpii/node_modules/preferencesServer/test/data/userLookup.json diff --git a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js index 8daca71f7..8b42b2ff0 100644 --- a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js +++ b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js @@ -413,7 +413,6 @@ fluid.defaults("gpii.tests.preferencesServer.cloudSafeCred.testEnvironment", { "%gpii-universal/gpii/node_modules/preferencesServer/test/data/gpiiKeys.json", "%gpii-universal/gpii/node_modules/preferencesServer/test/data/prefsSafes.json", "%gpii-universal/gpii/node_modules/preferencesServer/test/data/gpiiCloudSafeCred.json", - "%gpii-universal/gpii/node_modules/preferencesServer/test/data/userLookup.json", "%gpii-universal/testData/dbData/views.json" ] } diff --git a/gpii/node_modules/preferencesServer/test/data/userLookup.json b/gpii/node_modules/preferencesServer/test/data/userLookup.json deleted file mode 100644 index 396968632..000000000 --- a/gpii/node_modules/preferencesServer/test/data/userLookup.json +++ /dev/null @@ -1,16 +0,0 @@ -[ - { - "_id": "_design/lookup", - "views": { - "byUsernameOrEmail": { - "map": "function (doc) {\n if (doc.type === 'user') { emit(doc.username, doc); \n emit(doc.email, doc); \n } \n}" - }, - "byVerificationCode": { - "map": "function (doc) {\n if (doc.verification_code) { emit(doc.verification_code, doc); \n } \n}" - }, - "byResetCode": { - "map": "function (doc) {\n if (doc.reset_code) { emit(doc.reset_code, doc); \n } \n}" - } - } - } -] diff --git a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js index b1404fcaf..b2686cd63 100644 --- a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js +++ b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js @@ -110,7 +110,6 @@ fluid.defaults("gpii.tests.preferencesServer.preferencesService.baseEnvironment" data: [ "%gpii-universal/gpii/node_modules/preferencesServer/test/data/gpiiKeys-preferenceServiceTests.json", "%gpii-universal/gpii/node_modules/preferencesServer/test/data/prefsSafes-preferencesServiceTests.json", - "%gpii-universal/gpii/node_modules/preferencesServer/test/data/userLookup.json", "%gpii-universal/gpii/node_modules/preferencesServer/test/data/gpiiCloudSafeCred.json", "%gpii-universal/gpii/node_modules/preferencesServer/test/data/prefsSafes.json", "%gpii-universal/testData/dbData/views.json" diff --git a/testData/dbData/views.json b/testData/dbData/views.json index 6c8de31df..96bd380a8 100644 --- a/testData/dbData/views.json +++ b/testData/dbData/views.json @@ -33,5 +33,19 @@ "map": "function(doc) {emit(doc.schemaVersion, doc); }" } } + }, + { + "_id": "_design/lookup", + "views": { + "byUsernameOrEmail": { + "map": "function (doc) {\n if (doc.type === 'user') { emit(doc.username, doc); \n emit(doc.email, doc); \n } \n}" + }, + "byVerificationCode": { + "map": "function (doc) {\n if (doc.type === 'user' && doc.verification_code) { emit(doc.verification_code, doc); \n } \n}" + }, + "byResetCode": { + "map": "function (doc) {\n if (doc.type === 'user' && doc.reset_code) { emit(doc.reset_code, doc); \n } \n}" + } + } } ] From 7e7fdf98ebdcb2b34e79b3606b4d4fd01d58a36a Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Thu, 19 Mar 2020 18:43:03 -0700 Subject: [PATCH 68/72] GPII-2966 Updating test payloads --- .../node_modules/preferencesServer/test/cloudSafeCredTests.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js index 8b42b2ff0..1c32dbb07 100644 --- a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js +++ b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js @@ -157,7 +157,6 @@ gpii.tests.preferencesServer.cloudSafeCred.put.successFixtures = [ "mouseEmulation": { "-provisional-initDelay": 120, "cursorSpeed": 0.850, - "cursorAcceleration": 0.800, "-provisional-mouseEmulation/enabled": true } }, @@ -166,8 +165,7 @@ gpii.tests.preferencesServer.cloudSafeCred.put.successFixtures = [ "org.alsa-project": { "id": "org.alsa-project", "parameters": { - "volume": 14, - "pitch": 100 + "masterVolume": 14 } } } From bf6e5b3b918937e30dcf35c45f4cea45c730dc69 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Mon, 30 Mar 2020 10:17:38 -0700 Subject: [PATCH 69/72] GPII-2966 Breaking up promises into event firing transform. --- .../src/preferencesService.js | 65 ++++++++++--------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index 13aa8966e..e6df47827 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -100,7 +100,8 @@ var fluid = fluid || require("infusion"); onCreatePreferences: null, onAssociatePreferences: null, onCloudSafeCredCreate: null, - onCloudSafeUnlock: null + onCloudSafeUnlock: null, + onUpdatePrefsSafe: null }, listeners: { onCreatePreferences: [{ @@ -164,7 +165,24 @@ var fluid = fluid || require("infusion"); func: "{dataStore}.findById", args: ["{arguments}.0.prefsSafeId"], namespace: "findById" - }] + }], + // onUpdatePrefsSafe is a pseudoevent for a promise chain. The primary method call is + // `dataStore.updatePrefsSafe` which is flanked by calls to `getPrefsSafe` in order to confirm + // existence of the safe, and then to return the final contents + "onUpdatePrefsSafe.checkPrefsSetExist": { + func: "{that}.getPrefsSafe", + args: "{arguments}.1.id" + }, + "onUpdatePrefsSafe.updatePrefsSafe": { + func: "{dataStore}.updatePrefsSafe", + args: ["{arguments}.1.id", "{arguments}.1"], + priority: "after:checkPrefsSetExist" + }, + "onUpdatePrefsSafe.getPrefsSafe": { + func: "{that}.getPrefsSafe", + args: "{arguments}.1.id", + priority: "after:updatePrefsSafe" + } } }); @@ -262,36 +280,19 @@ var fluid = fluid || require("infusion"); }); } else { - that.getPrefsSafe(prefsSafeData.id).then(function () { - // TODO This will have json schema validation when the scaffolding is all in. - dataStore.updatePrefsSafe(prefsSafeData.id, prefsSafeData).then( - function (/* updatedReturn */) { - that.getPrefsSafe(prefsSafeData.id).then( - function (finalData) { - promiseTogo.resolve(finalData); - }, - function (err) { - fluid.log(err); - promiseTogo.reject({ - isError: true, - errorCode: gpii.preferencesServer.errors.missingPrefsSafe.errorCode, - message: gpii.preferencesServer.errors.missingPrefsSafe.message - }); - } - ); - }, - function (err) { - promiseTogo.reject(err); - } - ); - }, function (err) { - fluid.log(err); - promiseTogo.reject({ - isError: true, - errorCode: gpii.preferencesServer.errors.missingPrefsSafe.errorCode, - message: gpii.preferencesServer.errors.missingPrefsSafe.message - }); - }); + fluid.promise.fireTransformEvent(that.events.onUpdatePrefsSafe, {}, prefsSafeData).then( + function (data) { + promiseTogo.resolve(data); + }, + function (err) { + fluid.log(err); + promiseTogo.reject({ + isError: true, + errorCode: gpii.preferencesServer.errors.missingPrefsSafe.errorCode, + message: gpii.preferencesServer.errors.missingPrefsSafe.message + }); + } + ); } return promiseTogo; }; From 331cfac88036bbee095fda62e95576c6718dce31 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Mon, 30 Mar 2020 15:44:16 -0700 Subject: [PATCH 70/72] GPII-2966 minor typo --- gpii/node_modules/gpii-db-operation/src/DbUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpii/node_modules/gpii-db-operation/src/DbUtils.js b/gpii/node_modules/gpii-db-operation/src/DbUtils.js index 44f918251..13dcea0b4 100644 --- a/gpii/node_modules/gpii-db-operation/src/DbUtils.js +++ b/gpii/node_modules/gpii-db-operation/src/DbUtils.js @@ -55,7 +55,7 @@ gpii.dbOperation.getCurrentTimestamp = function () { * included in the promise rejection payload. * @param {String} errorCode - If this isn't the appropriate type, this error code will be * included in the promise rejection payload. - * @return {fluid.promise} Promise, when the item is valid it resolves with the + * @return {fluid.promise} Promise, when the item is valid, it resolves with the * original item. When the item is not valid, it rejects with an error payload including * the supplied `errorMessage`. */ From 18ff970e0572c23bd6c527d458a437d6c5b18124 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Mon, 30 Mar 2020 16:00:33 -0700 Subject: [PATCH 71/72] GPII-2966 prefssafe -> prefsSafe --- documentation/PreferencesServer.md | 32 +++++++++---------- .../src/preferencesServer.js | 14 ++++---- .../src/preferencesServerConst.js | 4 +-- .../src/preferencesService.js | 2 +- .../test/cloudSafeCredTests.js | 8 ++--- .../test/preferencesServiceTests.js | 4 +-- .../preferencesServer/test/prefsSafesTests.js | 26 +++++++-------- 7 files changed, 45 insertions(+), 45 deletions(-) diff --git a/documentation/PreferencesServer.md b/documentation/PreferencesServer.md index d94753cf4..4491ac07f 100644 --- a/documentation/PreferencesServer.md +++ b/documentation/PreferencesServer.md @@ -341,14 +341,14 @@ There are two important things to note here: to `http://registry.gpii.net/common/fontSize`. Since we do not allow the same setting to be present multiple times in the NP set, the fontSize has been stored in the flat ontology and removed from the ISO24751 block. -### GET /prefssafe/:prefsSafeId +### GET /prefsSafe/:prefsSafeId This end point will return the entire preferences safe, including the embedded preference sets. The URL param is the `id` of the preferences safe. This will not return any attached keys, credentials, or other records. #### Example GET -URL: `http://preferences.gpii.net/prefssafe/prefsSafe-alice` +URL: `http://preferences.gpii.net/prefsSafe/prefsSafe-alice` Example Success Payload: @@ -385,11 +385,11 @@ returned: { "isError": true, "errorCode": "GPII_ERR_NO_PREFSSAFE", - "message": "Missing prefssafe" + "message": "Missing prefsSafe" } ``` -### GET /prefssafe-with-keys/:prefsSafeId +### GET /prefsSafe-with-keys/:prefsSafeId This endpoint will return the entire preferences safe structure, along with records directory related to it, such as keys and credentials. A top level object will contain the preferences safe under key `prefsSafe`, and the related @@ -397,7 +397,7 @@ documents under key `keys`. #### Example GET -URL: `http://preferences.gpii.net/prefssafe-with-keys/prefsSafe-alice` +URL: `http://preferences.gpii.net/prefsSafe-with-keys/prefsSafe-alice` Example returned item: @@ -455,11 +455,11 @@ If the safe with the specified `prefsSafeId` does not exist, the following error { "isError": true, "errorCode": "GPII_ERR_NO_PREFSSAFE", - "message": "Missing prefssafe" + "message": "Missing prefsSafe" } ``` -### POST /prefssafe +### POST /prefsSafe Creates a new preferences safe in the system. Takes a full preferences safe JSON payload, albiet without a `id`. The returned payload will include the entire preferences safe, including the updated `timestampCreated` field, @@ -467,7 +467,7 @@ and a newly provisioned `id`. #### Example POST -URL: `http://preferences.gpii.net/prefssafe` +URL: `http://preferences.gpii.net/prefsSafe` The POST payload should be a full preferences safe without an `id`: @@ -508,14 +508,14 @@ with the contents of the system error: } ``` -### PUT /prefssafe/:prefsSafeId +### PUT /prefsSafe/:prefsSafeId Updates an existing preferences safe in the database, using the full preferences safe format. Will return the updated safe, which should include an updated `timestampUpdated` field. #### Example PUT -URL: `http://preferences.gpii.net/prefssafe/prefsSafe-alice` +URL: `http://preferences.gpii.net/prefsSafe/prefsSafe-alice` Example PUT body: @@ -557,7 +557,7 @@ suitable message will be returned. } ``` -### GET /prefssafes +### GET /prefsSafes Returns a list of preferences safes, including only basic information about each one. Ideal for building a table or listing of preferences safes. Each item in the list representing a preferences safe will include `id`, `name`, @@ -566,7 +566,7 @@ paging, etc. #### Example GET -URL: `http://preferences.gpii.net/prefssafes` +URL: `http://preferences.gpii.net/prefsSafes` Example return payload: @@ -596,7 +596,7 @@ Example return payload: There should never be an error payload for this endpoint. In the situation where there are no preferences safes stored in the system it will merely contain zero rows. -### GET /prefssafe-keys/:prefsSafeId +### GET /prefsSafe-keys/:prefsSafeId This will return the associated keys and credentials documents for a given preferences safe, in a `rows` field. Also included is a `total_rows` and `offset` field, but do note that the `total_rows` field is not accurate as @@ -604,7 +604,7 @@ of the time of writing, and should be ignored. #### Example GET -URL: `http://preferences.gpii.net/prefssafe-keys/prefsSafe-alice` +URL: `http://preferences.gpii.net/prefsSafe-keys/prefsSafe-alice` An example payload for a particlar safe may be: @@ -635,7 +635,7 @@ An example payload for a particlar safe may be: } ``` -### POST /prefssafe-key-create +### POST /prefsSafe-key-create This endpoint will add a new `gpiiKey` document to the system. There are no URL parameters, but the JSON body takes 3 fields, one of them optional. Required are the `prefsSafeId` and `prefsSetId`. These indicate the preferences safe, @@ -646,7 +646,7 @@ detailing the failure. #### Example POST: -URL: `http://preferences.gpii.net/prefssafe-key-create` +URL: `http://preferences.gpii.net/prefsSafe-key-create` Example POST Body: diff --git a/gpii/node_modules/preferencesServer/src/preferencesServer.js b/gpii/node_modules/preferencesServer/src/preferencesServer.js index cefacab3f..658dadaed 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesServer.js +++ b/gpii/node_modules/preferencesServer/src/preferencesServer.js @@ -54,37 +54,37 @@ fluid.defaults("gpii.preferencesServer", { }, // GPII-2966 prefsSafeGet: { - route: "/prefssafe/:prefsSafeId", + route: "/prefsSafe/:prefsSafeId", method: "get", type: "gpii.preferencesServer.prefsSafeGet.handler" }, prefsSafeWithKeysGet: { - route: "/prefssafe-with-keys/:prefsSafeId", + route: "/prefsSafe-with-keys/:prefsSafeId", method: "get", type: "gpii.preferencesServer.prefsSafeWithKeysGet.handler" }, createPrefsSafe: { - route: "/prefssafe", + route: "/prefsSafe", method: "post", type: "gpii.preferencesServer.prefsSafePost.handler" }, updatePrefsSafe: { - route: "/prefssafe/:prefsSafeId", + route: "/prefsSafe/:prefsSafeId", method: "put", type: "gpii.preferencesServer.prefsSafePut.handler" }, listPrefsSafes: { - route: "/prefssafes", + route: "/prefsSafes", method: "get", type: "gpii.preferencesServer.prefsSafeList.handler" }, findRelatedDocsForPrefsSafe: { - route: "/prefssafe-keys/:prefsSafeId", + route: "/prefsSafe-keys/:prefsSafeId", method: "get", type: "gpii.preferencesServer.findRelatedDocsForPrefsSafe.handler" }, prefsSafeKeyCreate: { - route: "/prefssafe-key-create", + route: "/prefsSafe-key-create", method: "post", type: "gpii.preferencesServer.prefsSafeKeyCreate.handler" }, diff --git a/gpii/node_modules/preferencesServer/src/preferencesServerConst.js b/gpii/node_modules/preferencesServer/src/preferencesServerConst.js index 67ac6bcd8..019abda6e 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesServerConst.js +++ b/gpii/node_modules/preferencesServer/src/preferencesServerConst.js @@ -42,12 +42,12 @@ gpii.preferencesServer.errors = fluid.freezeRecursive({ }, missingPrefsSafe: { errorCode: "GPII_ERR_NO_PREFSSAFE", - message: "Missing prefssafe" + message: "Missing prefsSafe" }, // Catch all error for unaccepted errors errorAccessingPrefsSafe: { errorCode: "GPII_ERR_ACCESSING_PREFSSAFE", - message: "Error accessing prefssafe" + message: "Error accessing prefsSafe" }, errorNotPrefsSafe: { errorCode: "GPII_ERR_NOT_PREFSSAFE", diff --git a/gpii/node_modules/preferencesServer/src/preferencesService.js b/gpii/node_modules/preferencesServer/src/preferencesService.js index e6df47827..8e65001ec 100644 --- a/gpii/node_modules/preferencesServer/src/preferencesService.js +++ b/gpii/node_modules/preferencesServer/src/preferencesService.js @@ -304,7 +304,7 @@ var fluid = fluid || require("infusion"); * exists and is active. It will then take the username and password and * create a new gpii-express-user entry. With that we will then create * the cloudsafe credential document that will contain the ID's of both - * the prefssafe and the user record. + * the prefsSafe and the user record. * * Currently this method does only a small amount of validation on the username * and password, requiring that both fields are included and of length greater than diff --git a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js index 1c32dbb07..7106f3b30 100644 --- a/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js +++ b/gpii/node_modules/preferencesServer/test/cloudSafeCredTests.js @@ -38,7 +38,7 @@ gpii.tests.preferencesServer.config = { // Step 2: Verify that the Cloud Safe Cred Document is correct // Step 3: Verify that the gpii-express-user document is correct // Step 4: Verify that this is included in the list keys endpoint -// Step 5: Verify that this is included in the prefssafe with keys endpoint +// Step 5: Verify that this is included in the prefsSafe with keys endpoint fluid.registerNamespace("gpii.tests.preferencesServer.cloudSafeCred.put"); /* @@ -80,7 +80,7 @@ gpii.tests.preferencesServer.cloudSafeCred.put.buildSuccessTestDef = function (f getFullSafe: { type: "kettle.test.request.http", options: { - path: "/prefssafe-with-keys/" + fixture.url, + path: "/prefsSafe-with-keys/" + fixture.url, method: "GET", port: 8081, termMap: { @@ -123,7 +123,7 @@ gpii.tests.preferencesServer.cloudSafeCred.put.buildSuccessTestDef = function (f gpii.tests.preferencesServer.cloudSafeCred.put.successFixtures = [ { - name: "PUT: Add a cloudsafe credential to an existing prefssafe", + name: "PUT: Add a cloudsafe credential to an existing prefsSafe", prefsSafeId: "prefsSafe-1", url: "%prefsSafeId", putCloudCredBody: { @@ -235,7 +235,7 @@ gpii.tests.preferencesServer.cloudSafeCred.put.failureFixtures = [ failedCreateExpected: { isError: true, errorCode: "GPII_ERR_NO_PREFSSAFE", - message: "Missing prefssafe" + message: "Missing prefsSafe" } }, { diff --git a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js index b2686cd63..2e45d876c 100644 --- a/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js +++ b/gpii/node_modules/preferencesServer/test/preferencesServiceTests.js @@ -479,7 +479,7 @@ fluid.defaults("gpii.tests.preferencesServer.preferencesService.addGpiiKey", { reject: "jqUnit.assertLeftHand", rejectArgs: ["Preference safe doesn't exist, can't create key", { "isError": true, - "message": "Missing prefssafe", + "message": "Missing prefsSafe", "errorCode": "GPII_ERR_NO_PREFSSAFE" }, "{arguments}.0"] }] @@ -528,7 +528,7 @@ fluid.defaults("gpii.tests.preferencesServer.preferencesService.cloudSafeCredCre reject: "jqUnit.assertLeftHand", rejectArgs: ["Error message saying the prefs safe does not exist.", { "isError": true, - "message": "Missing prefssafe", + "message": "Missing prefsSafe", "errorCode": "GPII_ERR_NO_PREFSSAFE" }, "{arguments}.0"] }] diff --git a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js index 7a4fd6ebe..21db0ea22 100644 --- a/gpii/node_modules/preferencesServer/test/prefsSafesTests.js +++ b/gpii/node_modules/preferencesServer/test/prefsSafesTests.js @@ -43,7 +43,7 @@ gpii.tests.preferencesServer.prefsSafes.get.buildTestDef = function (fixture) { getRequest: { type: "kettle.test.request.http", options: { - path: "/prefssafe/" + fixture.url, + path: "/prefsSafe/" + fixture.url, method: "GET", port: 8081, termMap: { @@ -104,7 +104,7 @@ gpii.tests.preferencesServer.prefsSafes.get.failFixtures = [ expected: { "isError": true, "errorCode": "GPII_ERR_NO_PREFSSAFE", - "message": "Missing prefssafe" + "message": "Missing prefsSafe" } } ]; @@ -121,7 +121,7 @@ gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.buildTestDef = function getRequest: { type: "kettle.test.request.http", options: { - path: "/prefssafe-with-keys/" + fixture.url, + path: "/prefsSafe-with-keys/" + fixture.url, method: "GET", port: 8081, termMap: { @@ -204,7 +204,7 @@ gpii.tests.preferencesServer.prefsSafes.getSafeWithKeys.failFixtures = [ expected: { "isError": true, "errorCode": "GPII_ERR_NO_PREFSSAFE", - "message": "Missing prefssafe" + "message": "Missing prefsSafe" } } ]; @@ -221,7 +221,7 @@ gpii.tests.preferencesServer.prefsSafes.putSafe.buildTestDef = function (fixture getRequest: { type: "kettle.test.request.http", options: { - path: "/prefssafe/" + fixture.url, + path: "/prefsSafe/" + fixture.url, method: "PUT", port: 8081, termMap: { @@ -333,7 +333,7 @@ gpii.tests.preferencesServer.prefsSafes.putSafe.failFixtures = [ expected: { isError: true, errorCode: "GPII_ERR_NO_PREFSSAFE", - message: "Missing prefssafe" + message: "Missing prefsSafe" } }, { @@ -386,7 +386,7 @@ gpii.tests.preferencesServer.prefsSafes.postSafe.buildTestDef = function (fixtur getRequest: { type: "kettle.test.request.http", options: { - path: "/prefssafe", + path: "/prefsSafe", method: "POST", port: 8081 } @@ -466,7 +466,7 @@ gpii.tests.preferencesServer.prefsSafes.list.buildTestDef = function (fixture) { getRequest: { type: "kettle.test.request.http", options: { - path: "/prefssafes", + path: "/prefsSafes", method: "GET", port: 8081 } @@ -564,7 +564,7 @@ gpii.tests.preferencesServer.prefsSafes.list.emptyDatabase = [ getRequest: { type: "kettle.test.request.http", options: { - path: "/prefssafes", + path: "/prefsSafes", method: "GET", port: 8081 } @@ -596,7 +596,7 @@ gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.buildTestDef = function getRequest: { type: "kettle.test.request.http", options: { - path: "/prefssafe-keys/" + fixture.url, + path: "/prefsSafe-keys/" + fixture.url, method: "GET", port: 8081, termMap: { @@ -617,7 +617,7 @@ gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.buildTestDef = function gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.successFixtures = [ { - name: "GET: Basic listing of keys for a prefssafe", + name: "GET: Basic listing of keys for a prefsSafe", prefsSafeId: "prefsSafe-7", url: "%prefsSafeId", expected: { @@ -656,7 +656,7 @@ gpii.tests.preferencesServer.prefsSafes.listKeysForSafe.failFixtures = [ expected: { "isError": true, "errorCode": "GPII_ERR_NO_PREFSSAFE", - "message": "Missing prefssafe" + "message": "Missing prefsSafe" } } ]; @@ -673,7 +673,7 @@ gpii.tests.preferencesServer.prefsSafes.prefsSafeKeyCreate.buildTestDef = functi getRequest: { type: "kettle.test.request.http", options: { - path: "/prefssafe-key-create", + path: "/prefsSafe-key-create", method: "POST", port: 8081 } From 934316613b1cca00596033f80e0c5a98a88e3a71 Mon Sep 17 00:00:00 2001 From: Steven Githens Date: Tue, 26 May 2020 15:03:56 -0700 Subject: [PATCH 72/72] GPII-2966 The lifecycle manager utils tests need to run in node. --- .../test/html/LifecycleManagerUtilsTest.html | 44 ------------------- tests/all-tests.js | 1 + tests/web/html/all-tests.html | 1 - 3 files changed, 1 insertion(+), 45 deletions(-) delete mode 100644 gpii/node_modules/lifecycleManager/test/html/LifecycleManagerUtilsTest.html diff --git a/gpii/node_modules/lifecycleManager/test/html/LifecycleManagerUtilsTest.html b/gpii/node_modules/lifecycleManager/test/html/LifecycleManagerUtilsTest.html deleted file mode 100644 index bb79b1b11..000000000 --- a/gpii/node_modules/lifecycleManager/test/html/LifecycleManagerUtilsTest.html +++ /dev/null @@ -1,44 +0,0 @@ - - - - - GPII Lifecycle Manager Utilities Tests - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    GPII Lifecycle Manager Utilities Tests

    -

    -
    -

    -
      - - - diff --git a/tests/all-tests.js b/tests/all-tests.js index 432e2a9d0..ef4e95ed6 100644 --- a/tests/all-tests.js +++ b/tests/all-tests.js @@ -68,6 +68,7 @@ var testIncludes = [ "../gpii/node_modules/gpii-oauth2/gpii-oauth2-authz-server/test/authGrantFinderTests.js", "../gpii/node_modules/gpii-oauth2/gpii-oauth2-authz-server/test/authorizationServiceTests.js", "../gpii/node_modules/gpii-oauth2/gpii-oauth2-utilities/test/OAuth2UtilitiesTests.js", + "../gpii/node_modules/lifecycleManager/test/js/LifeCycleManagerUtilsTests.js", "../gpii/node_modules/matchMakerFramework/test/MatchMakerFrameworkTests.js", "../gpii/node_modules/ontologyHandler/test/node/OntologyHandlerTests.js", "../gpii/node_modules/preferencesServer/test/preferencesServerTests.js", diff --git a/tests/web/html/all-tests.html b/tests/web/html/all-tests.html index 9bf6ffaf6..700b8d4ab 100644 --- a/tests/web/html/all-tests.html +++ b/tests/web/html/all-tests.html @@ -15,7 +15,6 @@ "/gpii/node_modules/gpii-user-errors/test/html/UserErrorsTest.html", "/gpii/node_modules/journal/test/html/JournalIdParserTests.html", "/gpii/node_modules/lifecycleManager/test/html/LifecycleManagerResolverTest.html", - "/gpii/node_modules/lifecycleManager/test/html/LifecycleManagerUtilsTest.html", "/gpii/node_modules/lifecycleManager/test/html/LifecycleManagerTest.html", "/gpii/node_modules/matchMakerFramework/test/html/MatchMakerUtilitiesTest.html", "/gpii/node_modules/ontologyHandler/test/html/OntologyHandlerUtilitiesTest.html",