2017-12-22 21:32:52 +01:00
|
|
|
|
|
|
|
import {loadPlugin} from '../../src/lib/plugin-loader';
|
|
|
|
import assert from 'assert';
|
|
|
|
import path from 'path';
|
2017-04-22 08:23:16 +02:00
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
require('../../src/lib/logger').setup([]);
|
2017-04-22 08:23:16 +02:00
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
describe('plugin loader', () => {
|
2017-04-22 08:23:16 +02:00
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
test('testing auth valid plugin loader', () => {
|
2017-04-22 08:23:16 +02:00
|
|
|
let _config = {
|
|
|
|
self_path: path.join(__dirname, './'),
|
|
|
|
max_users: 0,
|
|
|
|
auth: {
|
|
|
|
'./unit/partials/test-plugin-storage/verdaccio-plugin': {}
|
|
|
|
}
|
|
|
|
}
|
2017-12-22 21:32:52 +01:00
|
|
|
let plugins = loadPlugin(_config, _config.auth, {}, function (p) {
|
2017-04-22 08:23:16 +02:00
|
|
|
return p.authenticate || p.allow_access || p.allow_publish;
|
|
|
|
});
|
2017-12-22 21:32:52 +01:00
|
|
|
assert(plugins.length === 1);
|
2017-04-22 08:23:16 +02:00
|
|
|
});
|
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
test('testing auth plugin invalid plugin', () => {
|
2017-04-22 08:23:16 +02:00
|
|
|
let _config = {
|
|
|
|
self_path: path.join(__dirname, './'),
|
|
|
|
auth: {
|
|
|
|
'./unit/partials/test-plugin-storage/invalid-plugin': {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
2017-12-22 21:32:52 +01:00
|
|
|
loadPlugin(_config, _config.auth, {}, function (p) {
|
2017-04-22 08:23:16 +02:00
|
|
|
return p.authenticate || p.allow_access || p.allow_publish;
|
|
|
|
});
|
|
|
|
} catch(e) {
|
|
|
|
assert(e.message === '"./unit/partials/test-plugin-storage/invalid-plugin" doesn\'t look like a valid plugin');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
test('testing auth plugin invalid plugin sanityCheck', () => {
|
2017-04-22 08:23:16 +02:00
|
|
|
let _config = {
|
|
|
|
self_path: path.join(__dirname, './'),
|
|
|
|
auth: {
|
|
|
|
'./unit/partials/test-plugin-storage/invalid-plugin-sanity': {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
2017-12-22 21:32:52 +01:00
|
|
|
loadPlugin(_config, _config.auth, {}, function (plugin) {
|
|
|
|
return plugin.authenticate || plugin.allow_access || plugin.allow_publish;
|
2017-04-22 08:23:16 +02:00
|
|
|
});
|
2017-12-22 21:32:52 +01:00
|
|
|
} catch(err) {
|
|
|
|
assert(err.message === '"./unit/partials/test-plugin-storage/invalid-plugin-sanity" doesn\'t look like a valid plugin');
|
2017-04-22 08:23:16 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
test('testing auth plugin no plugins', () => {
|
2017-04-22 08:23:16 +02:00
|
|
|
let _config = {
|
2017-04-22 09:31:12 +02:00
|
|
|
self_path: path.join(__dirname, './'),
|
2017-04-22 08:23:16 +02:00
|
|
|
auth: {
|
|
|
|
'./unit/partials/test-plugin-storage/invalid-package': {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
2017-12-22 21:32:52 +01:00
|
|
|
loadPlugin(_config, _config.auth, {}, function (plugin) {
|
|
|
|
return plugin.authenticate || plugin.allow_access || plugin.allow_publish;
|
2017-04-22 08:23:16 +02:00
|
|
|
});
|
|
|
|
} catch(e) {
|
|
|
|
assert(e.message === `"./unit/partials/test-plugin-storage/invalid-package" plugin not found\ntry "npm install verdaccio-./unit/partials/test-plugin-storage/invalid-package"`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|