From 1014a619230166b4f29c7ee317cef8feef41ab3e Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Thu, 30 Jan 2020 11:31:51 -0800 Subject: [PATCH 01/75] sonar changes --- microservices/forumApi/db/db.js | 12 ++- microservices/forumApi/db/model/topic.js | 8 +- .../forumApi/routes/v1/routes/comments.js | 6 +- .../forumApi/routes/v1/routes/topics.js | 4 - .../routes/v1/subscribers/subscribers.js | 8 +- microservices/requestApi/auth/auth.js | 2 +- microservices/requestApi/auth/webhook_auth.js | 4 +- microservices/requestApi/db/model/request.js | 4 +- .../requestApi/notifications/email/index.js | 8 +- .../requestApi/notifications/gitops/index.js | 12 +-- .../requestApi/notifications/notifications.js | 4 +- .../requestApi/routes/routes/requests.js | 73 +++++++------------ .../requestApi/routes/v1/routes/requests.js | 4 +- .../requestApi/routes/v1/routes/webhook.js | 4 +- .../requestApi/routes/v2/db/model/request.js | 8 +- .../requestApi/routes/v2/routes/requests.js | 28 +++---- .../requestApi/routes/v2/routes/webhook.js | 4 +- 17 files changed, 84 insertions(+), 109 deletions(-) diff --git a/microservices/forumApi/db/db.js b/microservices/forumApi/db/db.js index 87149d363..7cb1c253f 100644 --- a/microservices/forumApi/db/db.js +++ b/microservices/forumApi/db/db.js @@ -5,10 +5,10 @@ mongoose.set('useCreateIndex', true); const dbProps = config.get('database'); -dbHost = dbProps.host; -dbUser = dbProps.username; -dbPass = dbProps.password; -dbName = dbProps.dbName; +const dbHost = dbProps.host; +const dbUser = dbProps.username; +const dbPass = dbProps.password; +const dbName = dbProps.dbName; var db = {}; @@ -37,9 +37,7 @@ db.init = function(){ db.Permission = require('./model/permission'); db.User = require('./model/user'); - var collections = Object.keys(db.db.collections); - -}; +} diff --git a/microservices/forumApi/db/model/topic.js b/microservices/forumApi/db/model/topic.js index e3055f3cf..f77af8a47 100644 --- a/microservices/forumApi/db/model/topic.js +++ b/microservices/forumApi/db/model/topic.js @@ -34,7 +34,7 @@ model.getAll = function(query, limit, page, user, callback){ checkGroups.splice(index,1); } - var index = checkGroups.indexOf('/oc'); + index = checkGroups.indexOf('/oc'); if (index !== -1){ checkGroups.splice(index,1); } @@ -54,7 +54,8 @@ model.getAll = function(query, limit, page, user, callback){ from: "permissions", let: { topicId: "$_id", parent: "$parent_id"}, pipeline: [ - {$match: { + { + $match: { $expr: { $and: [ {$or: [ @@ -65,7 +66,8 @@ model.getAll = function(query, limit, page, user, callback){ {$eq: ["$allow", true]} ] } - }}, + } + }, { $match: { $or: [ diff --git a/microservices/forumApi/routes/v1/routes/comments.js b/microservices/forumApi/routes/v1/routes/comments.js index af0dc30cc..58b5a742d 100644 --- a/microservices/forumApi/routes/v1/routes/comments.js +++ b/microservices/forumApi/routes/v1/routes/comments.js @@ -79,10 +79,10 @@ router.post("/:topicId", function(req, res, next){ return; } - subscribers.subscribe(topic._id, req.user.id, true, (err) => { - if (err) { + subscribers.subscribe(topic._id, req.user.id, true, (err2) => { + if (err2) { res.status(500); - res.json({error: err.message}); + res.json({error: err2.message}); return; } diff --git a/microservices/forumApi/routes/v1/routes/topics.js b/microservices/forumApi/routes/v1/routes/topics.js index 4a60b7a52..2890b864f 100644 --- a/microservices/forumApi/routes/v1/routes/topics.js +++ b/microservices/forumApi/routes/v1/routes/topics.js @@ -142,9 +142,7 @@ router.post("/", function(req, res, next){ router.delete('/:topicId', function(req, res){ var db = require('../db/db'); - var config = require('config'); var logger = require('npmlog'); - var mongoose = require('mongoose'); var topicId = mongoose.Types.ObjectId(req.params.topicId); db.Topic.getAll({_id: topicId}, 1, 1, req.user, function(topicErr, topicRes) { @@ -188,7 +186,6 @@ router.delete('/:topicId', function(req, res){ router.put('/:topicId/subscribe', function(req, res){ var db = require('../db/db'); - var mongoose = require('mongoose'); var subscribers = require('../subscribers/subscribers'); var topicId = mongoose.Types.ObjectId(req.params.topicId); @@ -215,7 +212,6 @@ router.put('/:topicId/subscribe', function(req, res){ router.put('/:topicId/unsubscribe', function(req, res){ var db = require('../db/db'); - var mongoose = require('mongoose'); var subscribers = require('../subscribers/subscribers'); var topicId = mongoose.Types.ObjectId(req.params.topicId); diff --git a/microservices/forumApi/routes/v1/subscribers/subscribers.js b/microservices/forumApi/routes/v1/subscribers/subscribers.js index 034596a28..f89d7b9bd 100644 --- a/microservices/forumApi/routes/v1/subscribers/subscribers.js +++ b/microservices/forumApi/routes/v1/subscribers/subscribers.js @@ -1,8 +1,8 @@ var db = require('../db/db'); -var subscribers = {}; +var s = {}; -subscribers.subscribe = function(topicId, userId, contributed, callback){ +s.subscribe = function(topicId, userId, contributed, callback){ db.Topic.findById(topicId).exec((err, topic) => { if (err || topic == null) { callback({error:'topic not found'}); @@ -30,7 +30,7 @@ subscribers.subscribe = function(topicId, userId, contributed, callback){ }); }; -subscribers.unsubscribe = function(topicId, userId, callback){ +s.unsubscribe = function(topicId, userId, callback){ db.Topic.findById(topicId).exec((err, topic) => { if (err || topic == null) { callback({error:'topic not found'}); @@ -51,4 +51,4 @@ subscribers.unsubscribe = function(topicId, userId, callback){ }; -module.exports = subscribers; \ No newline at end of file +module.exports = s; \ No newline at end of file diff --git a/microservices/requestApi/auth/auth.js b/microservices/requestApi/auth/auth.js index b622ca9d8..f8181b6e3 100644 --- a/microservices/requestApi/auth/auth.js +++ b/microservices/requestApi/auth/auth.js @@ -9,7 +9,7 @@ var auth = function(db){ const isOutputChecker = (user => user.groups.includes(config.get('outputCheckerGroup'))) const isInReportsGroup = (user => user.groups.includes(config.get('reportsGroup'))) - const isInGroupToCreateRequest = (user => user.groups.includes(config.get('requiredRoleToCreateRequest'))) + passport.use(new JWTStrategy({ jwtFromRequest: ExtractJWT.fromAuthHeaderAsBearerToken(), diff --git a/microservices/requestApi/auth/webhook_auth.js b/microservices/requestApi/auth/webhook_auth.js index 790d499dd..e479514ca 100644 --- a/microservices/requestApi/auth/webhook_auth.js +++ b/microservices/requestApi/auth/webhook_auth.js @@ -1,10 +1,10 @@ var auth = function(){ const passport = require('passport'); - const passJwt = require('passport-jwt'); + const passApiKey = require('passport-headerapikey'); const HeaderAPIKeyStrategy = passApiKey.HeaderAPIKeyStrategy; const config = require('config'); - const logger = require('npmlog'); + passport.use(new HeaderAPIKeyStrategy( { header: 'Authorization', prefix: 'Api-Key ' }, diff --git a/microservices/requestApi/db/model/request.js b/microservices/requestApi/db/model/request.js index a5ba173c0..fb488b8c1 100644 --- a/microservices/requestApi/db/model/request.js +++ b/microservices/requestApi/db/model/request.js @@ -325,7 +325,7 @@ model.getAll = function(query, limit, page, user, callback){ logger.verbose("getAll ", user.supervisor, user.outputchecker); - var queryRequests = function(err, topicR, projectR){ + var queryRequests = function(err2, topicR, projectR){ logger.verbose("get all topics model get all", topicR); if ('_id' in query) { query['_id'] = mongoose.Types.ObjectId(query['_id']); @@ -411,7 +411,7 @@ model.getAll = function(query, limit, page, user, callback){ } if ('_id' in query) { - db.Request.findById(query['_id'], (err, req) => { + db.Request.findById(query['_id'], (err3, req) => { getAllTopics(user, { id: req.topic }, queryRequests); }); } else { diff --git a/microservices/requestApi/notifications/email/index.js b/microservices/requestApi/notifications/email/index.js index 385e04067..03dcacdac 100644 --- a/microservices/requestApi/notifications/email/index.js +++ b/microservices/requestApi/notifications/email/index.js @@ -1,4 +1,4 @@ -var notifications = function(db){ +var notification = function(db){ var notifications = {}; var fs = require('fs'); @@ -80,14 +80,14 @@ var notifications = function(db){ if ( (submittedUnclaimed) && (config.has('emailOnInitialSubmit')) ){ var emailList = config.get('emailOnInitialSubmit'); - for (var i=0; i { + db.Request.findById(id, (err2, requestForUpdate) => { requestForUpdate.mergeRequestLink = link; requestForUpdate.mergeRequestStatus = { code: code, @@ -201,4 +201,4 @@ var gitops = function(db){ return gitops; } -module.exports = gitops; \ No newline at end of file +module.exports = gitop; \ No newline at end of file diff --git a/microservices/requestApi/notifications/notifications.js b/microservices/requestApi/notifications/notifications.js index 4335943b2..ac2a2aba1 100644 --- a/microservices/requestApi/notifications/notifications.js +++ b/microservices/requestApi/notifications/notifications.js @@ -1,4 +1,4 @@ -var notifications = function(db){ +var notification = function(db){ const email = require('./email')(db); const gitops = require('./gitops')(db); @@ -19,4 +19,4 @@ var notifications = function(db){ return notifications; } -module.exports = notifications; \ No newline at end of file +module.exports = notification; \ No newline at end of file diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index 54324d511..84995ea2a 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -1,5 +1,4 @@ var buildStatic = function(db, router){ - var mongoose = require('mongoose'); router.get('/status_codes', function(req, res, next) { res.json(db.Request.stateCodeLookup()); @@ -29,7 +28,7 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ /* GET all requests. */ router.get('/', function(req, res, next) { - var logger = require('npmlog'); + //var logger = require('npmlog'); var limit = 100; if (typeof(req.query.limit) !== "undefined"){ @@ -69,25 +68,24 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ } if (typeof(req.query.start_date) !== "undefined"){ - var split = req.query.start_date.split(/[-\/]/); - var year = split[0] ? split[0] : 0; - var month = split[1] ? split[1]-1 : 0; - var day = split[2] ? split[2] : 0; - var hour = split[3] ? split[3] : 0; - var minute = split[4] ? split[4] : 0; - var second = split[5] ? split[5] : 0; + let split = req.query.start_date.split(/[-\/]/); + let year = split[0] ? split[0] : 0; + let month = split[1] ? split[1]-1 : 0; + let day = split[2] ? split[2] : 0; + let hour = split[3] ? split[3] : 0; + let minute = split[4] ? split[4] : 0; + let second = split[5] ? split[5] : 0; q.submittedDate = {$gte: new Date(year, month, day, hour, minute, second)}; } if (typeof(req.query.end_date) !== "undefined"){ - var split = req.query.end_date.split(/[-\/]/); - var year = split[0] ? split[0] : 0; - var month = split[1] ? (split[1]-1) : 0; - var day = split[2] ? split[2] : 0; - var hour = split[3] ? split[3] : 0; - var minute = split[4] ? split[4] : 0; - var second = split[5] ? split[5] : 0; - var d = new Date(year, month, day, hour, minute, second); + let split = req.query.end_date.split(/[-\/]/); + let year = split[0] ? split[0] : 0; + let month = split[1] ? (split[1]-1) : 0; + let day = split[2] ? split[2] : 0; + let hour = split[3] ? split[3] : 0; + let minute = split[4] ? split[4] : 0; + let second = split[5] ? split[5] : 0; if (typeof(q.submittedDate) === "undefined"){ q.submittedDate = {$lte: new Date(year, month, day, hour, minute, second)}; }else{ @@ -232,9 +230,9 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ } //note not returning if an error as it'll force a delete below log.error("Error updating request", e); - db.Request.deleteOne({_id: result._id}, function(e){ - if (e) { - log.error("Error deleting request", result, e); + db.Request.deleteOne({_id: result._id}, function(e2){ + if (e2) { + log.error("Error deleting request", result, e2); } }); res.status(500); @@ -269,7 +267,6 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ /* GET specific request. */ router.get('/:requestId', function(req, res, next) { - var logger = require('npmlog'); var includeFileStatus = true; if (typeof(req.query.include_file_status) !== "undefined"){ @@ -374,7 +371,7 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ var policy = findRes.type + "-" + findRes.exportType; - for (var i=0; i { httpReq.put({ url: config.get('validationApi') + '/v1/validate/' + myFile + '/' + policy, @@ -402,10 +399,8 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ //submit a request router.put('/submit/:requestId', function(req, res, next){ - var config = require('config'); var logger = require('npmlog'); var requestId = mongoose.Types.ObjectId(req.params.requestId); - var httpReq = require('request'); // Lookup project from user groups var project = projectConfig.deriveProjectFromUser(req.user); @@ -446,18 +441,10 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ return; } - var numResults = 0; - var allResults = []; - var pass = true; - if (reqRes.reviewers.length > 0) { reqRes.state = db.Request.IN_REVIEW_STATE; - } else if (reqRes.type === db.Request.INPUT_TYPE && autoAccept.import) { - reqRes.state = db.Request.AWAITING_REVIEW_STATE; - db.Request.setChrono(reqRes, req.user.id); - reqRes.state = db.Request.APPROVED_STATE; - } else if (reqRes.type === db.Request.EXPORT_TYPE && autoAccept.export) { + } else if ( (reqRes.type === db.Request.INPUT_TYPE && autoAccept.import) || (reqRes.type === db.Request.EXPORT_TYPE && autoAccept.export) ){ reqRes.state = db.Request.AWAITING_REVIEW_STATE; db.Request.setChrono(reqRes, req.user.id); reqRes.state = db.Request.APPROVED_STATE; @@ -476,7 +463,7 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ util.getBundleMeta(reqRes.files, function(metadataRes){ var bundleSize = 0; - for (var i=0; i Date: Thu, 30 Jan 2020 12:54:38 -0800 Subject: [PATCH 02/75] a few more --- microservices/requestApi/db/db.js | 8 ++++---- microservices/requestApi/routes/routes/requests.js | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/microservices/requestApi/db/db.js b/microservices/requestApi/db/db.js index 81af23ac9..0bcf4ca8e 100644 --- a/microservices/requestApi/db/db.js +++ b/microservices/requestApi/db/db.js @@ -5,10 +5,10 @@ mongoose.set('useCreateIndex', true); const dbProps = config.get('database'); -dbHost = dbProps.host; -dbUser = dbProps.username; -dbPass = dbProps.password; -dbName = dbProps.dbName; +const dbHost = dbProps.host; +const dbUser = dbProps.username; +const dbPass = dbProps.password; +const dbName = dbProps.dbName; function versionedDB(version){ diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index 84995ea2a..b5516ac3f 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -487,7 +487,7 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ } let pass = true; - var blocked = false; + let blocked = false; for (let i=0; i < reqRes.files.length; i++) { for (var j=0; j < status[reqRes.files[i]].length; j++) { @@ -558,6 +558,7 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ return; } let pass = true; + let blocked = false; for (let i=0; i < reqRes.files.length; i++){ for (var j=0; j < status[reqRes.files[i]].length; j++) { if ((status[reqRes.files[i]][j].state === 1) && (status[reqRes.files[i]][j].mandatory === true)) { From e315c887ce343750545af97d842e6518b39a43b6 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Thu, 30 Jan 2020 13:06:52 -0800 Subject: [PATCH 03/75] a few more --- microservices/requestApi/db/db.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microservices/requestApi/db/db.js b/microservices/requestApi/db/db.js index 0bcf4ca8e..d1ec37e15 100644 --- a/microservices/requestApi/db/db.js +++ b/microservices/requestApi/db/db.js @@ -45,7 +45,7 @@ function versionedDB(version){ db.init(); return db; -}; +} From f432599f056a2b9fed00e48256788629063bff20 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Thu, 30 Jan 2020 14:14:15 -0800 Subject: [PATCH 04/75] added more tests for v2 --- microservices/requestApi/test/v2/requests.js | 85 ++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index 0d3dd23c6..a031b4cb9 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -132,6 +132,23 @@ describe("Requests", function() { }); }); + it('it should fail without a name', function (done) { + chai.request(server) + .post('/v2/') + .set("Authorization", "Bearer " + jwt) + .send({ + text: "text", + number: 9 + }) + .end(function (err, res) { + res.should.have.status(500); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + res.body.error.should.be.a('string'); + done(); + }); + }); + it('it should create a request', function (done) { chai.request(server) .post('/v2/') @@ -198,6 +215,19 @@ describe("Requests", function() { done(); }); }); + + it('it should get a specific request but without file statuses', function (done) { + chai.request(server) + .get('/v2/' + activeRequestId + "?include_file_status=false") + .set("Authorization", "Bearer " + jwt) + .end(function (err, res) { + res.should.have.status(200); + res.body.should.have.property('_id'); + res.body.should.not.have.property('fileStatus') + done(); + }); + }); + }); describe('/DELETE /v2/requestId', function() { @@ -498,3 +528,58 @@ describe("Requests", function() { }); }); + +describe("Forms", function() { + describe('/GET v2/forms', function () { + it('it should get unauthorized', function (done) { + chai.request(server) + .get('/v2/forms') + .end(function (err, res) { + res.should.have.status(401); + done(); + }); + }); + + it('it should get all forms', function (done) { + chai.request(server) + .get('/v2/forms') + .set("Authorization", "Bearer "+jwt) + .end(function (err, res) { + res.should.have.status(200); + res.body.should.have.property('data'); + done(); + }); + }); + + it('it should get default forms', function (done) { + chai.request(server) + .get('/v2/forms/defaults') + .set("Authorization", "Bearer "+jwt) + .end(function (err, res) { + res.should.have.status(200); + res.body.should.have.property('forms'); + res.body.forms.should.have.property('internal') + res.body.forms.should.have.property('external') + done(); + }); + }); + + it('it should get a specific form', function (done) { + chai.request(server) + .get('/v2/forms/test') + .set("Authorization", "Bearer "+jwt) + .end(function (err, res) { + res.should.have.status(200); + res.body.should.have.property('forms'); + res.body.forms.should.have.property('internal') + res.body.forms.should.have.property('external') + done(); + }); + }); + + + + }); + + +}); \ No newline at end of file From f9f44c69d1cdf4795e864128c5af56119fb954f2 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Thu, 30 Jan 2020 14:30:49 -0800 Subject: [PATCH 05/75] added more tests for v2 --- microservices/requestApi/test/v2/requests.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index a031b4cb9..f1562bf29 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -557,9 +557,8 @@ describe("Forms", function() { .set("Authorization", "Bearer "+jwt) .end(function (err, res) { res.should.have.status(200); - res.body.should.have.property('forms'); - res.body.forms.should.have.property('internal') - res.body.forms.should.have.property('external') + res.body.should.have.property('0'); + res.body[0].should.have.property('_id'); done(); }); }); @@ -570,9 +569,7 @@ describe("Forms", function() { .set("Authorization", "Bearer "+jwt) .end(function (err, res) { res.should.have.status(200); - res.body.should.have.property('forms'); - res.body.forms.should.have.property('internal') - res.body.forms.should.have.property('external') + res.body.should.have.property('_id'); done(); }); }); From 8a381381d656dc6dcdcaf5fa37e204370272e505 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Thu, 30 Jan 2020 14:34:56 -0800 Subject: [PATCH 06/75] added more tests for v2 --- microservices/requestApi/test/v2/requests.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index f1562bf29..388e2d9b7 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -546,7 +546,8 @@ describe("Forms", function() { .set("Authorization", "Bearer "+jwt) .end(function (err, res) { res.should.have.status(200); - res.body.should.have.property('data'); + res.body.should.have.property('0'); + res.body[0].should.have.property('_id'); done(); }); }); @@ -557,8 +558,9 @@ describe("Forms", function() { .set("Authorization", "Bearer "+jwt) .end(function (err, res) { res.should.have.status(200); - res.body.should.have.property('0'); - res.body[0].should.have.property('_id'); + res.body.should.have.property('forms'); + res.body.forms.should.have.property('internal') + res.body.forms.should.have.property('external') done(); }); }); From ceff08853398e14080858ac41159700df0cd4eb1 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Thu, 30 Jan 2020 14:55:36 -0800 Subject: [PATCH 07/75] more test coverage --- microservices/requestApi/test/v1/requests.js | 25 +++++++++++++++++++- microservices/requestApi/test/v2/requests.js | 25 +++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index 0246ce496..7fe19ba91 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -93,6 +93,29 @@ describe("Requests", function() { }); }); + it('it should get file_status_codes', function (done) { + chai.request(server) + .get('/v1/file_status_codes') + .end(function (err, res) { + res.should.have.status(200); + res.body.should.have.property('0'); + res.body.should.have.property('1'); + res.body.should.have.property('2'); + done(); + }); + }); + + it('it should get request_types', function (done) { + chai.request(server) + .get('/v1/request_types') + .end(function (err, res) { + res.should.have.status(200); + res.body.should.have.property('import'); + res.body.should.have.property('export'); + done(); + }); + }); + it('it should get all status code mappings', function (done) { chai.request(server) .get('/v1/status_codes') @@ -186,7 +209,7 @@ describe("Requests", function() { describe('/GET v1 & v1/requestId', function () { it('it should get requests', function (done) { chai.request(server) - .get('/v1') + .get('/v1?limit=1&page=1&name=testName&start_date=2000/01/01/00/00/00&end_date=9999/01/01/00/00/00') .set("Authorization", "Bearer " + jwt) .end(function (err, res) { res.should.have.status(200); diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index 388e2d9b7..e5fe325c1 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -93,6 +93,29 @@ describe("Requests", function() { }); }); + it('it should get file_status_codes', function (done) { + chai.request(server) + .get('/v1/file_status_codes') + .end(function (err, res) { + res.should.have.status(200); + res.body.should.have.property('0'); + res.body.should.have.property('1'); + res.body.should.have.property('2'); + done(); + }); + }); + + it('it should get request_types', function (done) { + chai.request(server) + .get('/v1/request_types') + .end(function (err, res) { + res.should.have.status(200); + res.body.should.have.property('import'); + res.body.should.have.property('export'); + done(); + }); + }); + it('it should get all status code mappings', function (done) { chai.request(server) .get('/v2/status_codes') @@ -174,7 +197,7 @@ describe("Requests", function() { describe('/GET v2 & v2/requestId', function () { it('it should get requests', function (done) { chai.request(server) - .get('/v2') + .get('/v2?limit=1&page=1&name=testName&start_date=2000/01/01/00/00/00&end_date=9999/01/01/00/00/00') .set("Authorization", "Bearer " + jwt) .end(function (err, res) { res.should.have.status(200); From 56a98f81fb35eda34d3c02237e2427c1e897c6eb Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Fri, 31 Jan 2020 08:19:02 -0800 Subject: [PATCH 08/75] test tweaks --- microservices/requestApi/test/v1/requests.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index 7fe19ba91..d47eea24e 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -96,6 +96,7 @@ describe("Requests", function() { it('it should get file_status_codes', function (done) { chai.request(server) .get('/v1/file_status_codes') + .set("Authorization", "Bearer "+jwt) .end(function (err, res) { res.should.have.status(200); res.body.should.have.property('0'); @@ -108,6 +109,7 @@ describe("Requests", function() { it('it should get request_types', function (done) { chai.request(server) .get('/v1/request_types') + .set("Authorization", "Bearer "+jwt) .end(function (err, res) { res.should.have.status(200); res.body.should.have.property('import'); @@ -212,6 +214,7 @@ describe("Requests", function() { .get('/v1?limit=1&page=1&name=testName&start_date=2000/01/01/00/00/00&end_date=9999/01/01/00/00/00') .set("Authorization", "Bearer " + jwt) .end(function (err, res) { + console.log("SHOULD GET REQUEST body". res.body); res.should.have.status(200); res.body.length.should.be.eql(1); done(); From 2338112ab1571a0d1ba5f6b159be08ca8603c4fa Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Fri, 31 Jan 2020 08:31:17 -0800 Subject: [PATCH 09/75] test tweaks --- microservices/requestApi/test/v1/requests.js | 2 +- microservices/requestApi/test/v2/requests.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index d47eea24e..5a1640410 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -214,7 +214,7 @@ describe("Requests", function() { .get('/v1?limit=1&page=1&name=testName&start_date=2000/01/01/00/00/00&end_date=9999/01/01/00/00/00') .set("Authorization", "Bearer " + jwt) .end(function (err, res) { - console.log("SHOULD GET REQUEST body". res.body); + console.log("SHOULD GET REQUEST body", res.body); res.should.have.status(200); res.body.length.should.be.eql(1); done(); diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index e5fe325c1..fc5a46071 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -95,7 +95,8 @@ describe("Requests", function() { it('it should get file_status_codes', function (done) { chai.request(server) - .get('/v1/file_status_codes') + .get('/v2/file_status_codes') + .set("Authorization", "Bearer " + jwt) .end(function (err, res) { res.should.have.status(200); res.body.should.have.property('0'); @@ -107,7 +108,8 @@ describe("Requests", function() { it('it should get request_types', function (done) { chai.request(server) - .get('/v1/request_types') + .get('/v2/request_types') + .set("Authorization", "Bearer " + jwt) .end(function (err, res) { res.should.have.status(200); res.body.should.have.property('import'); From f0c98498f6cc689966c24985093d2428a9151e26 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Fri, 31 Jan 2020 08:43:00 -0800 Subject: [PATCH 10/75] test tweaks --- microservices/requestApi/test/v1/requests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index 5a1640410..b882ac586 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -211,7 +211,7 @@ describe("Requests", function() { describe('/GET v1 & v1/requestId', function () { it('it should get requests', function (done) { chai.request(server) - .get('/v1?limit=1&page=1&name=testName&start_date=2000/01/01/00/00/00&end_date=9999/01/01/00/00/00') + .get('/v1?limit=1&page=1&name=testName') .set("Authorization", "Bearer " + jwt) .end(function (err, res) { console.log("SHOULD GET REQUEST body", res.body); From 4c5a0c878657526d91d2bd410fe6ce00d4a31e08 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Fri, 31 Jan 2020 08:50:26 -0800 Subject: [PATCH 11/75] test tweaks --- microservices/requestApi/test/v1/requests.js | 1 - microservices/requestApi/test/v2/requests.js | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index b882ac586..243249ff0 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -214,7 +214,6 @@ describe("Requests", function() { .get('/v1?limit=1&page=1&name=testName') .set("Authorization", "Bearer " + jwt) .end(function (err, res) { - console.log("SHOULD GET REQUEST body", res.body); res.should.have.status(200); res.body.length.should.be.eql(1); done(); diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index fc5a46071..1b5b5b23f 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -199,9 +199,10 @@ describe("Requests", function() { describe('/GET v2 & v2/requestId', function () { it('it should get requests', function (done) { chai.request(server) - .get('/v2?limit=1&page=1&name=testName&start_date=2000/01/01/00/00/00&end_date=9999/01/01/00/00/00') + .get('/v2?limit=1&page=1') .set("Authorization", "Bearer " + jwt) .end(function (err, res) { + console.log("v2 should get requests body", res.body); res.should.have.status(200); res.body.length.should.be.eql(1); done(); From 6b1b8419abd4b73b1ec752b4035575d76bf78b89 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Fri, 31 Jan 2020 11:00:17 -0800 Subject: [PATCH 12/75] sonar tweaks --- microservices/requestApi/test/v2/requests.js | 3 +-- sonar-project.properties | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index 1b5b5b23f..0654effbe 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -199,10 +199,9 @@ describe("Requests", function() { describe('/GET v2 & v2/requestId', function () { it('it should get requests', function (done) { chai.request(server) - .get('/v2?limit=1&page=1') + .get('/v2?limit=1&page=1&state=0') .set("Authorization", "Bearer " + jwt) .end(function (err, res) { - console.log("v2 should get requests body", res.body); res.should.have.status(200); res.body.length.should.be.eql(1); done(); diff --git a/sonar-project.properties b/sonar-project.properties index 2c0c1698b..34ba98570 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -24,7 +24,8 @@ projectApi.sonar.projectBaseDir=microservices/projectApi projectApi.sonar.sources=auth,bin,db,routes requestApi.sonar.projectBaseDir=microservices/requestApi -requestApi.sonar.sources=auth,bin,db,routes,notifications +requestApi.sonar.sources=auth,bin,db,routes,clients,messages,util +requestApi.sonar.exclusions=**/notifications/*.js policyApi.sonar.projectBaseDir=microservices policyApi.sonar.sources=policyApi/db,policyApi/v1 From 619a7b8e5267b9b284570fed72606dc513461536 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Fri, 31 Jan 2020 11:25:21 -0800 Subject: [PATCH 13/75] adding more tests --- microservices/requestApi/test/v1/requests.js | 52 +++++++++++++++++++- microservices/requestApi/test/v2/requests.js | 2 +- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index 243249ff0..8a93e0c3b 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -211,7 +211,7 @@ describe("Requests", function() { describe('/GET v1 & v1/requestId', function () { it('it should get requests', function (done) { chai.request(server) - .get('/v1?limit=1&page=1&name=testName') + .get('/v1?limit=1&page=1&name=testName&start_date=2000-01-01-01-01-01&end_date=9999-01-01-01-01-01') .set("Authorization", "Bearer " + jwt) .end(function (err, res) { res.should.have.status(200); @@ -313,6 +313,18 @@ describe("Requests", function() { }); }); + it('it should fail to save a request', function (done) { + chai.request(server) + .put('/v1/save/1') + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + }); + }); + it('it should save a request', function (done) { chai.request(server) .put('/v1/save/' + activeRequestId) @@ -364,6 +376,17 @@ describe("Requests", function() { done(); }); }); + + it('it should fail to save a request that is in wrong state', function (done) { + chai.request(server) + .put('/v1/save/' + activeRequestId) + .set("Authorization", "Bearer " + jwt) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + }); + }); }); describe('/PUT /v1/pickup/requestId', function() { @@ -406,7 +429,6 @@ describe("Requests", function() { .set("Authorization", "Bearer " + jwt) .send({ name: "testName3", - tags: ["test"], purpose: "purpose", phoneNumber: "555-555-5555", subPopulation: "sub-population", @@ -483,6 +505,19 @@ describe("Requests", function() { setTimeout(done, 2000); }); }); + + it('it should fail to submit an invalid request', function (done) { + chai.request(server) + .put('/v1/submit/1') + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); it('it should submit a request', function (done) { chai.request(server) @@ -498,6 +533,19 @@ describe("Requests", function() { }); }); + it('it should fail to submit an already submitted request', function (done) { + chai.request(server) + .put('/v1/submit/' + activeRequestId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + it('it should pickup a request', function (done) { chai.request(server) .put('/v1/pickup/' + activeRequestId) diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index 0654effbe..31dc5a260 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -199,7 +199,7 @@ describe("Requests", function() { describe('/GET v2 & v2/requestId', function () { it('it should get requests', function (done) { chai.request(server) - .get('/v2?limit=1&page=1&state=0') + .get('/v2?limit=101&page=0&state=0&name=*') .set("Authorization", "Bearer " + jwt) .end(function (err, res) { res.should.have.status(200); From 6a13c4c78f4471914284b7b22f09441421aba3be Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Fri, 31 Jan 2020 11:41:12 -0800 Subject: [PATCH 14/75] test tweaks --- microservices/requestApi/test/v1/requests.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index 8a93e0c3b..cfc00535e 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -211,7 +211,7 @@ describe("Requests", function() { describe('/GET v1 & v1/requestId', function () { it('it should get requests', function (done) { chai.request(server) - .get('/v1?limit=1&page=1&name=testName&start_date=2000-01-01-01-01-01&end_date=9999-01-01-01-01-01') + .get('/v1?limit=1&page=1&name=testName') .set("Authorization", "Bearer " + jwt) .end(function (err, res) { res.should.have.status(200); @@ -319,6 +319,7 @@ describe("Requests", function() { .set("Authorization", "Bearer " + jwt) .send({}) .end(function (err, res) { + console.log("it should fail to save a request", res.body); res.should.have.status(400); res.body.should.be.a('object'); res.body.should.have.property('error'); @@ -512,6 +513,7 @@ describe("Requests", function() { .set("Authorization", "Bearer " + jwt) .send({}) .end(function (err, res) { + console.log("IT SHOULD FAIL TO SUBMIT AN INVALID REQUEST", res.body); res.should.have.status(400); res.body.should.be.a('object'); res.body.should.have.property('error'); From 269715f42005e65111caf7ad2714f9bd95b138f8 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Fri, 31 Jan 2020 11:51:45 -0800 Subject: [PATCH 15/75] tweak --- microservices/requestApi/db/model/request.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/microservices/requestApi/db/model/request.js b/microservices/requestApi/db/model/request.js index fb488b8c1..c70671300 100644 --- a/microservices/requestApi/db/model/request.js +++ b/microservices/requestApi/db/model/request.js @@ -399,6 +399,9 @@ model.getAll = function(query, limit, page, user, callback){ ]; db.Request.aggregate(q).exec(function(err, results){ + if (err){ + return callback(err, []); + } logger.verbose("in topic bind"); if (results){ for (var i=0; i Date: Fri, 31 Jan 2020 13:55:46 -0800 Subject: [PATCH 16/75] debug --- microservices/requestApi/routes/routes/requests.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index b5516ac3f..c56748cf6 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -313,7 +313,9 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ var config = require('config'); var logger = require('npmlog'); + console.log("Saving"); db.Request.getAll({_id: requestId}, 1, 1, req.user, function(findErr, findRes){ + console.log("Inside get all", findErr, findRes); if (findErr || !findRes || findRes.length <= 0){ res.status(400); res.json({error: "No such request"}); From 6bcc60f5749836f2dadf7dd8c5cd70c6c5f76db0 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Fri, 31 Jan 2020 14:14:12 -0800 Subject: [PATCH 17/75] test tweaks --- microservices/requestApi/routes/routes/requests.js | 2 +- microservices/requestApi/test/v1/requests.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index c56748cf6..73c446240 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -315,7 +315,7 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ console.log("Saving"); db.Request.getAll({_id: requestId}, 1, 1, req.user, function(findErr, findRes){ - console.log("Inside get all", findErr, findRes); + console.log("Inside get all", findErr, findRes, requestId); if (findErr || !findRes || findRes.length <= 0){ res.status(400); res.json({error: "No such request"}); diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index cfc00535e..7696de14f 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -315,7 +315,7 @@ describe("Requests", function() { it('it should fail to save a request', function (done) { chai.request(server) - .put('/v1/save/1') + .put('/v1/save/' + activeRequestId.substring(0, activeRequestId.length-1)+"1") .set("Authorization", "Bearer " + jwt) .send({}) .end(function (err, res) { From c796a32e4279f98f502008db055b8c88cb33d83d Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Fri, 31 Jan 2020 14:56:16 -0800 Subject: [PATCH 18/75] test tweaks --- microservices/requestApi/routes/routes/requests.js | 2 +- microservices/requestApi/test/v1/requests.js | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index 73c446240..bc3c3b496 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -315,7 +315,7 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ console.log("Saving"); db.Request.getAll({_id: requestId}, 1, 1, req.user, function(findErr, findRes){ - console.log("Inside get all", findErr, findRes, requestId); + console.log("Inside get all", requestId, findErr, findRes); if (findErr || !findRes || findRes.length <= 0){ res.status(400); res.json({error: "No such request"}); diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index 7696de14f..126f62473 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -313,13 +313,18 @@ describe("Requests", function() { }); }); + var incorrectId = activeRequestId.substring(0, activeRequestId.length-1)+"1"; + if (incorrectId === activeRequestId){ + incorrectId = activeRequestId.substring(0, activeRequestId.length-1)+"2"; + } + it('it should fail to save a request', function (done) { chai.request(server) - .put('/v1/save/' + activeRequestId.substring(0, activeRequestId.length-1)+"1") + .put('/v1/save/' + incorrectId) .set("Authorization", "Bearer " + jwt) .send({}) .end(function (err, res) { - console.log("it should fail to save a request", res.body); + console.log("it should fail to save a request", incorrectId, res.body); res.should.have.status(400); res.body.should.be.a('object'); res.body.should.have.property('error'); From e5d6cdd975b61f3c56e4b72bcbca593779a23ed3 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Fri, 31 Jan 2020 15:05:52 -0800 Subject: [PATCH 19/75] debug --- microservices/requestApi/routes/routes/requests.js | 1 + 1 file changed, 1 insertion(+) diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index bc3c3b496..5f61ad46c 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -309,6 +309,7 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ //save a request router.put("/save/:requestId", function(req, res, next){ + console.log("req.params.requestId", req.params.requestId); var requestId = mongoose.Types.ObjectId(req.params.requestId); var config = require('config'); var logger = require('npmlog'); From ca923136eb43819287a35a529f2329955413e8a3 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Fri, 31 Jan 2020 15:15:19 -0800 Subject: [PATCH 20/75] debug --- microservices/requestApi/test/v1/requests.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index 126f62473..f96bd5951 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -314,9 +314,11 @@ describe("Requests", function() { }); var incorrectId = activeRequestId.substring(0, activeRequestId.length-1)+"1"; + console.log("D", activeRequestId, incorrectId); if (incorrectId === activeRequestId){ incorrectId = activeRequestId.substring(0, activeRequestId.length-1)+"2"; } + console.log("D", activeRequestId, incorrectId); it('it should fail to save a request', function (done) { chai.request(server) From 5ca442444436d56c0105606442f0abdb7ff5c913 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Fri, 31 Jan 2020 15:35:18 -0800 Subject: [PATCH 21/75] debug --- microservices/requestApi/test/v1/requests.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index f96bd5951..234b4db2a 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -17,6 +17,7 @@ chai.use(chaiHttp); describe("Requests", function() { var activeRequestId = ''; + var incorrectId = ''; var fileId = 'test_' + Math.random().toString(36) + '.jpeg'; after(function(done){ db.Request.deleteMany({}, function(err){ @@ -309,16 +310,15 @@ describe("Requests", function() { res.body.should.have.property('result'); res.body.result.should.have.property('_id'); activeRequestId = res.body.result._id; + incorrectId = activeRequestId.substring(0, activeRequestId.length-1)+"1"; + if (incorrectId === activeRequestId){ + incorrectId = activeRequestId.substring(0, activeRequestId.length-1)+"2"; + } + console.log("D", activeRequestId, incorrectId); done(); }); }); - var incorrectId = activeRequestId.substring(0, activeRequestId.length-1)+"1"; - console.log("D", activeRequestId, incorrectId); - if (incorrectId === activeRequestId){ - incorrectId = activeRequestId.substring(0, activeRequestId.length-1)+"2"; - } - console.log("D", activeRequestId, incorrectId); it('it should fail to save a request', function (done) { chai.request(server) From 4ba48d0eba7e1d8a17c6e27789a9d1f414a4e00e Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Fri, 31 Jan 2020 15:42:19 -0800 Subject: [PATCH 22/75] fix --- microservices/requestApi/db/model/request.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/microservices/requestApi/db/model/request.js b/microservices/requestApi/db/model/request.js index c70671300..6f3c3591c 100644 --- a/microservices/requestApi/db/model/request.js +++ b/microservices/requestApi/db/model/request.js @@ -405,8 +405,10 @@ model.getAll = function(query, limit, page, user, callback){ logger.verbose("in topic bind"); if (results){ for (var i=0; i Date: Mon, 3 Feb 2020 08:30:13 -0800 Subject: [PATCH 23/75] fixes --- microservices/requestApi/db/model/request.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microservices/requestApi/db/model/request.js b/microservices/requestApi/db/model/request.js index 6f3c3591c..18f43c33e 100644 --- a/microservices/requestApi/db/model/request.js +++ b/microservices/requestApi/db/model/request.js @@ -405,7 +405,7 @@ model.getAll = function(query, limit, page, user, callback){ logger.verbose("in topic bind"); if (results){ for (var i=0; i Date: Mon, 3 Feb 2020 08:37:49 -0800 Subject: [PATCH 24/75] fixes --- microservices/requestApi/db/model/request.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/microservices/requestApi/db/model/request.js b/microservices/requestApi/db/model/request.js index 18f43c33e..199af9c0b 100644 --- a/microservices/requestApi/db/model/request.js +++ b/microservices/requestApi/db/model/request.js @@ -405,7 +405,7 @@ model.getAll = function(query, limit, page, user, callback){ logger.verbose("in topic bind"); if (results){ for (var i=0; i { - getAllTopics(user, { id: req.topic }, queryRequests); + if ( (typeof(req) !== "undefined") && (typeof(req.topic) !== "undefined") ){ + getAllTopics(user, { id: req.topic }, queryRequests); + } }); } else { getAllTopics(user, {}, queryRequests); From cc2ea91dcf6778e1bdd02780c5cfb3e6c3917df8 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 08:42:57 -0800 Subject: [PATCH 25/75] fixes --- microservices/requestApi/db/model/request.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/microservices/requestApi/db/model/request.js b/microservices/requestApi/db/model/request.js index 199af9c0b..bbdbd0dd6 100644 --- a/microservices/requestApi/db/model/request.js +++ b/microservices/requestApi/db/model/request.js @@ -406,6 +406,7 @@ model.getAll = function(query, limit, page, user, callback){ if (results){ for (var i=0; i { if ( (typeof(req) !== "undefined") && (typeof(req.topic) !== "undefined") ){ + console.log("TOPIC ID", req.topic); getAllTopics(user, { id: req.topic }, queryRequests); } }); From 7e2f1f06938dca38f195ef04952ae2c181576d64 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 08:54:26 -0800 Subject: [PATCH 26/75] fixes --- microservices/requestApi/routes/routes/requests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index 5f61ad46c..e63fd97dc 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -309,11 +309,11 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ //save a request router.put("/save/:requestId", function(req, res, next){ - console.log("req.params.requestId", req.params.requestId); var requestId = mongoose.Types.ObjectId(req.params.requestId); var config = require('config'); var logger = require('npmlog'); + console.log("req.params.requestId", req.params.requestId, requestId); console.log("Saving"); db.Request.getAll({_id: requestId}, 1, 1, req.user, function(findErr, findRes){ console.log("Inside get all", requestId, findErr, findRes); From d850c4a9803ca46cd24ff3fb482e8a6ef94160aa Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 09:14:46 -0800 Subject: [PATCH 27/75] debug --- microservices/requestApi/db/model/request.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/microservices/requestApi/db/model/request.js b/microservices/requestApi/db/model/request.js index bbdbd0dd6..47af44757 100644 --- a/microservices/requestApi/db/model/request.js +++ b/microservices/requestApi/db/model/request.js @@ -417,6 +417,7 @@ model.getAll = function(query, limit, page, user, callback){ } if ('_id' in query) { + console.log("id in query"); db.Request.findById(query['_id'], (err3, req) => { if ( (typeof(req) !== "undefined") && (typeof(req.topic) !== "undefined") ){ console.log("TOPIC ID", req.topic); @@ -424,6 +425,7 @@ model.getAll = function(query, limit, page, user, callback){ } }); } else { + console.log("id NOT in query"); getAllTopics(user, {}, queryRequests); } }; From 515d37f8784bd14bdd9e0d6cd0e651f70172e102 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 09:20:14 -0800 Subject: [PATCH 28/75] debug --- microservices/requestApi/db/model/request.js | 1 + 1 file changed, 1 insertion(+) diff --git a/microservices/requestApi/db/model/request.js b/microservices/requestApi/db/model/request.js index 47af44757..bf8fe1595 100644 --- a/microservices/requestApi/db/model/request.js +++ b/microservices/requestApi/db/model/request.js @@ -419,6 +419,7 @@ model.getAll = function(query, limit, page, user, callback){ if ('_id' in query) { console.log("id in query"); db.Request.findById(query['_id'], (err3, req) => { + console.log("_ID", typeof(req), req); if ( (typeof(req) !== "undefined") && (typeof(req.topic) !== "undefined") ){ console.log("TOPIC ID", req.topic); getAllTopics(user, { id: req.topic }, queryRequests); From a72373218c462f97bfadfadfd1e91faeab98ea96 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 09:27:22 -0800 Subject: [PATCH 29/75] fixes --- microservices/requestApi/db/model/request.js | 7 +------ microservices/requestApi/routes/routes/requests.js | 3 --- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/microservices/requestApi/db/model/request.js b/microservices/requestApi/db/model/request.js index bf8fe1595..405fa8dc7 100644 --- a/microservices/requestApi/db/model/request.js +++ b/microservices/requestApi/db/model/request.js @@ -406,7 +406,6 @@ model.getAll = function(query, limit, page, user, callback){ if (results){ for (var i=0; i { - console.log("_ID", typeof(req), req); - if ( (typeof(req) !== "undefined") && (typeof(req.topic) !== "undefined") ){ - console.log("TOPIC ID", req.topic); + if ( (req !== null) && (typeof(req) !== "undefined") && (typeof(req.topic) !== "undefined") ){ getAllTopics(user, { id: req.topic }, queryRequests); } }); } else { - console.log("id NOT in query"); getAllTopics(user, {}, queryRequests); } }; diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index e63fd97dc..b5516ac3f 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -313,10 +313,7 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ var config = require('config'); var logger = require('npmlog'); - console.log("req.params.requestId", req.params.requestId, requestId); - console.log("Saving"); db.Request.getAll({_id: requestId}, 1, 1, req.user, function(findErr, findRes){ - console.log("Inside get all", requestId, findErr, findRes); if (findErr || !findRes || findRes.length <= 0){ res.status(400); res.json({error: "No such request"}); From dda9794d08d16723d3217f638a1d316b850a7db6 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 09:53:49 -0800 Subject: [PATCH 30/75] debug --- microservices/requestApi/db/model/request.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/microservices/requestApi/db/model/request.js b/microservices/requestApi/db/model/request.js index 405fa8dc7..0ba2676eb 100644 --- a/microservices/requestApi/db/model/request.js +++ b/microservices/requestApi/db/model/request.js @@ -417,8 +417,11 @@ model.getAll = function(query, limit, page, user, callback){ if ('_id' in query) { db.Request.findById(query['_id'], (err3, req) => { + console.log("_ID", typeof(req), typeof(req.topic), req); if ( (req !== null) && (typeof(req) !== "undefined") && (typeof(req.topic) !== "undefined") ){ getAllTopics(user, { id: req.topic }, queryRequests); + }else{ + callback(null, []); } }); } else { From 882e05b896631315082b52a1adf9fae5b5df0f98 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 09:59:25 -0800 Subject: [PATCH 31/75] debug --- microservices/requestApi/db/model/request.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microservices/requestApi/db/model/request.js b/microservices/requestApi/db/model/request.js index 0ba2676eb..ec2e19616 100644 --- a/microservices/requestApi/db/model/request.js +++ b/microservices/requestApi/db/model/request.js @@ -417,7 +417,7 @@ model.getAll = function(query, limit, page, user, callback){ if ('_id' in query) { db.Request.findById(query['_id'], (err3, req) => { - console.log("_ID", typeof(req), typeof(req.topic), req); + console.log("_ID", typeof(req), req); if ( (req !== null) && (typeof(req) !== "undefined") && (typeof(req.topic) !== "undefined") ){ getAllTopics(user, { id: req.topic }, queryRequests); }else{ From f3155642df6c2a5b1396910b8741e4626d7ba1f1 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 10:58:53 -0800 Subject: [PATCH 32/75] test fixes --- microservices/requestApi/db/model/request.js | 1 - microservices/requestApi/routes/routes/requests.js | 2 ++ microservices/requestApi/test/v1/requests.js | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/microservices/requestApi/db/model/request.js b/microservices/requestApi/db/model/request.js index ec2e19616..63db5be34 100644 --- a/microservices/requestApi/db/model/request.js +++ b/microservices/requestApi/db/model/request.js @@ -417,7 +417,6 @@ model.getAll = function(query, limit, page, user, callback){ if ('_id' in query) { db.Request.findById(query['_id'], (err3, req) => { - console.log("_ID", typeof(req), req); if ( (req !== null) && (typeof(req) !== "undefined") && (typeof(req.topic) !== "undefined") ){ getAllTopics(user, { id: req.topic }, queryRequests); }else{ diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index b5516ac3f..b4878dbf4 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -402,6 +402,8 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ var logger = require('npmlog'); var requestId = mongoose.Types.ObjectId(req.params.requestId); + console.log("Submitting", req.params.requestId, requestId); + // Lookup project from user groups var project = projectConfig.deriveProjectFromUser(req.user); diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index 234b4db2a..23865f73a 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -326,10 +326,10 @@ describe("Requests", function() { .set("Authorization", "Bearer " + jwt) .send({}) .end(function (err, res) { - console.log("it should fail to save a request", incorrectId, res.body); res.should.have.status(400); res.body.should.be.a('object'); res.body.should.have.property('error'); + done(); }); }); @@ -393,6 +393,7 @@ describe("Requests", function() { res.should.have.status(400); res.body.should.be.a('object'); res.body.should.have.property('error'); + done(); }); }); }); From 60cf205279fa338a3d91da7d1280ad338a7ba34f Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 11:15:24 -0800 Subject: [PATCH 33/75] fixed tests --- microservices/requestApi/test/v1/requests.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index 23865f73a..b32058ef9 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -517,11 +517,10 @@ describe("Requests", function() { it('it should fail to submit an invalid request', function (done) { chai.request(server) - .put('/v1/submit/1') + .put('/v1/submit/' + incorrectId) .set("Authorization", "Bearer " + jwt) .send({}) .end(function (err, res) { - console.log("IT SHOULD FAIL TO SUBMIT AN INVALID REQUEST", res.body); res.should.have.status(400); res.body.should.be.a('object'); res.body.should.have.property('error'); From c0bea86d407cb490bce1abf7fe559918e6639efb Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 11:20:57 -0800 Subject: [PATCH 34/75] caught the case when an invalid object id is passed --- .../requestApi/routes/routes/requests.js | 100 ++++++++++++++++-- 1 file changed, 89 insertions(+), 11 deletions(-) diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index b4878dbf4..d2475d463 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -273,7 +273,14 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ includeFileStatus = req.query.include_file_status == "true"; } - var requestId = mongoose.Types.ObjectId(req.params.requestId); + var requestId = null; + try{ + requestId = mongoose.Types.ObjectId(req.params.requestId); + }catch(ex){ + res.status(400); + res.json({error: "Invalid Request ID" }); + return; + } db.Request.getAll({_id: requestId}, 1, 1, req.user, function(findErr, findRes){ if (findErr || !findRes || findRes.length === 0){ @@ -302,14 +309,21 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ res.json(findRes) } - }); + });4 }); //save a request router.put("/save/:requestId", function(req, res, next){ - var requestId = mongoose.Types.ObjectId(req.params.requestId); + var requestId = null; + try{ + requestId = mongoose.Types.ObjectId(req.params.requestId); + }catch(ex){ + res.status(400); + res.json({error: "Invalid Request ID" }); + return; + } var config = require('config'); var logger = require('npmlog'); @@ -400,7 +414,15 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ //submit a request router.put('/submit/:requestId', function(req, res, next){ var logger = require('npmlog'); - var requestId = mongoose.Types.ObjectId(req.params.requestId); + + var requestId = null; + try{ + requestId = mongoose.Types.ObjectId(req.params.requestId); + }catch(ex){ + res.status(400); + res.json({error: "Invalid Request ID" }); + return; + } console.log("Submitting", req.params.requestId, requestId); @@ -624,7 +646,15 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ }); router.put('/cancel/:requestId', function(req, res){ - var requestId = mongoose.Types.ObjectId(req.params.requestId); + + var requestId = null; + try{ + requestId = mongoose.Types.ObjectId(req.params.requestId); + }catch(ex){ + res.status(400); + res.json({error: "Invalid Request ID" }); + return; + } var logger = require('npmlog'); db.Request.getAll({_id: requestId}, 1, 1, req.user, function(reqErr, reqRes) { @@ -675,7 +705,15 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ }); router.put('/withdraw/:requestId', function(req, res){ - var requestId = mongoose.Types.ObjectId(req.params.requestId); + + var requestId = null; + try{ + requestId = mongoose.Types.ObjectId(req.params.requestId); + }catch(ex){ + res.status(400); + res.json({error: "Invalid Request ID" }); + return; + } var logger = require('npmlog'); @@ -729,7 +767,15 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ router.put('/approve/:requestId', function(req, res){ var config = require('config'); - var requestId = mongoose.Types.ObjectId(req.params.requestId); + + var requestId = null; + try{ + requestId = mongoose.Types.ObjectId(req.params.requestId); + }catch(ex){ + res.status(400); + res.json({error: "Invalid Request ID" }); + return; + } var logger = require('npmlog'); db.Request.getAll({_id: requestId}, 1, 1, req.user, function(reqErr, reqRes) { @@ -795,7 +841,15 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ router.put('/deny/:requestId', function(req, res){ var config = require('config'); - var requestId = mongoose.Types.ObjectId(req.params.requestId); + + var requestId = null; + try{ + requestId = mongoose.Types.ObjectId(req.params.requestId); + }catch(ex){ + res.status(400); + res.json({error: "Invalid Request ID" }); + return; + } var logger = require('npmlog'); if (config.has('allowDenyRequest') && !config.get('allowDenyRequest')){ @@ -854,7 +908,15 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ router.put('/requestRevisions/:requestId', function(req, res){ var config = require('config'); - var requestId = mongoose.Types.ObjectId(req.params.requestId); + + var requestId = null; + try{ + requestId = mongoose.Types.ObjectId(req.params.requestId); + }catch(ex){ + res.status(400); + res.json({error: "Invalid Request ID" }); + return; + } var logger = require('npmlog'); db.Request.getAll({_id: requestId}, 1, 1, req.user, function(reqErr, reqRes) { @@ -905,7 +967,15 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ router.put('/pickup/:requestId', function(req, res){ var config = require('config'); var logger = require('npmlog'); - var requestId = mongoose.Types.ObjectId(req.params.requestId); + + var requestId = null; + try{ + requestId = mongoose.Types.ObjectId(req.params.requestId); + }catch(ex){ + res.status(400); + res.json({error: "Invalid Request ID" }); + return; + } db.Request.getAll({_id: requestId}, 1, 1, req.user, function(reqErr, reqRes) { logger.verbose("pickup request", reqErr, reqRes); @@ -958,7 +1028,15 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ router.delete('/:requestId', function(req, res){ var config = require('config'); var logger = require('npmlog'); - var requestId = mongoose.Types.ObjectId(req.params.requestId); + + var requestId = null; + try{ + requestId = mongoose.Types.ObjectId(req.params.requestId); + }catch(ex){ + res.status(400); + res.json({error: "Invalid Request ID" }); + return; + } db.Request.getAll({_id: requestId}, 1, 1, req.user, function(reqErr, reqRes) { if (reqErr || !reqRes || reqRes.length <= 0){ From 0bf997a999c9d01e5f66c2e4d7d8dbb1c5a2c3e3 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 11:25:58 -0800 Subject: [PATCH 35/75] fixes --- microservices/requestApi/routes/routes/requests.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index d2475d463..04cb243e5 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -424,15 +424,17 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ return; } - console.log("Submitting", req.params.requestId, requestId); - // Lookup project from user groups var project = projectConfig.deriveProjectFromUser(req.user); db.Request.getAll({_id: requestId}, 1, 1, req.user, function (reqErr, reqRes) { if (reqErr || !reqRes || reqRes.length == 0) { res.status(400); - res.json({error: reqErr.message}); + if (reqErr){ + res.json({error: reqErr.message}); + }else{ + res.json({error: "No Results"}); + } return; } From abca432c049d94bf83565b9c370fbfab0c6cb34b Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 11:36:18 -0800 Subject: [PATCH 36/75] syntax error --- microservices/requestApi/routes/routes/requests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index 04cb243e5..e0488c795 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -309,7 +309,7 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ res.json(findRes) } - });4 + }); }); From 279b51dbd6d73c515276f71274c7c6ef4e8b65fa Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 12:48:14 -0800 Subject: [PATCH 37/75] more test coverage --- microservices/requestApi/test/v1/requests.js | 100 ++++++++++++++++++- 1 file changed, 97 insertions(+), 3 deletions(-) diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index b32058ef9..d264bdcf1 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -18,6 +18,7 @@ chai.use(chaiHttp); describe("Requests", function() { var activeRequestId = ''; var incorrectId = ''; + var validTopicId = ''; var fileId = 'test_' + Math.random().toString(36) + '.jpeg'; after(function(done){ db.Request.deleteMany({}, function(err){ @@ -203,6 +204,7 @@ describe("Requests", function() { res.body.should.have.property('result'); res.body.result.should.have.property('_id'); activeRequestId = res.body.result._id; + validTopicId = res.body.result.topic_id; done(); }); }); @@ -212,7 +214,7 @@ describe("Requests", function() { describe('/GET v1 & v1/requestId', function () { it('it should get requests', function (done) { chai.request(server) - .get('/v1?limit=1&page=1&name=testName') + .get('/v1?limit=1&page=1&name=testName&topic_id=' + validTopicId + '&type=export') .set("Authorization", "Bearer " + jwt) .end(function (err, res) { res.should.have.status(200); @@ -221,6 +223,18 @@ describe("Requests", function() { }); }); + it('it should fail with an invalid id', function (done) { + chai.request(server) + .get('/v1/1') + .set("Authorization", "Bearer " + jwt) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + it('it should get supervisor requests from internal', function (done) { chai.request(server) .get('/v1') @@ -314,7 +328,19 @@ describe("Requests", function() { if (incorrectId === activeRequestId){ incorrectId = activeRequestId.substring(0, activeRequestId.length-1)+"2"; } - console.log("D", activeRequestId, incorrectId); + done(); + }); + }); + + it('it should fail to save a with an invalid id', function (done) { + chai.request(server) + .put('/v1/save/1') + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); done(); }); }); @@ -338,7 +364,18 @@ describe("Requests", function() { .put('/v1/save/' + activeRequestId) .set("Authorization", "Bearer " + jwt) .send({ - files: [fileId] + files: [fileId], + supportingFiles: [fileId], + name: "testNameChanged", + tags: ["testChanged"], + purpose: "purposeChanged", + phoneNumber: "555-555-5554", + subPopulation: "sub-populationChanged", + variableDescriptions: "variable descriptions changed", + selectionCriteria: "selection criteria changed", + steps: "steps changed", + freq: "freq changed", + confidentiality: "none changed" }) .end(function (err, res) { res.should.have.status(200); @@ -385,6 +422,18 @@ describe("Requests", function() { }); }); + it('it should fail to submit a request with an invalid id', function (done) { + chai.request(server) + .put('/v1/submit/1') + .set("Authorization", "Bearer " + jwt) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + it('it should fail to save a request that is in wrong state', function (done) { chai.request(server) .put('/v1/save/' + activeRequestId) @@ -396,6 +445,51 @@ describe("Requests", function() { done(); }); }); + + it('it should get (submitted) requests by date', function (done) { + chai.request(server) + .get('/v1?start_date=2000-01-01-01-01-01&end_date=9999-12-31-23-59-59') + .set("Authorization", "Bearer " + jwt) + .end(function (err, res) { + res.should.have.status(200); + res.body.length.should.be.eql(1); + done(); + }); + }); + + it('it should fail to submit a request without files', function (done) { + chai.request(server) + .post('/v1/') + .set("Authorization", "Bearer " + jwt) + .send({ + name: "testNameX", + tags: ["test"], + purpose: "purpose", + phoneNumber: "555-555-5555", + subPopulation: "sub-population", + variableDescriptions: "variable descriptions", + selectionCriteria: "selection criteria", + steps: "steps", + freq: "freq", + confidentiality: "none" + }) + .end(function (err, res) { + + let intermId = res.body.result._id; + + chai.request(server) + .put('/v1/submit/' + intermId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err2, res) { + + res.should.have.status(403); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + }); }); describe('/PUT /v1/pickup/requestId', function() { From dc3a47453b48fe13869b72284522e8090b4331f4 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 12:56:30 -0800 Subject: [PATCH 38/75] debug --- microservices/requestApi/test/v1/requests.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index d264bdcf1..ecccb8205 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -214,9 +214,10 @@ describe("Requests", function() { describe('/GET v1 & v1/requestId', function () { it('it should get requests', function (done) { chai.request(server) - .get('/v1?limit=1&page=1&name=testName&topic_id=' + validTopicId + '&type=export') + .get('/v1?limit=1&page=1&name=testName&topic_id=' + validTopicId ) .set("Authorization", "Bearer " + jwt) .end(function (err, res) { + console.log('GET REQUESTS ', res.body); res.should.have.status(200); res.body.length.should.be.eql(1); done(); @@ -482,7 +483,7 @@ describe("Requests", function() { .set("Authorization", "Bearer " + jwt) .send({}) .end(function (err2, res) { - + console.log("EXPECTED FAIL", res.body); res.should.have.status(403); res.body.should.be.a('object'); res.body.should.have.property('error'); From 6b4e4a44f3bdaf185752c2f2079ca35b0c4ad7a4 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 13:05:46 -0800 Subject: [PATCH 39/75] debug --- microservices/requestApi/test/v1/requests.js | 25 +++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index ecccb8205..7af82bbad 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -214,7 +214,7 @@ describe("Requests", function() { describe('/GET v1 & v1/requestId', function () { it('it should get requests', function (done) { chai.request(server) - .get('/v1?limit=1&page=1&name=testName&topic_id=' + validTopicId ) + .get('/v1?limit=1&page=1&name=testName' ) .set("Authorization", "Bearer " + jwt) .end(function (err, res) { console.log('GET REQUESTS ', res.body); @@ -477,17 +477,24 @@ describe("Requests", function() { .end(function (err, res) { let intermId = res.body.result._id; - + chai.request(server) - .put('/v1/submit/' + intermId) + .put('/v1/save/' + activeRequestId) .set("Authorization", "Bearer " + jwt) .send({}) - .end(function (err2, res) { - console.log("EXPECTED FAIL", res.body); - res.should.have.status(403); - res.body.should.be.a('object'); - res.body.should.have.property('error'); - done(); + .end(function(e, r){ + + chai.request(server) + .put('/v1/submit/' + intermId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err2, res2) { + console.log("EXPECTED FAIL", res2.body); + res2.should.have.status(403); + res2.body.should.be.a('object'); + res2.body.should.have.property('error'); + done(); + }); }); }); }); From dea27a1d10b0b8e45390261256a97a4df68b238e Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 13:14:40 -0800 Subject: [PATCH 40/75] debug --- .travis.yml | 1 + microservices/requestApi/test/v1/requests.js | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 783d37e37..c194767f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -141,6 +141,7 @@ matrix: packages: - g++-4.8 - python3-pip + - python3.5 before_script: - |- wget -q ${HELM_URL}/${HELM_TGZ} diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index 7af82bbad..dc45ea4b3 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -204,7 +204,7 @@ describe("Requests", function() { res.body.should.have.property('result'); res.body.result.should.have.property('_id'); activeRequestId = res.body.result._id; - validTopicId = res.body.result.topic_id; + validTopicId = res.body.result.topic; done(); }); }); @@ -214,7 +214,7 @@ describe("Requests", function() { describe('/GET v1 & v1/requestId', function () { it('it should get requests', function (done) { chai.request(server) - .get('/v1?limit=1&page=1&name=testName' ) + .get('/v1?limit=1&page=1&name=testName&topic_id=' + validTopicId + '&type=export' ) .set("Authorization", "Bearer " + jwt) .end(function (err, res) { console.log('GET REQUESTS ', res.body); @@ -463,7 +463,7 @@ describe("Requests", function() { .post('/v1/') .set("Authorization", "Bearer " + jwt) .send({ - name: "testNameX", + name: "testNameX234", tags: ["test"], purpose: "purpose", phoneNumber: "555-555-5555", @@ -489,7 +489,7 @@ describe("Requests", function() { .set("Authorization", "Bearer " + jwt) .send({}) .end(function (err2, res2) { - console.log("EXPECTED FAIL", res2.body); + console.log("EXPECTED FAIL", r, res2.body); res2.should.have.status(403); res2.body.should.be.a('object'); res2.body.should.have.property('error'); From 39d8bd93a4a201cfda7626598e911a4ac8e08980 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 13:19:57 -0800 Subject: [PATCH 41/75] fix tests --- microservices/requestApi/test/v1/requests.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index dc45ea4b3..29d3df3f6 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -479,7 +479,7 @@ describe("Requests", function() { let intermId = res.body.result._id; chai.request(server) - .put('/v1/save/' + activeRequestId) + .put('/v1/save/' + intermId) .set("Authorization", "Bearer " + jwt) .send({}) .end(function(e, r){ @@ -489,7 +489,6 @@ describe("Requests", function() { .set("Authorization", "Bearer " + jwt) .send({}) .end(function (err2, res2) { - console.log("EXPECTED FAIL", r, res2.body); res2.should.have.status(403); res2.body.should.be.a('object'); res2.body.should.have.property('error'); From a1c657532590162903543f28f81e3965748b9116 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 15:01:26 -0800 Subject: [PATCH 42/75] update python for request api, added a lot more tests --- .travis.yml | 2 + microservices/requestApi/test/v1/requests.js | 554 ++++++++++++++++++- 2 files changed, 542 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index c194767f5..9dcfe49dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -193,6 +193,7 @@ matrix: export MINIO_SECRET_KEY="secretkey" ./minio server /tmp & - |- + alias python=python3.5 cd /home/travis/build/bcgov/OCWA/microservices/validateApi sudo pip3 install -U setuptools sudo pip3 install -r requirements.txt @@ -200,6 +201,7 @@ matrix: sudo pip3 install -e . python3 wsgi.py & - |- + alias python=python3.5 cd /home/travis/build/bcgov/OCWA/microservices/policyApi sudo pip3 install -U setuptools sudo pip3 install -r requirements.txt diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index 29d3df3f6..4ec20e855 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -19,6 +19,9 @@ describe("Requests", function() { var activeRequestId = ''; var incorrectId = ''; var validTopicId = ''; + var approvedRequestId = ''; + var deniedRequestId = ''; + var cancelledRequestId = ''; var fileId = 'test_' + Math.random().toString(36) + '.jpeg'; after(function(done){ db.Request.deleteMany({}, function(err){ @@ -205,6 +208,10 @@ describe("Requests", function() { res.body.result.should.have.property('_id'); activeRequestId = res.body.result._id; validTopicId = res.body.result.topic; + incorrectId = activeRequestId.substring(0, activeRequestId.length-1)+"1"; + if (incorrectId === activeRequestId){ + incorrectId = activeRequestId.substring(0, activeRequestId.length-1)+"2"; + } done(); }); }); @@ -236,6 +243,18 @@ describe("Requests", function() { }); }); + it('it should fail with an incorrect id', function (done) { + chai.request(server) + .get('/v1/' + incorrectId) + .set("Authorization", "Bearer " + jwt) + .end(function (err, res) { + res.should.have.status(500); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + it('it should get supervisor requests from internal', function (done) { chai.request(server) .get('/v1') @@ -286,6 +305,34 @@ describe("Requests", function() { describe('/DELETE /v1/requestId', function() { + it('it should fail to delete an invalid id', function (done) { + chai.request(server) + .delete('/v1/1') + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + it('it should fail to delete an incorrect id', function (done) { + chai.request(server) + .delete('/v1/' + incorrectId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(500); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + + it('it should delete a request', function (done) { chai.request(server) .delete('/v1/' + activeRequestId) @@ -325,10 +372,6 @@ describe("Requests", function() { res.body.should.have.property('result'); res.body.result.should.have.property('_id'); activeRequestId = res.body.result._id; - incorrectId = activeRequestId.substring(0, activeRequestId.length-1)+"1"; - if (incorrectId === activeRequestId){ - incorrectId = activeRequestId.substring(0, activeRequestId.length-1)+"2"; - } done(); }); }); @@ -376,7 +419,11 @@ describe("Requests", function() { selectionCriteria: "selection criteria changed", steps: "steps changed", freq: "freq changed", - confidentiality: "none changed" + confidentiality: "none changed", + branch: "master", + externalRepository: "http://github.com/bcgov/OCWA", + repository: "http://github.com/bcgov/OCWA", + codeDescription: "This repository" }) .end(function (err, res) { res.should.have.status(200); @@ -409,6 +456,19 @@ describe("Requests", function() { describe('/PUT /v1/submit/requestId', function() { + it('it should fail to submit an invalid request', function (done) { + chai.request(server) + .put('/v1/submit/' + incorrectId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + it('it should submit a request', function (done) { chai.request(server) .put('/v1/submit/' + activeRequestId) @@ -423,6 +483,32 @@ describe("Requests", function() { }); }); + it('it should fail to delete a request in a non WIP state', function (done) { + chai.request(server) + .delete('/v1/' + activeRequestId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(403); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + it('it should fail to submit an already submitted request', function (done) { + chai.request(server) + .put('/v1/submit/' + activeRequestId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + it('it should fail to submit a request with an invalid id', function (done) { chai.request(server) .put('/v1/submit/1') @@ -500,6 +586,33 @@ describe("Requests", function() { }); describe('/PUT /v1/pickup/requestId', function() { + + it('it should fail to pickup an invalid id', function (done) { + chai.request(server) + .put('/v1/pickup/1') + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + it('it should fail to pickup an incorrect id', function (done) { + chai.request(server) + .put('/v1/pickup/' + incorrectId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(500); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + it('it should pickup a request', function (done) { chai.request(server) .put('/v1/pickup/' + activeRequestId) @@ -527,6 +640,59 @@ describe("Requests", function() { res.should.have.status(200); res.body.should.be.a('object'); res.body.should.have.property('message'); + approvedRequestId = activeRequestId; + done(); + }); + }); + + it('it should fail to pickup a request that is in an incorrect state', function (done) { + chai.request(server) + .put('/v1/pickup/' + activeRequestId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + it('it should fail to approve an invalid id', function (done) { + chai.request(server) + .put('/v1/approve/1') + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + it('it should fail to approve an incorrect id', function (done) { + chai.request(server) + .put('/v1/approve/' + incorrectId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(500); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + it('it should fail to approve an request thats in a non review state', function (done) { + chai.request(server) + .put('/v1/approve/' + approvedRequestId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); done(); }); }); @@ -559,6 +725,32 @@ describe("Requests", function() { }); }); + it('it should fail to cancel an invalid id', function (done) { + chai.request(server) + .put('/v1/cancel/1') + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + it('it should fail to cancel an incorrect id', function (done) { + chai.request(server) + .put('/v1/cancel/' + incorrectId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(500); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + it('it should cancel a request', function (done) { chai.request(server) .put('/v1/cancel/' + activeRequestId) @@ -568,6 +760,20 @@ describe("Requests", function() { res.should.have.status(200); res.body.should.be.a('object'); res.body.should.have.property('message'); + cancelledRequestId = activeRequestId; + done(); + }); + }); + + it('it should fail to cancel an already cancelled request', function (done) { + chai.request(server) + .put('/v1/cancel/' + incorrectId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); done(); }); }); @@ -615,10 +821,81 @@ describe("Requests", function() { setTimeout(done, 2000); }); }); - - it('it should fail to submit an invalid request', function (done) { + + it('it should submit a request', function (done) { chai.request(server) - .put('/v1/submit/' + incorrectId) + .put('/v1/submit/' + activeRequestId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + expect(res.body.error).to.equal(undefined); + res.should.have.status(200); + res.body.should.be.a('object'); + res.body.should.have.property('message'); + done(); + }); + }); + + it('it should pickup a request', function (done) { + chai.request(server) + .put('/v1/pickup/' + activeRequestId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + expect(res.body.error).to.equal(undefined); + res.should.have.status(200); + res.body.should.be.a('object'); + res.body.should.have.property('message'); + done(); + }); + }); + + it('it should fail to deny an invalid id', function (done) { + chai.request(server) + .put('/v1/deny/1') + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + it('it should fail to deny an incorrect id', function (done) { + chai.request(server) + .put('/v1/deny/' + incorrectId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(500); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + it('it should deny a request', function (done) { + chai.request(server) + .put('/v1/deny/' + activeRequestId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + expect(res.body.error).to.equal(undefined); + res.should.have.status(200); + res.body.should.be.a('object'); + res.body.should.have.property('message'); + res.body.should.have.property('result'); + deniedRequestId = activeRequestId; + + done(); + }); + }); + + it('it should fail to deny an already denied request', function (done) { + chai.request(server) + .put('/v1/deny/' + activeRequestId) .set("Authorization", "Bearer " + jwt) .send({}) .end(function (err, res) { @@ -629,6 +906,103 @@ describe("Requests", function() { }); }); + it('it should fail to cancel an already denied request', function (done) { + chai.request(server) + .put('/v1/cancel/' + incorrectId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + }); + + describe('/PUT /v1/withdraw/requestId', function() { + it('it should create a request', function (done) { + chai.request(server) + .post('/v1/') + .set("Authorization", "Bearer " + jwt) + .send({ + name: "testName7", + tags: ["test"], + purpose: "purpose", + phoneNumber: "555-555-5555", + subPopulation: "sub-population", + variableDescriptions: "variable descriptions", + selectionCriteria: "selection criteria", + steps: "steps", + freq: "freq", + confidentiality: "none" + }) + .end(function (err, res) { + res.should.have.status(200); + res.body.should.be.a('object'); + res.body.should.have.property('message'); + res.body.should.have.property('result'); + res.body.result.should.have.property('_id'); + activeRequestId = res.body.result._id; + done(); + }); + }); + + it('it should fail to withdraw an incorrect id', function (done) { + chai.request(server) + .put('/v1/withdraw/' + incorrectId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(500); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + it('it should fail to withdraw a request with an invalid id', function (done) { + chai.request(server) + .put('/v1/withdraw/1') + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + it('it should fail to withdraw a request that hasn\'t been submitted', function (done) { + chai.request(server) + .put('/v1/withdraw/' + activeRequestId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + it('it should save a request', function (done) { + chai.request(server) + .put('/v1/save/' + activeRequestId) + .set("Authorization", "Bearer " + jwt) + .send({ + files: [fileId] + }) + .end(function (err, res) { + res.should.have.status(200); + res.body.should.be.a('object'); + res.body.should.have.property('message'); + setTimeout(done, 2000); + }); + }); + it('it should submit a request', function (done) { chai.request(server) .put('/v1/submit/' + activeRequestId) @@ -643,9 +1017,23 @@ describe("Requests", function() { }); }); - it('it should fail to submit an already submitted request', function (done) { + it('it should withdraw a submitted request', function (done) { chai.request(server) - .put('/v1/submit/' + activeRequestId) + .put('/v1/withdraw/' + activeRequestId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(200); + res.body.should.be.a('object'); + res.body.should.have.property('message'); + done(); + }); + }); + + + it('it should fail to withdraw an approved request', function (done) { + chai.request(server) + .put('/v1/withdraw/' + approvedRequestId) .set("Authorization", "Bearer " + jwt) .send({}) .end(function (err, res) { @@ -656,6 +1044,106 @@ describe("Requests", function() { }); }); + it('it should fail to withdraw a denied request', function (done) { + chai.request(server) + .put('/v1/withdraw/' + deniedRequestId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + it('it should fail to withdraw a cancelled request', function (done) { + chai.request(server) + .put('/v1/withdraw/' + cancelledRequestId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + + it('it should fail to delete a request that has ever been submitted', function (done) { + chai.request(server) + .delete('/v1/' + activeRequestId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(403); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + }); + + describe('/PUT /v1/requestRevisions/requestId', function() { + it('it should create a request', function (done) { + chai.request(server) + .post('/v1/') + .set("Authorization", "Bearer " + jwt) + .send({ + name: "testName8", + tags: ["test"], + purpose: "purpose", + phoneNumber: "555-555-5555", + subPopulation: "sub-population", + variableDescriptions: "variable descriptions", + selectionCriteria: "selection criteria", + steps: "steps", + freq: "freq", + confidentiality: "none" + }) + .end(function (err, res) { + res.should.have.status(200); + res.body.should.be.a('object'); + res.body.should.have.property('message'); + res.body.should.have.property('result'); + res.body.result.should.have.property('_id'); + activeRequestId = res.body.result._id; + done(); + }); + }); + + it('it should save a request', function (done) { + chai.request(server) + .put('/v1/save/' + activeRequestId) + .set("Authorization", "Bearer " + jwt) + .send({ + files: [fileId] + }) + .end(function (err, res) { + res.should.have.status(200); + res.body.should.be.a('object'); + res.body.should.have.property('message'); + setTimeout(done, 2000); + }); + }); + + + it('it should submit a request', function (done) { + chai.request(server) + .put('/v1/submit/' + activeRequestId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + expect(res.body.error).to.equal(undefined); + res.should.have.status(200); + res.body.should.be.a('object'); + res.body.should.have.property('message'); + done(); + }); + }); + it('it should pickup a request', function (done) { chai.request(server) .put('/v1/pickup/' + activeRequestId) @@ -670,17 +1158,55 @@ describe("Requests", function() { }); }); - it('it should deny a request', function (done) { + it('it should fail to request revisions on an invalid id', function (done) { chai.request(server) - .put('/v1/deny/' + activeRequestId) + .put('/v1/requestRevisions/1') + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + it('it should fail to request revisions on an incorrect id', function (done) { + chai.request(server) + .put('/v1/requestRevisions/' + incorrectId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(500); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + + it('it should request revisions', function (done) { + chai.request(server) + .put('/v1/requestRevisions/' + activeRequestId) .set("Authorization", "Bearer " + jwt) .send({}) .end(function (err, res) { - expect(res.body.error).to.equal(undefined); res.should.have.status(200); res.body.should.be.a('object'); res.body.should.have.property('message'); - res.body.should.have.property('result'); + done(); + }); + }); + + it('it should fail to request revisions on an non review state', function (done) { + chai.request(server) + .put('/v1/requestRevisions/' + activeRequestId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); done(); }); }); From debd15d85ecc84a04c5e4890e5ab4b98b5759287 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 15:17:14 -0800 Subject: [PATCH 43/75] fixes for some of the edge cases --- .travis.yml | 4 +-- .../requestApi/routes/routes/requests.js | 30 ++++++++----------- microservices/requestApi/test/v1/requests.js | 1 - 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9dcfe49dc..a6e596b49 100644 --- a/.travis.yml +++ b/.travis.yml @@ -193,7 +193,7 @@ matrix: export MINIO_SECRET_KEY="secretkey" ./minio server /tmp & - |- - alias python=python3.5 + alias python3=python3.5 cd /home/travis/build/bcgov/OCWA/microservices/validateApi sudo pip3 install -U setuptools sudo pip3 install -r requirements.txt @@ -201,7 +201,7 @@ matrix: sudo pip3 install -e . python3 wsgi.py & - |- - alias python=python3.5 + alias python3=python3.5 cd /home/travis/build/bcgov/OCWA/microservices/policyApi sudo pip3 install -U setuptools sudo pip3 install -r requirements.txt diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index e0488c795..c6945743e 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -430,11 +430,7 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ db.Request.getAll({_id: requestId}, 1, 1, req.user, function (reqErr, reqRes) { if (reqErr || !reqRes || reqRes.length == 0) { res.status(400); - if (reqErr){ - res.json({error: reqErr.message}); - }else{ - res.json({error: "No Results"}); - } + res.json({error: "No Results"}); return; } @@ -660,9 +656,9 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ var logger = require('npmlog'); db.Request.getAll({_id: requestId}, 1, 1, req.user, function(reqErr, reqRes) { - if (reqErr || !reqRes){ + if (reqErr || !reqRes || reqRes.length === 0){ res.status(500); - res.json({error: reqErr.message}); + res.json({error: "No such request"}); return; } @@ -722,7 +718,7 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ db.Request.getAll({_id: requestId}, 1, 1, req.user, function(reqErr, reqRes) { if (reqErr || !reqRes || reqRes.length === 0){ res.status(500); - res.json({error: reqErr.message}); + res.json({error: "No such request"}); return; } @@ -781,9 +777,9 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ var logger = require('npmlog'); db.Request.getAll({_id: requestId}, 1, 1, req.user, function(reqErr, reqRes) { - if (reqErr || !reqRes){ + if (reqErr || !reqRes || reqRes.length === 0){ res.status(500); - res.json({error: reqErr.message}); + res.json({error: "No such request"}); return; } @@ -861,9 +857,9 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ } db.Request.getAll({_id: requestId}, 1, 1, req.user, function(reqErr, reqRes) { - if (reqErr || !reqRes){ + if (reqErr || !reqRes || reqRes.length === 0){ res.status(500); - res.json({error: reqErr.message}); + res.json({error: "No such request"}); return; } @@ -922,9 +918,9 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ var logger = require('npmlog'); db.Request.getAll({_id: requestId}, 1, 1, req.user, function(reqErr, reqRes) { - if (reqErr || !reqRes){ + if (reqErr || !reqRes || reqRes.length === 0){ res.status(500); - res.json({error: reqErr.message}); + res.json({error: "No such request"}); return; } @@ -981,9 +977,9 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ db.Request.getAll({_id: requestId}, 1, 1, req.user, function(reqErr, reqRes) { logger.verbose("pickup request", reqErr, reqRes); - if (reqErr || !reqRes){ + if (reqErr || !reqRes || reqRes.length === 0){ res.status(500); - res.json({error: reqErr.message}); + res.json({error: "No such request"}); return; } @@ -1043,7 +1039,7 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ db.Request.getAll({_id: requestId}, 1, 1, req.user, function(reqErr, reqRes) { if (reqErr || !reqRes || reqRes.length <= 0){ res.status(500); - res.json({error: reqErr.message}); + res.json({error: "No such request"}); return; } diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index 4ec20e855..c8ffc9469 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -224,7 +224,6 @@ describe("Requests", function() { .get('/v1?limit=1&page=1&name=testName&topic_id=' + validTopicId + '&type=export' ) .set("Authorization", "Bearer " + jwt) .end(function (err, res) { - console.log('GET REQUESTS ', res.body); res.should.have.status(200); res.body.length.should.be.eql(1); done(); From eb93d49f1732fb0bff0247229a7794c78e9a28dc Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Mon, 3 Feb 2020 15:22:32 -0800 Subject: [PATCH 44/75] fix 2 broken tests --- microservices/requestApi/test/v1/requests.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index c8ffc9469..7d6918f05 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -766,7 +766,7 @@ describe("Requests", function() { it('it should fail to cancel an already cancelled request', function (done) { chai.request(server) - .put('/v1/cancel/' + incorrectId) + .put('/v1/cancel/' + activeRequestId) .set("Authorization", "Bearer " + jwt) .send({}) .end(function (err, res) { @@ -907,7 +907,7 @@ describe("Requests", function() { it('it should fail to cancel an already denied request', function (done) { chai.request(server) - .put('/v1/cancel/' + incorrectId) + .put('/v1/cancel/' + activeRequestId) .set("Authorization", "Bearer " + jwt) .send({}) .end(function (err, res) { From 1cbca2292cf1016402a5dea7217b5dde155f3f51 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Tue, 4 Feb 2020 11:06:33 -0800 Subject: [PATCH 45/75] more tests and using python 3.5 --- .travis.yml | 4 +- .../requestApi/routes/v2/routes/requests.js | 19 +- microservices/requestApi/test/v1/requests.js | 24 -- microservices/requestApi/test/v2/requests.js | 324 +++++++++++++++++- 4 files changed, 335 insertions(+), 36 deletions(-) diff --git a/.travis.yml b/.travis.yml index a6e596b49..a3a9cc531 100644 --- a/.travis.yml +++ b/.travis.yml @@ -199,7 +199,7 @@ matrix: sudo pip3 install -r requirements.txt cp config/default.json.template config/default.json sudo pip3 install -e . - python3 wsgi.py & + python3.5 wsgi.py & - |- alias python3=python3.5 cd /home/travis/build/bcgov/OCWA/microservices/policyApi @@ -207,7 +207,7 @@ matrix: sudo pip3 install -r requirements.txt cp config/default.json.template config/default.json sudo pip3 install -e . - python3 wsgi.py & + python3.5 wsgi.py & - |- cd /home/travis/build/bcgov/OCWA/microservices/requestApi NODE_ENV=test npm start & diff --git a/microservices/requestApi/routes/v2/routes/requests.js b/microservices/requestApi/routes/v2/routes/requests.js index 2cb8ec321..70de6a5c0 100644 --- a/microservices/requestApi/routes/v2/routes/requests.js +++ b/microservices/requestApi/routes/v2/routes/requests.js @@ -217,7 +217,14 @@ var getRouter = function(db){ //save a request router.put("/save/:requestId", function(req, res, next){ var mongoose = require('mongoose'); - var requestId = mongoose.Types.ObjectId(req.params.requestId); + var requestId = null; + try{ + requestId = mongoose.Types.ObjectId(req.params.requestId); + }catch(ex){ + res.status(400); + res.json({error: "Invalid Request ID" }); + return; + } var config = require('config'); var logger = require('npmlog'); @@ -379,7 +386,15 @@ var getRouter = function(db){ var mongoose = require('mongoose'); var config = require('config'); var logger = require('npmlog'); - var requestId = mongoose.Types.ObjectId(req.params.requestId); + + var requestId = null; + try{ + requestId = mongoose.Types.ObjectId(req.params.requestId); + }catch(ex){ + res.status(400); + res.json({error: "Invalid Request ID" }); + return; + } db.Request.getAll({_id: requestId}, 1, 1, req.user, function(reqErr, reqRes) { if (reqErr || !reqRes || reqRes.length <= 0){ diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index 7d6918f05..359d896db 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -23,30 +23,6 @@ describe("Requests", function() { var deniedRequestId = ''; var cancelledRequestId = ''; var fileId = 'test_' + Math.random().toString(36) + '.jpeg'; - after(function(done){ - db.Request.deleteMany({}, function(err){ - var minio = require('minio'); - var config = require('config'); - var storageConfig = config.get('storageApi'); - var Minio = require('minio'); - var minioClient = new Minio.Client({ - endPoint: storageConfig['uri'], - port: storageConfig['port'], - useSSL: storageConfig['useSSL'], - accessKey: storageConfig['key'], - secretKey: storageConfig['secret'] - }); - minioClient.removeObject(storageConfig.bucket, fileId, function(err) { - if (err) { - console.log('Unable to remove object', err); - done(); - return; - } - done(); - }) - }); - - }); before(function(done){ var minio = require('minio'); diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index 31dc5a260..fd9fa5100 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -8,6 +8,7 @@ var expect = chai.expect; var config = require('config'); var jwt = config.get('testJWT'); +var adminJwt = config.get('testAdminJWT'); var db = require('../../routes/v2/db/db'); @@ -17,6 +18,8 @@ chai.use(chaiHttp); describe("Requests", function() { var activeRequestId = ''; + var incorrectId = ''; + var v1Id = ''; var fileId = 'test_' + Math.random().toString(36) + '.jpeg'; after(function(done){ db.Request.deleteMany({}, function(err){ @@ -135,13 +138,13 @@ describe("Requests", function() { }); }); - it('it should get all records (max 100) (currently 0)', function (done) { + it('it should get all records (max 100) (currently 6)', function (done) { chai.request(server) .get('/v2/') .set("Authorization", "Bearer "+jwt) .end(function (err, res) { res.should.have.status(200); - res.body.length.should.be.eql(0); + res.body.length.should.be.eql(6); done(); }); }); @@ -190,6 +193,10 @@ describe("Requests", function() { res.body.should.have.property('result'); res.body.result.should.have.property('_id'); activeRequestId = res.body.result._id; + incorrectId = activeRequestId.substring(0, activeRequestId.length-1)+"1"; + if (incorrectId === activeRequestId){ + incorrectId = activeRequestId.substring(0, activeRequestId.length-1)+"2"; + } done(); }); }); @@ -199,7 +206,7 @@ describe("Requests", function() { describe('/GET v2 & v2/requestId', function () { it('it should get requests', function (done) { chai.request(server) - .get('/v2?limit=101&page=0&state=0&name=*') + .get('/v2?limit=101&page=0&state=0&name=*&id='+activeRequestId) .set("Authorization", "Bearer " + jwt) .end(function (err, res) { res.should.have.status(200); @@ -214,7 +221,7 @@ describe("Requests", function() { .set("Authorization", "Bearer " + config.get('testSupervisorInternalJWT')) .end(function (err, res) { res.should.have.status(200); - res.body.length.should.be.eql(1); + res.body.length.should.be.eql(7); done(); }); }); @@ -225,7 +232,7 @@ describe("Requests", function() { .set("Authorization", "Bearer " + config.get('testSupervisorExternalJWT')) .end(function (err, res) { res.should.have.status(200); - res.body.length.should.be.eql(1); + res.body.length.should.be.eql(7); done(); }); }); @@ -269,6 +276,34 @@ describe("Requests", function() { done(); }); }); + + it('it should fail to delete an incorrect id', function (done) { + chai.request(server) + .delete('/v2/' + incorrectId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(500); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + + + it('it should fail to delete an invalid id', function (done) { + chai.request(server) + .delete('/v2/1') + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); }); describe('/PUT /v2/save/requestId', function() { @@ -293,6 +328,33 @@ describe("Requests", function() { }); }); + it('it should fail to save a with an invalid id', function (done) { + chai.request(server) + .put('/v2/save/1') + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + + + it('it should fail to save a request', function (done) { + chai.request(server) + .put('/v2/save/' + incorrectId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(400); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); + it('it should save a request', function (done) { chai.request(server) .put('/v2/save/' + activeRequestId) @@ -327,6 +389,25 @@ describe("Requests", function() { done(); }); }); + + it('it should update a v1 request', function (done) { + chai.request(server) + .get('/v1?state=1') + .set("Authorization", "Bearer "+jwt) + .end(function (err, res) { + var intermId = res.body.result._id; + chai.request(server) + .put('/v2/save/' + intermId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(200); + res.body.should.be.a('object'); + res.body.should.have.property('message'); + done(); + }); + }); + }); }); describe('/PUT /v2/submit/requestId', function() { @@ -344,6 +425,19 @@ describe("Requests", function() { done(); }); }); + + it('it should fail to delete a request that is submitted', function (done) { + chai.request(server) + .delete('/v2/' + activeRequestId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(403); + res.body.should.be.a('object'); + res.body.should.have.property('error'); + done(); + }); + }); }); describe('/PUT /v2/pickup/requestId', function() { @@ -601,9 +695,223 @@ describe("Forms", function() { }); }); + it('it should fail to create a form without admin', function (done) { + chai.request(server) + .post('/v2/forms') + .set("Authorization", "Bearer "+jwt) + .end(function (err, res) { + res.should.have.status(403); + res.body.should.have.property('error'); + done(); + }); + }); - - }); + + it('it should fail to create a form with no information', function (done) { + chai.request(server) + .post('/v2/forms') + .set("Authorization", "Bearer "+adminJwt) + .send({}) + .end(function (err, res) { + res.should.have.status(500); + res.body.should.have.property('error'); + done(); + }); + }); + + it('it should create a form', function (done) { + chai.request(server) + .post('/v2/forms') + .set("Authorization", "Bearer "+adminJwt) + .send({ + "title": "testform", + "display": "form", + "type": "form", + "name": "testform", + "path": "testform", + "components": [{ + "input": true, + "tableView": true, + "inputType": "text", + "inputMask": "", + "label": "First Name", + "key": "firstName", + "placeholder": "", + "prefix": "", + "suffix": "", + "multiple": false, + "defaultValue": "", + "protected": false, + "unique": false, + "persistent": true, + "validate": { + "required": false, + "minLength": "", + "maxLength": "", + "pattern": "", + "custom": "", + "customPrivate": false + }, + "conditional": { + "show": "", + "when": null, + "eq": "" + }, + "type": "textfield", + "tags": [], + "lockKey": true, + "isNew": false + }, { + "input": true, + "tableView": true, + "inputType": "text", + "inputMask": "", + "label": "Last Name", + "key": "lastName", + "placeholder": "", + "prefix": "", + "suffix": "", + "multiple": false, + "defaultValue": "", + "protected": false, + "unique": false, + "persistent": true, + "validate": { + "required": false, + "minLength": "", + "maxLength": "", + "pattern": "", + "custom": "", + "customPrivate": false + }, + "conditional": { + "show": "", + "when": null, + "eq": "" + }, + "type": "textfield", + "tags": [], + "lockKey": true, + "isNew": false + }, { + "input": true, + "tableView": true, + "inputType": "email", + "label": "Email", + "key": "email", + "placeholder": "Enter your email address", + "prefix": "", + "suffix": "", + "defaultValue": "", + "protected": false, + "unique": false, + "persistent": true, + "kickbox": { + "enabled": false + }, + "type": "email", + "lockKey": true, + "isNew": false + }, { + "input": true, + "tableView": true, + "inputMask": "(999) 999-9999", + "label": "Phone Number", + "key": "phoneNumber", + "placeholder": "", + "prefix": "", + "suffix": "", + "multiple": false, + "protected": false, + "unique": false, + "persistent": true, + "defaultValue": "", + "validate": { + "required": false + }, + "type": "phoneNumber", + "conditional": { + "eq": "", + "when": null, + "show": "" + }, + "tags": [], + "lockKey": true, + "isNew": false + }, { + "input": true, + "label": "Submit", + "tableView": false, + "key": "submit", + "size": "md", + "leftIcon": "", + "rightIcon": "", + "block": false, + "action": "submit", + "disableOnInvalid": false, + "theme": "primary", + "type": "button" + }] + }) + .end(function (err, res) { + res.should.have.status(200); + res.body.should.have.property('_id'); + done(); + }); + }); + + it('it should fail to update a form with no admin', function (done) { + chai.request(server) + .put('/v2/forms/testform') + .set("Authorization", "Bearer "+jwt) + .send({ + "title": "testform2", + }) + .end(function (err, res) { + res.should.have.status(403); + res.body.should.have.property('error'); + done(); + }); + }); + + it('it should update a form', function (done) { + chai.request(server) + .put('/v2/forms/testform') + .set("Authorization", "Bearer "+adminJwt) + .send({ + "title": "testform2", + }) + .end(function (err, res) { + res.should.have.status(200); + res.body.should.have.property('_id'); + done(); + }); + }); + + it('it should fail to delete a form with no admin', function (done) { + chai.request(server) + .delete('/v2/forms/testform') + .set("Authorization", "Bearer "+jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(403); + res.body.should.have.property('error'); + done(); + }); + }); + + it('it should delete a form', function (done) { + chai.request(server) + .delete('/v2/forms/testform') + .set("Authorization", "Bearer "+adminJwt) + .send({}) + .end(function (err, res) { + res.should.have.status(200); + res.body.should.have.property('_id'); + done(); + }); + }); -}); \ No newline at end of file + }); +}); From c393c2755a1640885d5ba31c5a5a460b1e88ba68 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Tue, 4 Feb 2020 11:35:36 -0800 Subject: [PATCH 46/75] bug fixes and test tweaks --- .../requestApi/routes/v2/db/model/request.js | 6 +- microservices/requestApi/test/v1/requests.js | 24 ++++++++ microservices/requestApi/test/v2/requests.js | 55 ++++++++++++------- 3 files changed, 64 insertions(+), 21 deletions(-) diff --git a/microservices/requestApi/routes/v2/db/model/request.js b/microservices/requestApi/routes/v2/db/model/request.js index b653ead81..b96321acd 100644 --- a/microservices/requestApi/routes/v2/db/model/request.js +++ b/microservices/requestApi/routes/v2/db/model/request.js @@ -263,7 +263,11 @@ model.getAll = function(query, limit, page, user, callback){ if ('_id' in query) { db.Request.findById(query['_id'], (err, req) => { - getAllTopics(user, { id: req.topic }, queryRequests); + if ( (req !== null) && (typeof(req) !== "undefined") && (typeof(req.topic) !== "undefined") ){ + getAllTopics(user, { id: req.topic }, queryRequests); + }else{ + callback(null, []); + } }); } else { getAllTopics(user, {}, queryRequests); diff --git a/microservices/requestApi/test/v1/requests.js b/microservices/requestApi/test/v1/requests.js index 359d896db..7d6918f05 100644 --- a/microservices/requestApi/test/v1/requests.js +++ b/microservices/requestApi/test/v1/requests.js @@ -23,6 +23,30 @@ describe("Requests", function() { var deniedRequestId = ''; var cancelledRequestId = ''; var fileId = 'test_' + Math.random().toString(36) + '.jpeg'; + after(function(done){ + db.Request.deleteMany({}, function(err){ + var minio = require('minio'); + var config = require('config'); + var storageConfig = config.get('storageApi'); + var Minio = require('minio'); + var minioClient = new Minio.Client({ + endPoint: storageConfig['uri'], + port: storageConfig['port'], + useSSL: storageConfig['useSSL'], + accessKey: storageConfig['key'], + secretKey: storageConfig['secret'] + }); + minioClient.removeObject(storageConfig.bucket, fileId, function(err) { + if (err) { + console.log('Unable to remove object', err); + done(); + return; + } + done(); + }) + }); + + }); before(function(done){ var minio = require('minio'); diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index fd9fa5100..3251c98d4 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -144,7 +144,7 @@ describe("Requests", function() { .set("Authorization", "Bearer "+jwt) .end(function (err, res) { res.should.have.status(200); - res.body.length.should.be.eql(6); + res.body.length.should.be.eql(0); done(); }); }); @@ -221,7 +221,7 @@ describe("Requests", function() { .set("Authorization", "Bearer " + config.get('testSupervisorInternalJWT')) .end(function (err, res) { res.should.have.status(200); - res.body.length.should.be.eql(7); + res.body.length.should.be.eql(1); done(); }); }); @@ -232,7 +232,7 @@ describe("Requests", function() { .set("Authorization", "Bearer " + config.get('testSupervisorExternalJWT')) .end(function (err, res) { res.should.have.status(200); - res.body.length.should.be.eql(7); + res.body.length.should.be.eql(1); done(); }); }); @@ -391,22 +391,37 @@ describe("Requests", function() { }); it('it should update a v1 request', function (done) { - chai.request(server) - .get('/v1?state=1') - .set("Authorization", "Bearer "+jwt) - .end(function (err, res) { - var intermId = res.body.result._id; - chai.request(server) - .put('/v2/save/' + intermId) - .set("Authorization", "Bearer " + jwt) - .send({}) - .end(function (err, res) { - res.should.have.status(200); - res.body.should.be.a('object'); - res.body.should.have.property('message'); - done(); + chai.request(server) + .post('/v1/') + .set("Authorization", "Bearer " + jwt) + .send({ + name: "testName", + tags: ["test"], + purpose: "purpose", + phoneNumber: "555-555-5555", + subPopulation: "sub-population", + variableDescriptions: "variable descriptions", + selectionCriteria: "selection criteria", + steps: "steps", + freq: "freq", + confidentiality: "none" + }) + .end(function (err, res) { + + var intermId = res.body.result._id; + + chai.request(server) + .put('/v2/save/' + intermId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(200); + res.body.should.be.a('object'); + res.body.should.have.property('message'); + done(); + }); }); - }); + }); }); }); @@ -700,6 +715,7 @@ describe("Forms", function() { .post('/v2/forms') .set("Authorization", "Bearer "+jwt) .end(function (err, res) { + console.log("FORM ADMIN", res.status. res.body); res.should.have.status(403); res.body.should.have.property('error'); done(); @@ -713,6 +729,7 @@ describe("Forms", function() { .set("Authorization", "Bearer "+adminJwt) .send({}) .end(function (err, res) { + console.log("FORM ADMIN", res.status, res.body); res.should.have.status(500); res.body.should.have.property('error'); done(); @@ -911,7 +928,5 @@ describe("Forms", function() { done(); }); }); - - }); }); From 8c8a871396f8afaa274ef2ccd43543321adad249 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Tue, 4 Feb 2020 12:59:27 -0800 Subject: [PATCH 47/75] fix syntax --- microservices/requestApi/test/v2/requests.js | 1 - 1 file changed, 1 deletion(-) diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index 3251c98d4..a81492622 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -661,7 +661,6 @@ describe("Requests", function() { }); }); -}); describe("Forms", function() { describe('/GET v2/forms', function () { From 35012770ad38fd79024b7ae0b2adfce8143b0cf2 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Tue, 4 Feb 2020 13:23:36 -0800 Subject: [PATCH 48/75] debug --- microservices/requestApi/test/v2/requests.js | 1 + 1 file changed, 1 insertion(+) diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index a81492622..b2bd6f237 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -433,6 +433,7 @@ describe("Requests", function() { .set("Authorization", "Bearer " + jwt) .send({}) .end(function (err, res) { + console.log("SHOULD SUBMIT", activeRequestId); expect(res.body.error).to.equal(undefined); res.should.have.status(200); res.body.should.be.a('object'); From 1ce55401cf13b8eeede5b7e42147b94cdd1c5be4 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Tue, 4 Feb 2020 14:01:15 -0800 Subject: [PATCH 49/75] debug --- microservices/requestApi/routes/routes/requests.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index c6945743e..4ee7cf4c7 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -427,8 +427,11 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ // Lookup project from user groups var project = projectConfig.deriveProjectFromUser(req.user); + console.log("SUBMISSION DB", db); + db.Request.getAll({_id: requestId}, 1, 1, req.user, function (reqErr, reqRes) { if (reqErr || !reqRes || reqRes.length == 0) { + console.log("SUBMISSION ERROR", reqErr, resRes); res.status(400); res.json({error: "No Results"}); return; From 76ea8531aa92359c95ff957dcb6e7a12c482ffac Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Tue, 4 Feb 2020 14:12:58 -0800 Subject: [PATCH 50/75] added version to models for debugging --- microservices/requestApi/db/model/request.js | 2 ++ microservices/requestApi/routes/routes/requests.js | 2 +- microservices/requestApi/routes/v2/db/model/request.js | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/microservices/requestApi/db/model/request.js b/microservices/requestApi/db/model/request.js index 63db5be34..395885337 100644 --- a/microservices/requestApi/db/model/request.js +++ b/microservices/requestApi/db/model/request.js @@ -428,4 +428,6 @@ model.getAll = function(query, limit, page, user, callback){ } }; +model.VERSION = 1; + module.exports = model; diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index 4ee7cf4c7..d8b74dd7f 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -427,7 +427,7 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ // Lookup project from user groups var project = projectConfig.deriveProjectFromUser(req.user); - console.log("SUBMISSION DB", db); + console.log("SUBMISSION DB v", db.Request.VERSION); db.Request.getAll({_id: requestId}, 1, 1, req.user, function (reqErr, reqRes) { if (reqErr || !reqRes || reqRes.length == 0) { diff --git a/microservices/requestApi/routes/v2/db/model/request.js b/microservices/requestApi/routes/v2/db/model/request.js index b96321acd..c2a229f35 100644 --- a/microservices/requestApi/routes/v2/db/model/request.js +++ b/microservices/requestApi/routes/v2/db/model/request.js @@ -275,4 +275,6 @@ model.getAll = function(query, limit, page, user, callback){ }; +model.VERSION = 2; + module.exports = model; From 13885b84ff5e82b343cfa27f69e498d9294b9314 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Tue, 4 Feb 2020 14:29:55 -0800 Subject: [PATCH 51/75] debug --- microservices/requestApi/routes/routes/requests.js | 2 -- microservices/requestApi/routes/v2/db/model/request.js | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index d8b74dd7f..ec689d532 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -427,8 +427,6 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ // Lookup project from user groups var project = projectConfig.deriveProjectFromUser(req.user); - console.log("SUBMISSION DB v", db.Request.VERSION); - db.Request.getAll({_id: requestId}, 1, 1, req.user, function (reqErr, reqRes) { if (reqErr || !reqRes || reqRes.length == 0) { console.log("SUBMISSION ERROR", reqErr, resRes); diff --git a/microservices/requestApi/routes/v2/db/model/request.js b/microservices/requestApi/routes/v2/db/model/request.js index c2a229f35..2ec89eff3 100644 --- a/microservices/requestApi/routes/v2/db/model/request.js +++ b/microservices/requestApi/routes/v2/db/model/request.js @@ -262,7 +262,8 @@ model.getAll = function(query, limit, page, user, callback){ if ('_id' in query) { - db.Request.findById(query['_id'], (err, req) => { + db.Request.findById(query['_id'], (err3, req) => { + console.log("ID Query?", err3, req); if ( (req !== null) && (typeof(req) !== "undefined") && (typeof(req.topic) !== "undefined") ){ getAllTopics(user, { id: req.topic }, queryRequests); }else{ From 22cbc92b8079d34f4fbff8797db538995b498dfe Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Tue, 4 Feb 2020 14:36:29 -0800 Subject: [PATCH 52/75] debug --- microservices/requestApi/routes/v2/db/model/request.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microservices/requestApi/routes/v2/db/model/request.js b/microservices/requestApi/routes/v2/db/model/request.js index 2ec89eff3..9661e3ae9 100644 --- a/microservices/requestApi/routes/v2/db/model/request.js +++ b/microservices/requestApi/routes/v2/db/model/request.js @@ -263,7 +263,7 @@ model.getAll = function(query, limit, page, user, callback){ if ('_id' in query) { db.Request.findById(query['_id'], (err3, req) => { - console.log("ID Query?", err3, req); + console.log("ID Query?", query['_id'], err3, req); if ( (req !== null) && (typeof(req) !== "undefined") && (typeof(req.topic) !== "undefined") ){ getAllTopics(user, { id: req.topic }, queryRequests); }else{ From b795ec3c4c30acc7e2128292fd9c9cfb6dc59a4c Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Tue, 4 Feb 2020 14:43:14 -0800 Subject: [PATCH 53/75] debug --- microservices/requestApi/test/v2/requests.js | 62 ++++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index b2bd6f237..1300c490e 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -390,39 +390,39 @@ describe("Requests", function() { }); }); - it('it should update a v1 request', function (done) { - chai.request(server) - .post('/v1/') - .set("Authorization", "Bearer " + jwt) - .send({ - name: "testName", - tags: ["test"], - purpose: "purpose", - phoneNumber: "555-555-5555", - subPopulation: "sub-population", - variableDescriptions: "variable descriptions", - selectionCriteria: "selection criteria", - steps: "steps", - freq: "freq", - confidentiality: "none" - }) - .end(function (err, res) { + // it('it should update a v1 request', function (done) { + // chai.request(server) + // .post('/v1/') + // .set("Authorization", "Bearer " + jwt) + // .send({ + // name: "testName", + // tags: ["test"], + // purpose: "purpose", + // phoneNumber: "555-555-5555", + // subPopulation: "sub-population", + // variableDescriptions: "variable descriptions", + // selectionCriteria: "selection criteria", + // steps: "steps", + // freq: "freq", + // confidentiality: "none" + // }) + // .end(function (err, res) { - var intermId = res.body.result._id; + // var intermId = res.body.result._id; - chai.request(server) - .put('/v2/save/' + intermId) - .set("Authorization", "Bearer " + jwt) - .send({}) - .end(function (err, res) { - res.should.have.status(200); - res.body.should.be.a('object'); - res.body.should.have.property('message'); - done(); - }); - }); - }); - }); + // chai.request(server) + // .put('/v2/save/' + intermId) + // .set("Authorization", "Bearer " + jwt) + // .send({}) + // .end(function (err, res) { + // res.should.have.status(200); + // res.body.should.be.a('object'); + // res.body.should.have.property('message'); + // done(); + // }); + // }); + // }); + // }); }); describe('/PUT /v2/submit/requestId', function() { From 722d8f7ca50e7bb7326abfb88784842989c03dd3 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Tue, 4 Feb 2020 14:48:21 -0800 Subject: [PATCH 54/75] debug --- microservices/requestApi/test/v2/requests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index 1300c490e..05eb4d823 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -422,7 +422,7 @@ describe("Requests", function() { // }); // }); // }); - // }); + }); }); describe('/PUT /v2/submit/requestId', function() { From aea8ba222c8b355cff2dcbd319b9201cb15b11de Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Tue, 4 Feb 2020 14:57:06 -0800 Subject: [PATCH 55/75] test tweaks --- microservices/requestApi/test/v2/requests.js | 66 ++++++++++---------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index 05eb4d823..f2b59784e 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -18,6 +18,7 @@ chai.use(chaiHttp); describe("Requests", function() { var activeRequestId = ''; + var firstId = ''; var incorrectId = ''; var v1Id = ''; var fileId = 'test_' + Math.random().toString(36) + '.jpeg'; @@ -193,6 +194,7 @@ describe("Requests", function() { res.body.should.have.property('result'); res.body.result.should.have.property('_id'); activeRequestId = res.body.result._id; + firstId = res.body.result._id; incorrectId = activeRequestId.substring(0, activeRequestId.length-1)+"1"; if (incorrectId === activeRequestId){ incorrectId = activeRequestId.substring(0, activeRequestId.length-1)+"2"; @@ -390,46 +392,45 @@ describe("Requests", function() { }); }); - // it('it should update a v1 request', function (done) { - // chai.request(server) - // .post('/v1/') - // .set("Authorization", "Bearer " + jwt) - // .send({ - // name: "testName", - // tags: ["test"], - // purpose: "purpose", - // phoneNumber: "555-555-5555", - // subPopulation: "sub-population", - // variableDescriptions: "variable descriptions", - // selectionCriteria: "selection criteria", - // steps: "steps", - // freq: "freq", - // confidentiality: "none" - // }) - // .end(function (err, res) { + it('it should update a v1 request', function (done) { + chai.request(server) + .post('/v1/') + .set("Authorization", "Bearer " + jwt) + .send({ + name: "testName", + tags: ["test"], + purpose: "purpose", + phoneNumber: "555-555-5555", + subPopulation: "sub-population", + variableDescriptions: "variable descriptions", + selectionCriteria: "selection criteria", + steps: "steps", + freq: "freq", + confidentiality: "none" + }) + .end(function (err, res) { - // var intermId = res.body.result._id; + var intermId = res.body.result._id; - // chai.request(server) - // .put('/v2/save/' + intermId) - // .set("Authorization", "Bearer " + jwt) - // .send({}) - // .end(function (err, res) { - // res.should.have.status(200); - // res.body.should.be.a('object'); - // res.body.should.have.property('message'); - // done(); - // }); - // }); - // }); + chai.request(server) + .put('/v2/save/' + intermId) + .set("Authorization", "Bearer " + jwt) + .send({}) + .end(function (err, res) { + res.should.have.status(200); + res.body.should.be.a('object'); + res.body.should.have.property('message'); + done(); + }); + }); + }); }); - }); describe('/PUT /v2/submit/requestId', function() { it('it should submit a request', function (done) { chai.request(server) - .put('/v2/submit/' + activeRequestId) + .put('/v2/submit/' + firstId) .set("Authorization", "Bearer " + jwt) .send({}) .end(function (err, res) { @@ -661,6 +662,7 @@ describe("Requests", function() { }); }); }); +}); describe("Forms", function() { From 1f93ccd4d0cb982fe45edff1d8011e3e4271c8a6 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Tue, 4 Feb 2020 15:02:18 -0800 Subject: [PATCH 56/75] tweaks --- microservices/requestApi/routes/routes/requests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index ec689d532..702e4c46c 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -429,7 +429,7 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ db.Request.getAll({_id: requestId}, 1, 1, req.user, function (reqErr, reqRes) { if (reqErr || !reqRes || reqRes.length == 0) { - console.log("SUBMISSION ERROR", reqErr, resRes); + console.log("SUBMISSION ERROR", reqErr, reqRes); res.status(400); res.json({error: "No Results"}); return; From b0a7005bbaa67d86f1b0f7e382d362a1004b7121 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Tue, 4 Feb 2020 15:11:28 -0800 Subject: [PATCH 57/75] debug --- microservices/requestApi/routes/routes/requests.js | 2 ++ microservices/requestApi/test/v2/requests.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index 702e4c46c..ea0607033 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -424,6 +424,8 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ return; } + console.log("TRYING TO SUBMIT", requestId); + // Lookup project from user groups var project = projectConfig.deriveProjectFromUser(req.user); diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index f2b59784e..9fa6b7b9f 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -434,7 +434,7 @@ describe("Requests", function() { .set("Authorization", "Bearer " + jwt) .send({}) .end(function (err, res) { - console.log("SHOULD SUBMIT", activeRequestId); + console.log("SHOULD SUBMIT", firstId, activeRequestId); expect(res.body.error).to.equal(undefined); res.should.have.status(200); res.body.should.be.a('object'); From 539da66f25c8a4064c18ab1d71d907b62d05b294 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Tue, 4 Feb 2020 15:20:49 -0800 Subject: [PATCH 58/75] insanity --- microservices/requestApi/test/v2/requests.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index 9fa6b7b9f..cfe7bc160 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -20,7 +20,6 @@ describe("Requests", function() { var activeRequestId = ''; var firstId = ''; var incorrectId = ''; - var v1Id = ''; var fileId = 'test_' + Math.random().toString(36) + '.jpeg'; after(function(done){ db.Request.deleteMany({}, function(err){ @@ -430,7 +429,7 @@ describe("Requests", function() { it('it should submit a request', function (done) { chai.request(server) - .put('/v2/submit/' + firstId) + .put('/v2/submit/' + activeRequestId) .set("Authorization", "Bearer " + jwt) .send({}) .end(function (err, res) { From d24eba4fe7ef8bc93a9c01a6371eb3fabebb170f Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Tue, 4 Feb 2020 15:27:03 -0800 Subject: [PATCH 59/75] debug --- .../requestApi/routes/v2/routes/requests.js | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/microservices/requestApi/routes/v2/routes/requests.js b/microservices/requestApi/routes/v2/routes/requests.js index 70de6a5c0..1d75a6f28 100644 --- a/microservices/requestApi/routes/v2/routes/requests.js +++ b/microservices/requestApi/routes/v2/routes/requests.js @@ -44,19 +44,23 @@ var getRouter = function(db){ }); router.post(FORMS_SUB_ROUTE, function(req, res, next){ - let adminGroup = config.get("adminGroup"); - if (req.user.groups.indexOf(adminGroup) === -1){ - res.status(403); - res.json({error: "Forbidden"}); - } - formioClient.postForm(req.body, function(formErr, formRes){ - if (formErr){ - res.status(500); - res.json({error: formErr}); - return; + try{ + let adminGroup = config.get("adminGroup"); + if (req.user.groups.indexOf(adminGroup) === -1){ + res.status(403); + res.json({error: "Forbidden"}); } - res.json(JSON.parse(formRes)); - }); + formioClient.postForm(req.body, function(formErr, formRes){ + if (formErr){ + res.status(500); + res.json({error: formErr}); + return; + } + res.json(JSON.parse(formRes)); + }); + }catch(ex){ + console.log("EXCEPTION WHILE POSTING FORM", ex); + } }); router = routes.buildStatic(db, router); From 327aa63dce990cd8ea03c096ef131418d87c6947 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Tue, 4 Feb 2020 15:31:41 -0800 Subject: [PATCH 60/75] fixes to some form sub routes --- .../requestApi/routes/v2/routes/requests.js | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/microservices/requestApi/routes/v2/routes/requests.js b/microservices/requestApi/routes/v2/routes/requests.js index 1d75a6f28..56c2accf0 100644 --- a/microservices/requestApi/routes/v2/routes/requests.js +++ b/microservices/requestApi/routes/v2/routes/requests.js @@ -44,23 +44,20 @@ var getRouter = function(db){ }); router.post(FORMS_SUB_ROUTE, function(req, res, next){ - try{ - let adminGroup = config.get("adminGroup"); - if (req.user.groups.indexOf(adminGroup) === -1){ - res.status(403); - res.json({error: "Forbidden"}); - } - formioClient.postForm(req.body, function(formErr, formRes){ - if (formErr){ - res.status(500); - res.json({error: formErr}); - return; - } - res.json(JSON.parse(formRes)); - }); - }catch(ex){ - console.log("EXCEPTION WHILE POSTING FORM", ex); + var config = require('config'); + let adminGroup = config.get("adminGroup"); + if (req.user.groups.indexOf(adminGroup) === -1){ + res.status(403); + res.json({error: "Forbidden"}); } + formioClient.postForm(req.body, function(formErr, formRes){ + if (formErr){ + res.status(500); + res.json({error: formErr}); + return; + } + res.json(JSON.parse(formRes)); + }); }); router = routes.buildStatic(db, router); @@ -482,6 +479,7 @@ var getRouter = function(db){ }); router.put(FORMS_SUB_ROUTE+'/:formName', function(req, res, next){ + var config = require('config'); let adminGroup = config.get("adminGroup"); if (req.user.groups.indexOf(adminGroup) === -1){ res.status(403); @@ -499,6 +497,7 @@ var getRouter = function(db){ }); router.delete('/formio/:formName', function(req, res, next){ + var config = require('config'); var adminGroup = config.get("adminGroup"); if (req.user.groups.indexOf(adminGroup) === -1){ From 40130e56c535e9419b8423f064f5ac76197a097e Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Wed, 5 Feb 2020 07:42:22 -0800 Subject: [PATCH 61/75] fix test error --- microservices/requestApi/test/v2/requests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index cfe7bc160..40e150933 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -716,7 +716,7 @@ describe("Forms", function() { .post('/v2/forms') .set("Authorization", "Bearer "+jwt) .end(function (err, res) { - console.log("FORM ADMIN", res.status. res.body); + console.log("FORM ADMIN", res.status, res.body); res.should.have.status(403); res.body.should.have.property('error'); done(); From b17e90f0cba4a1c66ceb78c2d0e4241305fbd3f6 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Wed, 5 Feb 2020 07:59:30 -0800 Subject: [PATCH 62/75] couple of tweaks --- .../requestApi/routes/v2/routes/requests.js | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/microservices/requestApi/routes/v2/routes/requests.js b/microservices/requestApi/routes/v2/routes/requests.js index 56c2accf0..6af189219 100644 --- a/microservices/requestApi/routes/v2/routes/requests.js +++ b/microservices/requestApi/routes/v2/routes/requests.js @@ -56,7 +56,13 @@ var getRouter = function(db){ res.json({error: formErr}); return; } - res.json(JSON.parse(formRes)); + + var r = formRes + try{ + r = JSON.parse(formRes); + }catch(ex){} + + res.json(r); }); }); @@ -492,7 +498,12 @@ var getRouter = function(db){ res.json({error: formErr}); return; } - res.json(JSON.parse(formRes)); + var r = formRes + try{ + r = JSON.parse(formRes); + }catch(ex){} + + res.json(r); }); }); @@ -511,7 +522,12 @@ var getRouter = function(db){ res.json({error: formErr}); return; } - res.json(JSON.parse(formRes)); + var r = formRes + try{ + r = JSON.parse(formRes); + }catch(ex){} + + res.json(r); }); }); From 484797129cedb0e70fb7dad228422905538b79a9 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Wed, 5 Feb 2020 08:15:37 -0800 Subject: [PATCH 63/75] fixed some bugs, changed the log level of some stuff and removed test debugging logs --- .../requestApi/clients/formio_client.js | 20 +++++++++---------- .../requestApi/routes/routes/requests.js | 3 --- .../requestApi/routes/v2/routes/requests.js | 18 +++++++++++++++-- microservices/requestApi/test/v2/requests.js | 2 -- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/microservices/requestApi/clients/formio_client.js b/microservices/requestApi/clients/formio_client.js index b2c0635c1..c9a4f973d 100644 --- a/microservices/requestApi/clients/formio_client.js +++ b/microservices/requestApi/clients/formio_client.js @@ -59,7 +59,7 @@ formio.auth = function(callback){ formio.getSubmissions = function(formName, callback) { this.auth(function(err, jwt){ if (err){ - logger.error("Error getting jwt", err); + logger.debug("Error getting jwt", err); } var url = config.get('formio.url') + "/"+formName+"/submission"; @@ -85,7 +85,7 @@ formio.getSubmission = function(formName, submissionId, callback) { this.auth(function(err, jwt){ if (err){ - logger.error("Error getting jwt", err); + logger.debug("Error getting jwt", err); } var url = config.get('formio.url') + "/"+formName+"/submission/"+submissionId; logger.verbose("formio get submission", url); @@ -106,7 +106,7 @@ formio.getSubmission = function(formName, submissionId, callback) { formio.postSubmission = function(formName, values, callback) { this.auth(function(err, jwt){ if (err){ - logger.error("Error getting jwt", err); + logger.debug("Error getting jwt", err); } var url = config.get('formio.url') + "/"+formName+"/submission"; @@ -139,7 +139,7 @@ formio.postSubmission = function(formName, values, callback) { formio.deleteSubmission = function(formName, submissionId, callback) { this.auth(function(err, jwt){ if (err){ - logger.error("Error getting jwt", err); + logger.debug("Error getting jwt", err); } var url = config.get('formio.url') + "/"+formName+"/submission/"+submissionId; @@ -156,7 +156,7 @@ formio.deleteSubmission = function(formName, submissionId, callback) { formio.putSubmission = function(formName, submissionId, values, callback) { this.auth(function(err, jwt){ if (err){ - logger.error("Error getting jwt", err); + logger.debug("Error getting jwt", err); } var url = config.get('formio.url') + "/"+formName+"/submission/"+submissionId; @@ -182,7 +182,7 @@ formio.getForms = function(callback) { } this.auth(function(err, jwt){ if (err){ - logger.error("Error getting jwt", err); + logger.debug("Error getting jwt", err); } var url = config.get('formio.url') + "/form"; @@ -208,7 +208,7 @@ formio.getForm = function(formName, callback) { } this.auth(function(err, jwt){ if (err){ - logger.error("Error getting jwt", err); + logger.debug("Error getting jwt", err); } var url = config.get('formio.url') + "/"+formName; @@ -229,7 +229,7 @@ formio.getForm = function(formName, callback) { formio.postForm = function(data, callback) { this.auth(function(err, jwt){ if (err){ - logger.error("Error getting jwt", err); + logger.debug("Error getting jwt", err); } var url = config.get('formio.url') + "/form"; @@ -246,7 +246,7 @@ formio.postForm = function(data, callback) { formio.putForm = function(formName, data, callback) { this.auth(function(err, jwt){ if (err){ - logger.error("Error getting jwt", err); + logger.debug("Error getting jwt", err); } var url = config.get('formio.url') + "/form/" + formName; @@ -263,7 +263,7 @@ formio.putForm = function(formName, data, callback) { formio.deleteForm = function(formName, callback) { this.auth(function(err, jwt){ if (err){ - logger.error("Error getting jwt", err); + logger.debug("Error getting jwt", err); } var url = config.get('formio.url') + "/" + formName; diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index ea0607033..c6945743e 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -424,14 +424,11 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ return; } - console.log("TRYING TO SUBMIT", requestId); - // Lookup project from user groups var project = projectConfig.deriveProjectFromUser(req.user); db.Request.getAll({_id: requestId}, 1, 1, req.user, function (reqErr, reqRes) { if (reqErr || !reqRes || reqRes.length == 0) { - console.log("SUBMISSION ERROR", reqErr, reqRes); res.status(400); res.json({error: "No Results"}); return; diff --git a/microservices/requestApi/routes/v2/routes/requests.js b/microservices/requestApi/routes/v2/routes/requests.js index 6af189219..5cd9930e4 100644 --- a/microservices/requestApi/routes/v2/routes/requests.js +++ b/microservices/requestApi/routes/v2/routes/requests.js @@ -39,7 +39,13 @@ var getRouter = function(db){ res.json({error: formErr}); return; } - res.json(JSON.parse(formRes)); + var r = formRes + try{ + r = JSON.parse(formRes); + }catch(ex){} + + res.status(r.status) + res.json(r); }); }); @@ -62,6 +68,7 @@ var getRouter = function(db){ r = JSON.parse(formRes); }catch(ex){} + res.status(r.status) res.json(r); }); }); @@ -480,7 +487,12 @@ var getRouter = function(db){ res.json({error: formErr}); return; } - res.json(JSON.parse(formRes)); + try{ + r = JSON.parse(formRes); + }catch(ex){} + + res.status(r.status) + res.json(r); }); }); @@ -503,6 +515,7 @@ var getRouter = function(db){ r = JSON.parse(formRes); }catch(ex){} + res.status(r.status) res.json(r); }); }); @@ -527,6 +540,7 @@ var getRouter = function(db){ r = JSON.parse(formRes); }catch(ex){} + res.status(r.status) res.json(r); }); }); diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index 40e150933..0e4216ec9 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -716,7 +716,6 @@ describe("Forms", function() { .post('/v2/forms') .set("Authorization", "Bearer "+jwt) .end(function (err, res) { - console.log("FORM ADMIN", res.status, res.body); res.should.have.status(403); res.body.should.have.property('error'); done(); @@ -730,7 +729,6 @@ describe("Forms", function() { .set("Authorization", "Bearer "+adminJwt) .send({}) .end(function (err, res) { - console.log("FORM ADMIN", res.status, res.body); res.should.have.status(500); res.body.should.have.property('error'); done(); From dd5db073b76ebcd7b071bfc520155361b5eba7f1 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Wed, 5 Feb 2020 08:24:07 -0800 Subject: [PATCH 64/75] fixing some more things --- microservices/requestApi/routes/v2/db/model/request.js | 1 - microservices/requestApi/routes/v2/routes/requests.js | 10 +++++++--- microservices/requestApi/test/v2/requests.js | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/microservices/requestApi/routes/v2/db/model/request.js b/microservices/requestApi/routes/v2/db/model/request.js index 9661e3ae9..b49d7937f 100644 --- a/microservices/requestApi/routes/v2/db/model/request.js +++ b/microservices/requestApi/routes/v2/db/model/request.js @@ -263,7 +263,6 @@ model.getAll = function(query, limit, page, user, callback){ if ('_id' in query) { db.Request.findById(query['_id'], (err3, req) => { - console.log("ID Query?", query['_id'], err3, req); if ( (req !== null) && (typeof(req) !== "undefined") && (typeof(req.topic) !== "undefined") ){ getAllTopics(user, { id: req.topic }, queryRequests); }else{ diff --git a/microservices/requestApi/routes/v2/routes/requests.js b/microservices/requestApi/routes/v2/routes/requests.js index 5cd9930e4..5d746f73c 100644 --- a/microservices/requestApi/routes/v2/routes/requests.js +++ b/microservices/requestApi/routes/v2/routes/requests.js @@ -44,7 +44,6 @@ var getRouter = function(db){ r = JSON.parse(formRes); }catch(ex){} - res.status(r.status) res.json(r); }); }); @@ -55,6 +54,7 @@ var getRouter = function(db){ if (req.user.groups.indexOf(adminGroup) === -1){ res.status(403); res.json({error: "Forbidden"}); + return; } formioClient.postForm(req.body, function(formErr, formRes){ if (formErr){ @@ -491,7 +491,6 @@ var getRouter = function(db){ r = JSON.parse(formRes); }catch(ex){} - res.status(r.status) res.json(r); }); }); @@ -502,6 +501,7 @@ var getRouter = function(db){ if (req.user.groups.indexOf(adminGroup) === -1){ res.status(403); res.json({error: "Forbidden"}); + return; } var formName = req.params.formName; formioClient.putForm(formName, req.body, function(formErr, formRes){ @@ -527,6 +527,7 @@ var getRouter = function(db){ if (req.user.groups.indexOf(adminGroup) === -1){ res.status(403); res.json({error: "Forbidden"}); + return; } var formName = req.params.formName; formioClient.putForm(formName, req.body, function(formErr, formRes){ @@ -540,7 +541,10 @@ var getRouter = function(db){ r = JSON.parse(formRes); }catch(ex){} - res.status(r.status) + try{ + res.status(r.status) + }catch(ex){} + res.json(r); }); }); diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index 0e4216ec9..abcd19881 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -870,6 +870,7 @@ describe("Forms", function() { }] }) .end(function (err, res) { + console.log("should create form", res.status, res.body); res.should.have.status(200); res.body.should.have.property('_id'); done(); From 0d4738fd2c2d303159aedfeeb07e79ffab8ccd4f Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Wed, 5 Feb 2020 08:46:09 -0800 Subject: [PATCH 65/75] tweaks --- microservices/requestApi/routes/v2/routes/requests.js | 7 +++++-- microservices/requestApi/test/v2/requests.js | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/microservices/requestApi/routes/v2/routes/requests.js b/microservices/requestApi/routes/v2/routes/requests.js index 5d746f73c..e7a06b1c0 100644 --- a/microservices/requestApi/routes/v2/routes/requests.js +++ b/microservices/requestApi/routes/v2/routes/requests.js @@ -68,7 +68,6 @@ var getRouter = function(db){ r = JSON.parse(formRes); }catch(ex){} - res.status(r.status) res.json(r); }); }); @@ -499,10 +498,12 @@ var getRouter = function(db){ var config = require('config'); let adminGroup = config.get("adminGroup"); if (req.user.groups.indexOf(adminGroup) === -1){ + console.log("FORMIO FORBIDDEN"); res.status(403); res.json({error: "Forbidden"}); return; } + console.log("FORMIO ALLOWED"); var formName = req.params.formName; formioClient.putForm(formName, req.body, function(formErr, formRes){ if (formErr){ @@ -525,10 +526,12 @@ var getRouter = function(db){ var adminGroup = config.get("adminGroup"); if (req.user.groups.indexOf(adminGroup) === -1){ + console.log("FORMIO FORBIDDEN"); res.status(403); res.json({error: "Forbidden"}); return; } + console.log("FORMIO ALLOWED"); var formName = req.params.formName; formioClient.putForm(formName, req.body, function(formErr, formRes){ if (formErr){ @@ -544,7 +547,7 @@ var getRouter = function(db){ try{ res.status(r.status) }catch(ex){} - + res.json(r); }); }); diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index abcd19881..86468182f 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -433,7 +433,6 @@ describe("Requests", function() { .set("Authorization", "Bearer " + jwt) .send({}) .end(function (err, res) { - console.log("SHOULD SUBMIT", firstId, activeRequestId); expect(res.body.error).to.equal(undefined); res.should.have.status(200); res.body.should.be.a('object'); From ce4876b27a4655e048292308a3b2d9053e02c4f3 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Wed, 5 Feb 2020 09:06:00 -0800 Subject: [PATCH 66/75] test tweaks --- .../requestApi/routes/v2/routes/requests.js | 6 +++++- microservices/requestApi/test/v2/requests.js | 15 +-------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/microservices/requestApi/routes/v2/routes/requests.js b/microservices/requestApi/routes/v2/routes/requests.js index e7a06b1c0..4c4a94b80 100644 --- a/microservices/requestApi/routes/v2/routes/requests.js +++ b/microservices/requestApi/routes/v2/routes/requests.js @@ -516,12 +516,16 @@ var getRouter = function(db){ r = JSON.parse(formRes); }catch(ex){} - res.status(r.status) + try{ + res.status(r.status) + }catch(ex){} + res.json(r); }); }); router.delete('/formio/:formName', function(req, res, next){ + console.log("IN DELETE FORM ROUTE"); var config = require('config'); var adminGroup = config.get("adminGroup"); diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index 86468182f..7c6b3a254 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -721,19 +721,6 @@ describe("Forms", function() { }); }); - - it('it should fail to create a form with no information', function (done) { - chai.request(server) - .post('/v2/forms') - .set("Authorization", "Bearer "+adminJwt) - .send({}) - .end(function (err, res) { - res.should.have.status(500); - res.body.should.have.property('error'); - done(); - }); - }); - it('it should create a form', function (done) { chai.request(server) .post('/v2/forms') @@ -869,7 +856,7 @@ describe("Forms", function() { }] }) .end(function (err, res) { - console.log("should create form", res.status, res.body); + console.log("SHOULD CREATE A FORM", res.status, res.body); res.should.have.status(200); res.body.should.have.property('_id'); done(); From 135098155ef2c3a08f7485d006a69c18c019a68b Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Wed, 5 Feb 2020 09:13:54 -0800 Subject: [PATCH 67/75] fixed a bug --- .../requestApi/routes/v2/routes/requests.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/microservices/requestApi/routes/v2/routes/requests.js b/microservices/requestApi/routes/v2/routes/requests.js index 4c4a94b80..7e0374087 100644 --- a/microservices/requestApi/routes/v2/routes/requests.js +++ b/microservices/requestApi/routes/v2/routes/requests.js @@ -498,12 +498,11 @@ var getRouter = function(db){ var config = require('config'); let adminGroup = config.get("adminGroup"); if (req.user.groups.indexOf(adminGroup) === -1){ - console.log("FORMIO FORBIDDEN"); res.status(403); res.json({error: "Forbidden"}); return; } - console.log("FORMIO ALLOWED"); + var formName = req.params.formName; formioClient.putForm(formName, req.body, function(formErr, formRes){ if (formErr){ @@ -516,26 +515,23 @@ var getRouter = function(db){ r = JSON.parse(formRes); }catch(ex){} - try{ + if (typeof(r.status) === "Number"){ res.status(r.status) - }catch(ex){} + } res.json(r); }); }); - router.delete('/formio/:formName', function(req, res, next){ - console.log("IN DELETE FORM ROUTE"); + router.delete(FORMS_SUB_ROUTE+'/:formName', function(req, res, next){ var config = require('config'); var adminGroup = config.get("adminGroup"); if (req.user.groups.indexOf(adminGroup) === -1){ - console.log("FORMIO FORBIDDEN"); res.status(403); res.json({error: "Forbidden"}); return; } - console.log("FORMIO ALLOWED"); var formName = req.params.formName; formioClient.putForm(formName, req.body, function(formErr, formRes){ if (formErr){ @@ -548,9 +544,9 @@ var getRouter = function(db){ r = JSON.parse(formRes); }catch(ex){} - try{ + if (typeof(r.status) === "Number"){ res.status(r.status) - }catch(ex){} + } res.json(r); }); From 870a9d2419ee90867b8d2290213087690658612c Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Wed, 5 Feb 2020 09:26:14 -0800 Subject: [PATCH 68/75] test tweaks --- microservices/requestApi/test/v2/requests.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index 7c6b3a254..4de206a0a 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -18,9 +18,9 @@ chai.use(chaiHttp); describe("Requests", function() { var activeRequestId = ''; - var firstId = ''; var incorrectId = ''; var fileId = 'test_' + Math.random().toString(36) + '.jpeg'; + var activeFormId = ''; after(function(done){ db.Request.deleteMany({}, function(err){ var minio = require('minio'); @@ -856,9 +856,9 @@ describe("Forms", function() { }] }) .end(function (err, res) { - console.log("SHOULD CREATE A FORM", res.status, res.body); res.should.have.status(200); res.body.should.have.property('_id'); + activeFormId = res.body._id; done(); }); }); @@ -882,6 +882,7 @@ describe("Forms", function() { .put('/v2/forms/testform') .set("Authorization", "Bearer "+adminJwt) .send({ + "_id": activeFormId, "title": "testform2", }) .end(function (err, res) { @@ -895,7 +896,9 @@ describe("Forms", function() { chai.request(server) .delete('/v2/forms/testform') .set("Authorization", "Bearer "+jwt) - .send({}) + .send({ + "_id": activeFormId, + }) .end(function (err, res) { res.should.have.status(403); res.body.should.have.property('error'); @@ -907,7 +910,9 @@ describe("Forms", function() { chai.request(server) .delete('/v2/forms/testform') .set("Authorization", "Bearer "+adminJwt) - .send({}) + .send({ + "_id": activeFormId, + }) .end(function (err, res) { res.should.have.status(200); res.body.should.have.property('_id'); From 30287215a2fe3a74da6b2b8274d866a5f7e41fa7 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Wed, 5 Feb 2020 09:32:07 -0800 Subject: [PATCH 69/75] tweaks --- microservices/requestApi/test/v2/requests.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index 4de206a0a..13abbba12 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -865,7 +865,7 @@ describe("Forms", function() { it('it should fail to update a form with no admin', function (done) { chai.request(server) - .put('/v2/forms/testform') + .put('/v2/forms/'+activeFormId) .set("Authorization", "Bearer "+jwt) .send({ "title": "testform2", @@ -879,10 +879,9 @@ describe("Forms", function() { it('it should update a form', function (done) { chai.request(server) - .put('/v2/forms/testform') + .put('/v2/forms/'+activeFormId) .set("Authorization", "Bearer "+adminJwt) .send({ - "_id": activeFormId, "title": "testform2", }) .end(function (err, res) { @@ -894,11 +893,9 @@ describe("Forms", function() { it('it should fail to delete a form with no admin', function (done) { chai.request(server) - .delete('/v2/forms/testform') + .delete('/v2/forms/'+activeFormId) .set("Authorization", "Bearer "+jwt) - .send({ - "_id": activeFormId, - }) + .send({}) .end(function (err, res) { res.should.have.status(403); res.body.should.have.property('error'); @@ -908,11 +905,9 @@ describe("Forms", function() { it('it should delete a form', function (done) { chai.request(server) - .delete('/v2/forms/testform') + .delete('/v2/forms/'+activeFormId) .set("Authorization", "Bearer "+adminJwt) - .send({ - "_id": activeFormId, - }) + .send({}) .end(function (err, res) { res.should.have.status(200); res.body.should.have.property('_id'); From 3bcb425ce02067157bd1e5a2080add3861e5d702 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Wed, 5 Feb 2020 09:38:19 -0800 Subject: [PATCH 70/75] tweaks to log levels --- microservices/requestApi/routes/routes/requests.js | 2 +- microservices/requestApi/routes/v2/routes/requests.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index c6945743e..680cf0a20 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -396,7 +396,7 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ logger.debug("file", myFile, "put up for validation"); logger.verbose("put file", myFile, " up for validation", apiErr, apiRes, body); if (apiErr) { - logger.error("Error validating file: ", apiErr); + logger.debug("Error validating file: ", apiErr); } }); })(findRes.files[i]) diff --git a/microservices/requestApi/routes/v2/routes/requests.js b/microservices/requestApi/routes/v2/routes/requests.js index 7e0374087..7a66ccb01 100644 --- a/microservices/requestApi/routes/v2/routes/requests.js +++ b/microservices/requestApi/routes/v2/routes/requests.js @@ -155,7 +155,7 @@ var getRouter = function(db){ request.save(function(saveErr, result){ if (saveErr || !result) { - log.error("Error saving request", saveErr, result); + log.debug("Error saving request", saveErr, result); res.status(500); res.json({error: saveErr.message}); return; From 6009bdffa1770bc3fe3ed12130fde1781e2ba9b8 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Wed, 5 Feb 2020 09:59:59 -0800 Subject: [PATCH 71/75] removed some duplicated code --- .../requestApi/routes/routes/requests.js | 130 +++++------------- .../requestApi/routes/v2/routes/requests.js | 121 +++++++--------- 2 files changed, 83 insertions(+), 168 deletions(-) diff --git a/microservices/requestApi/routes/routes/requests.js b/microservices/requestApi/routes/routes/requests.js index 680cf0a20..8dab4344e 100644 --- a/microservices/requestApi/routes/routes/requests.js +++ b/microservices/requestApi/routes/routes/requests.js @@ -481,108 +481,22 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ var storageApi = config.get('storageApi'); var warnSize = reqRes.type === db.Request.EXPORT_TYPE ? storageApi.warnRequestBundlesize : storageApi.warnImportRequestBundlesize; var maxSize = reqRes.type === db.Request.EXPORT_TYPE ? storageApi.maxRequestBundlesize : storageApi.maxImportRequestBundlesize; - if ( (warnSize > 0) || (maxSize > 0)){ - util.getBundleMeta(reqRes.files, function(metadataRes){ - var bundleSize = 0; - for (let i=0; i 0) && (bundleSize >= warnSize) && (bundleSize < maxSize)){ - logger.warn("Bundle exceeds warn size but not max size"); - } - - if ( (maxSize > 0) && (bundleSize >= maxSize)){ - logger.error("Bundle exceeds max size"); - res.status(403); - res.json({error: "Request submission failed, total request filesize exceeds maximum", info: maxSize}); - return; - } - - util.getFileStatus(reqRes.files, function(status) { - if (Object.keys(status).length !== reqRes.files.length){ - res.status(403); - res.json({error: "Not all files were submitted for validation, did you let save finish?"}); - return; - } - - let pass = true; - let blocked = false; - - for (let i=0; i < reqRes.files.length; i++) { - for (var j=0; j < status[reqRes.files[i]].length; j++) { - - if ((status[reqRes.files[i]][j].state === 1) && (status[reqRes.files[i]][j].mandatory === true)) { - blocked = true; - } - - if ((status[reqRes.files[i]][j].pass === false) && (status[reqRes.files[i]][j].mandatory === true)) { - pass = false; - } - } - } - - if (pass) { - db.Request.updateOne({_id: reqRes._id}, reqRes, function (updateErr) { - if (!updateErr) { - //works around a bug where the date isn't coming back from findOneAndUpdate so just hard casting it properly - reqRes.chronology[reqRes.chronology.length-1].timestamp = new Date(reqRes.chronology[reqRes.chronology.length-1].timestamp); - reqRes.fileStatus = status; - notify.notify(reqRes, req.user, (reqRes.state===db.Request.AWAITING_REVIEW_STATE)); - - if ((reqRes.type === db.Request.INPUT_TYPE && autoAccept.import) - || (reqRes.type === db.Request.EXPORT_TYPE && autoAccept.export)) { - notify.gitops().approve(reqRes).then((arg) => { - logRequestFinalState(reqRes, req.user); - res.json({message: "Request approved", result: reqRes}); - }).catch(err => { - reqRes.state = db.Request.WIP_STATE; - reqRes.chronology.splice(-1,1); - db.Request.updateOne({_id: reqRes._id}, reqRes, function (uerr) { - if (uerr) { - logger.error("Unable to revert changes after failed code merge.", uerr); - } - }); - res.status(400); - res.json({error: "Error - " + err}); - return; - }); - } else { - res.json({message: "Request submitted", result: reqRes}); - } - return; - - }else{ - res.status(403); - res.json({error: updateErr.message}); - return; - } - }); - - return; - } - res.status(403); - if (blocked){ - res.json({error: "Request submission failed, one or more files is blocked", fileStatus: status}); - return; - } - res.json({error: "Request submission failed, validation pending, please wait", fileStatus: status}); - return; - }); - }); - }else{ + var getFileStatusAndUpdate = function(reqRes){ util.getFileStatus(reqRes.files, function(status) { if (Object.keys(status).length !== reqRes.files.length){ res.status(403); res.json({error: "Not all files were submitted for validation, did you let save finish?"}); return; } + let pass = true; let blocked = false; - for (let i=0; i < reqRes.files.length; i++){ + + for (let i=0; i < reqRes.files.length; i++) { for (var j=0; j < status[reqRes.files[i]].length; j++) { + if ((status[reqRes.files[i]][j].state === 1) && (status[reqRes.files[i]][j].mandatory === true)) { blocked = true; } @@ -592,6 +506,7 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ } } } + if (pass) { db.Request.updateOne({_id: reqRes._id}, reqRes, function (updateErr) { if (!updateErr) { @@ -599,8 +514,9 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ reqRes.chronology[reqRes.chronology.length-1].timestamp = new Date(reqRes.chronology[reqRes.chronology.length-1].timestamp); reqRes.fileStatus = status; notify.notify(reqRes, req.user, (reqRes.state===db.Request.AWAITING_REVIEW_STATE)); + if ((reqRes.type === db.Request.INPUT_TYPE && autoAccept.import) - || (reqRes.type === db.Request.EXPORT_TYPE && autoAccept.export)) { + || (reqRes.type === db.Request.EXPORT_TYPE && autoAccept.export)) { notify.gitops().approve(reqRes).then((arg) => { logRequestFinalState(reqRes, req.user); res.json({message: "Request approved", result: reqRes}); @@ -616,11 +532,11 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ res.json({error: "Error - " + err}); return; }); - - }else{ + } else { res.json({message: "Request submitted", result: reqRes}); } return; + }else{ res.status(403); res.json({error: updateErr.message}); @@ -639,6 +555,32 @@ var buildDynamic = function(projectConfig, db, notify, util, router){ return; }); } + + if ( (warnSize > 0) || (maxSize > 0)){ + util.getBundleMeta(reqRes.files, function(metadataRes){ + + var bundleSize = 0; + for (let i=0; i 0) && (bundleSize >= warnSize) && (bundleSize < maxSize)){ + logger.warn("Bundle exceeds warn size but not max size"); + } + + if ( (maxSize > 0) && (bundleSize >= maxSize)){ + logger.error("Bundle exceeds max size"); + res.status(403); + res.json({error: "Request submission failed, total request filesize exceeds maximum", info: maxSize}); + return; + } + + getFileStatusAndUpdate(reqRes); + }); + }else{ + getFileStatusAndUpdate(reqRes); + } }); }); }); diff --git a/microservices/requestApi/routes/v2/routes/requests.js b/microservices/requestApi/routes/v2/routes/requests.js index 7a66ccb01..42f5fe803 100644 --- a/microservices/requestApi/routes/v2/routes/requests.js +++ b/microservices/requestApi/routes/v2/routes/requests.js @@ -276,6 +276,46 @@ var getRouter = function(db){ db.Request.setChrono(findRes, req.user.id, objectDelta); } + var update = function(findRes){ + db.Request.updateOne({_id: requestId}, findRes, function(saveErr){ + if (saveErr) { + res.json({error: saveErr.message}); + return; + } + + var httpReq = require('request'); + + var policy = findRes.type + "-" + findRes.exportType; + + for (let i=0; i Date: Wed, 5 Feb 2020 10:35:32 -0800 Subject: [PATCH 72/75] bug fixes --- microservices/requestApi/routes/v2/routes/requests.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/microservices/requestApi/routes/v2/routes/requests.js b/microservices/requestApi/routes/v2/routes/requests.js index 42f5fe803..5a7bd9384 100644 --- a/microservices/requestApi/routes/v2/routes/requests.js +++ b/microservices/requestApi/routes/v2/routes/requests.js @@ -276,7 +276,7 @@ var getRouter = function(db){ db.Request.setChrono(findRes, req.user.id, objectDelta); } - var update = function(findRes){ + var update = function(findRes, formRes){ db.Request.updateOne({_id: requestId}, findRes, function(saveErr){ if (saveErr) { res.json({error: saveErr.message}); @@ -342,7 +342,7 @@ var getRouter = function(db){ return; } - update(findRes); + update(findRes, formRes); }); }else{ @@ -358,7 +358,7 @@ var getRouter = function(db){ findRes.submissionId = formRes._id; - update(findRes); + update(findRes, formRes); }); } @@ -506,7 +506,7 @@ var getRouter = function(db){ return; } var formName = req.params.formName; - formioClient.deleteForm(formName, req.body, function(formErr, formRes){ + formioClient.deleteForm(formName, function(formErr, formRes){ if (formErr){ res.status(500); res.json({error: formErr}); From 153ece63ea09a04211749c0bca6be3bead4246bb Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Wed, 5 Feb 2020 10:53:12 -0800 Subject: [PATCH 73/75] test tweak --- microservices/requestApi/test/v2/requests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index 13abbba12..a36605309 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -905,7 +905,7 @@ describe("Forms", function() { it('it should delete a form', function (done) { chai.request(server) - .delete('/v2/forms/'+activeFormId) + .delete('/v2/forms/testform') .set("Authorization", "Bearer "+adminJwt) .send({}) .end(function (err, res) { From 9a72997ac991e5e93d17d559a3a098f8277a6457 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Wed, 5 Feb 2020 11:01:52 -0800 Subject: [PATCH 74/75] test fix --- microservices/requestApi/test/v2/requests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microservices/requestApi/test/v2/requests.js b/microservices/requestApi/test/v2/requests.js index a36605309..431ce03b5 100644 --- a/microservices/requestApi/test/v2/requests.js +++ b/microservices/requestApi/test/v2/requests.js @@ -910,7 +910,7 @@ describe("Forms", function() { .send({}) .end(function (err, res) { res.should.have.status(200); - res.body.should.have.property('_id'); + expect(res.body).to.equal("OK"); done(); }); }); From 6d2a66197085ab6f64feaf74f0898955c1a073a7 Mon Sep 17 00:00:00 2001 From: BrandonSharratt Date: Wed, 5 Feb 2020 15:35:12 -0800 Subject: [PATCH 75/75] increment file wait time --- .../Include/scripts/groovy/test/ocwa/common/Constant.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui_tests/Include/scripts/groovy/test/ocwa/common/Constant.groovy b/ui_tests/Include/scripts/groovy/test/ocwa/common/Constant.groovy index 17008866d..1d2716e16 100644 --- a/ui_tests/Include/scripts/groovy/test/ocwa/common/Constant.groovy +++ b/ui_tests/Include/scripts/groovy/test/ocwa/common/Constant.groovy @@ -10,7 +10,7 @@ public class Constant { } static final def DEFAULT_TIMEOUT = 10 - static final def FILE_UPLOAD_TIMEOUT = 5 + static final def FILE_UPLOAD_TIMEOUT = 10 static final def DOWNLOAD_INTERFACE_TIMEOUT = 2 static final def ASSIGN_TO_ME_TIMEOUT = 2 static final def STATUS_CHECK_WAIT = 2