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.'
)

View File

@ -53,7 +53,7 @@ export const deleteProviderService: FastifyPluginAsync = async (fastify) => {
return oauth.provider
})
if (user.current.password != null) {
strategies.push('local')
strategies.push('Local')
}
const oauthProvider = OAuths.find((oauth) => oauth.provider === provider)
if (oauthProvider == null) {

View File

@ -4,8 +4,8 @@ import axios from 'axios'
import { OAuthStrategy } from '../../../../../tools/utils/OAuthStrategy.js'
export const DISCORD_PROVIDER = 'discord'
export const DISCORD_BASE_URL = 'https://discord.com/api/v6'
export const DISCORD_PROVIDER = 'Discord'
export const DISCORD_BASE_URL = 'https://discord.com/api/v10'
export const DISCORD_CLIENT_ID =
process.env.DISCORD_CLIENT_ID ?? 'DISCORD_CLIENT_ID'
export const DISCORD_CLIENT_SECRET =

View File

@ -4,7 +4,7 @@ import axios from 'axios'
import { OAuthStrategy } from '../../../../../tools/utils/OAuthStrategy.js'
export const GITHUB_PROVIDER = 'github'
export const GITHUB_PROVIDER = 'GitHub'
export const GITHUB_BASE_URL = 'https://github.com'
export const GITHUB_API_BASE_URL = 'https://api.github.com'
export const GITHUB_CLIENT_ID =

View File

@ -4,7 +4,7 @@ import axios from 'axios'
import { OAuthStrategy } from '../../../../../tools/utils/OAuthStrategy.js'
export const GOOGLE_PROVIDER = 'google'
export const GOOGLE_PROVIDER = 'Google'
export const GOOGLE_BASE_URL = 'https://accounts.google.com/o/oauth2/v2/auth'
export const GOOGLE_OAUTH2_TOKEN = 'https://oauth2.googleapis.com/token'
export const GOOGLE_USERINFO =

View File

@ -53,11 +53,11 @@ export const postSigninUser: FastifyPluginAsync = async (fastify) => {
throw fastify.httpErrors.badRequest('Invalid credentials.')
}
const accessToken = generateAccessToken({
currentStrategy: 'local',
currentStrategy: 'Local',
id: user.id
})
const refreshToken = await generateRefreshToken({
currentStrategy: 'local',
currentStrategy: 'Local',
id: user.id
})
reply.statusCode = 200

View File

@ -58,7 +58,7 @@ await tap.test('POST /users/signup', async (t) => {
url: '/users/signup',
payload: {
...payload,
email: 'incorrect-email'
email: 'incorrect-email@abc'
}
})
t.equal(response.statusCode, 400)