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

96 lines
2.7 KiB
JavaScript
Raw Normal View History

2017-12-02 11:19:08 +01:00
import assert from 'assert';
2015-04-11 15:09:19 +02:00
2017-12-02 11:19:08 +01:00
export default function(server2){
const requestAuthFail = (user, pass, message, statusCode) => {
return server2.auth(user, pass)
.status(statusCode)
.body_error(message)
.then(function() {
return server2.whoami();
})
.then(function(username) {
assert.equal(username, null);
});
};
const requestAuthOk = (user, pass, regex, statusCode) => {
return server2.auth(user, pass)
.status(statusCode)
.body_ok(regex)
.then(function() {
return server2.whoami();
})
.then(function(username) {
assert.equal(username, user);
});
};
2015-04-11 15:09:19 +02:00
2017-12-02 11:19:08 +01:00
describe('test default authentication', () => {
2015-04-11 15:09:19 +02:00
2017-12-02 11:19:08 +01:00
test('should not authenticate with wrong password', () => {
return requestAuthFail('authtest', 'wrongpass1', 'i don\'t like your password', 401);
2017-04-19 21:15:28 +02:00
});
2015-04-11 15:09:19 +02:00
2017-12-02 11:19:08 +01:00
test('should right password handled by plugin', () => {
return requestAuthOk('authtest2', 'blahblah', /'authtest2'/, 201);
2017-04-19 21:15:28 +02:00
});
2015-04-11 15:09:19 +02:00
2017-04-19 21:15:28 +02:00
});
2015-04-11 15:09:19 +02:00
2017-12-02 11:19:08 +01:00
describe('test access authorization', () => {
2015-04-11 15:09:19 +02:00
describe('access with user authtest', () => {
2017-12-02 11:19:08 +01:00
beforeAll(function() {
return server2.auth('authtest', 'blahblah')
.status(201)
2017-04-19 21:15:28 +02:00
.body_ok(/'authtest'/);
});
2015-04-11 15:09:19 +02:00
2017-12-02 11:19:08 +01:00
test('access test-auth-allow', () => {
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
test('access test-deny', () => {
return server2.getPackage('test-deny')
.status(403)
.body_error('not allowed to access package');
2017-04-19 21:15:28 +02:00
});
2015-04-11 15:09:19 +02:00
2017-12-02 11:19:08 +01:00
test('access test-auth-regular', () => {
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
2017-12-02 11:19:08 +01:00
describe('access with user authtest2', () => {
beforeAll(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-12-02 11:19:08 +01:00
test('access test-auth-allow', () => {
return server2.getPackage('test-auth-allow')
.status(403)
.body_error('not allowed to access package');
2017-04-19 21:15:28 +02:00
});
2015-04-11 15:09:19 +02:00
2017-12-02 11:19:08 +01:00
test('access test-auth-deny', () => {
return server2.getPackage('test-auth-deny')
.status(403)
.body_error('not allowed to access package');
2017-04-19 21:15:28 +02:00
});
2015-04-11 15:09:19 +02:00
2017-12-02 11:19:08 +01:00
test('access test-auth-regular', () => {
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
2017-04-19 21:15:28 +02:00
});
2017-12-02 11:19:08 +01:00
}