Cotton code
44 lines · 2.2 KB · RustRaw
//! WhatsApp's passkey step through the real session host and Chrome, on a Mac//! that has both. Run before a live re-link://!//!   COTTON_SESSION_HOST=apps/cotton/Mac/build/helpers/cotton-session-host \//!     cargo test -p cotton-mac --test whatsapp_passkey_chrome -- --ignored --nocapture//!//! It opens web.whatsapp.com in the broker's visible Chrome, asks for a//! passkey over synthetic options (Chrome shows its sheet, or the page its Use//! passkey button), then cancels: the ask must end at once and the tab close.use std::sync::Arc;use std::time::{Duration, Instant};use cotton_mac::whatsapp_passkey::{ChromePasskey, PasskeyBrowser};use serde_json::json;// RULE: the passkey tab opens at web.whatsapp.com through the broker and// a cancel ends the ask at once, closing the tab.#[test]#[ignore = "needs Chrome and a built cotton-session-host (COTTON_SESSION_HOST)"]fn the_passkey_tab_opens_at_whatsapp_and_a_cancel_ends_it() {    let host = std::env::var("COTTON_SESSION_HOST").expect("COTTON_SESSION_HOST");    // A socket path holds at most 103 bytes: a short folder.    let data = tempfile::Builder::new().prefix("wa").tempdir_in("/tmp").unwrap();    let chrome = Arc::new(ChromePasskey::new(host.into(), data.path().to_path_buf()));    let options = json!({        "challenge": "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8", "timeout": 60000, "rpId": "whatsapp.com",        "allowCredentials": [{ "id": "Y3JlZGVudGlhbC1pZC0xNg", "type": "public-key", "transports": ["internal", "hybrid"] }],        "userVerification": "required", "extensions": null    });    let asking = {        let chrome = Arc::clone(&chrome);        std::thread::spawn(move || chrome.assert("walk", &options))    };    // Long enough for the profile to start, the page to load and the ask to begin.    std::thread::sleep(Duration::from_secs(20));    assert!(!asking.is_finished(), "the ask ended before anyone answered: {:?}", asking.join());    let cancelled = Instant::now();    chrome.close("walk");    let answer = asking.join().unwrap();    println!("ask ended {:?} after the cancel: {answer:?}", cancelled.elapsed());    assert!(answer.is_err());    assert!(cancelled.elapsed() < Duration::from_secs(10), "the cancel did not end the ask");}