mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-06 22:40:26 -05:00
chore(config): increase test coverage (#4382)
* chore(config): increase test coverage * adjust length (32 bytes in hex)
This commit is contained in:
parent
e1efd79b60
commit
4d9632424d
7 changed files with 111 additions and 4 deletions
5
.changeset/young-donuts-own.md
Normal file
5
.changeset/young-donuts-own.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@verdaccio/config': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
chore(config): increase test coverage
|
|
@ -3,8 +3,7 @@ const config = require('../../jest/config');
|
||||||
module.exports = Object.assign({}, config, {
|
module.exports = Object.assign({}, config, {
|
||||||
coverageThreshold: {
|
coverageThreshold: {
|
||||||
global: {
|
global: {
|
||||||
// FIXME: increase to 90
|
lines: 90,
|
||||||
lines: 85,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,7 +27,7 @@ export const PACKAGE_ACCESS = {
|
||||||
|
|
||||||
export function normalizeUserList(groupsList: any): any {
|
export function normalizeUserList(groupsList: any): any {
|
||||||
const result: any[] = [];
|
const result: any[] = [];
|
||||||
if (_.isNil(groupsList)) {
|
if (_.isNil(groupsList) || _.isEmpty(groupsList)) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
42
packages/config/test/agent.spec.ts
Normal file
42
packages/config/test/agent.spec.ts
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import { getUserAgent } from '../src';
|
||||||
|
|
||||||
|
describe('getUserAgent', () => {
|
||||||
|
test('should return custom user agent when customUserAgent is true', () => {
|
||||||
|
const customUserAgent = true;
|
||||||
|
const version = '1.0.0';
|
||||||
|
const name = 'MyAgent';
|
||||||
|
|
||||||
|
const result = getUserAgent(customUserAgent, version, name);
|
||||||
|
|
||||||
|
expect(result).toBe('MyAgent/1.0.0');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should return custom user agent when customUserAgent is a non-empty string', () => {
|
||||||
|
const customUserAgent = 'CustomAgent/1.0.0';
|
||||||
|
const version = '1.0.0';
|
||||||
|
const name = 'MyAgent';
|
||||||
|
|
||||||
|
const result = getUserAgent(customUserAgent, version, name);
|
||||||
|
|
||||||
|
expect(result).toBe('CustomAgent/1.0.0');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should return "hidden" when customUserAgent is false', () => {
|
||||||
|
const customUserAgent = false;
|
||||||
|
const version = '1.0.0';
|
||||||
|
const name = 'MyAgent';
|
||||||
|
|
||||||
|
const result = getUserAgent(customUserAgent, version, name);
|
||||||
|
|
||||||
|
expect(result).toBe('hidden');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should return default user agent when customUserAgent is undefined', () => {
|
||||||
|
const version = '1.0.0';
|
||||||
|
const name = 'MyAgent';
|
||||||
|
|
||||||
|
const result = getUserAgent(undefined, version, name);
|
||||||
|
|
||||||
|
expect(result).toBe('MyAgent/1.0.0');
|
||||||
|
});
|
||||||
|
});
|
|
@ -13,6 +13,7 @@ describe('Config builder', () => {
|
||||||
proxy: 'some',
|
proxy: 'some',
|
||||||
})
|
})
|
||||||
.addLogger({ level: 'info', type: 'stdout', format: 'json' })
|
.addLogger({ level: 'info', type: 'stdout', format: 'json' })
|
||||||
|
.addAuth({ htpasswd: { file: '.htpasswd' } })
|
||||||
.addStorage('/tmp/verdaccio')
|
.addStorage('/tmp/verdaccio')
|
||||||
.addSecurity({ api: { legacy: true } });
|
.addSecurity({ api: { legacy: true } });
|
||||||
expect(config.getConfig()).toEqual({
|
expect(config.getConfig()).toEqual({
|
||||||
|
@ -21,6 +22,11 @@ describe('Config builder', () => {
|
||||||
legacy: true,
|
legacy: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
auth: {
|
||||||
|
htpasswd: {
|
||||||
|
file: '.htpasswd',
|
||||||
|
},
|
||||||
|
},
|
||||||
storage: '/tmp/verdaccio',
|
storage: '/tmp/verdaccio',
|
||||||
packages: {
|
packages: {
|
||||||
'upstream/*': {
|
'upstream/*': {
|
||||||
|
|
|
@ -106,6 +106,20 @@ describe('checkSecretKey', () => {
|
||||||
const config = new Config(parseConfigFile(resolveConf('default')));
|
const config = new Config(parseConfigFile(resolveConf('default')));
|
||||||
expect(typeof config.checkSecretKey('') === 'string').toBeTruthy();
|
expect(typeof config.checkSecretKey('') === 'string').toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('with enhanced legacy signature', () => {
|
||||||
|
const config = new Config(parseConfigFile(resolveConf('default')));
|
||||||
|
config.security.enhancedLegacySignature = true;
|
||||||
|
expect(typeof config.checkSecretKey() === 'string').toBeTruthy();
|
||||||
|
expect(config.secret.length).toBe(32);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('without enhanced legacy signature', () => {
|
||||||
|
const config = new Config(parseConfigFile(resolveConf('default')));
|
||||||
|
config.security.enhancedLegacySignature = false;
|
||||||
|
expect(typeof config.checkSecretKey() === 'string').toBeTruthy();
|
||||||
|
expect(config.secret.length).toBe(64);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getMatchedPackagesSpec', () => {
|
describe('getMatchedPackagesSpec', () => {
|
||||||
|
@ -159,3 +173,18 @@ describe('VERDACCIO_STORAGE_PATH', () => {
|
||||||
delete process.env.VERDACCIO_STORAGE_PATH;
|
delete process.env.VERDACCIO_STORAGE_PATH;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('configPath', () => {
|
||||||
|
test('should set configPath in config', () => {
|
||||||
|
const defaultConfig = parseConfigFile(resolveConf('default'));
|
||||||
|
const config = new Config(defaultConfig);
|
||||||
|
expect(config.getConfigPath()).toBe(path.join(__dirname, '../src/conf/default.yaml'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should throw an error if configPath is not provided', () => {
|
||||||
|
const defaultConfig = parseConfigFile(resolveConf('default'));
|
||||||
|
defaultConfig.configPath = '';
|
||||||
|
defaultConfig.config_path = '';
|
||||||
|
expect(() => new Config(defaultConfig)).toThrow('configPath property is required');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
import { parseConfigFile } from '../src';
|
import { parseConfigFile } from '../src';
|
||||||
import { PACKAGE_ACCESS, normalisePackageAccess } from '../src/package-access';
|
import { PACKAGE_ACCESS, normalisePackageAccess, normalizeUserList } from '../src/package-access';
|
||||||
import { parseConfigurationFile } from './utils';
|
import { parseConfigurationFile } from './utils';
|
||||||
|
|
||||||
describe('Package access utilities', () => {
|
describe('Package access utilities', () => {
|
||||||
|
@ -123,4 +123,30 @@ describe('Package access utilities', () => {
|
||||||
expect(_.isArray(all.publish)).toBeTruthy();
|
expect(_.isArray(all.publish)).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('normaliseUserList', () => {
|
||||||
|
test('should normalize user list', () => {
|
||||||
|
const groupsList = 'admin superadmin';
|
||||||
|
const result = normalizeUserList(groupsList);
|
||||||
|
expect(result).toEqual(['admin', 'superadmin']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should normalize empty user list', () => {
|
||||||
|
const groupsList = '';
|
||||||
|
const result = normalizeUserList(groupsList);
|
||||||
|
expect(result).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should normalize user list array', () => {
|
||||||
|
const groupsList = ['admin', 'superadmin'];
|
||||||
|
const result = normalizeUserList(groupsList);
|
||||||
|
expect(result).toEqual(['admin', 'superadmin']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should throw error for invalid user list', () => {
|
||||||
|
const groupsList = { group: 'admin' };
|
||||||
|
expect(() => {
|
||||||
|
normalizeUserList(groupsList);
|
||||||
|
}).toThrow('CONFIG: bad package acl (array or string expected): {"group":"admin"}');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue