From 37ca5017ee91a142c3751301fcd7cfcb6f1f0ba8 Mon Sep 17 00:00:00 2001 From: Andrey Latysh Date: Tue, 28 Nov 2017 18:04:01 +0200 Subject: [PATCH 1/5] DEV-330; https://support.dataart.com/browse/DEV-330; Configuration name length exceeded error. --- integration-tests/rest-configuration.js | 12 ++++++++++++ integration-tests/ws-configuration.js | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/integration-tests/rest-configuration.js b/integration-tests/rest-configuration.js index 13205e9..f8ac36f 100644 --- a/integration-tests/rest-configuration.js +++ b/integration-tests/rest-configuration.js @@ -31,6 +31,7 @@ describe('REST API Configuration', function () { describe('#Update', function () { var propertyId = "test_property_create"; + var propertyIdWith33symbols = "a11112222333344445555666677778888"; var propertyValue = {"value": "test_value_create"}; it('should create configuration', function (done) { @@ -47,6 +48,17 @@ describe('REST API Configuration', function () { .send(done); }); + it('should fail with 400 when configuration name\'s length exceeded', function (done) { + req.update(path.current) + .params({ + id: propertyIdWith33symbols, + jwt: utils.jwt.admin, + data: propertyValue + }) + .expectError(status.BAD_REQUEST) + .send(done); + }); + after(function (done) { utils.delete(path.current, { id: propertyId, diff --git a/integration-tests/ws-configuration.js b/integration-tests/ws-configuration.js index 5f96fb9..3f7b6b9 100644 --- a/integration-tests/ws-configuration.js +++ b/integration-tests/ws-configuration.js @@ -142,6 +142,7 @@ describe('WebSocket API Configuration', function () { describe('#configuration/put', function () { var requestId = getRequestId(); var configurationName = "ws_test_property"; + var configurationNameWith33symbols = "a11112222333344445555666677778888"; var configurationValue = "ws_test_value_create"; it('should create configuration', function (done) { @@ -166,6 +167,18 @@ describe('WebSocket API Configuration', function () { }); + it('should fail with 400 when configuration name\'s length exceeded', function (done) { + connTokenAuth.params({ + action: 'configuration/put', + requestId: requestId, + name: configurationNameWith33symbols, + value: configurationValue + }) + .expectError(status.BAD_REQUEST) + .send(done); + + }); + after(function (done) { utils.delete(path.current, { id: configurationName, From a2d9e71f393714b609c567e7d49aafaba034c51a Mon Sep 17 00:00:00 2001 From: AndreyLatysh Date: Thu, 30 Nov 2017 13:05:56 +0200 Subject: [PATCH 2/5] Update ws-configuration.js --- integration-tests/ws-configuration.js | 1 - 1 file changed, 1 deletion(-) diff --git a/integration-tests/ws-configuration.js b/integration-tests/ws-configuration.js index 3f7b6b9..951ba35 100644 --- a/integration-tests/ws-configuration.js +++ b/integration-tests/ws-configuration.js @@ -176,7 +176,6 @@ describe('WebSocket API Configuration', function () { }) .expectError(status.BAD_REQUEST) .send(done); - }); after(function (done) { From 0c81f99b43ddcf31aa3f59025b2bea08c9b3d6a2 Mon Sep 17 00:00:00 2001 From: Andrey Latysh Date: Thu, 7 Dec 2017 19:24:14 +0200 Subject: [PATCH 3/5] DEV-350 Tests fixed according to the changes related to the last login time update. --- integration-tests/rest-user.js | 1 - integration-tests/ws-user.js | 2 -- 2 files changed, 3 deletions(-) diff --git a/integration-tests/rest-user.js b/integration-tests/rest-user.js index 04d056a..f199356 100644 --- a/integration-tests/rest-user.js +++ b/integration-tests/rest-user.js @@ -480,7 +480,6 @@ describe('REST API User', function () { login: user.login, role: 1, status: 1, - lastLogin: null, introReviewed: true }) .send(done); diff --git a/integration-tests/ws-user.js b/integration-tests/ws-user.js index 8b1b0df..7d7dd73 100644 --- a/integration-tests/ws-user.js +++ b/integration-tests/ws-user.js @@ -266,7 +266,6 @@ describe('WebSocket API User', function () { login: user.login, role: 1, status: 0, - lastLogin: null, introReviewed: false } }) @@ -653,7 +652,6 @@ describe('WebSocket API User', function () { login: user.login, role: 1, status: 1, - lastLogin: null, introReviewed: true } }) From 90ef15c74e28cdb58e30a67d3dea5bc4d5f88b06 Mon Sep 17 00:00:00 2001 From: Andrey Latysh Date: Mon, 11 Dec 2017 12:20:03 +0200 Subject: [PATCH 4/5] Added tests for the last login update. --- integration-tests/rest-user.js | 94 ++++++++++++++++++++++++++++++++++ integration-tests/ws-user.js | 58 +++++++++++++++++++++ 2 files changed, 152 insertions(+) diff --git a/integration-tests/rest-user.js b/integration-tests/rest-user.js index f199356..d1abeb7 100644 --- a/integration-tests/rest-user.js +++ b/integration-tests/rest-user.js @@ -4,6 +4,7 @@ var utils = require('./common/utils'); var path = require('./common/path'); var status = require('./common/http').status; var req = require('./common/request'); +var assert = require('assert'); describe('REST API User', function () { this.timeout(90000); @@ -794,6 +795,99 @@ describe('REST API User', function () { }); }); + describe('#Last Login', function () { + + it('should set last login on first login', function (done) { + var user = { + login: utils.getName('usr-1'), + password: utils.NEW_USER_PASSWORD + }; + var params = {jwt: utils.jwt.admin}; + + utils.createUser(user.login, user.password, 0, 0, + function (err, result) { + if (err) { + return done(err); + } + user.id = result.id; + }); + + setTimeout(function() { + utils.createAuth(path.JWT, {data: { + login: user.login, + password: user.password + } + }, function (err, result) { + if (err) { + return done(err); + } + })}, 100); + + setTimeout(function() { + (utils.get(path.combine(path.USER, user.id), params, function (err, result) { + if (err) { + return done(err); + } + assert(result.lastLogin !== null); + done(); + }))}, 200); + }); + + it('should set last login on token refresh', function (done) { + var user = { + login: utils.getName('usr-2'), + password: utils.NEW_USER_PASSWORD + }; + var params = {jwt: utils.jwt.admin}; + + utils.createUser(user.login, user.password, 0, 0, + function (err, result) { + if (err) { + return done(err); + } + user.id = result.id; + }); + + setTimeout(function createToken(callback) { + var args = { + actions: [ + 'GetDeviceNotification', + 'GetDeviceCommand', + 'CreateDeviceNotification', + 'CreateDeviceCommand', + 'UpdateDeviceCommand' + ], + networkIds: void 0, + deviceId: void 0 + }; + utils.jwt.create(user.id, args.actions, args.networkIds, args.deviceId, function (err, result) { + if (err) { + return done(err); + } + user.refreshToken = result.refreshToken; + })}, 100); + + setTimeout(function() { + utils.createAuth(path.JWT + '/refresh', { + data: { + refreshToken: user.refreshToken + }}, function (err, result) { + if (err) { + return done(err); + } + })}, 200); + + setTimeout(function() { + (utils.get(path.combine(path.USER, user.id), params, function (err, result) { + if (err) { + return done(err); + } + assert(result.lastLogin !== null); + done(); + }))}, 300); + }); + }); + after(function (done) { utils.clearDataJWT(done); }); diff --git a/integration-tests/ws-user.js b/integration-tests/ws-user.js index 7d7dd73..728a91d 100644 --- a/integration-tests/ws-user.js +++ b/integration-tests/ws-user.js @@ -1081,6 +1081,64 @@ describe('WebSocket API User', function () { }); }); + describe('#Last Login', function () { + + it('should set last login on authentication', function (done) { + var user = { + login: utils.getName('usr-1'), + password: utils.NEW_USER_PASSWORD + }; + var params = {jwt: utils.jwt.admin}; + + utils.createUser(user.login, user.password, 0, 0, + function (err, result) { + if (err) { + return done(err); + } + user.id = result.id; + }); + + setTimeout(function createToken(callback) { + var args = { + actions: [ + 'GetDeviceNotification', + 'GetDeviceCommand', + 'CreateDeviceNotification', + 'CreateDeviceCommand', + 'UpdateDeviceCommand' + ], + networkIds: void 0, + deviceId: void 0 + }; + utils.jwt.create(user.id, args.actions, args.networkIds, args.deviceId, function (err, result) { + if (err) { + return done(err); + } + user.accessToken = result.accessToken; + })}, 100); + + setTimeout(function authenticateConn(callback) { + conn.params({ + action: 'authenticate', + requestId: getRequestId(), + token: user.accessToken + }) + .send(callback); + }, 200); + + setTimeout(function() { + adminConn.params({ + action: 'user/get', + userId: user.id + }) + .assert(function (result) { + assert(result.user.lastLogin !== null); + }) + .send(done); + }, 300); + }); + }); + after(function (done) { adminConn.close(); noTokenConn.close(); From 45069e25b0ffd68cde20f039ed229afbc804dcb3 Mon Sep 17 00:00:00 2001 From: Andrey Latysh Date: Mon, 11 Dec 2017 13:04:19 +0200 Subject: [PATCH 5/5] Added validation that last login does not update on token creation requested by admin. --- integration-tests/rest-user.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/integration-tests/rest-user.js b/integration-tests/rest-user.js index d1abeb7..89cee2e 100644 --- a/integration-tests/rest-user.js +++ b/integration-tests/rest-user.js @@ -867,6 +867,14 @@ describe('REST API User', function () { user.refreshToken = result.refreshToken; })}, 100); + setTimeout(function() { + (utils.get(path.combine(path.USER, user.id), params, function (err, result) { + if (err) { + return done(err); + } + assert(result.lastLogin === null); + }))}, 200); + setTimeout(function() { utils.createAuth(path.JWT + '/refresh', { data: { @@ -875,7 +883,7 @@ describe('REST API User', function () { if (err) { return done(err); } - })}, 200); + })}, 300); setTimeout(function() { (utils.get(path.combine(path.USER, user.id), params, function (err, result) { @@ -884,7 +892,7 @@ describe('REST API User', function () { } assert(result.lastLogin !== null); done(); - }))}, 300); + }))}, 400); }); });