Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.
Rust apple-notesapple-reminderscloudkitcrdtdesktop-appicloudicloud-calendaricloud-driveicloud-notesicloud-photosiphonelinuxlinux-desktoplocal-firstoffline-firstprivacyrusttauritauri-appwindows
Sign-in: a failed answer about where a code can go is an error, never 'nowhere to send'
Yashwanth Kamireddi6a77704ea94e
diff --git a/crates/quince-auth/src/lib.rs b/crates/quince-auth/src/lib.rsindex c99d899..1159bc9 100644--- a/crates/quince-auth/src/lib.rs+++ b/crates/quince-auth/src/lib.rs@@ -1257,9 +1257,37 @@ impl Client {.send().await?;self.capture(&r);+ let status = r.status();let text = r.text().await.unwrap_or_default();+ // A reply Apple refused, or one that names no devices and no numbers at all, says+ // nothing about where a code can go. Read as "0 devices, no numbers" it told someone+ // with an iPhone and a number that their account had nowhere to send a code (reported+ // on X, 5 Nov 2026, after airplane-mode codes had failed): it is an error, and the code+ // screen falls back to its plain wording.+ if !status.is_success() {+ return Err(apple_error(+ "reading where Apple can send a code",+ status,+ &text,+ ));+ }let v = auth_options_of(&text);let places = two_factor_places(&v);+ let says_where = places.iter().any(|p| {+ [+ "trustedDeviceCount",+ "hasTrustedDevices",+ "trustedPhoneNumbers",+ "trustedPhoneNumber",+ ]+ .iter()+ .any(|k| p.get(*k).is_some())+ });+ if !says_where {+ return Err(Error::Protocol(+ "Apple didn't say where it can send a code".into(),+ ));+ }let phones = trusted_phones(&v);self.phones.clone_from(&phones);diff --git a/crates/quince-auth/tests/auth_flow.rs b/crates/quince-auth/tests/auth_flow.rsindex 2c035dc..5a304bf 100644--- a/crates/quince-auth/tests/auth_flow.rs+++ b/crates/quince-auth/tests/auth_flow.rs@@ -1148,10 +1148,10 @@ async fn trusted_numbers_are_found_wherever_apple_keeps_them() {"bridgeInitiateData": {"phoneNumberVerification": {"trustedPhoneNumbers": [- { "id": 1, "numberWithDialCode": "+91 ••••• ••318", "pushMode": "sms" },+ { "id": 1, "numberWithDialCode": "+1 ••• ••• ••42", "pushMode": "sms" },{ "id": 2, "obfuscatedNumber": "(•••) •••-••12", "pushMode": "voice", "nonFTEU": true }],- "trustedPhoneNumber": { "id": 1, "numberWithDialCode": "+91 ••••• ••318", "pushMode": "sms" },+ "trustedPhoneNumber": { "id": 1, "numberWithDialCode": "+1 ••• ••• ••42", "pushMode": "sms" },"securityCode": { "tooManyCodesSent": true }}}@@ -1202,7 +1202,7 @@ async fn trusted_numbers_are_found_wherever_apple_keeps_them() {let options = client.two_factor_options().await.unwrap();let ids: Vec<u64> = options.phones.iter().map(|p| p.id).collect();assert_eq!(ids, vec![1, 2], "{label}: each number once");- assert_eq!(options.phones[0].masked_number, "+91 ••••• ••318");+ assert_eq!(options.phones[0].masked_number, "+1 ••• ••• ••42");assert_eq!(options.phones[1].mode, "voice", "{label}");assert_eq!(options.trusted_device_count, 0, "{label}");assert!(options.too_many_codes_sent, "{label}");@@ -1223,6 +1223,64 @@ async fn trusted_numbers_are_found_wherever_apple_keeps_them() {}}+/// Apple's answer to "where can a code go" refused, empty, or a page with nothing in it: an+/// error, never "this account has nowhere to send a code" to someone whose iPhone and number+/// are right there. An account Apple says truly has none still reads as none.+#[tokio::test]+async fn a_failed_answer_is_never_nowhere_to_send() {+ for (label, reply, said) in [+ (+ "refused",+ ResponseTemplate::new(401).set_body_string("{}"),+ false,+ ),+ (+ "empty",+ ResponseTemplate::new(200).set_body_json(json!({})),+ false,+ ),+ (+ "bare page",+ ResponseTemplate::new(200)+ .insert_header("content-type", "text/html")+ .set_body_string("<html></html>"),+ false,+ ),+ (+ "truly none",+ ResponseTemplate::new(200)+ .set_body_json(json!({ "trustedDeviceCount": 0, "trustedPhoneNumbers": [] })),+ true,+ ),+ ] {+ let server = MockServer::start().await;+ mount_init(&server, 200).await;+ mount_complete(&server, 409).await;+ Mock::given(method("GET"))+ .and(path("/appleauth/auth"))+ .respond_with(reply)+ .mount(&server)+ .await;+ let dir = tempfile::tempdir().unwrap();+ let mut client = client_for(&server, dir.path());+ client+ .sign_in("[email protected]", "hunter2")+ .await+ .unwrap();+ let options = client.two_factor_options().await;+ if said {+ let o = options.unwrap();+ assert_eq!((o.trusted_device_count, o.phones.len()), (0, 0), "{label}");+ } else {+ assert!(+ options.is_err(),+ "{label}: {:?}",+ options.map(|o| o.trusted_device_count)+ );+ }+ }+}+/// The reply as it has always been, with the numbers at the top: read as before, texted.#[tokio::test]async fn trusted_numbers_at_the_top_are_still_texted() {