2017-12-22 15:32:52 -05:00
|
|
|
|
|
|
|
import {loadPlugin} from '../../src/lib/plugin-loader';
|
|
|
|
import assert from 'assert';
|
|
|
|
import path from 'path';
|
2017-04-22 01:23:16 -05:00
|
|
|
|
2017-11-01 11:47:20 -05:00
|
|
|
require('../../src/lib/logger').setup([]);
|
2017-04-22 01:23:16 -05:00
|
|
|
|
2017-11-01 11:47:20 -05:00
|
|
|
describe('plugin loader', () => {
|
2017-04-22 01:23:16 -05:00
|
|
|
|
2017-12-25 06:27:35 -05:00
|
|
|
test('testing auth valid plugin loader', () => {
|
|
|
|
let _config = {
|
|
|
|
self_path: path.join(__dirname, './'),
|
|
|
|
max_users: 0,
|
|
|
|
auth: {
|
|
|
|
'./unit/partials/test-plugin-storage/verdaccio-plugin': {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let plugins = loadPlugin(_config, _config.auth, {}, function (p) {
|
|
|
|
return p.authenticate || p.allow_access || p.allow_publish;
|
|
|
|
});
|
|
|
|
assert(plugins.length === 1);
|
|
|
|
});
|
2017-04-22 01:23:16 -05:00
|
|
|
|
2017-12-25 06:27:35 -05:00
|
|
|
test('testing storage valid plugin loader', () => {
|
|
|
|
let _config = {
|
|
|
|
self_path: path.join(__dirname, './'),
|
|
|
|
max_users: 0,
|
|
|
|
auth: {
|
|
|
|
'./unit/partials/test-plugin-storage/verdaccio-es6-plugin': {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let plugins = loadPlugin(_config, _config.auth, {}, function (p) {
|
|
|
|
return p.getPackageStorage;
|
|
|
|
});
|
|
|
|
assert(plugins.length === 1);
|
|
|
|
});
|
2017-04-22 01:23:16 -05:00
|
|
|
|
2017-12-25 06:27:35 -05:00
|
|
|
test('testing auth plugin invalid plugin', () => {
|
|
|
|
let _config = {
|
|
|
|
self_path: path.join(__dirname, './'),
|
|
|
|
auth: {
|
|
|
|
'./unit/partials/test-plugin-storage/invalid-plugin': {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
loadPlugin(_config, _config.auth, {}, function (p) {
|
|
|
|
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-04-22 01:23:16 -05:00
|
|
|
|
2017-12-25 06:27:35 -05:00
|
|
|
test('testing auth plugin invalid plugin sanityCheck', () => {
|
|
|
|
let _config = {
|
|
|
|
self_path: path.join(__dirname, './'),
|
|
|
|
auth: {
|
|
|
|
'./unit/partials/test-plugin-storage/invalid-plugin-sanity': {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
loadPlugin(_config, _config.auth, {}, function (plugin) {
|
|
|
|
return plugin.authenticate || plugin.allow_access || plugin.allow_publish;
|
|
|
|
});
|
|
|
|
} catch(err) {
|
|
|
|
assert(err.message === '"./unit/partials/test-plugin-storage/invalid-plugin-sanity" doesn\'t look like a valid plugin');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('testing auth plugin no plugins', () => {
|
|
|
|
let _config = {
|
|
|
|
self_path: path.join(__dirname, './'),
|
|
|
|
auth: {
|
|
|
|
'./unit/partials/test-plugin-storage/invalid-package': {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
loadPlugin(_config, _config.auth, {}, function (plugin) {
|
|
|
|
return plugin.authenticate || plugin.allow_access || plugin.allow_publish;
|
|
|
|
});
|
|
|
|
} 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"`);
|
|
|
|
}
|
|
|
|
});
|
2017-04-22 01:23:16 -05:00
|
|
|
|
|
|
|
});
|