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

27 lines
622 B
JavaScript
Raw Normal View History

2017-04-19 21:15:28 +02:00
'use strict';
2015-04-11 15:09:19 +02:00
2017-04-19 21:15:28 +02:00
module.exports = Plugin;
2015-04-11 15:09:19 +02:00
function Plugin(config, stuff) {
2017-04-19 21:15:28 +02:00
let self = Object.create(Plugin.prototype);
self._config = config;
return self;
2015-04-11 15:09:19 +02:00
}
// plugin is expected to be compatible with...
2017-04-19 21:15:28 +02:00
Plugin.prototype.verdaccio_version = '1.1.0';
2015-04-11 15:09:19 +02:00
Plugin.prototype.authenticate = function(user, password, cb) {
2017-04-19 21:15:28 +02:00
let self = this;
2015-04-11 15:09:19 +02:00
if (user !== self._config.accept_user) {
// delegate to next plugin
2017-04-19 21:15:28 +02:00
return cb(null, false);
2015-04-11 15:09:19 +02:00
}
if (password !== self._config.with_password) {
2017-04-19 21:15:28 +02:00
let err = Error('i don\'t like your password');
err.status = 403;
return cb(err);
2015-04-11 15:09:19 +02:00
}
2017-04-19 21:15:28 +02:00
return cb(null, [user]);
};