fix: stricter ajv validation

This commit is contained in:
Divlo
2022-04-07 14:56:07 +00:00
parent 694ac58aad
commit 69c567cb66
19 changed files with 1075 additions and 1067 deletions

View File

@ -21,7 +21,7 @@ await tap.test('GET /users/current', async (t) => {
const responseJson = response.json()
t.equal(response.statusCode, 200)
t.equal(responseJson.user.name, user.name)
t.strictSame(responseJson.user.strategies, ['local'])
t.strictSame(responseJson.user.strategies, ['Local'])
})
await t.test('fails with unauthenticated user', async (t) => {

View File

@ -44,7 +44,7 @@ export const getCurrentUser: FastifyPluginAsync = async (fastify) => {
return oauth.provider
})
if (user.current.password != null) {
strategies.push('local')
strategies.push('Local')
}
reply.statusCode = 200
return {

View File

@ -52,7 +52,7 @@ export const putCurrentUser: FastifyPluginAsync = async (fastify) => {
fastify.route<{
Body: BodyPutServiceSchemaType
Params: QueryPutCurrentUserSchemaType
Querystring: QueryPutCurrentUserSchemaType
}>({
method: 'PUT',
url: '/users/current',
@ -62,7 +62,7 @@ export const putCurrentUser: FastifyPluginAsync = async (fastify) => {
throw fastify.httpErrors.forbidden()
}
const { name, email, status, biography, website } = request.body
const { redirectURI } = request.params
const { redirectURI } = request.query
const userValidation = await prisma.user.findFirst({
where: {
OR: [
@ -90,9 +90,9 @@ export const putCurrentUser: FastifyPluginAsync = async (fastify) => {
return oauth.provider
})
if (request.user.current.password != null) {
strategies.push('local')
strategies.push('Local')
}
if (email === null && strategies.includes('local')) {
if (email === null && strategies.includes('Local')) {
throw fastify.httpErrors.badRequest(
'You must have an email to sign in.'
)