2018-06-28 11:33:37 -05:00
|
|
|
import _ from 'lodash';
|
2021-10-29 10:33:05 -05:00
|
|
|
import path from 'path';
|
2018-06-28 11:33:37 -05:00
|
|
|
|
2020-11-15 05:14:09 -05:00
|
|
|
import {
|
|
|
|
Config,
|
|
|
|
DEFAULT_REGISTRY,
|
|
|
|
DEFAULT_UPLINK,
|
|
|
|
ROLES,
|
|
|
|
WEB_TITLE,
|
2021-10-29 10:33:05 -05:00
|
|
|
defaultSecurity,
|
2022-08-02 15:45:16 -05:00
|
|
|
getDefaultConfig,
|
2021-10-29 10:33:05 -05:00
|
|
|
parseConfigFile,
|
2020-11-15 05:14:09 -05:00
|
|
|
} from '../src';
|
2021-04-25 03:08:14 -05:00
|
|
|
import { parseConfigurationFile } from './utils';
|
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
|
|
|
};
|
|
|
|
|
2020-11-08 09:20:02 -05:00
|
|
|
describe('check basic content parsed file', () => {
|
2021-05-08 17:44:07 -05: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();
|
2022-03-28 13:02:08 -05:00
|
|
|
// log
|
|
|
|
expect(config.log).toBeDefined();
|
|
|
|
expect(config.log.type).toEqual('stdout');
|
|
|
|
expect(config.log.format).toEqual('pretty');
|
|
|
|
expect(config.log.level).toEqual('http');
|
2021-05-08 17:44:07 -05:00
|
|
|
// 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();
|
|
|
|
|
|
|
|
expect(config.experiments).toBeUndefined();
|
|
|
|
expect(config.security).toEqual(defaultSecurity);
|
|
|
|
};
|
|
|
|
|
2020-11-08 09:20:02 -05:00
|
|
|
test('parse default.yaml', () => {
|
2022-08-02 15:45:16 -05:00
|
|
|
const config = new Config(getDefaultConfig());
|
2020-11-08 09:20:02 -05:00
|
|
|
checkDefaultUplink(config);
|
|
|
|
expect(config.storage).toBe('./storage');
|
|
|
|
expect(config.auth.htpasswd.file).toBe('./htpasswd');
|
|
|
|
checkDefaultConfPackages(config);
|
2017-08-02 13:45:21 -05:00
|
|
|
});
|
|
|
|
|
2021-05-08 17:44:07 -05:00
|
|
|
test('parse docker.yaml', () => {
|
2022-08-02 15:45:16 -05:00
|
|
|
const config = new Config(getDefaultConfig('docker.yaml'));
|
2021-05-08 17:44:07 -05:00
|
|
|
checkDefaultUplink(config);
|
|
|
|
expect(config.storage).toBe('/verdaccio/storage/data');
|
|
|
|
expect(config.auth.htpasswd.file).toBe('/verdaccio/storage/htpasswd');
|
|
|
|
checkDefaultConfPackages(config);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('checkSecretKey', () => {
|
|
|
|
test('with default.yaml and pre selected secret', () => {
|
|
|
|
const config = new Config(parseConfigFile(resolveConf('default')));
|
|
|
|
expect(config.checkSecretKey('12345')).toEqual('12345');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('with default.yaml and void secret', () => {
|
|
|
|
const config = new Config(parseConfigFile(resolveConf('default')));
|
|
|
|
expect(typeof config.checkSecretKey() === 'string').toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('with default.yaml and emtpy string secret', () => {
|
|
|
|
const config = new Config(parseConfigFile(resolveConf('default')));
|
|
|
|
expect(typeof config.checkSecretKey('') === 'string').toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getMatchedPackagesSpec', () => {
|
|
|
|
test('should match with react as defined in config file', () => {
|
|
|
|
const configParsed = parseConfigFile(parseConfigurationFile('config-getMatchedPackagesSpec'));
|
|
|
|
const config = new Config(configParsed);
|
|
|
|
expect(config.getMatchedPackagesSpec('react')).toEqual({
|
|
|
|
access: ['admin'],
|
|
|
|
proxy: ['facebook'],
|
|
|
|
publish: ['admin'],
|
|
|
|
unpublish: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should not match with react as defined in config file', () => {
|
|
|
|
const configParsed = parseConfigFile(parseConfigurationFile('config-getMatchedPackagesSpec'));
|
|
|
|
const config = new Config(configParsed);
|
|
|
|
expect(config.getMatchedPackagesSpec('somePackage')).toEqual({
|
|
|
|
access: [ROLES.$ALL],
|
|
|
|
proxy: ['npmjs'],
|
|
|
|
publish: [ROLES.$AUTH],
|
|
|
|
unpublish: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('VERDACCIO_STORAGE_PATH', () => {
|
2021-04-25 03:08:14 -05:00
|
|
|
test('should set storage to value set in VERDACCIO_STORAGE_PATH environment variable', () => {
|
|
|
|
const storageLocation = '/tmp/verdaccio';
|
|
|
|
process.env.VERDACCIO_STORAGE_PATH = storageLocation;
|
|
|
|
const config = new Config(parseConfigFile(resolveConf('default')));
|
|
|
|
expect(config.storage).toBe(storageLocation);
|
|
|
|
delete process.env.VERDACCIO_STORAGE_PATH;
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should set storage path to VERDACCIO_STORAGE_PATH if both config and env are set', () => {
|
|
|
|
const storageLocation = '/tmp/verdaccio';
|
|
|
|
process.env.VERDACCIO_STORAGE_PATH = storageLocation;
|
|
|
|
const config = new Config(parseConfigFile(parseConfigurationFile('storage')));
|
|
|
|
expect(config.storage).toBe(storageLocation);
|
|
|
|
delete process.env.VERDACCIO_STORAGE_PATH;
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should take storage from environment variable if not exists in configs', () => {
|
|
|
|
const storageLocation = '/tmp/verdaccio';
|
|
|
|
process.env.VERDACCIO_STORAGE_PATH = storageLocation;
|
|
|
|
const defaultConfig = parseConfigFile(resolveConf('default'));
|
|
|
|
delete defaultConfig.storage;
|
|
|
|
const config = new Config(defaultConfig);
|
|
|
|
expect(config.storage).toBe(storageLocation);
|
|
|
|
delete process.env.VERDACCIO_STORAGE_PATH;
|
|
|
|
});
|
2017-08-02 13:45:21 -05:00
|
|
|
});
|