Cotton code
56 lines · 3.4 KB · RustRaw
//! FAKES AUDIT (coordinator, 24 Nov 2026): the fake object every Mac test lands on refuses what the Worker//! refuses, so a Mac test can never pass on an OK the real object would not give. Each refusal here is the//! Worker's own (apps/business/src/business.ts import, `refuseDeviceClear`; seal.ts `blindBudget`), and a refused//! call keeps nothing. Synthetic rows only.mod support;use serde_json::{json, Value};use support::object::{kit_table, sealed_table, FakeObject, BLIND_PER_CALL, IMPORT_ROWS};fn post(object: &FakeObject, body: Value) -> (u16, Value) {    let answer = reqwest::blocking::Client::new().post(format!("{}/v1/act", object.server.url)).json(&body).send().expect("the fake answers");    (answer.status().as_u16(), answer.json().unwrap_or(Value::Null))}fn object() -> FakeObject {    FakeObject::start("00000000-0000-4000-8000-00000000fa4e", "+15550000000", vec![kit_table("seal_key"), sealed_table("person", &["archived_at", "trashed_at"], &["full_name"], &[])])}fn sealed_row(id: &str, tokens: usize) -> Value {    json!({ "table": "person", "id": id, "data": { "sealed_enc": "s1:x", "dek_enc": "d1:x", "seal_v": 1 }, "blind": (0..tokens).map(|t| format!("tok{t}")).collect::<Vec<_>>() })}#[test]fn an_import_over_the_worker_limits_is_refused_and_keeps_nothing() {    let object = object();    let rows: Vec<Value> = (0..=IMPORT_ROWS).map(|i| sealed_row(&format!("p{i}"), 0)).collect();    let (status, body) = post(&object, json!({ "act": "import_rows", "args": { "rows": rows } }));    assert_eq!((status, body["code"].as_str()), (413, Some("too_many")));    let heavy = vec![sealed_row("a", BLIND_PER_CALL), sealed_row("b", 1)];    let (status, body) = post(&object, json!({ "act": "import_rows", "args": { "rows": heavy } }));    assert_eq!((status, body["code"].as_str()), (413, Some("too_large")));    // One row alone is exempt, as on the Worker.    let (status, _) = post(&object, json!({ "act": "import_rows", "args": { "rows": [sealed_row("alone", BLIND_PER_CALL + 1)] } }));    assert_eq!(status, 200);    assert_eq!(object.state.lock().unwrap().live("person").len(), 1, "a refused call kept rows");}#[test]fn a_sealed_column_in_the_clear_an_unknown_column_or_table_is_refused() {    let object = object();    let clear = json!({ "table": "person", "id": "c", "data": { "full_name": "Invented Name" } });    let (status, body) = post(&object, json!({ "act": "import_rows", "args": { "rows": [sealed_row("ok", 1), clear] } }));    assert_eq!((status, body["code"].as_str()), (400, Some("sealed_in_clear")));    assert!(object.state.lock().unwrap().live("person").is_empty(), "the whole call is refused");    let (status, body) = post(&object, json!({ "act": "create", "args": { "table": "person", "id": "s", "data": { "sealed_enc": "s1:x", "dek_enc": "d1:x", "seal_v": 1, "no_such_column": 1 } } }));    assert_eq!((status, body["code"].as_str()), (400, Some("bad_column")));    let (status, body) = post(&object, json!({ "act": "create", "args": { "table": "no_such_table", "id": "x", "data": {} } }));    assert_eq!((status, body["code"].as_str()), (404, Some("no_such_table")));    // A clear column of a sealed table is the device's to say.    let (status, _) = post(&object, json!({ "act": "create", "args": { "table": "person", "id": "t", "data": { "sealed_enc": "s1:x", "dek_enc": "d1:x", "seal_v": 1, "trashed_at": null } } }));    assert_eq!(status, 200);}