Using Joi.object when configuring route validation (#24596)

* Using Joi.object when configuring route validation

* Adding forgotten API

* Fixing test
This commit is contained in:
Brandon Kobel 2018-11-01 05:32:12 -07:00 committed by GitHub
parent 157477a2d7
commit 70f1a4094e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 18 additions and 18 deletions

View file

@ -26,9 +26,9 @@ export function registerKqlTelemetryApi(server) {
method: 'POST',
config: {
validate: {
payload: {
payload: Joi.object({
opt_in: Joi.bool().required(),
},
}),
},
tags: ['api'],
},

View file

@ -51,10 +51,10 @@ export function registerStatsApi(kbnServer, server, config) {
path: '/api/stats',
config: {
validate: {
query: {
query: Joi.object({
extended: Joi.string().valid('', 'true', 'false'),
legacy: Joi.string().valid('', 'true', 'false')
}
})
},
tags: ['api'],
},

View file

@ -6,7 +6,7 @@
import Joi from 'joi';
export const userSchema = {
export const userSchema = Joi.object({
username: Joi.string().required(),
password: Joi.string(),
roles: Joi.array().items(Joi.string()),
@ -14,4 +14,4 @@ export const userSchema = {
email: Joi.string().allow(null, ''),
metadata: Joi.object(),
enabled: Joi.boolean().default(true)
};
});

View file

@ -62,10 +62,10 @@ describe('Authentication routes', () => {
expect(loginRoute.config).to.eql({
auth: false,
validate: {
payload: {
payload: Joi.object({
username: Joi.string().required(),
password: Joi.string().required()
}
})
},
response: {
emptyStatusCode: 204,
@ -304,10 +304,10 @@ describe('Authentication routes', () => {
expect(samlAcsRoute.config).to.eql({
auth: false,
validate: {
payload: {
payload: Joi.object({
SAMLResponse: Joi.string().required(),
RelayState: Joi.string().allow('')
}
})
}
});
});

View file

@ -60,10 +60,10 @@ describe('User routes', () => {
expect(changePasswordRoute.config).to.have.property('pre');
expect(changePasswordRoute.config.pre).to.have.length(1);
expect(changePasswordRoute.config.validate).to.eql({
payload: {
payload: Joi.object({
password: Joi.string(),
newPassword: Joi.string().required()
}
})
});
});

View file

@ -18,10 +18,10 @@ export function initAuthenticateApi(server) {
config: {
auth: false,
validate: {
payload: {
payload: Joi.object({
username: Joi.string().required(),
password: Joi.string().required()
}
})
},
response: {
emptyStatusCode: 204,
@ -58,10 +58,10 @@ export function initAuthenticateApi(server) {
config: {
auth: false,
validate: {
payload: {
payload: Joi.object({
SAMLResponse: Joi.string().required(),
RelayState: Joi.string().allow('')
}
})
}
},
async handler(request, h) {

View file

@ -121,10 +121,10 @@ export function initUsersApi(server) {
},
config: {
validate: {
payload: {
payload: Joi.object({
password: Joi.string(),
newPassword: Joi.string().required()
}
})
},
pre: [routePreCheckLicenseFn]
}