Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nmattia committed Nov 23, 2023
1 parent 7e95d95 commit 141e3c3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test("Should not issue delegation when /.well-known/ii-alternative-origins has t
'{"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"
);
await niceDemoAppView.setDerivationOrigin(await TEST_APP_CANONICAL_URL());
await niceDemoAppView.setDerivationOrigin(TEST_APP_CANONICAL_URL);
expect(await niceDemoAppView.getPrincipal()).toBe("2vxsx-fae");
await niceDemoAppView.signin();

Expand Down Expand Up @@ -70,7 +70,7 @@ test("Should not follow redirect returned by /.well-known/ii-alternative-origins
'{"alternativeOrigins":["https://evil.com"]}',
"redirect"
);
await niceDemoAppView.setDerivationOrigin(await TEST_APP_CANONICAL_URL());
await niceDemoAppView.setDerivationOrigin(TEST_APP_CANONICAL_URL);
expect(await niceDemoAppView.getPrincipal()).toBe("2vxsx-fae");
await niceDemoAppView.signin();

Expand Down Expand Up @@ -108,9 +108,7 @@ test("Should fetch /.well-known/ii-alternative-origins using the non-raw url", a
`{"alternativeOrigins":["${TEST_APP_NICE_URL}"]}`,
"certified"
);
await niceDemoAppView.setDerivationOrigin(
await TEST_APP_CANONICAL_URL_RAW()
);
await niceDemoAppView.setDerivationOrigin(TEST_APP_CANONICAL_URL_RAW);
expect(await niceDemoAppView.getPrincipal()).toBe("2vxsx-fae");
await niceDemoAppView.signin();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test("Should not issue delegation when derivationOrigin is missing from /.well-k
await niceDemoAppView.open(TEST_APP_NICE_URL, II_URL);
await niceDemoAppView.waitForDisplay();
await niceDemoAppView.resetAlternativeOrigins();
await niceDemoAppView.setDerivationOrigin(await TEST_APP_CANONICAL_URL());
await niceDemoAppView.setDerivationOrigin(TEST_APP_CANONICAL_URL);
expect(await niceDemoAppView.getPrincipal()).toBe("2vxsx-fae");
await niceDemoAppView.signin();

Expand Down
31 changes: 23 additions & 8 deletions src/frontend/src/test-e2e/constants.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
import { readCanisterId } from "../../../../vite.plugins";
import { execSync } from "child_process";

const testAppCanisterId = () => readCanisterId({ canisterName: "test_app" });
/**
* Read a canister ID from dfx's local state
*/
export const readCanisterId = ({
canisterName,
}: {
canisterName: string;
}): string => {
try {
const stdout = execSync(`dfx canister id ${canisterName}`);
const res = stdout.toString().trim();
console.log("Canister: ", canisterName, res);
return res;
} catch (e) {
throw Error(`Could not get canister ID: ${e}`);
}
};

export const TEST_APP_CANONICAL_URL = async () =>
`https://${await testAppCanisterId()}.icp0.io`;
export const TEST_APP_CANONICAL_URL_RAW = async () =>
`https://${await testAppCanisterId()}.raw.icp0.io`;
export const TEST_APP_CANONICAL_URL_LEGACY = async () =>
`https://${await testAppCanisterId()}.ic0.app`;
const testAppCanisterId = readCanisterId({ canisterName: "test_app" });

export const TEST_APP_CANONICAL_URL = `https://${testAppCanisterId}.icp0.io`;
export const TEST_APP_CANONICAL_URL_RAW = `https://${testAppCanisterId}.raw.icp0.io`;
export const TEST_APP_CANONICAL_URL_LEGACY = `https://${testAppCanisterId}.ic0.app`;
export const TEST_APP_NICE_URL = "https://nice-name.com";
export const II_URL =
process.env.II_URL ?? "https://identity.internetcomputer.org";
Expand Down
14 changes: 5 additions & 9 deletions src/frontend/src/test-e2e/principals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ test("Should issue the same principal to nice url and canonical url", async () =
expect(credentials).toHaveLength(1);

const canonicalDemoAppView = new DemoAppView(browser);
await canonicalDemoAppView.open(await TEST_APP_CANONICAL_URL(), II_URL);
await canonicalDemoAppView.open(TEST_APP_CANONICAL_URL, II_URL);
await canonicalDemoAppView.waitForDisplay();
await canonicalDemoAppView.setDerivationOrigin(
await TEST_APP_CANONICAL_URL()
);
await canonicalDemoAppView.setDerivationOrigin(TEST_APP_CANONICAL_URL);
expect(await canonicalDemoAppView.getPrincipal()).toBe("2vxsx-fae");
await canonicalDemoAppView.signin();

Expand All @@ -54,7 +52,7 @@ test("Should issue the same principal to nice url and canonical url", async () =
`{"alternativeOrigins":["${TEST_APP_NICE_URL}"]}`,
"certified"
);
await niceDemoAppView.setDerivationOrigin(await TEST_APP_CANONICAL_URL());
await niceDemoAppView.setDerivationOrigin(TEST_APP_CANONICAL_URL);
expect(await niceDemoAppView.getPrincipal()).toBe("2vxsx-fae");
await niceDemoAppView.signin();

Expand Down Expand Up @@ -109,10 +107,8 @@ test("Should issue the same principal to dapps on legacy & official domains", as
};

// Compare that principals issues for ic0.app & icp0.io are the same
const principal1 = await authenticate(await TEST_APP_CANONICAL_URL());
const principal2 = await authenticate(
await TEST_APP_CANONICAL_URL_LEGACY()
);
const principal1 = await authenticate(TEST_APP_CANONICAL_URL);
const principal2 = await authenticate(TEST_APP_CANONICAL_URL_LEGACY);

expect(principal1).toEqual(principal2);
});
Expand Down

0 comments on commit 141e3c3

Please sign in to comment.