Skip to content

Commit

Permalink
Do not clear localstorage on logout (#1929)
Browse files Browse the repository at this point in the history
* Do not clear localstorage on logout

Deleting identity numbers on logout is unexpected and
destructive. A change was requested to no longer do that.

Instead, we should give users a different way of managing the
numbers shown on the landing page (to be solved as a separate PR).

Note: 3 lines were changed in the production code. The rest is adapting
the e2e tests to use the pick identity flow instead of entering it new.

* Rename changed flows
  • Loading branch information
Frederik Rothenberger authored Sep 26, 2023
1 parent 0a038b1 commit a7766b8
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 48 deletions.
1 change: 0 additions & 1 deletion src/frontend/src/components/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const logoutSection = (
</div>`;

const logout = () => {
localStorage.clear();
clearHash();
window.location.reload();
};
Expand Down
3 changes: 1 addition & 2 deletions src/frontend/src/flows/manage/deviceSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ export const deleteDevice = async ({
});

if (sameDevice) {
// clear anchor and reload the page.
// reload the page.
// do not call "reload", otherwise the management page will try to reload the list of devices which will cause an error
localStorage.clear();
location.reload();
return;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/test-e2e/addDevice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test("Add device", async () => {
await mainView.waitForDeviceCount(DEVICE_NAME1, 2);

await mainView.logout();
await FLOWS.login(userNumber, DEVICE_NAME1, browser);
await FLOWS.loginAuthenticateView(userNumber, DEVICE_NAME1, browser);
});
}, 300_000);

Expand Down
27 changes: 10 additions & 17 deletions src/frontend/src/test-e2e/flows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,39 +83,32 @@ export const FLOWS = {
await authenticateView.register();
return await FLOWS.registerPin(browser, pin);
},
login: async (
loginAuthenticateView: async (
userNumber: string,
deviceName: string,
browser: WebdriverIO.Browser
): Promise<void> => {
const welcomeView = new WelcomeView(browser);
await welcomeView.waitForDisplay();
await welcomeView.login();
await welcomeView.typeUserNumber(userNumber);
await browser.$("button[data-action='continue']").click();
const authenticateView = new AuthenticateView(browser);
await authenticateView.waitForDisplay();
await authenticateView.pickAnchor(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);
},
loginPin: async (
loginPinAuthenticateView: async (
userNumber: string,
pin: string,
deviceName: string,
browser: WebdriverIO.Browser
): Promise<void> => {
const welcomeView = new WelcomeView(browser);
await welcomeView.waitForDisplay();
await welcomeView.login();
await welcomeView.typeUserNumber(userNumber);
await browser.$("button[data-action='continue']").click();
const authenticateView = new AuthenticateView(browser);
await authenticateView.waitForDisplay();
await authenticateView.pickAnchor(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);
const mainView = new MainView(browser);
await mainView.waitForTempKeyDisplay(deviceName);
},
addRecoveryMechanismSeedPhrase: async (
browser: WebdriverIO.Browser
Expand Down Expand Up @@ -172,8 +165,8 @@ export const FLOWS = {
browser: WebdriverIO.Browser,
recoveryPhrase: string
): Promise<void> => {
const welcomeView = new WelcomeView(browser);
await welcomeView.recover();
const authenticateView = new AuthenticateView(browser);
await authenticateView.recover();
const recoveryView = new RecoverView(browser);
await recoveryView.waitForSeedInputDisplay();
await recoveryView.enterSeedPhrase(recoveryPhrase);
Expand Down
24 changes: 8 additions & 16 deletions src/frontend/src/test-e2e/pinAuth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ test("Register and Log in with PIN identity", async () => {
await mainView.waitForDisplay(); // we should be logged in
await mainView.waitForTempKeyDisplay(DEFAULT_PIN_DEVICE_NAME);
await mainView.logout();
await FLOWS.loginPin(userNumber, pin, DEFAULT_PIN_DEVICE_NAME, browser);
await FLOWS.loginPinAuthenticateView(userNumber, pin, browser);
await mainView.waitForTempKeyDisplay(DEFAULT_PIN_DEVICE_NAME);
}, APPLE_USER_AGENT);
}, 300_000);

Expand All @@ -69,11 +70,10 @@ test("Register and log in with PIN identity, retry on wrong PIN", async () => {
await mainView.waitForDisplay(); // we should be logged in
await mainView.logout();

const welcomeView = new WelcomeView(browser);
await welcomeView.waitForDisplay();
await welcomeView.login();
await welcomeView.typeUserNumber(userNumber);
await browser.$("button[data-action='continue']").click();
const authenticateView = new AuthenticateView(browser);
await authenticateView.waitForDisplay();
await authenticateView.pickAnchor(userNumber);

const pinAuthView = new PinAuthView(browser);
await pinAuthView.waitForDisplay();
await pinAuthView.enterPin(wrongPin);
Expand Down Expand Up @@ -106,7 +106,7 @@ test("Should not prompt for PIN after deleting temp key", async () => {
await browser.acceptAlert();

// login now happens using the WebAuthn flow
await FLOWS.login(userNumber, DEVICE_NAME1, browser);
await FLOWS.loginAuthenticateView(userNumber, DEVICE_NAME1, browser);
}, APPLE_USER_AGENT);
}, 300_000);

Expand Down Expand Up @@ -155,15 +155,7 @@ test("Register with PIN then log into client application", async () => {

await switchToPopup(browser);

const authenticateView = new AuthenticateView(browser);
await authenticateView.waitForDisplay();
await authenticateView.pickAnchor(userNumber);

const pinAuthView = new PinAuthView(browser);
await pinAuthView.waitForDisplay();
await pinAuthView.enterPin(pin);

await FLOWS.skipRecoveryNag(browser);
await FLOWS.loginPinAuthenticateView(userNumber, pin, browser);
await waitToClose(browser);

await demoAppView.waitForDisplay();
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/test-e2e/register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test("Register new identity and login with it", async () => {
const mainView = new MainView(browser);
await mainView.waitForDeviceDisplay(DEVICE_NAME1);
await mainView.logout();
await FLOWS.login(userNumber, DEVICE_NAME1, browser);
await FLOWS.loginAuthenticateView(userNumber, DEVICE_NAME1, browser);
});
}, 300_000);

Expand Down
21 changes: 11 additions & 10 deletions src/frontend/src/test-e2e/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ export class WelcomeView extends View {
await this.browser.$("#loginButton").click();
await this.browser.$("#addNewDeviceButton").click();
}

async recover(): Promise<void> {
await this.browser.$("#loginButton").waitForDisplayed();
await this.browser.$("#loginButton").scrollIntoView();
await this.browser.$("#loginButton").click();
await this.browser.$("#recoverButton").waitForDisplayed();
await this.browser.$("#recoverButton").scrollIntoView();
await this.browser.$("#recoverButton").click();
await this.browser.$('[data-action="recover-with-phrase"]').click();
}
}

export class RenameView extends View {
Expand Down Expand Up @@ -537,6 +527,17 @@ export class AuthenticateView extends View {
async switchToAnchorInput(): Promise<void> {
await this.browser.$('[data-role="anchor-input"]').click();
}

async recover(): Promise<void> {
await await this.browser.$('[data-role="more-options"]').click();
await this.browser.$("#recoverButton").waitForDisplayed();
await this.browser.$("#recoverButton").scrollIntoView();
await this.browser.$("#recoverButton").click();
await this.browser
.$('[data-action="recover-with-phrase"]')
.waitForDisplayed();
await this.browser.$('[data-action="recover-with-phrase"]').click();
}
}

export class WelcomeBackView extends View {
Expand Down

0 comments on commit a7766b8

Please sign in to comment.