0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-02-03 23:09:17 -05:00
verdaccio/test/unit/modules/api/legacy/validate.api.params.middleware.spec.ts
Juan Picado bae430fe24
feat: refactor test and use verdaccio 6 core modules (#3569)
chore: clean up comments

remove commitlint

update deps

add new tests

test

separate ci

test

test

test

test

test

test

chore: add preprelase

test

test

test

test

test

chore: update deps

Update release-snapshot.yml

Update .npmignore

test

chore: remove @verdaccio/commons-api dep

chore: cleanup

remove normalizeContributors

remove validateMetadata

fix test

clean up getLocalRegistryTarballUri

Update store.spec.ts

clean up convertDistRemoteToLocalTarballUrls

chore: update libraries

reuse getPublic url

clean up

Update jest.config.js

Update jest.config.js

update nvmrc

add tests
2023-01-28 14:39:37 +01:00

43 lines
1.2 KiB
TypeScript

// ensure that all arguments are validated
import fs from 'fs';
import path from 'path';
/**
* 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);
*/
describe('api endpoint app.param()', () => {
const file = '../endpoint/index.ts';
let m;
const requirePath = path.normalize(path.join(__dirname + '/../../../../../src/api/web/', file));
const source = fs.readFileSync(requirePath, 'utf8');
const very_scary_regexp = /\n\s*app\.(\w+)\s*\(\s*(("[^"]*")|('[^']*'))\s*,/g;
const appParams = {};
while ((m = very_scary_regexp.exec(source)) != null) {
if (m[1] === 'set') {
continue;
}
let inner = m[2].slice(1, m[2].length - 1);
let t;
inner.split('/').forEach(function (x) {
t = x.match(/^:([^?:]*)\??$/);
if (m[1] === 'param') {
appParams[x] = 'ok';
} else if (t) {
appParams[t[1]] = appParams[t[1]] || m[0].trim();
}
});
}
test.each(Object.keys(appParams))('should validate ":%s"', (param) => {
expect(appParams[param]).toEqual('ok');
});
});