2018-06-17 06:34:59 -05:00
|
|
|
import path from 'path';
|
2020-08-13 16:27:00 -05:00
|
|
|
import { setup } from '@verdaccio/logger';
|
2020-03-03 17:59:19 -05:00
|
|
|
|
|
|
|
import { loadPlugin } from '../src/plugin-loader';
|
2018-06-17 06:34:59 -05:00
|
|
|
|
2019-07-16 01:40:01 -05:00
|
|
|
setup([]);
|
2018-06-17 06:34:59 -05:00
|
|
|
|
|
|
|
describe('plugin loader', () => {
|
2019-05-20 00:26:40 -05:00
|
|
|
const relativePath = path.join(__dirname, './partials/test-plugin-storage');
|
2020-08-13 16:27:00 -05:00
|
|
|
const buildConf = (name) => {
|
2018-06-17 06:34:59 -05:00
|
|
|
return {
|
|
|
|
self_path: path.join(__dirname, './'),
|
|
|
|
max_users: 0,
|
|
|
|
auth: {
|
2020-08-13 16:27:00 -05:00
|
|
|
[`${relativePath}/${name}`]: {},
|
|
|
|
},
|
2018-06-17 06:34:59 -05:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('auth plugins', () => {
|
|
|
|
test('testing auth valid plugin loader', () => {
|
|
|
|
const _config = buildConf('verdaccio-plugin');
|
2019-08-16 14:20:18 -05:00
|
|
|
// @ts-ignore
|
2018-06-17 06:34:59 -05:00
|
|
|
const plugins = loadPlugin(_config, _config.auth, {}, function (plugin) {
|
|
|
|
return plugin.authenticate || plugin.allow_access || plugin.allow_publish;
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(plugins).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('testing storage valid plugin loader', () => {
|
|
|
|
const _config = buildConf('verdaccio-es6-plugin');
|
2019-08-16 14:20:18 -05:00
|
|
|
// @ts-ignore
|
2018-06-17 06:34:59 -05:00
|
|
|
const plugins = loadPlugin(_config, _config.auth, {}, function (p) {
|
|
|
|
return p.getPackageStorage;
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(plugins).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('testing auth plugin invalid plugin', () => {
|
|
|
|
const _config = buildConf('invalid-plugin');
|
|
|
|
try {
|
2019-07-16 01:40:01 -05:00
|
|
|
// @ts-ignore
|
2018-06-17 06:34:59 -05:00
|
|
|
loadPlugin(_config, _config.auth, {}, function (p) {
|
|
|
|
return p.authenticate || p.allow_access || p.allow_publish;
|
|
|
|
});
|
2020-08-13 16:27:00 -05:00
|
|
|
} catch (e) {
|
2020-03-03 17:59:19 -05:00
|
|
|
expect(e.message).toEqual(`"${relativePath}/invalid-plugin" plugin does not have the right code structure`);
|
2018-06-17 06:34:59 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('testing auth plugin invalid plugin sanityCheck', () => {
|
|
|
|
const _config = buildConf('invalid-plugin-sanity');
|
|
|
|
try {
|
2019-07-16 01:40:01 -05:00
|
|
|
// @ts-ignore
|
2018-06-17 06:34:59 -05:00
|
|
|
loadPlugin(_config, _config.auth, {}, function (plugin) {
|
|
|
|
return plugin.authenticate || plugin.allow_access || plugin.allow_publish;
|
|
|
|
});
|
2020-08-13 16:27:00 -05:00
|
|
|
} catch (err) {
|
2020-03-03 17:59:19 -05:00
|
|
|
expect(err.message).toEqual(`sanity check has failed, "${relativePath}/invalid-plugin-sanity" is not a valid plugin`);
|
2018-06-17 06:34:59 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('testing auth plugin no plugins', () => {
|
|
|
|
const _config = buildConf('invalid-package');
|
|
|
|
try {
|
2019-07-16 01:40:01 -05:00
|
|
|
// @ts-ignore
|
2018-06-17 06:34:59 -05:00
|
|
|
loadPlugin(_config, _config.auth, {}, function (plugin) {
|
|
|
|
return plugin.authenticate || plugin.allow_access || plugin.allow_publish;
|
|
|
|
});
|
2020-08-13 16:27:00 -05:00
|
|
|
} catch (e) {
|
2018-06-17 06:34:59 -05:00
|
|
|
expect(e.message).toMatch('plugin not found');
|
|
|
|
expect(e.message).toMatch('/partials/test-plugin-storage/invalid-package');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-07-16 01:40:01 -05:00
|
|
|
test.todo('test middleware plugins');
|
|
|
|
test.todo('test storage plugins');
|
2018-06-17 06:34:59 -05:00
|
|
|
});
|
|
|
|
});
|