From 82972091dc6ca19800fe06bde65a2cc812a5b10f Mon Sep 17 00:00:00 2001 From: Jesse Wright <63333554+jeswr@users.noreply.github.com> Date: Mon, 13 Nov 2023 10:05:37 +0000 Subject: [PATCH] fix: Prevent race condition in login flow (#484) Initalise completeLoginConditions at start of login to prevent race conditions. --- .../internal-playwright-helpers/src/flows/auth.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/internal-playwright-helpers/src/flows/auth.ts b/packages/internal-playwright-helpers/src/flows/auth.ts index 8bf0a98b..c863d7db 100644 --- a/packages/internal-playwright-helpers/src/flows/auth.ts +++ b/packages/internal-playwright-helpers/src/flows/auth.ts @@ -57,6 +57,12 @@ export class AuthFlow { const testPage = new TestPage(this.page, this.openidProvider); const cognitoPage = new CognitoPage(this.page); const openIdPage = new OpenIdPage(this.page); + // Clicking on the consent screen from the broker will redirect to the + // test page, and trigger the token request. To prevent this being a + // race condition, waiting on this request should be done prior to + // giving consent. + const completeLoginConditions = [testPage.handleRedirect()]; + // First, initiate login in the test client, and wait for the redirect to the OP await Promise.all([ this.page.waitForURL( @@ -79,11 +85,6 @@ export class AuthFlow { ]); } - // Clicking on the consent screen from the broker will redirect to the - // test page, and trigger the token request. To prevent this being a - // race condition, waiting on this request should be done prior to - // giving consent. - const completeLoginConditions = [testPage.handleRedirect()]; // TODO: handle allow === false if (options.allow && OpenIdPage.isOnPage(new URL(this.page.url()))) { completeLoginConditions.push(openIdPage.allow(timeoutOptions));