Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Sign-in: a code sent to the devices after a text is checked as theirs

Yashwanth Kamireddi54af212fa30e
diff --git a/.uiverify/signin-code-route.mjs b/.uiverify/signin-code-route.mjs
new file mode 100644
index 0000000..d09b765
--- /dev/null
+++ b/.uiverify/signin-code-route.mjs
@@ -0,0 +1,60 @@
+// The code screen sends the code back the way it came: texted to a number, it is checked as
+// that number's; asked for again on the devices after a text, it is checked as a device code
+// again — a device code checked as a texted one was refused as wrong, every time.
+//
+// URL=http://localhost:4203 ENGINE=webkit node .uiverify/signin-code-route.mjs
+import { engine, engineName } from "./engine.mjs";
+import { SERVICES, installStub } from "./stub.mjs";
+const URL = process.env.URL ?? "http://localhost:4173";
+const b = await engine.launch();
+let failures = 0;
+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${engineName} ${m}`); if (!p) failures++; };
+const TWO_FACTOR = { trustedDeviceCount: 2, phones: [{ id: 7, maskedNumber: "+1 (•••) •••-••01" }], tooManyCodesSent: false };
+
+async function codeScreen() {
+ const ctx = await b.newContext({ viewport: { width: 1100, height: 800 } });
+ await ctx.addInitScript(installStub, { screen: "code", services: SERVICES, twoFactor: TWO_FACTOR });
+ const page = await ctx.newPage();
+ page.on("pageerror", (e) => ok(false, `page error: ${e.message}`));
+ await page.goto(URL, { waitUntil: "networkidle" });
+ await page.fill('input[aria-label="Apple Account"]', "[email protected]");
+ await page.fill('input[aria-label="Password"]', "not-a-real-password");
+ await page.click('button[type="submit"]');
+ await page.locator(".code").waitFor();
+ await page.waitForTimeout(200);
+ return { ctx, page };
+}
+const type = async (page, code) => {
+ await page.locator('[aria-label="Digit 1"]').click();
+ await page.keyboard.type(code);
+ await page.waitForTimeout(300);
+};
+
+{
+ const { ctx, page } = await codeScreen();
+ await page.getByRole("button", { name: "Didn't get a code?" }).click();
+ await page.getByRole("button", { name: /^Text / }).click();
+ await page.waitForTimeout(200);
+ ok(/texted a code/.test(await page.locator(".lede").innerText()), "after Text, the screen says where the code went");
+ await type(page, "123456");
+ ok((await page.evaluate(() => window.__codeVia)) === "sms:7", `a texted code is checked as the number's [${await page.evaluate(() => window.__codeVia)}]`);
+ await ctx.close();
+}
+{
+ const { ctx, page } = await codeScreen();
+ await page.getByRole("button", { name: "Didn't get a code?" }).click();
+ await page.getByRole("button", { name: /^Text / }).click();
+ await page.waitForTimeout(200);
+ await page.getByRole("button", { name: "Didn't get a code?" }).click();
+ await page.getByRole("button", { name: "Send to my devices again" }).click();
+ await page.waitForTimeout(200);
+ const lede = await page.locator(".lede").innerText();
+ ok(!/texted/.test(lede), `sent to the devices after a text, the screen no longer says it was texted [${lede}]`);
+ await type(page, "654321");
+ ok((await page.evaluate(() => window.__codeVia)) === "devices", `and the code is checked as a device code [${await page.evaluate(() => window.__codeVia)}]`);
+ await ctx.close();
+}
+
+await b.close();
+console.log(failures ? `\n${failures} FAILED` : "\nall passed");
+process.exit(failures ? 1 : 0);
diff --git a/.uiverify/stub.mjs b/.uiverify/stub.mjs
index 02db99b..74a4658 100644
--- a/.uiverify/stub.mjs
+++ b/.uiverify/stub.mjs
@@ -162,7 +162,7 @@ export function installStub({ screen, services, twoFactor, calendarFixture, note
return { hasStoredSession: screen === "library", signedIn: screen === "library" };
case "auth_resume": return screen === "library" ? "library" : "signin";
case "auth_sign_in": return screen === "code" ? "needs_two_factor" : "complete";
- case "auth_submit_code": return null;
+ case "auth_submit_code": window.__codeVia = "devices"; return null;
case "account_services": return services;
case "calendar_events": {
window.__eventReads = (window.__eventReads ?? 0) + 1;
@@ -990,7 +990,7 @@ export function installStub({ screen, services, twoFactor, calendarFixture, note
case "auth_two_factor_options": return twoFactor;
case "auth_resend_code": return null;
case "auth_send_sms": return null;
- case "auth_submit_sms_code": return null;
+ case "auth_submit_sms_code": window.__codeVia = `sms:${args?.phoneId}`; return null;
case "auth_sign_out": sessionStorage.setItem("__signedOut", JSON.stringify(args)); return null;
case "search_everything": {
// A search across every app, as search.rs answers it: every word has to begin a word
diff --git a/src/screens/CodeEntry.tsx b/src/screens/CodeEntry.tsx
index b57274b..c07f27d 100644
--- a/src/screens/CodeEntry.tsx
+++ b/src/screens/CodeEntry.tsx
@@ -156,7 +156,14 @@ export function CodeEntry({
className="quiet"
type="button"
disabled={busy}
- onClick={() => run(api.resendCode, "Sent again. Check your devices.")}
+ // Back on the devices: the code they show is checked as theirs, not as the
+ // number's it was texted to before — that was refused as wrong every time.
+ onClick={() =>
+ run(async () => {
+ await api.resendCode();
+ setSmsPhoneId(null);
+ }, "Sent again. Check your devices.")
+ }
>
Send to my devices again
</button>