Add query param validation to remaining new-style services [azuredevops appveyor npm] (#3164)
Remove now-obsolete code. Close #2675
This commit is contained in:
@@ -106,9 +106,7 @@ module.exports = class BaseService {
|
||||
* - capture: Array of names for the capture groups in the regular
|
||||
* expression. The handler will be passed an object containing
|
||||
* the matches.
|
||||
* - queryParams: Array of names for query parameters which will the service
|
||||
* uses. For cache safety, only the whitelisted query
|
||||
* parameters will be passed to the handler.
|
||||
* - queryParamSchema: Joi schema for valid query params.
|
||||
*/
|
||||
static get route() {
|
||||
throw new Error(`Route not defined for ${this.name}`)
|
||||
|
||||
@@ -18,10 +18,8 @@ const isValidRoute = Joi.object({
|
||||
then: Joi.array().items(Joi.string().required()),
|
||||
}),
|
||||
queryParamSchema: Joi.object().schema(),
|
||||
queryParams: Joi.array().items(Joi.string().required()),
|
||||
})
|
||||
.xor('pattern', 'format')
|
||||
.oxor('queryParamSchema', 'queryParams')
|
||||
.required()
|
||||
|
||||
function assertValidRoute(route, message = undefined) {
|
||||
@@ -71,12 +69,12 @@ function namedParamsForMatch(captureNames = [], match, ServiceClass) {
|
||||
return result
|
||||
}
|
||||
|
||||
function getQueryParamNames({ queryParams = [], queryParamSchema }) {
|
||||
function getQueryParamNames({ queryParamSchema }) {
|
||||
if (queryParamSchema) {
|
||||
const { children, renames = [] } = Joi.describe(queryParamSchema)
|
||||
return Object.keys(children).concat(renames.map(({ from }) => from))
|
||||
} else {
|
||||
return queryParams
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ describe('Route helpers', function() {
|
||||
const { regex, captureNames } = prepareRoute({
|
||||
base: 'foo',
|
||||
pattern: ':namedParamA',
|
||||
queryParams: ['queryParamA'],
|
||||
queryParamSchema: Joi.object({ queryParamA: Joi.string() }).required(),
|
||||
})
|
||||
|
||||
const regexExec = str => regex.exec(str)
|
||||
@@ -108,7 +108,6 @@ describe('Route helpers', function() {
|
||||
})
|
||||
|
||||
it('getQueryParamNames', function() {
|
||||
expect(getQueryParamNames({ queryParams: ['foo'] })).to.deep.equal(['foo'])
|
||||
expect(
|
||||
getQueryParamNames({
|
||||
queryParamSchema: Joi.object({ foo: Joi.string() }).required(),
|
||||
|
||||
Reference in New Issue
Block a user