From d0245b59bcf837d0592eb3a4e3eaad8e6439a7c0 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sun, 11 Jun 2023 21:14:08 +0200 Subject: [PATCH] add another error handler for non-indirect case --- .../backend/src/server/oauth/OAuth2ProviderService.ts | 3 +++ packages/backend/test/e2e/oauth.ts | 8 +------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/server/oauth/OAuth2ProviderService.ts b/packages/backend/src/server/oauth/OAuth2ProviderService.ts index ded2b2756..4b24ea113 100644 --- a/packages/backend/src/server/oauth/OAuth2ProviderService.ts +++ b/packages/backend/src/server/oauth/OAuth2ProviderService.ts @@ -357,6 +357,7 @@ export class OAuth2ProviderService { mode: 'indirect', modes: getQueryMode(this.config.url), })); + fastify.use('/oauth/authorize', this.#server.errorHandler()); fastify.use('/oauth/decision', bodyParser.urlencoded({ extended: false })); fastify.use('/oauth/decision', this.#server.decision((req, done) => { @@ -373,3 +374,5 @@ export class OAuth2ProviderService { fastify.use('/oauth/token', this.#server.errorHandler()); } } + +// TODO: remove console.log and use proper logger diff --git a/packages/backend/test/e2e/oauth.ts b/packages/backend/test/e2e/oauth.ts index d0d11b55c..c152c33ba 100644 --- a/packages/backend/test/e2e/oauth.ts +++ b/packages/backend/test/e2e/oauth.ts @@ -125,13 +125,7 @@ async function assertDirectError(response: Response, status: number, error: stri assert.strictEqual(response.status, status); const data = await response.json(); - // `mode: indirect` may throw a direct error with `code` while the default direct mode uses `error` - // For now this doesn't matter too much since direct errors are not intended to be sent to clients. - if ('code' in data) { - assert.strictEqual(data.code, error); - } else { - assert.strictEqual(data.error, error); - } + assert.strictEqual(data.error, error); } describe('OAuth', () => {