2017-04-19 14:15:28 -05:00
|
|
|
'use strict';
|
|
|
|
|
2014-02-01 03:08:48 -05:00
|
|
|
// ensure that all arguments are validated
|
|
|
|
|
2017-06-11 02:01:13 -05:00
|
|
|
const assert = require('assert');
|
|
|
|
const path = require('path');
|
2014-02-01 03:08:48 -05:00
|
|
|
|
2017-08-05 03:34:31 -05: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);
|
|
|
|
*/
|
2017-11-01 11:47:20 -05:00
|
|
|
describe('api endpoint app.param()', runTest('../endpoint/index.js'));
|
2014-11-13 12:13:37 -05:00
|
|
|
|
2017-11-01 11:47:20 -05:00
|
|
|
function runTest(file) {
|
2014-11-13 12:13:37 -05:00
|
|
|
return function() {
|
2017-06-11 02:01:13 -05:00
|
|
|
|
2017-06-21 12:02:52 -05:00
|
|
|
let requirePath = path.normalize(path.join(__dirname + '/../../src/api/web/', file));
|
2017-06-11 02:01:13 -05:00
|
|
|
let source = require('fs').readFileSync(requirePath, 'utf8');
|
2014-11-13 12:13:37 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
let very_scary_regexp = /\n\s*app\.(\w+)\s*\(\s*(("[^"]*")|('[^']*'))\s*,/g;
|
|
|
|
let m;
|
2017-08-05 03:34:31 -05:00
|
|
|
let appParams = {};
|
2014-11-13 12:13:37 -05:00
|
|
|
|
2017-08-05 03:34:31 -05:00
|
|
|
// look up for matches in the source code
|
2014-11-13 12:13:37 -05:00
|
|
|
while ((m = very_scary_regexp.exec(source)) != null) {
|
2017-04-19 14:15:28 -05:00
|
|
|
if (m[1] === 'set') continue;
|
2014-11-13 12:13:37 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
let inner = m[2].slice(1, m[2].length-1);
|
|
|
|
var t;
|
2014-11-13 12:13:37 -05:00
|
|
|
|
|
|
|
inner.split('/').forEach(function(x) {
|
2017-04-23 13:02:26 -05:00
|
|
|
t = x.match(/^:([^?:]*)\??$/);
|
2014-11-13 12:13:37 -05:00
|
|
|
if (m[1] === 'param') {
|
2017-08-05 03:34:31 -05:00
|
|
|
appParams[x] = 'ok';
|
2017-04-23 13:02:26 -05:00
|
|
|
} else if (t) {
|
2017-08-05 03:34:31 -05:00
|
|
|
appParams[t[1]] = appParams[t[1]] || m[0].trim();
|
2014-11-13 12:13:37 -05:00
|
|
|
}
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2014-11-13 12:13:37 -05:00
|
|
|
}
|
|
|
|
|
2017-11-01 11:47:20 -05:00
|
|
|
|
|
|
|
Object.keys(appParams).forEach(function(param) {
|
|
|
|
test('should validate ":'+param+'"', () => {
|
|
|
|
assert.equal(appParams[param], 'ok');
|
|
|
|
});
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
|
|
|
};
|
2014-11-13 12:13:37 -05:00
|
|
|
}
|
2014-02-01 03:08:48 -05:00
|
|
|
|