Skip to content

Commit c05cef6

Browse files
TheSentinel454Elrondclaude
committed
test(search): sign the profile-search request in the timeout test
`/profiles/search` admits only a NIP-98-signed member POST, so the deadline-contract test now signs it as the fixture's reader. Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Luke Tornquist <[email protected]>
1 parent 519975d commit c05cef6

1 file changed

Lines changed: 34 additions & 22 deletions

File tree

‎crates/buzz-relay/src/api/bridge.rs‎

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9174,24 +9174,43 @@ pub(crate) mod postgres_tests {
91749174
}
91759175

91769176
async fn http(&self, uri: &str, filter: &serde_json::Value) -> (StatusCode, Value) {
9177-
self.post(uri, &serde_json::json!([filter])).await
9177+
let body = serde_json::to_vec(&[filter]).expect("json");
9178+
self.post(uri, body, axum::http::HeaderMap::new()).await
91789179
}
91799180

9180-
async fn post(&self, uri: &str, body: &serde_json::Value) -> (StatusCode, Value) {
9181+
/// `POST /profiles/search` for `needle`, NIP-98 signed by the reader.
9182+
async fn profile_search(&self) -> (StatusCode, Value) {
9183+
let path = super::super::profiles::SEARCH_PATH;
9184+
let body = serde_json::to_vec(&serde_json::json!({"query": "needle"})).expect("json");
9185+
let url = super::nip98_expected_url(
9186+
&self.state.config.relay_url,
9187+
&TenantContext::resolved(self.community, self.host.clone()),
9188+
path,
9189+
);
9190+
let auth = make_nip98_headers(&self.reader, &url, "POST", &body);
9191+
self.post(path, body, auth).await
9192+
}
9193+
9194+
async fn post(
9195+
&self,
9196+
uri: &str,
9197+
body: Vec<u8>,
9198+
headers: axum::http::HeaderMap,
9199+
) -> (StatusCode, Value) {
91819200
use axum::body::Body;
91829201
use axum::http::{header, Request};
91839202
use tower::ServiceExt;
9203+
let mut request = Request::builder()
9204+
.method("POST")
9205+
.uri(uri)
9206+
.header(header::HOST, &self.host)
9207+
.header("x-pubkey", self.reader.public_key().to_hex())
9208+
.header("content-type", "application/json");
9209+
if let Some(map) = request.headers_mut() {
9210+
map.extend(headers);
9211+
}
91849212
let resp = crate::router::build_router(self.state.clone())
9185-
.oneshot(
9186-
Request::builder()
9187-
.method("POST")
9188-
.uri(uri)
9189-
.header(header::HOST, &self.host)
9190-
.header("x-pubkey", self.reader.public_key().to_hex())
9191-
.header("content-type", "application/json")
9192-
.body(Body::from(serde_json::to_vec(body).expect("json")))
9193-
.expect("request"),
9194-
)
9213+
.oneshot(request.body(Body::from(body)).expect("request"))
91959214
.await
91969215
.expect("oneshot");
91979216
let status = resp.status();
@@ -9391,7 +9410,6 @@ pub(crate) mod postgres_tests {
93919410
async fn search_statement_timeout_maps_to_timeout_contract() {
93929411
use crate::handlers::req::{QUERY_TIMED_OUT_CLOSED, SEARCH_FAILED_CLOSED};
93939412
let fx = cancel_fixture().await;
9394-
let profiles = serde_json::json!({"query": "needle"});
93959413
let closed = |reason: &str| format!(r#"["CLOSED","s","{reason}"]"#);
93969414

93979415
// Healthy controls.
@@ -9401,9 +9419,7 @@ pub(crate) mod postgres_tests {
94019419
body.to_string().contains("root needle"),
94029420
"search hit: {body}"
94039421
);
9404-
let (status, body) = fx
9405-
.post(super::super::profiles::SEARCH_PATH, &profiles)
9406-
.await;
9422+
let (status, body) = fx.profile_search().await;
94079423
assert_eq!(status, StatusCode::OK, "healthy profile search: {body}");
94089424
let frame = fx.ws_search().await;
94099425
assert!(frame.contains("root needle"), "healthy WS search: {frame}");
@@ -9421,9 +9437,7 @@ pub(crate) mod postgres_tests {
94219437
);
94229438
let (status, body) = fx.http("/query", &fx.search_filter()).await;
94239439
assert_eq!((status, body["error"].as_str()), timed_out, "HTTP search");
9424-
let (status, body) = fx
9425-
.post(super::super::profiles::SEARCH_PATH, &profiles)
9426-
.await;
9440+
let (status, body) = fx.profile_search().await;
94279441
assert_eq!(
94289442
(status, body["error"].as_str()),
94299443
timed_out,
@@ -9453,9 +9467,7 @@ pub(crate) mod postgres_tests {
94539467
failed,
94549468
"HTTP search ordinary error"
94559469
);
9456-
let (status, body) = fx
9457-
.post(super::super::profiles::SEARCH_PATH, &profiles)
9458-
.await;
9470+
let (status, body) = fx.profile_search().await;
94599471
assert_eq!(
94609472
(status, body["error"].as_str()),
94619473
failed,

0 commit comments

Comments
 (0)