1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/test/functional/plugins/auth.spec.js

122 lines
3.2 KiB
JavaScript
Raw Normal View History

2017-04-19 21:15:28 +02:00
'use strict';
2015-04-11 15:09:19 +02:00
require('../lib/startup');
2017-04-19 21:15:28 +02:00
let assert = require('assert');
2015-04-11 15:09:19 +02:00
module.exports = function() {
const server2 = process.server2;
const requestAuthFail = (user, pass, message) => {
return server2.auth(user, pass)
.status(409)
.body_error(message)
.then(function() {
return server2.whoami();
})
.then(function(username) {
assert.equal(username, null);
});
};
const requestAuthOk = (user, pass, regex) => {
return server2.auth(user, pass)
.status(201)
.body_ok(regex)
.then(function() {
return server2.whoami();
})
.then(function(username) {
assert.equal(username, user);
});
};
2015-04-11 15:09:19 +02:00
describe('test default authentication', function() {
2017-04-19 21:15:28 +02:00
let authstr;
2015-04-11 15:09:19 +02:00
before(function() {
2017-04-19 21:15:28 +02:00
authstr = server2.authstr;
});
2015-04-11 15:09:19 +02:00
2017-04-19 21:15:28 +02:00
it('should not authenticate with wrong password', function() {
return requestAuthFail('authtest', 'wrongpass', 'this user already exists');
2017-04-19 21:15:28 +02:00
});
2015-04-11 15:09:19 +02:00
it('should be wrong password handled by plugin', function() {
return requestAuthFail('authtest2', 'wrongpass', 'registration is disabled');
2017-04-19 21:15:28 +02:00
});
2015-04-11 15:09:19 +02:00
it('should right password handled by plugin', function() {
return requestAuthOk('authtest2', 'blahblah', /'authtest2'/);
2017-04-19 21:15:28 +02:00
});
2015-04-11 15:09:19 +02:00
after(function() {
2017-04-19 21:15:28 +02:00
server2.authstr = authstr;
});
});
2015-04-11 15:09:19 +02:00
describe('test access authorization', function() {
2017-04-19 21:15:28 +02:00
let authstr;
2015-04-11 15:09:19 +02:00
before(function() {
2017-04-19 21:15:28 +02:00
authstr = server2.authstr;
});
2015-04-11 15:09:19 +02:00
describe('access with user authtest', function() {
2017-04-19 21:15:28 +02:00
before(function() {
return server2.auth('authtest', 'test')
.status(201)
2017-04-19 21:15:28 +02:00
.body_ok(/'authtest'/);
});
2015-04-11 15:09:19 +02:00
2017-04-19 21:15:28 +02:00
it('access test-auth-allow', function() {
return server2.getPackage('test-auth-allow')
.status(404)
2017-04-19 21:15:28 +02:00
.body_error('no such package available');
});
2015-04-11 15:09:19 +02:00
2017-04-19 21:15:28 +02:00
it('access test-auth-deny', function() {
return server2.getPackage('test-auth-deny')
.status(403)
2017-04-19 21:15:28 +02:00
.body_error('you\'re not allowed here');
});
2015-04-11 15:09:19 +02:00
2017-04-19 21:15:28 +02:00
it('access test-auth-regular', function() {
return server2.getPackage('test-auth-regular')
.status(404)
2017-04-19 21:15:28 +02:00
.body_error('no such package available');
});
});
2015-04-11 15:09:19 +02:00
describe('access with user authtest2', function() {
2017-04-19 21:15:28 +02:00
before(function() {
return server2.auth('authtest2', 'blahblah')
.status(201)
2017-04-19 21:15:28 +02:00
.body_ok(/'authtest2'/);
});
2015-04-11 15:09:19 +02:00
2017-04-19 21:15:28 +02:00
it('access test-auth-allow', function() {
return server2.getPackage('test-auth-allow')
.status(403)
2017-04-19 21:15:28 +02:00
.body_error('i don\'t know anything about you');
});
2015-04-11 15:09:19 +02:00
2017-04-19 21:15:28 +02:00
it('access test-auth-deny', function() {
return server2.getPackage('test-auth-deny')
.status(403)
2017-04-19 21:15:28 +02:00
.body_error('i don\'t know anything about you');
});
2015-04-11 15:09:19 +02:00
2017-04-19 21:15:28 +02:00
it('access test-auth-regular', function() {
return server2.getPackage('test-auth-regular')
.status(404)
2017-04-19 21:15:28 +02:00
.body_error('no such package available');
});
});
2015-04-11 15:09:19 +02:00
after(function() {
2017-04-19 21:15:28 +02:00
server2.authstr = authstr;
});
});
};
2015-04-11 15:09:19 +02:00