From 8b28208c4667dae20b0ff94262fcdcefe3df8161 Mon Sep 17 00:00:00 2001 From: Sergiu Alexandrescu Date: Fri, 25 Sep 2015 14:48:37 +0000 Subject: [PATCH 01/42] added more tests or object/unsubscribe --- test/admin/admin.js | 4 +-- test/object/object.js | 76 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/test/admin/admin.js b/test/admin/admin.js index 1812337..aca8582 100644 --- a/test/admin/admin.js +++ b/test/admin/admin.js @@ -34,7 +34,7 @@ var userEmail = 'user'+Math.round(Math.random()*1000000)+'@example.com'; describe('Admin', function() { it('should return a 200 code to indicate success when creating a new admin', function(done) { - this.timeout(10000); + this.timeout(12*DELAY); request(url) .post('/admin/add') @@ -45,7 +45,7 @@ describe('Admin', function() { done(err); } res.statusCode.should.be.equal(200); - setTimeout(done, 4*DELAY); + setTimeout(done, 8*DELAY); }); }); diff --git a/test/object/object.js b/test/object/object.js index a36d1ff..3358005 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -567,7 +567,81 @@ it('should return a success response to indicate that a object has been unsubscr res.statusCode.should.be.equal(200); done(); }); -}) +}); + +it('should return a success response to indicate that a object has NOT been unsubscribed because of empty body', function(done) { + var subclientrequest = {}; + + request(url) + .post('/object/unsubscribe') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', authValue) + .send(subclientrequest) + .end(function(err, res) { + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('should return a success response to indicate that a object has NOT been unsubscribed because of missing channel', function(done) { + var subclientrequest = { + "something": {} + }; + + request(url) + .post('/object/unsubscribe') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', authValue) + .send(subclientrequest) + .end(function(err, res) { + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('should return a success response to indicate that a object has NOT been unsubscribed because of missing context', function(done) { + var subclientrequest = { + "channel": { + "model": "comments" + } + }; + + request(url) + .post('/object/unsubscribe') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', authValue) + .send(subclientrequest) + .end(function(err, res) { + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('should return a success response to indicate that a object has NOT been unsubscribed because of missing model', function(done) { + var subclientrequest = { + "channel": { + "context": contextID + } + }; + + request(url) + .post('/object/unsubscribe') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', authValue) + .send(subclientrequest) + .end(function(err, res) { + res.statusCode.should.be.equal(400); + done(); + }); +}); it('should return a success response to indicate that a object has been deleted', function(done) { var clientrequest = { From 12f8e2ed6bbf0062cc8f94713ead5a11ced3d811 Mon Sep 17 00:00:00 2001 From: Sergiu Alexandrescu Date: Fri, 25 Sep 2015 15:18:22 +0000 Subject: [PATCH 02/42] added new test to test object/create with an admin --- test/object/object.js | 68 ++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/test/object/object.js b/test/object/object.js index 3358005..292122f 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -12,6 +12,7 @@ var appIDsha256 = common.appIDsha256; var token; var appID; var authValue; +var userAuthValue; var contextID; var subclientrequest = { @@ -187,7 +188,7 @@ before(function(done){ .send(clientrequest) .end(function(err, res) { token = res.body.content.token; - authValue = 'Bearer ' + token; + userAuthValue = 'Bearer ' + token; done(); }); }, 7*DELAY); @@ -203,7 +204,7 @@ it('should return an error (400) response to indicate that the client made a bad .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification ) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue ) + .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { res.statusCode.should.be.equal(400); @@ -244,7 +245,7 @@ it('should return a success response to indicate that object has been created', .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue ) + .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { res.statusCode.should.be.equal(202); @@ -253,6 +254,31 @@ it('should return a success response to indicate that object has been created', }); }); +// it('should return a success response to indicate that object has been created by an admin', function(done) { + // var clientrequest = { + // "model": "comments", + // "context": contextID, + // "content": { + // "events_id" :1 + // } + // }; + // request(url) + // .post('/object/create') + // .set('X-BLGREQ-SIGN', appIDsha256) + // .set('X-BLGREQ-UDID', deviceIdentification) + // .set('X-BLGREQ-APPID',appID) + // .set('Authorization', authValue ) + // .send(clientrequest) + // .end(function(err, res) { + // console.log(res.body); + // console.log(authValue); + // authValue + // res.statusCode.should.be.equal(202); + // res.body.content.should.be.equal("Created"); + // done(); + // }); +// }); + it('should return an error response to indicate that object has NOT been created because of missing authentication', function(done) { var clientrequest = { "model": "comments", @@ -285,7 +311,7 @@ it('should return an error response to indicate that object has NOT been created .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue ) + .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { res.statusCode.should.be.equal(400); @@ -305,7 +331,7 @@ it('should return an error response to indicate that object has NOT been created .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue ) + .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { res.statusCode.should.be.equal(400); @@ -325,7 +351,7 @@ it('should return a success response to indicate the count of a certain filter/s .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue ) + .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { res.statusCode.should.be.equal(200); @@ -352,7 +378,7 @@ it('should return a success response to indicate that a object has been updated' .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue ) + .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { res.statusCode.should.be.equal(202); @@ -429,7 +455,7 @@ it('should return a success response to indicate that a object has NOT been upda .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue ) + .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { res.statusCode.should.be.equal(400); @@ -454,7 +480,7 @@ it('should return a success response to indicate that a object has NOT been upda .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue ) + .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { res.statusCode.should.be.equal(400); @@ -475,7 +501,7 @@ it('should return a success response to indicate that a object has been subscrib .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue ) + .set('Authorization', userAuthValue ) .send(subclientrequest) .end(function(err, res) { res.statusCode.should.be.equal(200); @@ -491,7 +517,7 @@ it('should return an error response to indicate that a object has NOT been subsc .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue ) + .set('Authorization', userAuthValue ) .send() .end(function(err, res) { res.statusCode.should.be.equal(400); @@ -541,7 +567,7 @@ it('should return an error response to indicate that a object has NOT been subsc .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue ) + .set('Authorization', userAuthValue ) .send() .end(function(err, res) { res.statusCode.should.be.equal(400); @@ -561,7 +587,7 @@ it('should return a success response to indicate that a object has been unsubscr .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue) + .set('Authorization', userAuthValue) .send(subclientrequest) .end(function(err, res) { res.statusCode.should.be.equal(200); @@ -577,7 +603,7 @@ it('should return a success response to indicate that a object has NOT been unsu .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue) + .set('Authorization', userAuthValue) .send(subclientrequest) .end(function(err, res) { res.statusCode.should.be.equal(400); @@ -595,7 +621,7 @@ it('should return a success response to indicate that a object has NOT been unsu .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue) + .set('Authorization', userAuthValue) .send(subclientrequest) .end(function(err, res) { res.statusCode.should.be.equal(400); @@ -615,7 +641,7 @@ it('should return a success response to indicate that a object has NOT been unsu .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue) + .set('Authorization', userAuthValue) .send(subclientrequest) .end(function(err, res) { res.statusCode.should.be.equal(400); @@ -635,7 +661,7 @@ it('should return a success response to indicate that a object has NOT been unsu .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue) + .set('Authorization', userAuthValue) .send(subclientrequest) .end(function(err, res) { res.statusCode.should.be.equal(400); @@ -654,7 +680,7 @@ it('should return a success response to indicate that a object has been deleted' .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue ) + .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { res.statusCode.should.be.equal(202); @@ -699,7 +725,7 @@ it('should return an error response to indicate that the object id was missing', .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue ) + .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { res.statusCode.should.be.equal(400); @@ -719,7 +745,7 @@ it('should return an error response to indicate that the object model was missin .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue ) + .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { res.statusCode.should.be.equal(400); @@ -759,7 +785,7 @@ it('should return an error response to indicate that the object was not deleted .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) - .set('Authorization', authValue ) + .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { res.statusCode.should.be.equal(400); From 02a79c91f2a03892aaf035ac0df81dccce8c6db9 Mon Sep 17 00:00:00 2001 From: Razvan Botea Date: Mon, 28 Sep 2015 14:04:49 +0300 Subject: [PATCH 03/42] removed useless admin/user get at object/create --- controllers/object.js | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/controllers/object.js b/controllers/object.js index 8606d0f..e04bbf1 100644 --- a/controllers/object.js +++ b/controllers/object.js @@ -423,23 +423,8 @@ router.post('/create', function(req, res, next) { } async.series([ - function(callback) { - if (isAdmin) { - Models.Admin(req.user.email, function(err, result) { - if (err) return callback(err); - content.user_id = result.id; - isAdmin = true; - callback(); - }); - } else { - Models.User(req.user.email, appId, function(err, result) { - if (err) return callback(err); - content.user_id = result.id; - callback(); - }); - } - }, function(aggCallback) { + content.user_id = req.user.id; app.messagingClient.send([JSON.stringify({ op: 'add', object: content, From d95cff0ef552bfe31f48e133872e74a60b4e1cbf Mon Sep 17 00:00:00 2001 From: Sergiu Alexandrescu Date: Mon, 28 Sep 2015 12:26:02 +0000 Subject: [PATCH 04/42] added new tests for object/update and object/create --- test/object/object.js | 96 +++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 50 deletions(-) diff --git a/test/object/object.js b/test/object/object.js index 292122f..1faa0ba 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -254,30 +254,27 @@ it('should return a success response to indicate that object has been created', }); }); -// it('should return a success response to indicate that object has been created by an admin', function(done) { - // var clientrequest = { - // "model": "comments", - // "context": contextID, - // "content": { - // "events_id" :1 - // } - // }; - // request(url) - // .post('/object/create') - // .set('X-BLGREQ-SIGN', appIDsha256) - // .set('X-BLGREQ-UDID', deviceIdentification) - // .set('X-BLGREQ-APPID',appID) - // .set('Authorization', authValue ) - // .send(clientrequest) - // .end(function(err, res) { - // console.log(res.body); - // console.log(authValue); - // authValue - // res.statusCode.should.be.equal(202); - // res.body.content.should.be.equal("Created"); - // done(); - // }); -// }); +it('should return a success response to indicate that object has been created by an admin', function(done) { + var clientrequest = { + "model": "comments", + "context": contextID, + "content": { + "events_id" :1 + } + }; + request(url) + .post('/object/create') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', authValue ) + .send(clientrequest) + .end(function(err, res) { + res.statusCode.should.be.equal(202); + res.body.content.should.be.equal("Created"); + done(); + }); +}); it('should return an error response to indicate that object has NOT been created because of missing authentication', function(done) { var clientrequest = { @@ -386,32 +383,31 @@ it('should return a success response to indicate that a object has been updated' }); }); -// it('should return a success response to indicate that a object has NOT been updated bacause user not authenticated', function(done) { - // var clientrequest = { - // "model": "comments", - // "id": 1, - // "context": contextID, - // "patches": [ - // { - // "op": "replace", - // "path": "comments/1/text", - // "value": "some edited text" - // } - // ] - // }; - // request(url) - // .post('/object/update') - // .set('X-BLGREQ-SIGN', appIDsha256) - // .set('X-BLGREQ-UDID', deviceIdentification) - // .set('X-BLGREQ-APPID',appID) - // .set('Authorization', authValue + '66' ) - // .send(clientrequest) - // .end(function(err, res) { - // res.statusCode.should.be.equal(401); - // done(); - // }); -// }); - +it('should return a success response to indicate that a object has NOT been updated bacause of bad authentication', function(done) { + var clientrequest = { + "model": "comments", + "id": 1, + "context": contextID, + "patches": [ + { + "op": "replace", + "path": "comments/1/text", + "value": "some edited text" + } + ] + }; + request(url) + .post('/object/update') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', authValue + '66' ) + .send(clientrequest) + .end(function(err, res) { + res.statusCode.should.be.equal(401); + done(); + }); +}); it('should return a success response to indicate that a object has NOT been updated because of missing authorization ', function(done) { var clientrequest = { From 5e062e5efe3c0649cb12181c047a6143d82d34e2 Mon Sep 17 00:00:00 2001 From: Sergiu Alexandrescu Date: Tue, 29 Sep 2015 09:26:58 +0000 Subject: [PATCH 05/42] cleaned up added remove_model test added remove object test enabled dynamic scripting in elasticsearch via .travis.yml --- .travis.yml | 2 + test/admin/admin.js | 713 +++++++++++++++++++++++++++------------- test/api.js | 22 +- test/context/context.js | 28 +- test/device/device.js | 42 ++- test/object/object.js | 266 ++++++++++----- test/user/user.js | 101 ++++-- 7 files changed, 807 insertions(+), 367 deletions(-) diff --git a/.travis.yml b/.travis.yml index bc30782..18e896b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,8 @@ before_install: before_script: - telepat configure elasticsearch - bash .travis/start.sh + - 'echo "script.disable_dynamic: false" | sudo tee -a /etc/elasticsearch/elasticsearch.yml' + - 'echo "script.groovy.sandbox.enable: true" | sudo tee -a /etc/elasticsearch/elasticsearch.yml' after_script: - codeclimate-test-reporter < coverage/lcov.info node_js: diff --git a/test/admin/admin.js b/test/admin/admin.js index aca8582..0f1dd46 100644 --- a/test/admin/admin.js +++ b/test/admin/admin.js @@ -34,12 +34,14 @@ var userEmail = 'user'+Math.round(Math.random()*1000000)+'@example.com'; describe('Admin', function() { it('should return a 200 code to indicate success when creating a new admin', function(done) { + this.timeout(12*DELAY); request(url) .post('/admin/add') .send(admin) .end(function(err, res) { + if (err) { throw err; done(err); @@ -55,6 +57,7 @@ describe('Admin', function() { .post('/admin/add') .send(admin) .end(function(err, res) { + res.statusCode.should.be.equal(409); done(); }); @@ -62,60 +65,73 @@ describe('Admin', function() { }); it('should return a 4xx code to indicate failure when admin email is missing', function(done) { + var admin = { password: adminPassword }; + request(url) .post('/admin/add') .send(admin) .end(function(err, res) { + res.statusCode.should.be.within(400,499); done(); }); }); it('should return a 4xx code to indicate failure when admin email is empty', function(done) { + var admin = { email: "", password: adminPassword }; + request(url) .post('/admin/add') .send(admin) .end(function(err, res) { + res.statusCode.should.be.within(400,499); done(); }); }); it('should return a 4xx code to indicate failure when admin password is empty', function(done) { + var admin = { email: adminEmail, password: "" }; + request(url) .post('/admin/add') .send(admin) .end(function(err, res) { + res.statusCode.should.be.within(400,499); done(); }); }); it('should return a 4xx code to indicate failure when admin password is missing', function(done) { + var admin = { email: adminEmail }; + request(url) .post('/admin/add') .send(admin) .end(function(err, res) { + res.statusCode.should.be.within(400,499); done(); }); }); it('should return an error for logging in with wrong user or password', function(done) { + var randEmail = 'adminx@example.com'; var admin = { email: randEmail, @@ -125,16 +141,50 @@ describe('Admin', function() { .post('/admin/login') .send(admin) .end(function(err, res) { + res.statusCode.should.be.equal(401); done(); }); }); + + it('should return an error for logging in missing password', function(done) { + + var randEmail = 'adminx@example.com'; + var admin = { + email: randEmail + }; + + request(url) + .post('/admin/login') + .send(admin) + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); + }); + + it('should return an error for logging in missing email & password', function(done) { + + var admin = {}; + + request(url) + .post('/admin/login') + .send(admin) + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); + }); it('should return a valid authorization token', function(done) { + request(url) .post('/admin/login') .send(admin) .end(function(err, res) { + authValue = 'Bearer ' + res.body.content.token; adminAuth = authValue; admin = res.body.content.user; @@ -144,12 +194,14 @@ describe('Admin', function() { }); it('should return information about the logged admin', function(done) { + request(url) .get('/admin/me') .set('Content-type','application/json') .set('Authorization', authValue ) .send() .end(function(err, res) { + res.statusCode.should.be.equal(200); res.body.content.email.should.be.equal(admin.email); res.body.content.isAdmin.should.be.equal(true); @@ -158,26 +210,31 @@ describe('Admin', function() { }); it('should return a succes response indicating the admin account has been updated', function(done) { + + var requestBody = { + patches: [ + { + op: 'replace', + path: 'admin/'+admin.id+'/name', + value: 'Admin Name v2' + } + ] + }; + request(url) .post('/admin/update') .set('Content-type','application/json') .set('Authorization', authValue ) - .send({ - patches: [ - { - op: 'replace', - path: 'admin/'+admin.id+'/name', - value: 'Admin Name v2' - } - ] - }) + .send(requestBody) .end(function(err, res) { + res.statusCode.should.be.equal(200); done(); }); }); it('should return an error response indicating the admin account has NOT been updated because of invalid admin id', function(done) { + var admin = { patches: [ { @@ -187,59 +244,135 @@ describe('Admin', function() { } ] }; + request(url) .post('/admin/update') .set('Content-type','application/json') + .set('Authorization', authValue ) .send(admin) .end(function(err, res) { + + res.statusCode.should.be.equal(401); + done(); + }); + }); + + it('should return an error response indicating the admin account has NOT been updated because of missing authorization header', function(done) { + + var admin = { + patches: [ + { + op: 'replace', + path: 'admin/garbage/name', + value: 'Admin Name v2' + } + ] + }; + + request(url) + .post('/admin/update') + .set('Content-type','application/json') + .send(admin) + .end(function(err, res) { + res.statusCode.should.be.equal(401); done(); }); }); it('should return an error response indicating the admin account has NOT been updated because of missing request body', function(done) { + request(url) .post('/admin/update') .set('Content-type','application/json') .set('Authorization', authValue ) .send() .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); + }); + + + it('should return an error response indicating the admin account has NOT been updated because patches is not an array', function(done) { + + var admin = { + patches: {} + }; + + request(url) + .post('/admin/update') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .send(admin) + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); + }); + + it('should return an error response indicating the admin account has NOT been updated because patches is empty', function(done) { + + var admin = { + patches: [] + }; + + request(url) + .post('/admin/update') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .send(admin) + .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return an error response indicating the admin account has NOT been deleted because of missing credentials', function(done) { + request(url) .post('/admin/delete') .set('Content-type','application/json') .send() .end(function(err, res) { + res.statusCode.should.be.equal(401); done(); }); }); it('should return a succes response indicating the admin account has been deleted', function(done) { + this.timeout(20*DELAY); + request(url) .post('/admin/delete') .set('Content-type','application/json') .set('Authorization', authValue) .send() .end(function(err, res) { + res.statusCode.should.be.equal(200); + setTimeout(function() { + request(url) .post('/admin/add') .send(admin) .end(function(err, res) { + res.statusCode.should.be.equal(200); + setTimeout(function () { + request(url) .post('/admin/login') .send(admin) .end(function(err, res) { + authValue = 'Bearer ' + res.body.content.token; adminAuth = authValue; res.statusCode.should.be.equal(200); @@ -250,42 +383,48 @@ describe('Admin', function() { }, 8*DELAY); }); }); - }); describe('App', function() { before(function(done){ + this.timeout(20*DELAY); var clientrequest = { "name": "test-app", "keys": [ appKey ] }; + request(url) - .post('/admin/app/add') - .set('Content-type','application/json') - .set('Authorization', authValue) - .send(clientrequest) - .end(function(err, res) { - appID = res.body.content.id; - request(url) - .post('/admin/add') - .send(admin2) - .end(function(err, res) { - setTimeout(function () { - request(url) - .post('/admin/login') - .set('Content-type','application/json') - .send(admin2) - .end(function(err, res) { - token2 = res.body.content.token; - authValue2 = 'Bearer ' + token2; - done(); - }); - }, 3*DELAY); - }); - }); + .post('/admin/app/add') + .set('Content-type','application/json') + .set('Authorization', authValue) + .send(clientrequest) + .end(function(err, res) { + + appID = res.body.content.id; + + request(url) + .post('/admin/add') + .send(admin2) + .end(function(err, res) { + + setTimeout(function () { + + request(url) + .post('/admin/login') + .set('Content-type','application/json') + .send(admin2) + .end(function(err, res) { + + token2 = res.body.content.token; + authValue2 = 'Bearer ' + token2; + done(); + }); + }, 3*DELAY); + }); + }); }); it('should return a success response to indicate app succesfully created', function(done) { @@ -307,6 +446,7 @@ describe('App', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + var objectKey = Object.keys(res.body.content)[0]; appID = res.body.content.id; (res.body.content[objectKey] == successResponse[1]).should.be.ok; @@ -315,44 +455,53 @@ describe('App', function() { }); it('should return an error response to indicate app was not created because of missing app name', function(done) { + var clientrequest = { "keys": ["3406870085495689e34d878f09faf52c"] }; + request(url) .post('/admin/app/add') .set('Content-type','application/json') .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return a list of applications for the current admin', function(done) { + var clientrequest = { "name": "test-app", "keys": [ appKey ] }; + request(url) .post('/admin/app/add') .set('Content-type','application/json') .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + request(url) .post('/admin/app/add') .set('Content-type','application/json') .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + setTimeout(function () { + request(url) .get('/admin/apps') .set('Content-type','application/json') .set('Authorization', authValue ) .send() .end(function(err, res) { + res.statusCode.should.be.equal(200); res.body.status.should.be.equal(200); (Object.keys(res.body.content).length >= 3).should.be.ok; @@ -364,16 +513,19 @@ describe('App', function() { }); it('should return a success response for updating an app', function(done) { + var clientrequest = { "name": "test-app", "keys": [ appKey ] }; + request(url) .post('/admin/app/add') .set('Content-type','application/json') .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + var objectKey = Object.keys(res.body.content)[0]; var appID = res.body.content.id; var clientrequest2 = { @@ -385,7 +537,9 @@ describe('App', function() { } ] }; + setTimeout(function () { + request(url) .post('/admin/app/update') .set('Content-type','application/json') @@ -402,7 +556,6 @@ describe('App', function() { it('should return an error response for NOT updating an app because of missing appID', function(done) { - var clientrequest2 = { patches: [ { @@ -414,32 +567,38 @@ describe('App', function() { }; request(url) - .post('/admin/app/update') - .set('Content-type','application/json') - .set('Authorization', authValue ) - .set('X-BLGREQ-APPID', appID + '66' ) - .send(clientrequest2) - .end(function(err, res) { - res.statusCode.should.be.equal(404); - done(); - }); + .post('/admin/app/update') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .set('X-BLGREQ-APPID', appID + '66' ) + .send(clientrequest2) + .end(function(err, res) { + + res.statusCode.should.be.equal(404); + done(); + }); }); it('should return a success response for removing an app', function(done) { + var clientrequest = { "name": "test-app", "keys": [ appKey ] }; + request(url) .post('/admin/app/add') .set('Content-type','application/json') .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + var objectKey = Object.keys(res.body.content)[0]; var appID = res.body.content.id; + setTimeout(function() { + request(url) .post('/admin/app/remove') .set('Content-type','application/json') @@ -447,6 +606,7 @@ describe('App', function() { .set('X-BLGREQ-APPID', appID ) .send() .end(function(err, res) { + res.statusCode.should.be.equal(200); res.body.content.should.be.equal('App removed'); done(); @@ -456,6 +616,7 @@ describe('App', function() { }); it('should return an error response for trying to remove an app that does NOT exist', function(done) { + request(url) .post('/admin/app/remove') .set('Content-type','application/json') @@ -463,6 +624,7 @@ describe('App', function() { .set('X-BLGREQ-APPID', Math.round(Math.random()*1000000)+1000 ) .send() .end(function(err, res) { + res.statusCode.should.be.equal(404); done(); }); @@ -475,18 +637,18 @@ describe('App', function() { }; request(url) - .post('/admin/app/authorize') - .set('Content-type','application/json') - .set('X-BLGREQ-APPID', appID) - .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') - .set('Authorization', authValue ) - .send(clientrequest) - .end(function(err, res) { - //console.log(res.body); - if(res) - res.statusCode.should.be.equal(200); - done(); - }); + .post('/admin/app/authorize') + .set('Content-type','application/json') + .set('X-BLGREQ-APPID', appID) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') + .set('Authorization', authValue ) + .send(clientrequest) + .end(function(err, res) { + + if(res) + res.statusCode.should.be.equal(200); + done(); + }); }); it('should return an error response to indicate admin has NOT been authorized because of the email field is missing', function(done) { @@ -494,28 +656,29 @@ describe('App', function() { var clientrequest = {}; request(url) - .post('/admin/app/authorize') - .set('Content-type','application/json') - .set('X-BLGREQ-APPID', appID) - .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') - .set('Authorization', authValue ) - .send(clientrequest) - .end(function(err, res) { - //console.log(res.body); - if(res) - res.statusCode.should.be.equal(400); - done(); - }); + .post('/admin/app/authorize') + .set('Content-type','application/json') + .set('X-BLGREQ-APPID', appID) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') + .set('Authorization', authValue ) + .send(clientrequest) + .end(function(err, res) { + + if(res) + res.statusCode.should.be.equal(400); + done(); + }); }); it('should return an error response to indicate admin with email address already authorized for application', function(done) { + this.timeout(10*DELAY); + var clientrequest = { + "email": adminEmail2 + }; + setTimeout(function () { - var clientrequest = { - "email": adminEmail2 - }; - request(url) .post('/admin/app/authorize') .set('Content-type','application/json') @@ -524,8 +687,7 @@ describe('App', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - //console.log(appID); - //console.log(res.body); + if(res) res.statusCode.should.be.equal(409); done(); @@ -540,17 +702,18 @@ describe('App', function() { }; request(url) - .post('/admin/app/authorize') - .set('Content-type','application/json') - .set('X-BLGREQ-APPID', appID + '66') - .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') - .set('Authorization', authValue ) - .send(clientrequest) - .end(function(err, res) { - if(res) - res.statusCode.should.be.equal(404); - done(); - }); + .post('/admin/app/authorize') + .set('Content-type','application/json') + .set('X-BLGREQ-APPID', appID + '66') + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') + .set('Authorization', authValue ) + .send(clientrequest) + .end(function(err, res) { + + if(res) + res.statusCode.should.be.equal(404); + done(); + }); }); it('should return an succes to indicate an admin has been deauthorized to an application', function(done) { @@ -560,17 +723,18 @@ describe('App', function() { }; request(url) - .post('/admin/app/deauthorize') - .set('Content-type','application/json') - .set('X-BLGREQ-APPID', appID) - .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') - .set('Authorization', authValue ) - .send(clientrequest) - .end(function(err, res) { - if(res) - res.statusCode.should.be.equal(200); - done(); - }); + .post('/admin/app/deauthorize') + .set('Content-type','application/json') + .set('X-BLGREQ-APPID', appID) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') + .set('Authorization', authValue ) + .send(clientrequest) + .end(function(err, res) { + + if(res) + res.statusCode.should.be.equal(200); + done(); + }); }); it('should return an error response to indicate admin has NOT been deauthorized because of the email field is missing', function(done) { @@ -578,18 +742,18 @@ describe('App', function() { var clientrequest = {}; request(url) - .post('/admin/app/deauthorize') - .set('Content-type','application/json') - .set('X-BLGREQ-APPID', appID) - .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') - .set('Authorization', authValue ) - .send(clientrequest) - .end(function(err, res) { - //console.log(res.body); - if(res) - res.statusCode.should.be.equal(400); - done(); - }); + .post('/admin/app/deauthorize') + .set('Content-type','application/json') + .set('X-BLGREQ-APPID', appID) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') + .set('Authorization', authValue ) + .send(clientrequest) + .end(function(err, res) { + + if(res) + res.statusCode.should.be.equal(400); + done(); + }); }); it('should return an error response to indicate admin with email address is the last admin of the application', function(done) { @@ -599,19 +763,18 @@ describe('App', function() { }; request(url) - .post('/admin/app/deauthorize') - .set('Content-type','application/json') - .set('X-BLGREQ-APPID', appID) - .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') - .set('Authorization', authValue ) - .send(clientrequest) - .end(function(err, res) { - //console.log(appID); - //console.log(res.body); - if(res) - res.statusCode.should.be.equal(409); - done(); - }); + .post('/admin/app/deauthorize') + .set('Content-type','application/json') + .set('X-BLGREQ-APPID', appID) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') + .set('Authorization', authValue ) + .send(clientrequest) + .end(function(err, res) { + + if(res) + res.statusCode.should.be.equal(409); + done(); + }); }); it('should return an error response to indicate admin has NOT been deauthenticated because application with that ID doesn\'t exist', function(done) { @@ -621,27 +784,30 @@ describe('App', function() { }; request(url) - .post('/admin/app/deauthorize') - .set('Content-type','application/json') - .set('X-BLGREQ-APPID', appID + '66') - .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') - .set('Authorization', authValue ) - .send(clientrequest) - .end(function(err, res) { - if(res) - res.statusCode.should.be.equal(404); - done(); - }); + .post('/admin/app/deauthorize') + .set('Content-type','application/json') + .set('X-BLGREQ-APPID', appID + '66') + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') + .set('Authorization', authValue ) + .send(clientrequest) + .end(function(err, res) { + + if(res) + res.statusCode.should.be.equal(404); + done(); + }); }); }); describe('Context', function() { it('should return a success response to indicate context succesfully created', function(done) { + var clientrequest = { "name": "context", "meta": {"info": "some meta info"}, } + request(url) .post('/admin/context/add') .set('Content-type','application/json') @@ -649,6 +815,7 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { + var objectKey = Object.keys(res.body.content)[0]; contextID = res.body.content.id; (res.body.content[objectKey].name == clientrequest.name).should.be.ok; @@ -658,9 +825,11 @@ describe('Context', function() { }); it('should return the requested context', function(done) { + var clientrequest = { "id": contextID } + request(url) .post('/admin/context') .set('Content-type','application/json') @@ -668,14 +837,16 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(200); done(); }); }); it('should NOT return the requested context, requested context ID is missing', function(done) { - var clientrequest = { - } + + var clientrequest = {}; + request(url) .post('/admin/context') .set('Content-type','application/json') @@ -683,28 +854,33 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return an error response to indicate context NOT succesfully created because of bad client headers', function(done) { + var clientrequest = { "name": "context", "meta": {"info": "some meta info"} }; + request(url) .post('/admin/context/add') .set('Content-type','application/json') .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return an error response to indicate context NOT succesfully created because request body is empty', function(done) { + var clientrequest = {}; request(url) @@ -713,12 +889,14 @@ describe('Context', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return a success response to indicate context was updated', function(done) { + var clientrequest = { "id": contextID, "patches": [ @@ -728,7 +906,8 @@ describe('Context', function() { "value": "New name" } ] - } + }; + request(url) .post('/admin/context/update') .set('Content-type','application/json') @@ -736,16 +915,19 @@ describe('Context', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(200); done(); }); }); it('should return an error response to indicate context was NOT updated because patches are missing', function(done) { + var clientrequest = { "id": Math.round(Math.random()*1000000)+100, "name": "new name" - } + }; + request(url) .post('/admin/context/update') .set('Content-type','application/json') @@ -753,12 +935,14 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return an error response to indicate context was NOT updated because context does not exist', function(done) { + var clientrequest = { "id": Math.round(Math.random()*1000000)+100, "patches": [{ @@ -767,6 +951,7 @@ describe('Context', function() { value: "new value" }] }; + request(url) .post('/admin/context/update') .set('Content-type','application/json') @@ -774,15 +959,18 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(404); done(); }); }); it('should return an error response to indicate context was NOT updated because of missing context id', function(done) { + var clientrequest = { "name": "new name" - } + }; + request(url) .post('/admin/context/update') .set('Content-type','application/json') @@ -790,12 +978,14 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return an error response to indicate context was NOT updated by another admin', function(done) { + var clientrequest = { "id": contextID, "patches": [ @@ -805,7 +995,7 @@ describe('Context', function() { "value": "New name" } ] - } + }; request(url) .post('/admin/context/update') @@ -814,15 +1004,18 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(401); done(); }); }); it('should return an error response to indicate context was NOT removed because of invalid context id', function(done) { + var clientrequest = { "id": 1 } + request(url) .post('/admin/context/remove') .set('Content-type','application/json') @@ -830,15 +1023,18 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(404); done(); }); }); it('should return an error indicating the requested context does NOT exist', function(done) { + var clientrequest = { "id": Math.round(Math.random()*1000000)+100 - } + }; + request(url) .post('/admin/context') .set('Content-type','application/json') @@ -846,6 +1042,7 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(404); res.body.message.should.be.equal("Context not found"); done(); @@ -853,8 +1050,11 @@ describe('Context', function() { }); it('should return all contexts using the old API', function(done) { + this.timeout(9*DELAY); + setTimeout(function () { + request(url) .get('/admin/contexts') .set('Content-type','application/json') @@ -862,6 +1062,7 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID) .send() .end(function(err, res) { + res.statusCode.should.be.equal(200); res.body.content.should.have.length(1); done(); @@ -870,8 +1071,11 @@ describe('Context', function() { }); it('should return all contexts using the new API', function(done) { + this.timeout(9*DELAY); + setTimeout(function () { + request(url) .get('/admin/context/all') .set('Content-type','application/json') @@ -879,6 +1083,7 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID) .send() .end(function(err, res) { + res.statusCode.should.be.equal(200); res.body.content.should.have.length(1); done(); @@ -887,9 +1092,11 @@ describe('Context', function() { }); it('should return a success response to indicate context was removed', function(done) { + var clientrequest = { "id": contextID - } + }; + request(url) .post('/admin/context/remove') .set('Content-type','application/json') @@ -897,6 +1104,7 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(200); res.body.content.should.be.equal('Context removed'); done(); @@ -905,7 +1113,9 @@ describe('Context', function() { }); describe('Schema', function() { + it('should return a success response to indicate schema succesfully updated', function(done) { + var clientrequest = { "appId": appID, "schema": { @@ -979,12 +1189,14 @@ describe('Schema', function() { .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(200); done(); }); }); it('should return an error response to indicate schema was NOT succesfully updated because of appID', function(done) { + var clientrequest = { "appId": "1", "schema": { @@ -1038,15 +1250,18 @@ describe('Schema', function() { .set('X-BLGREQ-APPID', Math.round(Math.random()*1000000)+1000 ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(404); done(); }); }); it('should return an error response to indicate schema was NOT succesfully updated because of missing schema object', function(done) { + var clientrequest = { "appId": "1" }; + request(url) .post('/admin/schema/update') .set('Content-type','application/json') @@ -1054,12 +1269,14 @@ describe('Schema', function() { .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return a success response to indicate schema was retrived succesfully using the old API', function(done) { + request(url) .get('/admin/schemas') .set('Content-type','application/json') @@ -1067,12 +1284,14 @@ describe('Schema', function() { .set('X-BLGREQ-APPID', appID ) .send() .end(function(err, res) { + res.statusCode.should.be.equal(200); done(); }); }); it('should return a success response to indicate schema was retrived succesfully using the new API', function(done) { + request(url) .get('/admin/schema/all') .set('Content-type','application/json') @@ -1080,29 +1299,31 @@ describe('Schema', function() { .set('X-BLGREQ-APPID', appID ) .send() .end(function(err, res) { + res.statusCode.should.be.equal(200); done(); }); }); - // it('should return a success response to indicate a model was removed from the application', function(done) { - - // var clientrequest = { - // "model_name": "things" - // }; - - // request(url) - // .post('/admin/schema/remove_model') - // .set('Content-type','application/json') - // .set('Authorization', authValue ) - // .set('X-BLGREQ-APPID', appID ) - // .send(clientrequest) - // .end(function(err, res) { - // console.log(res.body); - // res.statusCode.should.be.equal(200); - // done(); - // }); - // }); + it('should return a success response to indicate a model was removed from the application', function(done) { + + var clientrequest = { + "model_name": "things" + }; + + request(url) + .post('/admin/schema/remove_model') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .set('X-BLGREQ-APPID', appID ) + .send(clientrequest) + .end(function(err, res) { + + //console.log(res.body); + res.statusCode.should.be.equal(200); + done(); + }); + }); it('should return a error response to indicate a model was NOT removed from the application because of wrong appID', function(done) { @@ -1117,6 +1338,7 @@ describe('Schema', function() { .set('X-BLGREQ-APPID', appID + '66' ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(404); done(); }); @@ -1135,6 +1357,7 @@ describe('Schema', function() { .set('X-BLGREQ-APPID', appID + '66' ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(404); done(); }); @@ -1152,18 +1375,21 @@ describe('User', function() { }; before(function(done){ + this.timeout(11*DELAY); + request(url) - .post('/user/register') - .set('Content-type','application/json') - .set('X-BLGREQ-SIGN', appIDsha256 ) - .set('X-BLGREQ-APPID', appID ) - .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) - .send(clientrequest) - .end(function(err, res) { - //console.log(res.body); - setTimeout(done, 7*DELAY); - }); + .post('/user/register') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .send(clientrequest) + .end(function(err, res) { + + //console.log(res.body); + setTimeout(done, 7*DELAY); + }); }); it('should return a success response to indicate that an user was updated', function(done) { @@ -1181,23 +1407,25 @@ describe('User', function() { }; request(url) - .post('/admin/user/update') - .set('Content-type','application/json') - .set('X-BLGREQ-SIGN', appIDsha256) - .set('X-BLGREQ-APPID', appID) - .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') - .set('Authorization', authValue) - .send(clientrequest) - .end(function(err, res) { - //console.log(res.body); - res.statusCode.should.be.equal(200); - setTimeout(done, 8*DELAY); - }); + .post('/admin/user/update') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-APPID', appID) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') + .set('Authorization', authValue) + .send(clientrequest) + .end(function(err, res) { + + //console.log(res.body); + res.statusCode.should.be.equal(200); + setTimeout(done, 8*DELAY); + }); }); it('should return a success response to indicate that an user was NOT updated, user was missing from the request', function(done) { - var clientrequest = { - }; + + var clientrequest = {}; + request(url) .post('/admin/user/update') .set('Content-type','application/json') @@ -1207,17 +1435,20 @@ describe('User', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return a success response to indicate that an user was NOT updated, user email address was missing from the request', function(done) { + var clientrequest = { "user": { "name": "New Name" } }; + request(url) .post('/admin/user/update') .set('Content-type','application/json') @@ -1227,13 +1458,15 @@ describe('User', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return a success response indicating that a user has been deleted', function(done) { - this.timeout(25000); + + this.timeout(40*DELAY); request(url) .post('/user/register') @@ -1243,7 +1476,9 @@ describe('User', function() { .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { + setTimeout(function() { + request(url) .post('/admin/user/delete') .set('Content-type','application/json') @@ -1253,58 +1488,67 @@ describe('User', function() { .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(200); done(); }); }, 2*DELAY); }); - }); - // it('should return a success response indicating that a user has NOT been deleted, user does not belong to application', function(done) { - // this.timeout(25000); - // var userEmail = "user3@example.com"; - // var clientrequest = { - // "email": userEmail, - // "password": "secure_password1337", - // "name": "John Smith" - // }; - // request(url) - // .post('/user/register') - // .set('Content-type','application/json') - // .set('X-BLGREQ-SIGN', appIDsha256 ) - // .set('X-BLGREQ-APPID', appID ) - // .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) - // .send(clientrequest) - // .end(function(err, res) { - // var userEmail = "user2@example.com"; - // var clientrequest = { - // "email": userEmail, - // "password": "secure_password1337", - // "name": "John Smith" - // }; - // setTimeout(function() { - // request(url) - // .post('/admin/user/delete') - // .set('Content-type','application/json') - // .set('X-BLGREQ-SIGN', appIDsha256 ) - // .set('X-BLGREQ-APPID', appID ) - // .set('Authorization', authValue ) - // .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) - // .send(clientrequest) - // .end(function(err, res) { - // res.statusCode.should.be.equal(500); - // done(); - // }); - // }, DELAY); - // }); - // }); + it('should return a success response indicating that a user has NOT been deleted, user does not belong to application', function(done) { + + this.timeout(24*DELAY); + + var userEmail = "user3@example.com"; + var clientrequest = { + "email": userEmail, + "password": "secure_password1337", + "name": "John Smith" + }; + + request(url) + .post('/user/register') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .send(clientrequest) + .end(function(err, res) { + + var userEmail = "user2@example.com"; + var clientrequest = { + "email": userEmail, + "password": "secure_password1337", + "name": "John Smith" + }; + + setTimeout(function() { + + request(url) + .post('/admin/user/delete') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('Authorization', authValue ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .send(clientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(404); + done(); + }); + }, 16*DELAY); + }); + }); it('should return a error response indicating that a user has NOT been deleted because of missing email address', function(done) { + var clientrequest = { "password": "secure_password1337", "name": "John Smith" }; + request(url) .post('/admin/user/delete') .set('Content-type','application/json') @@ -1314,34 +1558,40 @@ describe('User', function() { .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return an error response indicating that a user has NOT been deleted because of appID not found', function(done) { - this.timeout(25000); + + this.timeout(40*DELAY); + var userEmail = "user3@example.com"; var clientrequest = { "email": userEmail, "password": "secure_password1337", "name": "John Smith" }; + request(url) .post('/admin/user/delete') .set('Content-type','application/json') .set('X-BLGREQ-SIGN', appIDsha256 ) - .set('X-BLGREQ-APPID', Math.round(Math.random()*1000000)+1000 ) + .set('X-BLGREQ-APPID', Math.round(Math.random()*1000000)+1000 ) .set('Authorization', authValue ) .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(404); done(); }); }); it('should return an error response to indicate that an user was NOT found when trying to update', function(done) { + var clientrequest = { "email" : "wrong@example.com", "patches": [ @@ -1352,6 +1602,7 @@ describe('User', function() { } ] }; + request(url) .post('/admin/user/update') .set('Content-type','application/json') @@ -1361,12 +1612,14 @@ describe('User', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(404); done(); }); }); it('should return an error response to indicate that the user email is missing', function(done) { + var clientrequest = { "patches": [ { @@ -1376,6 +1629,7 @@ describe('User', function() { } ] }; + request(url) .post('/admin/user/update') .set('Content-type','application/json') @@ -1385,12 +1639,14 @@ describe('User', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return a success response to indicate that an admin list was retrived', function(done) { + request(url) .get('/admin/users') .set('Content-type','application/json') @@ -1400,14 +1656,14 @@ describe('User', function() { .set('Authorization', authValue ) .send() .end(function(err, res) { - if(res) { - res.statusCode.should.be.equal(200); - } + + res.statusCode.should.be.equal(200); done(); }); }); it('should return an error response to indicate that an admin list was NOT retrived for a bad app id', function(done) { + request(url) .get('/admin/users') .set('Content-type','application/json') @@ -1417,6 +1673,7 @@ describe('User', function() { .set('Authorization', authValue ) .send() .end(function(err, res) { + if(res) res.statusCode.should.be.equal(404); done(); @@ -1424,6 +1681,7 @@ describe('User', function() { }); it('should return a success response to indicate that an users list was retrived', function(done) { + request(url) .get('/admin/user/all') .set('Content-type','application/json') @@ -1433,6 +1691,7 @@ describe('User', function() { .set('Authorization', authValue ) .send() .end(function(err, res) { + if(res) { //console.log(res.body); res.body.content.should.not.be.empty; @@ -1443,6 +1702,7 @@ describe('User', function() { }); it('should return an error response to indicate that an users list was NOT retrived for a bad app id', function(done) { + request(url) .get('/admin/user/all') .set('Content-type','application/json') @@ -1452,6 +1712,7 @@ describe('User', function() { .set('Authorization', authValue ) .send() .end(function(err, res) { + if(res) res.statusCode.should.be.equal(404); done(); diff --git a/test/api.js b/test/api.js index 463a6c5..ffce1d4 100644 --- a/test/api.js +++ b/test/api.js @@ -4,17 +4,18 @@ function importTest(name, path) { }); } -describe('API', function () { - function normalizePort(val) { - var port = parseInt(val, 10); - if (isNaN(port)) { - return val; - } - if (port >= 0) { - return port; - } - return false; +function normalizePort(val) { + var port = parseInt(val, 10); + if (isNaN(port)) { + return val; + } + if (port >= 0) { + return port; } + return false; +}; + +describe('API', function () { before(function (done) { this.timeout(15000); @@ -26,6 +27,7 @@ describe('API', function () { server.listen(port); server.on('listening', function() { setTimeout(done, 3000); + //done(); }); }); diff --git a/test/context/context.js b/test/context/context.js index 9f5efb2..3c92f8d 100644 --- a/test/context/context.js +++ b/test/context/context.js @@ -27,23 +27,30 @@ var admin = { }; before(function(done){ + this.timeout(10000); + var clientrequest = { "name": "test-app", "keys": [ common.appKey ] }; + request(url) .post('/admin/add') .send(admin) .end(function(err, res) { + setTimeout(function () { + request(url) .post('/admin/login') .set('Content-type','application/json') .send(admin) .end(function(err, res) { + var token = res.body.content.token; authValue = 'Bearer ' + token; + request(url) .post('/admin/app/add') .set('Content-type','application/json') @@ -59,11 +66,14 @@ before(function(done){ }); before(function(done){ + this.timeout(10*DELAY); + var clientrequest = { "name": "context", "meta": {"info": "some meta info"}, - } + }; + request(url) .post('/admin/context/add') .set('Content-type','application/json') @@ -71,15 +81,18 @@ before(function(done){ .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { + contextID = res.body.content.id; done(); }); }); it('should return a success response to indicate context succesfully retrived', function(done) { + var clientrequest = { "id": contextID - } + }; + request(url) .post('/context') .set('Content-type','application/json') @@ -89,13 +102,16 @@ it('should return a success response to indicate context succesfully retrived', .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(200); done(); }); }); it('should return an error response to indicate context wa NOT succesfully retrived because of missing context ID', function(done) { - var clientrequest = {} + + var clientrequest = {}; + request(url) .post('/context') .set('Content-type','application/json') @@ -105,15 +121,18 @@ it('should return an error response to indicate context wa NOT succesfully retri .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return an error response to indicate context NOT succesfully retrived', function(done) { + var clientrequest = { id: Math.round(Math.random()*1000000)+1000 }; + request(url) .get('/context') .set('X-BLGREQ-SIGN', appIDsha256 ) @@ -122,12 +141,14 @@ it('should return an error response to indicate context NOT succesfully retrived .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(404); done(); }); }); it('should return a success response to indicate all contexts succesfully retrived', function(done) { + request(url) .get('/context/all') .set('Content-type','application/json') @@ -137,6 +158,7 @@ it('should return a success response to indicate all contexts succesfully retriv .set('Authorization', authValue ) .send() .end(function(err, res) { + res.statusCode.should.be.equal(200); done(); }); diff --git a/test/device/device.js b/test/device/device.js index a3fac25..a92f270 100644 --- a/test/device/device.js +++ b/test/device/device.js @@ -10,7 +10,7 @@ var appID; var authValue; var appIDsha256 = common.appIDsha256; -var adminEmail = 'admin'+Math.round(Math.random()*1000000)+'@example.com'; +var adminEmail = 'admin' + Math.round(Math.random() * 1000000) + '@example.com'; var adminPassword = '5f4dcc3b5aa765d61d8327deb882cf99'; var admin = { @@ -21,29 +21,37 @@ var admin = { var invalidUDID = 'invalid'; before(function(done){ - this.timeout(10000); + + this.timeout(25*DELAY); + var clientrequest = { "name": "test-app", "keys": [ common.appKey ] }; + request(url) .post('/admin/add') .send(admin) .end(function(err, res) { + setTimeout(function () { + request(url) .post('/admin/login') .set('Content-type','application/json') .send(admin) .end(function(err, res) { + var token = res.body.content.token; authValue = 'Bearer ' + token; + request(url) .post('/admin/app/add') .set('Content-type','application/json') .set('Authorization', authValue) .send(clientrequest) .end(function(err, res) { + appID = res.body.content.id; done(); }); @@ -53,6 +61,7 @@ before(function(done){ }); it('should return a success response to indicate device succesfully registered', function(done) { + var clientrequest = { "info": { "os": "Android", @@ -66,7 +75,8 @@ it('should return a success response to indicate device succesfully registered', "type": "android", "token": "android pn token" } - } + }; + request(url) .post('/device/register') .set('X-BLGREQ-SIGN', appIDsha256) @@ -74,6 +84,7 @@ it('should return a success response to indicate device succesfully registered', .set('X-BLGREQ-APPID', appID) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(200); res.body.content.identifier; done(); @@ -81,6 +92,7 @@ it('should return a success response to indicate device succesfully registered', }); it('should return a success response to indicate device succesfully registered with random udid', function(done) { + var clientrequest = { "info": { "os": "Android", @@ -94,7 +106,8 @@ it('should return a success response to indicate device succesfully registered w "type": "android", "token": "android pn token" } - } + }; + request(url) .post('/device/register') .set('X-BLGREQ-SIGN', appIDsha256) @@ -102,6 +115,7 @@ it('should return a success response to indicate device succesfully registered w .set('X-BLGREQ-APPID',1) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(200); res.body.content.identifier; done(); @@ -109,6 +123,7 @@ it('should return a success response to indicate device succesfully registered w }); it('should return an error response to indicate device succesfully registered, uuid missing from request', function(done) { + var clientrequest = { "info": { "os": "Android", @@ -122,7 +137,8 @@ it('should return an error response to indicate device succesfully registered, u "type": "android", "token": "android pn token" } - } + }; + request(url) .post('/device/register') .set('X-BLGREQ-SIGN', appIDsha256) @@ -130,18 +146,21 @@ it('should return an error response to indicate device succesfully registered, u .set('X-BLGREQ-APPID',1) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(200); done(); }); }); it('should return an error response to indicate device NOT succesfully registered because of missing info', function(done) { + var clientrequest = { "persistent": { "type": "android", "token": "android pn token" } - } + }; + request(url) .post('/device/register') .set('X-BLGREQ-SIGN', appIDsha256) @@ -149,13 +168,16 @@ it('should return an error response to indicate device NOT succesfully registere .set('X-BLGREQ-APPID',1) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return an error response to indicate device NOT succesfully registered because of missing body', function(done) { - var clientrequest = {} + + var clientrequest = {}; + request(url) .post('/device/register') .set('X-BLGREQ-SIGN', appIDsha256) @@ -163,12 +185,14 @@ it('should return an error response to indicate device NOT succesfully registere .set('X-BLGREQ-APPID',1) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return an error response to indicate device NOT succesfully registered because of invalid UDID', function(done) { + var clientrequest = { "info": { "os": "Android", @@ -182,7 +206,8 @@ it('should return an error response to indicate device NOT succesfully registere "type": "android", "token": "android pn token" } - } + }; + request(url) .post('/device/register') .set('X-BLGREQ-SIGN', appIDsha256) @@ -190,6 +215,7 @@ it('should return an error response to indicate device NOT succesfully registere .set('X-BLGREQ-APPID',appID) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(404); done(); }); diff --git a/test/object/object.js b/test/object/object.js index 1faa0ba..fac5f0d 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -60,7 +60,7 @@ var subclientrequest = { } }; -var adminEmail = 'admin'+Math.round(Math.random()*1000000)+'@example.com'; +var adminEmail = 'admin' + Math.round(Math.random()*1000000) + '@example.com'; var adminPassword = '5f4dcc3b5aa765d61d8327deb882cf99'; var admin = { @@ -71,77 +71,90 @@ var admin = { var invalidUDID = 'invalid'; before(function(done){ - this.timeout(10000); + + this.timeout(25*DELAY); + var clientrequest = { "name": "test-app", "keys": [ common.appKey ] }; + request(url) .post('/admin/add') .send(admin) .end(function(err, res) { + setTimeout(function () { + request(url) - .post('/admin/login') - .set('Content-type','application/json') - .send(admin) - .end(function(err, res) { - var token = res.body.content.token; - authValue = 'Bearer ' + token; - request(url) - .post('/admin/app/add') - .set('Content-type','application/json') - .set('Authorization', authValue) - .send(clientrequest) - .end(function(err, res) { - appID = res.body.content.id; - var clientrequest = { - "appId": appID, - "schema": { - "comments": { - "namespace": "comments", - "type": "comments", - "properties": { - "text": { - "type": "string" - } - }, - "read_acl": 6, - "write_acl": 6, - "meta_read_acl": 6 - } + .post('/admin/login') + .set('Content-type','application/json') + .send(admin) + .end(function(err, res) { + + var token = res.body.content.token; + authValue = 'Bearer ' + token; + + request(url) + .post('/admin/app/add') + .set('Content-type','application/json') + .set('Authorization', authValue) + .send(clientrequest) + .end(function(err, res) { + + appID = res.body.content.id; + var clientrequest = { + "appId": appID, + "schema": { + "comments": { + "namespace": "comments", + "type": "comments", + "properties": { + "text": { + "type": "string" + } + }, + "read_acl": 6, + "write_acl": 6, + "meta_read_acl": 6 } - }; - request(url) - .post('/admin/schema/update') - .set('Content-type','application/json') - .set('Authorization', authValue ) - .set('X-BLGREQ-APPID', appID ) - .send(clientrequest) - .end(function(err, res) { - var clientrequest = { - "name": "context" - } - request(url) - .post('/admin/context/add') - .set('Content-type','application/json') - .set('Authorization', authValue ) - .set('X-BLGREQ-APPID', appID ) - .send(clientrequest) - .end(function(err, res) { - var objectKey = Object.keys(res.body.content)[0]; - contextID = res.body.content.id; - done(); - }); - }); - }); - }); + } + }; + + request(url) + .post('/admin/schema/update') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .set('X-BLGREQ-APPID', appID ) + .send(clientrequest) + .end(function(err, res) { + + var clientrequest = { + "name": "context" + }; + + request(url) + .post('/admin/context/add') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .set('X-BLGREQ-APPID', appID ) + .send(clientrequest) + .end(function(err, res) { + + var objectKey = Object.keys(res.body.content)[0]; + contextID = res.body.content.id; + done(); + }); + }); + }); + }); }, 3*DELAY); }); }); before(function(done){ - this.timeout(13*DELAY); + + this.timeout(25*DELAY); var clientrequest = { "info": { @@ -156,7 +169,8 @@ before(function(done){ "type": "android", "token": "android pn token" } - } + }; + request(url) .post('/device/register') .set('X-BLGREQ-SIGN', appIDsha256) @@ -164,12 +178,14 @@ before(function(done){ .set('X-BLGREQ-APPID',appID) .send(clientrequest) .end(function(err, res) { + deviceIdentification = res.body.content.identifier; var clientrequest = { "email": 'admin'+Math.round(Math.random()*1000000)+'@example.com', "password": "secure_password1337", "name": "John Smith" }; + request(url) .post('/user/register') .set('Content-type','application/json') @@ -178,7 +194,9 @@ before(function(done){ .set('X-BLGREQ-UDID', deviceIdentification ) .send(clientrequest) .end(function(err, res) { + setTimeout(function () { + request(url) .post('/user/login_password') .set('Content-type','application/json') @@ -187,18 +205,22 @@ before(function(done){ .set('X-BLGREQ-UDID', deviceIdentification ) .send(clientrequest) .end(function(err, res) { + token = res.body.content.token; userAuthValue = 'Bearer ' + token; done(); }); - }, 7*DELAY); + }, 14*DELAY); }); }); }); it('should return an error (400) response to indicate that the client made a bad request', function(done) { + this.timeout(10*DELAY); + var clientrequest = {}; + request(url) .post('/object/create') .set('X-BLGREQ-SIGN', appIDsha256) @@ -207,6 +229,7 @@ it('should return an error (400) response to indicate that the client made a bad .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); @@ -220,6 +243,7 @@ it('should return an error (401) response to indicate that only authenticated us "content": { } }; + request(url) .post('/object/create') .set('X-BLGREQ-SIGN', appIDsha256) @@ -227,12 +251,14 @@ it('should return an error (401) response to indicate that only authenticated us .set('X-BLGREQ-APPID',appID) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(401); done(); }); }); it('should return a success response to indicate that object has been created', function(done) { + var clientrequest = { "model": "comments", "context": contextID, @@ -240,6 +266,7 @@ it('should return a success response to indicate that object has been created', "events_id" :1 } }; + request(url) .post('/object/create') .set('X-BLGREQ-SIGN', appIDsha256) @@ -248,6 +275,7 @@ it('should return a success response to indicate that object has been created', .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(202); res.body.content.should.be.equal("Created"); done(); @@ -255,6 +283,7 @@ it('should return a success response to indicate that object has been created', }); it('should return a success response to indicate that object has been created by an admin', function(done) { + var clientrequest = { "model": "comments", "context": contextID, @@ -262,6 +291,7 @@ it('should return a success response to indicate that object has been created by "events_id" :1 } }; + request(url) .post('/object/create') .set('X-BLGREQ-SIGN', appIDsha256) @@ -270,6 +300,7 @@ it('should return a success response to indicate that object has been created by .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(202); res.body.content.should.be.equal("Created"); done(); @@ -277,6 +308,7 @@ it('should return a success response to indicate that object has been created by }); it('should return an error response to indicate that object has NOT been created because of missing authentication', function(done) { + var clientrequest = { "model": "comments", "context": contextID, @@ -284,6 +316,7 @@ it('should return an error response to indicate that object has NOT been created "events_id" :1, } }; + request(url) .post('/object/create') .set('X-BLGREQ-SIGN', appIDsha256) @@ -291,18 +324,21 @@ it('should return an error response to indicate that object has NOT been created .set('X-BLGREQ-APPID',appID) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(401); done(); }); }); it('should return an error response to indicate that object has NOT been created because of missing model', function(done) { + var clientrequest = { "context": contextID, "content": { "events_id" :1, } }; + request(url) .post('/object/create') .set('X-BLGREQ-SIGN', appIDsha256) @@ -311,18 +347,21 @@ it('should return an error response to indicate that object has NOT been created .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return an error response to indicate that object has NOT been created because of missing context', function(done) { + var clientrequest = { "model": "comments", "content": { "events_id" :1, } }; + request(url) .post('/object/create') .set('X-BLGREQ-SIGN', appIDsha256) @@ -331,18 +370,21 @@ it('should return an error response to indicate that object has NOT been created .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return a success response to indicate the count of a certain filter/subscription', function(done) { + var clientrequest = { "channel": { "context": contextID, "model": "comments" } }; + request(url) .post('/object/count') .set('X-BLGREQ-SIGN', appIDsha256) @@ -351,6 +393,7 @@ it('should return a success response to indicate the count of a certain filter/s .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(200); done(); }); @@ -358,6 +401,7 @@ it('should return a success response to indicate the count of a certain filter/s it('should return a success response to indicate that a object has been updated', function(done) { + var clientrequest = { "model": "comments", "id": 1, @@ -370,6 +414,7 @@ it('should return a success response to indicate that a object has been updated' } ] }; + request(url) .post('/object/update') .set('X-BLGREQ-SIGN', appIDsha256) @@ -378,12 +423,14 @@ it('should return a success response to indicate that a object has been updated' .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(202); done(); }); }); it('should return a success response to indicate that a object has NOT been updated bacause of bad authentication', function(done) { + var clientrequest = { "model": "comments", "id": 1, @@ -396,6 +443,7 @@ it('should return a success response to indicate that a object has NOT been upda } ] }; + request(url) .post('/object/update') .set('X-BLGREQ-SIGN', appIDsha256) @@ -404,12 +452,14 @@ it('should return a success response to indicate that a object has NOT been upda .set('Authorization', authValue + '66' ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(401); done(); }); }); it('should return a success response to indicate that a object has NOT been updated because of missing authorization ', function(done) { + var clientrequest = { "model": "comments", "id": 1, @@ -421,7 +471,8 @@ it('should return a success response to indicate that a object has NOT been upda "value": "some edited text" }, ] - } + }; + request(url) .post('/object/update') .set('X-BLGREQ-SIGN', appIDsha256) @@ -429,12 +480,14 @@ it('should return a success response to indicate that a object has NOT been upda .set('X-BLGREQ-APPID',appID) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(401); done(); }); }); it('should return a success response to indicate that a object has NOT been updated because of missing id', function(done) { + var clientrequest = { "model": "comments", "context": contextID, @@ -445,7 +498,8 @@ it('should return a success response to indicate that a object has NOT been upda "value": "some edited text" }, ], - } + }; + request(url) .post('/object/update') .set('X-BLGREQ-SIGN', appIDsha256) @@ -454,12 +508,14 @@ it('should return a success response to indicate that a object has NOT been upda .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return a success response to indicate that a object has NOT been updated because of missing context ', function(done) { + var clientrequest = { "model": "comments", "id": 1, @@ -470,7 +526,8 @@ it('should return a success response to indicate that a object has NOT been upda "value": "some edited text" }, ], - } + }; + request(url) .post('/object/update') .set('X-BLGREQ-SIGN', appIDsha256) @@ -479,18 +536,21 @@ it('should return a success response to indicate that a object has NOT been upda .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return a success response to indicate that a object has been subscribed', function(done) { + var subclientrequest = { "channel": { "context": contextID, "model": "comments" } }; + request(url) .post('/object/subscribe') .set('Content-type','application/json') @@ -500,13 +560,16 @@ it('should return a success response to indicate that a object has been subscrib .set('Authorization', userAuthValue ) .send(subclientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(200); done(); }); }); it('should return an error response to indicate that a object has NOT been subscribed because of empty body', function(done) { + var subclientrequest = {}; + request(url) .post('/object/subscribe') .set('Content-type','application/json') @@ -516,12 +579,14 @@ it('should return an error response to indicate that a object has NOT been subsc .set('Authorization', userAuthValue ) .send() .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return an error response to indicate that a object has NOT been subscribed because of missing channel', function(done) { + var subclientrequest = { "filters": { "or": [ @@ -566,18 +631,21 @@ it('should return an error response to indicate that a object has NOT been subsc .set('Authorization', userAuthValue ) .send() .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return a success response to indicate that a object has been unsubscribed', function(done) { + var subclientrequest = { "channel": { "context": contextID, "model": "comments" } }; + request(url) .post('/object/unsubscribe') .set('X-BLGREQ-SIGN', appIDsha256) @@ -586,12 +654,14 @@ it('should return a success response to indicate that a object has been unsubscr .set('Authorization', userAuthValue) .send(subclientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(200); done(); }); }); it('should return a success response to indicate that a object has NOT been unsubscribed because of empty body', function(done) { + var subclientrequest = {}; request(url) @@ -602,12 +672,14 @@ it('should return a success response to indicate that a object has NOT been unsu .set('Authorization', userAuthValue) .send(subclientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return a success response to indicate that a object has NOT been unsubscribed because of missing channel', function(done) { + var subclientrequest = { "something": {} }; @@ -626,6 +698,7 @@ it('should return a success response to indicate that a object has NOT been unsu }); it('should return a success response to indicate that a object has NOT been unsubscribed because of missing context', function(done) { + var subclientrequest = { "channel": { "model": "comments" @@ -640,12 +713,14 @@ it('should return a success response to indicate that a object has NOT been unsu .set('Authorization', userAuthValue) .send(subclientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return a success response to indicate that a object has NOT been unsubscribed because of missing model', function(done) { + var subclientrequest = { "channel": { "context": contextID @@ -660,17 +735,20 @@ it('should return a success response to indicate that a object has NOT been unsu .set('Authorization', userAuthValue) .send(subclientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return a success response to indicate that a object has been deleted', function(done) { + var clientrequest = { "model": "comments", "context": contextID, "id" : 1, }; + request(url) .post('/object/delete') .set('X-BLGREQ-SIGN', appIDsha256) @@ -679,36 +757,42 @@ it('should return a success response to indicate that a object has been deleted' .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(202); done(); }); }); -// it('should return an error response to indicate that a object was NOT deleted', function(done) { -// this.timeout(10000); -// setTimeout(function() { -// var clientrequest = { -// "model": "comments", -// "context": 1, -// "id" : 1, -// }; - -// request(url) -// .post('/object/delete') -// .set('X-BLGREQ-SIGN', appIDsha256) -// .set('X-BLGREQ-UDID', deviceIdentification) -// .set('X-BLGREQ-APPID',1) -// .set('Authorization', authValue ) -// .send(clientrequest) -// .end(function(err, res) { -// res.statusCode.should.be.equal(404); -// done(); -// }); -// }, 5500); - -// }); +it('should return an error response to indicate that a object was NOT deleted', function(done) { + + this.timeout(20*DELAY); + + setTimeout(function() { + + var clientrequest = { + "model": "comments", + "context": 1, + "id" : 1, + }; + + request(url) + .post('/object/delete') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',1) + .set('Authorization', authValue ) + .send(clientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(404); + done(); + }); + }, 14*DELAY); + +}); it('should return an error response to indicate that the object id was missing', function(done) { + var clientrequest = { "model": "comments", "context": contextID, @@ -724,18 +808,21 @@ it('should return an error response to indicate that the object id was missing', .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return an error response to indicate that the object model was missing', function(done) { + var clientrequest = { "context": contextID, "id" : 1, "content": { } - } + }; + request(url) .post('/object/delete') .set('X-BLGREQ-SIGN', appIDsha256) @@ -744,12 +831,14 @@ it('should return an error response to indicate that the object model was missin .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); }); it('should return an error response to indicate that the object was not deleted because of missing authentication', function(done) { + var clientrequest = { "model": "comments", "context": contextID, @@ -757,6 +846,7 @@ it('should return an error response to indicate that the object was not deleted "content": { } }; + request(url) .post('/object/delete') .set('X-BLGREQ-SIGN', appIDsha256) @@ -764,18 +854,21 @@ it('should return an error response to indicate that the object was not deleted .set('X-BLGREQ-APPID',appID) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(401); done(); }); }); it('should return an error response to indicate that the object was not deleted because of missing context', function(done) { + var clientrequest = { "model": "comments", "id" : 1, "content": { } - } + }; + request(url) .post('/object/delete') .set('X-BLGREQ-SIGN', appIDsha256) @@ -784,6 +877,7 @@ it('should return an error response to indicate that the object was not deleted .set('Authorization', userAuthValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(400); done(); }); diff --git a/test/user/user.js b/test/user/user.js index 4a3d71f..59f6b5c 100644 --- a/test/user/user.js +++ b/test/user/user.js @@ -28,7 +28,10 @@ var admin = { }; before(function(done){ - var clientrequest = { + + this.timeout(10000); + + var deviceRegisterRequest = { "info": { "os": "Android", "version": "4.4.3", @@ -41,13 +44,14 @@ before(function(done){ "type": "android", "token": "android pn token" } - } + }; - this.timeout(10000); - var clientrequest = { + + var appRequest = { "name": "test-app", "keys": [ common.appKey ] }; + request(url) .post('/admin/add') .send(admin) @@ -58,36 +62,27 @@ before(function(done){ .set('Content-type','application/json') .send(admin) .end(function(err, res) { + var token = res.body.content.token; adminAuthValue = 'Bearer ' + token; + request(url) .post('/admin/app/add') .set('Content-type','application/json') .set('Authorization', adminAuthValue) - .send(clientrequest) + .send(appRequest) .end(function(err, res) { + appID = res.body.content.id; - var clientrequest = { - "info": { - "os": "Android", - "version": "4.4.3", - "sdk_level": 19, - "manufacturer": "HTC", - "model": "HTC One_M8", - "udid": invalidUDID - }, - "persistent": { - "type": "android", - "token": "android pn token" - } - } + request(url) .post('/device/register') .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', '') .set('X-BLGREQ-APPID',appID) - .send(clientrequest) + .send(deviceRegisterRequest) .end(function(err, res) { + deviceIdentification = res.body.content.identifier; done(); }); @@ -102,26 +97,29 @@ it('should return an error response to indicate that the user has NOT logged via var clientrequest = {}; request(url) - .post('/user/login') - .set('Content-type','application/json') - .set('X-BLGREQ-SIGN', appIDsha256 ) - .set('X-BLGREQ-APPID', appID ) - .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) - .send(clientrequest) - .end(function(err, res) { - //console.log(res.body); - res.statusCode.should.be.equal(400); - done(); - }); + .post('/user/login') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .send(clientrequest) + .end(function(err, res) { + //console.log(res.body); + res.statusCode.should.be.equal(400); + done(); + }); }); it('should return a success response to indicate that the user has logged in via user & password', function(done) { + this.timeout(10*DELAY); + var clientrequest = { "email": userEmail, "password": "secure_password1337", "name": "John Smith" }; + request(url) .post('/user/register') .set('Content-type','application/json') @@ -139,9 +137,11 @@ it('should return a success response to indicate that the user has logged in via .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { + token = res.body.content.token; userID = res.body.content.user.id; authValue = 'Bearer ' + token; + res.statusCode.should.be.equal(200); done(); }); @@ -150,7 +150,9 @@ it('should return a success response to indicate that the user has logged in via }); it('should return a success response to indicate that the user has logged in via Facebook', function(done) { + this.timeout(15*DELAY); + request('https://graph.facebook.com') .get('/oauth/access_token?client_id=1086083914753251&client_secret=40f626ca66e4472e0d11c22f048e9ea8&grant_type=client_credentials') .send() @@ -159,10 +161,12 @@ it('should return a success response to indicate that the user has logged in via .get('/v1.0/1086083914753251/accounts/test-users?access_token='+res.text.replace('access_token=', '')) .send() .end(function(err, res) { + var data = JSON.parse(res.text); var clientrequest = { "access_token": data.data[0].access_token }; + request(url) .post('/user/register') .set('Content-type','application/json') @@ -180,9 +184,7 @@ it('should return a success response to indicate that the user has logged in via .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { - //token = res.body.content.token; - //userID = res.body.content.user.id; - //authValue = 'Bearer ' + token; + res.statusCode.should.be.equal(200); done(); }); @@ -193,6 +195,7 @@ it('should return a success response to indicate that the user has logged in via }); it('should return a success response to indicate that the user info was retrived', function(done) { + request(url) .get('/user/me') .set('Content-type','application/json') @@ -202,17 +205,20 @@ it('should return a success response to indicate that the user info was retrived .set('Authorization', authValue ) .send() .end(function(err, res) { + res.statusCode.should.be.equal(200); done(); }); }); it('should return an error response to indicate that the user has NOT logged in via user & password because of Invalid Credentials', function(done) { + var clientrequest = { "email": userEmail, "password": "secure_password", "name": "John Smith" }; + request(url) .post('/user/login_password') .set('Content-type','application/json') @@ -221,17 +227,20 @@ it('should return an error response to indicate that the user has NOT logged in .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(401); done(); }); }); it('should return an error response to indicate that the user has NOT logged in via user & password because user not found', function(done) { + var clientrequest = { "email": 'user'+Math.round(Math.random()*1000000)+'@example.com', "password": "secure_password", "name": "John Smith" }; + request(url) .post('/user/login_password') .set('Content-type','application/json') @@ -246,6 +255,7 @@ it('should return an error response to indicate that the user has NOT logged in }); it('should return a success response to indicate that the user was updated', function(done) { + var clientrequest = { "patches" : [ { @@ -255,6 +265,7 @@ it('should return a success response to indicate that the user was updated', fun } ] }; + request(url) .post('/user/update') .set('Content-type','application/json') @@ -270,6 +281,7 @@ it('should return a success response to indicate that the user was updated', fun }); it('should return a success response to indicate that the token was updated', function(done) { + request(url) .get('/user/refresh_token') .set('Content-type','application/json') @@ -279,15 +291,19 @@ it('should return a success response to indicate that the token was updated', fu .set('Authorization', authValue ) .send() .end(function(err, res) { + token = res.body.content.token; authValue = 'Bearer ' + token; + res.statusCode.should.be.equal(200); done(); }); }); it('should return an error response to indicate that the token was NOT updated because of bad Authorization', function(done) { + var authValue = "something"; + request(url) .get('/user/refresh_token') .set('Content-type','application/json') @@ -297,13 +313,16 @@ it('should return an error response to indicate that the token was NOT updated b .set('Authorization', authValue ) .send() .end(function(err, res) { + res.statusCode.should.be.equal(401); done(); }); }); it('should return an error response to indicate that the token was NOT updated because of bad token', function(done) { + var authValue = 'Bearer something'; + request(url) .get('/user/refresh_token') .set('Content-type','application/json') @@ -313,6 +332,7 @@ it('should return an error response to indicate that the token was NOT updated b .set('Authorization', authValue ) .send() .end(function(err, res) { + res.statusCode.should.be.equal(400); res.body.message.should.be.equal("Malformed authorization token"); done(); @@ -320,6 +340,7 @@ it('should return an error response to indicate that the token was NOT updated b }); it('should return a success response to indicate that the user logged out', function(done) { + request(url) .get('/user/logout') .set('Content-type','application/json') @@ -329,17 +350,20 @@ it('should return a success response to indicate that the user logged out', func .set('Authorization', authValue) .send() .end(function(err, res) { + res.statusCode.should.be.equal(200); done(); }); }); it('should return a success response to indicate that the user has registered', function(done) { + var clientrequest = { "email": userEmail2, "password": "secure_password1337", "name": "John Smith" }; + request(url) .post('/user/register') .set('Content-type','application/json') @@ -348,17 +372,20 @@ it('should return a success response to indicate that the user has registered', .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(202); done(); }); }); it('should return a success response to indicate that the user has NOT registered', function(done) { + var clientrequest = { "email": userEmail, "password": "secure_password1337", "name": "John Smith" }; + request(url) .post('/user/register') .set('Content-type','application/json') @@ -367,17 +394,20 @@ it('should return a success response to indicate that the user has NOT registere .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(409); done(); }); }); it('should return a success response to indicate that the user was deleted', function(done) { + var clientrequest = { "email": userEmail, "password": "secure_password1337", "name": "John Smith" }; + request(url) .post('/user/login_password') .set('Content-type','application/json') @@ -386,6 +416,7 @@ it('should return a success response to indicate that the user was deleted', fun .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { + token = res.body.content.token; userID = res.body.content.user.id; authValue = 'Bearer ' + token; @@ -393,6 +424,7 @@ it('should return a success response to indicate that the user was deleted', fun "id" : userID, "email" : userEmail }; + request(url) .post('/user/delete') .set('X-BLGREQ-SIGN', appIDsha256) @@ -401,6 +433,7 @@ it('should return a success response to indicate that the user was deleted', fun .set('Authorization', authValue) .send(subclientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(202); done(); }); From 5f207f934358624c60dc79441adc3d241f35c8ea Mon Sep 17 00:00:00 2001 From: Sergiu Alexandrescu Date: Tue, 29 Sep 2015 12:03:33 +0000 Subject: [PATCH 06/42] added more tests --- controllers/admin.js | 30 ++-- test/context/context.js | 2 +- test/device/device.js | 84 ++++++---- test/object/object.js | 342 ++++++++++++++++++++++++++++------------ 4 files changed, 315 insertions(+), 143 deletions(-) diff --git a/controllers/admin.js b/controllers/admin.js index 202fcba..4fa6dc9 100644 --- a/controllers/admin.js +++ b/controllers/admin.js @@ -12,21 +12,21 @@ var userRoute = require('./admin/user'); var security = require('./security'); var Models = require('telepat-models'); -var unless = function(paths, middleware) { - return function(req, res, next) { - var excluded = false; - for (var i=0; i Date: Tue, 29 Sep 2015 15:13:44 +0300 Subject: [PATCH 07/42] Lowered the global delay of tests. Fixed merge conflicts. --- test/common.js | 2 +- test/user/user.js | 107 ++++++++++++++++++++++------------------------ 2 files changed, 53 insertions(+), 56 deletions(-) diff --git a/test/common.js b/test/common.js index b011608..3d89fb6 100644 --- a/test/common.js +++ b/test/common.js @@ -8,7 +8,7 @@ var logLevel = process.env.TP_TST_LOG || 1; exports.url = 'http://localhost:3000'; exports.appKey = appKey; exports.appIDsha256 = crypto.SHA256(appKey).toString(crypto.enc.Hex); -exports.DELAY = 400; +exports.DELAY = 100; exports.logLevel = logLevel; function highjackEnd(request) { diff --git a/test/user/user.js b/test/user/user.js index 59f6b5c..9208b01 100644 --- a/test/user/user.js +++ b/test/user/user.js @@ -1,8 +1,6 @@ var common = require('../common'); var request = common.request; var should = common.should; -var assert = common.assert; -var crypto = common.crypto; var url = common.url; var DELAY = common.DELAY; @@ -10,7 +8,6 @@ var appIDsha256 = common.appIDsha256; var deviceIdentification; var invalidUDID = 'invalid'; -var appIDsha256 = common.appIDsha256; var authValue; var adminAuthValue; var token; @@ -28,9 +25,9 @@ var admin = { }; before(function(done){ - + this.timeout(10000); - + var deviceRegisterRequest = { "info": { "os": "Android", @@ -45,13 +42,13 @@ before(function(done){ "token": "android pn token" } }; - + var appRequest = { "name": "test-app", "keys": [ common.appKey ] }; - + request(url) .post('/admin/add') .send(admin) @@ -62,17 +59,17 @@ before(function(done){ .set('Content-type','application/json') .send(admin) .end(function(err, res) { - + var token = res.body.content.token; adminAuthValue = 'Bearer ' + token; - + request(url) .post('/admin/app/add') .set('Content-type','application/json') .set('Authorization', adminAuthValue) .send(appRequest) .end(function(err, res) { - + appID = res.body.content.id; request(url) @@ -82,7 +79,7 @@ before(function(done){ .set('X-BLGREQ-APPID',appID) .send(deviceRegisterRequest) .end(function(err, res) { - + deviceIdentification = res.body.content.identifier; done(); }); @@ -111,15 +108,15 @@ it('should return an error response to indicate that the user has NOT logged via }); it('should return a success response to indicate that the user has logged in via user & password', function(done) { - - this.timeout(10*DELAY); - + + this.timeout(13*DELAY); + var clientrequest = { "email": userEmail, "password": "secure_password1337", "name": "John Smith" }; - + request(url) .post('/user/register') .set('Content-type','application/json') @@ -137,11 +134,11 @@ it('should return a success response to indicate that the user has logged in via .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { - + token = res.body.content.token; userID = res.body.content.user.id; authValue = 'Bearer ' + token; - + res.statusCode.should.be.equal(200); done(); }); @@ -150,9 +147,7 @@ it('should return a success response to indicate that the user has logged in via }); it('should return a success response to indicate that the user has logged in via Facebook', function(done) { - - this.timeout(15*DELAY); - + this.timeout(100*DELAY); request('https://graph.facebook.com') .get('/oauth/access_token?client_id=1086083914753251&client_secret=40f626ca66e4472e0d11c22f048e9ea8&grant_type=client_credentials') .send() @@ -161,12 +156,12 @@ it('should return a success response to indicate that the user has logged in via .get('/v1.0/1086083914753251/accounts/test-users?access_token='+res.text.replace('access_token=', '')) .send() .end(function(err, res) { - + var data = JSON.parse(res.text); var clientrequest = { "access_token": data.data[0].access_token }; - + request(url) .post('/user/register') .set('Content-type','application/json') @@ -184,18 +179,20 @@ it('should return a success response to indicate that the user has logged in via .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { - + //token = res.body.content.token; + //userID = res.body.content.user.id; + //authValue = 'Bearer ' + token; res.statusCode.should.be.equal(200); done(); }); - }, 4*DELAY); + }, 1); }); }); }); }); it('should return a success response to indicate that the user info was retrived', function(done) { - + request(url) .get('/user/me') .set('Content-type','application/json') @@ -205,20 +202,20 @@ it('should return a success response to indicate that the user info was retrived .set('Authorization', authValue ) .send() .end(function(err, res) { - + res.statusCode.should.be.equal(200); done(); }); }); it('should return an error response to indicate that the user has NOT logged in via user & password because of Invalid Credentials', function(done) { - + var clientrequest = { "email": userEmail, "password": "secure_password", "name": "John Smith" }; - + request(url) .post('/user/login_password') .set('Content-type','application/json') @@ -227,20 +224,20 @@ it('should return an error response to indicate that the user has NOT logged in .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(401); done(); }); }); it('should return an error response to indicate that the user has NOT logged in via user & password because user not found', function(done) { - + var clientrequest = { "email": 'user'+Math.round(Math.random()*1000000)+'@example.com', "password": "secure_password", "name": "John Smith" }; - + request(url) .post('/user/login_password') .set('Content-type','application/json') @@ -255,7 +252,7 @@ it('should return an error response to indicate that the user has NOT logged in }); it('should return a success response to indicate that the user was updated', function(done) { - + var clientrequest = { "patches" : [ { @@ -265,7 +262,7 @@ it('should return a success response to indicate that the user was updated', fun } ] }; - + request(url) .post('/user/update') .set('Content-type','application/json') @@ -281,7 +278,7 @@ it('should return a success response to indicate that the user was updated', fun }); it('should return a success response to indicate that the token was updated', function(done) { - + request(url) .get('/user/refresh_token') .set('Content-type','application/json') @@ -291,19 +288,19 @@ it('should return a success response to indicate that the token was updated', fu .set('Authorization', authValue ) .send() .end(function(err, res) { - + token = res.body.content.token; authValue = 'Bearer ' + token; - + res.statusCode.should.be.equal(200); done(); }); }); it('should return an error response to indicate that the token was NOT updated because of bad Authorization', function(done) { - + var authValue = "something"; - + request(url) .get('/user/refresh_token') .set('Content-type','application/json') @@ -313,16 +310,16 @@ it('should return an error response to indicate that the token was NOT updated b .set('Authorization', authValue ) .send() .end(function(err, res) { - + res.statusCode.should.be.equal(401); done(); }); }); it('should return an error response to indicate that the token was NOT updated because of bad token', function(done) { - + var authValue = 'Bearer something'; - + request(url) .get('/user/refresh_token') .set('Content-type','application/json') @@ -332,7 +329,7 @@ it('should return an error response to indicate that the token was NOT updated b .set('Authorization', authValue ) .send() .end(function(err, res) { - + res.statusCode.should.be.equal(400); res.body.message.should.be.equal("Malformed authorization token"); done(); @@ -340,7 +337,7 @@ it('should return an error response to indicate that the token was NOT updated b }); it('should return a success response to indicate that the user logged out', function(done) { - + request(url) .get('/user/logout') .set('Content-type','application/json') @@ -350,20 +347,20 @@ it('should return a success response to indicate that the user logged out', func .set('Authorization', authValue) .send() .end(function(err, res) { - + res.statusCode.should.be.equal(200); done(); }); }); it('should return a success response to indicate that the user has registered', function(done) { - + var clientrequest = { "email": userEmail2, "password": "secure_password1337", "name": "John Smith" }; - + request(url) .post('/user/register') .set('Content-type','application/json') @@ -372,20 +369,20 @@ it('should return a success response to indicate that the user has registered', .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(202); done(); }); }); it('should return a success response to indicate that the user has NOT registered', function(done) { - + var clientrequest = { "email": userEmail, "password": "secure_password1337", "name": "John Smith" }; - + request(url) .post('/user/register') .set('Content-type','application/json') @@ -394,20 +391,20 @@ it('should return a success response to indicate that the user has NOT registere .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(409); done(); }); }); it('should return a success response to indicate that the user was deleted', function(done) { - + var clientrequest = { "email": userEmail, "password": "secure_password1337", "name": "John Smith" }; - + request(url) .post('/user/login_password') .set('Content-type','application/json') @@ -416,7 +413,7 @@ it('should return a success response to indicate that the user was deleted', fun .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { - + token = res.body.content.token; userID = res.body.content.user.id; authValue = 'Bearer ' + token; @@ -424,7 +421,7 @@ it('should return a success response to indicate that the user was deleted', fun "id" : userID, "email" : userEmail }; - + request(url) .post('/user/delete') .set('X-BLGREQ-SIGN', appIDsha256) @@ -433,7 +430,7 @@ it('should return a success response to indicate that the user was deleted', fun .set('Authorization', authValue) .send(subclientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(202); done(); }); From 453cce968dfd56690781401a2168d432f6b2efed Mon Sep 17 00:00:00 2001 From: Sergiu Alexandrescu Date: Tue, 29 Sep 2015 12:46:45 +0000 Subject: [PATCH 08/42] added new object tests --- test/object/object.js | 220 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 212 insertions(+), 8 deletions(-) diff --git a/test/object/object.js b/test/object/object.js index fc0abc5..60cf2de 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -422,6 +422,49 @@ it('should return a success response to indicate the count of a certain filter/s }); }); +it('should return an error response because of invalid channel request', function(done) { + + var clientrequest = { + "channel": { + "context": contextID, + "model": "comments", + "parent": "parent", + "user": "user" + }, + filters: {} + }; + + request(url) + .post('/object/count') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send(clientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('should return an error response to indicate the count was not returned because of empty request', function(done) { + + request(url) + .post('/object/count') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send() + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); +}); + + it('should return a success response to indicate that a object has been updated', function(done) { @@ -476,7 +519,7 @@ it('should return a success response to indicate that a object has NOT been upda .send(clientrequest) .end(function(err, res) { - res.statusCode.should.be.equal(401); + res.statusCode.should.be.equal(400); done(); }); }); @@ -487,7 +530,7 @@ it('should return a success response to indicate that a object has NOT been upda "model": "comments", "id": 1, "context": contextID, - "patch": [ + "patches": [ { "op": "replace", "path": "comments/1/text", @@ -514,7 +557,7 @@ it('should return a success response to indicate that a object has NOT been upda var clientrequest = { "model": "comments", "context": contextID, - "patch": [ + "patches": [ { "op": "replace", "path": "comments/1/text", @@ -542,7 +585,63 @@ it('should return a success response to indicate that a object has NOT been upda var clientrequest = { "model": "comments", "id": 1, - "patch": [ + "patches": [ + { + "op": "replace", + "path": "comments/1/text", + "value": "some edited text" + }, + ], + }; + + request(url) + .post('/object/update') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send(clientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('should return a success response to indicate that a object has NOT been updated because of model not found ', function(done) { + + var clientrequest = { + "model": "thingy", + "id": 1, + "patches": [ + { + "op": "replace", + "path": "thingy/1/text", + "value": "some edited text" + }, + ], + }; + + request(url) + .post('/object/update') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send(clientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('should return a success response to indicate that a object has NOT been updated because of missing model ', function(done) { + + var clientrequest = { + "context": contextID, + "id": 1, + "patches": [ { "op": "replace", "path": "comments/1/text", @@ -565,6 +664,69 @@ it('should return a success response to indicate that a object has NOT been upda }); }); +it('should return a success response to indicate that a object has NOT been updated because patches is not an array ', function(done) { + + var clientrequest = { + "context": contextID, + "model": "comments", + "id": 1, + "patches": {}, + }; + + request(url) + .post('/object/update') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send(clientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('should return a success response to indicate that a object has NOT been updated because patches is an empty array', function(done) { + + var clientrequest = { + "context": contextID, + "model": "comments", + "id": 1, + "patches": [], + }; + + request(url) + .post('/object/update') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send(clientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('should return a success response to indicate that a object has NOT been updated because of empty request ', function(done) { + + request(url) + .post('/object/update') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send() + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); +}); + + it('should return a success response to indicate that a object has been subscribed', function(done) { var subclientrequest = { @@ -615,7 +777,7 @@ it('should return a success response to indicate that a object has NOT been subs }); }); -it('should return a success response to indicate that a object has NOT been subscribed because id was not found', function(done) { +it('should return a success response to indicate that a object has NOT been subscribed because object was not found', function(done) { var subclientrequest = { "channel": { @@ -784,7 +946,8 @@ it('should return a success response to indicate that a object has been unsubscr var subclientrequest = { "channel": { "context": contextID, - "model": "comments" + "model": "comments", + "id" : "66" } }; @@ -804,14 +967,38 @@ it('should return a success response to indicate that a object has been unsubscr it('should return a success response to indicate that a object has NOT been unsubscribed because of empty body', function(done) { - var subclientrequest = {}; - request(url) .post('/object/unsubscribe') .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification) .set('X-BLGREQ-APPID',appID) .set('Authorization', userAuthValue) + .send() + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('should return a success response to indicate that a object has NOT been unsubscribed', function(done) { + + var subclientrequest = { + "channel": { + "context": contextID, + "model": "comments", + "parent": "parent", + "user": "user" + } + }; + + request(url) + .post('/object/unsubscribe') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) .send(subclientrequest) .end(function(err, res) { @@ -820,6 +1007,7 @@ it('should return a success response to indicate that a object has NOT been unsu }); }); + it('should return a success response to indicate that a object has NOT been unsubscribed because of missing channel', function(done) { var subclientrequest = { @@ -1024,3 +1212,19 @@ it('should return an error response to indicate that the object was not deleted done(); }); }); + +it('should return an error response to indicate that the object was not deleted because of empty request', function(done) { + + request(url) + .post('/object/delete') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send() + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); +}); From 614e0e43174586e120f1a5ba1d224b8158b88531 Mon Sep 17 00:00:00 2001 From: Razvan Botea Date: Tue, 29 Sep 2015 16:18:42 +0300 Subject: [PATCH 09/42] Fixed /object/subscribe error response when object doesn't exist * fixed 500 error message when auth token is malphormed * fixed test error status code --- controllers/object.js | 42 +++++++++++++++++++++++++---------------- controllers/security.js | 7 ++++++- test/object/object.js | 2 +- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/controllers/object.js b/controllers/object.js index e04bbf1..efc4cf4 100644 --- a/controllers/object.js +++ b/controllers/object.js @@ -33,9 +33,7 @@ router.use(['/count'], security.objectACL('meta_read_acl')); var validateContext = function(appId, context, callback) { Models.Application.hasContext(appId, context, function(err, result) { - if (err && err.status == 404) { - callback(new Models.TelepatError(Models.TelepatError.errors.ApplicationNotFound)); - } else if (err) + if (err) return callback(err); else if (result === false) { callback(new Models.TelepatError(Models.TelepatError.errors.InvalidContext, [context, appId])); @@ -175,7 +173,9 @@ router.post('/subscribe', function(req, res, next) { return next(new Models.TelepatError(Models.TelepatError.errors.InvalidChannel)); } - async.waterfall([ + var objects = []; + + async.series([ //verify if context belongs to app function(callback) { validateContext(appId, context, callback); @@ -190,25 +190,35 @@ router.post('/subscribe', function(req, res, next) { callback(); }); }, - function(callback) { - Models.Subscription.add(deviceId, channelObject, function(err) { - if (err && err.status === 409) - return callback(); - - callback(err); - }); - }, function(callback) { if (id) { Models.Model(mdl, appId, context, id, function(err, results) { if (err) return callback(err); - callback(null, results); + objects.push(results); + + callback(); }); } else { - Models.Model.search(channelObject, callback); + Models.Model.search(channelObject, function(err, results) { + if (err) return callback(err); + + if (Array.isArray(results)) + objects.concat(results); + + callback(); + }); } - }/*, + }, + function(callback) { + Models.Subscription.add(deviceId, channelObject, function(err) { + if (err && err.status === 409) + return callback(); + + callback(err); + }); + } + /*, function(results, callback) { app.kafkaProducer.send([{ topic: 'track', @@ -489,7 +499,7 @@ router.post('/create', function(req, res, next) { * "model": "comment", * "id": 1, * "context": 1, - * "patch": [ + * "patches": [ * { * "op": "replace", * "path": "comment/1/text", diff --git a/controllers/security.js b/controllers/security.js index 3907000..e58b6d4 100644 --- a/controllers/security.js +++ b/controllers/security.js @@ -104,7 +104,12 @@ security.tokenValidation = function(req, res, next) { if (!req.headers.authorization) return next(new Models.TelepatError(Models.TelepatError.errors.AuthorizationMissing)); - return (expressJwt({secret: security.authSecret}))(req, res, next); + return (expressJwt({secret: security.authSecret}))(req, res, function(err) { + if (err && err.message == 'invalid signature') { + return next(new Models.TelepatError(Models.TelepatError.errors.MalformedAuthorizationToken)) + } else + return next(err); + }); }; security.adminAppValidation = function (req, res, next) { diff --git a/test/object/object.js b/test/object/object.js index fc0abc5..44b7304 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -476,7 +476,7 @@ it('should return a success response to indicate that a object has NOT been upda .send(clientrequest) .end(function(err, res) { - res.statusCode.should.be.equal(401); + res.statusCode.should.be.equal(400); done(); }); }); From 35ac9e0614f492d52c87b1cb67dec15d07155dd1 Mon Sep 17 00:00:00 2001 From: Andrei Marinescu Date: Tue, 29 Sep 2015 16:30:19 +0300 Subject: [PATCH 10/42] sudo false in travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 18e896b..fc31786 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: node_js +sudo: false services: - elasticsearch - redis From a3bda1f1af29613e7d06acd17eef12d6c67f31c9 Mon Sep 17 00:00:00 2001 From: Sergiu Alexandrescu Date: Tue, 29 Sep 2015 13:35:44 +0000 Subject: [PATCH 11/42] added update_immidiate test --- test/common.js | 2 +- test/object/object.js | 8 ++-- test/user/user.js | 106 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 5 deletions(-) diff --git a/test/common.js b/test/common.js index 3d89fb6..b011608 100644 --- a/test/common.js +++ b/test/common.js @@ -8,7 +8,7 @@ var logLevel = process.env.TP_TST_LOG || 1; exports.url = 'http://localhost:3000'; exports.appKey = appKey; exports.appIDsha256 = crypto.SHA256(appKey).toString(crypto.enc.Hex); -exports.DELAY = 100; +exports.DELAY = 400; exports.logLevel = logLevel; function highjackEnd(request) { diff --git a/test/object/object.js b/test/object/object.js index 60cf2de..98440b2 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -552,7 +552,7 @@ it('should return a success response to indicate that a object has NOT been upda }); }); -it('should return a success response to indicate that a object has NOT been updated because of missing id', function(done) { +it('should return an error response to indicate that a object has NOT been updated because of missing id', function(done) { var clientrequest = { "model": "comments", @@ -608,7 +608,7 @@ it('should return a success response to indicate that a object has NOT been upda }); }); -it('should return a success response to indicate that a object has NOT been updated because of model not found ', function(done) { +it('should return an error response to indicate that a object has NOT been updated because of model not found ', function(done) { var clientrequest = { "model": "thingy", @@ -631,7 +631,7 @@ it('should return a success response to indicate that a object has NOT been upda .send(clientrequest) .end(function(err, res) { - res.statusCode.should.be.equal(400); + res.statusCode.should.be.equal(404); done(); }); }); @@ -777,7 +777,7 @@ it('should return a success response to indicate that a object has NOT been subs }); }); -it('should return a success response to indicate that a object has NOT been subscribed because object was not found', function(done) { +it('should return an error response to indicate that a object has NOT been subscribed because object was not found', function(done) { var subclientrequest = { "channel": { diff --git a/test/user/user.js b/test/user/user.js index 9208b01..a2bba92 100644 --- a/test/user/user.js +++ b/test/user/user.js @@ -277,6 +277,112 @@ it('should return a success response to indicate that the user was updated', fun }); }); +it('should return a success response to indicate that the user password was updated', function(done) { + + var clientrequest = { + "patches" : [ + { + "op": "replace", + "path": "user/"+userID+"/password", + "value": "new value" + } + ] + }; + + request(url) + .post('/user/update') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .set('Authorization', authValue ) + .send(clientrequest) + .end(function(err, res) { + res.statusCode.should.be.equal(202); + done(); + }); +}); + +it('should return a success response to indicate that the user password was NOT updated because of empty request body', function(done) { + + request(url) + .post('/user/update') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .set('Authorization', authValue ) + .send() + .end(function(err, res) { + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('should return a success response to indicate that the user password was NOT updated because patches is not an array', function(done) { + + var clientrequest = { + "patches" : {} + }; + + request(url) + .post('/user/update') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .set('Authorization', authValue ) + .send(clientrequest) + .end(function(err, res) { + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('should return a success response to indicate that the user password was NOT updated because patches is an empty array', function(done) { + + var clientrequest = { + "patches" : [] + }; + + request(url) + .post('/user/update') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .set('Authorization', authValue ) + .send(clientrequest) + .end(function(err, res) { + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('should return a success response to indicate that the user was updated immidiate', function(done) { + + this.timeout(20*DELAY); + + var clientrequest = { + name: "new name", + password: "new pass" + }; + + request(url) + .post('/user/update_immediate') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .set('Authorization', authValue ) + .send(clientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(200); + setTimeout(done, 14*DELAY); + }); +}); + it('should return a success response to indicate that the token was updated', function(done) { request(url) From f2c5e1fb5709165b605d7a90600197b93f8a065f Mon Sep 17 00:00:00 2001 From: Andrei Marinescu Date: Tue, 29 Sep 2015 16:40:25 +0300 Subject: [PATCH 12/42] sudo true in travis - needed for elasticsearch configuration --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fc31786..18e896b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ language: node_js -sudo: false services: - elasticsearch - redis From f52afa06f2acb91ee29cf0e744a98a5e0442c2ed Mon Sep 17 00:00:00 2001 From: Sergiu Alexandrescu Date: Tue, 29 Sep 2015 14:13:56 +0000 Subject: [PATCH 13/42] corrected some tests --- test/object/object.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/object/object.js b/test/object/object.js index 98440b2..001b3be 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -732,7 +732,7 @@ it('should return a success response to indicate that a object has been subscrib var subclientrequest = { "channel": { "context": contextID, - "model": "comments", + "model": "comments" }, }; @@ -941,13 +941,12 @@ it('should return an error response to indicate that a object has NOT been subsc }); }); -it('should return a success response to indicate that a object has been unsubscribed', function(done) { +it('should return an success response to indicate that a object has been unsubscribed', function(done) { var subclientrequest = { "channel": { "context": contextID, - "model": "comments", - "id" : "66" + "model": "comments" } }; @@ -965,7 +964,7 @@ it('should return a success response to indicate that a object has been unsubscr }); }); -it('should return a success response to indicate that a object has NOT been unsubscribed because of empty body', function(done) { +it('should return an error response to indicate that a object has NOT been unsubscribed because of empty body', function(done) { request(url) .post('/object/unsubscribe') @@ -981,7 +980,7 @@ it('should return a success response to indicate that a object has NOT been unsu }); }); -it('should return a success response to indicate that a object has NOT been unsubscribed', function(done) { +it('should return a error response to indicate that a object has NOT been unsubscribed', function(done) { var subclientrequest = { "channel": { @@ -1031,7 +1030,8 @@ it('should return a success response to indicate that a object has NOT been unsu var subclientrequest = { "channel": { - "model": "comments" + "model": "comments", + "id" : "66" } }; From da4b1033b9a05d7e75786302c4dde51ba2b43d68 Mon Sep 17 00:00:00 2001 From: Razvan Botea Date: Tue, 29 Sep 2015 17:30:31 +0300 Subject: [PATCH 14/42] Fixed /user/update when updating password * fixed user/login_password after changing the password --- controllers/user.js | 38 ++++++++++++++++++++++++-------------- test/user/user.js | 4 ++-- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/controllers/user.js b/controllers/user.js index 84b5aa7..c89ff42 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -19,7 +19,7 @@ router.use(security.deviceIdValidation); router.use(security.applicationIdValidation); router.use(security.apiKeyValidation); -router.use(['/logout', '/me', '/update', '/delete'], security.tokenValidation); +router.use(['/logout', '/me', '/update', '/update_immediate', '/delete'], security.tokenValidation); /** * @api {post} /user/login Login @@ -602,8 +602,8 @@ router.post('/update', function(req, res, next) { if (patches[i].path.split('/')[2] == 'password') { - security.encryptPassword(patches[p].value, function(err, hash) { - patches[p].value = hash; + security.encryptPassword(patches[i].value, function(err, hash) { + patches[i].value = hash; i++; c(); }); @@ -638,27 +638,37 @@ router.post('/update', function(req, res, next) { router.post('/update_immediate', function(req, res, next) { var user = req.body; + var appId = req._telepat.applicationId; - if (user.password) { - var passwordSalt = req.app.get('password_salt'); - var md5password = crypto.createHash('md5').update(user.password).digest('hex'); - user.password = crypto.createHash('sha256').update(passwordSalt[0]+md5password+passwordSalt[1]).digest('hex'); - } + req.user.type = 'user'; async.waterfall([ function(callback) { - security.encryptPassword(user.password, callback); + if (user.password) + security.encryptPassword(user.password, callback); + else + callback(null, false); }, function(hash, callback) { - user.password = hash; + if (hash) + user.password = hash; - Models.User.update(user.email, user, function(err, result) { - if (err) return next(err); + var patches = []; - res.status(200).json({status: 200, content: "User updated"}).end(); + async.each(Object.keys(user), function(prop, c) { + var property = {}; + property[prop] = user[prop]; + patches.push(Models.Delta.formPatch(req.user, 'replace', property)); + c(); + }, function() { + Models.User.update(req.user.email, appId, patches, callback); }); } - ]); + ], function(err) { + if (err) return next(err); + + res.status(200).json({status: 200, content: "User updated"}).end(); + }); }); /** diff --git a/test/user/user.js b/test/user/user.js index a2bba92..49c175b 100644 --- a/test/user/user.js +++ b/test/user/user.js @@ -359,7 +359,7 @@ it('should return a success response to indicate that the user password was NOT }); }); -it('should return a success response to indicate that the user was updated immidiate', function(done) { +it('should return a success response to indicate that the user was updated immediate', function(done) { this.timeout(20*DELAY); @@ -507,7 +507,7 @@ it('should return a success response to indicate that the user was deleted', fun var clientrequest = { "email": userEmail, - "password": "secure_password1337", + "password": "new pass", "name": "John Smith" }; From fd5e45683d1a731933be5c8658dc1fecded93eb0 Mon Sep 17 00:00:00 2001 From: Sergiu Alexandrescu Date: Tue, 29 Sep 2015 14:32:35 +0000 Subject: [PATCH 15/42] added a test for user/update --- test/user/user.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/user/user.js b/test/user/user.js index a2bba92..38c171c 100644 --- a/test/user/user.js +++ b/test/user/user.js @@ -298,11 +298,39 @@ it('should return a success response to indicate that the user password was upda .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(202); done(); }); }); +it('should return an error response to indicate that the userID is not valid', function(done) { + + var clientrequest = { + "patches" : [ + { + "op": "replace", + "path": "user/" + userID + "66" +"/password", + "value": "new value" + } + ] + }; + + request(url) + .post('/user/update') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .set('Authorization', authValue ) + .send(clientrequest) + .end(function(err, res) { +console.log(res.body); + res.statusCode.should.be.equal(400); + done(); + }); +}); + it('should return a success response to indicate that the user password was NOT updated because of empty request body', function(done) { request(url) From 55e6c6d099b1ef565143f620a9cd02a52cec25fe Mon Sep 17 00:00:00 2001 From: Sergiu Alexandrescu Date: Tue, 29 Sep 2015 15:53:10 +0000 Subject: [PATCH 16/42] reached 85.5% coverage --- test/admin/admin.js | 618 +++++++++++++++++++++++++++----------------- test/user/user.js | 23 +- 2 files changed, 388 insertions(+), 253 deletions(-) diff --git a/test/admin/admin.js b/test/admin/admin.js index 0f1dd46..80ef868 100644 --- a/test/admin/admin.js +++ b/test/admin/admin.js @@ -34,14 +34,14 @@ var userEmail = 'user'+Math.round(Math.random()*1000000)+'@example.com'; describe('Admin', function() { it('should return a 200 code to indicate success when creating a new admin', function(done) { - + this.timeout(12*DELAY); request(url) .post('/admin/add') .send(admin) .end(function(err, res) { - + if (err) { throw err; done(err); @@ -57,7 +57,7 @@ describe('Admin', function() { .post('/admin/add') .send(admin) .end(function(err, res) { - + res.statusCode.should.be.equal(409); done(); }); @@ -65,73 +65,73 @@ describe('Admin', function() { }); it('should return a 4xx code to indicate failure when admin email is missing', function(done) { - + var admin = { password: adminPassword }; - + request(url) .post('/admin/add') .send(admin) .end(function(err, res) { - + res.statusCode.should.be.within(400,499); done(); }); }); it('should return a 4xx code to indicate failure when admin email is empty', function(done) { - + var admin = { email: "", password: adminPassword }; - + request(url) .post('/admin/add') .send(admin) .end(function(err, res) { - + res.statusCode.should.be.within(400,499); done(); }); }); it('should return a 4xx code to indicate failure when admin password is empty', function(done) { - + var admin = { email: adminEmail, password: "" }; - + request(url) .post('/admin/add') .send(admin) .end(function(err, res) { - + res.statusCode.should.be.within(400,499); done(); }); }); it('should return a 4xx code to indicate failure when admin password is missing', function(done) { - + var admin = { email: adminEmail }; - + request(url) .post('/admin/add') .send(admin) .end(function(err, res) { - + res.statusCode.should.be.within(400,499); done(); }); }); it('should return an error for logging in with wrong user or password', function(done) { - + var randEmail = 'adminx@example.com'; var admin = { email: randEmail, @@ -141,19 +141,19 @@ describe('Admin', function() { .post('/admin/login') .send(admin) .end(function(err, res) { - + res.statusCode.should.be.equal(401); done(); }); }); - + it('should return an error for logging in missing password', function(done) { - + var randEmail = 'adminx@example.com'; var admin = { email: randEmail }; - + request(url) .post('/admin/login') .send(admin) @@ -163,11 +163,11 @@ describe('Admin', function() { done(); }); }); - + it('should return an error for logging in missing email & password', function(done) { var admin = {}; - + request(url) .post('/admin/login') .send(admin) @@ -179,12 +179,12 @@ describe('Admin', function() { }); it('should return a valid authorization token', function(done) { - + request(url) .post('/admin/login') .send(admin) .end(function(err, res) { - + authValue = 'Bearer ' + res.body.content.token; adminAuth = authValue; admin = res.body.content.user; @@ -194,14 +194,14 @@ describe('Admin', function() { }); it('should return information about the logged admin', function(done) { - + request(url) .get('/admin/me') .set('Content-type','application/json') .set('Authorization', authValue ) .send() .end(function(err, res) { - + res.statusCode.should.be.equal(200); res.body.content.email.should.be.equal(admin.email); res.body.content.isAdmin.should.be.equal(true); @@ -210,7 +210,7 @@ describe('Admin', function() { }); it('should return a succes response indicating the admin account has been updated', function(done) { - + var requestBody = { patches: [ { @@ -220,21 +220,21 @@ describe('Admin', function() { } ] }; - + request(url) .post('/admin/update') .set('Content-type','application/json') .set('Authorization', authValue ) .send(requestBody) .end(function(err, res) { - + res.statusCode.should.be.equal(200); done(); }); }); it('should return an error response indicating the admin account has NOT been updated because of invalid admin id', function(done) { - + var admin = { patches: [ { @@ -244,7 +244,7 @@ describe('Admin', function() { } ] }; - + request(url) .post('/admin/update') .set('Content-type','application/json') @@ -256,9 +256,9 @@ describe('Admin', function() { done(); }); }); - + it('should return an error response indicating the admin account has NOT been updated because of missing authorization header', function(done) { - + var admin = { patches: [ { @@ -268,7 +268,7 @@ describe('Admin', function() { } ] }; - + request(url) .post('/admin/update') .set('Content-type','application/json') @@ -281,98 +281,98 @@ describe('Admin', function() { }); it('should return an error response indicating the admin account has NOT been updated because of missing request body', function(done) { - + request(url) .post('/admin/update') .set('Content-type','application/json') .set('Authorization', authValue ) .send() .end(function(err, res) { - + res.statusCode.should.be.equal(400); done(); }); }); - - + + it('should return an error response indicating the admin account has NOT been updated because patches is not an array', function(done) { - + var admin = { patches: {} }; - + request(url) .post('/admin/update') .set('Content-type','application/json') .set('Authorization', authValue ) .send(admin) .end(function(err, res) { - + res.statusCode.should.be.equal(400); done(); }); }); - + it('should return an error response indicating the admin account has NOT been updated because patches is empty', function(done) { - + var admin = { patches: [] }; - + request(url) .post('/admin/update') .set('Content-type','application/json') .set('Authorization', authValue ) .send(admin) .end(function(err, res) { - + res.statusCode.should.be.equal(400); done(); }); }); it('should return an error response indicating the admin account has NOT been deleted because of missing credentials', function(done) { - + request(url) .post('/admin/delete') .set('Content-type','application/json') .send() .end(function(err, res) { - + res.statusCode.should.be.equal(401); done(); }); }); it('should return a succes response indicating the admin account has been deleted', function(done) { - + this.timeout(20*DELAY); - + request(url) .post('/admin/delete') .set('Content-type','application/json') .set('Authorization', authValue) .send() .end(function(err, res) { - + res.statusCode.should.be.equal(200); - + setTimeout(function() { - + request(url) .post('/admin/add') .send(admin) .end(function(err, res) { - + res.statusCode.should.be.equal(200); - + setTimeout(function () { - + request(url) .post('/admin/login') .send(admin) .end(function(err, res) { - + authValue = 'Bearer ' + res.body.content.token; adminAuth = authValue; res.statusCode.should.be.equal(200); @@ -388,36 +388,36 @@ describe('Admin', function() { describe('App', function() { before(function(done){ - + this.timeout(20*DELAY); - + var clientrequest = { "name": "test-app", "keys": [ appKey ] }; - + request(url) .post('/admin/app/add') .set('Content-type','application/json') .set('Authorization', authValue) .send(clientrequest) .end(function(err, res) { - + appID = res.body.content.id; - + request(url) .post('/admin/add') .send(admin2) .end(function(err, res) { - + setTimeout(function () { - + request(url) .post('/admin/login') .set('Content-type','application/json') .send(admin2) .end(function(err, res) { - + token2 = res.body.content.token; authValue2 = 'Bearer ' + token2; done(); @@ -446,7 +446,7 @@ describe('App', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + var objectKey = Object.keys(res.body.content)[0]; appID = res.body.content.id; (res.body.content[objectKey] == successResponse[1]).should.be.ok; @@ -455,53 +455,53 @@ describe('App', function() { }); it('should return an error response to indicate app was not created because of missing app name', function(done) { - + var clientrequest = { "keys": ["3406870085495689e34d878f09faf52c"] }; - + request(url) .post('/admin/app/add') .set('Content-type','application/json') .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(400); done(); }); }); it('should return a list of applications for the current admin', function(done) { - + var clientrequest = { "name": "test-app", "keys": [ appKey ] }; - + request(url) .post('/admin/app/add') .set('Content-type','application/json') .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + request(url) .post('/admin/app/add') .set('Content-type','application/json') .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + setTimeout(function () { - + request(url) .get('/admin/apps') .set('Content-type','application/json') .set('Authorization', authValue ) .send() .end(function(err, res) { - + res.statusCode.should.be.equal(200); res.body.status.should.be.equal(200); (Object.keys(res.body.content).length >= 3).should.be.ok; @@ -513,19 +513,19 @@ describe('App', function() { }); it('should return a success response for updating an app', function(done) { - + var clientrequest = { "name": "test-app", "keys": [ appKey ] }; - + request(url) .post('/admin/app/add') .set('Content-type','application/json') .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + var objectKey = Object.keys(res.body.content)[0]; var appID = res.body.content.id; var clientrequest2 = { @@ -537,9 +537,9 @@ describe('App', function() { } ] }; - + setTimeout(function () { - + request(url) .post('/admin/app/update') .set('Content-type','application/json') @@ -553,7 +553,60 @@ describe('App', function() { }, 2*DELAY); }); }); - + + it('should return an error response for NOT updating an app because patches is not an array', function(done) { + + var clientrequest2 = { + patches: {} + }; + + request(url) + .post('/admin/app/update') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .set('X-BLGREQ-APPID', appID ) + .send(clientrequest2) + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); + }); + + it('should return an error response for NOT updating an app because patches is an empty array', function(done) { + + var clientrequest2 = { + patches: [] + }; + + request(url) + .post('/admin/app/update') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .set('X-BLGREQ-APPID', appID ) + .send(clientrequest2) + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); + }); + + it('should return an error response for NOT updating an app because of missing request body', function(done) { + + request(url) + .post('/admin/app/update') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .set('X-BLGREQ-APPID', appID ) + .send() + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); + }); + it('should return an error response for NOT updating an app because of missing appID', function(done) { var clientrequest2 = { @@ -573,32 +626,31 @@ describe('App', function() { .set('X-BLGREQ-APPID', appID + '66' ) .send(clientrequest2) .end(function(err, res) { - + res.statusCode.should.be.equal(404); done(); }); }); - it('should return a success response for removing an app', function(done) { - + var clientrequest = { "name": "test-app", "keys": [ appKey ] }; - + request(url) .post('/admin/app/add') .set('Content-type','application/json') .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + var objectKey = Object.keys(res.body.content)[0]; var appID = res.body.content.id; - + setTimeout(function() { - + request(url) .post('/admin/app/remove') .set('Content-type','application/json') @@ -606,7 +658,7 @@ describe('App', function() { .set('X-BLGREQ-APPID', appID ) .send() .end(function(err, res) { - + res.statusCode.should.be.equal(200); res.body.content.should.be.equal('App removed'); done(); @@ -616,7 +668,7 @@ describe('App', function() { }); it('should return an error response for trying to remove an app that does NOT exist', function(done) { - + request(url) .post('/admin/app/remove') .set('Content-type','application/json') @@ -624,18 +676,18 @@ describe('App', function() { .set('X-BLGREQ-APPID', Math.round(Math.random()*1000000)+1000 ) .send() .end(function(err, res) { - + res.statusCode.should.be.equal(404); done(); }); }); - + it('should return an succes to indicate an admin has been authorized to an application', function(done) { - + var clientrequest = { "email": adminEmail2 }; - + request(url) .post('/admin/app/authorize') .set('Content-type','application/json') @@ -651,10 +703,13 @@ describe('App', function() { }); }); - it('should return an error response to indicate admin has NOT been authorized because of the email field is missing', function(done) { - - var clientrequest = {}; - + + it('should return an error response to indicate admin has NOT been authorized because of missing email from body', function(done) { + + var clientrequest = { + "something": adminEmail2 + }; + request(url) .post('/admin/app/authorize') .set('Content-type','application/json') @@ -669,15 +724,32 @@ describe('App', function() { done(); }); }); - + + it('should return an error response to indicate admin has NOT been authorized because request body', function(done) { + + request(url) + .post('/admin/app/authorize') + .set('Content-type','application/json') + .set('X-BLGREQ-APPID', appID) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') + .set('Authorization', authValue ) + .send() + .end(function(err, res) { + + if(res) + res.statusCode.should.be.equal(400); + done(); + }); + }); + it('should return an error response to indicate admin with email address already authorized for application', function(done) { - + this.timeout(10*DELAY); - + var clientrequest = { "email": adminEmail2 }; - + setTimeout(function () { request(url) .post('/admin/app/authorize') @@ -687,20 +759,20 @@ describe('App', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + if(res) res.statusCode.should.be.equal(409); done(); }); }, 6*DELAY); }); - + it('should return an error response to indicate admin has NOT been authenticated because application with that ID doesn\'t exist', function(done) { - + var clientrequest = { "email": adminEmail2 }; - + request(url) .post('/admin/app/authorize') .set('Content-type','application/json') @@ -709,19 +781,19 @@ describe('App', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + if(res) res.statusCode.should.be.equal(404); done(); }); }); - + it('should return an succes to indicate an admin has been deauthorized to an application', function(done) { - + var clientrequest = { "email": adminEmail2 }; - + request(url) .post('/admin/app/deauthorize') .set('Content-type','application/json') @@ -730,17 +802,17 @@ describe('App', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + if(res) res.statusCode.should.be.equal(200); done(); }); }); - + it('should return an error response to indicate admin has NOT been deauthorized because of the email field is missing', function(done) { - + var clientrequest = {}; - + request(url) .post('/admin/app/deauthorize') .set('Content-type','application/json') @@ -749,19 +821,19 @@ describe('App', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + if(res) res.statusCode.should.be.equal(400); done(); }); }); - + it('should return an error response to indicate admin with email address is the last admin of the application', function(done) { - + var clientrequest = { "email": adminEmail }; - + request(url) .post('/admin/app/deauthorize') .set('Content-type','application/json') @@ -770,19 +842,19 @@ describe('App', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + if(res) res.statusCode.should.be.equal(409); done(); }); }); - + it('should return an error response to indicate admin has NOT been deauthenticated because application with that ID doesn\'t exist', function(done) { - + var clientrequest = { "email": adminEmail2 }; - + request(url) .post('/admin/app/deauthorize') .set('Content-type','application/json') @@ -791,7 +863,7 @@ describe('App', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + if(res) res.statusCode.should.be.equal(404); done(); @@ -802,12 +874,12 @@ describe('App', function() { describe('Context', function() { it('should return a success response to indicate context succesfully created', function(done) { - + var clientrequest = { "name": "context", "meta": {"info": "some meta info"}, } - + request(url) .post('/admin/context/add') .set('Content-type','application/json') @@ -815,7 +887,7 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { - + var objectKey = Object.keys(res.body.content)[0]; contextID = res.body.content.id; (res.body.content[objectKey].name == clientrequest.name).should.be.ok; @@ -825,11 +897,11 @@ describe('Context', function() { }); it('should return the requested context', function(done) { - + var clientrequest = { "id": contextID } - + request(url) .post('/admin/context') .set('Content-type','application/json') @@ -837,16 +909,16 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(200); done(); }); }); it('should NOT return the requested context, requested context ID is missing', function(done) { - + var clientrequest = {}; - + request(url) .post('/admin/context') .set('Content-type','application/json') @@ -854,49 +926,47 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(400); done(); }); }); it('should return an error response to indicate context NOT succesfully created because of bad client headers', function(done) { - + var clientrequest = { "name": "context", "meta": {"info": "some meta info"} }; - + request(url) .post('/admin/context/add') .set('Content-type','application/json') .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response to indicate context NOT succesfully created because request body is empty', function(done) { - - var clientrequest = {}; - + it('should return an error response to indicate context NOT successfully created because request body is empty', function(done) { + request(url) .post('/admin/context/add') .set('Content-type','application/json') .set('Authorization', authValue ) - .send(clientrequest) + .send() .end(function(err, res) { - + res.statusCode.should.be.equal(400); done(); }); }); it('should return a success response to indicate context was updated', function(done) { - + var clientrequest = { "id": contextID, "patches": [ @@ -907,7 +977,7 @@ describe('Context', function() { } ] }; - + request(url) .post('/admin/context/update') .set('Content-type','application/json') @@ -915,19 +985,54 @@ describe('Context', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(200); done(); }); }); it('should return an error response to indicate context was NOT updated because patches are missing', function(done) { - + + var clientrequest = { + "id": Math.round(Math.random()*1000000)+100, + "name": "new name" + }; + + request(url) + .post('/admin/context/update') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .set('X-BLGREQ-APPID', appID ) + .send(clientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); + }); + + it('should return an error response to indicate context was NOT updated because of missing request body', function(done) { + + request(url) + .post('/admin/context/update') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .set('X-BLGREQ-APPID', appID ) + .send() + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); + }); + + it('should return an error response to indicate context was NOT updated because patches are missing', function(done) { + var clientrequest = { "id": Math.round(Math.random()*1000000)+100, "name": "new name" }; - + request(url) .post('/admin/context/update') .set('Content-type','application/json') @@ -935,23 +1040,20 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response to indicate context was NOT updated because context does not exist', function(done) { - + + it('should return an error response to indicate context was NOT updated because patches is empty', function(done) { + var clientrequest = { "id": Math.round(Math.random()*1000000)+100, - "patches": [{ - op: "replace", - path: "context/0/name", - value: "new value" - }] + "patches": [] }; - + request(url) .post('/admin/context/update') .set('Content-type','application/json') @@ -959,18 +1061,18 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { - - res.statusCode.should.be.equal(404); + + res.statusCode.should.be.equal(400); done(); }); }); it('should return an error response to indicate context was NOT updated because of missing context id', function(done) { - + var clientrequest = { "name": "new name" }; - + request(url) .post('/admin/context/update') .set('Content-type','application/json') @@ -978,14 +1080,14 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(400); done(); }); }); it('should return an error response to indicate context was NOT updated by another admin', function(done) { - + var clientrequest = { "id": contextID, "patches": [ @@ -1004,18 +1106,18 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(401); done(); }); }); it('should return an error response to indicate context was NOT removed because of invalid context id', function(done) { - + var clientrequest = { "id": 1 } - + request(url) .post('/admin/context/remove') .set('Content-type','application/json') @@ -1023,18 +1125,18 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(404); done(); }); }); it('should return an error indicating the requested context does NOT exist', function(done) { - + var clientrequest = { "id": Math.round(Math.random()*1000000)+100 }; - + request(url) .post('/admin/context') .set('Content-type','application/json') @@ -1042,19 +1144,34 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(404); res.body.message.should.be.equal("Context not found"); done(); }); }); + it('should return an error response to indicate context was NOT removed because of missing id from request body', function(done) { + + request(url) + .post('/admin/context/remove') + .set('Content-type','application/json') + .set('Authorization', authValue) + .set('X-BLGREQ-APPID', appID) + .send() + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); + }); + it('should return all contexts using the old API', function(done) { - + this.timeout(9*DELAY); - + setTimeout(function () { - + request(url) .get('/admin/contexts') .set('Content-type','application/json') @@ -1062,7 +1179,7 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID) .send() .end(function(err, res) { - + res.statusCode.should.be.equal(200); res.body.content.should.have.length(1); done(); @@ -1071,11 +1188,11 @@ describe('Context', function() { }); it('should return all contexts using the new API', function(done) { - + this.timeout(9*DELAY); - + setTimeout(function () { - + request(url) .get('/admin/context/all') .set('Content-type','application/json') @@ -1083,7 +1200,7 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID) .send() .end(function(err, res) { - + res.statusCode.should.be.equal(200); res.body.content.should.have.length(1); done(); @@ -1092,11 +1209,11 @@ describe('Context', function() { }); it('should return a success response to indicate context was removed', function(done) { - + var clientrequest = { "id": contextID }; - + request(url) .post('/admin/context/remove') .set('Content-type','application/json') @@ -1104,7 +1221,7 @@ describe('Context', function() { .set('X-BLGREQ-APPID', appID) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(200); res.body.content.should.be.equal('Context removed'); done(); @@ -1113,9 +1230,9 @@ describe('Context', function() { }); describe('Schema', function() { - + it('should return a success response to indicate schema succesfully updated', function(done) { - + var clientrequest = { "appId": appID, "schema": { @@ -1189,14 +1306,14 @@ describe('Schema', function() { .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(200); done(); }); }); it('should return an error response to indicate schema was NOT succesfully updated because of appID', function(done) { - + var clientrequest = { "appId": "1", "schema": { @@ -1250,18 +1367,18 @@ describe('Schema', function() { .set('X-BLGREQ-APPID', Math.round(Math.random()*1000000)+1000 ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(404); done(); }); }); it('should return an error response to indicate schema was NOT succesfully updated because of missing schema object', function(done) { - + var clientrequest = { "appId": "1" }; - + request(url) .post('/admin/schema/update') .set('Content-type','application/json') @@ -1269,14 +1386,14 @@ describe('Schema', function() { .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(400); done(); }); }); it('should return a success response to indicate schema was retrived succesfully using the old API', function(done) { - + request(url) .get('/admin/schemas') .set('Content-type','application/json') @@ -1284,14 +1401,14 @@ describe('Schema', function() { .set('X-BLGREQ-APPID', appID ) .send() .end(function(err, res) { - + res.statusCode.should.be.equal(200); done(); }); }); it('should return a success response to indicate schema was retrived succesfully using the new API', function(done) { - + request(url) .get('/admin/schema/all') .set('Content-type','application/json') @@ -1299,18 +1416,18 @@ describe('Schema', function() { .set('X-BLGREQ-APPID', appID ) .send() .end(function(err, res) { - + res.statusCode.should.be.equal(200); done(); }); }); - + it('should return a success response to indicate a model was removed from the application', function(done) { - + var clientrequest = { "model_name": "things" }; - + request(url) .post('/admin/schema/remove_model') .set('Content-type','application/json') @@ -1318,19 +1435,19 @@ describe('Schema', function() { .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { - + //console.log(res.body); res.statusCode.should.be.equal(200); done(); }); }); - + it('should return a error response to indicate a model was NOT removed from the application because of wrong appID', function(done) { - + var clientrequest = { "model_name": "things" }; - + request(url) .post('/admin/schema/remove_model') .set('Content-type','application/json') @@ -1338,18 +1455,18 @@ describe('Schema', function() { .set('X-BLGREQ-APPID', appID + '66' ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(404); done(); }); }); - + it('should return a error response to indicate a model was NOT removed from the application because model name does NOT exist', function(done) { - + var clientrequest = { "model_name": "others" }; - + request(url) .post('/admin/schema/remove_model') .set('Content-type','application/json') @@ -1357,13 +1474,26 @@ describe('Schema', function() { .set('X-BLGREQ-APPID', appID + '66' ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(404); done(); }); }); + it('should return a error response to indicate a model was NOT removed from the application because model was missing from the request', function(done) { + request(url) + .post('/admin/schema/remove_model') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .set('X-BLGREQ-APPID', appID + '66' ) + .send() + .end(function(err, res) { + + res.statusCode.should.be.equal(404); + done(); + }); + }); }); describe('User', function() { @@ -1375,9 +1505,9 @@ describe('User', function() { }; before(function(done){ - + this.timeout(11*DELAY); - + request(url) .post('/user/register') .set('Content-type','application/json') @@ -1386,7 +1516,7 @@ describe('User', function() { .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { - + //console.log(res.body); setTimeout(done, 7*DELAY); }); @@ -1405,7 +1535,7 @@ describe('User', function() { } ] }; - + request(url) .post('/admin/user/update') .set('Content-type','application/json') @@ -1415,7 +1545,7 @@ describe('User', function() { .set('Authorization', authValue) .send(clientrequest) .end(function(err, res) { - + //console.log(res.body); res.statusCode.should.be.equal(200); setTimeout(done, 8*DELAY); @@ -1423,9 +1553,9 @@ describe('User', function() { }); it('should return a success response to indicate that an user was NOT updated, user was missing from the request', function(done) { - + var clientrequest = {}; - + request(url) .post('/admin/user/update') .set('Content-type','application/json') @@ -1435,20 +1565,20 @@ describe('User', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(400); done(); }); }); it('should return a success response to indicate that an user was NOT updated, user email address was missing from the request', function(done) { - + var clientrequest = { "user": { "name": "New Name" } }; - + request(url) .post('/admin/user/update') .set('Content-type','application/json') @@ -1458,14 +1588,14 @@ describe('User', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(400); done(); }); }); it('should return a success response indicating that a user has been deleted', function(done) { - + this.timeout(40*DELAY); request(url) @@ -1476,9 +1606,9 @@ describe('User', function() { .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { - + setTimeout(function() { - + request(url) .post('/admin/user/delete') .set('Content-type','application/json') @@ -1488,7 +1618,7 @@ describe('User', function() { .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(200); done(); }); @@ -1497,16 +1627,16 @@ describe('User', function() { }); it('should return a success response indicating that a user has NOT been deleted, user does not belong to application', function(done) { - + this.timeout(24*DELAY); - + var userEmail = "user3@example.com"; var clientrequest = { "email": userEmail, "password": "secure_password1337", "name": "John Smith" }; - + request(url) .post('/user/register') .set('Content-type','application/json') @@ -1515,7 +1645,7 @@ describe('User', function() { .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { - + var userEmail = "user2@example.com"; var clientrequest = { "email": userEmail, @@ -1524,7 +1654,7 @@ describe('User', function() { }; setTimeout(function() { - + request(url) .post('/admin/user/delete') .set('Content-type','application/json') @@ -1534,7 +1664,7 @@ describe('User', function() { .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(404); done(); }); @@ -1543,12 +1673,12 @@ describe('User', function() { }); it('should return a error response indicating that a user has NOT been deleted because of missing email address', function(done) { - + var clientrequest = { "password": "secure_password1337", "name": "John Smith" }; - + request(url) .post('/admin/user/delete') .set('Content-type','application/json') @@ -1558,23 +1688,23 @@ describe('User', function() { .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(400); done(); }); }); it('should return an error response indicating that a user has NOT been deleted because of appID not found', function(done) { - + this.timeout(40*DELAY); - + var userEmail = "user3@example.com"; var clientrequest = { "email": userEmail, "password": "secure_password1337", "name": "John Smith" }; - + request(url) .post('/admin/user/delete') .set('Content-type','application/json') @@ -1584,14 +1714,14 @@ describe('User', function() { .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(404); done(); }); }); it('should return an error response to indicate that an user was NOT found when trying to update', function(done) { - + var clientrequest = { "email" : "wrong@example.com", "patches": [ @@ -1602,7 +1732,7 @@ describe('User', function() { } ] }; - + request(url) .post('/admin/user/update') .set('Content-type','application/json') @@ -1612,14 +1742,14 @@ describe('User', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(404); done(); }); }); it('should return an error response to indicate that the user email is missing', function(done) { - + var clientrequest = { "patches": [ { @@ -1629,7 +1759,7 @@ describe('User', function() { } ] }; - + request(url) .post('/admin/user/update') .set('Content-type','application/json') @@ -1639,14 +1769,14 @@ describe('User', function() { .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(400); done(); }); }); it('should return a success response to indicate that an admin list was retrived', function(done) { - + request(url) .get('/admin/users') .set('Content-type','application/json') @@ -1656,14 +1786,14 @@ describe('User', function() { .set('Authorization', authValue ) .send() .end(function(err, res) { - + res.statusCode.should.be.equal(200); done(); }); }); it('should return an error response to indicate that an admin list was NOT retrived for a bad app id', function(done) { - + request(url) .get('/admin/users') .set('Content-type','application/json') @@ -1673,7 +1803,7 @@ describe('User', function() { .set('Authorization', authValue ) .send() .end(function(err, res) { - + if(res) res.statusCode.should.be.equal(404); done(); @@ -1681,7 +1811,7 @@ describe('User', function() { }); it('should return a success response to indicate that an users list was retrived', function(done) { - + request(url) .get('/admin/user/all') .set('Content-type','application/json') @@ -1691,7 +1821,7 @@ describe('User', function() { .set('Authorization', authValue ) .send() .end(function(err, res) { - + if(res) { //console.log(res.body); res.body.content.should.not.be.empty; @@ -1702,7 +1832,7 @@ describe('User', function() { }); it('should return an error response to indicate that an users list was NOT retrived for a bad app id', function(done) { - + request(url) .get('/admin/user/all') .set('Content-type','application/json') @@ -1712,7 +1842,7 @@ describe('User', function() { .set('Authorization', authValue ) .send() .end(function(err, res) { - + if(res) res.statusCode.should.be.equal(404); done(); diff --git a/test/user/user.js b/test/user/user.js index 3669b2b..600e36c 100644 --- a/test/user/user.js +++ b/test/user/user.js @@ -147,11 +147,14 @@ it('should return a success response to indicate that the user has logged in via }); it('should return a success response to indicate that the user has logged in via Facebook', function(done) { + this.timeout(100*DELAY); + request('https://graph.facebook.com') .get('/oauth/access_token?client_id=1086083914753251&client_secret=40f626ca66e4472e0d11c22f048e9ea8&grant_type=client_credentials') .send() .end(function(err, res) { + request('https://graph.facebook.com') .get('/v1.0/1086083914753251/accounts/test-users?access_token='+res.text.replace('access_token=', '')) .send() @@ -170,7 +173,9 @@ it('should return a success response to indicate that the user has logged in via .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { + setTimeout(function() { + request(url) .post('/user/login') .set('Content-type','application/json') @@ -179,13 +184,11 @@ it('should return a success response to indicate that the user has logged in via .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { - //token = res.body.content.token; - //userID = res.body.content.user.id; - //authValue = 'Bearer ' + token; + res.statusCode.should.be.equal(200); done(); }); - }, 1); + }, 4*DELAY); }); }); }); @@ -325,7 +328,7 @@ it('should return an error response to indicate that the userID is not valid', f .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { -console.log(res.body); + res.statusCode.should.be.equal(400); done(); }); @@ -387,7 +390,7 @@ it('should return a success response to indicate that the user password was NOT }); }); -it('should return a success response to indicate that the user was updated immediate', function(done) { +it('should return a success response to indicate that the user was updated immidiate', function(done) { this.timeout(20*DELAY); @@ -489,6 +492,8 @@ it('should return a success response to indicate that the user logged out', func it('should return a success response to indicate that the user has registered', function(done) { + this.timeout(20*DELAY); + var clientrequest = { "email": userEmail2, "password": "secure_password1337", @@ -505,7 +510,7 @@ it('should return a success response to indicate that the user has registered', .end(function(err, res) { res.statusCode.should.be.equal(202); - done(); + setTimeout(done, 14*DELAY); }); }); @@ -534,8 +539,8 @@ it('should return a success response to indicate that the user has NOT registere it('should return a success response to indicate that the user was deleted', function(done) { var clientrequest = { - "email": userEmail, - "password": "new pass", + "email": userEmail2, + "password": "secure_password1337", "name": "John Smith" }; From bf2d75e65892df0ede7df90a5c361a4de746a34a Mon Sep 17 00:00:00 2001 From: Andrei Marinescu Date: Wed, 30 Sep 2015 18:04:53 +0300 Subject: [PATCH 17/42] Fixed subscribe flow for models --- controllers/object.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/controllers/object.js b/controllers/object.js index efc4cf4..5d805e8 100644 --- a/controllers/object.js +++ b/controllers/object.js @@ -204,7 +204,7 @@ router.post('/subscribe', function(req, res, next) { if (err) return callback(err); if (Array.isArray(results)) - objects.concat(results); + objects = objects.concat(results); callback(); }); @@ -234,11 +234,11 @@ router.post('/subscribe', function(req, res, next) { callback(err, results); }); }*/ - ], function(err, result) { + ], function(err) { if (err) return next(err); - res.status(200).json({status: 200, content: result}).end(); + res.status(200).json({status: 200, content: objects}).end(); }); }); From 3fdf3765d188b89bff4b41bd95ef92ff019a7511 Mon Sep 17 00:00:00 2001 From: Razvan Botea Date: Wed, 30 Sep 2015 18:53:04 +0300 Subject: [PATCH 18/42] Updated code for the updated telepat models * Fixed some tests that needed some timeout --- app.js | 32 +++++++++----------------------- config.example.json | 4 ++-- controllers/object.js | 2 +- controllers/user.js | 2 +- test/admin/admin.js | 2 +- test/user/user.js | 4 ++-- 6 files changed, 16 insertions(+), 30 deletions(-) diff --git a/app.js b/app.js index 0eb6694..69aaa87 100644 --- a/app.js +++ b/app.js @@ -167,12 +167,12 @@ var OnServicesConnect = function() { }; async.waterfall([ - function DataBucket(callback) { + function(callback) { Models.Application.datasource.dataStorage.onReady(function() { callback(); }); }, - function RedisClient(callback) { + function(callback) { if (Models.Application.redisClient) Models.Application.redisClient = null; @@ -186,33 +186,19 @@ async.waterfall([ callback(); }); }, - function Kafka(callback) { + function(callback) { console.log('Waiting for Messaging Client connection...'); - var kafkaConfiguration = mainConfiguration[messagingClient]; + var clientConfiguration = mainConfiguration[messagingClient]; - app.messagingClient = new Models[messagingClient](kafkaConfiguration, 'telepat-api'); - app.messagingClient.on('ready', function() { + /** + * @type {MessagingClient} + */ + app.messagingClient = new Models[messagingClient](clientConfiguration, 'telepat-api'); + app.messagingClient.onReady(function() { console.log(('Connected to Messaging Client '+messagingClient).green); callback(); }); - app.messagingClient.on('error', function(err) { - console.log('Messaging client not available.'.red+' Trying to reconnect.'+err); - }); - - /*app.kafkaClient = new kafka.Client(app.kafkaConfig.host+':'+app.kafkaConfig.port+'/', - app.kafkaConfig.clientName); - app.kafkaClient.on('ready', function() { - console.log('Client connected to Zookeeper.'.green); - - app.kafkaProducer = new kafka.HighLevelProducer(app.kafkaClient); - app.kafkaProducer.on('error', function() {}); - - callback(); - }); - app.kafkaClient.on('error', function() { - console.log('Kafka broker not available.'.red+' Trying to reconnect.'); - });*/ } ], OnServicesConnect); diff --git a/config.example.json b/config.example.json index 34c99b7..ecd069f 100644 --- a/config.example.json +++ b/config.example.json @@ -1,6 +1,6 @@ { "main_database": "ElasticSearch", - "message_queue": "Kafka", + "message_queue": "kafka", "ElasticSearch": { "host": "hostname", "port": 9200, @@ -10,7 +10,7 @@ "host": "10.0.0.1", "port": 6379 }, - "Kafka": { + "kafka": { "host": "10.0.0.2", "port": 2181 }, diff --git a/controllers/object.js b/controllers/object.js index 5d805e8..d88b623 100644 --- a/controllers/object.js +++ b/controllers/object.js @@ -584,7 +584,7 @@ router.post('/update', function(req, res, next) { track_callback(err); }); }*/ - ], function(err, results) { + ], function(err) { if (err) { console.log(req.originalUrl+': '+err.message.red); return next(err); diff --git a/controllers/user.js b/controllers/user.js index c89ff42..a63a67f 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -287,7 +287,7 @@ router.post('/register', function(req, res, next) { })], 'aggregation', callback); }, //add this user to his/her friends array - function(result, callback) { + function(callback) { if (fbFriends.length) { app.messagingClient.send([JSON.stringify({fid: userProfile.id, friends: fbFriends})], 'update_friends', callback); diff --git a/test/admin/admin.js b/test/admin/admin.js index 80ef868..9fc32c3 100644 --- a/test/admin/admin.js +++ b/test/admin/admin.js @@ -1481,7 +1481,7 @@ describe('Schema', function() { }); it('should return a error response to indicate a model was NOT removed from the application because model was missing from the request', function(done) { - + this.timeout(4*DELAY); request(url) .post('/admin/schema/remove_model') .set('Content-type','application/json') diff --git a/test/user/user.js b/test/user/user.js index 600e36c..5f7717c 100644 --- a/test/user/user.js +++ b/test/user/user.js @@ -515,7 +515,7 @@ it('should return a success response to indicate that the user has registered', }); it('should return a success response to indicate that the user has NOT registered', function(done) { - + this.timeout(10*DELAY); var clientrequest = { "email": userEmail, "password": "secure_password1337", @@ -532,7 +532,7 @@ it('should return a success response to indicate that the user has NOT registere .end(function(err, res) { res.statusCode.should.be.equal(409); - done(); + setTimeout(done, 5*DELAY); }); }); From 64429c5db2dc1e5b8493df316a422f8b35bf7ea1 Mon Sep 17 00:00:00 2001 From: Razvan Botea Date: Thu, 1 Oct 2015 12:05:55 +0300 Subject: [PATCH 19/42] Extended timeout to a test to pass * code cleanup --- app.js | 1 - controllers/admin.js | 30 +++++++++++++++--------------- controllers/security.js | 10 ---------- controllers/user.js | 1 - test/admin/admin.js | 2 +- 5 files changed, 16 insertions(+), 28 deletions(-) diff --git a/app.js b/app.js index 69aaa87..6878821 100644 --- a/app.js +++ b/app.js @@ -196,7 +196,6 @@ async.waterfall([ */ app.messagingClient = new Models[messagingClient](clientConfiguration, 'telepat-api'); app.messagingClient.onReady(function() { - console.log(('Connected to Messaging Client '+messagingClient).green); callback(); }); } diff --git a/controllers/admin.js b/controllers/admin.js index 4fa6dc9..05368bb 100644 --- a/controllers/admin.js +++ b/controllers/admin.js @@ -12,21 +12,21 @@ var userRoute = require('./admin/user'); var security = require('./security'); var Models = require('telepat-models'); -// var unless = function(paths, middleware) { - // return function(req, res, next) { - // var excluded = false; - // for (var i=0; i Date: Thu, 1 Oct 2015 11:45:08 +0000 Subject: [PATCH 20/42] removed unused vars added admin/app/deauthorize tests added admin/app/authorize tests added context/add tests updated context/update tests added admin/user/update tests added /user/register tests added /user/login_password tests added /user/refresh_token tests --- test/admin/admin.js | 185 +++++++++++++++++++++++++++------ test/object/object.js | 2 +- test/user/user.js | 230 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 379 insertions(+), 38 deletions(-) diff --git a/test/admin/admin.js b/test/admin/admin.js index 524a480..f0d0bb5 100644 --- a/test/admin/admin.js +++ b/test/admin/admin.js @@ -1,8 +1,6 @@ var common = require('../common'); var request = common.request; var should = common.should; -var assert = common.assert; -var crypto = common.crypto; var url = common.url; var DELAY = common.DELAY; @@ -27,7 +25,6 @@ var admin2 = { var token2; var authValue2; -var deletedcontextID; var userEmail = 'user'+Math.round(Math.random()*1000000)+'@example.com'; @@ -809,9 +806,29 @@ describe('App', function() { }); }); + it('should return an error response to indicate admin has NOT been deauthorized because of empty request body', function(done) { + + request(url) + .post('/admin/app/deauthorize') + .set('Content-type','application/json') + .set('X-BLGREQ-APPID', appID) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') + .set('Authorization', authValue ) + .send() + .end(function(err, res) { + + if(res) + res.statusCode.should.be.equal(400); + done(); + }); + }); + + it('should return an error response to indicate admin has NOT been deauthorized because of the email field is missing', function(done) { - var clientrequest = {}; + var clientrequest = { + "something": adminEmail2 + }; request(url) .post('/admin/app/deauthorize') @@ -828,6 +845,27 @@ describe('App', function() { }); }); + it('should return an error response to indicate admin has NOT been deauthorized because admin was not found in application', function(done) { + + var clientrequest = { + "email": adminEmail2 + }; + + request(url) + .post('/admin/app/deauthorize') + .set('Content-type','application/json') + .set('X-BLGREQ-APPID', appID) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') + .set('Authorization', authValue2 ) + .send(clientrequest) + .end(function(err, res) { + + if(res) + res.statusCode.should.be.equal(401); + done(); + }); + }); + it('should return an error response to indicate admin with email address is the last admin of the application', function(done) { var clientrequest = { @@ -873,7 +911,7 @@ describe('App', function() { describe('Context', function() { - it('should return a success response to indicate context succesfully created', function(done) { + it('should return a success response to indicate context successfully created', function(done) { var clientrequest = { "name": "context", @@ -896,6 +934,21 @@ describe('Context', function() { }); }); + it('should return an error response to indicate context was NOT successfully created because of empty request body', function(done) { + + request(url) + .post('/admin/context/add') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .set('X-BLGREQ-APPID', appID ) + .send() + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); + }); + it('should return the requested context', function(done) { var clientrequest = { @@ -991,34 +1044,45 @@ describe('Context', function() { }); }); - it('should return an error response to indicate context was NOT updated because patches are missing', function(done) { + it('should return an error response to indicate context was NOT updated because context was not found', function(done) { var clientrequest = { - "id": Math.round(Math.random()*1000000)+100, - "name": "new name" + "id": contextID + '66', + "patches": [ + { + "op": "replace", + "path": "context/"+contextID + '66' +"/name", + "value": "New name" + } + ] }; request(url) .post('/admin/context/update') .set('Content-type','application/json') - .set('Authorization', authValue ) .set('X-BLGREQ-APPID', appID ) + .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - res.statusCode.should.be.equal(400); + res.statusCode.should.be.equal(404); done(); }); }); - it('should return an error response to indicate context was NOT updated because of missing request body', function(done) { + it('should return an error response to indicate context was NOT updated because patches are missing', function(done) { + + var clientrequest = { + "id": Math.round(Math.random()*1000000)+100, + "name": "new name" + }; request(url) .post('/admin/context/update') .set('Content-type','application/json') .set('Authorization', authValue ) .set('X-BLGREQ-APPID', appID ) - .send() + .send(clientrequest) .end(function(err, res) { res.statusCode.should.be.equal(400); @@ -1026,19 +1090,14 @@ describe('Context', function() { }); }); - it('should return an error response to indicate context was NOT updated because patches are missing', function(done) { - - var clientrequest = { - "id": Math.round(Math.random()*1000000)+100, - "name": "new name" - }; + it('should return an error response to indicate context was NOT updated because of missing request body', function(done) { request(url) .post('/admin/context/update') .set('Content-type','application/json') .set('Authorization', authValue ) .set('X-BLGREQ-APPID', appID ) - .send(clientrequest) + .send() .end(function(err, res) { res.statusCode.should.be.equal(400); @@ -1046,7 +1105,6 @@ describe('Context', function() { }); }); - it('should return an error response to indicate context was NOT updated because patches is empty', function(done) { var clientrequest = { @@ -1070,7 +1128,14 @@ describe('Context', function() { it('should return an error response to indicate context was NOT updated because of missing context id', function(done) { var clientrequest = { - "name": "new name" + "name": "new name", + "patches": [ + { + "op": "replace", + "path": "context/"+contextID+"/name", + "value": "New name" + } + ] }; request(url) @@ -1423,7 +1488,7 @@ describe('Schema', function() { }); it('should return a success response to indicate a model was removed from the application', function(done) { - this.timeout(6*DELAY); + var clientrequest = { "model_name": "things" }; @@ -1471,7 +1536,7 @@ describe('Schema', function() { .post('/admin/schema/remove_model') .set('Content-type','application/json') .set('Authorization', authValue ) - .set('X-BLGREQ-APPID', appID + '66' ) + .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { @@ -1481,16 +1546,20 @@ describe('Schema', function() { }); it('should return a error response to indicate a model was NOT removed from the application because model was missing from the request', function(done) { - this.timeout(4*DELAY); + + var clientrequest = { + "something": "others" + }; + request(url) .post('/admin/schema/remove_model') .set('Content-type','application/json') .set('Authorization', authValue ) - .set('X-BLGREQ-APPID', appID + '66' ) - .send() + .set('X-BLGREQ-APPID', appID) + .send(clientrequest) .end(function(err, res) { - res.statusCode.should.be.equal(404); + res.statusCode.should.be.equal(400); done(); }); }); @@ -1522,7 +1591,7 @@ describe('User', function() { }); }); - it('should return a success response to indicate that an user was updated', function(done) { + it('should return a success response to indicate that an user name was updated', function(done) { this.timeout(12*DELAY); var clientrequest = { @@ -1545,16 +1614,44 @@ describe('User', function() { .set('Authorization', authValue) .send(clientrequest) .end(function(err, res) { - + //console.log(clientrequest); //console.log(res.body); res.statusCode.should.be.equal(200); setTimeout(done, 8*DELAY); }); }); - it('should return a success response to indicate that an user was NOT updated, user was missing from the request', function(done) { + it('should return a success response to indicate that an user password was updated', function(done) { + this.timeout(12*DELAY); - var clientrequest = {}; + var clientrequest = { + "email" : userEmail, + "patches": [ + { + "op": "replace", + "path": "user/"+userEmail+"/password", + "value": "new value" + } + ] + }; + + request(url) + .post('/admin/user/update') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-APPID', appID) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') + .set('Authorization', authValue) + .send(clientrequest) + .end(function(err, res) { + + //console.log(res.body); + res.statusCode.should.be.equal(200); + setTimeout(done, 8*DELAY); + }); + }); + + it('should return an error response to indicate that an user was NOT updated, user was missing from the request', function(done) { request(url) .post('/admin/user/update') @@ -1563,7 +1660,7 @@ describe('User', function() { .set('X-BLGREQ-APPID', appID ) .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .set('Authorization', authValue ) - .send(clientrequest) + .send() .end(function(err, res) { res.statusCode.should.be.equal(400); @@ -1571,7 +1668,7 @@ describe('User', function() { }); }); - it('should return a success response to indicate that an user was NOT updated, user email address was missing from the request', function(done) { + it('should return an error response to indicate that an user was NOT updated, user email address was missing from the request', function(done) { var clientrequest = { "user": { @@ -1594,6 +1691,28 @@ describe('User', function() { }); }); + it('should return an error response to indicate that an user was NOT updated because patches is empty', function(done) { + + var clientrequest = { + "email" : userEmail, + "patches": [] + }; + + request(url) + .post('/admin/user/update') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .set('Authorization', authValue ) + .send(clientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); + }); + it('should return a success response indicating that a user has been deleted', function(done) { this.timeout(40*DELAY); diff --git a/test/object/object.js b/test/object/object.js index 001b3be..cc22791 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -495,7 +495,7 @@ it('should return a success response to indicate that a object has been updated' }); }); -it('should return a success response to indicate that a object has NOT been updated bacause of bad authentication', function(done) { +it('should return a success response to indicate that a object has NOT been updated because of bad authentication', function(done) { var clientrequest = { "model": "comments", diff --git a/test/user/user.js b/test/user/user.js index 5f7717c..cc12995 100644 --- a/test/user/user.js +++ b/test/user/user.js @@ -194,7 +194,7 @@ it('should return a success response to indicate that the user has logged in via }); }); -it('should return a success response to indicate that the user info was retrived', function(done) { +it('should return a success response to indicate that the user info was retrieved', function(done) { request(url) .get('/user/me') @@ -211,6 +211,73 @@ it('should return a success response to indicate that the user info was retrived }); }); +it('should return an error response to indicate that the user info was NOT retrieved because user was not found', function(done) { + + this.timeout(25*DELAY); + + var clientrequest = { + "email": "exampleUser@appscend.com", + "password": "secure_password1337", + "name": "John Smith" + }; + + request(url) + .post('/user/register') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .send(clientrequest) + .end(function(err, res) { + setTimeout(function() { + request(url) + .post('/user/login_password') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .send(clientrequest) + .end(function(err, res) { + + var token3 = res.body.content.token; + var userID3 = res.body.content.user.id; + var authValue3 = 'Bearer ' + token3; + var subclientrequest = { + "id" : userID3, + "email" : "exampleUser@appscend.com" + }; + + request(url) + .post('/user/delete') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', authValue3) + .send(subclientrequest) + .end(function(err, res) { + + setTimeout(function(){ + + request(url) + .get('/user/me') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .set('Authorization', authValue3 ) + .send() + .end(function(err, res) { + + res.statusCode.should.be.equal(404); + done(); + }); + },10*DELAY); + }); + }); + }, 7*DELAY); + }); +}); + it('should return an error response to indicate that the user has NOT logged in via user & password because of Invalid Credentials', function(done) { var clientrequest = { @@ -254,6 +321,46 @@ it('should return an error response to indicate that the user has NOT logged in }); }); +it('should return an error response to indicate that the user has NOT logged in via user & password because email was missing for request', function(done) { + + var clientrequest = { + "password": "secure_password", + "name": "John Smith" + }; + + request(url) + .post('/user/login_password') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .send(clientrequest) + .end(function(err, res) { + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('should return an error response to indicate that the user has NOT logged in via user & password because password was missing for request', function(done) { + + var clientrequest = { + "email": 'user'+Math.round(Math.random()*1000000)+'@example.com', + "name": "John Smith" + }; + + request(url) + .post('/user/login_password') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .send(clientrequest) + .end(function(err, res) { + res.statusCode.should.be.equal(400); + done(); + }); +}); + it('should return a success response to indicate that the user was updated', function(done) { var clientrequest = { @@ -473,6 +580,105 @@ it('should return an error response to indicate that the token was NOT updated b }); }); +it('should return an error response to indicate that the token was NOT updated because authorization is missing', function(done) { + + request(url) + .get('/user/refresh_token') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .send() + .end(function(err, res) { + + res.statusCode.should.be.equal(401); + done(); + }); +}); + +it('should return an error response to indicate that the token was NOT updated because X-BLGREQ-SIGN is missing', function(done) { + + request(url) + .get('/user/refresh_token') + .set('Content-type','application/json') + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', authValue ) + .send() + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('should return an error response to indicate that the token was NOT updated because Content-type is not application/json', function(done) { + + request(url) + .get('/user/refresh_token') + .set('Content-type','application/other') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', authValue ) + .send() + .end(function(err, res) { + + res.statusCode.should.be.equal(415); + done(); + }); +}); + +it('should return an error response to indicate that the token was NOT updated because of invalid api key', function(done) { + + request(url) + .get('/user/refresh_token') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 + '66') + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', authValue ) + .send() + .end(function(err, res) { + + res.statusCode.should.be.equal(401); + done(); + }); +}); + +it('should return an error response to indicate that the token was NOT updated because of missing UDID', function(done) { + + request(url) + .get('/user/refresh_token') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', authValue ) + .send() + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('should return an error response to indicate that the token was NOT updated because device ID does not exist', function(done) { + + request(url) + .get('/user/refresh_token') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification + '66') + .set('X-BLGREQ-APPID',appID+ '66') + .set('Authorization', authValue ) + .send() + .end(function(err, res) { + + res.statusCode.should.be.equal(404); + done(); + }); +}); + it('should return a success response to indicate that the user logged out', function(done) { request(url) @@ -514,8 +720,8 @@ it('should return a success response to indicate that the user has registered', }); }); -it('should return a success response to indicate that the user has NOT registered', function(done) { - this.timeout(10*DELAY); +it('should return a success response to indicate that the user has NOT registered because user is already registered', function(done) { + var clientrequest = { "email": userEmail, "password": "secure_password1337", @@ -532,7 +738,23 @@ it('should return a success response to indicate that the user has NOT registere .end(function(err, res) { res.statusCode.should.be.equal(409); - setTimeout(done, 5*DELAY); + done(); + }); +}); + +it('should return a success response to indicate that the user has NOT registered because of empty body', function(done) { + + request(url) + .post('/user/register') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .send() + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); }); }); From 12411749b12e51b4f72d8df34b258d558355b5ce Mon Sep 17 00:00:00 2001 From: Alexandrescu Sergiu Date: Thu, 1 Oct 2015 11:49:57 +0000 Subject: [PATCH 21/42] added timeout to admin/schema/remove_model test --- test/admin/admin.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/admin/admin.js b/test/admin/admin.js index f0d0bb5..23fdf5d 100644 --- a/test/admin/admin.js +++ b/test/admin/admin.js @@ -1488,6 +1488,7 @@ describe('Schema', function() { }); it('should return a success response to indicate a model was removed from the application', function(done) { + this.timeout(6*DELAY); var clientrequest = { "model_name": "things" From 6a8509f063e29961995878f4054c1438775b9fa2 Mon Sep 17 00:00:00 2001 From: Alexandrescu Sergiu Date: Thu, 1 Oct 2015 12:16:43 +0000 Subject: [PATCH 22/42] a small fix in controllers/device.js added a device/register test --- controllers/device.js | 3 ++- test/device/device.js | 19 ++++++++++++++++--- test/object/object.js | 14 +++++--------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/controllers/device.js b/controllers/device.js index 3847a3e..8c8187a 100644 --- a/controllers/device.js +++ b/controllers/device.js @@ -105,11 +105,12 @@ router.post('/register', function(req, res, next) { }); } } else { - req.body.id = req._telepat.device_id; if (Object.getOwnPropertyNames(req.body).length === 0) return next(new Models.TelepatError(Models.TelepatError.errors.RequestBodyEmpty)); + req.body.id = req._telepat.device_id; + Models.Subscription.updateDevice(req._telepat.device_id, req.body, function(err, result) { if (err && err.status == 404) { return next(new Models.TelepatError(Models.TelepatError.errors.DeviceNotFound)); diff --git a/test/device/device.js b/test/device/device.js index c812712..4a9bd75 100644 --- a/test/device/device.js +++ b/test/device/device.js @@ -206,14 +206,27 @@ it('should return an error response to indicate device NOT succesfully registere it('should return an error response to indicate device NOT succesfully registered because of missing body', function(done) { - var clientrequest = {}; - request(url) .post('/device/register') .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', '') .set('X-BLGREQ-APPID',1) - .send(clientrequest) + .send() + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('should return an error response to indicate device NOT succesfully registered because of missing body and invalidUDID', function(done) { + + request(url) + .post('/device/register') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', 'invalidUDID') + .set('X-BLGREQ-APPID',1) + .send() .end(function(err, res) { res.statusCode.should.be.equal(400); diff --git a/test/object/object.js b/test/object/object.js index cc22791..d935a07 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -1126,9 +1126,8 @@ it('should return an error response to indicate that the object id was missing', var clientrequest = { "model": "comments", "context": contextID, - "content": { - } - } + "content": {} + }; request(url) .post('/object/delete') @@ -1149,8 +1148,7 @@ it('should return an error response to indicate that the object model was missin var clientrequest = { "context": contextID, "id" : 1, - "content": { - } + "content": {} }; request(url) @@ -1173,8 +1171,7 @@ it('should return an error response to indicate that the object was not deleted "model": "comments", "context": contextID, "id" : 1, - "content": { - } + "content": {} }; request(url) @@ -1195,8 +1192,7 @@ it('should return an error response to indicate that the object was not deleted var clientrequest = { "model": "comments", "id" : 1, - "content": { - } + "content": {} }; request(url) From dfc6330de3968ecb1cad4731fa36df226bc41167 Mon Sep 17 00:00:00 2001 From: Alexandrescu Sergiu Date: Thu, 1 Oct 2015 12:28:43 +0000 Subject: [PATCH 23/42] fixed a small bug --- controllers/context.js | 2 +- test/context/context.js | 48 ++++++++++++++++++++--------------------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/controllers/context.js b/controllers/context.js index f79d38e..5a96b3d 100644 --- a/controllers/context.js +++ b/controllers/context.js @@ -100,7 +100,7 @@ router.post('/', function (req, res, next) { } Models.Context(req.body.id, function (err, res1) { - if (err && err.status === 404){ + if (err && err.status == 404){ return next(new Models.TelepatError(Models.TelepatError.errors.ContextNotFound)); } else if (err) next(err); diff --git a/test/context/context.js b/test/context/context.js index f0e00be..7a3c113 100644 --- a/test/context/context.js +++ b/test/context/context.js @@ -27,30 +27,30 @@ var admin = { }; before(function(done){ - + this.timeout(10000); - + var clientrequest = { "name": "test-app", "keys": [ common.appKey ] }; - + request(url) .post('/admin/add') .send(admin) .end(function(err, res) { - + setTimeout(function () { - + request(url) .post('/admin/login') .set('Content-type','application/json') .send(admin) .end(function(err, res) { - + var token = res.body.content.token; authValue = 'Bearer ' + token; - + request(url) .post('/admin/app/add') .set('Content-type','application/json') @@ -66,14 +66,14 @@ before(function(done){ }); before(function(done){ - + this.timeout(10*DELAY); - + var clientrequest = { "name": "context", "meta": {"info": "some meta info"}, }; - + request(url) .post('/admin/context/add') .set('Content-type','application/json') @@ -81,18 +81,18 @@ before(function(done){ .set('X-BLGREQ-APPID', appID ) .send(clientrequest) .end(function(err, res) { - + contextID = res.body.content.id; done(); }); }); it('should return a success response to indicate context succesfully retrived', function(done) { - + var clientrequest = { "id": contextID }; - + request(url) .post('/context') .set('Content-type','application/json') @@ -102,16 +102,14 @@ it('should return a success response to indicate context succesfully retrived', .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(200); done(); }); }); it('should return an error response to indicate context wa NOT succesfully retrived because of missing context ID', function(done) { - - var clientrequest = {}; - + request(url) .post('/context') .set('Content-type','application/json') @@ -119,36 +117,36 @@ it('should return an error response to indicate context wa NOT succesfully retri .set('X-BLGREQ-APPID', appID ) .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .set('Authorization', authValue ) - .send(clientrequest) + .send() .end(function(err, res) { - + res.statusCode.should.be.equal(400); done(); }); }); it('should return an error response to indicate context NOT succesfully retrived because of bad context ID', function(done) { - + var clientrequest = { id: Math.round(Math.random()*1000000)+1000 }; - + request(url) - .get('/context') + .post('/context') .set('X-BLGREQ-SIGN', appIDsha256 ) .set('X-BLGREQ-APPID', appID ) .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { - + res.statusCode.should.be.equal(404); done(); }); }); it('should return a success response to indicate all contexts succesfully retrived', function(done) { - + request(url) .get('/context/all') .set('Content-type','application/json') @@ -158,7 +156,7 @@ it('should return a success response to indicate all contexts succesfully retriv .set('Authorization', authValue ) .send() .end(function(err, res) { - + res.statusCode.should.be.equal(200); done(); }); From e5fac6cce19e5c3c7d9212547fc2faf0a75e78c2 Mon Sep 17 00:00:00 2001 From: Razvan Botea Date: Fri, 2 Oct 2015 12:18:55 +0300 Subject: [PATCH 24/42] Small code cleanup --- app.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app.js b/app.js index 6878821..4fe323e 100644 --- a/app.js +++ b/app.js @@ -195,9 +195,7 @@ async.waterfall([ * @type {MessagingClient} */ app.messagingClient = new Models[messagingClient](clientConfiguration, 'telepat-api'); - app.messagingClient.onReady(function() { - callback(); - }); + app.messagingClient.onReady(callback); } ], OnServicesConnect); From 15d8527e9e52b5db8a84f65d7ead99d81d6fbb76 Mon Sep 17 00:00:00 2001 From: Razvan Botea Date: Fri, 2 Oct 2015 12:28:02 +0300 Subject: [PATCH 25/42] Variable checks for main_database and message_queue --- app.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app.js b/app.js index 4fe323e..1b71037 100644 --- a/app.js +++ b/app.js @@ -80,6 +80,11 @@ if (validEnvVariables) { messagingClient = mainConfiguration.message_queue; } +if (!Models[mainDatabase]) { + console.log('Unable to load'.red+' "'+mainDatabase+'" main database: not found.\nAborting...'); + process.exit(-1); +} + Models.Application.datasource = new Models.Datasource(); Models.Application.datasource.setMainDatabase(new Models[mainDatabase](mainConfiguration[mainDatabase])); @@ -191,6 +196,11 @@ async.waterfall([ var clientConfiguration = mainConfiguration[messagingClient]; + if (!Models[messagingClient]) { + console.log('Unable to load'.red+' "'+messagingClient+'" messaging queue: not found. Aborting...'); + process.exit(-1); + } + /** * @type {MessagingClient} */ From f9d921d63c304a6749b1c8e7e6497cee1a300d8f Mon Sep 17 00:00:00 2001 From: Alexandrescu Sergiu Date: Fri, 2 Oct 2015 12:24:13 +0000 Subject: [PATCH 26/42] added invalid route test added /context test added more /object/create tests added more /object/subscribe tests added one more /user/login test cleaned up some tests --- test/admin/admin.js | 19 ++++ test/context/context.js | 20 ++++ test/object/object.js | 210 +++++++++++++++++++++++++++++++++++++++- test/user/user.js | 24 ++++- 4 files changed, 267 insertions(+), 6 deletions(-) diff --git a/test/admin/admin.js b/test/admin/admin.js index 23fdf5d..c2fd580 100644 --- a/test/admin/admin.js +++ b/test/admin/admin.js @@ -1564,6 +1564,25 @@ describe('Schema', function() { done(); }); }); + + it('should return a error response to indicate a model was NOT removed from the application because of bad route', function(done) { + + var clientrequest = { + "something": "others" + }; + + request(url) + .post('/admin/schema/remove_mode') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .set('X-BLGREQ-APPID', appID) + .send(clientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(404); + done(); + }); + }); }); describe('User', function() { diff --git a/test/context/context.js b/test/context/context.js index 7a3c113..1e4a3d5 100644 --- a/test/context/context.js +++ b/test/context/context.js @@ -145,6 +145,26 @@ it('should return an error response to indicate context NOT succesfully retrived }); }); +it('should return an error response to indicate context NOT succesfully retrived because of missing authorization', function(done) { + + var clientrequest = { + id: contextID + }; + + request(url) + .post('/context') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + + .send(clientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(404); + done(); + }); +}); + it('should return a success response to indicate all contexts succesfully retrived', function(done) { request(url) diff --git a/test/object/object.js b/test/object/object.js index d935a07..e55340f 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -1,8 +1,6 @@ var common = require('../common'); var request = common.request; var should = common.should; -var assert = common.assert; -var crypto = common.crypto; var url = common.url; var DELAY = common.DELAY; @@ -14,6 +12,7 @@ var appID; var authValue; var userAuthValue; var contextID; +var appKey = common.appKey; var subclientrequest = { "channel": { @@ -114,9 +113,36 @@ before(function(done){ "type": "string" } }, + "belongsTo": [ + { + "parentModel": "events", + "relationType": "hasMany" + } + ], "read_acl": 6, "write_acl": 6, "meta_read_acl": 6 + }, + "events": { + "namespace": "events", + "type": "events", + "properties": { + "text": { + "type": "string" + }, + "image": { + "type": "string" + }, + "options": { + "type": "object" + } + }, + "hasMany": [ + "comments" + ], + "read_acl": 7, + "write_acl": 7, + "meta_read_acl": 4 } } }; @@ -330,7 +356,7 @@ it('should return an error response to indicate that object has NOT been created }); }); -it('should return an error response to indicate that object has NOT been created because of missing model', function(done) { +it('should return an error response to indicate that object has NOT been created because of missing model in request body', function(done) { var clientrequest = { "context": contextID, @@ -353,6 +379,97 @@ it('should return an error response to indicate that object has NOT been created }); }); +it('should return an error response to indicate that object has NOT been created because content is missing', function(done) { + + var clientrequest = { + "context": contextID, + "model": "comments", + }; + + request(url) + .post('/object/create') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send(clientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(500); + done(); + }); +}); + +it('should return an error response to indicate that object has NOT been created because content is empty', function(done) { + + var clientrequest = { + "context": contextID, + "model": "comments", + "content": {} + }; + + request(url) + .post('/object/create') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send(clientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('should return an error response to indicate that object has NOT been created because of invalid parent', function(done) { + + var clientrequest = { + "context": contextID, + "model": "comments", + "content": { + "event_id" :1, + } + }; + + request(url) + .post('/object/create') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send(clientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('should return an error response to indicate that object has NOT been created because of model does not exist', function(done) { + + var clientrequest = { + "context": contextID, + "model": "something", + "content": { + "events_id" :1, + } + }; + + request(url) + .post('/object/create') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send(clientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(404); + done(); + }); +}); + it('should return an error response to indicate that object has NOT been created because of missing context', function(done) { var clientrequest = { @@ -751,6 +868,93 @@ it('should return a success response to indicate that a object has been subscrib }); }); +it('should return a success response to indicate that a object has been subscribed', function(done) { + + var subclientrequest = { + "channel": { + "context": contextID, + "model": "events" + }, + }; + + request(url) + .post('/object/subscribe') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send(subclientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(200); + done(); + }); +}); + +it('should return an error response to indicate that a object has NOT been subscribed because of invalid context', function(done) { + + var subclientrequest = { + "channel": { + "context": Math.round(Math.random()*1000000), + "model": "comments" + }, + }; + + request(url) + .post('/object/subscribe') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send(subclientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(500); + done(); + }); +}); + +it('should return an error response to indicate that a object has NOT been subscribed because context does not belong to app', function(done) { + + var clientrequest = { + "name": "test-app", + "keys": [ appKey ] + }; + + request(url) + .post('/admin/app/add') + .set('Content-type','application/json') + .set('Authorization', authValue) + .send(clientrequest) + .end(function(err, res) { + + var appID2 = res.body.content.id; + var subclientrequest = { + "channel": { + "context": contextID, + "model": "comments" + }, + }; + + request(url) + .post('/object/subscribe') + .set('Content-type', 'application/json') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID', appID2) + .set('Authorization', userAuthValue) + .send(subclientrequest) + .end(function (err, res) { + + res.statusCode.should.be.equal(404); + done(); + }); + }); +}); + + it('should return a success response to indicate that a object has NOT been subscribed', function(done) { var subclientrequest = { diff --git a/test/user/user.js b/test/user/user.js index cc12995..e41d11c 100644 --- a/test/user/user.js +++ b/test/user/user.js @@ -91,15 +91,13 @@ before(function(done){ it('should return an error response to indicate that the user has NOT logged via Facebook because of missing access token', function(done) { - var clientrequest = {}; - request(url) .post('/user/login') .set('Content-type','application/json') .set('X-BLGREQ-SIGN', appIDsha256 ) .set('X-BLGREQ-APPID', appID ) .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) - .send(clientrequest) + .send() .end(function(err, res) { //console.log(res.body); res.statusCode.should.be.equal(400); @@ -107,6 +105,26 @@ it('should return an error response to indicate that the user has NOT logged via }); }); +it('should return an error response to indicate that the user has NOT logged via Facebook because of invalid token', function(done) { + + var clientrequest = { + "access_token": "invalidToken" + }; + + request(url) + .post('/user/login') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .send(clientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(500); + done(); + }); +}); + it('should return a success response to indicate that the user has logged in via user & password', function(done) { this.timeout(13*DELAY); From e02d2406d8fec93e7fdea9666df6ec8c9f9c051e Mon Sep 17 00:00:00 2001 From: Razvan Botea Date: Fri, 2 Oct 2015 16:49:59 +0300 Subject: [PATCH 27/42] Added pagination support for subscribe requests. KR-159 * Fixed context routes which didn't require authorization * Added amqp to config example * Updated tests --- config.example.json | 5 +++++ controllers/admin.js | 5 +++-- controllers/admin/user.js | 13 ++++++++++--- controllers/context.js | 1 + controllers/object.js | 3 ++- package.json | 2 -- test/admin/admin.js | 8 ++++---- test/context/context.js | 2 +- 8 files changed, 26 insertions(+), 13 deletions(-) diff --git a/config.example.json b/config.example.json index ecd069f..595f8d3 100644 --- a/config.example.json +++ b/config.example.json @@ -14,5 +14,10 @@ "host": "10.0.0.2", "port": 2181 }, + "amqp": { + "host": "10.0.0.4", + "user": "telepat", + "password": "password" + }, "password_salt": "$2a$10$N9qo8uLOickgx2ZMRZoMye" } diff --git a/controllers/admin.js b/controllers/admin.js index 05368bb..b7e98f8 100644 --- a/controllers/admin.js +++ b/controllers/admin.js @@ -155,8 +155,9 @@ router.use('/users', * */ -router.get('/users', function(req, res, next) { - Models.User.getAll(req._telepat.applicationId, function(err, results) { +router.post('/users', function(req, res, next) { + var page = req.body.page ? req.body.page : 1; + Models.User.getAll(req._telepat.applicationId, page, function(err, results) { if (err) return next(err); results.forEach(function(item, index, originalArray) { diff --git a/controllers/admin/user.js b/controllers/admin/user.js index a001569..6897405 100644 --- a/controllers/admin/user.js +++ b/controllers/admin/user.js @@ -11,7 +11,7 @@ router.use('/all', security.applicationIdValidation, security.adminAppValidation); /** - * @api {get} /admin/user/all GetAppUsers + * @api {post} /admin/user/all GetAppUsers * @apiDescription Gets all users of the app * @apiName AdminGetUsers * @apiGroup Admin @@ -23,6 +23,12 @@ router.use('/all', Should have the format: Bearer $TOKEN * @apiHeader {String} X-BLGREQ-APPID Custom header which contains the application ID * + * @apiExample {json} Client Request + * + * { + * "page": 1 + * } + * * @apiSuccessExample {json} Success Response * { * "status": 200, @@ -34,10 +40,11 @@ router.use('/all', * @apiError 404 [011]ApplicationNotFound If the Application doesn't exist */ -router.get('/all', function(req, res, next) { +router.post('/all', function(req, res, next) { var appId = req._telepat.applicationId; + var page = req.body.page ? req.body.page : 1; - Models.User.getAll(appId, function(err, results) { + Models.User.getAll(appId, page, function(err, results) { if (err) return next(err); results.forEach(function(item, index, originalArray) { diff --git a/controllers/context.js b/controllers/context.js index 5a96b3d..30199dc 100644 --- a/controllers/context.js +++ b/controllers/context.js @@ -7,6 +7,7 @@ var security = require('./security'); router.use(security.applicationIdValidation); router.use(security.apiKeyValidation); router.use(security.deviceIdValidation); +router.use(security.tokenValidation); /** * @api {get} /context/all GetContexts diff --git a/controllers/object.js b/controllers/object.js index d88b623..974023a 100644 --- a/controllers/object.js +++ b/controllers/object.js @@ -125,6 +125,7 @@ router.post('/subscribe', function(req, res, next) { return next(new Models.TelepatError(Models.TelepatError.errors.RequestBodyEmpty)); } + var page = req.body.page ? req.body.page : 1; var channel = req.body.channel; if (!channel) { @@ -200,7 +201,7 @@ router.post('/subscribe', function(req, res, next) { callback(); }); } else { - Models.Model.search(channelObject, function(err, results) { + Models.Model.search(channelObject, page, function(err, results) { if (err) return callback(err); if (Array.isArray(results)) diff --git a/package.json b/package.json index 6215977..99fcaf3 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "bcrypt": "^0.8.5", "body-parser": "1.12.0", "colors": "1.1.0", - "cookie-parser": "1.3.4", "debug": "2.1.1", "express": "4.12.4", "express-jwt": "3.0.1", @@ -21,7 +20,6 @@ "morgan": "1.5.1", "object-sizeof": "1.0.6", "redis": "0.12.1", - "serve-favicon": "2.2.0", "telepat-models": "telepat-io/telepat-models#develop", "uuid": "2.0.1" }, diff --git a/test/admin/admin.js b/test/admin/admin.js index c2fd580..659f427 100644 --- a/test/admin/admin.js +++ b/test/admin/admin.js @@ -1917,7 +1917,7 @@ describe('User', function() { it('should return a success response to indicate that an admin list was retrived', function(done) { request(url) - .get('/admin/users') + .post('/admin/users') .set('Content-type','application/json') .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-APPID', appID) @@ -1934,7 +1934,7 @@ describe('User', function() { it('should return an error response to indicate that an admin list was NOT retrived for a bad app id', function(done) { request(url) - .get('/admin/users') + .post('/admin/users') .set('Content-type','application/json') .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-APPID', Math.round(Math.random()*1000000)+1000) @@ -1952,7 +1952,7 @@ describe('User', function() { it('should return a success response to indicate that an users list was retrived', function(done) { request(url) - .get('/admin/user/all') + .post('/admin/user/all') .set('Content-type','application/json') .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-APPID', appID) @@ -1973,7 +1973,7 @@ describe('User', function() { it('should return an error response to indicate that an users list was NOT retrived for a bad app id', function(done) { request(url) - .get('/admin/user/all') + .post('/admin/user/all') .set('Content-type','application/json') .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-APPID', Math.round(Math.random()*1000000)+1000) diff --git a/test/context/context.js b/test/context/context.js index 1e4a3d5..ff0789a 100644 --- a/test/context/context.js +++ b/test/context/context.js @@ -160,7 +160,7 @@ it('should return an error response to indicate context NOT succesfully retrived .send(clientrequest) .end(function(err, res) { - res.statusCode.should.be.equal(404); + res.statusCode.should.be.equal(401); done(); }); }); From 5dfa57a29b24cd93ce4f713d8bb56cad26f3b62e Mon Sep 17 00:00:00 2001 From: Razvan Botea Date: Fri, 2 Oct 2015 17:43:18 +0300 Subject: [PATCH 28/42] Removed tokenValidation middleware on object routes because objectACL already had that functionality integrated * Fixed objectACL so it would behave similarly to tokenValidation --- controllers/object.js | 64 ----------------------------------------- controllers/security.js | 13 ++++----- 2 files changed, 6 insertions(+), 71 deletions(-) diff --git a/controllers/object.js b/controllers/object.js index 974023a..a757a50 100644 --- a/controllers/object.js +++ b/controllers/object.js @@ -9,8 +9,6 @@ router.use(security.applicationIdValidation); router.use(security.apiKeyValidation); router.use(security.deviceIdValidation); -router.use(security.tokenValidation); - /** * Middleware used to load application model schema */ @@ -121,17 +119,9 @@ var validateContext = function(appId, context, callback) { * */ router.post('/subscribe', function(req, res, next) { - if (Object.getOwnPropertyNames(req.body).length === 0) { - return next(new Models.TelepatError(Models.TelepatError.errors.RequestBodyEmpty)); - } - var page = req.body.page ? req.body.page : 1; var channel = req.body.channel; - if (!channel) { - return next(new Models.TelepatError(Models.TelepatError.errors.MissingRequiredField, ['channel'])); - } - var id = channel.id, context = channel.context, mdl = channel.model, @@ -144,12 +134,6 @@ router.post('/subscribe', function(req, res, next) { if (!context) return next(new Models.TelepatError(Models.TelepatError.errors.MissingRequiredField, ['channel.context'])); - if (!mdl) - return next(new Models.TelepatError(Models.TelepatError.errors.MissingRequiredField, ['channel.model'])); - - if (!Models.Application.loadedAppModels[appId][mdl]) - return next(new Models.TelepatError(Models.TelepatError.errors.ApplicationSchemaModelNotFound, [appId, mdl])); - var channelObject = new Models.Channel(appId); if (id) { @@ -275,16 +259,8 @@ router.post('/subscribe', function(req, res, next) { * @apiError 400 [027]InvalidChannel When trying to subscribe to an invalid channel */ router.post('/unsubscribe', function(req, res, next) { - if (Object.getOwnPropertyNames(req.body).length === 0) { - return next(new Models.TelepatError(Models.TelepatError.errors.RequestBodyEmpty)); - } - var channel = req.body.channel; - if (!channel) { - return next(new Models.TelepatError(Models.TelepatError.errors.MissingRequiredField, ['channel'])); - } - var id = channel.id, context = channel.context, mdl = channel.model, @@ -297,12 +273,6 @@ router.post('/unsubscribe', function(req, res, next) { if (!context) return next(new Models.TelepatError(Models.TelepatError.errors.MissingRequiredField, ['channel.context'])); - if (!mdl) - return next(new Models.TelepatError(Models.TelepatError.errors.MissingRequiredField, ['channel.model'])); - - if (!Models.Application.loadedAppModels[appId][mdl]) - return next(new Models.TelepatError(Models.TelepatError.errors.ApplicationSchemaModelNotFound, [appId, mdl])); - var channelObject = new Models.Channel(appId); if (id) { @@ -398,10 +368,6 @@ router.post('/unsubscribe', function(req, res, next) { * */ router.post('/create', function(req, res, next) { - if (Object.getOwnPropertyNames(req.body).length === 0) { - return next(new Models.TelepatError(Models.TelepatError.errors.RequestBodyEmpty)); - } - var content = req.body.content; var mdl = req.body.model; var context = req.body.context; @@ -411,12 +377,6 @@ router.post('/create', function(req, res, next) { if (!context) return next(new Models.TelepatError(Models.TelepatError.errors.MissingRequiredField, ['channel.context'])); - if (!mdl) - return next(new Models.TelepatError(Models.TelepatError.errors.MissingRequiredField, ['channel.model'])); - - if (!Models.Application.loadedAppModels[appId][mdl]) - return next(new Models.TelepatError(Models.TelepatError.errors.ApplicationSchemaModelNotFound, [appId, mdl])); - content.type = mdl; content.context_id = context; content.application_id = appId; @@ -517,10 +477,6 @@ router.post('/create', function(req, res, next) { * } */ router.post('/update', function(req, res, next) { - if (Object.getOwnPropertyNames(req.body).length === 0) { - return next(new Models.TelepatError(Models.TelepatError.errors.RequestBodyEmpty)); - } - var modifiedMicrotime = microtime.now(); var context = req.body.context; var patch = req.body.patches; @@ -534,12 +490,6 @@ router.post('/update', function(req, res, next) { if (!context) return next(new Models.TelepatError(Models.TelepatError.errors.MissingRequiredField, ['context'])); - if (!mdl) - return next(new Models.TelepatError(Models.TelepatError.errors.MissingRequiredField, ['model'])); - - if (!Models.Application.loadedAppModels[appId][mdl]) - return next(new Models.TelepatError(Models.TelepatError.errors.ApplicationSchemaModelNotFound, [appId, mdl])); - if (!Array.isArray(req.body.patches)) { return next(new Models.TelepatError(Models.TelepatError.errors.InvalidFieldValue, ['"patches" is not an array'])); @@ -629,10 +579,6 @@ router.post('/update', function(req, res, next) { * */ router.post('/delete', function(req, res, next) { - if (Object.getOwnPropertyNames(req.body).length === 0) { - return next(new Models.TelepatError(Models.TelepatError.errors.RequestBodyEmpty)); - } - var id = req.body.id; var context = req.body.context; var mdl = req.body.model; @@ -644,12 +590,6 @@ router.post('/delete', function(req, res, next) { if (!context) return next(new Models.TelepatError(Models.TelepatError.errors.MissingRequiredField, ['context'])); - if (!mdl) - return next(new Models.TelepatError(Models.TelepatError.errors.MissingRequiredField, ['model'])); - - if (!Models.Application.loadedAppModels[appId][mdl]) - return next(new Models.TelepatError(Models.TelepatError.errors.ApplicationSchemaModelNotFound, [appId, mdl])); - async.series([ function(aggCallback) { app.messagingClient.send([JSON.stringify({ @@ -697,10 +637,6 @@ router.post('/delete', function(req, res, next) { * */ router.post('/count', function(req, res, next) { - if (Object.getOwnPropertyNames(req.body).length === 0) { - return next(new Models.TelepatError(Models.TelepatError.errors.RequestBodyEmpty)); - } - var appId = req._telepat.applicationId, channel = req.body.channel; diff --git a/controllers/security.js b/controllers/security.js index a652d05..09e3a5c 100644 --- a/controllers/security.js +++ b/controllers/security.js @@ -121,8 +121,10 @@ security.adminAppValidation = function (req, res, next) { security.objectACL = function (accessControl) { return function(req, res, next) { - if (!Object.getOwnPropertyNames(req.body).length) { - next(); + if (!req.headers.authorization) + return next(new Models.TelepatError(Models.TelepatError.errors.AuthorizationMissing)); + if (!req.body || !Object.getOwnPropertyNames(req.body).length) { + return next(new Models.TelepatError(Models.TelepatError.errors.RequestBodyEmpty)); } else if (req.body.model || (req.body.channel && req.body.channel.model)) { var mdl = req.body.model || req.body.channel.model; @@ -136,9 +138,6 @@ security.objectACL = function (accessControl) { var acl = Models.Application.loadedAppModels[req._telepat.applicationId][mdl][accessControl]; - if (!req.headers.authorization) - return next(new Models.TelepatError(Models.TelepatError.errors.AuthorizationMissing)); - if (acl & ACL_AUTHENTICATED || acl & ACL_ADMIN) { var authHeaderParts = req.headers.authorization.split(' '); var authToken = authHeaderParts[1]; @@ -146,7 +145,7 @@ security.objectACL = function (accessControl) { if (authToken) { jwt.verify(authToken, security.authSecret, function (err, decoded) { if (err) - return next(new Models.TelepatError(Models.TelepatError.errors.InvalidAuthorization, [err.message])); + return next(new Models.TelepatError(Models.TelepatError.errors.MalformedAuthorizationToken, [err.message])); if ((!(acl & ACL_UNAUTHENTICATED)) && (!(acl & ACL_AUTHENTICATED)) && (acl & ACL_ADMIN) && (!decoded.isAdmin) ) return next(new Models.TelepatError(Models.TelepatError.errors.OperationNotAllowed)); @@ -166,7 +165,7 @@ security.objectACL = function (accessControl) { return next(new Models.TelepatError(Models.TelepatError.errors.OperationNotAllowed)); } } else { - next(); + next(new Models.TelepatError(Models.TelepatError.errors.MissingRequiredField, ['model or channel.model'])); } } }; From 6bb570034cb9e9a5a48ee8df7b72e3766111c16b Mon Sep 17 00:00:00 2001 From: Alexandrescu Sergiu Date: Fri, 2 Oct 2015 15:06:24 +0000 Subject: [PATCH 29/42] added a /context test fixed a few typos --- test/context/context.js | 29 ++++++++++++++++++++++++----- test/object/object.js | 2 +- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/test/context/context.js b/test/context/context.js index ff0789a..dab9449 100644 --- a/test/context/context.js +++ b/test/context/context.js @@ -108,7 +108,7 @@ it('should return a success response to indicate context succesfully retrived', }); }); -it('should return an error response to indicate context wa NOT succesfully retrived because of missing context ID', function(done) { +it('should return an error response to indicate context wa NOT successfully retrieved because of missing context ID', function(done) { request(url) .post('/context') @@ -125,7 +125,7 @@ it('should return an error response to indicate context wa NOT succesfully retri }); }); -it('should return an error response to indicate context NOT succesfully retrived because of bad context ID', function(done) { +it('should return an error response to indicate context NOT successfully retrieved because of bad context ID', function(done) { var clientrequest = { id: Math.round(Math.random()*1000000)+1000 @@ -145,7 +145,7 @@ it('should return an error response to indicate context NOT succesfully retrived }); }); -it('should return an error response to indicate context NOT succesfully retrived because of missing authorization', function(done) { +it('should return an error response to indicate context NOT successfully retrieved because of missing authorization', function(done) { var clientrequest = { id: contextID @@ -156,7 +156,6 @@ it('should return an error response to indicate context NOT succesfully retrived .set('X-BLGREQ-SIGN', appIDsha256 ) .set('X-BLGREQ-APPID', appID ) .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) - .send(clientrequest) .end(function(err, res) { @@ -165,7 +164,27 @@ it('should return an error response to indicate context NOT succesfully retrived }); }); -it('should return a success response to indicate all contexts succesfully retrived', function(done) { +it('should return an error response to indicate context NOT successfully retrieved because of bad authorization', function(done) { + + var clientrequest = { + id: contextID + }; + + request(url) + .post('/context') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .set('Authorization', authValue + '66') + .send(clientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('should return a success response to indicate all contexts successfully retrieved', function(done) { request(url) .get('/context/all') diff --git a/test/object/object.js b/test/object/object.js index e55340f..072da6e 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -207,7 +207,7 @@ before(function(done){ deviceIdentification = res.body.content.identifier; var clientrequest = { - "email": 'admin'+Math.round(Math.random()*1000000)+'@example.com', + "email": 'user'+Math.round(Math.random()*1000000)+'@example.com', "password": "secure_password1337", "name": "John Smith" }; From 66fc2b7a9d82c6f9be2124e6cde08514f7a44136 Mon Sep 17 00:00:00 2001 From: Razvan Botea Date: Fri, 2 Oct 2015 18:49:23 +0300 Subject: [PATCH 30/42] Fixed /object/count --- controllers/object.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/object.js b/controllers/object.js index a757a50..0887cca 100644 --- a/controllers/object.js +++ b/controllers/object.js @@ -661,7 +661,7 @@ router.post('/count', function(req, res, next) { return next(new Models.TelepatError(Models.TelepatError.errors.InvalidChannel)); } - Models.Model.count(channel.model, appId, function(err, result) { + Models.Model.modelCountByChannel(channelObject, function(err, result) { if (err) return next(err); res.status(200).json({status: 200, content: result}).end(); From 5cbe65e7660deefa79210d8ebf48ac5f3f95eb35 Mon Sep 17 00:00:00 2001 From: Alexandrescu Sergiu Date: Mon, 5 Oct 2015 10:48:21 +0000 Subject: [PATCH 31/42] added a new object/unsubscribe test --- test/object/object.js | 85 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/test/object/object.js b/test/object/object.js index 072da6e..a284e99 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -1184,7 +1184,7 @@ it('should return an error response to indicate that a object has NOT been unsub }); }); -it('should return a error response to indicate that a object has NOT been unsubscribed', function(done) { +it('should return a error response (400) to indicate that a object has NOT been unsubscribed', function(done) { var subclientrequest = { "channel": { @@ -1210,6 +1210,89 @@ it('should return a error response to indicate that a object has NOT been unsubs }); }); +it('should return a error response (404) to indicate that a object has NOT been unsubscribed', function(done) { + + var subclientrequest = { + "channel": { + "context": contextID, + "model": "comments", + "id" : '66', + "parent": "parent", + "user": "user" + } + }; + + request(url) + .post('/object/unsubscribe') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send(subclientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(404); + done(); + }); +}); + +it('should return a error response (404) to indicate that a object has NOT been unsubscribed, using filters', function(done) { + + var subclientrequest = { + "channel": { + "context": contextID, + "model": "comments" + }, + "filters": { + "or": [ + { + "and": [ + { + "is": { + "gender": "male", + "age": 23 + } + }, + { + "range": { + "experience": { + "gte": 1, + "lte": 6 + } + } + } + ] + }, + { + "and": [ + { + "like": { + "image_url": "png", + "website": "png" + } + } + ] + } + ] + } + }; + + request(url) + .post('/object/unsubscribe') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send(subclientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(404); + done(); + }); +}); + it('should return a success response to indicate that a object has NOT been unsubscribed because of missing channel', function(done) { From 48163c2320da8750a8d1fe24ab5a6572a9aadc9c Mon Sep 17 00:00:00 2001 From: Alexandrescu Sergiu Date: Tue, 6 Oct 2015 08:04:25 +0000 Subject: [PATCH 32/42] deleted if.application[appID] return Models.TelepatError.errors.ApplicationNotFound from controllers/security.js added a /admin/contexts test for invalid appID request added answers to the schema, edited things in schema added /object/create test with events_id -1 added a /object/subscribe test with filters --- controllers/security.js | 4 -- test/admin/admin.js | 21 ++++++ test/object/object.js | 137 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 151 insertions(+), 11 deletions(-) diff --git a/controllers/security.js b/controllers/security.js index 09e3a5c..5d46604 100644 --- a/controllers/security.js +++ b/controllers/security.js @@ -105,10 +105,6 @@ security.tokenValidation = function(req, res, next) { security.adminAppValidation = function (req, res, next) { var appId = req._telepat.applicationId; - if (!app.applications[appId]) { - return next(new Models.TelepatError(Models.TelepatError.errors.ApplicationNotFound, [appId])); - } - if (!req.user) return next(); diff --git a/test/admin/admin.js b/test/admin/admin.js index 659f427..e9fd1e0 100644 --- a/test/admin/admin.js +++ b/test/admin/admin.js @@ -1273,6 +1273,27 @@ describe('Context', function() { }, 6*DELAY); }); + it('should NOT return all contexts using the old API because of invalid appID', function(done) { + + this.timeout(9*DELAY); + + setTimeout(function () { + + request(url) + .get('/admin/contexts') + .set('Content-type','application/json') + .set('Authorization', authValue) + .set('X-BLGREQ-APPID', appID + '66') + .send() + .end(function(err, res) { + + res.body.code.should.be.equal('011'); + res.statusCode.should.be.equal(404); + done(); + }); + }, 6*DELAY); + }); + it('should return a success response to indicate context was removed', function(done) { var clientrequest = { diff --git a/test/object/object.js b/test/object/object.js index a284e99..dd59fab 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -105,6 +105,20 @@ before(function(done){ var clientrequest = { "appId": appID, "schema": { + "answers": { + "namespace": "answers", + "type": "answers", + "properties": {}, + "belongsTo": [ + { + "parentModel": "events", + "relationType": "hasSome" + } + ], + "read_acl": 6, + "write_acl": 6, + "meta_read_acl": 6 + }, "comments": { "namespace": "comments", "type": "comments", @@ -124,6 +138,32 @@ before(function(done){ "meta_read_acl": 6 }, "events": { + "namespace": "events", + "type": "events", + "properties": { + "text": { + "type": "string" + }, + "image": { + "type": "string" + }, + "options": { + "type": "object" + } + }, + "hasMany": [ + "comments" + ], + "hasSome": [ + "answers" + ], + "read_acl": 7, + "write_acl": 7, + "meta_read_acl": 4, + "icon": "fa-image", + "hasSome_property": "options" + }, + "things": { "namespace": "events", "type": "events", "properties": { @@ -245,15 +285,13 @@ it('should return an error (400) response to indicate that the client made a bad this.timeout(10*DELAY); - var clientrequest = {}; - request(url) .post('/object/create') .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentification ) .set('X-BLGREQ-APPID',appID) .set('Authorization', userAuthValue ) - .send(clientrequest) + .send() .end(function(err, res) { res.statusCode.should.be.equal(400); @@ -283,6 +321,33 @@ it('should return an error (401) response to indicate that only authenticated us }); }); +it('should return a error response to indicate that a object has NOT been created', function(done) { + + var subclientrequest = { + "context": contextID, + "model": "answers", + "content": { + events_id: -1 + } + }; + + request(url) + .post('/object/create') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send(subclientrequest) + .end(function(err, res) { + + res.body.code.should.be.equal('004'); + res.body.status.should.be.equal(400); + res.statusCode.should.be.equal(400); + done(); + }); +}); + it('should return a success response to indicate that object has been created', function(done) { var clientrequest = { @@ -850,7 +915,7 @@ it('should return a success response to indicate that a object has been subscrib "channel": { "context": contextID, "model": "comments" - }, + } }; request(url) @@ -868,13 +933,70 @@ it('should return a success response to indicate that a object has been subscrib }); }); -it('should return a success response to indicate that a object has been subscribed', function(done) { +it('should return an error response to indicate that a object has NOT been subscribed because of invalid authorization', function(done) { + + var subclientrequest = { + "channel": { + "context": contextID, + "model": "comments" + } + }; + var userAuthValue = 'Bearer '; + request(url) + .post('/object/subscribe') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send(subclientrequest) + .end(function(err, res) { +console.log(res.body); + res.body.code.should.be.equal('014'); + res.statusCode.should.be.equal(401); + done(); + }); +}); + +it('should return an error response to indicate that a object has been NOT subscribed because of filters', function(done) { var subclientrequest = { "channel": { "context": contextID, "model": "events" }, + "filters": { + "or": [ + { + "and": [ + { + "is": { + "gender": "male", + "age": 23 + } + }, + { + "range": { + "experience": { + "gte": 1, + "lte": 6 + } + } + } + ] + }, + { + "and": [ + { + "like": { + "image_url": "png", + "website": "png" + } + } + ] + } + ] + } }; request(url) @@ -887,7 +1009,8 @@ it('should return a success response to indicate that a object has been subscrib .send(subclientrequest) .end(function(err, res) { - res.statusCode.should.be.equal(200); + res.body.code.should.be.equal('002'); + res.statusCode.should.be.equal(500); done(); }); }); @@ -1074,7 +1197,7 @@ it('should return a success response to indicate that a object has NOT been subs var subclientrequest = { "channel": { "context": contextID, - "model": "things" + "model": "somethings" } }; From ebe3b2c59651b005405af1adbe5c50057b09642a Mon Sep 17 00:00:00 2001 From: Alexandrescu Sergiu Date: Tue, 6 Oct 2015 11:40:09 +0000 Subject: [PATCH 33/42] added an admin/login test corrected documentation and changelog --- CHANGELOG.md | 6 +++--- controllers/admin.js | 4 ++-- controllers/admin/admin.js | 4 ++-- controllers/admin/app.js | 14 +++++++------- controllers/admin/context.js | 2 +- controllers/admin/schema.js | 4 ++-- controllers/admin/user.js | 14 +++++++------- controllers/context.js | 4 ++-- controllers/device.js | 4 ++-- controllers/object.js | 14 +++++++------- controllers/user.js | 24 ++++++++++++------------ test/admin/admin.js | 18 +++++++++++++++++- test/object/object.js | 2 +- 13 files changed, 65 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 905a20f..3edd1f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ * Implemented mocha tests, added istanbul code coverage and integrated with travis CI * Lots of bug fixes * All update endpoints require patches -* Admin routes are sepparated in more than 1 file +* Admin routes are separated in more than 1 file * Passwords are stored using bcrypt * There's only one configuration file in the root folder. The example provided should be used. The original config file was added to .gitignore @@ -21,7 +21,7 @@ was added to .gitignore * Fixed lots of bugs and server crashes * User info is returned on login calls (user & admin) -* Sepparated user login and user register endpoints +* Separated user login and user register endpoints * Admin endpoint for deleting users sends messages to aggregator to delete objects (1 message per object removed) * Standardized /admin endpoints responses * Each patch from /object/update is sent in 1 message to the aggregator @@ -45,7 +45,7 @@ was added to .gitignore * Application ID is verified if it exists in all requests that require it * Standardized response of get context and get all contexts -* The npm package now requires the corect telepat-models module from the npm registry +* The npm package now requires the correct telepat-models module from the npm registry # 0.1.4 diff --git a/controllers/admin.js b/controllers/admin.js index b7e98f8..e3431f0 100644 --- a/controllers/admin.js +++ b/controllers/admin.js @@ -40,7 +40,7 @@ router.use('/contexts', security.adminAppValidation); /** * @api {get} /admin/contexts GetContexts - * @apiDescription Get all contexsts + * @apiDescription Get all contexts * @apiName AdminGetContexts * @apiGroup Admin * @apiVersion 0.2.3 @@ -133,7 +133,7 @@ router.use('/users', security.adminAppValidation); /** * @api {get} /admin/users GetAppusers - * @apiDescription Gets all users of the app + * @apiDescription Gets all users of the application * @apiName AdminGetUsers * @apiGroup Admin * @apiVersion 0.2.3 diff --git a/controllers/admin/admin.js b/controllers/admin/admin.js index b7afa91..4ce6f2e 100644 --- a/controllers/admin/admin.js +++ b/controllers/admin/admin.js @@ -86,7 +86,7 @@ router.post('/login', function (req, res, next) { * * @apiHeader {String} Content-type application/json * - * @apiParam {String} email (REQUIRED) Admin e-mail + * @apiParam {String} email (REQUIRED) Admin email * @apiParam {String} password (REQUIRED) The password * @apiParam {String} name Real name of the admin * @@ -164,7 +164,7 @@ router.use('/update', security.tokenValidation); /** * @api {post} /admin/update Update * @apiDescription Updates the currently logged admin. - Every property in the request body is used to udpate the admin. + Every property in the request body is used to update the admin. * @apiName AdminUpdate * @apiGroup Admin * @apiVersion 0.2.3 diff --git a/controllers/admin/app.js b/controllers/admin/app.js index 649cb20..532ae82 100644 --- a/controllers/admin/app.js +++ b/controllers/admin/app.js @@ -9,8 +9,8 @@ var Models = require('telepat-models'); router.use('/add', security.tokenValidation); /** * @api {post} /admin/app/add AppCreate - * @apiDescription Creates a app for the admin. - The request body should contain the app itself. + * @apiDescription Creates a application for the admin. + The request body should contain the application itself. * @apiName AdminAppAdd * @apiGroup Admin * @apiVersion 0.2.3 @@ -67,7 +67,7 @@ router.use('/remove', security.adminAppValidation); /** * @api {post} /admin/app/remove RemoveApp - * @apiDescription Removes an app from the admin. + * @apiDescription Removes an application from the admin. * @apiName AdminAppRemove * @apiGroup Admin * @apiVersion 0.2.3 @@ -90,7 +90,7 @@ router.use('/remove', * { * "code": "011", * "status": 404, - * "message": "Application with ID $APPID doest not exist." + * "message": "Application with ID $APPID does not exist." * } * */ @@ -149,7 +149,7 @@ router.use('/update', * { * "code": "011", * "status": 404, - * "message": "Application with ID $APPID doest not exist." + * "message": "Application with ID $APPID does not exist." * } * */ @@ -215,7 +215,7 @@ router.use('/authorize', * { * "code": "011", * "status": 404, - * "message": "Application with ID $APPID doest not exist." + * "message": "Application with ID $APPID does not exist." * } */ router.post('/authorize', function(req, res, next) { @@ -290,7 +290,7 @@ router.use('/deauthorize', * { * "code": "011", * "status": 404, - * "message": "Application with ID $APPID doest not exist." + * "message": "Application with ID $APPID does not exist." * } * */ diff --git a/controllers/admin/context.js b/controllers/admin/context.js index ae3c9c7..64b3e59 100644 --- a/controllers/admin/context.js +++ b/controllers/admin/context.js @@ -12,7 +12,7 @@ router.use('/', security.adminAppValidation); /** * @api {get} /admin/context/all GetContexts - * @apiDescription Get all contexsts + * @apiDescription Get all contexts * @apiName AdminGetContexts * @apiGroup Admin * @apiVersion 0.2.3 diff --git a/controllers/admin/schema.js b/controllers/admin/schema.js index 4d88bd9..78f28df 100644 --- a/controllers/admin/schema.js +++ b/controllers/admin/schema.js @@ -124,8 +124,8 @@ router.use('/remove_model', * "model_name": "events" * } * - * @apiError 404 [011]ApplicationNotFound If the Application doesn't exist - * @apiError 404 [022]ApplicationSchemaModelNotFound If the App does not have a model with that name + * @apiError 404 [011]ApplicationNotFound If the application doesn't exist + * @apiError 404 [022]ApplicationSchemaModelNotFound If the application does not have a model with that name */ router.post('/remove_model', function(req, res, next) { if (!req.body.model_name) { diff --git a/controllers/admin/user.js b/controllers/admin/user.js index 6897405..fc66c25 100644 --- a/controllers/admin/user.js +++ b/controllers/admin/user.js @@ -12,7 +12,7 @@ router.use('/all', security.adminAppValidation); /** * @api {post} /admin/user/all GetAppUsers - * @apiDescription Gets all users of the app + * @apiDescription Gets all users of the application * @apiName AdminGetUsers * @apiGroup Admin * @apiVersion 0.2.3 @@ -37,7 +37,7 @@ router.use('/all', * ] * } * - * @apiError 404 [011]ApplicationNotFound If the Application doesn't exist + * @apiError 404 [011]ApplicationNotFound If the application doesn't exist */ router.post('/all', function(req, res, next) { @@ -61,7 +61,7 @@ router.use('/update', security.adminAppValidation); /** * @api {post} /admin/user/update UserUpdate - * @apiDescription Updates an user from an app + * @apiDescription Updates an user from an application * @apiName AdminUpdateUser * @apiGroup Admin * @apiVersion 0.2.3 @@ -91,7 +91,7 @@ router.use('/update', * "content" : "User has been updated" * } * - * @apiError 404 [023]UserNotFound If the User doesn't exist. + * @apiError 404 [023]UserNotFound If the user doesn't exist. * */ router.post('/update', function(req, res, next) { @@ -150,7 +150,7 @@ router.use('/delete', security.adminAppValidation); /** * @api {post} /admin/user/delete UserDelete - * @apiDescription Deletes an user from an app + * @apiDescription Deletes an user from an application * @apiName AdminDeleteUser * @apiGroup Admin * @apiVersion 0.2.3 @@ -161,7 +161,7 @@ router.use('/delete', Should have the format: Bearer $TOKEN * @apiHeader {String} X-BLGREQ-APPID Custom header which contains the application ID * - * @apiParam {String} email The email address of an user from an app + * @apiParam {String} email The email address of an user from an application * * @apiExample {json} Client Request * { @@ -174,7 +174,7 @@ router.use('/delete', * "content" : "User deleted" * } * - * @apiError 404 [023]UserNotFound If the User doesn't exist. + * @apiError 404 [023]UserNotFound If the user doesn't exist. */ router.post('/delete', function(req, res, next) { if (!req.body.email) { diff --git a/controllers/context.js b/controllers/context.js index 30199dc..11f8347 100644 --- a/controllers/context.js +++ b/controllers/context.js @@ -21,7 +21,7 @@ router.use(security.tokenValidation); * Should have the format: Bearer $TOKEN * @apiHeader {String} X-BLGREQ-APPID Custom header which contains the application ID * @apiHeader {String} X-BLGREQ-SIGN Custom header containing the SHA256-ed API key of the application - * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from devie/register) + * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from device/register) * * @apiSuccessExample {json} Success Response * { @@ -62,7 +62,7 @@ router.get('/all', function (req, res, next) { * @apiHeader {String} Authorization The authorization token obtained in the login endpoint. Should have the format: Bearer $TOKEN * @apiHeader {String} X-BLGREQ-APPID Custom header which contains the application ID * @apiHeader {String} X-BLGREQ-SIGN Custom header containing the SHA256-ed API key of the application - * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from devie/register) + * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from device/register) * * @apiParam {Number} id ID of the context to get * diff --git a/controllers/device.js b/controllers/device.js index 8c8187a..3c77d19 100644 --- a/controllers/device.js +++ b/controllers/device.js @@ -8,8 +8,8 @@ router.use(security.deviceIdValidation); /** * @api {post} /device/register Register - * @apiDescription Registers a new device or updates an already existing one. If device udid is supplied in info it will try - * to search for a device with this udid and return the device id. + * @apiDescription Registers a new device or updates an already existing one. If device UDID is supplied in info it will try + * to search for a device with this UDID and return the device ID. * @apiName DeviceRegister * @apiGroup Device * @apiVersion 0.2.3 diff --git a/controllers/object.js b/controllers/object.js index 0887cca..215172d 100644 --- a/controllers/object.js +++ b/controllers/object.js @@ -54,7 +54,7 @@ var validateContext = function(appId, context, callback) { Should have the format: Bearer $TOKEN * @apiHeader {String} X-BLGREQ-APPID Custom header which contains the application ID * @apiHeader {String} X-BLGREQ-SIGN Custom header containing the SHA256-ed API key of the application - * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from devie/register) + * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from device/register) * * @apiParam {Object} channel Object representing the channel * @apiParam {Object} filters Object representing channel filters @@ -240,7 +240,7 @@ router.post('/subscribe', function(req, res, next) { Should have the format: Bearer $TOKEN * @apiHeader {String} X-BLGREQ-APPID Custom header which contains the application ID * @apiHeader {String} X-BLGREQ-SIGN Custom header containing the SHA256-ed API key of the application - * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from devie/register) + * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from device/register) * * @apiParam {Object} channel Object representing the channel * @apiParam {Object} filters Object representing the filters for the channel @@ -346,7 +346,7 @@ router.post('/unsubscribe', function(req, res, next) { Should have the format: Bearer $TOKEN * @apiHeader {String} X-BLGREQ-APPID Custom header which contains the application ID * @apiHeader {String} X-BLGREQ-SIGN Custom header containing the SHA256-ed API key of the application - * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from devie/register) + * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from device/register) * * @apiParam {String} model The type of object to subscribe to * @apiParam {Object} content Content of the object @@ -448,7 +448,7 @@ router.post('/create', function(req, res, next) { Should have the format: Bearer $TOKEN * @apiHeader {String} X-BLGREQ-APPID Custom header which contains the application ID * @apiHeader {String} X-BLGREQ-SIGN Custom header containing the SHA256-ed API key of the application - * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from devie/register) + * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from device/register) * * @apiParam {Number} id ID of the object (optional) * @apiParam {Number} context Context of the object @@ -558,7 +558,7 @@ router.post('/update', function(req, res, next) { Should have the format: Bearer $TOKEN * @apiHeader {String} X-BLGREQ-APPID Custom header which contains the application ID * @apiHeader {String} X-BLGREQ-SIGN Custom header containing the SHA256-ed API key of the application - * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from devie/register) + * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from device/register) * * @apiParam {Number} id ID of the object (optional) * @apiParam {Number} context Context of the object @@ -630,9 +630,9 @@ router.post('/delete', function(req, res, next) { Should have the format: Bearer $TOKEN * @apiHeader {String} X-BLGREQ-APPID Custom header which contains the application ID * @apiHeader {String} X-BLGREQ-SIGN Custom header containing the SHA256-ed API key of the application - * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from devie/register) + * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from device/register) * - * @apiParam {Object} channel The object reperesenting a channel + * @apiParam {Object} channel The object representing a channel * @apiParam {Object} filters Additional filters to the subscription channel * */ diff --git a/controllers/user.js b/controllers/user.js index a3c0487..c20226e 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -22,7 +22,7 @@ router.use(['/logout', '/me', '/update', '/update_immediate', '/delete'], securi /** * @api {post} /user/login Login - * @apiDescription Log in the user through facebook User is not created immediately. + * @apiDescription Log in the user through Facebook. * @apiName UserLogin * @apiGroup User * @apiVersion 0.2.3 @@ -30,7 +30,7 @@ router.use(['/logout', '/me', '/update', '/update_immediate', '/delete'], securi * @apiHeader {String} Content-type application/json * @apiHeader {String} X-BLGREQ-APPID Custom header which contains the application ID * @apiHeader {String} X-BLGREQ-SIGN Custom header containing the SHA256-ed API key of the application - * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from devie/register) + * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from device/register) * * @apiParam {String} access_token Facebook access token. * @@ -60,7 +60,7 @@ router.use(['/logout', '/me', '/update', '/update_immediate', '/delete'], securi * } * * @apiError 400 [028]InsufficientFacebookPermissions User email is not publicly available - * (insufficient facebook permissions) + * (insufficient Facebook permissions) * @apiError 404 [023]UserNotFound User not found * */ @@ -151,7 +151,7 @@ router.post('/login', function(req, res, next) { /** * @api {post} /user/register Register - * @apiDescription Registers a new user using a fb token or directly with an email and password. User is not created + * @apiDescription Registers a new user using a Facebook token or directly with an email and password. User is not created * immediately. * @apiName UserRegister * @apiGroup User @@ -160,7 +160,7 @@ router.post('/login', function(req, res, next) { * @apiHeader {String} Content-type application/json * @apiHeader {String} X-BLGREQ-APPID Custom header which contains the application ID * @apiHeader {String} X-BLGREQ-SIGN Custom header containing the SHA256-ed API key of the application - * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from devie/register) + * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from device/register) * * @apiParam {String} access_token Facebook access token. * @@ -312,7 +312,7 @@ router.post('/register', function(req, res, next) { * Should have the format: Bearer $TOKEN * @apiHeader {String} X-BLGREQ-APPID Custom header which contains the application ID * @apiHeader {String} X-BLGREQ-SIGN Custom header containing the SHA256-ed API key of the application - * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from devie/register) + * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from device/register) * * @apiParam {String} password The password * @apiParam {String} email The email @@ -355,7 +355,7 @@ router.get('/me', function(req, res, next) { * @apiHeader {String} Content-type application/json * @apiHeader {String} X-BLGREQ-APPID Custom header which contains the application ID * @apiHeader {String} X-BLGREQ-SIGN Custom header containing the SHA256-ed API key of the application - * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from devie/register) + * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from device/register) * * @apiParam {String} password The password * @apiParam {String} email The email @@ -453,7 +453,7 @@ router.post('/login_password', function(req, res, next) { * @apiHeader {String} Content-type application/json * @apiHeader {String} X-BLGREQ-APPID Custom header which contains the application ID * @apiHeader {String} X-BLGREQ-SIGN Custom header containing the SHA256-ed API key of the application - * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from devie/register) + * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from device/register) * * @apiSuccessExample {json} Success Response * { @@ -497,8 +497,8 @@ router.get('/logout', function(req, res, next) { /** * @api {get} /user/refresh_token Refresh Token - * @apiDescription Sends a new authentification token to the user. The old token must be provide (and it may or not - * may not be aleady expired). + * @apiDescription Sends a new authentication token to the user. The old token must be provide (and it may or not + * may not be already expired). * @apiName RefreshToken * @apiGroup User * @apiVersion 0.2.3 @@ -508,7 +508,7 @@ router.get('/logout', function(req, res, next) { * Should have the format: Bearer $TOKEN * @apiHeader {String} X-BLGREQ-APPID Custom header which contains the application ID * @apiHeader {String} X-BLGREQ-SIGN Custom header containing the SHA256-ed API key of the application - * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from devie/register) + * @apiHeader {String} X-BLGREQ-UDID Custom header containing the device ID (obtained from device/register) * * @apiSuccessExample {json} Success Response * { @@ -521,7 +521,7 @@ router.get('/logout', function(req, res, next) { * * @apiError 400 [013]AuthorizationMissing If authorization header is missing * @apiError 400 [039]ClientBadRequest Error decoding auth token - * @apiError 400 [040]MalformedAuthorizationToken Auth token is malformed + * @apiError 400 [040]MalformedAuthorizationToken Authorization token is malformed * @apiError 400 [014]InvalidAuthorization Authorization header is invalid */ router.get('/refresh_token', function(req, res, next) { diff --git a/test/admin/admin.js b/test/admin/admin.js index e9fd1e0..67ead38 100644 --- a/test/admin/admin.js +++ b/test/admin/admin.js @@ -127,7 +127,23 @@ describe('Admin', function() { }); }); - it('should return an error for logging in with wrong user or password', function(done) { + it('should return an error for logging in with wrong password', function(done) { + + var admin = { + email: adminEmail, + password: adminPassword + '66' + }; + request(url) + .post('/admin/login') + .send(admin) + .end(function(err, res) { + + res.statusCode.should.be.equal(401); + done(); + }); + }); + + it('should return an error for logging in with wrong user', function(done) { var randEmail = 'adminx@example.com'; var admin = { diff --git a/test/object/object.js b/test/object/object.js index dd59fab..021b34f 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -951,7 +951,7 @@ it('should return an error response to indicate that a object has NOT been subsc .set('Authorization', userAuthValue ) .send(subclientrequest) .end(function(err, res) { -console.log(res.body); + res.body.code.should.be.equal('014'); res.statusCode.should.be.equal(401); done(); From 3e345aee5dd34f0d3c311cb19cfa41a7ab410a46 Mon Sep 17 00:00:00 2001 From: Alexandrescu Sergiu Date: Tue, 6 Oct 2015 15:48:15 +0000 Subject: [PATCH 34/42] deleted unused lines from api added object/subscribe test added user test added a test for kr-172 but left it commented --- controllers/admin/context.js | 6 +- controllers/admin/user.js | 6 +- test/admin/admin.js | 107 ++++++++++++++++++++++++++++------- test/object/object.js | 81 +++++++++++++++++++++++++- 4 files changed, 167 insertions(+), 33 deletions(-) diff --git a/controllers/admin/context.js b/controllers/admin/context.js index 64b3e59..8cfb4af 100644 --- a/controllers/admin/context.js +++ b/controllers/admin/context.js @@ -271,11 +271,7 @@ router.post('/update', function (req, res, next) { Models.Context(req.body.id, callback); }, function(context, callback) { - if (app.applications[context.application_id].admins.indexOf(req.user.id) === -1) { - callback(new Models.TelepatError(Models.TelepatError.errors.ContextNotAllowed)); - } else { - Models.Context.update(req.body.id, req.body.patches, callback); - } + Models.Context.update(req.body.id, req.body.patches, callback); } ], function (err, result) { if (err && err.status == 404) diff --git a/controllers/admin/user.js b/controllers/admin/user.js index fc66c25..f0fd5b3 100644 --- a/controllers/admin/user.js +++ b/controllers/admin/user.js @@ -189,11 +189,7 @@ router.post('/delete', function(req, res, next) { Models.User(userEmail, appId, callback); }, function(user, callback) { - if (user.application_id != appId) { - return callback(new Models.TelepatError(Models.TelepatError.errors.UserNotFound)); - } else { - Models.User.delete(userEmail, appId, callback); - } + Models.User.delete(userEmail, appId, callback); } ], function(error, results) { if (error && error.status == 404) diff --git a/test/admin/admin.js b/test/admin/admin.js index 67ead38..336e8e2 100644 --- a/test/admin/admin.js +++ b/test/admin/admin.js @@ -6,6 +6,7 @@ var DELAY = common.DELAY; var authValue; var appID; +var appID2; var appIDsha256 = common.appIDsha256; var appKey = common.appKey; @@ -13,6 +14,8 @@ var adminEmail = 'admin'+Math.round(Math.random()*1000000)+'@example.com'; var adminPassword = '5f4dcc3b5aa765d61d8327deb882cf99'; var adminEmail2 = 'admin'+Math.round(Math.random()*1000000)+'@example.com'; +var adminEmail3 = 'admin'+Math.round(Math.random()*1000000)+'@example.com'; + var admin = { email: adminEmail, password: adminPassword @@ -21,10 +24,18 @@ var admin = { var admin2 = { email: adminEmail2, password: adminPassword -} +}; + +var admin3 = { + email: adminEmail3, + password: adminPassword +}; + + var token2; var authValue2; +var authValue3; var userEmail = 'user'+Math.round(Math.random()*1000000)+'@example.com'; @@ -416,26 +427,55 @@ describe('App', function() { .send(clientrequest) .end(function(err, res) { - appID = res.body.content.id; + appID = res.body.content.id; request(url) - .post('/admin/add') - .send(admin2) - .end(function(err, res) { - - setTimeout(function () { - - request(url) - .post('/admin/login') - .set('Content-type','application/json') - .send(admin2) - .end(function(err, res) { - - token2 = res.body.content.token; - authValue2 = 'Bearer ' + token2; - done(); - }); - }, 3*DELAY); + .post('/admin/app/add') + .set('Content-type', 'application/json') + .set('Authorization', authValue) + .send(clientrequest) + .end(function (err, res) { + + appID2 = res.body.content.id; + + request(url) + .post('/admin/add') + .send(admin2) + .end(function (err, res) { + + setTimeout(function () { + + request(url) + .post('/admin/login') + .set('Content-type', 'application/json') + .send(admin2) + .end(function (err, res) { + + token2 = res.body.content.token; + authValue2 = 'Bearer ' + token2; + + request(url) + .post('/admin/add') + .send(admin3) + .end(function (err, res) { + + setTimeout(function () { + + request(url) + .post('/admin/login') + .set('Content-type', 'application/json') + .send(admin3) + .end(function (err, res) { + + token3 = res.body.content.token; + authValue3 = 'Bearer ' + token3; + done(); + }); + }, 3 * DELAY); + }); + }); + }, 3 * DELAY); + }); }); }); }); @@ -695,7 +735,7 @@ describe('App', function() { }); }); - it('should return an succes to indicate an admin has been authorized to an application', function(done) { + it('should return an success to indicate an admin has been authorized to an application', function(done) { var clientrequest = { "email": adminEmail2 @@ -801,7 +841,7 @@ describe('App', function() { }); }); - it('should return an succes to indicate an admin has been deauthorized to an application', function(done) { + it('should return an success to indicate an admin has been deauthorized to an application', function(done) { var clientrequest = { "email": adminEmail2 @@ -822,6 +862,30 @@ describe('App', function() { }); }); +/* it('should return an error to indicate an admin has NOT been deauthorized to an application, admin not authorized', function(done) { + + var clientrequest = { + "email": adminEmail3 + }; + + request(url) + .post('/admin/app/deauthorize') + .set('Content-type','application/json') + .set('X-BLGREQ-APPID', appID) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') + .set('Authorization', authValue ) + .send(clientrequest) + .end(function(err, res) { + + if(res){ + res.body.code.should.be.equal('012'); + res.statusCode.should.be.equal(401); + } + done(); + }); + });*/ + + it('should return an error response to indicate admin has NOT been deauthorized because of empty request body', function(done) { request(url) @@ -1841,6 +1905,7 @@ describe('User', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('023'); res.statusCode.should.be.equal(404); done(); }); diff --git a/test/object/object.js b/test/object/object.js index 021b34f..567a693 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -67,7 +67,7 @@ var admin = { password: adminPassword }; -var invalidUDID = 'invalid'; +var contextID2; before(function(done){ @@ -209,7 +209,34 @@ before(function(done){ var objectKey = Object.keys(res.body.content)[0]; contextID = res.body.content.id; - done(); + + var clientrequest = { + "name": "test-app2", + "keys": [ common.appKey ] + }; + + request(url) + .post('/admin/app/add') + .set('Content-type','application/json') + .set('Authorization', authValue) + .send(clientrequest) + .end(function(err, res) { + + appID2 = res.body.content.id; + + request(url) + .post('/admin/context/add') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .set('X-BLGREQ-APPID', appID2 ) + .send(clientrequest) + .end(function(err, res) { + + + contextID2 = res.body.content.id; + done(); + }); + }); }); }); }); @@ -933,6 +960,56 @@ it('should return a success response to indicate that a object has been subscrib }); }); +it('should return a success response to indicate that a object has been subscribed with pagination', function(done) { + + var subclientrequest = { + page: 2, + "channel": { + "context": contextID, + "model": "comments" + } + }; + + request(url) + .post('/object/subscribe') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send(subclientrequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(200); + done(); + }); +}); + +it('should return a success response to indicate that a object has NOT been subscribed because context does not belong to application', function(done) { + + var subclientrequest = { + "channel": { + "context": contextID2, + "model": "comments" + } + }; + + request(url) + .post('/object/subscribe') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send(subclientrequest) + .end(function(err, res) { + + res.body.code.should.be.equal('026'); + res.statusCode.should.be.equal(403); + done(); + }); +}); + it('should return an error response to indicate that a object has NOT been subscribed because of invalid authorization', function(done) { var subclientrequest = { From e7dc93294277d39656b2fd668cf4fd66f7471e7c Mon Sep 17 00:00:00 2001 From: Alexandrescu Sergiu Date: Wed, 7 Oct 2015 11:01:16 +0000 Subject: [PATCH 35/42] added admin/users and admin/user/all tests with pagination added ACL tests --- test/admin/admin.js | 47 +++++++++- test/object/object.js | 200 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 240 insertions(+), 7 deletions(-) diff --git a/test/admin/admin.js b/test/admin/admin.js index 336e8e2..fa95928 100644 --- a/test/admin/admin.js +++ b/test/admin/admin.js @@ -2033,7 +2033,28 @@ describe('User', function() { }); }); - it('should return an error response to indicate that an admin list was NOT retrived for a bad app id', function(done) { + it('should return a success response to indicate that an admin list was retrieved with pagination', function(done) { + + var clientRequest = { + page: 2 + }; + + request(url) + .post('/admin/users') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-APPID', appID) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') + .set('Authorization', authValue ) + .send(clientRequest) + .end(function(err, res) { + + res.statusCode.should.be.equal(200); + done(); + }); + }); + + it('should return an error response to indicate that an admin list was NOT retrieved for a bad app id', function(done) { request(url) .post('/admin/users') @@ -2072,6 +2093,30 @@ describe('User', function() { }); }); + it('should return a success response to indicate that an users list was retrieved with pagination', function(done) { + + var clientRequest = { + page: 2 + }; + + request(url) + .post('/admin/user/all') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-APPID', appID) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28') + .set('Authorization', authValue ) + .send(clientRequest) + .end(function(err, res) { + + if(res) { + res.body.content.should.not.be.empty; + res.statusCode.should.be.equal(200); + } + done(); + }); + }); + it('should return an error response to indicate that an users list was NOT retrived for a bad app id', function(done) { request(url) diff --git a/test/object/object.js b/test/object/object.js index 567a693..adb993e 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -180,8 +180,29 @@ before(function(done){ "hasMany": [ "comments" ], - "read_acl": 7, - "write_acl": 7, + "read_acl": 0, + "write_acl": 0, + "meta_read_acl": 0 + }, + "others": { + "namespace": "events", + "type": "events", + "properties": { + "text": { + "type": "string" + }, + "image": { + "type": "string" + }, + "options": { + "type": "object" + } + }, + "hasMany": [ + "comments" + ], + "read_acl": 4, + "write_acl": 4, "meta_read_acl": 4 } } @@ -308,7 +329,7 @@ before(function(done){ }); }); -it('should return an error (400) response to indicate that the client made a bad request', function(done) { +it('should return an error (400) response to indicate that request body is empty', function(done) { this.timeout(10*DELAY); @@ -400,6 +421,56 @@ it('should return a success response to indicate that object has been created', }); }); +it('should return a success response to indicate that object has NOT been created because of ACL', function(done) { + + var clientrequest = { + "model": "others", + "context": contextID, + "content": { + "events_id" :1 + } + }; + + request(url) + .post('/object/create') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', userAuthValue ) + .send(clientrequest) + .end(function(err, res) { + + res.body.code.should.be.equal('015'); + res.statusCode.should.be.equal(403); + done(); + }); +}); + +it('should return a success response to indicate that object has NOT been created because of ACL', function(done) { + + var clientrequest = { + "model": "things", + "context": contextID, + "content": { + "events_id" :1 + } + }; + + request(url) + .post('/object/create') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',appID) + .set('Authorization', authValue ) + .send(clientrequest) + .end(function(err, res) { + + res.body.code.should.be.equal('015'); + res.statusCode.should.be.equal(403); + done(); + }); +}); + it('should return a success response to indicate that object has been created by an admin', function(done) { var clientrequest = { @@ -733,7 +804,7 @@ it('should return a success response to indicate that a object has NOT been upda }); }); -it('should return a success response to indicate that a object has NOT been updated because of missing authorization ', function(done) { +it('should return a success response to indicate that a object has NOT been updated because of missing authorization', function(done) { var clientrequest = { "model": "comments", @@ -1116,7 +1187,7 @@ it('should return an error response to indicate that a object has NOT been subsc }); }); -it('should return an error response to indicate that a object has NOT been subscribed because context does not belong to app', function(done) { +it('should return an error response to indicate that a object has NOT been subscribed because no schema is defined', function(done) { var clientrequest = { "name": "test-app", @@ -1131,6 +1202,7 @@ it('should return an error response to indicate that a object has NOT been subsc .end(function(err, res) { var appID2 = res.body.content.id; + var subclientrequest = { "channel": { "context": contextID, @@ -1148,12 +1220,128 @@ it('should return an error response to indicate that a object has NOT been subsc .send(subclientrequest) .end(function (err, res) { - res.statusCode.should.be.equal(404); + res.body.code.should.be.equal('043'); + res.statusCode.should.be.equal(501); done(); }); }); }); +it('should return an error response to indicate that a object has NOT been subscribed because context does not belong to app', function(done) { + + var clientrequest = { + "name": "test-app", + "keys": [ appKey ] + }; + + request(url) + .post('/admin/app/add') + .set('Content-type','application/json') + .set('Authorization', authValue) + .send(clientrequest) + .end(function(err, res) { + + var appID2 = res.body.content.id; + + var clientrequest = { + "appId": appID, + "schema": { + "comments": { + "namespace": "comments", + "type": "comments", + "properties": { + "text": { + "type": "string" + } + }, + "belongsTo": [ + { + "parentModel": "events", + "relationType": "hasMany" + } + ], + "read_acl": 6, + "write_acl": 6, + "meta_read_acl": 6 + }, + "events": { + "namespace": "events", + "type": "events", + "properties": { + "text": { + "type": "string" + }, + "image": { + "type": "string" + }, + "options": { + "type": "object" + } + }, + "hasMany": [ + "comments" + ], + "read_acl": 7, + "write_acl": 7, + "meta_read_acl": 4 + }, + "things": { + "namespace": "events", + "type": "events", + "properties": { + "text": { + "type": "string" + }, + "image": { + "type": "string" + }, + "options": { + "type": "object" + } + }, + "hasMany": [ + "comments" + ], + "read_acl": 7, + "write_acl": 7, + "meta_read_acl": 4 + } + } + }; + + request(url) + .post('/admin/schema/update') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .set('X-BLGREQ-APPID', appID2 ) + .send(clientrequest) + .end(function(err, res) { + + var subclientrequest = { + "channel": { + "context": contextID, + "model": "comments" + }, + }; + + request(url) + .post('/object/subscribe') + .set('Content-type', 'application/json') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID', appID2) + .set('Authorization', userAuthValue) + .send(subclientrequest) + .end(function (err, res) { + + res.body.code.should.be.equal('026'); + res.statusCode.should.be.equal(403); + done(); + }); + }); + }); +}); + it('should return a success response to indicate that a object has NOT been subscribed', function(done) { From db9dfdd39e1e52fe02bb7050c09b60870c1865b1 Mon Sep 17 00:00:00 2001 From: Razvan Botea Date: Wed, 7 Oct 2015 15:59:00 +0300 Subject: [PATCH 36/42] Applications loaded on boot up are stored in Application from telepat-models * Fixed user.delete to send parent objects to aggregator for deletion * If application has no schema, all object methods will send an 501 error * /user/login_password adds the device in the user object --- app.js | 33 ++++---- controllers/admin/admin.js | 6 +- controllers/admin/app.js | 22 +++--- controllers/admin/context.js | 6 +- controllers/admin/schema.js | 6 +- controllers/admin/user.js | 36 ++++++--- controllers/object.js | 28 ++----- controllers/security.js | 14 ++-- controllers/user.js | 14 ++++ test/object/object.js | 144 ++++++----------------------------- 10 files changed, 118 insertions(+), 191 deletions(-) diff --git a/app.js b/app.js index 1b71037..1ad7874 100644 --- a/app.js +++ b/app.js @@ -94,8 +94,6 @@ if(mainConfiguration.passwordSalt === undefined || mainConfiguration.passwordSal } app.set('password_salt', mainConfiguration.passwordSalt); -app.applications = {}; - app.use(function(req, res, next) { if (dbConnected) return next(); @@ -103,21 +101,18 @@ app.use(function(req, res, next) { next(new Models.TelepatError(Models.TelepatError.errors.ServerNotAvailable)); }); -var loadApplications = function() { - Models.Application.getAll(function(err, results) { +var loadApplications = function(callback) { + Models.Application.loadAllApplications(function(err) { if (err) { console.log('Fatal error: '.red+' in retrieving all aplications', err); process.exit(-1); } - async.each(results, function(item, c){ - app.applications[item.id] = item; - c(); - }); + callback(); }); }; -var linkMiddlewaresAndRoutes = function() { +var linkMiddlewaresAndRoutes = function(callback) { app.use(security.corsValidation); app.use(security.contentTypeValidation); app.use(logger('dev')); @@ -128,9 +123,10 @@ var linkMiddlewaresAndRoutes = function() { app.use('/user', userRoute); app.use('/context', contextRoute); app.use('/device', deviceRoute); + callback(); }; -var linkErrorHandlingMiddlewares = function() { +var linkErrorHandlingMiddlewares = function(callback) { // error handlers // catch 404 and forward to error handler app.use(function(req, res, next) { @@ -154,21 +150,26 @@ var linkErrorHandlingMiddlewares = function() { res.json(responseBody).end(); }); + callback(); }; -var monitorUsrSignals = function() { +var monitorUsrSignals = function(callback) { //signal sent by nodemon when restarting the server process.on('SIGUSR2', function() { app.kafkaClient.close(); }); + callback(); }; var OnServicesConnect = function() { - dbConnected = true; - loadApplications(); - linkMiddlewaresAndRoutes(); - linkErrorHandlingMiddlewares(); - monitorUsrSignals(); + async.series([ + loadApplications, + linkMiddlewaresAndRoutes, + linkErrorHandlingMiddlewares, + monitorUsrSignals + ], function() { + dbConnected = true; + }); }; async.waterfall([ diff --git a/controllers/admin/admin.js b/controllers/admin/admin.js index 4ce6f2e..dd70df8 100644 --- a/controllers/admin/admin.js +++ b/controllers/admin/admin.js @@ -281,9 +281,9 @@ router.use('/apps', security.tokenValidation); */ router.get('/apps', function (req, res, next) { var adminApps = []; - async.each(Object.keys(app.applications), function(applicationId, c){ - if (app.applications[applicationId].admins.indexOf(req.user.id) !== -1) - adminApps.push(app.applications[applicationId]); + async.each(Object.keys(Models.Application.loadedAppModels), function(applicationId, c){ + if (Models.Application.loadedAppModels[applicationId].admins.indexOf(req.user.id) !== -1) + adminApps.push(Models.Application.loadedAppModels[applicationId]); c(); }, function(err) { if (err) return next(err); diff --git a/controllers/admin/app.js b/controllers/admin/app.js index 532ae82..f1e105c 100644 --- a/controllers/admin/app.js +++ b/controllers/admin/app.js @@ -55,7 +55,7 @@ router.post('/add', function (req, res, next) { if (err) next(err); else { - app.applications[res1.id] = res1; + Models.Application.loadedAppModels[res1.id] = res1; res.status(200).json({status: 200, content: res1}); } }); @@ -101,7 +101,7 @@ router.post('/remove', function (req, res, next) { if (err) next(err); else { - delete app.applications[appId]; + delete Models.Application.loadedAppModels[appId]; res.status(200).json({status: 200, content: 'App removed'}).end(); } }); @@ -169,7 +169,7 @@ router.post('/update', function (req, res, next) { if (err) return next(err); else { - app.applications[appId] = result; + Models.Application.loadedAppModels[appId] = result; res.status(200).json({status: 200, content: 'Updated'}).end(); } }); @@ -233,17 +233,17 @@ router.post('/authorize', function(req, res, next) { Models.Admin({email: adminEmail}, callback); }, function(admin, callback) { - if (app.applications[appId].admins.indexOf(admin.id) !== -1) { + if (Models.Application.loadedAppModels[appId].admins.indexOf(admin.id) !== -1) { return callback(new Models.TelepatError(Models.TelepatError.errors.AdminAlreadyAuthorized)); } - var patches = [Models.Delta.formPatch(app.applications[appId], 'append', {admins: admin.id})]; + var patches = [Models.Delta.formPatch(Models.Application.loadedAppModels[appId], 'append', {admins: admin.id})]; Models.Application.update(appId, patches, callback); } ], function(err, application) { if (err) return next(err); - app.applications[appId] = application; + Models.Application.loadedAppModels[appId] = application; res.status(200).json({status: 200, content: 'Admin added to application'}).end(); }); @@ -304,8 +304,8 @@ router.post('/deauthorize', function(req, res, next) { var appId = req._telepat.applicationId; var adminEmail = req.body.email; - if (adminEmail == req.user.email && app.applications[appId].admins.indexOf(req.user.id) == 0 - && app.applications[appId].admins.length == 1) { + if (adminEmail == req.user.email && Models.Application.loadedAppModels[appId].admins.indexOf(req.user.id) == 0 + && Models.Application.loadedAppModels[appId].admins.length == 1) { return next(new Models.TelepatError(Models.TelepatError.errors.AdminDeauthorizeLastAdmin)); } @@ -314,17 +314,17 @@ router.post('/deauthorize', function(req, res, next) { Models.Admin({email: adminEmail}, callback); }, function(admin, callback) { - if (app.applications[appId].admins.indexOf(admin.id) === -1) { + if (Models.Application.loadedAppModels[appId].admins.indexOf(admin.id) === -1) { return callback(Models.TelepatError(Models.TelepatError.errors.AdminNotFoundInApplication, [adminEmail])); } else { - var patches = [Models.Delta.formPatch(app.applications[appId], 'remove', {admins: admin.id})]; + var patches = [Models.Delta.formPatch(Models.Application.loadedAppModels[appId], 'remove', {admins: admin.id})]; Models.Application.update(appId, patches, callback); } } ], function(err, application) { if (err) return next(err); - app.applications[appId] = application; + Models.Application.loadedAppModels[appId] = application; res.status(200).json({status: 200, content: 'Admin removed from application'}).end(); }); diff --git a/controllers/admin/context.js b/controllers/admin/context.js index 8cfb4af..ae16701 100644 --- a/controllers/admin/context.js +++ b/controllers/admin/context.js @@ -271,7 +271,11 @@ router.post('/update', function (req, res, next) { Models.Context(req.body.id, callback); }, function(context, callback) { - Models.Context.update(req.body.id, req.body.patches, callback); + if (Models.Application.loadedAppModels[context.application_id].admins.indexOf(req.user.id) === -1) { + callback(new Models.TelepatError(Models.TelepatError.errors.ContextNotAllowed)); + } else { + Models.Context.update(req.body.id, req.body.patches, callback); + } } ], function (err, result) { if (err && err.status == 404) diff --git a/controllers/admin/schema.js b/controllers/admin/schema.js index 78f28df..4c30579 100644 --- a/controllers/admin/schema.js +++ b/controllers/admin/schema.js @@ -94,7 +94,7 @@ router.post('/update', function(req, res, next) { if (err){ next(err); } else { - app.applications[appId].schema = schema; + Models.Application.loadedAppModels[appId].schema = schema; res.status(200).json({status: 200, content: 'Schema updated'}).end(); } }); @@ -135,7 +135,7 @@ router.post('/remove_model', function(req, res, next) { var appId = req._telepat.applicationId; var modelName = req.body.model_name; - if (!app.applications[appId].schema[modelName]) { + if (!Models.Application.loadedAppModels[appId].schema[modelName]) { return next(new Models.TelepatError(Models.TelepatError.errors.ApplicationSchemaModelNotFound, [appId, modelName])); } @@ -143,7 +143,7 @@ router.post('/remove_model', function(req, res, next) { if (err){ next(err); } else { - delete app.applications[appId].schema[modelName]; + delete Models.Application.loadedAppModels[appId].schema[modelName]; res.status(200).json({status: 200, content: 'Schema updated'}).end(); } }); diff --git a/controllers/admin/user.js b/controllers/admin/user.js index f0fd5b3..50bce6c 100644 --- a/controllers/admin/user.js +++ b/controllers/admin/user.js @@ -183,35 +183,51 @@ router.post('/delete', function(req, res, next) { var appId = req._telepat.applicationId; var userEmail = req.body.email; + var objectsToBeDeleted = null; async.waterfall([ function(callback) { Models.User(userEmail, appId, callback); }, function(user, callback) { - Models.User.delete(userEmail, appId, callback); + if (user.application_id != appId) { + return callback(new Models.TelepatError(Models.TelepatError.errors.UserNotFound)); + } else { + Models.User.delete(userEmail, appId, function(err, results) { + if (err) return callback(err); + objectsToBeDeleted = results; + callback(); + }); + } } - ], function(error, results) { + ], function(error) { if (error && error.status == 404) return next(new Models.TelepatError(Models.TelepatError.errors.UserNotFound)); else if (error) return next(error); - if (results) { - async.each(results, function(item, c) { + if (objectsToBeDeleted) { + var brokerMessages = []; + + async.each(objectsToBeDeleted, function(item, c) { var context = item.context_id; - var mdl = item.value.type; - var id = item.value.id; + var mdl = item.type; + var id = item.id; - app.messagingClient.send([JSON.stringify({ + brokerMessages.push(JSON.stringify({ op: 'delete', object: {path: mdl+'/'+id}, context: context, applicationId: appId - })], 'aggregation', c); + })); + c(); + }, function() { + app.messagingClient.send(brokerMessages, 'aggregation', function(err){ + if (err) return next(err); + + res.status(200).json({status: 200, content: 'User deleted'}).end(); + }); }); } - - res.status(200).json({status: 200, content: 'User deleted'}).end(); }); }); diff --git a/controllers/object.js b/controllers/object.js index 215172d..8b11d47 100644 --- a/controllers/object.js +++ b/controllers/object.js @@ -9,22 +9,6 @@ router.use(security.applicationIdValidation); router.use(security.apiKeyValidation); router.use(security.deviceIdValidation); -/** - * Middleware used to load application model schema - */ -router.use(function(req, res, next) { - //roughly 67M - it self cleares so it doesn't get too big - if (sizeof(Models.Application.loadedAppModels) > (1 << 26)) { - delete Models.Application.loadedAppModels; - Models.Application.loadedAppModels = {}; - } - - if (!Models.Application.loadedAppModels[req._telepat.applicationId]) { - Models.Application.loadAppModels(req._telepat.applicationId, next); - } else - next(); -}); - router.use(['/subscribe', '/unsubscribe'], security.objectACL('read_acl')); router.use(['/create', '/update', '/delete'], security.objectACL('write_acl')); router.use(['/count'], security.objectACL('meta_read_acl')); @@ -381,15 +365,15 @@ router.post('/create', function(req, res, next) { content.context_id = context; content.application_id = appId; - if (Models.Application.loadedAppModels[appId][mdl].belongsTo && - Models.Application.loadedAppModels[appId][mdl].belongsTo.length) { - var parentModel = Models.Application.loadedAppModels[appId][mdl].belongsTo[0].parentModel; + if (Models.Application.loadedAppModels[appId].schema[mdl].belongsTo && + Models.Application.loadedAppModels[appId].schema[mdl].belongsTo.length) { + var parentModel = Models.Application.loadedAppModels[appId].schema[mdl].belongsTo[0].parentModel; if (!content[parentModel+'_id']) { return next(new Models.TelepatError(Models.TelepatError.errors.MissingRequiredField, [parentModel+'_id'])); - } else if (Models.Application.loadedAppModels[appId][mdl].belongsTo[0].relationType == 'hasSome' && - content[Models.Application.loadedAppModels[appId][parentModel].hasSome_property+'_index'] === undefined) { + } else if (Models.Application.loadedAppModels[appId].schema[mdl].belongsTo[0].relationType == 'hasSome' && + content[Models.Application.loadedAppModels[appId].schema[parentModel].hasSome_property+'_index'] === undefined) { return next(new Models.TelepatError(Models.TelepatError.errors.MissingRequiredField, - [Models.Application.loadedAppModels[appId][parentModel].hasSome_property+'_index'])); + [Models.Application.loadedAppModels[appId].schema[parentModel].hasSome_property+'_index'])); } } diff --git a/controllers/security.js b/controllers/security.js index 5d46604..40e85d8 100644 --- a/controllers/security.js +++ b/controllers/security.js @@ -32,7 +32,7 @@ security.apiKeyValidation = function(req, res, next) { else { var clientHash = req.get('X-BLGREQ-SIGN').toLowerCase(); var serverHash = null; - var apiKeys = app.applications[req.get('X-BLGREQ-APPID')].keys; + var apiKeys = Models.Application.loadedAppModels[req.get('X-BLGREQ-APPID')].keys; async.detect(apiKeys, function(item ,cb) { if (item) @@ -64,7 +64,7 @@ security.applicationIdValidation = function(req, res, next) { if (!req.get('X-BLGREQ-APPID')) return next(new Models.TelepatError(Models.TelepatError.errors.ApplicationIdMissing)); else { - if (!app.applications[req.get('X-BLGREQ-APPID')]) { + if (!Models.Application.loadedAppModels[req.get('X-BLGREQ-APPID')]) { return next(new Models.TelepatError(Models.TelepatError.errors.ApplicationNotFound, [req.get('X-BLGREQ-APPID')])); } @@ -108,7 +108,7 @@ security.adminAppValidation = function (req, res, next) { if (!req.user) return next(); - if (app.applications[appId].admins.indexOf(req.user.id) === -1) { + if (Models.Application.loadedAppModels[appId].admins.indexOf(req.user.id) === -1) { return next(new Models.TelepatError(Models.TelepatError.errors.ApplicationForbidden)); } @@ -127,12 +127,16 @@ security.objectACL = function (accessControl) { if (['user', 'context', 'application'].indexOf(mdl) !== -1) return next(); - if (!Models.Application.loadedAppModels[req._telepat.applicationId][mdl]) { + if (!Models.Application.loadedAppModels[req._telepat.applicationId].schema) { + return next(new Models.TelepatError(Models.TelepatError.errors.ApplicationHasNoSchema)); + } + + if (!Models.Application.loadedAppModels[req._telepat.applicationId].schema[mdl]) { return next(new Models.TelepatError(Models.TelepatError.errors.ApplicationSchemaModelNotFound, [req._telepat.applicationId, mdl])); } - var acl = Models.Application.loadedAppModels[req._telepat.applicationId][mdl][accessControl]; + var acl = Models.Application.loadedAppModels[req._telepat.applicationId].schema[mdl][accessControl]; if (acl & ACL_AUTHENTICATED || acl & ACL_ADMIN) { var authHeaderParts = req.headers.authorization.split(' '); diff --git a/controllers/user.js b/controllers/user.js index c20226e..975c881 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -418,6 +418,20 @@ router.post('/login_password', function(req, res, next) { } }); }, + function(callback) { + var patches = []; + patches.push(Models.Delta.formPatch(userProfile, 'append', {devices: deviceId})); + + if (userProfile.devices) { + var idx = userProfile.devices.indexOf(deviceId); + if (idx === -1) { + Models.User.update(userProfile.email, appId, patches, callback); + } else + callback(); + } else { + Models.User.update(userProfile.email, appId, patches, callback); + } + }, function(callback) { security.encryptPassword(req.body.password, function(err, hash) { if (err) diff --git a/test/object/object.js b/test/object/object.js index adb993e..00bc652 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -1187,11 +1187,31 @@ it('should return an error response to indicate that a object has NOT been subsc }); }); -it('should return an error response to indicate that a object has NOT been subscribed because no schema is defined', function(done) { +it('should return an error response to indicate that a object has NOT been subscribed because context does not belong to app', function(done) { var clientrequest = { - "name": "test-app", - "keys": [ appKey ] + name: "test-app", + keys: [ appKey ], + schema: { + "comments": { + "namespace": "comments", + "type": "comments", + "properties": { + "text": { + "type": "string" + } + }, + "belongsTo": [ + { + "parentModel": "events", + "relationType": "hasMany" + } + ], + "read_acl": 6, + "write_acl": 6, + "meta_read_acl": 6 + } + } }; request(url) @@ -1220,128 +1240,12 @@ it('should return an error response to indicate that a object has NOT been subsc .send(subclientrequest) .end(function (err, res) { - res.body.code.should.be.equal('043'); - res.statusCode.should.be.equal(501); + res.statusCode.should.be.equal(403); done(); }); }); }); -it('should return an error response to indicate that a object has NOT been subscribed because context does not belong to app', function(done) { - - var clientrequest = { - "name": "test-app", - "keys": [ appKey ] - }; - - request(url) - .post('/admin/app/add') - .set('Content-type','application/json') - .set('Authorization', authValue) - .send(clientrequest) - .end(function(err, res) { - - var appID2 = res.body.content.id; - - var clientrequest = { - "appId": appID, - "schema": { - "comments": { - "namespace": "comments", - "type": "comments", - "properties": { - "text": { - "type": "string" - } - }, - "belongsTo": [ - { - "parentModel": "events", - "relationType": "hasMany" - } - ], - "read_acl": 6, - "write_acl": 6, - "meta_read_acl": 6 - }, - "events": { - "namespace": "events", - "type": "events", - "properties": { - "text": { - "type": "string" - }, - "image": { - "type": "string" - }, - "options": { - "type": "object" - } - }, - "hasMany": [ - "comments" - ], - "read_acl": 7, - "write_acl": 7, - "meta_read_acl": 4 - }, - "things": { - "namespace": "events", - "type": "events", - "properties": { - "text": { - "type": "string" - }, - "image": { - "type": "string" - }, - "options": { - "type": "object" - } - }, - "hasMany": [ - "comments" - ], - "read_acl": 7, - "write_acl": 7, - "meta_read_acl": 4 - } - } - }; - - request(url) - .post('/admin/schema/update') - .set('Content-type','application/json') - .set('Authorization', authValue ) - .set('X-BLGREQ-APPID', appID2 ) - .send(clientrequest) - .end(function(err, res) { - - var subclientrequest = { - "channel": { - "context": contextID, - "model": "comments" - }, - }; - - request(url) - .post('/object/subscribe') - .set('Content-type', 'application/json') - .set('X-BLGREQ-SIGN', appIDsha256) - .set('X-BLGREQ-UDID', deviceIdentification) - .set('X-BLGREQ-APPID', appID2) - .set('Authorization', userAuthValue) - .send(subclientrequest) - .end(function (err, res) { - - res.body.code.should.be.equal('026'); - res.statusCode.should.be.equal(403); - done(); - }); - }); - }); -}); - it('should return a success response to indicate that a object has NOT been subscribed', function(done) { From 5f80366c4209b05a87ffb6915f3bc6da1fabf2b3 Mon Sep 17 00:00:00 2001 From: Alexandrescu Sergiu Date: Thu, 8 Oct 2015 09:08:16 +0000 Subject: [PATCH 37/42] fixed a small bug related to empty body reqeust added index to tests added code aserts to tests added /user/login test smaller DELAY --- controllers/device.js | 8 +- controllers/user.js | 4 + test/admin/admin.js | 280 +++++++++++++++++++++-------------- test/api.js | 10 +- test/common.js | 2 +- test/context/context.js | 20 +-- test/device/device.js | 152 +++++++++---------- test/object/object.js | 315 +++++++++++++++++++++++++++++----------- test/user/user.js | 129 +++++++++------- 9 files changed, 579 insertions(+), 341 deletions(-) diff --git a/controllers/device.js b/controllers/device.js index 3c77d19..21089f8 100644 --- a/controllers/device.js +++ b/controllers/device.js @@ -70,6 +70,11 @@ router.use(security.deviceIdValidation); */ router.post('/register', function(req, res, next) { if (req._telepat.device_id == 'TP_EMPTY_UDID' || req._telepat.device_id == '') { + + if (Object.getOwnPropertyNames(req.body).length === 0){ + return next(new Models.TelepatError(Models.TelepatError.errors.RequestBodyEmpty)); + } + if (!req.body.info) { return next(new Models.TelepatError(Models.TelepatError.errors.MissingRequiredField, ['info'])); } @@ -106,8 +111,9 @@ router.post('/register', function(req, res, next) { } } else { - if (Object.getOwnPropertyNames(req.body).length === 0) + if (Object.getOwnPropertyNames(req.body).length === 0){ return next(new Models.TelepatError(Models.TelepatError.errors.RequestBodyEmpty)); + } req.body.id = req._telepat.device_id; diff --git a/controllers/user.js b/controllers/user.js index 975c881..87f35c1 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -65,6 +65,10 @@ router.use(['/logout', '/me', '/update', '/update_immediate', '/delete'], securi * */ router.post('/login', function(req, res, next) { + + if (Object.getOwnPropertyNames(req.body).length === 0) + return next(new Models.TelepatError(Models.TelepatError.errors.RequestBodyEmpty)); + if (!req.body.access_token) return next(new Models.TelepatError(Models.TelepatError.errors.MissingRequiredField, ['access_token'])); diff --git a/test/admin/admin.js b/test/admin/admin.js index fa95928..860d235 100644 --- a/test/admin/admin.js +++ b/test/admin/admin.js @@ -31,17 +31,15 @@ var admin3 = { password: adminPassword }; - - var token2; var authValue2; var authValue3; var userEmail = 'user'+Math.round(Math.random()*1000000)+'@example.com'; -describe('Admin', function() { +describe('1.1.Admin', function() { - it('should return a 200 code to indicate success when creating a new admin', function(done) { + it('1.1.1 should return a 200 code to indicate success when creating a new admin', function(done) { this.timeout(12*DELAY); @@ -54,25 +52,27 @@ describe('Admin', function() { throw err; done(err); } + res.statusCode.should.be.equal(200); setTimeout(done, 8*DELAY); }); }); - it('should return a 409 code to indicate failure when admin already exists', function(done) { + it('1.1.2 should return an error (409) response to indicate failure when admin already exists', function(done) { request(url) .post('/admin/add') .send(admin) .end(function(err, res) { + res.body.code.should.be.equal('030'); res.statusCode.should.be.equal(409); done(); }); }); - it('should return a 4xx code to indicate failure when admin email is missing', function(done) { + it('1.1.3 should return an error response indicate failure when admin email is missing', function(done) { var admin = { password: adminPassword @@ -83,12 +83,13 @@ describe('Admin', function() { .send(admin) .end(function(err, res) { - res.statusCode.should.be.within(400,499); + res.body.code.should.be.equal('004'); + res.statusCode.should.be.equal(400); done(); }); }); - it('should return a 4xx code to indicate failure when admin email is empty', function(done) { + it('1.1.4 should return an error response to indicate failure when admin email is empty', function(done) { var admin = { email: "", @@ -100,12 +101,13 @@ describe('Admin', function() { .send(admin) .end(function(err, res) { - res.statusCode.should.be.within(400,499); + res.body.code.should.be.equal('004'); + res.statusCode.should.be.equal(400); done(); }); }); - it('should return a 4xx code to indicate failure when admin password is empty', function(done) { + it('1.1.5 should return an error response to indicate failure when admin password is empty', function(done) { var admin = { email: adminEmail, @@ -117,12 +119,13 @@ describe('Admin', function() { .send(admin) .end(function(err, res) { - res.statusCode.should.be.within(400,499); + res.body.code.should.be.equal('004'); + res.statusCode.should.be.equal(400); done(); }); }); - it('should return a 4xx code to indicate failure when admin password is missing', function(done) { + it('1.1.6 should return an error response to indicate failure when admin password is missing', function(done) { var admin = { email: adminEmail @@ -133,12 +136,13 @@ describe('Admin', function() { .send(admin) .end(function(err, res) { - res.statusCode.should.be.within(400,499); + res.body.code.should.be.equal('004'); + res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error for logging in with wrong password', function(done) { + it('1.1.7 should return an error for logging in with wrong password', function(done) { var admin = { email: adminEmail, @@ -149,12 +153,13 @@ describe('Admin', function() { .send(admin) .end(function(err, res) { + res.body.code.should.be.equal('016'); res.statusCode.should.be.equal(401); done(); }); }); - it('should return an error for logging in with wrong user', function(done) { + it('1.1.8 should return an error for logging in with wrong user', function(done) { var randEmail = 'adminx@example.com'; var admin = { @@ -166,12 +171,13 @@ describe('Admin', function() { .send(admin) .end(function(err, res) { + res.body.code.should.be.equal('016'); res.statusCode.should.be.equal(401); done(); }); }); - it('should return an error for logging in missing password', function(done) { + it('1.1.9 should return an error for logging in missing password', function(done) { var randEmail = 'adminx@example.com'; var admin = { @@ -183,12 +189,13 @@ describe('Admin', function() { .send(admin) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error for logging in missing email & password', function(done) { + it('1.1.10 should return an error for logging in missing email & password', function(done) { var admin = {}; @@ -197,12 +204,13 @@ describe('Admin', function() { .send(admin) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return a valid authorization token', function(done) { + it('1.1.11 should return a valid authorization token', function(done) { request(url) .post('/admin/login') @@ -217,7 +225,7 @@ describe('Admin', function() { }); }); - it('should return information about the logged admin', function(done) { + it('1.1.12 should return information about the logged admin', function(done) { request(url) .get('/admin/me') @@ -233,7 +241,7 @@ describe('Admin', function() { }); }); - it('should return a succes response indicating the admin account has been updated', function(done) { + it('1.1.13 should return an success response indicating the admin account has been updated', function(done) { var requestBody = { patches: [ @@ -257,7 +265,7 @@ describe('Admin', function() { }); }); - it('should return an error response indicating the admin account has NOT been updated because of invalid admin id', function(done) { + it('1.1.14 should return an error response indicating the admin account has NOT been updated because of invalid admin id', function(done) { var admin = { patches: [ @@ -276,12 +284,13 @@ describe('Admin', function() { .send(admin) .end(function(err, res) { + res.body.code.should.be.equal('041'); res.statusCode.should.be.equal(401); done(); }); }); - it('should return an error response indicating the admin account has NOT been updated because of missing authorization header', function(done) { + it('1.1.15 should return an error response indicating the admin account has NOT been updated because of missing authorization header', function(done) { var admin = { patches: [ @@ -299,12 +308,13 @@ describe('Admin', function() { .send(admin) .end(function(err, res) { + res.body.code.should.be.equal('013'); res.statusCode.should.be.equal(401); done(); }); }); - it('should return an error response indicating the admin account has NOT been updated because of missing request body', function(done) { + it('1.1.16 should return an error response indicating the admin account has NOT been updated because of missing request body', function(done) { request(url) .post('/admin/update') @@ -313,13 +323,14 @@ describe('Admin', function() { .send() .end(function(err, res) { + res.body.code.should.be.equal('005'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response indicating the admin account has NOT been updated because patches is not an array', function(done) { + it('1.1.17 should return an error response indicating the admin account has NOT been updated because patches is not an array', function(done) { var admin = { patches: {} @@ -332,12 +343,13 @@ describe('Admin', function() { .send(admin) .end(function(err, res) { + res.body.code.should.be.equal('038'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response indicating the admin account has NOT been updated because patches is empty', function(done) { + it('1.1.18 should return an error response indicating the admin account has NOT been updated because patches is empty', function(done) { var admin = { patches: [] @@ -350,12 +362,13 @@ describe('Admin', function() { .send(admin) .end(function(err, res) { + res.body.code.should.be.equal('038'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response indicating the admin account has NOT been deleted because of missing credentials', function(done) { + it('1.1.19 should return an error response indicating the admin account has NOT been deleted because of missing credentials', function(done) { request(url) .post('/admin/delete') @@ -368,7 +381,7 @@ describe('Admin', function() { }); }); - it('should return a succes response indicating the admin account has been deleted', function(done) { + it('1.1.20 should return an success response indicating the admin account has been deleted', function(done) { this.timeout(20*DELAY); @@ -409,7 +422,7 @@ describe('Admin', function() { }); }); -describe('App', function() { +describe('1.2.App', function() { before(function(done){ @@ -480,11 +493,13 @@ describe('App', function() { }); }); - it('should return a success response to indicate app succesfully created', function(done) { + it('1.2.1 should return a success response to indicate app successfully created', function(done) { + var clientrequest = { "name": "test-app", "keys": [ appKey ] }; + var successResponse = { "1": { "admin_id": adminEmail, @@ -492,7 +507,8 @@ describe('App', function() { "type": "application", "keys": [ appKey ] } - } + }; + request(url) .post('/admin/app/add') .set('Content-type','application/json') @@ -507,7 +523,7 @@ describe('App', function() { }); }); - it('should return an error response to indicate app was not created because of missing app name', function(done) { + it('1.2.2 should return an error response to indicate app was not created because of missing app name', function(done) { var clientrequest = { "keys": ["3406870085495689e34d878f09faf52c"] @@ -520,12 +536,13 @@ describe('App', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return a list of applications for the current admin', function(done) { + it('1.2.3 should return a list of applications for the current admin', function(done) { var clientrequest = { "name": "test-app", @@ -565,7 +582,7 @@ describe('App', function() { }); }); - it('should return a success response for updating an app', function(done) { + it('1.2.4 should return a success response for updating an app', function(done) { var clientrequest = { "name": "test-app", @@ -600,6 +617,7 @@ describe('App', function() { .set('X-BLGREQ-APPID', appID ) .send(clientrequest2) .end(function(err, res) { + res.statusCode.should.be.equal(200); done(); }); @@ -607,7 +625,7 @@ describe('App', function() { }); }); - it('should return an error response for NOT updating an app because patches is not an array', function(done) { + it('1.2.5 should return an error response for NOT updating an app because patches is not an array', function(done) { var clientrequest2 = { patches: {} @@ -621,12 +639,13 @@ describe('App', function() { .send(clientrequest2) .end(function(err, res) { + res.body.code.should.be.equal('038'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response for NOT updating an app because patches is an empty array', function(done) { + it('1.2.6 should return an error response for NOT updating an app because patches is an empty array', function(done) { var clientrequest2 = { patches: [] @@ -640,12 +659,13 @@ describe('App', function() { .send(clientrequest2) .end(function(err, res) { + res.body.code.should.be.equal('038'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response for NOT updating an app because of missing request body', function(done) { + it('1.2.7 should return an error response for NOT updating an app because of missing request body', function(done) { request(url) .post('/admin/app/update') @@ -655,12 +675,13 @@ describe('App', function() { .send() .end(function(err, res) { + res.body.code.should.be.equal('005'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response for NOT updating an app because of missing appID', function(done) { + it('1.2.8 should return an error response for NOT updating an app because of missing appID', function(done) { var clientrequest2 = { patches: [ @@ -680,12 +701,13 @@ describe('App', function() { .send(clientrequest2) .end(function(err, res) { + res.body.code.should.be.equal('011'); res.statusCode.should.be.equal(404); done(); }); }); - it('should return a success response for removing an app', function(done) { + it('1.2.9 should return a success response for removing an app', function(done) { var clientrequest = { "name": "test-app", @@ -720,7 +742,7 @@ describe('App', function() { }); }); - it('should return an error response for trying to remove an app that does NOT exist', function(done) { + it('1.2.10 should return an error response for trying to remove an app that does NOT exist', function(done) { request(url) .post('/admin/app/remove') @@ -730,12 +752,13 @@ describe('App', function() { .send() .end(function(err, res) { + res.body.code.should.be.equal('011'); res.statusCode.should.be.equal(404); done(); }); }); - it('should return an success to indicate an admin has been authorized to an application', function(done) { + it('1.2.11 should return an success to indicate an admin has been authorized to an application', function(done) { var clientrequest = { "email": adminEmail2 @@ -757,7 +780,7 @@ describe('App', function() { }); - it('should return an error response to indicate admin has NOT been authorized because of missing email from body', function(done) { + it('1.2.12 should return an error response to indicate admin has NOT been authorized because of missing email from body', function(done) { var clientrequest = { "something": adminEmail2 @@ -773,12 +796,13 @@ describe('App', function() { .end(function(err, res) { if(res) + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response to indicate admin has NOT been authorized because request body', function(done) { + it('1.2.13 should return an error response to indicate admin has NOT been authorized because request body', function(done) { request(url) .post('/admin/app/authorize') @@ -790,12 +814,13 @@ describe('App', function() { .end(function(err, res) { if(res) + res.body.code.should.be.equal('005'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response to indicate admin with email address already authorized for application', function(done) { + it('1.2.14 should return an error response to indicate admin with email address already authorized for application', function(done) { this.timeout(10*DELAY); @@ -814,13 +839,14 @@ describe('App', function() { .end(function(err, res) { if(res) + res.body.code.should.be.equal('017'); res.statusCode.should.be.equal(409); done(); }); }, 6*DELAY); }); - it('should return an error response to indicate admin has NOT been authenticated because application with that ID doesn\'t exist', function(done) { + it('1.2.15 should return an error response to indicate admin has NOT been authenticated because application with that ID doesn\'t exist', function(done) { var clientrequest = { "email": adminEmail2 @@ -836,12 +862,13 @@ describe('App', function() { .end(function(err, res) { if(res) + res.body.code.should.be.equal('011'); res.statusCode.should.be.equal(404); done(); }); }); - it('should return an success to indicate an admin has been deauthorized to an application', function(done) { + it('1.2.16 should return an success to indicate an admin has been deauthorized to an application', function(done) { var clientrequest = { "email": adminEmail2 @@ -862,7 +889,7 @@ describe('App', function() { }); }); -/* it('should return an error to indicate an admin has NOT been deauthorized to an application, admin not authorized', function(done) { +/* it('1.2.17 should return an error to indicate an admin has NOT been deauthorized to an application, admin not authorized', function(done) { var clientrequest = { "email": adminEmail3 @@ -886,7 +913,7 @@ describe('App', function() { });*/ - it('should return an error response to indicate admin has NOT been deauthorized because of empty request body', function(done) { + it('1.2.18 should return an error response to indicate admin has NOT been deauthorized because of empty request body', function(done) { request(url) .post('/admin/app/deauthorize') @@ -898,13 +925,14 @@ describe('App', function() { .end(function(err, res) { if(res) + res.body.code.should.be.equal('005'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response to indicate admin has NOT been deauthorized because of the email field is missing', function(done) { + it('1.2.19 should return an error response to indicate admin has NOT been deauthorized because of the email field is missing', function(done) { var clientrequest = { "something": adminEmail2 @@ -920,12 +948,13 @@ describe('App', function() { .end(function(err, res) { if(res) + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response to indicate admin has NOT been deauthorized because admin was not found in application', function(done) { + it('1.2.20 should return an error response to indicate admin has NOT been deauthorized because admin was not found in application', function(done) { var clientrequest = { "email": adminEmail2 @@ -941,12 +970,13 @@ describe('App', function() { .end(function(err, res) { if(res) + res.body.code.should.be.equal('012'); res.statusCode.should.be.equal(401); done(); }); }); - it('should return an error response to indicate admin with email address is the last admin of the application', function(done) { + it('1.2.21 should return an error response to indicate admin with email address is the last admin of the application', function(done) { var clientrequest = { "email": adminEmail @@ -962,12 +992,13 @@ describe('App', function() { .end(function(err, res) { if(res) + res.body.code.should.be.equal('018'); res.statusCode.should.be.equal(409); done(); }); }); - it('should return an error response to indicate admin has NOT been deauthenticated because application with that ID doesn\'t exist', function(done) { + it('1.2.22 should return an error response to indicate admin has NOT been deauthenticated because application with that ID doesn\'t exist', function(done) { var clientrequest = { "email": adminEmail2 @@ -983,15 +1014,16 @@ describe('App', function() { .end(function(err, res) { if(res) + res.body.code.should.be.equal('011'); res.statusCode.should.be.equal(404); done(); }); }); }); -describe('Context', function() { +describe('1.3.Context', function() { - it('should return a success response to indicate context successfully created', function(done) { + it('1.3.1 should return a success response to indicate context successfully created', function(done) { var clientrequest = { "name": "context", @@ -1014,7 +1046,7 @@ describe('Context', function() { }); }); - it('should return an error response to indicate context was NOT successfully created because of empty request body', function(done) { + it('1.3.2 should return an error response to indicate context was NOT successfully created because of empty request body', function(done) { request(url) .post('/admin/context/add') @@ -1024,12 +1056,13 @@ describe('Context', function() { .send() .end(function(err, res) { + res.body.code.should.be.equal('005'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return the requested context', function(done) { + it('1.3.3 should return the requested context', function(done) { var clientrequest = { "id": contextID @@ -1048,24 +1081,23 @@ describe('Context', function() { }); }); - it('should NOT return the requested context, requested context ID is missing', function(done) { - - var clientrequest = {}; + it('1.3.4 should NOT return the requested context, requested context ID is missing', function(done) { request(url) .post('/admin/context') .set('Content-type','application/json') .set('Authorization', authValue) .set('X-BLGREQ-APPID', appID) - .send(clientrequest) + .send() .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response to indicate context NOT succesfully created because of bad client headers', function(done) { + it('1.3.5 should return an error response to indicate context NOT successfully created because of bad client headers', function(done) { var clientrequest = { "name": "context", @@ -1079,12 +1111,13 @@ describe('Context', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('010'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response to indicate context NOT successfully created because request body is empty', function(done) { + it('1.3.6 should return an error response to indicate context NOT successfully created because request body is empty', function(done) { request(url) .post('/admin/context/add') @@ -1093,12 +1126,13 @@ describe('Context', function() { .send() .end(function(err, res) { + res.body.code.should.be.equal('010'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return a success response to indicate context was updated', function(done) { + it('1.3.7 should return a success response to indicate context was updated', function(done) { var clientrequest = { "id": contextID, @@ -1124,7 +1158,7 @@ describe('Context', function() { }); }); - it('should return an error response to indicate context was NOT updated because context was not found', function(done) { + it('1.3.8 should return an error response to indicate context was NOT updated because context was not found', function(done) { var clientrequest = { "id": contextID + '66', @@ -1145,12 +1179,13 @@ describe('Context', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('020'); res.statusCode.should.be.equal(404); done(); }); }); - it('should return an error response to indicate context was NOT updated because patches are missing', function(done) { + it('1.3.9 should return an error response to indicate context was NOT updated because patches are missing', function(done) { var clientrequest = { "id": Math.round(Math.random()*1000000)+100, @@ -1165,12 +1200,13 @@ describe('Context', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('038'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response to indicate context was NOT updated because of missing request body', function(done) { + it('1.3.10 should return an error response to indicate context was NOT updated because of missing request body', function(done) { request(url) .post('/admin/context/update') @@ -1180,12 +1216,13 @@ describe('Context', function() { .send() .end(function(err, res) { + res.body.code.should.be.equal('005'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response to indicate context was NOT updated because patches is empty', function(done) { + it('1.3.11 should return an error response to indicate context was NOT updated because patches is empty', function(done) { var clientrequest = { "id": Math.round(Math.random()*1000000)+100, @@ -1200,12 +1237,13 @@ describe('Context', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('038'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response to indicate context was NOT updated because of missing context id', function(done) { + it('1.3.12 should return an error response to indicate context was NOT updated because of missing context id', function(done) { var clientrequest = { "name": "new name", @@ -1226,12 +1264,13 @@ describe('Context', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response to indicate context was NOT updated by another admin', function(done) { + it('1.3.13 should return an error response to indicate context was NOT updated by another admin', function(done) { var clientrequest = { "id": contextID, @@ -1252,12 +1291,13 @@ describe('Context', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('012'); res.statusCode.should.be.equal(401); done(); }); }); - it('should return an error response to indicate context was NOT removed because of invalid context id', function(done) { + it('1.3.14 should return an error response to indicate context was NOT removed because of invalid context id', function(done) { var clientrequest = { "id": 1 @@ -1271,12 +1311,13 @@ describe('Context', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('020'); res.statusCode.should.be.equal(404); done(); }); }); - it('should return an error indicating the requested context does NOT exist', function(done) { + it('1.3.15 should return an error indicating the requested context does NOT exist', function(done) { var clientrequest = { "id": Math.round(Math.random()*1000000)+100 @@ -1290,13 +1331,14 @@ describe('Context', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('020'); res.statusCode.should.be.equal(404); res.body.message.should.be.equal("Context not found"); done(); }); }); - it('should return an error response to indicate context was NOT removed because of missing id from request body', function(done) { + it('1.3.16 should return an error response to indicate context was NOT removed because of missing id from request body', function(done) { request(url) .post('/admin/context/remove') @@ -1306,12 +1348,13 @@ describe('Context', function() { .send() .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return all contexts using the old API', function(done) { + it('1.3.17 should return all contexts using the old API', function(done) { this.timeout(9*DELAY); @@ -1332,7 +1375,7 @@ describe('Context', function() { }, 6*DELAY); }); - it('should return all contexts using the new API', function(done) { + it('1.3.18 should return all contexts using the new API', function(done) { this.timeout(9*DELAY); @@ -1353,7 +1396,7 @@ describe('Context', function() { }, 6*DELAY); }); - it('should NOT return all contexts using the old API because of invalid appID', function(done) { + it('1.3.19 should NOT return all contexts using the old API because of invalid appID', function(done) { this.timeout(9*DELAY); @@ -1374,7 +1417,7 @@ describe('Context', function() { }, 6*DELAY); }); - it('should return a success response to indicate context was removed', function(done) { + it('1.3.20 should return a success response to indicate context was removed', function(done) { var clientrequest = { "id": contextID @@ -1395,9 +1438,9 @@ describe('Context', function() { }); }); -describe('Schema', function() { +describe('1.4.Schema', function() { - it('should return a success response to indicate schema succesfully updated', function(done) { + it('1.4.1 should return a success response to indicate schema successfully updated', function(done) { var clientrequest = { "appId": appID, @@ -1478,7 +1521,7 @@ describe('Schema', function() { }); }); - it('should return an error response to indicate schema was NOT succesfully updated because of appID', function(done) { + it('1.4.2 should return an error response to indicate schema was NOT successfully updated because of appID', function(done) { var clientrequest = { "appId": "1", @@ -1534,12 +1577,13 @@ describe('Schema', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('011'); res.statusCode.should.be.equal(404); done(); }); }); - it('should return an error response to indicate schema was NOT succesfully updated because of missing schema object', function(done) { + it('1.4.3 should return an error response to indicate schema was NOT successfully updated because of missing schema object', function(done) { var clientrequest = { "appId": "1" @@ -1553,12 +1597,13 @@ describe('Schema', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return a success response to indicate schema was retrived succesfully using the old API', function(done) { + it('1.4.4 should return a success response to indicate schema was retrieved successfully using the old API', function(done) { request(url) .get('/admin/schemas') @@ -1573,7 +1618,7 @@ describe('Schema', function() { }); }); - it('should return a success response to indicate schema was retrived succesfully using the new API', function(done) { + it('1.4.5 should return a success response to indicate schema was retrievedsuccessfullyy using the new API', function(done) { request(url) .get('/admin/schema/all') @@ -1588,7 +1633,7 @@ describe('Schema', function() { }); }); - it('should return a success response to indicate a model was removed from the application', function(done) { + it('1.4.6 should return a success response to indicate a model was removed from the application', function(done) { this.timeout(6*DELAY); var clientrequest = { @@ -1603,13 +1648,12 @@ describe('Schema', function() { .send(clientrequest) .end(function(err, res) { - //console.log(res.body); res.statusCode.should.be.equal(200); done(); }); }); - it('should return a error response to indicate a model was NOT removed from the application because of wrong appID', function(done) { + it('1.4.7 should return a error response to indicate a model was NOT removed from the application because of wrong appID', function(done) { var clientrequest = { "model_name": "things" @@ -1623,12 +1667,13 @@ describe('Schema', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('011'); res.statusCode.should.be.equal(404); done(); }); }); - it('should return a error response to indicate a model was NOT removed from the application because model name does NOT exist', function(done) { + it('1.4.8 should return a error response to indicate a model was NOT removed from the application because model name does NOT exist', function(done) { var clientrequest = { "model_name": "others" @@ -1642,12 +1687,13 @@ describe('Schema', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('022'); res.statusCode.should.be.equal(404); done(); }); }); - it('should return a error response to indicate a model was NOT removed from the application because model was missing from the request', function(done) { + it('1.4.9 should return a error response to indicate a model was NOT removed from the application because model was missing from the request', function(done) { var clientrequest = { "something": "others" @@ -1661,12 +1707,13 @@ describe('Schema', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return a error response to indicate a model was NOT removed from the application because of bad route', function(done) { + it('1.4.10 should return a error response to indicate a model was NOT removed from the application because of bad route', function(done) { var clientrequest = { "something": "others" @@ -1680,13 +1727,14 @@ describe('Schema', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('003'); res.statusCode.should.be.equal(404); done(); }); }); }); -describe('User', function() { +describe('1.5.User', function() { var clientrequest = { "email": userEmail, @@ -1707,12 +1755,11 @@ describe('User', function() { .send(clientrequest) .end(function(err, res) { - //console.log(res.body); setTimeout(done, 7*DELAY); }); }); - it('should return a success response to indicate that an user name was updated', function(done) { + it('1.5.1 should return a success response to indicate that an user name was updated', function(done) { this.timeout(12*DELAY); var clientrequest = { @@ -1735,14 +1782,13 @@ describe('User', function() { .set('Authorization', authValue) .send(clientrequest) .end(function(err, res) { - //console.log(clientrequest); - //console.log(res.body); + res.statusCode.should.be.equal(200); setTimeout(done, 8*DELAY); }); }); - it('should return a success response to indicate that an user password was updated', function(done) { + it('1.5.2 should return a success response to indicate that an user password was updated', function(done) { this.timeout(12*DELAY); var clientrequest = { @@ -1766,13 +1812,12 @@ describe('User', function() { .send(clientrequest) .end(function(err, res) { - //console.log(res.body); res.statusCode.should.be.equal(200); setTimeout(done, 8*DELAY); }); }); - it('should return an error response to indicate that an user was NOT updated, user was missing from the request', function(done) { + it('1.5.3 should return an error response to indicate that an user was NOT updated, user was missing from the request', function(done) { request(url) .post('/admin/user/update') @@ -1784,12 +1829,13 @@ describe('User', function() { .send() .end(function(err, res) { + res.body.code.should.be.equal('005'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response to indicate that an user was NOT updated, user email address was missing from the request', function(done) { + it('1.5.4 should return an error response to indicate that an user was NOT updated, user email address was missing from the request', function(done) { var clientrequest = { "user": { @@ -1807,12 +1853,13 @@ describe('User', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('038'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response to indicate that an user was NOT updated because patches is empty', function(done) { + it('1.5.5 should return an error response to indicate that an user was NOT updated because patches is empty', function(done) { var clientrequest = { "email" : userEmail, @@ -1829,12 +1876,13 @@ describe('User', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('038'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return a success response indicating that a user has been deleted', function(done) { + it('1.5.6 should return a success response indicating that a user has been deleted', function(done) { this.timeout(40*DELAY); @@ -1866,7 +1914,7 @@ describe('User', function() { }); }); - it('should return a success response indicating that a user has NOT been deleted, user does not belong to application', function(done) { + it('1.5.7 should return a success response indicating that a user has NOT been deleted, user does not belong to application', function(done) { this.timeout(24*DELAY); @@ -1913,7 +1961,7 @@ describe('User', function() { }); }); - it('should return a error response indicating that a user has NOT been deleted because of missing email address', function(done) { + it('1.5.8 should return a error response indicating that a user has NOT been deleted because of missing email address', function(done) { var clientrequest = { "password": "secure_password1337", @@ -1930,12 +1978,13 @@ describe('User', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return an error response indicating that a user has NOT been deleted because of appID not found', function(done) { + it('1.5.9 should return an error response indicating that a user has NOT been deleted because of appID not found', function(done) { this.timeout(40*DELAY); @@ -1956,12 +2005,13 @@ describe('User', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('011'); res.statusCode.should.be.equal(404); done(); }); }); - it('should return an error response to indicate that an user was NOT found when trying to update', function(done) { + it('1.5.10 should return an error response to indicate that an user was NOT found when trying to update', function(done) { var clientrequest = { "email" : "wrong@example.com", @@ -1984,12 +2034,13 @@ describe('User', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('023'); res.statusCode.should.be.equal(404); done(); }); }); - it('should return an error response to indicate that the user email is missing', function(done) { + it('1.5.11 should return an error response to indicate that the user email is missing', function(done) { var clientrequest = { "patches": [ @@ -2011,12 +2062,13 @@ describe('User', function() { .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); - it('should return a success response to indicate that an admin list was retrived', function(done) { + it('1.5.12 should return a success response to indicate that an admin list was retrieved', function(done) { request(url) .post('/admin/users') @@ -2033,7 +2085,7 @@ describe('User', function() { }); }); - it('should return a success response to indicate that an admin list was retrieved with pagination', function(done) { + it('1.5.13 should return a success response to indicate that an admin list was retrieved with pagination', function(done) { var clientRequest = { page: 2 @@ -2054,7 +2106,7 @@ describe('User', function() { }); }); - it('should return an error response to indicate that an admin list was NOT retrieved for a bad app id', function(done) { + it('1.5.14 should return an error response to indicate that an admin list was NOT retrieved for a bad app id', function(done) { request(url) .post('/admin/users') @@ -2066,13 +2118,16 @@ describe('User', function() { .send() .end(function(err, res) { - if(res) + if(res) { + res.body.code.should.be.equal('011'); res.statusCode.should.be.equal(404); + } + done(); }); }); - it('should return a success response to indicate that an users list was retrived', function(done) { + it('1.5.15 should return a success response to indicate that an users list was retrieved', function(done) { request(url) .post('/admin/user/all') @@ -2085,7 +2140,6 @@ describe('User', function() { .end(function(err, res) { if(res) { - //console.log(res.body); res.body.content.should.not.be.empty; res.statusCode.should.be.equal(200); } @@ -2093,7 +2147,7 @@ describe('User', function() { }); }); - it('should return a success response to indicate that an users list was retrieved with pagination', function(done) { + it('1.5.16 should return a success response to indicate that an users list was retrieved with pagination', function(done) { var clientRequest = { page: 2 @@ -2117,7 +2171,7 @@ describe('User', function() { }); }); - it('should return an error response to indicate that an users list was NOT retrived for a bad app id', function(done) { + it('1.5.17 should return an error response to indicate that an users list was NOT retrieved for a bad app id', function(done) { request(url) .post('/admin/user/all') @@ -2129,8 +2183,10 @@ describe('User', function() { .send() .end(function(err, res) { - if(res) + if(res) { + res.body.code.should.be.equal('011'); res.statusCode.should.be.equal(404); + } done(); }); }); diff --git a/test/api.js b/test/api.js index ffce1d4..1c34d19 100644 --- a/test/api.js +++ b/test/api.js @@ -36,9 +36,9 @@ describe('API', function () { done(); }); - importTest("Admin", './admin/admin'); - importTest("Context", './context/context'); - importTest("Device", './device/device'); - importTest("Object", './object/object'); - importTest("User", './user/user'); + importTest("1.Admin", './admin/admin'); + importTest("2.Context", './context/context'); + importTest("3.Device", './device/device'); + importTest("4.Object", './object/object'); + importTest("5.User", './user/user'); }); diff --git a/test/common.js b/test/common.js index b011608..3d89fb6 100644 --- a/test/common.js +++ b/test/common.js @@ -8,7 +8,7 @@ var logLevel = process.env.TP_TST_LOG || 1; exports.url = 'http://localhost:3000'; exports.appKey = appKey; exports.appIDsha256 = crypto.SHA256(appKey).toString(crypto.enc.Hex); -exports.DELAY = 400; +exports.DELAY = 100; exports.logLevel = logLevel; function highjackEnd(request) { diff --git a/test/context/context.js b/test/context/context.js index dab9449..6752ad9 100644 --- a/test/context/context.js +++ b/test/context/context.js @@ -1,8 +1,6 @@ var common = require('../common'); var request = common.request; var should = common.should; -var assert = common.assert; -var crypto = common.crypto; var url = common.url; var DELAY = common.DELAY; @@ -28,7 +26,7 @@ var admin = { before(function(done){ - this.timeout(10000); + this.timeout(25*DELAY); var clientrequest = { "name": "test-app", @@ -87,7 +85,7 @@ before(function(done){ }); }); -it('should return a success response to indicate context succesfully retrived', function(done) { +it('2.1 should return a success response to indicate context successfully retrieved', function(done) { var clientrequest = { "id": contextID @@ -108,7 +106,7 @@ it('should return a success response to indicate context succesfully retrived', }); }); -it('should return an error response to indicate context wa NOT successfully retrieved because of missing context ID', function(done) { +it('2.2 should return an error response to indicate context was NOT successfully retrieved because of missing context ID', function(done) { request(url) .post('/context') @@ -120,12 +118,13 @@ it('should return an error response to indicate context wa NOT successfully retr .send() .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an error response to indicate context NOT successfully retrieved because of bad context ID', function(done) { +it('2.3 should return an error response to indicate context NOT successfully retrieved because of bad context ID', function(done) { var clientrequest = { id: Math.round(Math.random()*1000000)+1000 @@ -140,12 +139,13 @@ it('should return an error response to indicate context NOT successfully retriev .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('020'); res.statusCode.should.be.equal(404); done(); }); }); -it('should return an error response to indicate context NOT successfully retrieved because of missing authorization', function(done) { +it('2.4 should return an error response to indicate context NOT successfully retrieved because of missing authorization', function(done) { var clientrequest = { id: contextID @@ -159,12 +159,13 @@ it('should return an error response to indicate context NOT successfully retriev .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('013'); res.statusCode.should.be.equal(401); done(); }); }); -it('should return an error response to indicate context NOT successfully retrieved because of bad authorization', function(done) { +it('2.5 should return an error response to indicate context NOT successfully retrieved because of bad authorization', function(done) { var clientrequest = { id: contextID @@ -179,12 +180,13 @@ it('should return an error response to indicate context NOT successfully retriev .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('040'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a success response to indicate all contexts successfully retrieved', function(done) { +it('2.6 should return a success response to indicate all contexts successfully retrieved', function(done) { request(url) .get('/context/all') diff --git a/test/device/device.js b/test/device/device.js index 4a9bd75..d36806a 100644 --- a/test/device/device.js +++ b/test/device/device.js @@ -1,8 +1,6 @@ var common = require('../common'); var request = common.request; var should = common.should; -var assert = common.assert; -var crypto = common.crypto; var url = common.url; var DELAY = common.DELAY; @@ -26,8 +24,8 @@ before(function(done){ this.timeout(25*DELAY); var clientrequest = { - "name": "test-app", - "keys": [ common.appKey ] + name: "test-app", + keys: [ common.appKey ] }; request(url) @@ -61,20 +59,20 @@ before(function(done){ }); }); -it('should return a success response to indicate device succesfully registered', function(done) { +it('3.1 should return a success response to indicate device successfully registered', function(done) { - var clientrequest = { - "info": { - "os": "Android", - "version": "4.4.3", - "sdk_level": 19, - "manufacturer": "HTC", - "model": "HTC One_M8", - "udid": invalidUDID + var clientRequest = { + info: { + os: "Android", + version: "4.4.3", + sdk_level: 19, + manufacturer: "HTC", + model: "HTC One_M8", + udid: invalidUDID }, - "persistent": { - "type": "android", - "token": "android pn token" + persistent: { + type: "android", + token: "android pn token" } }; @@ -83,7 +81,7 @@ it('should return a success response to indicate device succesfully registered', .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', '') .set('X-BLGREQ-APPID', appID) - .send(clientrequest) + .send(clientRequest) .end(function(err, res) { res.statusCode.should.be.equal(200); @@ -92,20 +90,20 @@ it('should return a success response to indicate device succesfully registered', }); }); -it('should return a success response to indicate device succesfully registered with random udid', function(done) { +it('3.2 should return a success response to indicate device successfully registered with random UDID', function(done) { - var clientrequest = { - "info": { - "os": "Android", - "version": "4.4.3", - "sdk_level": 19, - "manufacturer": "HTC", - "model": "HTC One_M8", - "udid": Math.round(Math.random()*1000000)+1000 + var clientRequest = { + info: { + os: "Android", + version: "4.4.3", + sdk_level: 19, + manufacturer: "HTC", + model: "HTC One_M8", + udid: Math.round(Math.random()*1000000)+1000 }, - "persistent": { - "type": "android", - "token": "android pn token" + persistent: { + type: "android", + token: "android pn token" } }; @@ -114,7 +112,7 @@ it('should return a success response to indicate device succesfully registered w .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', '') .set('X-BLGREQ-APPID',1) - .send(clientrequest) + .send(clientRequest) .end(function(err, res) { res.statusCode.should.be.equal(200); @@ -123,19 +121,19 @@ it('should return a success response to indicate device succesfully registered w }); }); -it('should return a success response to indicate device succesfully updated', function(done) { +it('3.3 should return a success response to indicate device successfully updated', function(done) { - var clientrequest = { - "info": { - "os": "Android", - "version": "4.4.3", - "sdk_level": 19, - "manufacturer": "HTC", - "model": "HTC One_M8", + var clientRequest = { + info: { + os: "Android", + version: "4.4.3", + sdk_level: 19, + manufacturer: "HTC", + model: "HTC One_M8", }, - "persistent": { - "type": "android", - "token": "android pn token" + persistent: { + type: "android", + token: "android pn token" } }; @@ -144,7 +142,7 @@ it('should return a success response to indicate device succesfully updated', fu .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', deviceIdentifier) .set('X-BLGREQ-APPID',1) - .send(clientrequest) + .send(clientRequest) .end(function(err, res) { res.statusCode.should.be.equal(200); @@ -152,20 +150,19 @@ it('should return a success response to indicate device succesfully updated', fu }); }); -it('should return an error response to indicate device succesfully registered, uuid missing from request', function(done) { - - var clientrequest = { - "info": { - "os": "Android", - "version": "4.4.3", - "sdk_level": 19, - "manufacturer": "HTC", - "model": "HTC One_M8", +it('3.4 should return an error response to indicate device successfully registered, uuid missing from request', function(done) { + var clientRequest = { + info: { + os: "Android", + version: "4.4.3", + sdk_level: 19, + manufacturer: "HTC", + model: "HTC One_M8", }, - "persistent": { - "type": "android", - "token": "android pn token" + persistent: { + type: "android", + token: "android pn token" } }; @@ -174,7 +171,7 @@ it('should return an error response to indicate device succesfully registered, u .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', '') .set('X-BLGREQ-APPID',1) - .send(clientrequest) + .send(clientRequest) .end(function(err, res) { res.statusCode.should.be.equal(200); @@ -182,12 +179,12 @@ it('should return an error response to indicate device succesfully registered, u }); }); -it('should return an error response to indicate device NOT succesfully registered because of missing info', function(done) { +it('3.5 should return an error response to indicate device NOT successfully registered because of missing info', function(done) { - var clientrequest = { - "persistent": { - "type": "android", - "token": "android pn token" + var clientRequest = { + persistent: { + type: "android", + token: "android pn token" } }; @@ -196,15 +193,16 @@ it('should return an error response to indicate device NOT succesfully registere .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', '') .set('X-BLGREQ-APPID',1) - .send(clientrequest) + .send(clientRequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an error response to indicate device NOT succesfully registered because of missing body', function(done) { +it('3.6 should return an error response to indicate device NOT successfully registered because of missing body', function(done) { request(url) .post('/device/register') @@ -214,12 +212,13 @@ it('should return an error response to indicate device NOT succesfully registere .send() .end(function(err, res) { + res.body.code.should.be.equal('005'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an error response to indicate device NOT succesfully registered because of missing body and invalidUDID', function(done) { +it('3.7 should return an error response to indicate device NOT successfully registered because of missing body and invalidUDID', function(done) { request(url) .post('/device/register') @@ -229,25 +228,25 @@ it('should return an error response to indicate device NOT succesfully registere .send() .end(function(err, res) { + res.body.code.should.be.equal('005'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an error response to indicate device NOT succesfully registered because of invalid UDID', function(done) { - - var clientrequest = { - "info": { - "os": "Android", - "version": "4.4.3", - "sdk_level": 19, - "manufacturer": "HTC", - "model": "HTC One_M8", +it('3.8 should return an error response to indicate device NOT successfully registered because of invalid UDID', function(done) { + var clientRequest = { + info: { + os: "Android", + version: "4.4.3", + sdk_level: 19, + manufacturer: "HTC", + model: "HTC One_M8", }, - "persistent": { - "type": "android", - "token": "android pn token" + persistent: { + type: "android", + token: "android pn token" } }; @@ -256,9 +255,10 @@ it('should return an error response to indicate device NOT succesfully registere .set('X-BLGREQ-SIGN', appIDsha256) .set('X-BLGREQ-UDID', invalidUDID) .set('X-BLGREQ-APPID',appID) - .send(clientrequest) + .send(clientRequest) .end(function(err, res) { + res.body.code.should.be.equal('025'); res.statusCode.should.be.equal(404); done(); }); diff --git a/test/object/object.js b/test/object/object.js index 00bc652..b2da0b4 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -73,9 +73,9 @@ before(function(done){ this.timeout(25*DELAY); - var clientrequest = { - "name": "test-app", - "keys": [ common.appKey ] + var clientRequest = { + name: "test-app", + keys: [ common.appKey ] }; request(url) @@ -98,7 +98,7 @@ before(function(done){ .post('/admin/app/add') .set('Content-type','application/json') .set('Authorization', authValue) - .send(clientrequest) + .send(clientRequest) .end(function(err, res) { appID = res.body.content.id; @@ -232,8 +232,8 @@ before(function(done){ contextID = res.body.content.id; var clientrequest = { - "name": "test-app2", - "keys": [ common.appKey ] + name: "test-app2", + keys: [ common.appKey ] }; request(url) @@ -271,8 +271,8 @@ before(function(done){ this.timeout(25*DELAY); var clientrequest = { - "info": { - "os": "Android", + info: { + os: "Android", "version": "4.4.3", "sdk_level": 19, "manufacturer": "HTC", @@ -329,7 +329,7 @@ before(function(done){ }); }); -it('should return an error (400) response to indicate that request body is empty', function(done) { +it('4.1 should return an error (400) response to indicate that request body is empty', function(done) { this.timeout(10*DELAY); @@ -342,12 +342,13 @@ it('should return an error (400) response to indicate that request body is empty .send() .end(function(err, res) { + res.body.code.should.be.equal('005'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an error (401) response to indicate that only authenticated users may access this endpoint', function(done) { +it('4.2 should return an error (401) response to indicate that only authenticated users may access this endpoint', function(done) { var clientrequest = { "model": "something", @@ -364,12 +365,13 @@ it('should return an error (401) response to indicate that only authenticated us .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('013'); res.statusCode.should.be.equal(401); done(); }); }); -it('should return a error response to indicate that a object has NOT been created', function(done) { +it('4.3 should return a error response to indicate that a object has NOT been created', function(done) { var subclientrequest = { "context": contextID, @@ -396,7 +398,7 @@ it('should return a error response to indicate that a object has NOT been create }); }); -it('should return a success response to indicate that object has been created', function(done) { +it('4.4 should return a success response to indicate that object has been created', function(done) { var clientrequest = { "model": "comments", @@ -421,7 +423,7 @@ it('should return a success response to indicate that object has been created', }); }); -it('should return a success response to indicate that object has NOT been created because of ACL', function(done) { +it('4.5 should return a success response to indicate that object has NOT been created because of ACL', function(done) { var clientrequest = { "model": "others", @@ -446,7 +448,7 @@ it('should return a success response to indicate that object has NOT been create }); }); -it('should return a success response to indicate that object has NOT been created because of ACL', function(done) { +it('4.6 should return a success response to indicate that object has NOT been created because of ACL', function(done) { var clientrequest = { "model": "things", @@ -471,7 +473,7 @@ it('should return a success response to indicate that object has NOT been create }); }); -it('should return a success response to indicate that object has been created by an admin', function(done) { +it('4.7 should return a success response to indicate that object has been created by an admin', function(done) { var clientrequest = { "model": "comments", @@ -496,7 +498,7 @@ it('should return a success response to indicate that object has been created by }); }); -it('should return an error response to indicate that object has NOT been created because of missing authentication', function(done) { +it('4.8 should return an error response to indicate that object has NOT been created because of missing authentication', function(done) { var clientrequest = { "model": "comments", @@ -514,12 +516,13 @@ it('should return an error response to indicate that object has NOT been created .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('013'); res.statusCode.should.be.equal(401); done(); }); }); -it('should return an error response to indicate that object has NOT been created because of missing model in request body', function(done) { +it('4.9 should return an error response to indicate that object has NOT been created because of missing model in request body', function(done) { var clientrequest = { "context": contextID, @@ -537,12 +540,13 @@ it('should return an error response to indicate that object has NOT been created .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an error response to indicate that object has NOT been created because content is missing', function(done) { +it('4.10 should return an error response to indicate that object has NOT been created because content is missing', function(done) { var clientrequest = { "context": contextID, @@ -558,12 +562,13 @@ it('should return an error response to indicate that object has NOT been created .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('002'); res.statusCode.should.be.equal(500); done(); }); }); -it('should return an error response to indicate that object has NOT been created because content is empty', function(done) { +it('4.11 should return an error response to indicate that object has NOT been created because content is empty', function(done) { var clientrequest = { "context": contextID, @@ -580,12 +585,13 @@ it('should return an error response to indicate that object has NOT been created .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an error response to indicate that object has NOT been created because of invalid parent', function(done) { +it('4.12 should return an error response to indicate that object has NOT been created because of invalid parent', function(done) { var clientrequest = { "context": contextID, @@ -604,12 +610,13 @@ it('should return an error response to indicate that object has NOT been created .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an error response to indicate that object has NOT been created because of model does not exist', function(done) { +it('4.13 should return an error response to indicate that object has NOT been created because of model does not exist', function(done) { var clientrequest = { "context": contextID, @@ -628,12 +635,13 @@ it('should return an error response to indicate that object has NOT been created .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('022'); res.statusCode.should.be.equal(404); done(); }); }); -it('should return an error response to indicate that object has NOT been created because of missing context', function(done) { +it('4.14 should return an error response to indicate that object has NOT been created because of missing context', function(done) { var clientrequest = { "model": "comments", @@ -651,12 +659,13 @@ it('should return an error response to indicate that object has NOT been created .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an error response to indicate that object has NOT been created because of invalid appID', function(done) { +it('4.15 should return an error response to indicate that object has NOT been created because of invalid appID', function(done) { var clientrequest = { "model": "comments", @@ -674,12 +683,13 @@ it('should return an error response to indicate that object has NOT been created .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('011'); res.statusCode.should.be.equal(404); done(); }); }); -it('should return a success response to indicate the count of a certain filter/subscription', function(done) { +it('4.16 should return a success response to indicate the count of a certain filter/subscription', function(done) { var clientrequest = { "channel": { @@ -702,7 +712,7 @@ it('should return a success response to indicate the count of a certain filter/s }); }); -it('should return an error response because of invalid channel request', function(done) { +it('4.17 should return an error response because of invalid channel request', function(done) { var clientrequest = { "channel": { @@ -723,12 +733,13 @@ it('should return an error response because of invalid channel request', functio .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('027'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an error response to indicate the count was not returned because of empty request', function(done) { +it('4.18 should return an error response to indicate the count was not returned because of empty request', function(done) { request(url) .post('/object/count') @@ -739,6 +750,7 @@ it('should return an error response to indicate the count was not returned becau .send() .end(function(err, res) { + res.body.code.should.be.equal('005'); res.statusCode.should.be.equal(400); done(); }); @@ -746,7 +758,7 @@ it('should return an error response to indicate the count was not returned becau -it('should return a success response to indicate that a object has been updated', function(done) { +it('4.19 should return a success response to indicate that a object has been updated', function(done) { var clientrequest = { "model": "comments", @@ -775,7 +787,7 @@ it('should return a success response to indicate that a object has been updated' }); }); -it('should return a success response to indicate that a object has NOT been updated because of bad authentication', function(done) { +it('4.20 should return a success response to indicate that a object has NOT been updated because of bad authentication', function(done) { var clientrequest = { "model": "comments", @@ -799,12 +811,13 @@ it('should return a success response to indicate that a object has NOT been upda .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('040'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a success response to indicate that a object has NOT been updated because of missing authorization', function(done) { +it('4.21 should return a success response to indicate that a object has NOT been updated because of missing authorization', function(done) { var clientrequest = { "model": "comments", @@ -827,12 +840,13 @@ it('should return a success response to indicate that a object has NOT been upda .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('013'); res.statusCode.should.be.equal(401); done(); }); }); -it('should return an error response to indicate that a object has NOT been updated because of missing id', function(done) { +it('4.22 should return an error response to indicate that a object has NOT been updated because of missing id', function(done) { var clientrequest = { "model": "comments", @@ -855,12 +869,13 @@ it('should return an error response to indicate that a object has NOT been updat .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a success response to indicate that a object has NOT been updated because of missing context ', function(done) { +it('4.23 should return a success response to indicate that a object has NOT been updated because of missing context ', function(done) { var clientrequest = { "model": "comments", @@ -883,12 +898,13 @@ it('should return a success response to indicate that a object has NOT been upda .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an error response to indicate that a object has NOT been updated because of model not found ', function(done) { +it('4.24 should return an error response to indicate that a object has NOT been updated because of model not found ', function(done) { var clientrequest = { "model": "thingy", @@ -911,12 +927,13 @@ it('should return an error response to indicate that a object has NOT been updat .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('022'); res.statusCode.should.be.equal(404); done(); }); }); -it('should return a success response to indicate that a object has NOT been updated because of missing model ', function(done) { +it('4.25 should return a success response to indicate that a object has NOT been updated because of missing model ', function(done) { var clientrequest = { "context": contextID, @@ -939,12 +956,13 @@ it('should return a success response to indicate that a object has NOT been upda .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a success response to indicate that a object has NOT been updated because patches is not an array ', function(done) { +it('4.26 should return a success response to indicate that a object has NOT been updated because patches is not an array ', function(done) { var clientrequest = { "context": contextID, @@ -962,12 +980,13 @@ it('should return a success response to indicate that a object has NOT been upda .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('038'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a success response to indicate that a object has NOT been updated because patches is an empty array', function(done) { +it('4.27 should return a success response to indicate that a object has NOT been updated because patches is an empty array', function(done) { var clientrequest = { "context": contextID, @@ -985,12 +1004,13 @@ it('should return a success response to indicate that a object has NOT been upda .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('038'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a success response to indicate that a object has NOT been updated because of empty request ', function(done) { +it('4.28 should return a success response to indicate that a object has NOT been updated because of empty request ', function(done) { request(url) .post('/object/update') @@ -1001,13 +1021,14 @@ it('should return a success response to indicate that a object has NOT been upda .send() .end(function(err, res) { + res.body.code.should.be.equal('005'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a success response to indicate that a object has been subscribed', function(done) { +it('4.29 should return a success response to indicate that a object has been subscribed', function(done) { var subclientrequest = { "channel": { @@ -1031,7 +1052,7 @@ it('should return a success response to indicate that a object has been subscrib }); }); -it('should return a success response to indicate that a object has been subscribed with pagination', function(done) { +it('4.30 should return a success response to indicate that a object has been subscribed with pagination', function(done) { var subclientrequest = { page: 2, @@ -1056,7 +1077,7 @@ it('should return a success response to indicate that a object has been subscrib }); }); -it('should return a success response to indicate that a object has NOT been subscribed because context does not belong to application', function(done) { +it('4.31 should return a success response to indicate that a object has NOT been subscribed because context does not belong to application', function(done) { var subclientrequest = { "channel": { @@ -1081,7 +1102,7 @@ it('should return a success response to indicate that a object has NOT been subs }); }); -it('should return an error response to indicate that a object has NOT been subscribed because of invalid authorization', function(done) { +it('4.32 should return an error response to indicate that a object has NOT been subscribed because of invalid authorization', function(done) { var subclientrequest = { "channel": { @@ -1106,7 +1127,7 @@ it('should return an error response to indicate that a object has NOT been subsc }); }); -it('should return an error response to indicate that a object has been NOT subscribed because of filters', function(done) { +it('4.33 should return an error response to indicate that a object has been NOT subscribed because of filters', function(done) { var subclientrequest = { "channel": { @@ -1163,7 +1184,7 @@ it('should return an error response to indicate that a object has been NOT subsc }); }); -it('should return an error response to indicate that a object has NOT been subscribed because of invalid context', function(done) { +it('4.34 should return an error response to indicate that a object has NOT been subscribed because of invalid context', function(done) { var subclientrequest = { "channel": { @@ -1182,36 +1203,17 @@ it('should return an error response to indicate that a object has NOT been subsc .send(subclientrequest) .end(function(err, res) { + res.body.code.should.be.equal('002'); res.statusCode.should.be.equal(500); done(); }); }); -it('should return an error response to indicate that a object has NOT been subscribed because context does not belong to app', function(done) { +it('4.35 should return an error response to indicate that a object has NOT been subscribed because no schema is defined', function(done) { var clientrequest = { - name: "test-app", - keys: [ appKey ], - schema: { - "comments": { - "namespace": "comments", - "type": "comments", - "properties": { - "text": { - "type": "string" - } - }, - "belongsTo": [ - { - "parentModel": "events", - "relationType": "hasMany" - } - ], - "read_acl": 6, - "write_acl": 6, - "meta_read_acl": 6 - } - } + "name": "test-app", + "keys": [ appKey ] }; request(url) @@ -1240,14 +1242,130 @@ it('should return an error response to indicate that a object has NOT been subsc .send(subclientrequest) .end(function (err, res) { - res.statusCode.should.be.equal(403); + res.body.code.should.be.equal('043'); + res.statusCode.should.be.equal(501); done(); }); }); }); +it('4.36 should return an error response to indicate that a object has NOT been subscribed because context does not belong to app', function(done) { + + var clientrequest = { + "name": "test-app", + "keys": [ appKey ] + }; + + request(url) + .post('/admin/app/add') + .set('Content-type','application/json') + .set('Authorization', authValue) + .send(clientrequest) + .end(function(err, res) { -it('should return a success response to indicate that a object has NOT been subscribed', function(done) { + var appID2 = res.body.content.id; + + var clientrequest = { + "appId": appID, + "schema": { + "comments": { + "namespace": "comments", + "type": "comments", + "properties": { + "text": { + "type": "string" + } + }, + "belongsTo": [ + { + "parentModel": "events", + "relationType": "hasMany" + } + ], + "read_acl": 6, + "write_acl": 6, + "meta_read_acl": 6 + }, + "events": { + "namespace": "events", + "type": "events", + "properties": { + "text": { + "type": "string" + }, + "image": { + "type": "string" + }, + "options": { + "type": "object" + } + }, + "hasMany": [ + "comments" + ], + "read_acl": 7, + "write_acl": 7, + "meta_read_acl": 4 + }, + "things": { + "namespace": "events", + "type": "events", + "properties": { + "text": { + "type": "string" + }, + "image": { + "type": "string" + }, + "options": { + "type": "object" + } + }, + "hasMany": [ + "comments" + ], + "read_acl": 7, + "write_acl": 7, + "meta_read_acl": 4 + } + } + }; + + request(url) + .post('/admin/schema/update') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .set('X-BLGREQ-APPID', appID2 ) + .send(clientrequest) + .end(function(err, res) { + + var subclientrequest = { + "channel": { + "context": contextID, + "model": "comments" + }, + }; + + request(url) + .post('/object/subscribe') + .set('Content-type', 'application/json') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID', appID2) + .set('Authorization', userAuthValue) + .send(subclientrequest) + .end(function (err, res) { + + res.body.code.should.be.equal('026'); + res.statusCode.should.be.equal(403); + done(); + }); + }); + }); +}); + + +it('4.37 should return a success response to indicate that a object has NOT been subscribed because of invalid channel', function(done) { var subclientrequest = { "channel": { @@ -1268,12 +1386,13 @@ it('should return a success response to indicate that a object has NOT been subs .send(subclientrequest) .end(function(err, res) { + res.body.code.should.be.equal('027'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an error response to indicate that a object has NOT been subscribed because object was not found', function(done) { +it('4.38 should return an error response to indicate that a object has NOT been subscribed because object was not found', function(done) { var subclientrequest = { "channel": { @@ -1293,12 +1412,13 @@ it('should return an error response to indicate that a object has NOT been subsc .send(subclientrequest) .end(function(err, res) { + res.body.code.should.be.equal('034'); res.statusCode.should.be.equal(404); done(); }); }); -it('should return an error response to indicate that a object has NOT been subscribed because of empty body', function(done) { +it('4.39 should return an error response to indicate that a object has NOT been subscribed because of empty body', function(done) { request(url) .post('/object/subscribe') @@ -1310,12 +1430,13 @@ it('should return an error response to indicate that a object has NOT been subsc .send() .end(function(err, res) { + res.body.code.should.be.equal('005'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a success response to indicate that a object has NOT been subscribed because of missing context', function(done) { +it('4.40 should return a success response to indicate that a object has NOT been subscribed because of missing context', function(done) { var subclientrequest = { "channel": { @@ -1333,12 +1454,13 @@ it('should return a success response to indicate that a object has NOT been subs .send(subclientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a success response to indicate that a object has NOT been subscribed because of missing model', function(done) { +it('4.41 should return a success response to indicate that a object has NOT been subscribed because of missing model', function(done) { var subclientrequest = { "channel": { @@ -1356,12 +1478,13 @@ it('should return a success response to indicate that a object has NOT been subs .send(subclientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a success response to indicate that a object has NOT been subscribed because of model not found', function(done) { +it('4.42 should return a success response to indicate that a object has NOT been subscribed because of model not found', function(done) { var subclientrequest = { "channel": { @@ -1380,12 +1503,13 @@ it('should return a success response to indicate that a object has NOT been subs .send(subclientrequest) .end(function(err, res) { + res.body.code.should.be.equal('022'); res.statusCode.should.be.equal(404); done(); }); }); -it('should return an error response to indicate that a object has NOT been subscribed because of missing channel', function(done) { +it('4.43 should return an error response to indicate that a object has NOT been subscribed because of missing channel', function(done) { var subclientrequest = { "filters": { @@ -1432,12 +1556,13 @@ it('should return an error response to indicate that a object has NOT been subsc .send(subclientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an success response to indicate that a object has been unsubscribed', function(done) { +it('4.44 should return an success response to indicate that a object has been unsubscribed', function(done) { var subclientrequest = { "channel": { @@ -1460,7 +1585,7 @@ it('should return an success response to indicate that a object has been unsubsc }); }); -it('should return an error response to indicate that a object has NOT been unsubscribed because of empty body', function(done) { +it('4.45 should return an error response to indicate that a object has NOT been unsubscribed because of empty body', function(done) { request(url) .post('/object/unsubscribe') @@ -1471,12 +1596,13 @@ it('should return an error response to indicate that a object has NOT been unsub .send() .end(function(err, res) { + res.body.code.should.be.equal('005'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a error response (400) to indicate that a object has NOT been unsubscribed', function(done) { +it('4.46 should return a error response (400) to indicate that a object has NOT been unsubscribed', function(done) { var subclientrequest = { "channel": { @@ -1497,12 +1623,13 @@ it('should return a error response (400) to indicate that a object has NOT been .send(subclientrequest) .end(function(err, res) { + res.body.code.should.be.equal('027'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a error response (404) to indicate that a object has NOT been unsubscribed', function(done) { +it('4.47 should return a error response (404) to indicate that a object has NOT been unsubscribed', function(done) { var subclientrequest = { "channel": { @@ -1524,12 +1651,13 @@ it('should return a error response (404) to indicate that a object has NOT been .send(subclientrequest) .end(function(err, res) { + res.body.code.should.be.equal('037'); res.statusCode.should.be.equal(404); done(); }); }); -it('should return a error response (404) to indicate that a object has NOT been unsubscribed, using filters', function(done) { +it('4.48 should return a error response (404) to indicate that a object has NOT been unsubscribed, using filters', function(done) { var subclientrequest = { "channel": { @@ -1580,13 +1708,14 @@ it('should return a error response (404) to indicate that a object has NOT been .send(subclientrequest) .end(function(err, res) { + res.body.code.should.be.equal('037'); res.statusCode.should.be.equal(404); done(); }); }); -it('should return a success response to indicate that a object has NOT been unsubscribed because of missing channel', function(done) { +it('4.49 should return a success response to indicate that a object has NOT been unsubscribed because of missing channel', function(done) { var subclientrequest = { "something": {} @@ -1600,12 +1729,14 @@ it('should return a success response to indicate that a object has NOT been unsu .set('Authorization', userAuthValue) .send(subclientrequest) .end(function(err, res) { + + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a success response to indicate that a object has NOT been unsubscribed because of missing context', function(done) { +it('4.50 should return a success response to indicate that a object has NOT been unsubscribed because of missing context', function(done) { var subclientrequest = { "channel": { @@ -1623,12 +1754,13 @@ it('should return a success response to indicate that a object has NOT been unsu .send(subclientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a success response to indicate that a object has NOT been unsubscribed because of missing model', function(done) { +it('4.51 should return a success response to indicate that a object has NOT been unsubscribed because of missing model', function(done) { var subclientrequest = { "channel": { @@ -1645,12 +1777,13 @@ it('should return a success response to indicate that a object has NOT been unsu .send(subclientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a success response to indicate that a object has been deleted', function(done) { +it('4.52 should return a success response to indicate that a object has been deleted', function(done) { var clientrequest = { "model": "comments", @@ -1672,7 +1805,7 @@ it('should return a success response to indicate that a object has been deleted' }); }); -it('should return an error response to indicate that a object was NOT deleted', function(done) { +it('4.53 should return an error response to indicate that a object was NOT deleted', function(done) { this.timeout(20*DELAY); @@ -1693,6 +1826,7 @@ it('should return an error response to indicate that a object was NOT deleted', .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('011'); res.statusCode.should.be.equal(404); done(); }); @@ -1700,7 +1834,7 @@ it('should return an error response to indicate that a object was NOT deleted', }); -it('should return an error response to indicate that the object id was missing', function(done) { +it('4.54 should return an error response to indicate that the object id was missing', function(done) { var clientrequest = { "model": "comments", @@ -1717,12 +1851,13 @@ it('should return an error response to indicate that the object id was missing', .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an error response to indicate that the object model was missing', function(done) { +it('4.55 should return an error response to indicate that the object model was missing', function(done) { var clientrequest = { "context": contextID, @@ -1739,12 +1874,13 @@ it('should return an error response to indicate that the object model was missin .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an error response to indicate that the object was not deleted because of missing authentication', function(done) { +it('4.56 should return an error response to indicate that the object was not deleted because of missing authentication', function(done) { var clientrequest = { "model": "comments", @@ -1761,12 +1897,13 @@ it('should return an error response to indicate that the object was not deleted .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('013'); res.statusCode.should.be.equal(401); done(); }); }); -it('should return an error response to indicate that the object was not deleted because of missing context', function(done) { +it('4.57 should return an error response to indicate that the object was not deleted because of missing context', function(done) { var clientrequest = { "model": "comments", @@ -1783,12 +1920,13 @@ it('should return an error response to indicate that the object was not deleted .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an error response to indicate that the object was not deleted because of empty request', function(done) { +it('4.58 should return an error response to indicate that the object was not deleted because of empty request', function(done) { request(url) .post('/object/delete') @@ -1799,6 +1937,7 @@ it('should return an error response to indicate that the object was not deleted .send() .end(function(err, res) { + res.body.code.should.be.equal('005'); res.statusCode.should.be.equal(400); done(); }); diff --git a/test/user/user.js b/test/user/user.js index e41d11c..2028858 100644 --- a/test/user/user.js +++ b/test/user/user.js @@ -26,7 +26,7 @@ var admin = { before(function(done){ - this.timeout(10000); + this.timeout(25*DELAY); var deviceRegisterRequest = { "info": { @@ -89,7 +89,7 @@ before(function(done){ }); }); -it('should return an error response to indicate that the user has NOT logged via Facebook because of missing access token', function(done) { +it('5.1 should return an error response to indicate that the user has NOT logged via Facebook because request body is empty', function(done) { request(url) .post('/user/login') @@ -99,13 +99,35 @@ it('should return an error response to indicate that the user has NOT logged via .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send() .end(function(err, res) { - //console.log(res.body); + + res.body.code.should.be.equal('005'); + res.statusCode.should.be.equal(400); + done(); + }); +}); + +it('5.2 should return an error response to indicate that the user has NOT logged via Facebook because of missing access token', function(done) { + + var clientRequest = { + "something_else": "invalidToken" + }; + + request(url) + .post('/user/login') + .set('Content-type','application/json') + .set('X-BLGREQ-SIGN', appIDsha256 ) + .set('X-BLGREQ-APPID', appID ) + .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) + .send(clientRequest) + .end(function(err, res) { + + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an error response to indicate that the user has NOT logged via Facebook because of invalid token', function(done) { +it('5.3 should return an error response to indicate that the user has NOT logged via Facebook because of invalid token', function(done) { var clientrequest = { "access_token": "invalidToken" @@ -120,12 +142,13 @@ it('should return an error response to indicate that the user has NOT logged via .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('002'); res.statusCode.should.be.equal(500); done(); }); }); -it('should return a success response to indicate that the user has logged in via user & password', function(done) { +it('5.4 should return a success response to indicate that the user has logged in via user & password', function(done) { this.timeout(13*DELAY); @@ -164,7 +187,7 @@ it('should return a success response to indicate that the user has logged in via }); }); -it('should return a success response to indicate that the user has logged in via Facebook', function(done) { +it('5.5 should return a success response to indicate that the user has logged in via Facebook', function(done) { this.timeout(100*DELAY); @@ -212,7 +235,7 @@ it('should return a success response to indicate that the user has logged in via }); }); -it('should return a success response to indicate that the user info was retrieved', function(done) { +it('5.6 should return a success response to indicate that the user info was retrieved', function(done) { request(url) .get('/user/me') @@ -229,7 +252,7 @@ it('should return a success response to indicate that the user info was retrieve }); }); -it('should return an error response to indicate that the user info was NOT retrieved because user was not found', function(done) { +it('5.7 should return an error response to indicate that the user info was NOT retrieved because user was not found', function(done) { this.timeout(25*DELAY); @@ -286,6 +309,7 @@ it('should return an error response to indicate that the user info was NOT retri .send() .end(function(err, res) { + res.body.code.should.be.equal('023'); res.statusCode.should.be.equal(404); done(); }); @@ -296,7 +320,7 @@ it('should return an error response to indicate that the user info was NOT retri }); }); -it('should return an error response to indicate that the user has NOT logged in via user & password because of Invalid Credentials', function(done) { +it('5.8 should return an error response to indicate that the user has NOT logged in via user & password because of invalid credentials', function(done) { var clientrequest = { "email": userEmail, @@ -313,12 +337,13 @@ it('should return an error response to indicate that the user has NOT logged in .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('031'); res.statusCode.should.be.equal(401); done(); }); }); -it('should return an error response to indicate that the user has NOT logged in via user & password because user not found', function(done) { +it('5.9 should return an error response to indicate that the user has NOT logged in via user & password because user not found', function(done) { var clientrequest = { "email": 'user'+Math.round(Math.random()*1000000)+'@example.com', @@ -334,12 +359,14 @@ it('should return an error response to indicate that the user has NOT logged in .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { + + res.body.code.should.be.equal('023'); res.statusCode.should.be.equal(404); done(); }); }); -it('should return an error response to indicate that the user has NOT logged in via user & password because email was missing for request', function(done) { +it('5.10 should return an error response to indicate that the user has NOT logged in via user & password because email was missing for request', function(done) { var clientrequest = { "password": "secure_password", @@ -354,12 +381,14 @@ it('should return an error response to indicate that the user has NOT logged in .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { + + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an error response to indicate that the user has NOT logged in via user & password because password was missing for request', function(done) { +it('5.11 should return an error response to indicate that the user has NOT logged in via user & password because password was missing for request', function(done) { var clientrequest = { "email": 'user'+Math.round(Math.random()*1000000)+'@example.com', @@ -374,12 +403,14 @@ it('should return an error response to indicate that the user has NOT logged in .set('X-BLGREQ-UDID', 'd244854a-ce93-4ba3-a1ef-c4041801ce28' ) .send(clientrequest) .end(function(err, res) { + + res.body.code.should.be.equal('004'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a success response to indicate that the user was updated', function(done) { +it('5.12 should return a success response to indicate that the user was updated', function(done) { var clientrequest = { "patches" : [ @@ -400,12 +431,13 @@ it('should return a success response to indicate that the user was updated', fun .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + res.statusCode.should.be.equal(202); done(); }); }); -it('should return a success response to indicate that the user password was updated', function(done) { +it('5.13 should return a success response to indicate that the user password was updated', function(done) { var clientrequest = { "patches" : [ @@ -432,7 +464,7 @@ it('should return a success response to indicate that the user password was upda }); }); -it('should return an error response to indicate that the userID is not valid', function(done) { +it('5.14 should return an error response to indicate that the userID is not valid', function(done) { var clientrequest = { "patches" : [ @@ -454,12 +486,13 @@ it('should return an error response to indicate that the userID is not valid', f .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('042'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a success response to indicate that the user password was NOT updated because of empty request body', function(done) { +it('5.15 should return a success response to indicate that the user password was NOT updated because of empty request body', function(done) { request(url) .post('/user/update') @@ -470,12 +503,14 @@ it('should return a success response to indicate that the user password was NOT .set('Authorization', authValue ) .send() .end(function(err, res) { + + res.body.code.should.be.equal('005'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a success response to indicate that the user password was NOT updated because patches is not an array', function(done) { +it('5.16 should return a success response to indicate that the user password was NOT updated because patches is not an array', function(done) { var clientrequest = { "patches" : {} @@ -490,12 +525,14 @@ it('should return a success response to indicate that the user password was NOT .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + + res.body.code.should.be.equal('038'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a success response to indicate that the user password was NOT updated because patches is an empty array', function(done) { +it('5.17 should return a success response to indicate that the user password was NOT updated because patches is an empty array', function(done) { var clientrequest = { "patches" : [] @@ -510,12 +547,14 @@ it('should return a success response to indicate that the user password was NOT .set('Authorization', authValue ) .send(clientrequest) .end(function(err, res) { + + res.body.code.should.be.equal('038'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a success response to indicate that the user was updated immidiate', function(done) { +it('5.18 should return a success response to indicate that the user was updated immediate', function(done) { this.timeout(20*DELAY); @@ -539,7 +578,7 @@ it('should return a success response to indicate that the user was updated immid }); }); -it('should return a success response to indicate that the token was updated', function(done) { +it('5.19 should return a success response to indicate that the token was updated', function(done) { request(url) .get('/user/refresh_token') @@ -559,7 +598,7 @@ it('should return a success response to indicate that the token was updated', fu }); }); -it('should return an error response to indicate that the token was NOT updated because of bad Authorization', function(done) { +it('5.20 should return an error response to indicate that the token was NOT updated because of bad authorization', function(done) { var authValue = "something"; @@ -573,12 +612,13 @@ it('should return an error response to indicate that the token was NOT updated b .send() .end(function(err, res) { + res.body.code.should.be.equal('014'); res.statusCode.should.be.equal(401); done(); }); }); -it('should return an error response to indicate that the token was NOT updated because of bad token', function(done) { +it('5.21 should return an error response to indicate that the token was NOT updated because of bad token', function(done) { var authValue = 'Bearer something'; @@ -592,13 +632,14 @@ it('should return an error response to indicate that the token was NOT updated b .send() .end(function(err, res) { + res.body.code.should.be.equal('040'); res.statusCode.should.be.equal(400); res.body.message.should.be.equal("Malformed authorization token"); done(); }); }); -it('should return an error response to indicate that the token was NOT updated because authorization is missing', function(done) { +it('5.22 should return an error response to indicate that the token was NOT updated because authorization is missing', function(done) { request(url) .get('/user/refresh_token') @@ -609,12 +650,13 @@ it('should return an error response to indicate that the token was NOT updated b .send() .end(function(err, res) { + res.body.code.should.be.equal('013'); res.statusCode.should.be.equal(401); done(); }); }); -it('should return an error response to indicate that the token was NOT updated because X-BLGREQ-SIGN is missing', function(done) { +it('5.23 should return an error response to indicate that the token was NOT updated because X-BLGREQ-SIGN is missing', function(done) { request(url) .get('/user/refresh_token') @@ -625,12 +667,13 @@ it('should return an error response to indicate that the token was NOT updated b .send() .end(function(err, res) { + res.body.code.should.be.equal('007'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an error response to indicate that the token was NOT updated because Content-type is not application/json', function(done) { +it('5.24 should return an error response to indicate that the token was NOT updated because Content-type is not application/json', function(done) { request(url) .get('/user/refresh_token') @@ -642,12 +685,13 @@ it('should return an error response to indicate that the token was NOT updated b .send() .end(function(err, res) { + res.body.code.should.be.equal('006'); res.statusCode.should.be.equal(415); done(); }); }); -it('should return an error response to indicate that the token was NOT updated because of invalid api key', function(done) { +it('5.25 should return an error response to indicate that the token was NOT updated because of invalid API key', function(done) { request(url) .get('/user/refresh_token') @@ -659,12 +703,13 @@ it('should return an error response to indicate that the token was NOT updated b .send() .end(function(err, res) { + res.body.code.should.be.equal('008'); res.statusCode.should.be.equal(401); done(); }); }); -it('should return an error response to indicate that the token was NOT updated because of missing UDID', function(done) { +it('5.26 should return an error response to indicate that the token was NOT updated because of missing UDID', function(done) { request(url) .get('/user/refresh_token') @@ -675,29 +720,13 @@ it('should return an error response to indicate that the token was NOT updated b .send() .end(function(err, res) { + res.body.code.should.be.equal('009'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return an error response to indicate that the token was NOT updated because device ID does not exist', function(done) { - - request(url) - .get('/user/refresh_token') - .set('Content-type','application/json') - .set('X-BLGREQ-SIGN', appIDsha256) - .set('X-BLGREQ-UDID', deviceIdentification + '66') - .set('X-BLGREQ-APPID',appID+ '66') - .set('Authorization', authValue ) - .send() - .end(function(err, res) { - - res.statusCode.should.be.equal(404); - done(); - }); -}); - -it('should return a success response to indicate that the user logged out', function(done) { +it('5.27 should return a success response to indicate that the user logged out', function(done) { request(url) .get('/user/logout') @@ -714,7 +743,7 @@ it('should return a success response to indicate that the user logged out', func }); }); -it('should return a success response to indicate that the user has registered', function(done) { +it('5.28 should return a success response to indicate that the user has registered', function(done) { this.timeout(20*DELAY); @@ -738,7 +767,7 @@ it('should return a success response to indicate that the user has registered', }); }); -it('should return a success response to indicate that the user has NOT registered because user is already registered', function(done) { +it('5.29 should return a success response to indicate that the user has NOT registered because user is already registered', function(done) { var clientrequest = { "email": userEmail, @@ -755,12 +784,13 @@ it('should return a success response to indicate that the user has NOT registere .send(clientrequest) .end(function(err, res) { + res.body.code.should.be.equal('029'); res.statusCode.should.be.equal(409); done(); }); }); -it('should return a success response to indicate that the user has NOT registered because of empty body', function(done) { +it('5.30 should return a success response to indicate that the user has NOT registered because of empty body', function(done) { request(url) .post('/user/register') @@ -771,12 +801,13 @@ it('should return a success response to indicate that the user has NOT registere .send() .end(function(err, res) { + res.body.code.should.be.equal('005'); res.statusCode.should.be.equal(400); done(); }); }); -it('should return a success response to indicate that the user was deleted', function(done) { +it('5.31 should return a success response to indicate that the user was deleted', function(done) { var clientrequest = { "email": userEmail2, From 1c2d2fa0a2d5db790e9f2aa30d8dd517ed935848 Mon Sep 17 00:00:00 2001 From: Alexandrescu Sergiu Date: Thu, 8 Oct 2015 09:37:44 +0000 Subject: [PATCH 38/42] added a larger dellay to test 1.4.6 --- test/admin/admin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/admin/admin.js b/test/admin/admin.js index 860d235..0d4c813 100644 --- a/test/admin/admin.js +++ b/test/admin/admin.js @@ -1634,7 +1634,7 @@ describe('1.4.Schema', function() { }); it('1.4.6 should return a success response to indicate a model was removed from the application', function(done) { - this.timeout(6*DELAY); + this.timeout(12*DELAY); var clientrequest = { "model_name": "things" From 5b3cb923def28a7cba76d8edc27ca548fd8d79ce Mon Sep 17 00:00:00 2001 From: Alexandrescu Sergiu Date: Thu, 8 Oct 2015 10:50:05 +0000 Subject: [PATCH 39/42] commented test 1.2.17 added a larger delay for 1.1.1 --- test/admin/admin.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/admin/admin.js b/test/admin/admin.js index 0d4c813..a9fbe4a 100644 --- a/test/admin/admin.js +++ b/test/admin/admin.js @@ -41,7 +41,7 @@ describe('1.1.Admin', function() { it('1.1.1 should return a 200 code to indicate success when creating a new admin', function(done) { - this.timeout(12*DELAY); + this.timeout(20*DELAY); request(url) .post('/admin/add') @@ -54,7 +54,7 @@ describe('1.1.Admin', function() { } res.statusCode.should.be.equal(200); - setTimeout(done, 8*DELAY); + setTimeout(done, 12*DELAY); }); }); @@ -889,7 +889,7 @@ describe('1.2.App', function() { }); }); -/* it('1.2.17 should return an error to indicate an admin has NOT been deauthorized to an application, admin not authorized', function(done) { + /*it('1.2.17 should return an error to indicate an admin has NOT been deauthorized to an application, admin not authorized', function(done) { var clientrequest = { "email": adminEmail3 @@ -1618,7 +1618,7 @@ describe('1.4.Schema', function() { }); }); - it('1.4.5 should return a success response to indicate schema was retrievedsuccessfullyy using the new API', function(done) { + it('1.4.5 should return a success response to indicate schema was retrieved successfully using the new API', function(done) { request(url) .get('/admin/schema/all') From b503b2896ff42a27d362c9190ff40097e84d9592 Mon Sep 17 00:00:00 2001 From: Razvan Botea Date: Fri, 9 Oct 2015 13:37:18 +0300 Subject: [PATCH 40/42] fix crash at boot up --- app.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app.js b/app.js index 1ad7874..a6e7856 100644 --- a/app.js +++ b/app.js @@ -202,6 +202,7 @@ async.waterfall([ process.exit(-1); } + clientConfiguration = clientConfiguration || {broadcast: false}; /** * @type {MessagingClient} */ From f7f5e6006faa02ce7f43ba322cea3eac832d6919 Mon Sep 17 00:00:00 2001 From: Razvan Botea Date: Fri, 9 Oct 2015 16:47:35 +0300 Subject: [PATCH 41/42] Improved tests: added default 10s timeout, every test that works with workers wait 2 seconds before calling done() * Subscribe only returns objects if page > 1 --- controllers/object.js | 40 +- test/admin/admin.js | 520 +++++++++++++--------- test/context/context.js | 73 ++-- test/device/device.js | 61 ++- test/object/object.js | 942 ++++++++++++++++++++++------------------ test/user/user.js | 240 ++++++---- 6 files changed, 1081 insertions(+), 795 deletions(-) diff --git a/controllers/object.js b/controllers/object.js index 8b11d47..9cea1dd 100644 --- a/controllers/object.js +++ b/controllers/object.js @@ -149,14 +149,15 @@ router.post('/subscribe', function(req, res, next) { function(callback) { validateContext(appId, context, callback); }, - //see if device exists function(callback) { - Models.Subscription.getDevice(deviceId, function(err) { - if (err) { - callback(err); - } + //only add subscription on initial /subscribe + if (page && page > 1) + return callback(); + Models.Subscription.add(deviceId, channelObject, function(err) { + if (err && err.status === 409) + return callback(); - callback(); + callback(err); }); }, function(callback) { @@ -178,14 +179,6 @@ router.post('/subscribe', function(req, res, next) { callback(); }); } - }, - function(callback) { - Models.Subscription.add(deviceId, channelObject, function(err) { - if (err && err.status === 409) - return callback(); - - callback(err); - }); } /*, function(results, callback) { @@ -281,18 +274,13 @@ router.post('/unsubscribe', function(req, res, next) { return next(new Models.TelepatError(Models.TelepatError.errors.InvalidChannel)); } - async.waterfall([ + async.series([ //verify if context belongs to app function(callback) { validateContext(appId, context, callback); }, function(callback) { - Models.Subscription.remove(deviceId, channelObject, function(err, results) { - if (err) - callback(err, null); - else - callback(null, {status: 200, content: 'Subscription removed'}); - }); + Models.Subscription.remove(deviceId, channelObject, callback); }/*, function(result, callback) { app.kafkaProducer.send([{ @@ -310,10 +298,12 @@ router.post('/unsubscribe', function(req, res, next) { callback(err, result); }); }*/ - ], function(err, results) { - if (err) return next(err); - - res.status(200).json(results).end(); + ], function(err) { + if (err) { + return next(err); + } else { + res.status(200).json({status: 200, content: 'Subscription removed'}).end(); + } }); }); diff --git a/test/admin/admin.js b/test/admin/admin.js index a9fbe4a..fc3eb95 100644 --- a/test/admin/admin.js +++ b/test/admin/admin.js @@ -41,7 +41,7 @@ describe('1.1.Admin', function() { it('1.1.1 should return a 200 code to indicate success when creating a new admin', function(done) { - this.timeout(20*DELAY); + this.timeout(100*DELAY); request(url) .post('/admin/add') @@ -54,12 +54,14 @@ describe('1.1.Admin', function() { } res.statusCode.should.be.equal(200); - setTimeout(done, 12*DELAY); + done(); }); }); it('1.1.2 should return an error (409) response to indicate failure when admin already exists', function(done) { + this.timeout(100*DELAY); + request(url) .post('/admin/add') .send(admin) @@ -74,6 +76,8 @@ describe('1.1.Admin', function() { it('1.1.3 should return an error response indicate failure when admin email is missing', function(done) { + this.timeout(100*DELAY); + var admin = { password: adminPassword }; @@ -91,6 +95,8 @@ describe('1.1.Admin', function() { it('1.1.4 should return an error response to indicate failure when admin email is empty', function(done) { + this.timeout(100*DELAY); + var admin = { email: "", password: adminPassword @@ -109,6 +115,8 @@ describe('1.1.Admin', function() { it('1.1.5 should return an error response to indicate failure when admin password is empty', function(done) { + this.timeout(100*DELAY); + var admin = { email: adminEmail, password: "" @@ -127,6 +135,8 @@ describe('1.1.Admin', function() { it('1.1.6 should return an error response to indicate failure when admin password is missing', function(done) { + this.timeout(100*DELAY); + var admin = { email: adminEmail }; @@ -144,6 +154,8 @@ describe('1.1.Admin', function() { it('1.1.7 should return an error for logging in with wrong password', function(done) { + this.timeout(100*DELAY); + var admin = { email: adminEmail, password: adminPassword + '66' @@ -161,6 +173,8 @@ describe('1.1.Admin', function() { it('1.1.8 should return an error for logging in with wrong user', function(done) { + this.timeout(100*DELAY); + var randEmail = 'adminx@example.com'; var admin = { email: randEmail, @@ -179,6 +193,8 @@ describe('1.1.Admin', function() { it('1.1.9 should return an error for logging in missing password', function(done) { + this.timeout(100*DELAY); + var randEmail = 'adminx@example.com'; var admin = { email: randEmail @@ -197,6 +213,8 @@ describe('1.1.Admin', function() { it('1.1.10 should return an error for logging in missing email & password', function(done) { + this.timeout(100*DELAY); + var admin = {}; request(url) @@ -212,13 +230,15 @@ describe('1.1.Admin', function() { it('1.1.11 should return a valid authorization token', function(done) { + this.timeout(100*DELAY); + request(url) .post('/admin/login') .send(admin) .end(function(err, res) { authValue = 'Bearer ' + res.body.content.token; - adminAuth = authValue; + var adminAuth = authValue; admin = res.body.content.user; res.statusCode.should.be.equal(200); done(); @@ -227,6 +247,8 @@ describe('1.1.Admin', function() { it('1.1.12 should return information about the logged admin', function(done) { + this.timeout(100*DELAY); + request(url) .get('/admin/me') .set('Content-type','application/json') @@ -243,6 +265,8 @@ describe('1.1.Admin', function() { it('1.1.13 should return an success response indicating the admin account has been updated', function(done) { + this.timeout(100*DELAY); + var requestBody = { patches: [ { @@ -267,6 +291,8 @@ describe('1.1.Admin', function() { it('1.1.14 should return an error response indicating the admin account has NOT been updated because of invalid admin id', function(done) { + this.timeout(100*DELAY); + var admin = { patches: [ { @@ -292,6 +318,8 @@ describe('1.1.Admin', function() { it('1.1.15 should return an error response indicating the admin account has NOT been updated because of missing authorization header', function(done) { + this.timeout(100*DELAY); + var admin = { patches: [ { @@ -316,6 +344,8 @@ describe('1.1.Admin', function() { it('1.1.16 should return an error response indicating the admin account has NOT been updated because of missing request body', function(done) { + this.timeout(100*DELAY); + request(url) .post('/admin/update') .set('Content-type','application/json') @@ -332,6 +362,8 @@ describe('1.1.Admin', function() { it('1.1.17 should return an error response indicating the admin account has NOT been updated because patches is not an array', function(done) { + this.timeout(100*DELAY); + var admin = { patches: {} }; @@ -351,6 +383,8 @@ describe('1.1.Admin', function() { it('1.1.18 should return an error response indicating the admin account has NOT been updated because patches is empty', function(done) { + this.timeout(100*DELAY); + var admin = { patches: [] }; @@ -370,6 +404,8 @@ describe('1.1.Admin', function() { it('1.1.19 should return an error response indicating the admin account has NOT been deleted because of missing credentials', function(done) { + this.timeout(100*DELAY); + request(url) .post('/admin/delete') .set('Content-type','application/json') @@ -383,7 +419,7 @@ describe('1.1.Admin', function() { it('1.1.20 should return an success response indicating the admin account has been deleted', function(done) { - this.timeout(20*DELAY); + this.timeout(100*DELAY); request(url) .post('/admin/delete') @@ -394,30 +430,24 @@ describe('1.1.Admin', function() { res.statusCode.should.be.equal(200); - setTimeout(function() { - - request(url) - .post('/admin/add') - .send(admin) - .end(function(err, res) { - - res.statusCode.should.be.equal(200); - - setTimeout(function () { + request(url) + .post('/admin/add') + .send(admin) + .end(function(err, res) { - request(url) - .post('/admin/login') - .send(admin) - .end(function(err, res) { + res.statusCode.should.be.equal(200); - authValue = 'Bearer ' + res.body.content.token; - adminAuth = authValue; - res.statusCode.should.be.equal(200); - done(); - }); - }, 8*DELAY); - }); - }, 8*DELAY); + request(url) + .post('/admin/login') + .send(admin) + .end(function(err, res) { + + authValue = 'Bearer ' + res.body.content.token; + adminAuth = authValue; + res.statusCode.should.be.equal(200); + done(); + }); + }); }); }); }); @@ -426,7 +456,7 @@ describe('1.2.App', function() { before(function(done){ - this.timeout(20*DELAY); + this.timeout(100*DELAY); var clientrequest = { "name": "test-app", @@ -456,38 +486,32 @@ describe('1.2.App', function() { .send(admin2) .end(function (err, res) { - setTimeout(function () { - - request(url) - .post('/admin/login') - .set('Content-type', 'application/json') - .send(admin2) - .end(function (err, res) { - - token2 = res.body.content.token; - authValue2 = 'Bearer ' + token2; - - request(url) - .post('/admin/add') - .send(admin3) - .end(function (err, res) { - - setTimeout(function () { - - request(url) - .post('/admin/login') - .set('Content-type', 'application/json') - .send(admin3) - .end(function (err, res) { - - token3 = res.body.content.token; - authValue3 = 'Bearer ' + token3; - done(); - }); - }, 3 * DELAY); - }); - }); - }, 3 * DELAY); + request(url) + .post('/admin/login') + .set('Content-type', 'application/json') + .send(admin2) + .end(function (err, res) { + + token2 = res.body.content.token; + authValue2 = 'Bearer ' + token2; + + request(url) + .post('/admin/add') + .send(admin3) + .end(function (err, res) { + + request(url) + .post('/admin/login') + .set('Content-type', 'application/json') + .send(admin3) + .end(function (err, res) { + + token3 = res.body.content.token; + authValue3 = 'Bearer ' + token3; + done(); + }); + }); + }); }); }); }); @@ -495,6 +519,8 @@ describe('1.2.App', function() { it('1.2.1 should return a success response to indicate app successfully created', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "name": "test-app", "keys": [ appKey ] @@ -525,6 +551,8 @@ describe('1.2.App', function() { it('1.2.2 should return an error response to indicate app was not created because of missing app name', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "keys": ["3406870085495689e34d878f09faf52c"] }; @@ -544,6 +572,8 @@ describe('1.2.App', function() { it('1.2.3 should return a list of applications for the current admin', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "name": "test-app", "keys": [ appKey ] @@ -563,27 +593,26 @@ describe('1.2.App', function() { .send(clientrequest) .end(function(err, res) { - setTimeout(function () { - - request(url) - .get('/admin/apps') - .set('Content-type','application/json') - .set('Authorization', authValue ) - .send() - .end(function(err, res) { - - res.statusCode.should.be.equal(200); - res.body.status.should.be.equal(200); - (Object.keys(res.body.content).length >= 3).should.be.ok; - done(); - }); - }, 1000); + request(url) + .get('/admin/apps') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .send() + .end(function(err, res) { + + res.statusCode.should.be.equal(200); + res.body.status.should.be.equal(200); + (Object.keys(res.body.content).length >= 3).should.be.ok; + done(); + }); }); }); }); it('1.2.4 should return a success response for updating an app', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "name": "test-app", "keys": [ appKey ] @@ -596,7 +625,6 @@ describe('1.2.App', function() { .send(clientrequest) .end(function(err, res) { - var objectKey = Object.keys(res.body.content)[0]; var appID = res.body.content.id; var clientrequest2 = { patches: [ @@ -608,25 +636,24 @@ describe('1.2.App', function() { ] }; - setTimeout(function () { - - request(url) - .post('/admin/app/update') - .set('Content-type','application/json') - .set('Authorization', authValue ) - .set('X-BLGREQ-APPID', appID ) - .send(clientrequest2) - .end(function(err, res) { + request(url) + .post('/admin/app/update') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .set('X-BLGREQ-APPID', appID ) + .send(clientrequest2) + .end(function(err, res) { - res.statusCode.should.be.equal(200); - done(); - }); - }, 2*DELAY); + res.statusCode.should.be.equal(200); + done(); + }); }); }); it('1.2.5 should return an error response for NOT updating an app because patches is not an array', function(done) { + this.timeout(100*DELAY); + var clientrequest2 = { patches: {} }; @@ -647,6 +674,8 @@ describe('1.2.App', function() { it('1.2.6 should return an error response for NOT updating an app because patches is an empty array', function(done) { + this.timeout(100*DELAY); + var clientrequest2 = { patches: [] }; @@ -667,6 +696,8 @@ describe('1.2.App', function() { it('1.2.7 should return an error response for NOT updating an app because of missing request body', function(done) { + this.timeout(100*DELAY); + request(url) .post('/admin/app/update') .set('Content-type','application/json') @@ -683,6 +714,8 @@ describe('1.2.App', function() { it('1.2.8 should return an error response for NOT updating an app because of missing appID', function(done) { + this.timeout(100*DELAY); + var clientrequest2 = { patches: [ { @@ -709,6 +742,8 @@ describe('1.2.App', function() { it('1.2.9 should return a success response for removing an app', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "name": "test-app", "keys": [ appKey ] @@ -721,29 +756,27 @@ describe('1.2.App', function() { .send(clientrequest) .end(function(err, res) { - var objectKey = Object.keys(res.body.content)[0]; var appID = res.body.content.id; - setTimeout(function() { - - request(url) - .post('/admin/app/remove') - .set('Content-type','application/json') - .set('Authorization', authValue ) - .set('X-BLGREQ-APPID', appID ) - .send() - .end(function(err, res) { + request(url) + .post('/admin/app/remove') + .set('Content-type','application/json') + .set('Authorization', authValue ) + .set('X-BLGREQ-APPID', appID ) + .send() + .end(function(err, res) { - res.statusCode.should.be.equal(200); - res.body.content.should.be.equal('App removed'); - done(); - }); - }, 2*DELAY); + res.statusCode.should.be.equal(200); + res.body.content.should.be.equal('App removed'); + done(); + }); }); }); it('1.2.10 should return an error response for trying to remove an app that does NOT exist', function(done) { + this.timeout(100*DELAY); + request(url) .post('/admin/app/remove') .set('Content-type','application/json') @@ -760,6 +793,8 @@ describe('1.2.App', function() { it('1.2.11 should return an success to indicate an admin has been authorized to an application', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "email": adminEmail2 }; @@ -782,6 +817,8 @@ describe('1.2.App', function() { it('1.2.12 should return an error response to indicate admin has NOT been authorized because of missing email from body', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "something": adminEmail2 }; @@ -804,6 +841,8 @@ describe('1.2.App', function() { it('1.2.13 should return an error response to indicate admin has NOT been authorized because request body', function(done) { + this.timeout(100*DELAY); + request(url) .post('/admin/app/authorize') .set('Content-type','application/json') @@ -822,7 +861,7 @@ describe('1.2.App', function() { it('1.2.14 should return an error response to indicate admin with email address already authorized for application', function(done) { - this.timeout(10*DELAY); + this.timeout(100*DELAY); var clientrequest = { "email": adminEmail2 @@ -848,6 +887,8 @@ describe('1.2.App', function() { it('1.2.15 should return an error response to indicate admin has NOT been authenticated because application with that ID doesn\'t exist', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "email": adminEmail2 }; @@ -870,6 +911,8 @@ describe('1.2.App', function() { it('1.2.16 should return an success to indicate an admin has been deauthorized to an application', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "email": adminEmail2 }; @@ -915,6 +958,8 @@ describe('1.2.App', function() { it('1.2.18 should return an error response to indicate admin has NOT been deauthorized because of empty request body', function(done) { + this.timeout(100*DELAY); + request(url) .post('/admin/app/deauthorize') .set('Content-type','application/json') @@ -934,6 +979,8 @@ describe('1.2.App', function() { it('1.2.19 should return an error response to indicate admin has NOT been deauthorized because of the email field is missing', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "something": adminEmail2 }; @@ -956,6 +1003,8 @@ describe('1.2.App', function() { it('1.2.20 should return an error response to indicate admin has NOT been deauthorized because admin was not found in application', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "email": adminEmail2 }; @@ -978,6 +1027,8 @@ describe('1.2.App', function() { it('1.2.21 should return an error response to indicate admin with email address is the last admin of the application', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "email": adminEmail }; @@ -1000,6 +1051,8 @@ describe('1.2.App', function() { it('1.2.22 should return an error response to indicate admin has NOT been deauthenticated because application with that ID doesn\'t exist', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "email": adminEmail2 }; @@ -1025,10 +1078,12 @@ describe('1.3.Context', function() { it('1.3.1 should return a success response to indicate context successfully created', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "name": "context", - "meta": {"info": "some meta info"}, - } + name: "context", + meta: {info: "some meta info"} + }; request(url) .post('/admin/context/add') @@ -1064,9 +1119,11 @@ describe('1.3.Context', function() { it('1.3.3 should return the requested context', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "id": contextID - } + }; request(url) .post('/admin/context') @@ -1083,6 +1140,8 @@ describe('1.3.Context', function() { it('1.3.4 should NOT return the requested context, requested context ID is missing', function(done) { + this.timeout(100*DELAY); + request(url) .post('/admin/context') .set('Content-type','application/json') @@ -1099,9 +1158,11 @@ describe('1.3.Context', function() { it('1.3.5 should return an error response to indicate context NOT successfully created because of bad client headers', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "name": "context", - "meta": {"info": "some meta info"} + name: "context", + meta: {info: "some meta info"} }; request(url) @@ -1119,6 +1180,8 @@ describe('1.3.Context', function() { it('1.3.6 should return an error response to indicate context NOT successfully created because request body is empty', function(done) { + this.timeout(100*DELAY); + request(url) .post('/admin/context/add') .set('Content-type','application/json') @@ -1134,6 +1197,8 @@ describe('1.3.Context', function() { it('1.3.7 should return a success response to indicate context was updated', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "id": contextID, "patches": [ @@ -1160,6 +1225,8 @@ describe('1.3.Context', function() { it('1.3.8 should return an error response to indicate context was NOT updated because context was not found', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "id": contextID + '66', "patches": [ @@ -1187,6 +1254,8 @@ describe('1.3.Context', function() { it('1.3.9 should return an error response to indicate context was NOT updated because patches are missing', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "id": Math.round(Math.random()*1000000)+100, "name": "new name" @@ -1208,6 +1277,8 @@ describe('1.3.Context', function() { it('1.3.10 should return an error response to indicate context was NOT updated because of missing request body', function(done) { + this.timeout(100*DELAY); + request(url) .post('/admin/context/update') .set('Content-type','application/json') @@ -1224,6 +1295,8 @@ describe('1.3.Context', function() { it('1.3.11 should return an error response to indicate context was NOT updated because patches is empty', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "id": Math.round(Math.random()*1000000)+100, "patches": [] @@ -1245,6 +1318,8 @@ describe('1.3.Context', function() { it('1.3.12 should return an error response to indicate context was NOT updated because of missing context id', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "name": "new name", "patches": [ @@ -1272,6 +1347,8 @@ describe('1.3.Context', function() { it('1.3.13 should return an error response to indicate context was NOT updated by another admin', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "id": contextID, "patches": [ @@ -1299,9 +1376,11 @@ describe('1.3.Context', function() { it('1.3.14 should return an error response to indicate context was NOT removed because of invalid context id', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "id": 1 - } + }; request(url) .post('/admin/context/remove') @@ -1319,6 +1398,8 @@ describe('1.3.Context', function() { it('1.3.15 should return an error indicating the requested context does NOT exist', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "id": Math.round(Math.random()*1000000)+100 }; @@ -1340,6 +1421,8 @@ describe('1.3.Context', function() { it('1.3.16 should return an error response to indicate context was NOT removed because of missing id from request body', function(done) { + this.timeout(100*DELAY); + request(url) .post('/admin/context/remove') .set('Content-type','application/json') @@ -1356,71 +1439,64 @@ describe('1.3.Context', function() { it('1.3.17 should return all contexts using the old API', function(done) { - this.timeout(9*DELAY); + this.timeout(100*DELAY); - setTimeout(function () { - - request(url) - .get('/admin/contexts') - .set('Content-type','application/json') - .set('Authorization', authValue) - .set('X-BLGREQ-APPID', appID) - .send() - .end(function(err, res) { + request(url) + .get('/admin/contexts') + .set('Content-type','application/json') + .set('Authorization', authValue) + .set('X-BLGREQ-APPID', appID) + .send() + .end(function(err, res) { - res.statusCode.should.be.equal(200); - res.body.content.should.have.length(1); - done(); - }); - }, 6*DELAY); + res.statusCode.should.be.equal(200); + res.body.content.should.have.length(1); + done(); + }); }); it('1.3.18 should return all contexts using the new API', function(done) { - this.timeout(9*DELAY); - - setTimeout(function () { + this.timeout(100*DELAY); - request(url) - .get('/admin/context/all') - .set('Content-type','application/json') - .set('Authorization', authValue) - .set('X-BLGREQ-APPID', appID) - .send() - .end(function(err, res) { + request(url) + .get('/admin/context/all') + .set('Content-type','application/json') + .set('Authorization', authValue) + .set('X-BLGREQ-APPID', appID) + .send() + .end(function(err, res) { - res.statusCode.should.be.equal(200); - res.body.content.should.have.length(1); - done(); - }); - }, 6*DELAY); + res.statusCode.should.be.equal(200); + res.body.content.should.have.length(1); + done(); + }); }); it('1.3.19 should NOT return all contexts using the old API because of invalid appID', function(done) { - this.timeout(9*DELAY); - - setTimeout(function () { + this.timeout(100*DELAY); - request(url) - .get('/admin/contexts') - .set('Content-type','application/json') - .set('Authorization', authValue) - .set('X-BLGREQ-APPID', appID + '66') - .send() - .end(function(err, res) { + request(url) + .get('/admin/contexts') + .set('Content-type','application/json') + .set('Authorization', authValue) + .set('X-BLGREQ-APPID', appID + '66') + .send() + .end(function(err, res) { - res.body.code.should.be.equal('011'); - res.statusCode.should.be.equal(404); - done(); - }); - }, 6*DELAY); + res.body.code.should.be.equal('011'); + res.statusCode.should.be.equal(404); + done(); + }); }); it('1.3.20 should return a success response to indicate context was removed', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "id": contextID + id: contextID }; request(url) @@ -1442,6 +1518,8 @@ describe('1.4.Schema', function() { it('1.4.1 should return a success response to indicate schema successfully updated', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "appId": appID, "schema": { @@ -1523,6 +1601,8 @@ describe('1.4.Schema', function() { it('1.4.2 should return an error response to indicate schema was NOT successfully updated because of appID', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "appId": "1", "schema": { @@ -1585,8 +1665,10 @@ describe('1.4.Schema', function() { it('1.4.3 should return an error response to indicate schema was NOT successfully updated because of missing schema object', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "appId": "1" + appId: "1" }; request(url) @@ -1605,6 +1687,8 @@ describe('1.4.Schema', function() { it('1.4.4 should return a success response to indicate schema was retrieved successfully using the old API', function(done) { + this.timeout(100*DELAY); + request(url) .get('/admin/schemas') .set('Content-type','application/json') @@ -1620,6 +1704,8 @@ describe('1.4.Schema', function() { it('1.4.5 should return a success response to indicate schema was retrieved successfully using the new API', function(done) { + this.timeout(100*DELAY); + request(url) .get('/admin/schema/all') .set('Content-type','application/json') @@ -1634,10 +1720,11 @@ describe('1.4.Schema', function() { }); it('1.4.6 should return a success response to indicate a model was removed from the application', function(done) { - this.timeout(12*DELAY); + + this.timeout(100*DELAY); var clientrequest = { - "model_name": "things" + model_name: "things" }; request(url) @@ -1655,8 +1742,10 @@ describe('1.4.Schema', function() { it('1.4.7 should return a error response to indicate a model was NOT removed from the application because of wrong appID', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model_name": "things" + model_name: "things" }; request(url) @@ -1675,8 +1764,10 @@ describe('1.4.Schema', function() { it('1.4.8 should return a error response to indicate a model was NOT removed from the application because model name does NOT exist', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model_name": "others" + model_name: "others" }; request(url) @@ -1695,8 +1786,10 @@ describe('1.4.Schema', function() { it('1.4.9 should return a error response to indicate a model was NOT removed from the application because model was missing from the request', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "something": "others" + something: "others" }; request(url) @@ -1715,8 +1808,10 @@ describe('1.4.Schema', function() { it('1.4.10 should return a error response to indicate a model was NOT removed from the application because of bad route', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "something": "others" + something: "others" }; request(url) @@ -1737,14 +1832,14 @@ describe('1.4.Schema', function() { describe('1.5.User', function() { var clientrequest = { - "email": userEmail, - "password": "secure_password1337", - "name": "John Smith" + email: userEmail, + password: "secure_password1337", + name: "John Smith" }; before(function(done){ - this.timeout(11*DELAY); + this.timeout(100*DELAY); request(url) .post('/user/register') @@ -1755,20 +1850,21 @@ describe('1.5.User', function() { .send(clientrequest) .end(function(err, res) { - setTimeout(done, 7*DELAY); + setTimeout(done, 20*DELAY); }); }); it('1.5.1 should return a success response to indicate that an user name was updated', function(done) { - this.timeout(12*DELAY); + + this.timeout(100*DELAY); var clientrequest = { - "email" : userEmail, - "patches": [ + email : userEmail, + patches: [ { - "op": "replace", - "path": "user/"+userEmail+"/name", - "value": "new value" + op: "replace", + path: "user/"+userEmail+"/name", + value: "new value" } ] }; @@ -1784,12 +1880,12 @@ describe('1.5.User', function() { .end(function(err, res) { res.statusCode.should.be.equal(200); - setTimeout(done, 8*DELAY); + done(); }); }); it('1.5.2 should return a success response to indicate that an user password was updated', function(done) { - this.timeout(12*DELAY); + this.timeout(100*DELAY); var clientrequest = { "email" : userEmail, @@ -1813,12 +1909,14 @@ describe('1.5.User', function() { .end(function(err, res) { res.statusCode.should.be.equal(200); - setTimeout(done, 8*DELAY); + done(); }); }); it('1.5.3 should return an error response to indicate that an user was NOT updated, user was missing from the request', function(done) { + this.timeout(100*DELAY); + request(url) .post('/admin/user/update') .set('Content-type','application/json') @@ -1837,6 +1935,8 @@ describe('1.5.User', function() { it('1.5.4 should return an error response to indicate that an user was NOT updated, user email address was missing from the request', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "user": { "name": "New Name" @@ -1861,6 +1961,8 @@ describe('1.5.User', function() { it('1.5.5 should return an error response to indicate that an user was NOT updated because patches is empty', function(done) { + this.timeout(100*DELAY); + var clientrequest = { "email" : userEmail, "patches": [] @@ -1884,7 +1986,7 @@ describe('1.5.User', function() { it('1.5.6 should return a success response indicating that a user has been deleted', function(done) { - this.timeout(40*DELAY); + this.timeout(100*DELAY); request(url) .post('/user/register') @@ -1910,19 +2012,19 @@ describe('1.5.User', function() { res.statusCode.should.be.equal(200); done(); }); - }, 2*DELAY); + }, 20*DELAY); }); }); it('1.5.7 should return a success response indicating that a user has NOT been deleted, user does not belong to application', function(done) { - this.timeout(24*DELAY); + this.timeout(100*DELAY); var userEmail = "user3@example.com"; var clientrequest = { - "email": userEmail, - "password": "secure_password1337", - "name": "John Smith" + email: userEmail, + password: "secure_password1337", + name: "John Smith" }; request(url) @@ -1957,15 +2059,17 @@ describe('1.5.User', function() { res.statusCode.should.be.equal(404); done(); }); - }, 16*DELAY); + }, 20*DELAY); }); }); it('1.5.8 should return a error response indicating that a user has NOT been deleted because of missing email address', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "password": "secure_password1337", - "name": "John Smith" + password: "secure_password1337", + name: "John Smith" }; request(url) @@ -1986,13 +2090,13 @@ describe('1.5.User', function() { it('1.5.9 should return an error response indicating that a user has NOT been deleted because of appID not found', function(done) { - this.timeout(40*DELAY); + this.timeout(100*DELAY); var userEmail = "user3@example.com"; var clientrequest = { - "email": userEmail, - "password": "secure_password1337", - "name": "John Smith" + email: userEmail, + password: "secure_password1337", + name: "John Smith" }; request(url) @@ -2013,13 +2117,15 @@ describe('1.5.User', function() { it('1.5.10 should return an error response to indicate that an user was NOT found when trying to update', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "email" : "wrong@example.com", - "patches": [ + email : "wrong@example.com", + patches: [ { - "op": "replace", - "path": "user/"+userEmail+"/name", - "value": "new value" + op: "replace", + path: "user/"+userEmail+"/name", + value: "new value" } ] }; @@ -2042,12 +2148,14 @@ describe('1.5.User', function() { it('1.5.11 should return an error response to indicate that the user email is missing', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "patches": [ + patches: [ { - "op": "replace", - "path": "user/"+userEmail+"/name", - "value": "new value" + op: "replace", + path: "user/"+userEmail+"/name", + value: "new value" } ] }; @@ -2070,6 +2178,8 @@ describe('1.5.User', function() { it('1.5.12 should return a success response to indicate that an admin list was retrieved', function(done) { + this.timeout(100*DELAY); + request(url) .post('/admin/users') .set('Content-type','application/json') @@ -2087,6 +2197,8 @@ describe('1.5.User', function() { it('1.5.13 should return a success response to indicate that an admin list was retrieved with pagination', function(done) { + this.timeout(100*DELAY); + var clientRequest = { page: 2 }; @@ -2108,6 +2220,8 @@ describe('1.5.User', function() { it('1.5.14 should return an error response to indicate that an admin list was NOT retrieved for a bad app id', function(done) { + this.timeout(100*DELAY); + request(url) .post('/admin/users') .set('Content-type','application/json') @@ -2129,6 +2243,8 @@ describe('1.5.User', function() { it('1.5.15 should return a success response to indicate that an users list was retrieved', function(done) { + this.timeout(100*DELAY); + request(url) .post('/admin/user/all') .set('Content-type','application/json') @@ -2149,6 +2265,8 @@ describe('1.5.User', function() { it('1.5.16 should return a success response to indicate that an users list was retrieved with pagination', function(done) { + this.timeout(100*DELAY); + var clientRequest = { page: 2 }; @@ -2173,6 +2291,8 @@ describe('1.5.User', function() { it('1.5.17 should return an error response to indicate that an users list was NOT retrieved for a bad app id', function(done) { + this.timeout(100*DELAY); + request(url) .post('/admin/user/all') .set('Content-type','application/json') diff --git a/test/context/context.js b/test/context/context.js index 6752ad9..93b10bb 100644 --- a/test/context/context.js +++ b/test/context/context.js @@ -11,9 +11,9 @@ var appID; var token; var clientrequest = { - 'email': 'user'+Math.round(Math.random()*1000000)+'@example.com', - 'password': 'secure_password1337', - 'name': 'John Smith' + email: 'user'+Math.round(Math.random()*1000000)+'@example.com', + password: 'secure_password1337', + name: 'John Smith' }; var adminEmail = 'admin'+Math.round(Math.random()*1000000)+'@example.com'; @@ -26,11 +26,11 @@ var admin = { before(function(done){ - this.timeout(25*DELAY); + this.timeout(100*DELAY); var clientrequest = { - "name": "test-app", - "keys": [ common.appKey ] + name: "test-app", + keys: [ common.appKey ] }; request(url) @@ -38,38 +38,35 @@ before(function(done){ .send(admin) .end(function(err, res) { - setTimeout(function () { - - request(url) - .post('/admin/login') - .set('Content-type','application/json') - .send(admin) - .end(function(err, res) { - - var token = res.body.content.token; - authValue = 'Bearer ' + token; - - request(url) - .post('/admin/app/add') - .set('Content-type','application/json') - .set('Authorization', authValue) - .send(clientrequest) - .end(function(err, res) { - appID = res.body.content.id; - done(); - }); - }); - }, 3*DELAY); + request(url) + .post('/admin/login') + .set('Content-type','application/json') + .send(admin) + .end(function(err, res) { + + var token = res.body.content.token; + authValue = 'Bearer ' + token; + + request(url) + .post('/admin/app/add') + .set('Content-type','application/json') + .set('Authorization', authValue) + .send(clientrequest) + .end(function(err, res) { + appID = res.body.content.id; + done(); + }); + }); }); }); before(function(done){ - this.timeout(10*DELAY); + this.timeout(100*DELAY); var clientrequest = { - "name": "context", - "meta": {"info": "some meta info"}, + name: "context", + meta: {info: "some meta info"}, }; request(url) @@ -87,8 +84,10 @@ before(function(done){ it('2.1 should return a success response to indicate context successfully retrieved', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "id": contextID + id: contextID }; request(url) @@ -108,6 +107,8 @@ it('2.1 should return a success response to indicate context successfully retrie it('2.2 should return an error response to indicate context was NOT successfully retrieved because of missing context ID', function(done) { + this.timeout(100*DELAY); + request(url) .post('/context') .set('Content-type','application/json') @@ -126,6 +127,8 @@ it('2.2 should return an error response to indicate context was NOT successfully it('2.3 should return an error response to indicate context NOT successfully retrieved because of bad context ID', function(done) { + this.timeout(100*DELAY); + var clientrequest = { id: Math.round(Math.random()*1000000)+1000 }; @@ -147,6 +150,8 @@ it('2.3 should return an error response to indicate context NOT successfully ret it('2.4 should return an error response to indicate context NOT successfully retrieved because of missing authorization', function(done) { + this.timeout(100*DELAY); + var clientrequest = { id: contextID }; @@ -167,6 +172,8 @@ it('2.4 should return an error response to indicate context NOT successfully ret it('2.5 should return an error response to indicate context NOT successfully retrieved because of bad authorization', function(done) { + this.timeout(100*DELAY); + var clientrequest = { id: contextID }; @@ -188,6 +195,8 @@ it('2.5 should return an error response to indicate context NOT successfully ret it('2.6 should return a success response to indicate all contexts successfully retrieved', function(done) { + this.timeout(100*DELAY); + request(url) .get('/context/all') .set('Content-type','application/json') diff --git a/test/device/device.js b/test/device/device.js index d36806a..6dc69d0 100644 --- a/test/device/device.js +++ b/test/device/device.js @@ -21,7 +21,7 @@ var deviceIdentifier; before(function(done){ - this.timeout(25*DELAY); + this.timeout(100*DELAY); var clientrequest = { name: "test-app", @@ -33,34 +33,33 @@ before(function(done){ .send(admin) .end(function(err, res) { - setTimeout(function () { - - request(url) - .post('/admin/login') - .set('Content-type','application/json') - .send(admin) - .end(function(err, res) { - - var token = res.body.content.token; - authValue = 'Bearer ' + token; - - request(url) - .post('/admin/app/add') - .set('Content-type','application/json') - .set('Authorization', authValue) - .send(clientrequest) - .end(function(err, res) { - - appID = res.body.content.id; - done(); - }); - }); - }, 3*DELAY); + request(url) + .post('/admin/login') + .set('Content-type','application/json') + .send(admin) + .end(function(err, res) { + + var token = res.body.content.token; + authValue = 'Bearer ' + token; + + request(url) + .post('/admin/app/add') + .set('Content-type','application/json') + .set('Authorization', authValue) + .send(clientrequest) + .end(function(err, res) { + + appID = res.body.content.id; + done(); + }); + }); }); }); it('3.1 should return a success response to indicate device successfully registered', function(done) { + this.timeout(100*DELAY); + var clientRequest = { info: { os: "Android", @@ -92,6 +91,8 @@ it('3.1 should return a success response to indicate device successfully registe it('3.2 should return a success response to indicate device successfully registered with random UDID', function(done) { + this.timeout(100*DELAY); + var clientRequest = { info: { os: "Android", @@ -123,6 +124,8 @@ it('3.2 should return a success response to indicate device successfully registe it('3.3 should return a success response to indicate device successfully updated', function(done) { + this.timeout(100*DELAY); + var clientRequest = { info: { os: "Android", @@ -152,6 +155,8 @@ it('3.3 should return a success response to indicate device successfully updated it('3.4 should return an error response to indicate device successfully registered, uuid missing from request', function(done) { + this.timeout(100*DELAY); + var clientRequest = { info: { os: "Android", @@ -181,6 +186,8 @@ it('3.4 should return an error response to indicate device successfully register it('3.5 should return an error response to indicate device NOT successfully registered because of missing info', function(done) { + this.timeout(100*DELAY); + var clientRequest = { persistent: { type: "android", @@ -204,6 +211,8 @@ it('3.5 should return an error response to indicate device NOT successfully regi it('3.6 should return an error response to indicate device NOT successfully registered because of missing body', function(done) { + this.timeout(100*DELAY); + request(url) .post('/device/register') .set('X-BLGREQ-SIGN', appIDsha256) @@ -220,6 +229,8 @@ it('3.6 should return an error response to indicate device NOT successfully regi it('3.7 should return an error response to indicate device NOT successfully registered because of missing body and invalidUDID', function(done) { + this.timeout(100*DELAY); + request(url) .post('/device/register') .set('X-BLGREQ-SIGN', appIDsha256) @@ -236,6 +247,8 @@ it('3.7 should return an error response to indicate device NOT successfully regi it('3.8 should return an error response to indicate device NOT successfully registered because of invalid UDID', function(done) { + this.timeout(100*DELAY); + var clientRequest = { info: { os: "Android", diff --git a/test/object/object.js b/test/object/object.js index b2da0b4..5170cb3 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -15,42 +15,42 @@ var contextID; var appKey = common.appKey; var subclientrequest = { - "channel": { - "id": 1, - "context": 1, - "model": "comments", - "parent": { - "id": 1, - "model": "events" + channel: { + id: 1, + context: 1, + model: "comments", + parent: { + id: 1, + model: "events" }, - "user": 2 + user: 2 }, - "filters": { - "or": [ + filters: { + or: [ { - "and": [ + and: [ { - "is": { - "gender": "male", - "age": 23 + is: { + gender: "male", + age: 23 } }, { - "range": { - "experience": { - "gte": 1, - "lte": 6 + range: { + experience: { + gte: 1, + lte: 6 } } } ] }, { - "and": [ + and: [ { - "like": { - "image_url": "png", - "website": "png" + like: { + image_url: "png", + website: "png" } } ] @@ -71,7 +71,7 @@ var contextID2; before(function(done){ - this.timeout(25*DELAY); + this.timeout(100*DELAY); var clientRequest = { name: "test-app", @@ -83,9 +83,7 @@ before(function(done){ .send(admin) .end(function(err, res) { - setTimeout(function () { - - request(url) + request(url) .post('/admin/login') .set('Content-type','application/json') .send(admin) @@ -103,107 +101,107 @@ before(function(done){ appID = res.body.content.id; var clientrequest = { - "appId": appID, - "schema": { - "answers": { - "namespace": "answers", - "type": "answers", - "properties": {}, - "belongsTo": [ + appId: appID, + schema: { + answers: { + namespace: "answers", + type: "answers", + properties: {}, + belongsTo: [ { - "parentModel": "events", - "relationType": "hasSome" + parentModel: "events", + relationType: "hasSome" } ], - "read_acl": 6, - "write_acl": 6, - "meta_read_acl": 6 + read_acl: 6, + write_acl: 6, + meta_read_acl: 6 }, - "comments": { - "namespace": "comments", - "type": "comments", - "properties": { - "text": { - "type": "string" + comments: { + namespace: "comments", + type: "comments", + properties: { + text: { + type: "string" } }, - "belongsTo": [ + belongsTo: [ { - "parentModel": "events", - "relationType": "hasMany" + parentModel: "events", + relationType: "hasMany" } ], - "read_acl": 6, - "write_acl": 6, - "meta_read_acl": 6 + read_acl: 6, + write_acl: 6, + meta_read_acl: 6 }, - "events": { - "namespace": "events", - "type": "events", - "properties": { - "text": { - "type": "string" + events: { + namespace: "events", + type: "events", + properties: { + text: { + type: "string" }, - "image": { - "type": "string" + image: { + type: "string" }, - "options": { - "type": "object" + options: { + type: "object" } }, - "hasMany": [ + hasMany: [ "comments" ], - "hasSome": [ + hasSome: [ "answers" ], - "read_acl": 7, - "write_acl": 7, - "meta_read_acl": 4, - "icon": "fa-image", - "hasSome_property": "options" + read_acl: 7, + write_acl: 7, + meta_read_acl: 4, + icon: "fa-image", + hasSome_property: "options" }, - "things": { - "namespace": "events", - "type": "events", - "properties": { - "text": { - "type": "string" + things: { + namespace: "events", + type: "events", + properties: { + text: { + type: "string" }, - "image": { - "type": "string" + image: { + type: "string" }, - "options": { + options: { "type": "object" } }, - "hasMany": [ + hasMany: [ "comments" ], - "read_acl": 0, - "write_acl": 0, - "meta_read_acl": 0 + read_acl: 0, + write_acl: 0, + meta_read_acl: 0 }, - "others": { - "namespace": "events", - "type": "events", - "properties": { - "text": { - "type": "string" + others: { + namespace: "events", + type: "events", + properties: { + text: { + type: "string" }, - "image": { - "type": "string" + image: { + type: "string" }, - "options": { - "type": "object" + options: { + type: "object" } }, - "hasMany": [ + hasMany: [ "comments" ], - "read_acl": 4, - "write_acl": 4, - "meta_read_acl": 4 + read_acl: 4, + write_acl: 4, + meta_read_acl: 4 } } }; @@ -217,7 +215,7 @@ before(function(done){ .end(function(err, res) { var clientrequest = { - "name": "context" + name: "context" }; request(url) @@ -262,26 +260,25 @@ before(function(done){ }); }); }); - }, 3*DELAY); }); }); before(function(done){ - this.timeout(25*DELAY); + this.timeout(100*DELAY); var clientrequest = { info: { os: "Android", - "version": "4.4.3", - "sdk_level": 19, - "manufacturer": "HTC", - "model": "HTC One_M8", - "udid": invalidUDID + version: "4.4.3", + sdk_level: 19, + manufacturer: "HTC", + model: "HTC One_M8", + udid: invalidUDID }, - "persistent": { - "type": "android", - "token": "android pn token" + persistent: { + type: "android", + token: "android pn token" } }; @@ -295,9 +292,9 @@ before(function(done){ deviceIdentification = res.body.content.identifier; var clientrequest = { - "email": 'user'+Math.round(Math.random()*1000000)+'@example.com', - "password": "secure_password1337", - "name": "John Smith" + email: 'user'+Math.round(Math.random()*1000000)+'@example.com', + password: "secure_password1337", + name: "John Smith" }; request(url) @@ -324,14 +321,14 @@ before(function(done){ userAuthValue = 'Bearer ' + token; done(); }); - }, 14*DELAY); + }, 20*DELAY); }); }); }); it('4.1 should return an error (400) response to indicate that request body is empty', function(done) { - this.timeout(10*DELAY); + this.timeout(100*DELAY); request(url) .post('/object/create') @@ -350,10 +347,12 @@ it('4.1 should return an error (400) response to indicate that request body is e it('4.2 should return an error (401) response to indicate that only authenticated users may access this endpoint', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model": "something", - "context": contextID, - "content": { + model: "something", + context: contextID, + content: { } }; @@ -373,10 +372,12 @@ it('4.2 should return an error (401) response to indicate that only authenticate it('4.3 should return a error response to indicate that a object has NOT been created', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { - "context": contextID, - "model": "answers", - "content": { + context: contextID, + model: "answers", + content: { events_id: -1 } }; @@ -400,11 +401,13 @@ it('4.3 should return a error response to indicate that a object has NOT been cr it('4.4 should return a success response to indicate that object has been created', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model": "comments", - "context": contextID, - "content": { - "events_id" :1 + model: "comments", + context: contextID, + content: { + events_id :1 } }; @@ -425,11 +428,13 @@ it('4.4 should return a success response to indicate that object has been create it('4.5 should return a success response to indicate that object has NOT been created because of ACL', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model": "others", - "context": contextID, - "content": { - "events_id" :1 + model: "others", + context: contextID, + content: { + events_id :1 } }; @@ -450,11 +455,13 @@ it('4.5 should return a success response to indicate that object has NOT been cr it('4.6 should return a success response to indicate that object has NOT been created because of ACL', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model": "things", - "context": contextID, - "content": { - "events_id" :1 + model: "things", + context: contextID, + content: { + events_id: 1 } }; @@ -475,11 +482,13 @@ it('4.6 should return a success response to indicate that object has NOT been cr it('4.7 should return a success response to indicate that object has been created by an admin', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model": "comments", - "context": contextID, - "content": { - "events_id" :1 + model: "comments", + context: contextID, + content: { + events_id: 1 } }; @@ -500,11 +509,13 @@ it('4.7 should return a success response to indicate that object has been create it('4.8 should return an error response to indicate that object has NOT been created because of missing authentication', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model": "comments", - "context": contextID, - "content": { - "events_id" :1, + model: "comments", + context: contextID, + content: { + events_id: 1 } }; @@ -524,10 +535,12 @@ it('4.8 should return an error response to indicate that object has NOT been cre it('4.9 should return an error response to indicate that object has NOT been created because of missing model in request body', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "context": contextID, - "content": { - "events_id" :1, + context: contextID, + content: { + events_id :1 } }; @@ -548,9 +561,11 @@ it('4.9 should return an error response to indicate that object has NOT been cre it('4.10 should return an error response to indicate that object has NOT been created because content is missing', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "context": contextID, - "model": "comments", + context: contextID, + model: "comments" }; request(url) @@ -570,10 +585,12 @@ it('4.10 should return an error response to indicate that object has NOT been cr it('4.11 should return an error response to indicate that object has NOT been created because content is empty', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "context": contextID, - "model": "comments", - "content": {} + context: contextID, + model: "comments", + content: {} }; request(url) @@ -593,11 +610,13 @@ it('4.11 should return an error response to indicate that object has NOT been cr it('4.12 should return an error response to indicate that object has NOT been created because of invalid parent', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "context": contextID, - "model": "comments", - "content": { - "event_id" :1, + context: contextID, + model: "comments", + content: { + event_id: 1 } }; @@ -618,11 +637,13 @@ it('4.12 should return an error response to indicate that object has NOT been cr it('4.13 should return an error response to indicate that object has NOT been created because of model does not exist', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "context": contextID, - "model": "something", - "content": { - "events_id" :1, + context: contextID, + model: "something", + content: { + events_id: 1 } }; @@ -643,10 +664,12 @@ it('4.13 should return an error response to indicate that object has NOT been cr it('4.14 should return an error response to indicate that object has NOT been created because of missing context', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model": "comments", - "content": { - "events_id" :1, + model: "comments", + content: { + events_id: 1 } }; @@ -667,10 +690,12 @@ it('4.14 should return an error response to indicate that object has NOT been cr it('4.15 should return an error response to indicate that object has NOT been created because of invalid appID', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model": "comments", - "content": { - "events_id" :1, + model: "comments", + content: { + events_id: 1 } }; @@ -691,10 +716,12 @@ it('4.15 should return an error response to indicate that object has NOT been cr it('4.16 should return a success response to indicate the count of a certain filter/subscription', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "channel": { - "context": contextID, - "model": "comments" + channel: { + context: contextID, + model: "comments" } }; @@ -714,12 +741,14 @@ it('4.16 should return a success response to indicate the count of a certain fil it('4.17 should return an error response because of invalid channel request', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "channel": { - "context": contextID, - "model": "comments", - "parent": "parent", - "user": "user" + channel: { + context: contextID, + model: "comments", + parent: "parent", + user: "user" }, filters: {} }; @@ -741,6 +770,8 @@ it('4.17 should return an error response because of invalid channel request', fu it('4.18 should return an error response to indicate the count was not returned because of empty request', function(done) { + this.timeout(100*DELAY); + request(url) .post('/object/count') .set('X-BLGREQ-SIGN', appIDsha256) @@ -760,15 +791,17 @@ it('4.18 should return an error response to indicate the count was not returned it('4.19 should return a success response to indicate that a object has been updated', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model": "comments", - "id": 1, - "context": contextID, - "patches": [ + model: "comments", + id: 1, + context: contextID, + patches: [ { - "op": "replace", - "path": "comments/1/text", - "value": "some edited text" + op: "replace", + path: "comments/1/text", + value: "some edited text" } ] }; @@ -789,15 +822,17 @@ it('4.19 should return a success response to indicate that a object has been upd it('4.20 should return a success response to indicate that a object has NOT been updated because of bad authentication', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model": "comments", - "id": 1, - "context": contextID, - "patches": [ + model: "comments", + id: 1, + context: contextID, + patches: [ { - "op": "replace", - "path": "comments/1/text", - "value": "some edited text" + op: "replace", + path: "comments/1/text", + value: "some edited text" } ] }; @@ -819,16 +854,18 @@ it('4.20 should return a success response to indicate that a object has NOT been it('4.21 should return a success response to indicate that a object has NOT been updated because of missing authorization', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model": "comments", - "id": 1, - "context": contextID, - "patches": [ + model: "comments", + id: 1, + context: contextID, + patches: [ { - "op": "replace", - "path": "comments/1/text", - "value": "some edited text" - }, + op: "replace", + path: "comments/1/text", + value: "some edited text" + } ] }; @@ -848,15 +885,17 @@ it('4.21 should return a success response to indicate that a object has NOT been it('4.22 should return an error response to indicate that a object has NOT been updated because of missing id', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model": "comments", - "context": contextID, - "patches": [ + model: "comments", + context: contextID, + patches: [ { - "op": "replace", - "path": "comments/1/text", - "value": "some edited text" - }, + op: "replace", + path: "comments/1/text", + value: "some edited text" + } ], }; @@ -877,16 +916,18 @@ it('4.22 should return an error response to indicate that a object has NOT been it('4.23 should return a success response to indicate that a object has NOT been updated because of missing context ', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model": "comments", - "id": 1, - "patches": [ + model: "comments", + id: 1, + patches: [ { - "op": "replace", - "path": "comments/1/text", - "value": "some edited text" - }, - ], + op: "replace", + path: "comments/1/text", + value: "some edited text" + } + ] }; request(url) @@ -906,16 +947,18 @@ it('4.23 should return a success response to indicate that a object has NOT been it('4.24 should return an error response to indicate that a object has NOT been updated because of model not found ', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model": "thingy", - "id": 1, - "patches": [ + model: "thingy", + id: 1, + patches: [ { - "op": "replace", - "path": "thingy/1/text", - "value": "some edited text" - }, - ], + op: "replace", + path: "thingy/1/text", + value: "some edited text" + } + ] }; request(url) @@ -935,16 +978,18 @@ it('4.24 should return an error response to indicate that a object has NOT been it('4.25 should return a success response to indicate that a object has NOT been updated because of missing model ', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "context": contextID, - "id": 1, - "patches": [ + context: contextID, + id: 1, + patches: [ { - "op": "replace", - "path": "comments/1/text", - "value": "some edited text" - }, - ], + op: "replace", + path: "comments/1/text", + value: "some edited text" + } + ] }; request(url) @@ -964,11 +1009,13 @@ it('4.25 should return a success response to indicate that a object has NOT been it('4.26 should return a success response to indicate that a object has NOT been updated because patches is not an array ', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "context": contextID, - "model": "comments", - "id": 1, - "patches": {}, + context: contextID, + model: "comments", + id: 1, + patches: {} }; request(url) @@ -988,11 +1035,13 @@ it('4.26 should return a success response to indicate that a object has NOT been it('4.27 should return a success response to indicate that a object has NOT been updated because patches is an empty array', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "context": contextID, - "model": "comments", - "id": 1, - "patches": [], + context: contextID, + model: "comments", + id: 1, + patches: [] }; request(url) @@ -1012,6 +1061,8 @@ it('4.27 should return a success response to indicate that a object has NOT been it('4.28 should return a success response to indicate that a object has NOT been updated because of empty request ', function(done) { + this.timeout(100*DELAY); + request(url) .post('/object/update') .set('X-BLGREQ-SIGN', appIDsha256) @@ -1030,10 +1081,12 @@ it('4.28 should return a success response to indicate that a object has NOT been it('4.29 should return a success response to indicate that a object has been subscribed', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { - "channel": { - "context": contextID, - "model": "comments" + channel: { + context: contextID, + model: "comments" } }; @@ -1054,11 +1107,13 @@ it('4.29 should return a success response to indicate that a object has been sub it('4.30 should return a success response to indicate that a object has been subscribed with pagination', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { page: 2, - "channel": { - "context": contextID, - "model": "comments" + channel: { + context: contextID, + model: "comments" } }; @@ -1079,10 +1134,12 @@ it('4.30 should return a success response to indicate that a object has been sub it('4.31 should return a success response to indicate that a object has NOT been subscribed because context does not belong to application', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { - "channel": { - "context": contextID2, - "model": "comments" + channel: { + context: contextID2, + model: "comments" } }; @@ -1104,10 +1161,12 @@ it('4.31 should return a success response to indicate that a object has NOT been it('4.32 should return an error response to indicate that a object has NOT been subscribed because of invalid authorization', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { - "channel": { - "context": contextID, - "model": "comments" + channel: { + context: contextID, + model: "comments" } }; var userAuthValue = 'Bearer '; @@ -1129,37 +1188,39 @@ it('4.32 should return an error response to indicate that a object has NOT been it('4.33 should return an error response to indicate that a object has been NOT subscribed because of filters', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { - "channel": { - "context": contextID, - "model": "events" + channel: { + context: contextID, + model: "events" }, - "filters": { - "or": [ + filters: { + or: [ { - "and": [ + and: [ { - "is": { - "gender": "male", - "age": 23 + is: { + gender: "male", + age: 23 } }, { - "range": { - "experience": { - "gte": 1, - "lte": 6 + range: { + experience: { + gte: 1, + lte: 6 } } } ] }, { - "and": [ + and: [ { - "like": { - "image_url": "png", - "website": "png" + like: { + image_url: "png", + website: "png" } } ] @@ -1186,11 +1247,13 @@ it('4.33 should return an error response to indicate that a object has been NOT it('4.34 should return an error response to indicate that a object has NOT been subscribed because of invalid context', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { - "channel": { - "context": Math.round(Math.random()*1000000), - "model": "comments" - }, + channel: { + context: Math.round(Math.random()*1000000), + model: "comments" + } }; request(url) @@ -1211,9 +1274,11 @@ it('4.34 should return an error response to indicate that a object has NOT been it('4.35 should return an error response to indicate that a object has NOT been subscribed because no schema is defined', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "name": "test-app", - "keys": [ appKey ] + name: "test-app", + keys: [ appKey ] }; request(url) @@ -1226,10 +1291,10 @@ it('4.35 should return an error response to indicate that a object has NOT been var appID2 = res.body.content.id; var subclientrequest = { - "channel": { - "context": contextID, - "model": "comments" - }, + channel: { + context: contextID, + model: "comments" + } }; request(url) @@ -1251,9 +1316,11 @@ it('4.35 should return an error response to indicate that a object has NOT been it('4.36 should return an error response to indicate that a object has NOT been subscribed because context does not belong to app', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "name": "test-app", - "keys": [ appKey ] + name: "test-app", + keys: [ appKey ] }; request(url) @@ -1266,67 +1333,67 @@ it('4.36 should return an error response to indicate that a object has NOT been var appID2 = res.body.content.id; var clientrequest = { - "appId": appID, - "schema": { - "comments": { - "namespace": "comments", - "type": "comments", - "properties": { - "text": { - "type": "string" + appId: appID, + schema: { + comments: { + namespace: "comments", + type: "comments", + properties: { + text: { + type: "string" } }, - "belongsTo": [ + belongsTo: [ { - "parentModel": "events", - "relationType": "hasMany" + parentModel: "events", + relationType: "hasMany" } ], - "read_acl": 6, - "write_acl": 6, - "meta_read_acl": 6 + read_acl: 6, + write_acl: 6, + meta_read_acl: 6 }, - "events": { - "namespace": "events", - "type": "events", - "properties": { - "text": { - "type": "string" + events: { + namespace: "events", + type: "events", + properties: { + text: { + type: "string" }, - "image": { - "type": "string" + image: { + type: "string" }, - "options": { - "type": "object" + options: { + type: "object" } }, - "hasMany": [ + hasMany: [ "comments" ], - "read_acl": 7, - "write_acl": 7, - "meta_read_acl": 4 + read_acl: 7, + write_acl: 7, + meta_read_acl: 4 }, - "things": { - "namespace": "events", - "type": "events", - "properties": { - "text": { - "type": "string" + things: { + namespace: "events", + type: "events", + properties: { + text: { + type: "string" }, - "image": { - "type": "string" + image: { + type: "string" }, - "options": { - "type": "object" + options: { + type: "object" } }, - "hasMany": [ + hasMany: [ "comments" ], - "read_acl": 7, - "write_acl": 7, - "meta_read_acl": 4 + read_acl: 7, + write_acl: 7, + meta_read_acl: 4 } } }; @@ -1340,10 +1407,10 @@ it('4.36 should return an error response to indicate that a object has NOT been .end(function(err, res) { var subclientrequest = { - "channel": { - "context": contextID, - "model": "comments" - }, + channel: { + context: contextID, + model: "comments" + } }; request(url) @@ -1367,12 +1434,14 @@ it('4.36 should return an error response to indicate that a object has NOT been it('4.37 should return a success response to indicate that a object has NOT been subscribed because of invalid channel', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { - "channel": { - "context": contextID, - "model": "comments", - "parent": "parent", - "user": "user" + channel: { + context: contextID, + model: "comments", + parent: "parent", + user: "user" } }; @@ -1394,11 +1463,13 @@ it('4.37 should return a success response to indicate that a object has NOT been it('4.38 should return an error response to indicate that a object has NOT been subscribed because object was not found', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { - "channel": { - "context": contextID, - "model": "comments", - "id" : "66" + channel: { + context: contextID, + model: "comments", + id : "66" } }; @@ -1420,6 +1491,8 @@ it('4.38 should return an error response to indicate that a object has NOT been it('4.39 should return an error response to indicate that a object has NOT been subscribed because of empty body', function(done) { + this.timeout(100*DELAY); + request(url) .post('/object/subscribe') .set('Content-type','application/json') @@ -1438,9 +1511,11 @@ it('4.39 should return an error response to indicate that a object has NOT been it('4.40 should return a success response to indicate that a object has NOT been subscribed because of missing context', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { - "channel": { - "model": "comments" + channel: { + model: "comments" } }; @@ -1462,9 +1537,11 @@ it('4.40 should return a success response to indicate that a object has NOT been it('4.41 should return a success response to indicate that a object has NOT been subscribed because of missing model', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { - "channel": { - "context": contextID + channel: { + context: contextID } }; @@ -1486,10 +1563,12 @@ it('4.41 should return a success response to indicate that a object has NOT been it('4.42 should return a success response to indicate that a object has NOT been subscribed because of model not found', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { - "channel": { - "context": contextID, - "model": "somethings" + channel: { + context: contextID, + model: "somethings" } }; @@ -1511,33 +1590,35 @@ it('4.42 should return a success response to indicate that a object has NOT been it('4.43 should return an error response to indicate that a object has NOT been subscribed because of missing channel', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { - "filters": { - "or": [ + filters: { + or: [ { - "and": [ + and: [ { - "is": { - "gender": "male", - "age": 23 + is: { + gender: "male", + age: 23 } }, { - "range": { - "experience": { - "gte": 1, - "lte": 6 + range: { + experience: { + gte: 1, + lte: 6 } } } ] }, { - "and": [ + and: [ { - "like": { - "image_url": "png", - "website": "png" + like: { + image_url: "png", + website: "png" } } ] @@ -1564,10 +1645,12 @@ it('4.43 should return an error response to indicate that a object has NOT been it('4.44 should return an success response to indicate that a object has been unsubscribed', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { - "channel": { - "context": contextID, - "model": "comments" + channel: { + context: contextID, + model: "comments" } }; @@ -1587,6 +1670,8 @@ it('4.44 should return an success response to indicate that a object has been un it('4.45 should return an error response to indicate that a object has NOT been unsubscribed because of empty body', function(done) { + this.timeout(100*DELAY); + request(url) .post('/object/unsubscribe') .set('X-BLGREQ-SIGN', appIDsha256) @@ -1604,12 +1689,14 @@ it('4.45 should return an error response to indicate that a object has NOT been it('4.46 should return a error response (400) to indicate that a object has NOT been unsubscribed', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { - "channel": { - "context": contextID, - "model": "comments", - "parent": "parent", - "user": "user" + channel: { + context: contextID, + model: "comments", + parent: "parent", + user: "user" } }; @@ -1631,13 +1718,13 @@ it('4.46 should return a error response (400) to indicate that a object has NOT it('4.47 should return a error response (404) to indicate that a object has NOT been unsubscribed', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { - "channel": { - "context": contextID, - "model": "comments", - "id" : '66', - "parent": "parent", - "user": "user" + channel: { + context: contextID, + model: "comments", + id : '66654654646546546546546546546546546546546' } }; @@ -1651,45 +1738,47 @@ it('4.47 should return a error response (404) to indicate that a object has NOT .send(subclientrequest) .end(function(err, res) { - res.body.code.should.be.equal('037'); res.statusCode.should.be.equal(404); + res.body.code.should.be.equal('037'); done(); }); }); it('4.48 should return a error response (404) to indicate that a object has NOT been unsubscribed, using filters', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { - "channel": { - "context": contextID, - "model": "comments" + channel: { + context: contextID, + model: "comments" }, - "filters": { - "or": [ + filters: { + or: [ { - "and": [ + and: [ { - "is": { - "gender": "male", - "age": 23 + is: { + gender: "male", + age: 23 } }, { - "range": { - "experience": { - "gte": 1, - "lte": 6 + range: { + experience: { + gte: 1, + lte: 6 } } } ] }, { - "and": [ + and: [ { - "like": { - "image_url": "png", - "website": "png" + like: { + image_url: "png", + website: "png" } } ] @@ -1717,8 +1806,10 @@ it('4.48 should return a error response (404) to indicate that a object has NOT it('4.49 should return a success response to indicate that a object has NOT been unsubscribed because of missing channel', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { - "something": {} + something: {} }; request(url) @@ -1738,10 +1829,12 @@ it('4.49 should return a success response to indicate that a object has NOT been it('4.50 should return a success response to indicate that a object has NOT been unsubscribed because of missing context', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { - "channel": { - "model": "comments", - "id" : "66" + channel: { + model: "comments", + id : "66" } }; @@ -1762,9 +1855,11 @@ it('4.50 should return a success response to indicate that a object has NOT been it('4.51 should return a success response to indicate that a object has NOT been unsubscribed because of missing model', function(done) { + this.timeout(100*DELAY); + var subclientrequest = { - "channel": { - "context": contextID + channel: { + context: contextID } }; @@ -1785,10 +1880,12 @@ it('4.51 should return a success response to indicate that a object has NOT been it('4.52 should return a success response to indicate that a object has been deleted', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model": "comments", - "context": contextID, - "id" : 1, + model: "comments", + context: contextID, + id : 1 }; request(url) @@ -1807,39 +1904,38 @@ it('4.52 should return a success response to indicate that a object has been del it('4.53 should return an error response to indicate that a object was NOT deleted', function(done) { - this.timeout(20*DELAY); - - setTimeout(function() { + this.timeout(100*DELAY); - var clientrequest = { - "model": "comments", - "context": 1, - "id" : 1, - }; + var clientrequest = { + model: "comments", + context: 1, + id : 1 + }; - request(url) - .post('/object/delete') - .set('X-BLGREQ-SIGN', appIDsha256) - .set('X-BLGREQ-UDID', deviceIdentification) - .set('X-BLGREQ-APPID',1) - .set('Authorization', authValue ) - .send(clientrequest) - .end(function(err, res) { + request(url) + .post('/object/delete') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', deviceIdentification) + .set('X-BLGREQ-APPID',1) + .set('Authorization', authValue ) + .send(clientrequest) + .end(function(err, res) { - res.body.code.should.be.equal('011'); - res.statusCode.should.be.equal(404); - done(); - }); - }, 14*DELAY); + res.body.code.should.be.equal('011'); + res.statusCode.should.be.equal(404); + done(); + }); }); it('4.54 should return an error response to indicate that the object id was missing', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model": "comments", - "context": contextID, - "content": {} + model: "comments", + context: contextID, + content: {} }; request(url) @@ -1859,10 +1955,12 @@ it('4.54 should return an error response to indicate that the object id was miss it('4.55 should return an error response to indicate that the object model was missing', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "context": contextID, - "id" : 1, - "content": {} + context: contextID, + id : 1, + content: {} }; request(url) @@ -1882,11 +1980,13 @@ it('4.55 should return an error response to indicate that the object model was m it('4.56 should return an error response to indicate that the object was not deleted because of missing authentication', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model": "comments", - "context": contextID, - "id" : 1, - "content": {} + model: "comments", + context: contextID, + id : 1, + content: {} }; request(url) @@ -1905,10 +2005,12 @@ it('4.56 should return an error response to indicate that the object was not del it('4.57 should return an error response to indicate that the object was not deleted because of missing context', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "model": "comments", - "id" : 1, - "content": {} + model: "comments", + id: 1, + content: {} }; request(url) @@ -1928,6 +2030,8 @@ it('4.57 should return an error response to indicate that the object was not del it('4.58 should return an error response to indicate that the object was not deleted because of empty request', function(done) { + this.timeout(100*DELAY); + request(url) .post('/object/delete') .set('X-BLGREQ-SIGN', appIDsha256) diff --git a/test/user/user.js b/test/user/user.js index 2028858..174255d 100644 --- a/test/user/user.js +++ b/test/user/user.js @@ -26,71 +26,71 @@ var admin = { before(function(done){ - this.timeout(25*DELAY); + this.timeout(100*DELAY); var deviceRegisterRequest = { - "info": { - "os": "Android", - "version": "4.4.3", - "sdk_level": 19, - "manufacturer": "HTC", - "model": "HTC One_M8", - "udid": invalidUDID + info: { + os: "Android", + version: "4.4.3", + sdk_level: 19, + manufacturer: "HTC", + model: "HTC One_M8", + udid: invalidUDID }, - "persistent": { - "type": "android", - "token": "android pn token" + persistent: { + type: "android", + token: "android pn token" } }; var appRequest = { - "name": "test-app", - "keys": [ common.appKey ] + name: "test-app", + keys: [ common.appKey ] }; request(url) .post('/admin/add') .send(admin) .end(function(err, res) { - setTimeout(function () { - request(url) - .post('/admin/login') - .set('Content-type','application/json') - .send(admin) - .end(function(err, res) { + request(url) + .post('/admin/login') + .set('Content-type','application/json') + .send(admin) + .end(function(err, res) { - var token = res.body.content.token; - adminAuthValue = 'Bearer ' + token; + var token = res.body.content.token; + adminAuthValue = 'Bearer ' + token; - request(url) - .post('/admin/app/add') - .set('Content-type','application/json') - .set('Authorization', adminAuthValue) - .send(appRequest) - .end(function(err, res) { + request(url) + .post('/admin/app/add') + .set('Content-type','application/json') + .set('Authorization', adminAuthValue) + .send(appRequest) + .end(function(err, res) { - appID = res.body.content.id; + appID = res.body.content.id; - request(url) - .post('/device/register') - .set('X-BLGREQ-SIGN', appIDsha256) - .set('X-BLGREQ-UDID', '') - .set('X-BLGREQ-APPID',appID) - .send(deviceRegisterRequest) - .end(function(err, res) { + request(url) + .post('/device/register') + .set('X-BLGREQ-SIGN', appIDsha256) + .set('X-BLGREQ-UDID', '') + .set('X-BLGREQ-APPID',appID) + .send(deviceRegisterRequest) + .end(function(err, res) { - deviceIdentification = res.body.content.identifier; - done(); - }); - }); - }); - }, 4*DELAY); + deviceIdentification = res.body.content.identifier; + done(); + }); + }); + }); }); }); it('5.1 should return an error response to indicate that the user has NOT logged via Facebook because request body is empty', function(done) { + this.timeout(100*DELAY); + request(url) .post('/user/login') .set('Content-type','application/json') @@ -108,8 +108,10 @@ it('5.1 should return an error response to indicate that the user has NOT logged it('5.2 should return an error response to indicate that the user has NOT logged via Facebook because of missing access token', function(done) { + this.timeout(100*DELAY); + var clientRequest = { - "something_else": "invalidToken" + something_else: "invalidToken" }; request(url) @@ -129,8 +131,10 @@ it('5.2 should return an error response to indicate that the user has NOT logged it('5.3 should return an error response to indicate that the user has NOT logged via Facebook because of invalid token', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "access_token": "invalidToken" + access_token: "invalidToken" }; request(url) @@ -150,12 +154,12 @@ it('5.3 should return an error response to indicate that the user has NOT logged it('5.4 should return a success response to indicate that the user has logged in via user & password', function(done) { - this.timeout(13*DELAY); + this.timeout(100*DELAY); var clientrequest = { - "email": userEmail, - "password": "secure_password1337", - "name": "John Smith" + email: userEmail, + password: "secure_password1337", + name: "John Smith" }; request(url) @@ -183,7 +187,7 @@ it('5.4 should return a success response to indicate that the user has logged in res.statusCode.should.be.equal(200); done(); }); - }, 7*DELAY); + }, 20*DELAY); }); }); @@ -203,7 +207,7 @@ it('5.5 should return a success response to indicate that the user has logged in var data = JSON.parse(res.text); var clientrequest = { - "access_token": data.data[0].access_token + access_token: data.data[0].access_token }; request(url) @@ -229,7 +233,7 @@ it('5.5 should return a success response to indicate that the user has logged in res.statusCode.should.be.equal(200); done(); }); - }, 4*DELAY); + }, 20*DELAY); }); }); }); @@ -237,6 +241,8 @@ it('5.5 should return a success response to indicate that the user has logged in it('5.6 should return a success response to indicate that the user info was retrieved', function(done) { + this.timeout(100*DELAY); + request(url) .get('/user/me') .set('Content-type','application/json') @@ -254,12 +260,12 @@ it('5.6 should return a success response to indicate that the user info was retr it('5.7 should return an error response to indicate that the user info was NOT retrieved because user was not found', function(done) { - this.timeout(25*DELAY); + this.timeout(100*DELAY); var clientrequest = { - "email": "exampleUser@appscend.com", - "password": "secure_password1337", - "name": "John Smith" + email: "exampleUser@appscend.com", + password: "secure_password1337", + name: "John Smith" }; request(url) @@ -284,8 +290,8 @@ it('5.7 should return an error response to indicate that the user info was NOT r var userID3 = res.body.content.user.id; var authValue3 = 'Bearer ' + token3; var subclientrequest = { - "id" : userID3, - "email" : "exampleUser@appscend.com" + id : userID3, + email : "exampleUser@appscend.com" }; request(url) @@ -313,19 +319,21 @@ it('5.7 should return an error response to indicate that the user info was NOT r res.statusCode.should.be.equal(404); done(); }); - },10*DELAY); + }, 20*DELAY); }); }); - }, 7*DELAY); + }, 20*DELAY); }); }); it('5.8 should return an error response to indicate that the user has NOT logged in via user & password because of invalid credentials', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "email": userEmail, - "password": "secure_password", - "name": "John Smith" + email: userEmail, + password: "secure_password", + name: "John Smith" }; request(url) @@ -345,10 +353,12 @@ it('5.8 should return an error response to indicate that the user has NOT logged it('5.9 should return an error response to indicate that the user has NOT logged in via user & password because user not found', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "email": 'user'+Math.round(Math.random()*1000000)+'@example.com', - "password": "secure_password", - "name": "John Smith" + email: 'user'+Math.round(Math.random()*1000000)+'@example.com', + password: "secure_password", + name: "John Smith" }; request(url) @@ -368,9 +378,11 @@ it('5.9 should return an error response to indicate that the user has NOT logged it('5.10 should return an error response to indicate that the user has NOT logged in via user & password because email was missing for request', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "password": "secure_password", - "name": "John Smith" + password: "secure_password", + name: "John Smith" }; request(url) @@ -390,9 +402,11 @@ it('5.10 should return an error response to indicate that the user has NOT logge it('5.11 should return an error response to indicate that the user has NOT logged in via user & password because password was missing for request', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "email": 'user'+Math.round(Math.random()*1000000)+'@example.com', - "name": "John Smith" + email: 'user'+Math.round(Math.random()*1000000)+'@example.com', + name: "John Smith" }; request(url) @@ -412,12 +426,14 @@ it('5.11 should return an error response to indicate that the user has NOT logge it('5.12 should return a success response to indicate that the user was updated', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "patches" : [ + patches : [ { - "op": "replace", - "path": "user/"+userID+"/name", - "value": "new value" + op: "replace", + path: "user/"+userID+"/name", + value: "new value" } ] }; @@ -439,12 +455,14 @@ it('5.12 should return a success response to indicate that the user was updated' it('5.13 should return a success response to indicate that the user password was updated', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "patches" : [ + patches : [ { - "op": "replace", - "path": "user/"+userID+"/password", - "value": "new value" + op: "replace", + path: "user/"+userID+"/password", + value: "new value" } ] }; @@ -466,12 +484,14 @@ it('5.13 should return a success response to indicate that the user password was it('5.14 should return an error response to indicate that the userID is not valid', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "patches" : [ + patches : [ { - "op": "replace", - "path": "user/" + userID + "66" +"/password", - "value": "new value" + op: "replace", + path: "user/" + userID + "66" +"/password", + value: "new value" } ] }; @@ -494,6 +514,8 @@ it('5.14 should return an error response to indicate that the userID is not vali it('5.15 should return a success response to indicate that the user password was NOT updated because of empty request body', function(done) { + this.timeout(100*DELAY); + request(url) .post('/user/update') .set('Content-type','application/json') @@ -512,8 +534,10 @@ it('5.15 should return a success response to indicate that the user password was it('5.16 should return a success response to indicate that the user password was NOT updated because patches is not an array', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "patches" : {} + patches : {} }; request(url) @@ -534,8 +558,10 @@ it('5.16 should return a success response to indicate that the user password was it('5.17 should return a success response to indicate that the user password was NOT updated because patches is an empty array', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "patches" : [] + patches : [] }; request(url) @@ -556,7 +582,7 @@ it('5.17 should return a success response to indicate that the user password was it('5.18 should return a success response to indicate that the user was updated immediate', function(done) { - this.timeout(20*DELAY); + this.timeout(100*DELAY); var clientrequest = { name: "new name", @@ -574,12 +600,14 @@ it('5.18 should return a success response to indicate that the user was updated .end(function(err, res) { res.statusCode.should.be.equal(200); - setTimeout(done, 14*DELAY); + done(); }); }); it('5.19 should return a success response to indicate that the token was updated', function(done) { + this.timeout(100*DELAY); + request(url) .get('/user/refresh_token') .set('Content-type','application/json') @@ -600,6 +628,8 @@ it('5.19 should return a success response to indicate that the token was updated it('5.20 should return an error response to indicate that the token was NOT updated because of bad authorization', function(done) { + this.timeout(100*DELAY); + var authValue = "something"; request(url) @@ -620,6 +650,8 @@ it('5.20 should return an error response to indicate that the token was NOT upda it('5.21 should return an error response to indicate that the token was NOT updated because of bad token', function(done) { + this.timeout(100*DELAY); + var authValue = 'Bearer something'; request(url) @@ -641,6 +673,8 @@ it('5.21 should return an error response to indicate that the token was NOT upda it('5.22 should return an error response to indicate that the token was NOT updated because authorization is missing', function(done) { + this.timeout(100*DELAY); + request(url) .get('/user/refresh_token') .set('Content-type','application/json') @@ -658,6 +692,8 @@ it('5.22 should return an error response to indicate that the token was NOT upda it('5.23 should return an error response to indicate that the token was NOT updated because X-BLGREQ-SIGN is missing', function(done) { + this.timeout(100*DELAY); + request(url) .get('/user/refresh_token') .set('Content-type','application/json') @@ -675,6 +711,8 @@ it('5.23 should return an error response to indicate that the token was NOT upda it('5.24 should return an error response to indicate that the token was NOT updated because Content-type is not application/json', function(done) { + this.timeout(100*DELAY); + request(url) .get('/user/refresh_token') .set('Content-type','application/other') @@ -693,6 +731,8 @@ it('5.24 should return an error response to indicate that the token was NOT upda it('5.25 should return an error response to indicate that the token was NOT updated because of invalid API key', function(done) { + this.timeout(100*DELAY); + request(url) .get('/user/refresh_token') .set('Content-type','application/json') @@ -711,6 +751,8 @@ it('5.25 should return an error response to indicate that the token was NOT upda it('5.26 should return an error response to indicate that the token was NOT updated because of missing UDID', function(done) { + this.timeout(100*DELAY); + request(url) .get('/user/refresh_token') .set('Content-type','application/json') @@ -728,6 +770,8 @@ it('5.26 should return an error response to indicate that the token was NOT upda it('5.27 should return a success response to indicate that the user logged out', function(done) { + this.timeout(100*DELAY); + request(url) .get('/user/logout') .set('Content-type','application/json') @@ -745,12 +789,14 @@ it('5.27 should return a success response to indicate that the user logged out', it('5.28 should return a success response to indicate that the user has registered', function(done) { + this.timeout(100*DELAY); + this.timeout(20*DELAY); var clientrequest = { - "email": userEmail2, - "password": "secure_password1337", - "name": "John Smith" + email: userEmail2, + password: "secure_password1337", + name: "John Smith" }; request(url) @@ -770,9 +816,9 @@ it('5.28 should return a success response to indicate that the user has register it('5.29 should return a success response to indicate that the user has NOT registered because user is already registered', function(done) { var clientrequest = { - "email": userEmail, - "password": "secure_password1337", - "name": "John Smith" + email: userEmail, + password: "secure_password1337", + name: "John Smith" }; request(url) @@ -792,6 +838,8 @@ it('5.29 should return a success response to indicate that the user has NOT regi it('5.30 should return a success response to indicate that the user has NOT registered because of empty body', function(done) { + this.timeout(100*DELAY); + request(url) .post('/user/register') .set('Content-type','application/json') @@ -809,10 +857,12 @@ it('5.30 should return a success response to indicate that the user has NOT regi it('5.31 should return a success response to indicate that the user was deleted', function(done) { + this.timeout(100*DELAY); + var clientrequest = { - "email": userEmail2, - "password": "secure_password1337", - "name": "John Smith" + email: userEmail2, + password: "secure_password1337", + name: "John Smith" }; request(url) @@ -828,8 +878,8 @@ it('5.31 should return a success response to indicate that the user was deleted' userID = res.body.content.user.id; authValue = 'Bearer ' + token; var subclientrequest = { - "id" : userID, - "email" : userEmail + id : userID, + email : userEmail }; request(url) From e111000cd33b64d41c3503523b1362271b372472 Mon Sep 17 00:00:00 2001 From: Razvan Botea Date: Fri, 9 Oct 2015 17:40:59 +0300 Subject: [PATCH 42/42] Updated to version 0.2.5 --- CHANGELOG.md | 11 +++++++++++ package.json | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3edd1f9..03bd51b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# 0.2.5 + +* Fixed `/user/update` when updating password +* Further improved the tests, now each test has an ID displayed for easy lookup. Tests should run faster. +* Variable checks for message queue client and main database +* Added pagination support for subscribe requests +* Removed `tokenValidation` in object routes because `objectACL` was already doing that +* `/object/count` should now work +* Applications loaded on boot up are saved in Application object from telepat-models +* Fixed some minor bugs + # 0.2.4 * Implemented /admin/authorize and /admin/deauthorize to add/remove admins to an application diff --git a/package.json b/package.json index 99fcaf3..7b8097d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "telepat-api", - "version": "0.2.4", + "version": "0.2.5", "scripts": { "start": "./bin/www", "test": "istanbul cover _mocha -- test/api.js -R spec" @@ -20,7 +20,7 @@ "morgan": "1.5.1", "object-sizeof": "1.0.6", "redis": "0.12.1", - "telepat-models": "telepat-io/telepat-models#develop", + "telepat-models": "0.2.5", "uuid": "2.0.1" }, "bugs": {