2018-06-28 18:33:37 +02:00
|
|
|
import path from 'path';
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
|
|
|
import Config from '../../../src/lib/config';
|
|
|
|
import {parseConfigFile} from '../../../src/lib/utils';
|
|
|
|
import {DEFAULT_REGISTRY, DEFAULT_UPLINK, ROLES, WEB_TITLE} from '../../../src/lib/constants';
|
2017-08-02 20:45:21 +02:00
|
|
|
|
2018-06-17 13:34:59 +02:00
|
|
|
const resolveConf = (conf) => path.join(__dirname, `../../../conf/${conf}.yaml`);
|
2018-06-30 22:39:06 +02:00
|
|
|
require('../../../src/lib/logger').setup([]);
|
2017-08-02 20:46:06 +02:00
|
|
|
|
2018-06-28 18:33:37 +02:00
|
|
|
const checkDefaultUplink = (config) => {
|
|
|
|
expect(_.isObject(config.uplinks[DEFAULT_UPLINK])).toBeTruthy();
|
|
|
|
expect(config.uplinks[DEFAULT_UPLINK].url).toMatch(DEFAULT_REGISTRY);
|
2017-08-02 20:45:21 +02:00
|
|
|
};
|
|
|
|
|
2018-06-28 18:33:37 +02:00
|
|
|
const checkDefaultConfPackages = (config) => {
|
|
|
|
//auth
|
|
|
|
expect(_.isObject(config.auth)).toBeTruthy();
|
|
|
|
expect(_.isObject(config.auth.htpasswd)).toBeTruthy();
|
|
|
|
expect(config.auth.htpasswd.file).toMatch(/htpasswd/);
|
|
|
|
|
|
|
|
//web
|
|
|
|
expect(_.isObject(config.web)).toBeTruthy();
|
|
|
|
expect(config.web.title).toBe(WEB_TITLE);
|
|
|
|
expect(config.web.enable).toBeUndefined();
|
|
|
|
|
|
|
|
// packages
|
|
|
|
expect(_.isObject(config.packages)).toBeTruthy();
|
|
|
|
expect(Object.keys(config.packages).join('|')).toBe('@*/*|**');
|
|
|
|
expect(config.packages['@*/*'].access).toBeDefined();
|
|
|
|
expect(config.packages['@*/*'].access).toContainEqual(ROLES.$ALL);
|
|
|
|
expect(config.packages['@*/*'].publish).toBeDefined();
|
|
|
|
expect(config.packages['@*/*'].publish).toContainEqual(ROLES.$AUTH);
|
|
|
|
expect(config.packages['@*/*'].proxy).toBeDefined();
|
|
|
|
expect(config.packages['@*/*'].proxy).toContainEqual(DEFAULT_UPLINK);
|
|
|
|
expect(config.packages['**'].access).toBeDefined();
|
|
|
|
expect(config.packages['**'].access).toContainEqual(ROLES.$ALL);
|
|
|
|
expect(config.packages['**'].publish).toBeDefined();
|
|
|
|
expect(config.packages['**'].publish).toContainEqual(ROLES.$AUTH);
|
|
|
|
expect(config.packages['**'].proxy).toBeDefined();
|
|
|
|
expect(config.packages['**'].proxy,).toContainEqual(DEFAULT_UPLINK);
|
|
|
|
// uplinks
|
|
|
|
expect(config.uplinks[DEFAULT_UPLINK]).toBeDefined();
|
|
|
|
expect(config.uplinks[DEFAULT_UPLINK].url).toEqual(DEFAULT_REGISTRY);
|
|
|
|
// audit
|
|
|
|
expect(config.middlewares).toBeDefined();
|
|
|
|
expect(config.middlewares.audit).toBeDefined();
|
|
|
|
expect(config.middlewares.audit.enabled).toBeTruthy();
|
|
|
|
// logs
|
|
|
|
expect(config.logs).toBeDefined();
|
|
|
|
expect(config.logs[0].type).toEqual('stdout');
|
|
|
|
expect(config.logs[0].format).toEqual('pretty');
|
|
|
|
expect(config.logs[0].level).toEqual('http');
|
|
|
|
//must not be enabled by default
|
|
|
|
expect(config.notify).toBeUndefined();
|
|
|
|
expect(config.store).toBeUndefined();
|
|
|
|
expect(config.publish).toBeUndefined();
|
|
|
|
expect(config.url_prefix).toBeUndefined();
|
|
|
|
expect(config.url_prefix).toBeUndefined();
|
2017-08-02 20:46:06 +02:00
|
|
|
};
|
2017-08-02 20:45:21 +02:00
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
describe('Config file', () => {
|
|
|
|
beforeAll(function() {
|
2017-08-02 20:45:21 +02:00
|
|
|
|
2018-06-28 18:33:37 +02:00
|
|
|
this.config = new Config(parseConfigFile(resolveConf('full')));
|
2017-08-02 20:45:21 +02:00
|
|
|
});
|
|
|
|
|
2017-08-02 20:46:06 +02:00
|
|
|
describe('Config file', () => {
|
2017-11-01 17:47:20 +01:00
|
|
|
test('parse full.yaml', () => {
|
2018-06-28 18:33:37 +02:00
|
|
|
const config = new Config(parseConfigFile(resolveConf('full')));
|
|
|
|
checkDefaultUplink(config);
|
|
|
|
expect(config.storage).toBe('./storage');
|
|
|
|
checkDefaultConfPackages(config);
|
2017-08-02 20:45:21 +02:00
|
|
|
});
|
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
test('parse docker.yaml', () => {
|
2018-06-28 18:33:37 +02:00
|
|
|
const config = new Config(parseConfigFile(resolveConf('docker')));
|
|
|
|
checkDefaultUplink(config);
|
2018-07-25 18:48:26 +02:00
|
|
|
expect(config.storage).toBe('/verdaccio/storage/data');
|
|
|
|
expect(config.auth.htpasswd.file).toBe('/verdaccio/storage/htpasswd');
|
2018-06-28 18:33:37 +02:00
|
|
|
checkDefaultConfPackages(config);
|
2017-08-02 20:45:21 +02:00
|
|
|
});
|
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
test('parse default.yaml', () => {
|
2018-06-28 18:33:37 +02:00
|
|
|
const config = new Config(parseConfigFile(resolveConf('default')));
|
|
|
|
checkDefaultUplink(config);
|
|
|
|
expect(config.storage).toBe('./storage');
|
|
|
|
expect(config.auth.htpasswd.file).toBe('./htpasswd');
|
|
|
|
checkDefaultConfPackages(config);
|
2017-08-02 20:45:21 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|