mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-27 22:59:51 -05:00
chore: more unit test for config utils
This commit is contained in:
parent
39651bb6b3
commit
91a6c202ff
4 changed files with 56 additions and 6 deletions
|
@ -5,7 +5,7 @@ import minimatch from 'minimatch';
|
|||
|
||||
import {ErrorCode} from './utils';
|
||||
|
||||
import type {PackageList} from '@verdaccio/types';
|
||||
import type {PackageList, UpLinksConfList} from '@verdaccio/types';
|
||||
import type {MatchedPackage} from '../../types';
|
||||
|
||||
const BLACKLIST = {
|
||||
|
@ -41,7 +41,7 @@ export function normalizeUserlist(oldFormat: any, newFormat: any) {
|
|||
return _.flatten(result);
|
||||
}
|
||||
|
||||
export function uplinkSanityCheck(uplinks: any, users: any = BLACKLIST) {
|
||||
export function uplinkSanityCheck(uplinks: UpLinksConfList, users: any = BLACKLIST) {
|
||||
const newUplinks = _.clone(uplinks);
|
||||
let newUsers = _.clone(users);
|
||||
|
||||
|
@ -58,9 +58,9 @@ export function uplinkSanityCheck(uplinks: any, users: any = BLACKLIST) {
|
|||
}
|
||||
|
||||
export function sanityCheckNames(item: string, users: any) {
|
||||
assert(item !== 'all' && item !== 'owner' && item !== 'anonymous' && item !== 'undefined' && item !== 'none', 'CONFIG: reserved user/uplink name: ' + item);
|
||||
assert(!item.match(/\s/), 'CONFIG: invalid user name: ' + item);
|
||||
assert(users[item] == null, 'CONFIG: duplicate user/uplink name: ' + item);
|
||||
assert(item !== 'all' && item !== 'owner' && item !== 'anonymous' && item !== 'undefined' && item !== 'none', 'CONFIG: reserved uplink name: ' + item);
|
||||
assert(!item.match(/\s/), 'CONFIG: invalid uplink name: ' + item);
|
||||
assert(users[item] == null, 'CONFIG: duplicate uplink name: ' + item);
|
||||
users[item] = true;
|
||||
|
||||
return users;
|
||||
|
|
|
@ -3,7 +3,12 @@
|
|||
import path from 'path';
|
||||
import {spliceURL} from '../../../src/utils/string';
|
||||
import {parseConfigFile} from '../../../src/lib/utils';
|
||||
import {getMatchedPackagesSpec, hasProxyTo, normalisePackageAccess} from '../../../src/lib/config-utils';
|
||||
import {
|
||||
getMatchedPackagesSpec,
|
||||
hasProxyTo,
|
||||
normalisePackageAccess, sanityCheckUplinksProps,
|
||||
uplinkSanityCheck
|
||||
} from '../../../src/lib/config-utils';
|
||||
import {PACKAGE_ACCESS, ROLES} from '../../../src/lib/constants';
|
||||
|
||||
describe('Config Utilities', () => {
|
||||
|
@ -12,6 +17,35 @@ describe('Config Utilities', () => {
|
|||
return path.join(__dirname, `../partials/config/yaml/${name}.yaml`);
|
||||
};
|
||||
|
||||
describe('uplinkSanityCheck', () => {
|
||||
test('should test basic conversion', ()=> {
|
||||
const uplinks = uplinkSanityCheck(parseConfigFile(parsePartial('uplink-basic')).uplinks);
|
||||
expect(Object.keys(uplinks)).toContain('server1');
|
||||
expect(Object.keys(uplinks)).toContain('server2');
|
||||
});
|
||||
|
||||
test('should throw error on blacklisted uplink name', ()=> {
|
||||
const {uplinks} = parseConfigFile(parsePartial('uplink-wrong'));
|
||||
|
||||
expect(() => {
|
||||
uplinkSanityCheck(uplinks)
|
||||
}).toThrow('CONFIG: reserved uplink name: anonymous');
|
||||
});
|
||||
});
|
||||
|
||||
describe('sanityCheckUplinksProps', () => {
|
||||
test('should fails if url prop is missing', ()=> {
|
||||
const {uplinks} = parseConfigFile(parsePartial('uplink-wrong'));
|
||||
expect(() => {
|
||||
sanityCheckUplinksProps(uplinks)
|
||||
}).toThrow('CONFIG: no url for uplink: none-url');
|
||||
});
|
||||
|
||||
test('should bypass an empty uplink list', ()=> {
|
||||
expect(sanityCheckUplinksProps([])).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('normalisePackageAccess', () => {
|
||||
test('should test basic conversion', ()=> {
|
||||
const {packages} = parseConfigFile(parsePartial('pkgs-basic'));
|
||||
|
|
7
test/unit/partials/config/yaml/uplink-basic.yaml
Normal file
7
test/unit/partials/config/yaml/uplink-basic.yaml
Normal file
|
@ -0,0 +1,7 @@
|
|||
uplinks:
|
||||
server1:
|
||||
url: http://localhost:55551/
|
||||
maxage: 0
|
||||
server2:
|
||||
url: http://localhost:55551/
|
||||
maxage: 0
|
9
test/unit/partials/config/yaml/uplink-wrong.yaml
Normal file
9
test/unit/partials/config/yaml/uplink-wrong.yaml
Normal file
|
@ -0,0 +1,9 @@
|
|||
uplinks:
|
||||
facebook:
|
||||
url: http://localhost:55551/
|
||||
maxage: 0
|
||||
anonymous:
|
||||
url: http://localhost:55551/
|
||||
maxage: 0
|
||||
none-url:
|
||||
maxage: 0
|
Loading…
Add table
Reference in a new issue