Merge branch 'main' into wt/t_14ac0a3f
Some checks failed
ci / test (pull_request) Successful in 5m56s
android-ci / android (pull_request) Has been cancelled
ci / sdk (pull_request) Successful in 1m30s
ci / fuzz (pull_request) Has been cancelled

This commit is contained in:
sirius 2026-09-21 15:10:10 +00:00
commit 49756d2a2d
11 changed files with 1013 additions and 19 deletions

View file

@ -540,3 +540,126 @@ fn ratchet_state_survives_reopening_the_store() {
assert_eq!(store.load_ratchet(&pk(1)).expect("load"), Some(blob));
assert_eq!(store.list_messages(&pk(1)).unwrap()[0].plaintext, b"hello");
}
// ---- the wallet catalogue (`wallets`) --------------------------------------
//
// Several wallet *files* live under one identity: the row here is what makes a
// wallet survive a restart, because the wallet child's own config only ever
// describes the one it is pointed at right now.
fn new_wallet(filename: &str, name: Option<&str>) -> onionwire::NewWallet {
onionwire::NewWallet {
name: name.map(str::to_string),
identity_pubkey: pk(7),
onion_locator: "walletloc.onion".to_string(),
wallet_filename: filename.to_string(),
}
}
#[test]
fn create_wallet_stores_every_field_and_reads_it_back() {
let dir = tempfile::tempdir().expect("tempdir");
let store = Store::open_at_with_passphrase(dir.path(), "wallet-pass").expect("open");
let row = store
.create_wallet(&new_wallet("savings", Some("Savings")))
.expect("create");
assert!(row.id > 0, "id assigned: {row:?}");
assert!(row.created_at > 0, "created_at stamped: {row:?}");
assert_eq!(row.wallet_filename, "savings");
assert_eq!(row.name.as_deref(), Some("Savings"));
assert_eq!(row.identity_pubkey, pk(7));
assert_eq!(row.onion_locator, "walletloc.onion");
let got = store
.get_wallet_by_id(row.id)
.expect("get")
.expect("row exists");
assert_eq!(got, row, "the stored row is what came back");
}
#[test]
fn multiple_wallets_coexist_and_survive_a_reopen() {
let dir = tempfile::tempdir().expect("tempdir");
let (spending, savings) = {
let store = Store::open_at_with_passphrase(dir.path(), "wallet-pass").expect("open");
let spending = store
.create_wallet(&new_wallet("spending", Some("Spending")))
.expect("spending");
let savings = store
.create_wallet(&new_wallet("savings", None))
.expect("savings");
assert_ne!(spending.id, savings.id, "two wallets, two rows");
(spending.id, savings.id)
};
let store = Store::open_at_with_passphrase(dir.path(), "wallet-pass").expect("reopen");
let rows = store.list_wallets().expect("list");
assert_eq!(rows.len(), 2, "both wallets remembered: {rows:?}");
assert_eq!(rows[0].id, spending, "creation order");
assert_eq!(rows[1].id, savings);
assert_eq!(
rows[1].name, None,
"an unlabelled wallet round-trips as None"
);
assert_eq!(rows[1].wallet_filename, "savings");
}
#[test]
fn a_second_wallet_cannot_reuse_a_wallet_filename() {
let dir = tempfile::tempdir().expect("tempdir");
let store = Store::open_at_with_passphrase(dir.path(), "wallet-pass").expect("open");
let first = store
.create_wallet(&new_wallet("onionwire", None))
.expect("first");
let err = store
.create_wallet(&new_wallet("onionwire", Some("Clash")))
.expect_err("a duplicate filename must not overwrite the first wallet");
assert!(
err.to_string().contains("onionwire"),
"names the file: {err}"
);
let rows = store.list_wallets().expect("list");
assert_eq!(rows.len(), 1, "the rejected insert left one row: {rows:?}");
assert_eq!(rows[0], first, "the first wallet is untouched");
}
#[test]
fn delete_wallet_removes_only_that_row() {
let dir = tempfile::tempdir().expect("tempdir");
let store = Store::open_at_with_passphrase(dir.path(), "wallet-pass").expect("open");
let a = store.create_wallet(&new_wallet("a", None)).expect("a");
let b = store.create_wallet(&new_wallet("b", None)).expect("b");
assert!(store.delete_wallet(a.id).expect("delete"), "row was there");
assert_eq!(store.get_wallet_by_id(a.id).expect("get"), None);
let rows = store.list_wallets().expect("list");
assert_eq!(rows.len(), 1);
assert_eq!(rows[0].id, b.id);
assert!(
!store
.delete_wallet(9999)
.expect("unknown id is not an error"),
"nothing to delete reports false"
);
}
#[test]
fn a_wallet_without_a_label_or_locator_stores_nulls_and_rejects_a_blank_filename() {
let dir = tempfile::tempdir().expect("tempdir");
let store = Store::open_at_with_passphrase(dir.path(), "wallet-pass").expect("open");
let mut blank = new_wallet("blank", Some(" "));
blank.onion_locator = String::new();
let row = store.create_wallet(&blank).expect("blank label");
assert_eq!(row.name, None, "a whitespace label is no label");
assert_eq!(row.onion_locator, "", "a locator may be empty pre-publish");
let err = store
.create_wallet(&new_wallet(" ", None))
.expect_err("an empty filename cannot name a wallet file");
assert!(err.to_string().contains("filename"), "{err}");
}

View file

@ -819,6 +819,80 @@ async fn mock_digest_auth_accepted() {
assert!(got.starts_with('4'), "got {got}");
}
/// The seed is a spend key: `mnemonic` must be one `query_key mnemonic` call
/// and nothing else, so the caller sees exactly what the open wallet answers.
#[tokio::test]
async fn mnemonic_returns_the_words_the_rpc_answers() {
const WORDS: &str = "one two three four five six seven eight nine ten eleven twelve \
thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty twentyone \
twentytwo twentythree twentyfour twentyfive";
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let port = listener.local_addr().unwrap().port();
tokio::spawn(serve_rpc_conns(
listener,
Arc::new(|method: &str| match method {
"query_key" => rpc_result(&format!(r#"{{"key":"{WORDS}"}}"#)),
other => panic!("mnemonic must make one query_key call, saw {other}"),
}),
None,
None,
));
let got = recording_wallet(port).mnemonic().await.expect("mnemonic");
assert_eq!(got, WORDS);
}
/// A wallet with no open file answers a JSON-RPC error. It must surface as the
/// wallet's error, and the RPC login from the URL must not ride along with it.
#[tokio::test]
async fn mnemonic_surfaces_an_rpc_error_without_leaking_the_login() {
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let port = listener.local_addr().unwrap().port();
tokio::spawn(serve_rpc_conns(
listener,
Arc::new(|_: &str| rpc_error(-1, "wallet file is not open")),
None,
None,
));
let err = recording_wallet(port).mnemonic().await.unwrap_err();
let msg = err.to_string();
assert!(msg.contains("wallet file is not open"), "got {err}");
assert!(!msg.contains("secret"), "password leaked: {err}");
assert!(!msg.contains("http://"), "endpoint leaked: {err}");
}
/// The refused-digest refusal names the login in prose ("the login does not
/// match"), which is exactly the copy that must not carry the credential.
#[tokio::test]
async fn mnemonic_refuses_a_rejected_digest_without_leaking_the_login() {
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let port = listener.local_addr().unwrap().port();
tokio::spawn(serve_rpc_conns_with(
listener,
Arc::new(|_: &str| "HTTP/1.1 401 Unauthorized\r\nContent-Length: 0\r\n\r\n".to_string()),
None,
None,
true,
));
let err = recording_wallet(port).mnemonic().await.unwrap_err();
let msg = err.to_string();
assert!(msg.contains("digest rejected"), "got {err}");
assert!(!msg.contains("secret"), "password leaked: {err}");
}
/// No endpoint, no dial: the refusal is the configured-guard copy the rest of
/// the wallet uses, not a connection error.
#[test]
fn mnemonic_on_an_unconfigured_wallet_is_a_refusal_not_a_dial() {
let w = Wallet::disabled();
let err = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.block_on(w.mnemonic())
.unwrap_err();
assert_eq!(err.to_string(), NOT_CONFIGURED_MSG);
}
/// Answers the Digest challenge, then holds the reply for `delay`. Lets a test
/// prove which call classes get which budget.
async fn serve_delayed(listener: TcpListener, delay: std::time::Duration) {