Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nmattia committed Nov 20, 2023
1 parent 0b2d86c commit f748010
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 123 deletions.
7 changes: 1 addition & 6 deletions demos/test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
},
"scripts": {
"build": "vite build",
"dev": "vite",
"lint:fix": "npm run lint -- --fix",
"make:docs/reference": "",
"publish:release": "",
"test:coverage": "",
"test": ""
"dev": "vite"
},
"devDependencies": {
"vite": "^4.3.9"
Expand Down
16 changes: 3 additions & 13 deletions src/frontend/src/test-e2e/addDevice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ test("Add device", async () => {
await runInBrowser(async (browser: WebdriverIO.Browser) => {
const firstAuthenticator = await addVirtualAuthenticator(browser);
await browser.url(II_URL);
const userNumber = await FLOWS.registerNewIdentityWelcomeView(
DEVICE_NAME1,
browser
);

const userNumber = await FLOWS.registerNewIdentityWelcomeView(browser);
const mainView = new MainView(browser);
await mainView.waitForDeviceDisplay(DEVICE_NAME1);
// We're removing the first authenticator here, because unfortunately we
Expand All @@ -56,10 +52,7 @@ test("Add remote device", async () => {
await runInBrowser(async (browser: WebdriverIO.Browser) => {
await addVirtualAuthenticator(browser);
await browser.url(II_URL);
const _userNumber = await FLOWS.registerNewIdentityWelcomeView(
DEVICE_NAME1,
browser
);
const _userNumber = await FLOWS.registerNewIdentityWelcomeView(browser);
const mainView = new MainView(browser);
await mainView.waitForDeviceDisplay(DEVICE_NAME1);
await mainView.addAdditionalDevice();
Expand Down Expand Up @@ -118,10 +111,7 @@ test("Add remote device starting on new device", async () => {
await runInBrowser(async (browser: WebdriverIO.Browser) => {
await addVirtualAuthenticator(browser);
await browser.url(II_URL);
const userNumber = await FLOWS.registerNewIdentityWelcomeView(
DEVICE_NAME1,
browser
);
const userNumber = await FLOWS.registerNewIdentityWelcomeView(browser);
const mainView = new MainView(browser);
await mainView.waitForDeviceDisplay(DEVICE_NAME1);

Expand Down
14 changes: 3 additions & 11 deletions src/frontend/src/test-e2e/alternativeOrigin/endpointFormat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import {
import { AuthenticateView, DemoAppView, ErrorView } from "../views";

import {
DEVICE_NAME1,
II_URL,
REPLICA_URL,
TEST_APP_CANISTER_ID,
TEST_APP_CANONICAL_URL,
TEST_APP_NICE_URL,
Expand All @@ -22,7 +20,7 @@ test("Should not issue delegation when /.well-known/ii-alternative-origins has t
await runInBrowser(async (browser: WebdriverIO.Browser) => {
const authenticatorId1 = await addVirtualAuthenticator(browser);
await browser.url(II_URL);
await FLOWS.registerNewIdentityWelcomeView(DEVICE_NAME1, browser);
await FLOWS.registerNewIdentityWelcomeView(browser);
await FLOWS.addRecoveryMechanismSeedPhrase(browser);
const credentials = await getWebAuthnCredentials(browser, authenticatorId1);
expect(credentials).toHaveLength(1);
Expand All @@ -31,7 +29,6 @@ test("Should not issue delegation when /.well-known/ii-alternative-origins has t
await niceDemoAppView.open(TEST_APP_NICE_URL, II_URL);
await niceDemoAppView.waitForDisplay();
await niceDemoAppView.updateAlternativeOrigins(
REPLICA_URL,
TEST_APP_CANISTER_ID,
'{"alternativeOrigins":["https://a0.com", "https://a1.com", "https://a2.com", "https://a3.com", "https://a4.com", "https://a5.com", "https://a6.com", "https://a7.com", "https://a8.com", "https://a9.com", "https://a10.com"]}',
"certified"
Expand Down Expand Up @@ -62,7 +59,7 @@ test("Should not follow redirect returned by /.well-known/ii-alternative-origins
await runInBrowser(async (browser: WebdriverIO.Browser) => {
const authenticatorId1 = await addVirtualAuthenticator(browser);
await browser.url(II_URL);
await FLOWS.registerNewIdentityWelcomeView(DEVICE_NAME1, browser);
await FLOWS.registerNewIdentityWelcomeView(browser);
await FLOWS.addRecoveryMechanismSeedPhrase(browser);
const credentials = await getWebAuthnCredentials(browser, authenticatorId1);
expect(credentials).toHaveLength(1);
Expand All @@ -71,7 +68,6 @@ test("Should not follow redirect returned by /.well-known/ii-alternative-origins
await niceDemoAppView.open(TEST_APP_NICE_URL, II_URL);
await niceDemoAppView.waitForDisplay();
await niceDemoAppView.updateAlternativeOrigins(
REPLICA_URL,
TEST_APP_CANISTER_ID,
'{"alternativeOrigins":["https://evil.com"]}',
"redirect"
Expand Down Expand Up @@ -102,10 +98,7 @@ test("Should fetch /.well-known/ii-alternative-origins using the non-raw url", a
await runInBrowser(async (browser: WebdriverIO.Browser) => {
const authenticatorId1 = await addVirtualAuthenticator(browser);
await browser.url(II_URL);
const userNumber = await FLOWS.registerNewIdentityWelcomeView(
DEVICE_NAME1,
browser
);
const userNumber = await FLOWS.registerNewIdentityWelcomeView(browser);
await FLOWS.addRecoveryMechanismSeedPhrase(browser);
const credentials = await getWebAuthnCredentials(browser, authenticatorId1);
expect(credentials).toHaveLength(1);
Expand All @@ -114,7 +107,6 @@ test("Should fetch /.well-known/ii-alternative-origins using the non-raw url", a
await niceDemoAppView.open(TEST_APP_NICE_URL, II_URL);
await niceDemoAppView.waitForDisplay();
await niceDemoAppView.updateAlternativeOrigins(
REPLICA_URL,
TEST_APP_CANISTER_ID,
`{"alternativeOrigins":["${TEST_APP_NICE_URL}"]}`,
"certified"
Expand Down
19 changes: 4 additions & 15 deletions src/frontend/src/test-e2e/alternativeOrigin/ingressFormat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import {
import { DemoAppView, ErrorView } from "../views";

import {
DEVICE_NAME1,
II_URL,
REPLICA_URL,
TEST_APP_CANISTER_ID,
TEST_APP_CANONICAL_URL,
TEST_APP_NICE_URL,
Expand All @@ -22,21 +20,15 @@ test("Should not issue delegation when derivationOrigin is missing from /.well-k
await runInBrowser(async (browser: WebdriverIO.Browser) => {
const authenticatorId1 = await addVirtualAuthenticator(browser);
await browser.url(II_URL);
const _userNumber = await FLOWS.registerNewIdentityWelcomeView(
DEVICE_NAME1,
browser
);
const _userNumber = await FLOWS.registerNewIdentityWelcomeView(browser);
await FLOWS.addRecoveryMechanismSeedPhrase(browser);
const credentials = await getWebAuthnCredentials(browser, authenticatorId1);
expect(credentials).toHaveLength(1);

const niceDemoAppView = new DemoAppView(browser);
await niceDemoAppView.open(TEST_APP_NICE_URL, II_URL);
await niceDemoAppView.waitForDisplay();
await niceDemoAppView.resetAlternativeOrigins(
REPLICA_URL,
TEST_APP_CANISTER_ID
);
await niceDemoAppView.resetAlternativeOrigins(TEST_APP_CANISTER_ID);
await niceDemoAppView.setDerivationOrigin(TEST_APP_CANONICAL_URL);
expect(await niceDemoAppView.getPrincipal()).toBe("2vxsx-fae");
await niceDemoAppView.signin();
Expand All @@ -63,18 +55,15 @@ test("Should not issue delegation when derivationOrigin is malformed", async ()
await runInBrowser(async (browser: WebdriverIO.Browser) => {
const authenticatorId1 = await addVirtualAuthenticator(browser);
await browser.url(II_URL);
await FLOWS.registerNewIdentityWelcomeView(DEVICE_NAME1, browser);
await FLOWS.registerNewIdentityWelcomeView(browser);
await FLOWS.addRecoveryMechanismSeedPhrase(browser);
const credentials = await getWebAuthnCredentials(browser, authenticatorId1);
expect(credentials).toHaveLength(1);

const niceDemoAppView = new DemoAppView(browser);
await niceDemoAppView.open(TEST_APP_NICE_URL, II_URL);
await niceDemoAppView.waitForDisplay();
await niceDemoAppView.resetAlternativeOrigins(
REPLICA_URL,
TEST_APP_CANISTER_ID
);
await niceDemoAppView.resetAlternativeOrigins(TEST_APP_CANISTER_ID);
await niceDemoAppView.setDerivationOrigin(
"https://some-random-disallowed-url.com"
);
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/src/test-e2e/authData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FLOWS } from "./flows";
import { addVirtualAuthenticator, runInBrowser, switchToPopup } from "./util";
import { DemoAppView } from "./views";

import { DEVICE_NAME1, II_URL, TEST_APP_NICE_URL } from "./constants";
import { II_URL, TEST_APP_NICE_URL } from "./constants";

test("Authorize ready message should be sent immediately", async () => {
await runInBrowser(async (browser: WebdriverIO.Browser) => {
Expand All @@ -29,7 +29,7 @@ test("Should allow valid message", async () => {
await demoAppView.sendValidMessage(); // message 2: authorize-client

await switchToPopup(browser);
await FLOWS.registerNewIdentityAuthenticateView(DEVICE_NAME1, browser);
await FLOWS.registerNewIdentityAuthenticateView(browser);
await browser
.$("[data-role=notify-auth-success]")
.waitForDisplayed({ timeout: 15_000 });
Expand Down Expand Up @@ -61,7 +61,7 @@ test("Should ignore invalid data and allow second valid message", async () => {
await demoAppView.sendValidMessage(); // message 3

await switchToPopup(browser);
await FLOWS.registerNewIdentityAuthenticateView(DEVICE_NAME1, browser);
await FLOWS.registerNewIdentityAuthenticateView(browser);
await browser
.$("[data-role=notify-auth-success]")
.waitForDisplayed({ timeout: 15_000 });
Expand Down
1 change: 0 additions & 1 deletion src/frontend/src/test-e2e/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const TEST_APP_CANISTER_ID = test_app_canister_ids.test_app.local;
export const TEST_APP_CANONICAL_URL = `https://${TEST_APP_CANISTER_ID}.icp0.io`;
export const TEST_APP_CANONICAL_URL_LEGACY = `https://${TEST_APP_CANISTER_ID}.ic0.app`;
export const TEST_APP_NICE_URL = "https://nice-name.com";
export const REPLICA_URL = "https://icp-api.io";
export const II_URL =
process.env.II_URL ?? "https://identity.internetcomputer.org";

Expand Down
8 changes: 4 additions & 4 deletions src/frontend/src/test-e2e/delegationTtl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "./util";
import { DemoAppView } from "./views";

import { DEVICE_NAME1, II_URL, TEST_APP_NICE_URL } from "./constants";
import { II_URL, TEST_APP_NICE_URL } from "./constants";

test("Delegation maxTimeToLive: 1 min", async () => {
await runInBrowser(async (browser: WebdriverIO.Browser) => {
Expand All @@ -19,7 +19,7 @@ test("Delegation maxTimeToLive: 1 min", async () => {
await demoAppView.setMaxTimeToLive(BigInt(60_000_000_000));
await demoAppView.signin();
await switchToPopup(browser);
await FLOWS.registerNewIdentityAuthenticateView(DEVICE_NAME1, browser);
await FLOWS.registerNewIdentityAuthenticateView(browser);
await demoAppView.waitForAuthenticated();

const exp = await browser.$("#expiration").getText();
Expand All @@ -38,7 +38,7 @@ test("Delegation maxTimeToLive: 1 day", async () => {
await demoAppView.setMaxTimeToLive(BigInt(86400_000_000_000));
await demoAppView.signin();
await switchToPopup(browser);
await FLOWS.registerNewIdentityAuthenticateView(DEVICE_NAME1, browser);
await FLOWS.registerNewIdentityAuthenticateView(browser);
await waitToClose(browser);
expect(await demoAppView.getPrincipal()).not.toBe("2vxsx-fae");
const exp = await browser.$("#expiration").getText();
Expand All @@ -56,7 +56,7 @@ test("Delegation maxTimeToLive: 2 months", async () => {
await demoAppView.setMaxTimeToLive(BigInt(5_184_000_000_000_000)); // 60 days
await demoAppView.signin();
await switchToPopup(browser);
await FLOWS.registerNewIdentityAuthenticateView(DEVICE_NAME1, browser);
await FLOWS.registerNewIdentityAuthenticateView(browser);
await demoAppView.waitForAuthenticated();
const exp = await browser.$("#expiration").getText();
// NB: Max out at 30 days
Expand Down
2 changes: 0 additions & 2 deletions src/frontend/src/test-e2e/flows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const FLOWS = {
return userNumber;
},
registerNewIdentityWelcomeView: async (
deviceName: string,
browser: WebdriverIO.Browser
): Promise<string> => {
const welcomeView = new WelcomeView(browser);
Expand All @@ -33,7 +32,6 @@ export const FLOWS = {
return await FLOWS.register(browser);
},
registerNewIdentityAuthenticateView: async (
deviceName: string,
browser: WebdriverIO.Browser
): Promise<string> => {
const authenticateView = new AuthenticateView(browser);
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/test-e2e/misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test("Device can be renamed", async () => {
await runInBrowser(async (browser: WebdriverIO.Browser) => {
await addVirtualAuthenticator(browser);
await browser.url(II_URL);
await FLOWS.registerNewIdentityWelcomeView(DEVICE_NAME1, browser);
await FLOWS.registerNewIdentityWelcomeView(browser);
const mainView = new MainView(browser);
await mainView.waitForDeviceDisplay(DEVICE_NAME1);
const newName = DEVICE_NAME1 + "-new";
Expand Down
5 changes: 1 addition & 4 deletions src/frontend/src/test-e2e/pinAuth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Principal } from "@dfinity/principal";
import {
DEVICE_NAME1,
II_URL,
REPLICA_URL,
TEST_APP_CANISTER_ID,
TEST_APP_NICE_URL,
} from "./constants";
Expand Down Expand Up @@ -144,9 +143,7 @@ test("Log into client application using PIN registration flow", async () => {
await FLOWS.registerPinNewIdentityAuthenticateView(pin, browser);

const principal = await demoAppView.waitForAuthenticated();
expect(await demoAppView.whoami(REPLICA_URL, TEST_APP_CANISTER_ID)).toBe(
principal
);
expect(await demoAppView.whoami(TEST_APP_CANISTER_ID)).toBe(principal);

// default value
const exp = await browser.$("#expiration").getText();
Expand Down
13 changes: 2 additions & 11 deletions src/frontend/src/test-e2e/principals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import {
import { AuthenticateView, DemoAppView } from "./views";

import {
DEVICE_NAME1,
II_URL,
REPLICA_URL,
TEST_APP_CANISTER_ID,
TEST_APP_CANONICAL_URL,
TEST_APP_CANONICAL_URL_LEGACY,
Expand All @@ -23,10 +21,7 @@ test("Should issue the same principal to nice url and canonical url", async () =
await runInBrowser(async (browser: WebdriverIO.Browser) => {
const authenticatorId1 = await addVirtualAuthenticator(browser);
await browser.url(II_URL);
const userNumber = await FLOWS.registerNewIdentityWelcomeView(
DEVICE_NAME1,
browser
);
const userNumber = await FLOWS.registerNewIdentityWelcomeView(browser);
await FLOWS.addRecoveryMechanismSeedPhrase(browser);
const credentials = await getWebAuthnCredentials(browser, authenticatorId1);
expect(credentials).toHaveLength(1);
Expand Down Expand Up @@ -55,7 +50,6 @@ test("Should issue the same principal to nice url and canonical url", async () =
await niceDemoAppView.open(TEST_APP_NICE_URL, II_URL);
await niceDemoAppView.waitForDisplay();
await niceDemoAppView.updateAlternativeOrigins(
REPLICA_URL,
TEST_APP_CANISTER_ID,
`{"alternativeOrigins":["${TEST_APP_NICE_URL}"]}`,
"certified"
Expand Down Expand Up @@ -85,10 +79,7 @@ test("Should issue the same principal to dapps on legacy & official domains", as
// create a new anchor
const registrationAuthenticator = await addVirtualAuthenticator(browser);
await browser.url(II_URL);
const userNumber = await FLOWS.registerNewIdentityWelcomeView(
DEVICE_NAME1,
browser
);
const userNumber = await FLOWS.registerNewIdentityWelcomeView(browser);
await FLOWS.addRecoveryMechanismSeedPhrase(browser); // avoids being prompted later during authz
const credentials = await getWebAuthnCredentials(
browser,
Expand Down
5 changes: 1 addition & 4 deletions src/frontend/src/test-e2e/recovery/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ test("Recover with phrase", async () => {
await runInBrowser(async (browser: WebdriverIO.Browser) => {
await addVirtualAuthenticator(browser);
await browser.url(II_URL);
const _userNumber = await FLOWS.registerNewIdentityWelcomeView(
DEVICE_NAME1,
browser
);
const _userNumber = await FLOWS.registerNewIdentityWelcomeView(browser);
const mainView = new MainView(browser);
await mainView.waitForDeviceDisplay(DEVICE_NAME1);
const seedPhrase = await FLOWS.addRecoveryMechanismSeedPhrase(browser);
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/test-e2e/recovery/protected/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test("Make recovery protected", async () => {
await runInBrowser(async (browser: WebdriverIO.Browser) => {
await addVirtualAuthenticator(browser);
await browser.url(II_URL);
await FLOWS.registerNewIdentityWelcomeView(DEVICE_NAME1, browser);
await FLOWS.registerNewIdentityWelcomeView(browser);
const mainView = new MainView(browser);
await mainView.waitForDeviceDisplay(DEVICE_NAME1);
const seedPhrase = await FLOWS.addRecoveryMechanismSeedPhrase(browser);
Expand All @@ -23,7 +23,7 @@ test("Make recovery unprotected", async () => {
await runInBrowser(async (browser: WebdriverIO.Browser) => {
await addVirtualAuthenticator(browser);
await browser.url(II_URL);
await FLOWS.registerNewIdentityWelcomeView(DEVICE_NAME1, browser);
await FLOWS.registerNewIdentityWelcomeView(browser);
const mainView = new MainView(browser);
await mainView.waitForDeviceDisplay(DEVICE_NAME1);
const seedPhrase = await FLOWS.addRecoveryMechanismSeedPhrase(browser);
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/test-e2e/recovery/protected/reset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test("Reset protected recovery phrase", async () => {
await runInBrowser(async (browser: WebdriverIO.Browser) => {
await addVirtualAuthenticator(browser);
await browser.url(II_URL);
await FLOWS.registerNewIdentityWelcomeView(DEVICE_NAME1, browser);
await FLOWS.registerNewIdentityWelcomeView(browser);
const mainView = new MainView(browser);
await mainView.waitForDeviceDisplay(DEVICE_NAME1);
const seedPhrase = await FLOWS.addRecoveryMechanismSeedPhrase(browser);
Expand Down Expand Up @@ -37,7 +37,7 @@ test("Reset protected recovery phrase, confirm with incorrect seed phrase", asyn
await runInBrowser(async (browser: WebdriverIO.Browser) => {
await addVirtualAuthenticator(browser);
await browser.url(II_URL);
await FLOWS.registerNewIdentityWelcomeView(DEVICE_NAME1, browser);
await FLOWS.registerNewIdentityWelcomeView(browser);
const mainView = new MainView(browser);
await mainView.waitForDeviceDisplay(DEVICE_NAME1);
const seedPhrase = await FLOWS.addRecoveryMechanismSeedPhrase(browser);
Expand Down
Loading

0 comments on commit f748010

Please sign in to comment.