Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(node): assert denial bodies leak no replica or repo data
CodeRabbit nitpick: the new replica-mutation denial tests only checked
the 404 status. The path instructions for this file require non-leaking
body assertions on denied responses, matching the sibling
list_replicas_is_read_visibility_gated test. Assert the denied PUT and
DELETE bodies contain neither the submitted replica URL nor the repo id,
in both the handler-level test and the real-signature e2e.
  • Loading branch information
beardthelion committed Sep 11, 2026
commit ec3af1c30ce3168334a4fe0872c245fd94207f31
40 changes: 39 additions & 1 deletion crates/gitlawb-node/src/test_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,12 @@ mod tests {
)
.with_state(state.clone())
};
let body = || Body::from(r#"{"url":"https://replica.example.com/me"}"#.to_string());
let replica_url = "https://replica.example.com/me";
let body = || Body::from(format!(r#"{{"url":"{replica_url}"}}"#));
let leaks = |bytes: &[u8]| {
let text = String::from_utf8_lossy(bytes);
text.contains(replica_url) || text.contains(&priv_repo.id)
};

// Private repo, non-reader stranger: register → 404, nothing written.
let resp = router()
Expand All @@ -1492,6 +1497,13 @@ mod tests {
StatusCode::NOT_FOUND,
"a non-reader must not register on a private repo"
);
let bytes = axum::body::to_bytes(resp.into_body(), usize::MAX)
.await
.unwrap();
assert!(
!leaks(&bytes),
"a denied register body must not leak the replica url or repo data"
);
assert!(
state
.db
Expand All @@ -1517,6 +1529,13 @@ mod tests {
StatusCode::NOT_FOUND,
"a non-reader must not unregister on a private repo"
);
let bytes = axum::body::to_bytes(resp.into_body(), usize::MAX)
.await
.unwrap();
assert!(
!leaks(&bytes),
"a denied unregister body must not leak the replica url or repo data"
);

// Private repo, listed reader: register → 201, unregister → 200.
let resp = router()
Expand Down Expand Up @@ -1618,7 +1637,12 @@ mod tests {

let router = app(pool).await;
let path = format!("/api/v1/repos/{short}/sig-repl-priv/replicas");
let replica_url = "https://replica.example.com/e2e";
let reg_body: &[u8] = br#"{"url":"https://replica.example.com/e2e"}"#;
let leaks = |bytes: &[u8]| {
let text = String::from_utf8_lossy(bytes);
text.contains(replica_url) || text.contains(&repo.id)
};
let signed_req = |kp: &Keypair, method: &str, body: &'static [u8]| {
let signed = sign_request(kp, method, &path, body);
Request::builder()
Expand All @@ -1643,6 +1667,13 @@ mod tests {
StatusCode::NOT_FOUND,
"a verified non-reader must not register on a private repo"
);
let bytes = axum::body::to_bytes(resp.into_body(), usize::MAX)
.await
.unwrap();
assert!(
!leaks(&bytes),
"a denied register body must not leak the replica url or repo data"
);
assert!(
state.db.list_replicas(&repo.id).await.unwrap().is_empty(),
"a denied register must not create a replica row"
Expand All @@ -1659,6 +1690,13 @@ mod tests {
StatusCode::NOT_FOUND,
"a verified non-reader must not unregister on a private repo"
);
let bytes = axum::body::to_bytes(resp.into_body(), usize::MAX)
.await
.unwrap();
assert!(
!leaks(&bytes),
"a denied unregister body must not leak the replica url or repo data"
);

// Listed reader: PUT → 201, DELETE → 200.
let resp = router
Expand Down
Loading