2017-01-27 00:20:03 +00:00
|
|
|
|
|
|
|
|
|
var Promise = require('bluebird');
|
|
|
|
|
var request = Promise.promisifyAll(require('request'));
|
|
|
|
|
var assert = require('assert');
|
|
|
|
|
|
|
|
|
|
module.exports = function(port) {
|
|
|
|
|
var PORT = port;
|
|
|
|
|
var BASE_URL = 'http://localhost:' + PORT;
|
|
|
|
|
|
|
|
|
|
function execute_reset_password(jar, transporter, user, new_password) {
|
|
|
|
|
return request.postAsync({
|
2017-05-14 15:34:51 +00:00
|
|
|
|
url: BASE_URL + '/reset-password',
|
2017-01-27 00:20:03 +00:00
|
|
|
|
jar: jar,
|
|
|
|
|
form: { userid: user }
|
|
|
|
|
})
|
|
|
|
|
.then(function(res) {
|
|
|
|
|
assert.equal(res.statusCode, 204);
|
|
|
|
|
var html_content = transporter.sendMail.getCall(0).args[0].html;
|
|
|
|
|
var regexp = /identity_token=([a-zA-Z0-9]+)/;
|
|
|
|
|
var token = regexp.exec(html_content)[1];
|
|
|
|
|
// console.log(html_content, token);
|
|
|
|
|
return request.getAsync({
|
2017-05-14 15:34:51 +00:00
|
|
|
|
url: BASE_URL + '/reset-password?identity_token=' + token,
|
2017-01-27 00:20:03 +00:00
|
|
|
|
jar: jar
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.then(function(res) {
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
return request.postAsync({
|
2017-05-14 15:34:51 +00:00
|
|
|
|
url: BASE_URL + '/new-password',
|
2017-01-27 00:20:03 +00:00
|
|
|
|
jar: jar,
|
|
|
|
|
form: {
|
|
|
|
|
password: new_password
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-28 17:27:54 +00:00
|
|
|
|
function execute_register_totp(jar, transporter) {
|
|
|
|
|
return request.postAsync({
|
2017-05-14 15:34:51 +00:00
|
|
|
|
url: BASE_URL + '/totp-register',
|
2017-01-28 17:27:54 +00:00
|
|
|
|
jar: jar
|
|
|
|
|
})
|
|
|
|
|
.then(function(res) {
|
|
|
|
|
assert.equal(res.statusCode, 204);
|
|
|
|
|
var html_content = transporter.sendMail.getCall(0).args[0].html;
|
|
|
|
|
var regexp = /identity_token=([a-zA-Z0-9]+)/;
|
|
|
|
|
var token = regexp.exec(html_content)[1];
|
|
|
|
|
// console.log(html_content, token);
|
|
|
|
|
return request.getAsync({
|
2017-05-14 15:34:51 +00:00
|
|
|
|
url: BASE_URL + '/totp-register?identity_token=' + token,
|
2017-01-28 17:27:54 +00:00
|
|
|
|
jar: jar
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.then(function(res) {
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
return request.postAsync({
|
2017-05-14 15:34:51 +00:00
|
|
|
|
url : BASE_URL + '/new-totp-secret',
|
2017-01-28 17:27:54 +00:00
|
|
|
|
jar: jar,
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.then(function(res) {
|
|
|
|
|
console.log(res.statusCode);
|
|
|
|
|
console.log(res.body);
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
return Promise.resolve(res.body);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-27 00:20:03 +00:00
|
|
|
|
function execute_totp(jar, token) {
|
|
|
|
|
return request.postAsync({
|
2017-05-14 15:34:51 +00:00
|
|
|
|
url: BASE_URL + '/2ndfactor/totp',
|
2017-01-27 00:20:03 +00:00
|
|
|
|
jar: jar,
|
|
|
|
|
form: {
|
|
|
|
|
token: token
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function execute_u2f_authentication(jar) {
|
|
|
|
|
return request.getAsync({
|
2017-05-14 15:34:51 +00:00
|
|
|
|
url: BASE_URL + '/2ndfactor/u2f/sign_request',
|
2017-01-27 00:20:03 +00:00
|
|
|
|
jar: jar
|
|
|
|
|
})
|
|
|
|
|
.then(function(res) {
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
return request.postAsync({
|
2017-05-14 15:34:51 +00:00
|
|
|
|
url: BASE_URL + '/2ndfactor/u2f/sign',
|
2017-01-27 00:20:03 +00:00
|
|
|
|
jar: jar,
|
|
|
|
|
form: {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function execute_verification(jar) {
|
2017-05-14 15:34:51 +00:00
|
|
|
|
return request.getAsync({ url: BASE_URL + '/verify', jar: jar })
|
2017-01-27 00:20:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function execute_login(jar) {
|
2017-05-14 15:34:51 +00:00
|
|
|
|
return request.getAsync({ url: BASE_URL + '/login', jar: jar })
|
2017-01-27 00:20:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function execute_u2f_registration(jar, transporter) {
|
|
|
|
|
return request.postAsync({
|
2017-05-14 15:34:51 +00:00
|
|
|
|
url: BASE_URL + '/u2f-register',
|
2017-01-27 00:20:03 +00:00
|
|
|
|
jar: jar
|
|
|
|
|
})
|
|
|
|
|
.then(function(res) {
|
|
|
|
|
assert.equal(res.statusCode, 204);
|
|
|
|
|
var html_content = transporter.sendMail.getCall(0).args[0].html;
|
|
|
|
|
var regexp = /identity_token=([a-zA-Z0-9]+)/;
|
|
|
|
|
var token = regexp.exec(html_content)[1];
|
|
|
|
|
// console.log(html_content, token);
|
|
|
|
|
return request.getAsync({
|
2017-05-14 15:34:51 +00:00
|
|
|
|
url: BASE_URL + '/u2f-register?identity_token=' + token,
|
2017-01-27 00:20:03 +00:00
|
|
|
|
jar: jar
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.then(function(res) {
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
return request.getAsync({
|
2017-05-14 15:34:51 +00:00
|
|
|
|
url: BASE_URL + '/2ndfactor/u2f/register_request',
|
2017-01-27 00:20:03 +00:00
|
|
|
|
jar: jar,
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.then(function(res) {
|
|
|
|
|
assert.equal(res.statusCode, 200);
|
|
|
|
|
return request.postAsync({
|
2017-05-14 15:34:51 +00:00
|
|
|
|
url: BASE_URL + '/2ndfactor/u2f/register',
|
2017-01-27 00:20:03 +00:00
|
|
|
|
jar: jar,
|
|
|
|
|
form: {
|
|
|
|
|
s: 'test'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function execute_first_factor(jar) {
|
|
|
|
|
return request.postAsync({
|
2017-05-14 15:34:51 +00:00
|
|
|
|
url: BASE_URL + '/1stfactor',
|
2017-01-27 00:20:03 +00:00
|
|
|
|
jar: jar,
|
|
|
|
|
form: {
|
|
|
|
|
username: 'test_ok',
|
|
|
|
|
password: 'password'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-01-28 00:32:25 +00:00
|
|
|
|
|
|
|
|
|
function execute_failing_first_factor(jar) {
|
|
|
|
|
return request.postAsync({
|
2017-05-14 15:34:51 +00:00
|
|
|
|
url: BASE_URL + '/1stfactor',
|
2017-01-28 00:32:25 +00:00
|
|
|
|
jar: jar,
|
|
|
|
|
form: {
|
|
|
|
|
username: 'test_nok',
|
|
|
|
|
password: 'password'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-01-27 00:20:03 +00:00
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
login: execute_login,
|
|
|
|
|
verify: execute_verification,
|
|
|
|
|
reset_password: execute_reset_password,
|
|
|
|
|
u2f_authentication: execute_u2f_authentication,
|
|
|
|
|
u2f_registration: execute_u2f_registration,
|
|
|
|
|
first_factor: execute_first_factor,
|
2017-01-28 00:32:25 +00:00
|
|
|
|
failing_first_factor: execute_failing_first_factor,
|
2017-01-27 00:20:03 +00:00
|
|
|
|
totp: execute_totp,
|
2017-01-28 17:27:54 +00:00
|
|
|
|
register_totp: execute_register_totp,
|
2017-01-27 00:20:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|