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

87 lines
2.6 KiB
JavaScript
Raw Normal View History

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
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 08:23:16 +02: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 08:23:16 +02: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 08:23:16 +02: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 08:23:16 +02:00
});