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