From 1188e4573ffea88d4349eb5cca2812d9e950ce96 Mon Sep 17 00:00:00 2001 From: Timo Hocker <35867059+TimoHocker@users.noreply.github.com> Date: Tue, 4 Jan 2022 15:01:33 +0100 Subject: [PATCH] fix promise not being awaited --- lib/AuthHandler.ts | 2 +- package.json | 2 +- test/spec/AuthHandler.ts | 15 +++++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/AuthHandler.ts b/lib/AuthHandler.ts index f9ce4b6..0f6d264 100644 --- a/lib/AuthHandler.ts +++ b/lib/AuthHandler.ts @@ -280,7 +280,7 @@ export default function create_auth_handler ( const token = (/(?\S+) (?.+)/ui) .exec (req.headers.authorization as string); - process_request (request, token, default_handler, options); + await process_request (request, token, default_handler, options); return request.is_successful; }; diff --git a/package.json b/package.json index 518bb2b..deddf24 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sapphirecode/auth-server-helper", - "version": "2.1.3", + "version": "2.1.4", "main": "dist/index.js", "author": { "name": "Timo Hocker", diff --git a/test/spec/AuthHandler.ts b/test/spec/AuthHandler.ts index b70c7c2..f888737 100644 --- a/test/spec/AuthHandler.ts +++ b/test/spec/AuthHandler.ts @@ -102,7 +102,9 @@ describe ('auth handler', () => { access_token_expires_in: expires_seconds, leave_open: true }); - req.response.end ('custom response'); + req.response.write ('custom response, '); + (req.response.connection as unknown as Record) + .append_flag = true; } else { req.deny (); @@ -128,8 +130,13 @@ describe ('auth handler', () => { } }); - server = http.createServer ((req: IncomingMessage, res: ServerResponse) => { - ah (req, res); + server = http.createServer (async ( + req: IncomingMessage, + res: ServerResponse + ) => { + const is_successful = await ah (req, res); + if ((res.connection as unknown as Record).append_flag) + res.end (String (is_successful)); }); server.listen (3000); }); @@ -338,7 +345,7 @@ describe ('auth handler', () => { expect (resp1.headers['content-type']) .toEqual ('text/plain'); expect (resp1.body) - .toEqual ('custom response'); + .toEqual ('custom response, true'); let signature = ''; for (const c of resp1.headers['set-cookie'] as string[]) { if (c.includes ('cookie_jar='))