0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-13 22:48:31 -05:00
verdaccio/test/unit/plugin_loader.spec.js

73 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-04-22 08:23:16 +02:00
'use strict';
2017-11-01 17:47:20 +01:00
require('../../src/lib/logger').setup([]);
2017-04-22 08:23:16 +02:00
const assert = require('assert');
2017-06-22 01:02:52 +08:00
const load_plugins = require('../../src/lib/plugin-loader').load_plugins;
2017-04-22 08:23:16 +02:00
const path = require('path');
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': {}
}
}
let p = load_plugins(_config, _config.auth, {}, function (p) {
return p.authenticate || p.allow_access || p.allow_publish;
});
assert(p.length === 1);
});
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 {
load_plugins(_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-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 {
load_plugins(_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-sanity" doesn\'t look like a valid plugin');
}
});
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 {
load_plugins(_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-package" plugin not found\ntry "npm install verdaccio-./unit/partials/test-plugin-storage/invalid-package"`);
}
});
});