2018-06-28 18:33:37 +02:00
|
|
|
import path from 'path';
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
2020-03-03 23:59:19 +01:00
|
|
|
import { setup } from '@verdaccio/logger';
|
2020-08-13 23:27:00 +02:00
|
|
|
import { DEFAULT_REGISTRY, DEFAULT_UPLINK, ROLES, WEB_TITLE } from '@verdaccio/dev-commons';
|
2020-03-03 23:59:19 +01:00
|
|
|
|
2020-08-13 23:27:00 +02:00
|
|
|
import { parseConfigFile } from '@verdaccio/utils';
|
|
|
|
import { Config, readDefaultConfig } from '../src';
|
2019-07-16 08:40:01 +02:00
|
|
|
|
|
|
|
setup([]);
|
2017-08-02 20:45:21 +02:00
|
|
|
|
2019-05-22 07:50:14 +02:00
|
|
|
const resolveConf = (conf) => {
|
|
|
|
const { name, ext } = path.parse(conf);
|
|
|
|
|
2020-03-03 23:59:19 +01:00
|
|
|
return path.join(__dirname, `../src/conf/${name}${ext.startsWith('.') ? ext : '.yaml'}`);
|
2019-05-22 07:50:14 +02:00
|
|
|
};
|
2020-03-03 23:59:19 +01: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) => {
|
2019-12-23 09:29:27 +01:00
|
|
|
// auth
|
2018-06-28 18:33:37 +02:00
|
|
|
expect(_.isObject(config.auth)).toBeTruthy();
|
|
|
|
expect(_.isObject(config.auth.htpasswd)).toBeTruthy();
|
|
|
|
expect(config.auth.htpasswd.file).toMatch(/htpasswd/);
|
|
|
|
|
2019-12-23 09:29:27 +01:00
|
|
|
// web
|
2018-06-28 18:33:37 +02:00
|
|
|
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();
|
2020-08-13 23:27:00 +02:00
|
|
|
expect(config.packages['**'].proxy).toContainEqual(DEFAULT_UPLINK);
|
2018-06-28 18:33:37 +02:00
|
|
|
// 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
|
2020-04-13 14:34:26 +02:00
|
|
|
expect(config.logs).toBeDefined();
|
2021-03-30 20:32:46 +02:00
|
|
|
expect(config.logs.type).toEqual('stdout');
|
|
|
|
expect(config.logs.format).toEqual('pretty');
|
|
|
|
expect(config.logs.level).toEqual('http');
|
2019-12-23 09:29:27 +01:00
|
|
|
// must not be enabled by default
|
2018-06-28 18:33:37 +02:00
|
|
|
expect(config.notify).toBeUndefined();
|
|
|
|
expect(config.store).toBeUndefined();
|
|
|
|
expect(config.publish).toBeUndefined();
|
|
|
|
expect(config.url_prefix).toBeUndefined();
|
|
|
|
expect(config.url_prefix).toBeUndefined();
|
2019-10-02 20:56:50 +02:00
|
|
|
|
|
|
|
expect(config.experiments).toBeUndefined();
|
2019-10-02 20:59:39 +02:00
|
|
|
expect(config.security).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', () => {
|
2020-08-13 23:27:00 +02:00
|
|
|
beforeAll(function () {
|
2019-12-23 09:29:27 +01:00
|
|
|
/* eslint no-invalid-this: 0 */
|
2019-08-16 21:20:18 +02:00
|
|
|
// @ts-ignore
|
2018-08-20 16:31:39 +02:00
|
|
|
this.config = new Config(parseConfigFile(resolveConf('default')));
|
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 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');
|
2019-07-16 08:40:01 +02:00
|
|
|
// @ts-ignore
|
2018-07-25 18:48:26 +02:00
|
|
|
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');
|
2019-07-16 08:40:01 +02:00
|
|
|
// @ts-ignore
|
2018-06-28 18:33:37 +02:00
|
|
|
expect(config.auth.htpasswd.file).toBe('./htpasswd');
|
|
|
|
checkDefaultConfPackages(config);
|
2017-08-02 20:45:21 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-13 23:27:00 +02:00
|
|
|
describe('Config file', () => {});
|
2017-08-02 20:45:21 +02:00
|
|
|
});
|