mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-08 23:25:51 +01:00
fix: configuration files inconsistencies, add unit test
This commit is contained in:
parent
cda92ac5ab
commit
644c0981db
@ -29,7 +29,7 @@ packages:
|
|||||||
'@*/*':
|
'@*/*':
|
||||||
# scoped packages
|
# scoped packages
|
||||||
access: $all
|
access: $all
|
||||||
publish: $all
|
publish: $authenticated
|
||||||
proxy: npmjs
|
proxy: npmjs
|
||||||
|
|
||||||
'**':
|
'**':
|
||||||
@ -42,7 +42,7 @@ packages:
|
|||||||
|
|
||||||
# allow all known users to publish packages
|
# allow all known users to publish packages
|
||||||
# (anyone can register by default, remember?)
|
# (anyone can register by default, remember?)
|
||||||
publish: $all
|
publish: $authenticated
|
||||||
|
|
||||||
# if package is not available locally, proxy requests to 'npmjs' registry
|
# if package is not available locally, proxy requests to 'npmjs' registry
|
||||||
proxy: npmjs
|
proxy: npmjs
|
||||||
|
@ -67,6 +67,11 @@ uplinks:
|
|||||||
#cache: false
|
#cache: false
|
||||||
|
|
||||||
packages:
|
packages:
|
||||||
|
'@*/*':
|
||||||
|
# scoped packages
|
||||||
|
access: $all
|
||||||
|
publish: $authenticated
|
||||||
|
proxy: npmjs
|
||||||
# uncomment this for packages with "local-" prefix to be available
|
# uncomment this for packages with "local-" prefix to be available
|
||||||
# for admin only, it's a recommended way of handling private packages
|
# for admin only, it's a recommended way of handling private packages
|
||||||
#'local-*':
|
#'local-*':
|
||||||
@ -83,7 +88,7 @@ packages:
|
|||||||
access: $all
|
access: $all
|
||||||
|
|
||||||
# allow 'admin' to publish packages
|
# allow 'admin' to publish packages
|
||||||
publish: admin
|
publish: $authenticated
|
||||||
|
|
||||||
# if package is not available locally, proxy requests to 'npmjs' registry
|
# if package is not available locally, proxy requests to 'npmjs' registry
|
||||||
proxy: npmjs
|
proxy: npmjs
|
||||||
@ -169,7 +174,7 @@ notify:
|
|||||||
# content: '{ "text": "Package *{{ name }}* published to version *{{ dist-tags.latest }}*", "username": "Verdaccio", "icon_emoji": ":package:" }'
|
# content: '{ "text": "Package *{{ name }}* published to version *{{ dist-tags.latest }}*", "username": "Verdaccio", "icon_emoji": ":package:" }'
|
||||||
|
|
||||||
# Multiple notification endpoints can be created by specifying a collection
|
# Multiple notification endpoints can be created by specifying a collection
|
||||||
'example-package-1'
|
'example-package-1':
|
||||||
method: POST
|
method: POST
|
||||||
# Only run this notification if the package name matches the regular
|
# Only run this notification if the package name matches the regular
|
||||||
# expression
|
# expression
|
||||||
@ -180,7 +185,6 @@ notify:
|
|||||||
# packagePatternFlags: i
|
# packagePatternFlags: i
|
||||||
# If this endpoint requires specific headers, set them here
|
# If this endpoint requires specific headers, set them here
|
||||||
# as an array of key: value objects.
|
# as an array of key: value objects.
|
||||||
headers: [{'Content-type': 'application/x-www-form-urlencoded'}]
|
|
||||||
# headers supports as well a literal object
|
# headers supports as well a literal object
|
||||||
headers: {'Content-type': 'application/x-www-form-urlencoded'}
|
headers: {'Content-type': 'application/x-www-form-urlencoded'}
|
||||||
# set the URL endpoint for this call
|
# set the URL endpoint for this call
|
||||||
|
@ -70,9 +70,10 @@ class Config {
|
|||||||
assert(!arg.match(/\s/), 'CONFIG: invalid user name: ' + arg);
|
assert(!arg.match(/\s/), 'CONFIG: invalid user name: ' + arg);
|
||||||
assert(users[arg] == null, 'CONFIG: duplicate user/uplink name: ' + arg);
|
assert(users[arg] == null, 'CONFIG: duplicate user/uplink name: ' + arg);
|
||||||
users[arg] = true;
|
users[arg] = true;
|
||||||
}
|
};
|
||||||
|
|
||||||
// sanity check for strategic config properties
|
// sanity check for strategic config properties
|
||||||
;['users', 'uplinks', 'packages'].forEach(function(x) {
|
['users', 'uplinks', 'packages'].forEach(function(x) {
|
||||||
if (self[x] == null) self[x] = {};
|
if (self[x] == null) self[x] = {};
|
||||||
assert(Utils.is_object(self[x]), `CONFIG: bad "${x}" value (object expected)`);
|
assert(Utils.is_object(self[x]), `CONFIG: bad "${x}" value (object expected)`);
|
||||||
});
|
});
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const semver = require('semver');
|
const semver = require('semver');
|
||||||
|
const YAML = require('js-yaml');
|
||||||
const URL = require('url');
|
const URL = require('url');
|
||||||
|
const fs = require('fs');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const Logger = require('./logger');
|
const Logger = require('./logger');
|
||||||
const createError = require('http-errors');
|
const createError = require('http-errors');
|
||||||
@ -348,6 +350,8 @@ const ErrorCode = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const parseConfigFile = (config_path) => YAML.safeLoad(fs.readFileSync(config_path, 'utf8'));
|
||||||
|
|
||||||
module.exports.parseInterval = parseInterval;
|
module.exports.parseInterval = parseInterval;
|
||||||
module.exports.semver_sort = semverSort;
|
module.exports.semver_sort = semverSort;
|
||||||
module.exports.parse_address = parse_address;
|
module.exports.parse_address = parse_address;
|
||||||
@ -363,3 +367,4 @@ module.exports.validate_package = validate_package;
|
|||||||
module.exports.getWebProtocol = getWebProtocol;
|
module.exports.getWebProtocol = getWebProtocol;
|
||||||
module.exports.getLatestVersion = getLatestVersion;
|
module.exports.getLatestVersion = getLatestVersion;
|
||||||
module.exports.ErrorCode = ErrorCode;
|
module.exports.ErrorCode = ErrorCode;
|
||||||
|
module.exports.parseConfigFile = parseConfigFile;
|
||||||
|
@ -6,14 +6,24 @@ const Config = require('../../src/lib/config');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
const resolveConf = (conf) => {
|
const resolveConf = (conf) => path.join(__dirname, `../../conf/${conf}.yaml`);
|
||||||
const fullConfigPath = path.join(__dirname, `../../conf/${conf}.yaml`);
|
|
||||||
return fullConfigPath;
|
const checkUplink = (config) => {
|
||||||
|
assert.equal(_.isObject(config.uplinks['npmjs']), true);
|
||||||
|
assert.equal(config.uplinks['npmjs'].url, 'https://registry.npmjs.org');
|
||||||
};
|
};
|
||||||
|
|
||||||
const validateConfigFile = (config) => {
|
const checkPackages = (config) => {
|
||||||
assert.ok(_.isObject(config.uplinks['npmjs']));
|
assert.equal(_.isObject(config.packages), true);
|
||||||
}
|
assert.equal(Object.keys(config.packages).join('|'), '@*/*|**');
|
||||||
|
assert.equal(config.packages['@*/*'].access, '$all');
|
||||||
|
assert.equal(config.packages['@*/*'].publish, '$authenticated');
|
||||||
|
assert.equal(config.packages['@*/*'].proxy, 'npmjs');
|
||||||
|
assert.equal(config.packages['**'].access, '$all');
|
||||||
|
assert.equal(config.packages['**'].publish, '$authenticated');
|
||||||
|
assert.equal(config.packages['**'].proxy, 'npmjs');
|
||||||
|
assert.equal(config.uplinks['npmjs'].url, 'https://registry.npmjs.org');
|
||||||
|
};
|
||||||
|
|
||||||
describe('Config file', function() {
|
describe('Config file', function() {
|
||||||
before(function() {
|
before(function() {
|
||||||
@ -21,25 +31,29 @@ describe('Config file', function() {
|
|||||||
this.config = new Config(Utils.parseConfigFile(resolveConf('full')));
|
this.config = new Config(Utils.parseConfigFile(resolveConf('full')));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Config file', function() {
|
describe('Config file', () => {
|
||||||
it('parse full.yaml', function () {
|
it('parse full.yaml', () => {
|
||||||
const config = new Config(Utils.parseConfigFile(resolveConf('full')));
|
const config = new Config(Utils.parseConfigFile(resolveConf('full')));
|
||||||
validateConfigFile(config);
|
checkUplink(config);
|
||||||
|
assert.equal(config.storage, './storage');
|
||||||
|
assert.equal(config.web.title, 'Verdaccio');
|
||||||
|
checkPackages(config);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('parse docker.yaml', function () {
|
it('parse docker.yaml', () => {
|
||||||
const config = new Config(Utils.parseConfigFile(resolveConf('docker')));
|
const config = new Config(Utils.parseConfigFile(resolveConf('docker')));
|
||||||
validateConfigFile(config);
|
checkUplink(config);
|
||||||
|
assert.equal(config.storage, '/verdaccio/storage');
|
||||||
|
assert.equal(config.auth.htpasswd.file, '/verdaccio/conf/htpasswd');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('parse default.yaml', function () {
|
it('parse default.yaml', () => {
|
||||||
const config = new Config(Utils.parseConfigFile(resolveConf('default')));
|
const config = new Config(Utils.parseConfigFile(resolveConf('default')));
|
||||||
validateConfigFile(config);
|
checkUplink(config);
|
||||||
|
assert.equal(config.storage, './storage');
|
||||||
|
assert.equal(config.auth.htpasswd.file, './htpasswd');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('npmjs uplink should have a default cache option that is true', () => {
|
|
||||||
assert.equal(this.config.uplinks['npmjs'].cache, true);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user