1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/test/unit/api/validate_all.spec.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-02-01 09:08:48 +01:00
// ensure that all arguments are validated
const path = require('path');
2014-02-01 09:08:48 +01:00
2017-08-05 10:34:31 +02:00
/**
* Validate.
app.param('package', validate_pkg);
app.param('filename', validate_name);
app.param('tag', validate_name);
app.param('version', validate_name);
app.param('revision', validate_name);
app.param('token', validate_name);
*/
2018-12-16 21:34:14 +01:00
describe('api endpoint app.param()', () => runTest('../endpoint/index.js'));
2017-11-01 17:47:20 +01:00
function runTest(file) {
return function() {
2017-04-19 21:15:28 +02:00
let m;
const requirePath = path.normalize(path.join(__dirname + '/../../../src/api/web/', file));
const source = require('fs').readFileSync(requirePath, 'utf8');
const very_scary_regexp = /\n\s*app\.(\w+)\s*\(\s*(("[^"]*")|('[^']*'))\s*,/g;
const appParams = {};
2017-08-05 10:34:31 +02:00
// look up for matches in the source code
while ((m = very_scary_regexp.exec(source)) != null) {
2017-04-19 21:15:28 +02:00
if (m[1] === 'set') continue;
2017-04-19 21:15:28 +02:00
let inner = m[2].slice(1, m[2].length-1);
var t;
inner.split('/').forEach(function(x) {
t = x.match(/^:([^?:]*)\??$/);
if (m[1] === 'param') {
2017-08-05 10:34:31 +02:00
appParams[x] = 'ok';
} else if (t) {
2017-08-05 10:34:31 +02:00
appParams[t[1]] = appParams[t[1]] || m[0].trim();
}
2017-04-19 21:15:28 +02:00
});
}
Object.keys(appParams).forEach(function(param) {
test('should validate ":'+param+'"', () => {
expect(appParams[param]).toEqual('ok');
});
});
2017-04-19 21:15:28 +02:00
};
}
2014-02-01 09:08:48 +01:00