Skip to content

Commit

Permalink
Merge pull request #113 from devicehive/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
tmatvienko authored Dec 11, 2017
2 parents 98a7acc + 97a371d commit 1b066c6
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 3 deletions.
12 changes: 12 additions & 0 deletions integration-tests/rest-configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down
103 changes: 102 additions & 1 deletion integration-tests/rest-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -480,7 +481,6 @@ describe('REST API User', function () {
login: user.login,
role: 1,
status: 1,
lastLogin: null,
introReviewed: true
})
.send(done);
Expand Down Expand Up @@ -795,6 +795,107 @@ 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.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: {
refreshToken: user.refreshToken
}}, function (err, result) {
if (err) {
return done(err);
}
})}, 300);

setTimeout(function() {
(utils.get(path.combine(path.USER, user.id), params, function (err, result) {
if (err) {
return done(err);
}
assert(result.lastLogin !== null);
done();
}))}, 400);
});
});

after(function (done) {
utils.clearDataJWT(done);
});
Expand Down
12 changes: 12 additions & 0 deletions integration-tests/ws-configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -166,6 +167,17 @@ 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,
Expand Down
60 changes: 58 additions & 2 deletions integration-tests/ws-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ describe('WebSocket API User', function () {
login: user.login,
role: 1,
status: 0,
lastLogin: null,
introReviewed: false
}
})
Expand Down Expand Up @@ -653,7 +652,6 @@ describe('WebSocket API User', function () {
login: user.login,
role: 1,
status: 1,
lastLogin: null,
introReviewed: true
}
})
Expand Down Expand Up @@ -1083,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();
Expand Down

0 comments on commit 1b066c6

Please sign in to comment.