Owner-authorized recovery of accumulated source changes.
Includes accepted work and in-progress changes; NOT a release or acceptance.
Parent baseline 1b6db09bd1. Runtime data, build caches and local credentials excluded.
158 lines
6.0 KiB
Rust
158 lines
6.0 KiB
Rust
//! Story 3.8 / AT-3.8-05: a revoked Resource is denied on both supported revisions, and the
|
|
//! denial telemetry carries the correlation identity but never the Resource URI/name/MIME/digest
|
|
//! or any content. The positive control proves the capture sink really records an allowed read.
|
|
//!
|
|
//! The tombstone is written with SQL into the same real schema the endpoint reads (the Admin revoke
|
|
//! path is exercised by `admin-api`); everything else here is the unchanged production MCP path.
|
|
|
|
use serde_json::json;
|
|
|
|
use super::fixtures::*;
|
|
|
|
async fn seed_tombstone(endpoint: &ResourceEndpoint) {
|
|
sqlx::query(
|
|
"insert into resource_security_revocations (
|
|
workspace_id, resource_id, revoked_at, actor_user_id, request_id, trace_id
|
|
) values ('ws_default', $1, now(), 'user_default_owner', 'story38-fixture', 'story38-fixture')",
|
|
)
|
|
.bind(endpoint.text.id.as_str())
|
|
.execute(endpoint.registry.pool())
|
|
.await
|
|
.expect("the fixture tombstone must be written into the live schema");
|
|
}
|
|
|
|
/// The revoked read is denied on both revisions; the captured telemetry keeps the Request ID and
|
|
/// the safe outcome only, while the allowed read is captured as a successful outcome.
|
|
#[tokio::test]
|
|
async fn story38_revoked_read_and_list_telemetry_are_content_free_on_both_revisions() {
|
|
let endpoint = standard_endpoint("revocation_telemetry").await;
|
|
let canary = String::from_utf8(endpoint.text.bytes.clone()).expect("text fixture is UTF-8");
|
|
seed_tombstone(&endpoint).await;
|
|
|
|
let denied_logs = CapturedLogs::default();
|
|
let mut denied_bodies = Vec::new();
|
|
{
|
|
let _capture = denied_logs.install();
|
|
for revision in supported_revisions() {
|
|
let response = read_resource(
|
|
&endpoint,
|
|
&revision,
|
|
&endpoint.text.uri,
|
|
Some("story38-denied-corr"),
|
|
)
|
|
.await;
|
|
denied_bodies.push((revision.clone(), json_body(response).await));
|
|
}
|
|
// The page must keep the other bound Resources while omitting the revoked one.
|
|
for revision in supported_revisions() {
|
|
let listed = json_body(list_resources(&endpoint, &revision, json!({})).await).await;
|
|
let uris = listed["result"]["resources"]
|
|
.as_array()
|
|
.expect("resources/list must still return a page")
|
|
.iter()
|
|
.map(|resource| resource["uri"].as_str().unwrap_or_default().to_owned())
|
|
.collect::<Vec<_>>();
|
|
assert!(
|
|
!uris.contains(&endpoint.text.uri),
|
|
"{revision}: a revoked Resource must disappear from list: {uris:?}"
|
|
);
|
|
assert!(
|
|
uris.contains(&endpoint.json.uri),
|
|
"{revision}: the control Resource must stay listed: {uris:?}"
|
|
);
|
|
let text = listed.to_string();
|
|
assert!(
|
|
!text.contains(&endpoint.text.name),
|
|
"{revision}: no revoked metadata may be listed: {text}"
|
|
);
|
|
}
|
|
}
|
|
|
|
for (revision, body) in denied_bodies {
|
|
assert!(
|
|
body.get("result").is_none(),
|
|
"{revision}: a revoked read must not return content: {body}"
|
|
);
|
|
assert_eq!(
|
|
body["error"]["code"].as_i64(),
|
|
Some(-32602),
|
|
"{revision}: the pinned safe NotAvailable code must be reused: {body}"
|
|
);
|
|
assert_eq!(
|
|
body["error"]["message"].as_str(),
|
|
Some("the requested resource is not available"),
|
|
"{revision}: the pinned safe NotAvailable message must be reused: {body}"
|
|
);
|
|
let text = body.to_string();
|
|
for leak in [
|
|
canary.trim(),
|
|
&endpoint.text.name,
|
|
&endpoint.text.uri,
|
|
"text/plain",
|
|
] {
|
|
assert!(
|
|
!text.contains(leak),
|
|
"{revision}: the denial must not disclose Resource data ({leak}): {body}"
|
|
);
|
|
}
|
|
}
|
|
|
|
let captured = denied_logs.output();
|
|
assert!(
|
|
captured.contains("story38-denied-corr"),
|
|
"the denied read telemetry must keep the Request ID, captured: {captured}"
|
|
);
|
|
assert!(
|
|
captured.contains("resource read outcome") && captured.contains("outcome=\"denied\""),
|
|
"the denied read must record a safe denied outcome, captured: {captured}"
|
|
);
|
|
assert!(
|
|
captured.contains("resource list page omitted revoked resources")
|
|
&& captured.contains("outcome=\"filtered\"")
|
|
&& captured.contains("revoked_omitted=1"),
|
|
"the list page must record that one revoked entry was omitted, captured: {captured}"
|
|
);
|
|
for leak in [
|
|
canary.trim(),
|
|
endpoint.text.name.as_str(),
|
|
endpoint.text.uri.as_str(),
|
|
"text/plain",
|
|
] {
|
|
assert!(
|
|
!captured.contains(leak),
|
|
"the denial telemetry must not capture Resource data ({leak}), captured: {captured}"
|
|
);
|
|
}
|
|
|
|
// Positive control: the same sink records an allowed read as a successful outcome.
|
|
let allowed_logs = CapturedLogs::default();
|
|
let allowed = {
|
|
let _capture = allowed_logs.install();
|
|
json_body(
|
|
read_resource(
|
|
&endpoint,
|
|
MODERN_REVISION,
|
|
&endpoint.json.uri,
|
|
Some("story38-allowed-corr"),
|
|
)
|
|
.await,
|
|
)
|
|
.await
|
|
};
|
|
assert!(
|
|
allowed.get("result").is_some(),
|
|
"the control Resource must stay readable: {allowed}"
|
|
);
|
|
let allowed_captured = allowed_logs.output();
|
|
assert!(
|
|
allowed_captured.contains("story38-allowed-corr")
|
|
&& allowed_captured.contains("outcome=\"ok\"")
|
|
&& allowed_captured.contains("content_bytes="),
|
|
"the same sink must capture an allowed read outcome, captured: {allowed_captured}"
|
|
);
|
|
assert!(
|
|
!allowed_captured.contains(endpoint.text.uri.as_str()),
|
|
"an allowed read telemetry must not capture the URI either, captured: {allowed_captured}"
|
|
);
|
|
}
|