Skip to content

Commit

Permalink
Add e2e tests for login without prefilled user number (#1933)
Browse files Browse the repository at this point in the history
Due to the change in #1929 the login flow with unknown user number
was no longer tested. This  reintroduces these tests for both
webAuthn and PIN login.
  • Loading branch information
frederikrothenberger authored Sep 26, 2023
1 parent 1b1ce4e commit e28c880
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/frontend/src/test-e2e/flows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ export const FLOWS = {
await authenticateView.register();
return await FLOWS.registerPin(browser, pin);
},
loginWelcomeView: async (
userNumber: string,
deviceName: string,
browser: WebdriverIO.Browser
): Promise<void> => {
const welcomeView = new WelcomeView(browser);
await welcomeView.waitForDisplay();
await welcomeView.login(userNumber);
// This flow assumes no recovery phrase, so we explicitly skip the recovery nag here
await FLOWS.skipRecoveryNag(browser);
const mainView = new MainView(browser);
await mainView.waitForDeviceDisplay(deviceName);
},
loginAuthenticateView: async (
userNumber: string,
deviceName: string,
Expand Down Expand Up @@ -110,6 +123,20 @@ export const FLOWS = {
// This flow assumes no recovery phrase, so we explicitly skip the recovery nag here
await FLOWS.skipRecoveryNag(browser);
},
loginPinWelcomeView: async (
userNumber: string,
pin: string,
browser: WebdriverIO.Browser
): Promise<void> => {
const welcomeView = new WelcomeView(browser);
await welcomeView.waitForDisplay();
await welcomeView.login(userNumber);
const pinAuthView = new PinAuthView(browser);
await pinAuthView.waitForDisplay();
await pinAuthView.enterPin(pin);
// This flow assumes no recovery phrase, so we explicitly skip the recovery nag here
await FLOWS.skipRecoveryNag(browser);
},
addRecoveryMechanismSeedPhrase: async (
browser: WebdriverIO.Browser
): Promise<string> => {
Expand Down
19 changes: 19 additions & 0 deletions src/frontend/src/test-e2e/pinAuth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ test("Register and Log in with PIN identity", async () => {
}, APPLE_USER_AGENT);
}, 300_000);

test("Register with PIN and login without prefilled identity number", async () => {
await runInBrowser(async (browser: WebdriverIO.Browser) => {
const pin = "123456";
await browser.url(II_URL);
const userNumber = await FLOWS.registerPinWelcomeView(browser, pin);

const mainView = new MainView(browser);
await mainView.waitForTempKeyDisplay(DEFAULT_PIN_DEVICE_NAME);

// clear local storage, so that the identity number is not prefilled
await browser.execute("localStorage.clear()");

// load the II page again
await browser.url(II_URL);
await FLOWS.loginPinWelcomeView(userNumber, pin, browser);
await mainView.waitForTempKeyDisplay(DEFAULT_PIN_DEVICE_NAME);
}, APPLE_USER_AGENT);
}, 300_000);

test("Register and log in with PIN identity, retry on wrong PIN", async () => {
await runInBrowser(async (browser: WebdriverIO.Browser) => {
const pin = "123456";
Expand Down
20 changes: 20 additions & 0 deletions src/frontend/src/test-e2e/register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ test("Register new identity and login with it", async () => {
});
}, 300_000);

test("Register new identity and login without prefilled identity number", async () => {
await runInBrowser(async (browser: WebdriverIO.Browser) => {
await browser.url(II_URL);
await addVirtualAuthenticator(browser);
const userNumber = await FLOWS.registerNewIdentityWelcomeView(
DEVICE_NAME1,
browser
);
const mainView = new MainView(browser);
await mainView.waitForDeviceDisplay(DEVICE_NAME1);

// clear local storage, so that the identity number is not prefilled
await browser.execute("localStorage.clear()");

// load the II page again
await browser.url(II_URL);
await FLOWS.loginWelcomeView(userNumber, DEVICE_NAME1, browser);
});
}, 300_000);

test("Log into client application, after registration", async () => {
await runInBrowser(async (browser: WebdriverIO.Browser) => {
await addVirtualAuthenticator(browser);
Expand Down
5 changes: 4 additions & 1 deletion src/frontend/src/test-e2e/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ export class WelcomeView extends View {
}

async typeUserNumber(userNumber: string): Promise<void> {
await this.browser.$('[data-role="anchor-input"]').waitForDisplayed();
await this.browser.$('[data-role="anchor-input"]').setValue(userNumber);
}

async login(): Promise<void> {
async login(userNumber: string): Promise<void> {
await this.browser.$("#loginButton").waitForDisplayed();
await this.browser.$("#loginButton").scrollIntoView();
await this.browser.$("#loginButton").click();
await this.typeUserNumber(userNumber);
await this.browser.$('[data-action="continue"').click();
}

async register(): Promise<void> {
Expand Down

0 comments on commit e28c880

Please sign in to comment.