feat(hub): email one-time-code sign-in

POST /v1/auth/email/start and /verify with HMAC-protected 8-digit codes
(10 min, 5 tries, atomic single use), browser-bound via a __Host- cookie,
same-origin checks, per-address/source/global rate limits and an injectable
sender. Enabled in /v1/info only when SMTP is configured. Email identities
use external_identities(provider='email') and never merge with GitHub.
This commit is contained in:
Loki 2026-10-24 17:42:49 +02:00
parent f1883e5001
commit cca084b0ae
Signed by: boba
GPG key ID: 253067914055423B
20 changed files with 1756 additions and 59 deletions

View file

@ -107,3 +107,28 @@ async fn smtp_probe_requires_tls_and_never_falls_back_to_cleartext_authenticatio
assert!(!commands.contains("AUTH"));
assert!(!commands.contains("MAIL FROM"));
}
#[test]
fn email_code_messages_are_bilingual_and_carry_no_links() {
use vnox_hub::mail::layout::Lang;
let origin = parse_origin("https://central.loki-code.dev").unwrap();
for (lang, tag, phrase) in [
(Lang::Ru, "lang=\"ru\"", "10 минут"),
(Lang::En, "lang=\"en\"", "10 minutes"),
] {
let email = templates::render_email_code(&origin, "12345678", lang).unwrap();
assert!(email.html.contains(tag) && email.html.contains(phrase));
assert!(email.text.contains("12345678") && email.html.contains("12345678"));
assert!(email.text.contains(phrase));
// No button and no copy-the-link block; only the bare origin in the footer.
assert_eq!(email.html.matches("href=\"").count(), 1);
assert!(!email.html.contains("?token=") && !email.html.contains("/login"));
assert!(!email.text.contains("http://") && !email.text.contains("?token"));
assert!(!email.subject.contains('\u{2014}'));
}
assert!(templates::render_email_code(&origin, "1234567", Lang::En).is_err());
assert!(templates::render_email_code(&origin, "1234567a", Lang::Ru).is_err());
assert_eq!(Lang::from_tag(Some("en")), Lang::En);
assert_eq!(Lang::from_tag(Some("de")), Lang::Ru);
assert_eq!(Lang::from_tag(None), Lang::Ru);
}