mirror of
https://github.com/block/buzz.git
synced 2026-11-24 18:21:59 +00:00
## Summary
Follow-up to #9653. Its new test
`cli_exits_nonzero_when_the_relay_refuses_a_raw_publish` went through
`run_from_args`, which resolves credentials from the caller's
environment. With `BUZZ_AUTH_TAG` set (as it is for agents run by the
ACP harness), the test client's key doesn't match the auth tag and the
test exits 3 instead of 2.
The check moves to an integration test,
[`tests/raw_publish_exit.rs`](c77555c348/crates/buzz-cli/tests/raw_publish_exit.rs),
that runs the built `buzz` binary against a fake relay answering
`accepted:false`, with every `BUZZ_*` variable removed from the child
only. It asserts exit 2, empty stdout, a `relay_error` and one
submission, so it covers the binary's real route and exit mapping.
## Regressions
None: test-only change.
### Validation
Ran the `buzz-cli` suite with a junk `BUZZ_AUTH_TAG` and
`BUZZ_FEDERATED_IDENTITY_TOKEN` set. Replacing the `Cmd::Raw` dispatch
with `Ok(())` makes the new test fail.
---------
Signed-off-by: Tom Brow <tomb@block.xyz>
86 lines
2.8 KiB
Rust
86 lines
2.8 KiB
Rust
//! Runs the real `buzz` binary against a local fake relay to check the
|
|
//! process exit code of `raw publish` when the relay refuses the event.
|
|
//!
|
|
//! The child gets none of the caller's `BUZZ_*` variables, so an agent's
|
|
//! inherited auth tag or federated identity cannot change the outcome.
|
|
|
|
use std::process::Command;
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
use std::sync::Arc;
|
|
|
|
use axum::http::StatusCode;
|
|
use axum::routing::post;
|
|
use axum::Router;
|
|
use tokio::net::TcpListener;
|
|
|
|
/// A relay bridge whose `/events` answers HTTP 200 with `accepted:false`,
|
|
/// as the relay does for a duplicate reaction. Returns its URL and a count
|
|
/// of submitted events.
|
|
async fn refusing_relay() -> (String, Arc<AtomicUsize>) {
|
|
let submitted = Arc::new(AtomicUsize::new(0));
|
|
let counter = submitted.clone();
|
|
let app = Router::new().route(
|
|
"/events",
|
|
post(move |body: String| {
|
|
let counter = counter.clone();
|
|
async move {
|
|
counter.fetch_add(1, Ordering::SeqCst);
|
|
let event: serde_json::Value = serde_json::from_str(&body).unwrap();
|
|
let id = event["id"].as_str().unwrap().to_string();
|
|
(
|
|
StatusCode::OK,
|
|
[("content-type", "application/json")],
|
|
format!(
|
|
r#"{{"event_id":"{id}","accepted":false,"message":"duplicate: reaction already exists"}}"#
|
|
),
|
|
)
|
|
}
|
|
}),
|
|
);
|
|
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
|
let addr = listener.local_addr().unwrap();
|
|
tokio::spawn(async move { axum::serve(listener, app).await.unwrap() });
|
|
(format!("http://{addr}"), submitted)
|
|
}
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
async fn raw_publish_exits_2_when_the_relay_refuses() {
|
|
let (url, submitted) = refusing_relay().await;
|
|
let key = nostr::Keys::generate().secret_key().to_secret_hex();
|
|
|
|
let mut cmd = Command::new(env!("CARGO_BIN_EXE_buzz"));
|
|
for (name, _) in std::env::vars_os() {
|
|
if name.to_string_lossy().starts_with("BUZZ_") {
|
|
cmd.env_remove(name);
|
|
}
|
|
}
|
|
cmd.args([
|
|
"--relay",
|
|
url.as_str(),
|
|
"--private-key",
|
|
key.as_str(),
|
|
"raw",
|
|
"publish",
|
|
"--kind",
|
|
"7",
|
|
"--content",
|
|
"+",
|
|
]);
|
|
let output = tokio::task::spawn_blocking(move || cmd.output().unwrap())
|
|
.await
|
|
.unwrap();
|
|
|
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
assert_eq!(
|
|
output.status.code(),
|
|
Some(2),
|
|
"a refused publish is a relay error; stderr: {stderr}"
|
|
);
|
|
assert!(
|
|
output.stdout.is_empty(),
|
|
"a refusal prints nothing to stdout"
|
|
);
|
|
assert!(stderr.contains("relay_error"), "stderr: {stderr}");
|
|
assert_eq!(submitted.load(Ordering::SeqCst), 1);
|
|
}
|