From edb52b872839d4c16d31c12f33c636503a1a0556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lloren=C3=A7=20Muntaner?= Date: Fri, 20 Dec 2024 15:33:46 +0100 Subject: [PATCH] Add new field to LoginSuccess to show add current device screen (#2759) * Add new field to LoginSuccess to show add current device screen * Add field to current tests --- src/frontend/src/components/authenticateBox/index.ts | 1 + src/frontend/src/utils/iiConnection.test.ts | 9 +++++++++ src/frontend/src/utils/iiConnection.ts | 5 +++++ src/showcase/src/flows.ts | 4 ++++ 4 files changed, 19 insertions(+) diff --git a/src/frontend/src/components/authenticateBox/index.ts b/src/frontend/src/components/authenticateBox/index.ts index 09cd29d81e..be078f9aaa 100644 --- a/src/frontend/src/components/authenticateBox/index.ts +++ b/src/frontend/src/components/authenticateBox/index.ts @@ -89,6 +89,7 @@ export const authenticateBox = async ({ connection: AuthenticatedConnection; newAnchor: boolean; authnMethod: "pin" | "passkey" | "recovery"; + showAddCurrentDevice: boolean; }> => { const promptAuth = async (autoSelectIdentity?: bigint) => authenticateBoxFlow({ diff --git a/src/frontend/src/utils/iiConnection.test.ts b/src/frontend/src/utils/iiConnection.test.ts index 324bf0da0f..48d9cdea5c 100644 --- a/src/frontend/src/utils/iiConnection.test.ts +++ b/src/frontend/src/utils/iiConnection.test.ts @@ -168,6 +168,7 @@ describe("Connection.login", () => { expect(loginResult.kind).toBe("loginSuccess"); if (loginResult.kind === "loginSuccess") { expect(loginResult.connection).toBeInstanceOf(AuthenticatedConnection); + expect(loginResult.showAddCurrentDevice).toBe(false); expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledTimes(1); expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledWith( [convertToCredentialData(mockDevice)], @@ -208,6 +209,7 @@ describe("Connection.login", () => { expect(secondLoginResult.kind).toBe("loginSuccess"); if (secondLoginResult.kind === "loginSuccess") { + expect(secondLoginResult.showAddCurrentDevice).toBe(true); expect(secondLoginResult.connection).toBeInstanceOf( AuthenticatedConnection ); @@ -258,6 +260,7 @@ describe("Connection.login", () => { expect(secondLoginResult.kind).toBe("loginSuccess"); if (secondLoginResult.kind === "loginSuccess") { + expect(secondLoginResult.showAddCurrentDevice).toBe(false); expect(secondLoginResult.connection).toBeInstanceOf( AuthenticatedConnection ); @@ -291,6 +294,7 @@ describe("Connection.login", () => { expect(loginResult.kind).toBe("loginSuccess"); if (loginResult.kind === "loginSuccess") { + expect(loginResult.showAddCurrentDevice).toBe(false); expect(loginResult.connection).toBeInstanceOf(AuthenticatedConnection); expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledTimes(1); expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledWith( @@ -318,6 +322,7 @@ describe("Connection.login", () => { expect(loginResult.kind).toBe("loginSuccess"); if (loginResult.kind === "loginSuccess") { + expect(loginResult.showAddCurrentDevice).toBe(false); expect(loginResult.connection).toBeInstanceOf(AuthenticatedConnection); expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledTimes(1); expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledWith( @@ -358,6 +363,7 @@ describe("Connection.login", () => { expect(secondLoginResult.kind).toBe("loginSuccess"); if (secondLoginResult.kind === "loginSuccess") { + expect(secondLoginResult.showAddCurrentDevice).toBe(false); expect(secondLoginResult.connection).toBeInstanceOf( AuthenticatedConnection ); @@ -391,6 +397,7 @@ describe("Connection.login", () => { expect(loginResult.kind).toBe("loginSuccess"); if (loginResult.kind === "loginSuccess") { + expect(loginResult.showAddCurrentDevice).toBe(false); expect(loginResult.connection).toBeInstanceOf(AuthenticatedConnection); expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledTimes(1); expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledWith( @@ -419,6 +426,7 @@ describe("Connection.login", () => { expect(loginResult.kind).toBe("loginSuccess"); if (loginResult.kind === "loginSuccess") { expect(loginResult.connection).toBeInstanceOf(AuthenticatedConnection); + expect(loginResult.showAddCurrentDevice).toBe(false); expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledTimes(1); expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledWith( [convertToCredentialData(mockDevice)], @@ -461,6 +469,7 @@ describe("Connection.login", () => { expect(secondLoginResult.connection).toBeInstanceOf( AuthenticatedConnection ); + expect(secondLoginResult.showAddCurrentDevice).toBe(false); expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenCalledTimes(2); expect(MultiWebAuthnIdentity.fromCredentials).toHaveBeenNthCalledWith( 2, diff --git a/src/frontend/src/utils/iiConnection.ts b/src/frontend/src/utils/iiConnection.ts index 518d885814..a441468cfa 100644 --- a/src/frontend/src/utils/iiConnection.ts +++ b/src/frontend/src/utils/iiConnection.ts @@ -94,6 +94,7 @@ export type LoginSuccess = { kind: "loginSuccess"; connection: AuthenticatedConnection; userNumber: bigint; + showAddCurrentDevice: boolean; }; export type RegFlowNextStep = @@ -323,6 +324,7 @@ export class Connection { actor ), userNumber, + showAddCurrentDevice: false, }; } @@ -460,6 +462,7 @@ export class Connection { kind: "loginSuccess", userNumber, connection, + showAddCurrentDevice: cancelledRpIds.size > 0, }; }; fromIdentity = async ( @@ -480,6 +483,7 @@ export class Connection { kind: "loginSuccess", userNumber, connection, + showAddCurrentDevice: false, }; }; @@ -520,6 +524,7 @@ export class Connection { userNumber, actor ), + showAddCurrentDevice: false, }; }; diff --git a/src/showcase/src/flows.ts b/src/showcase/src/flows.ts index 8724cb89f0..d4cf68167d 100644 --- a/src/showcase/src/flows.ts +++ b/src/showcase/src/flows.ts @@ -92,6 +92,7 @@ const registerFlowOpts: RegisterFlowOpts = { kind: "loginSuccess", userNumber: BigInt(12356), connection: mockConnection, + showAddCurrentDevice: false, }; }, registrationAllowed: true, @@ -122,6 +123,7 @@ export const iiFlows: Record void> = { kind: "loginSuccess", userNumber: BigInt(1234), connection: mockConnection, + showAddCurrentDevice: false, }); }, allowPinLogin: true, @@ -138,6 +140,7 @@ export const iiFlows: Record void> = { kind: "loginSuccess", userNumber: BigInt(1234), connection: mockConnection, + showAddCurrentDevice: false, }); }, recover: () => { @@ -146,6 +149,7 @@ export const iiFlows: Record void> = { kind: "loginSuccess", userNumber: BigInt(1234), connection: mockConnection, + showAddCurrentDevice: false, }); }, retrievePinIdentityMaterial: ({ userNumber }) => {