2017-04-19 14:15:28 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const Server = require('./lib/server');
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
2014-07-22 16:45:28 -05:00
|
|
|
|
|
|
|
module.exports = function() {
|
2017-04-19 14:15:28 -05:00
|
|
|
const server = new Server('http://localhost:55551/');
|
2014-07-22 16:45:28 -05:00
|
|
|
|
2014-11-12 06:14:37 -05:00
|
|
|
describe('adduser', function() {
|
2017-04-19 14:15:28 -05:00
|
|
|
const user = String(Math.random());
|
|
|
|
const pass = String(Math.random());
|
|
|
|
before(function() {
|
2015-04-11 12:11:04 -05:00
|
|
|
return server.auth(user, pass)
|
|
|
|
.status(201)
|
2017-04-19 14:15:28 -05:00
|
|
|
.body_ok(/user .* created/);
|
|
|
|
});
|
2014-07-22 16:45:28 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
it('creating new user', function() {});
|
2014-07-22 16:45:28 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
it('should log in', function() {
|
2015-04-11 12:11:04 -05:00
|
|
|
return server.auth(user, pass)
|
|
|
|
.status(201)
|
2017-04-19 14:15:28 -05:00
|
|
|
.body_ok(/you are authenticated as/);
|
|
|
|
});
|
2014-07-22 16:45:28 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
it('should not register more users', function() {
|
2015-04-11 12:11:04 -05:00
|
|
|
return server.auth(String(Math.random()), String(Math.random()))
|
|
|
|
.status(409)
|
2017-04-19 14:15:28 -05:00
|
|
|
.body_error(/maximum amount of users reached/);
|
|
|
|
});
|
|
|
|
});
|
2017-01-19 10:14:39 -05:00
|
|
|
|
|
|
|
describe('adduser created with htpasswd', function() {
|
2017-04-19 14:15:28 -05:00
|
|
|
let user = 'preexisting';
|
|
|
|
let pass = 'preexisting';
|
|
|
|
before(function() {
|
2017-01-19 10:14:39 -05:00
|
|
|
return fs.appendFileSync(
|
|
|
|
path.join(__dirname, 'test-storage', '.htpasswd'),
|
|
|
|
'preexisting:$apr1$4YSboUa9$yVKjE7.PxIOuK3M4D7VjX.'
|
2017-04-19 14:15:28 -05:00
|
|
|
);
|
|
|
|
});
|
|
|
|
it('should log in', function() {
|
2017-01-19 10:14:39 -05:00
|
|
|
return server.auth(user, pass)
|
|
|
|
.status(201)
|
2017-04-19 14:15:28 -05:00
|
|
|
.body_ok(/you are authenticated as/);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|