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: sending the code again reports why Apple refused, like the rest of sign-in

Yashwanth Kamireddidfde673c1be6
diff --git a/crates/quince-auth/src/lib.rs b/crates/quince-auth/src/lib.rs
index 5cb9c4a..e27e3be 100644
--- a/crates/quince-auth/src/lib.rs
+++ b/crates/quince-auth/src/lib.rs
@@ -1045,9 +1045,8 @@ impl Client {
self.capture(&r);
let status = r.status();
if !status.is_success() && status != StatusCode::NO_CONTENT {
- return Err(Error::Protocol(format!(
- "couldn't resend the code ({status})"
- )));
+ let body = r.text().await.unwrap_or_default();
+ return Err(apple_error("sending the code again", status, &body));
}
Ok(())
}
@@ -1066,9 +1065,8 @@ impl Client {
self.capture(&r);
let status = r.status();
if !status.is_success() && status != StatusCode::NO_CONTENT {
- return Err(Error::Protocol(format!(
- "couldn't send the text ({status})"
- )));
+ let body = r.text().await.unwrap_or_default();
+ return Err(apple_error("texting the code", status, &body));
}
Ok(())
}
diff --git a/crates/quince-auth/tests/auth_flow.rs b/crates/quince-auth/tests/auth_flow.rs
index e14e181..fd58408 100644
--- a/crates/quince-auth/tests/auth_flow.rs
+++ b/crates/quince-auth/tests/auth_flow.rs
@@ -1016,3 +1016,33 @@ async fn a_locked_account_says_so_not_wrong_password() {
);
assert!(err.to_string().contains("iforgot.apple.com"), "{err}");
}
+
+/// Asking for the code again too often is answered 429. That reads as "wait", the same as
+/// throttling anywhere else in sign-in, never as raw HTTP text, by either way of sending it.
+#[tokio::test]
+async fn asking_for_the_code_again_too_often_says_to_wait() {
+ let server = MockServer::start().await;
+ mount_init(&server, 200).await;
+ mount_complete(&server, 409).await;
+ Mock::given(method("PUT"))
+ .and(path("/appleauth/auth/verify/trusteddevice/securitycode"))
+ .respond_with(ResponseTemplate::new(429))
+ .mount(&server)
+ .await;
+ Mock::given(method("PUT"))
+ .and(path("/appleauth/auth/verify/phone"))
+ .respond_with(ResponseTemplate::new(429))
+ .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 err = client.resend_to_devices().await.unwrap_err();
+ assert!(matches!(err, quince_auth::Error::RateLimited), "{err:?}");
+ let err = client.send_sms(1).await.unwrap_err();
+ assert!(matches!(err, quince_auth::Error::RateLimited), "{err:?}");
+}