From 5f60a595161aa96cd110192bc810eb8fa478da21 Mon Sep 17 00:00:00 2001 From: simov Date: Sun, 26 Nov 2023 18:33:48 +0200 Subject: [PATCH] Add missing callback tests --- test/handler/handler.js | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/test/handler/handler.js b/test/handler/handler.js index 986b283..d05071f 100644 --- a/test/handler/handler.js +++ b/test/handler/handler.js @@ -123,18 +123,34 @@ describe('handler', () => { }) }) - describe('missing provider', () => { + describe('missing provider + missing callback', () => { ;['express', 'koa', 'hapi', 'fastify', 'node', 'aws', 'azure', 'gcloud', 'vercel'].forEach((handler) => { describe(handler, () => { before(async () => { - client = await Client({test: 'handlers', handler, config}) + client = await Client({ + test: 'handlers', + handler, + config: { + defaults: {origin: config.defaults.origin}, // no callback! + oauth2: config.oauth2 + } + }) }) after(async () => { await client.close() }) - it('/connect - misconfigured provider', async () => { + it('/connect - missing provider', async () => { + t.equal(config.defaults.dynamic, undefined) + var {body: {response}} = await request({ + url: client.url('/connect/oauth5'), + cookie: {}, + }) + t.deepEqual(response, {error: 'Grant: missing or misconfigured provider'}) + }) + + it('/connect - unsupported oauth version', async () => { var {body: {response}} = await request({ url: client.url('/connect/oauth2'), qs: {oauth: 5}, @@ -143,13 +159,22 @@ describe('handler', () => { t.deepEqual(response, {error: 'Grant: missing or misconfigured provider'}) }) - it('/connect - missing provider', async () => { - t.equal(config.defaults.dynamic, undefined) + it('/connect - authorize error', async () => { var {body: {response}} = await request({ - url: client.url('/connect/oauth5'), + url: client.url('/connect/oauth2'), + qs: {authorize_url: provider.url('/authorize_error_message')}, cookie: {}, }) - t.deepEqual(response, {error: 'Grant: missing or misconfigured provider'}) + t.deepEqual(response, {error: {message: 'invalid'}}) + }) + + it('/connect - access error', async () => { + var {body: {response}} = await request({ + url: client.url('/connect/oauth2'), + qs: {access_url: provider.url('/access_error_status')}, + cookie: {}, + }) + t.deepEqual(response, {error: {invalid: 'access_url'}}) }) it('/callback - missing session', async () => {