2017-10-13 16:17:18 -04:00
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
|
|
|
var async = require('async');
|
|
|
|
|
|
|
|
var mongoose = require('mongoose');
|
|
|
|
var User = require('../app/models/User.js');
|
|
|
|
var Invite = require('../app/models/Invite.js');
|
2017-10-13 18:08:13 -04:00
|
|
|
var Upload = require('../app/models/Upload.js');
|
|
|
|
var Token = require('../app/models/Token.js');
|
2017-10-13 16:17:18 -04:00
|
|
|
|
|
|
|
var chai = require('chai');
|
|
|
|
var should = chai.should();
|
|
|
|
var app = require('../server');
|
|
|
|
var server = app.server;
|
|
|
|
|
2017-10-13 18:08:13 -04:00
|
|
|
var util = require('./testUtil.js');
|
2017-10-13 16:17:18 -04:00
|
|
|
|
|
|
|
before(function (done) {
|
|
|
|
async.series([
|
|
|
|
function (cb) {
|
2017-10-13 18:08:13 -04:00
|
|
|
util.resetDatabase(cb);
|
2017-10-13 16:17:18 -04:00
|
|
|
},
|
2017-10-13 18:08:13 -04:00
|
|
|
function(cb) {
|
|
|
|
util.createInvites([{
|
|
|
|
code: 'TestCode1',
|
|
|
|
scope: ['test.perm']
|
|
|
|
}, {
|
|
|
|
code: 'TestCode2'
|
|
|
|
}, {
|
|
|
|
code: 'TestCode3',
|
|
|
|
exp: new Date() - 1
|
|
|
|
}
|
|
|
|
], cb);
|
2017-10-13 16:17:18 -04:00
|
|
|
}
|
|
|
|
], function (err) {
|
|
|
|
if (err) console.log(err);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Users', function () {
|
|
|
|
describe('/POST register', function () {
|
|
|
|
it('SHOULD register valid user, valid invite', function (done) {
|
2017-10-13 18:08:13 -04:00
|
|
|
util.verifySuccessfulRegister({
|
2017-10-13 16:17:18 -04:00
|
|
|
username: 'TestUser1',
|
|
|
|
password: 'TestPassword',
|
|
|
|
invite: 'TestCode1'
|
2017-10-13 18:08:13 -04:00
|
|
|
}, done);
|
2017-10-13 16:17:18 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('SHOULD register another valid user, valid invite', function(done) {
|
2017-10-13 18:08:13 -04:00
|
|
|
util.verifySuccessfulRegister({
|
2017-10-13 16:17:18 -04:00
|
|
|
username: 'TestUser2',
|
|
|
|
password: 'TestPassword',
|
|
|
|
invite: 'TestCode2'
|
2017-10-13 18:08:13 -04:00
|
|
|
}, done);
|
2017-10-13 16:17:18 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('SHOULD NOT register invalid user, valid invite', function (done) {
|
2017-10-13 18:08:13 -04:00
|
|
|
util.verifyFailedUserRegister({
|
2017-10-13 16:17:18 -04:00
|
|
|
username: 'TestUser1',
|
|
|
|
password: 'TestPassword',
|
|
|
|
invite: 'TestCode2'
|
2017-10-13 18:08:13 -04:00
|
|
|
}, done);
|
2017-10-13 16:17:18 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('SHOULD NOT register valid user, nonexistant invite', function (done) {
|
2017-10-13 18:08:13 -04:00
|
|
|
util.verifyFailedInviteRegister({
|
2017-10-13 16:17:18 -04:00
|
|
|
username: 'TestUser3',
|
|
|
|
password: 'TestPassword',
|
|
|
|
invite: 'bogus'
|
2017-10-13 18:08:13 -04:00
|
|
|
}, done);
|
2017-10-13 16:17:18 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('SHOULD NOT register valid user, used invite', function (done) {
|
2017-10-13 18:08:13 -04:00
|
|
|
util.verifyFailedInviteRegister({
|
2017-10-13 16:17:18 -04:00
|
|
|
username: 'TestUser3',
|
|
|
|
password: 'TestPassword',
|
|
|
|
invite: 'TestCode1'
|
2017-10-13 18:08:13 -04:00
|
|
|
}, done);
|
2017-10-13 16:17:18 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('SHOULD NOT register valid user, expired invite', function (done) {
|
2017-10-13 18:08:13 -04:00
|
|
|
util.verifyFailedInviteRegister({
|
2017-10-13 16:17:18 -04:00
|
|
|
username: 'TestUser3',
|
|
|
|
password: 'TestPassword',
|
|
|
|
invite: 'TestCode3'
|
2017-10-13 18:08:13 -04:00
|
|
|
}, done);
|
2017-10-13 16:17:18 -04:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('/POST login', function () {
|
|
|
|
it('SHOULD accept valid user, valid password', function (done) {
|
2017-10-13 18:08:13 -04:00
|
|
|
util.verifySuccessfulLogin({
|
2017-10-13 16:17:18 -04:00
|
|
|
username: 'TestUser1',
|
|
|
|
password: 'TestPassword'
|
2017-10-13 18:08:13 -04:00
|
|
|
}, done);
|
2017-10-13 16:17:18 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('SHOULD NOT accept valid user, invalid password', function (done) {
|
2017-10-13 18:08:13 -04:00
|
|
|
util.verifyFailedPasswordLogin({
|
2017-10-13 16:17:18 -04:00
|
|
|
username: 'TestUser1',
|
|
|
|
password: 'bogus'
|
2017-10-13 18:08:13 -04:00
|
|
|
}, done);
|
2017-10-13 16:17:18 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('SHOULD NOT accept invalid user, any password', function (done) {
|
2017-10-13 18:08:13 -04:00
|
|
|
util.verifyFailedUsernameLogin({
|
2017-10-13 16:17:18 -04:00
|
|
|
username: 'BogusTestUser',
|
|
|
|
password: 'bogus'
|
2017-10-13 18:08:13 -04:00
|
|
|
}, done);
|
2017-10-13 16:17:18 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Uploads', function () {
|
|
|
|
describe('/POST upload', function () {
|
|
|
|
it('SHOULD accept logged in valid upload', function(done) {
|
2017-10-13 18:08:13 -04:00
|
|
|
util.verifySuccessfulUpload({
|
2017-10-13 16:17:18 -04:00
|
|
|
username: 'TestUser2',
|
|
|
|
password: 'TestPassword'
|
2017-10-13 18:08:13 -04:00
|
|
|
}, done);
|
2017-10-13 16:17:18 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('SHOULD NOT accept unauthenticated valid upload', function(done) {
|
2017-10-13 18:08:13 -04:00
|
|
|
util.verifyFailedAuthUpload(done);
|
2017-10-13 16:17:18 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('SHOULD NOT accept invalid permission, valid upload', function(done) {
|
2017-10-13 18:08:13 -04:00
|
|
|
util.verifyFailedPermissionUpload({
|
2017-10-13 16:17:18 -04:00
|
|
|
username: 'TestUser1',
|
|
|
|
password: 'TestPassword'
|
2017-10-13 18:08:13 -04:00
|
|
|
}, done);
|
|
|
|
});
|
2017-10-13 16:17:18 -04:00
|
|
|
|
2017-10-13 18:08:13 -04:00
|
|
|
it('SHOULD NOT accept invalid size upload', function(done) {
|
|
|
|
util.verifyFailedSizeUpload({
|
|
|
|
username: 'TestUser2',
|
|
|
|
password: 'TestPassword'
|
|
|
|
}, done);
|
2017-10-13 16:17:18 -04:00
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
server.close(function () {
|
|
|
|
process.exit();
|
|
|
|
});
|
|
|
|
});
|