The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(http): add test module for dictation websocket handler
Steven Enamakelb180f0ddb0df
diff --git a/crates/openhuman-rpc/src/server/http/dictation.rs b/crates/openhuman-rpc/src/server/http/dictation.rsindex c28cf2435f..ecff7e9acc 100644--- a/crates/openhuman-rpc/src/server/http/dictation.rs+++ b/crates/openhuman-rpc/src/server/http/dictation.rs@@ -97,3 +97,7 @@ pub(super) async fn dictation_ws_handler(openhuman_core::voice::streaming::handle_dictation_ws(socket, config).await;})}++#[cfg(test)]+#[path = "dictation_tests.rs"]+mod tests;diff --git a/crates/openhuman-rpc/src/server/http/dictation_tests.rs b/crates/openhuman-rpc/src/server/http/dictation_tests.rsnew file mode 100644index 0000000000..7fab78de03--- /dev/null+++ b/crates/openhuman-rpc/src/server/http/dictation_tests.rs@@ -0,0 +1,50 @@+use axum::body::{to_bytes, Body};+use axum::http::{header, Request, StatusCode};+use axum::routing::get;+use axum::Router;+use tower::ServiceExt;++use super::dictation_ws_handler;++fn upgrade_request(uri: &str, origin: Option<&str>) -> Request<Body> {+ let mut builder = Request::builder()+ .uri(uri)+ .header(header::CONNECTION, "Upgrade")+ .header(header::UPGRADE, "websocket")+ .header("sec-websocket-version", "13")+ .header("sec-websocket-key", "dGhlIHNhbXBsZSBub25jZQ==");+ if let Some(origin) = origin {+ builder = builder.header(header::ORIGIN, origin);+ }+ builder.body(Body::empty()).unwrap()+}++async fn dispatch(request: Request<Body>) -> axum::response::Response {+ Router::new()+ .route("/ws/dictation", get(dictation_ws_handler))+ .oneshot(request)+ .await+ .unwrap()+}++#[tokio::test]+async fn dictation_rejects_foreign_browser_origins_before_authentication() {+ let response = dispatch(upgrade_request(+ "/ws/dictation?token=not-a-bearer",+ Some("https://attacker.example"),+ ))+ .await;+ assert_eq!(response.status(), StatusCode::FORBIDDEN);+ let body = to_bytes(response.into_body(), usize::MAX).await.unwrap();+ assert!(String::from_utf8_lossy(&body).contains("Origin not allowed"));+}++#[tokio::test]+async fn dictation_rejects_missing_and_invalid_credentials() {+ for uri in ["/ws/dictation", "/ws/dictation?token=not-a-bearer"] {+ let response = dispatch(upgrade_request(uri, None)).await;+ assert_eq!(response.status(), StatusCode::UNAUTHORIZED);+ let body = to_bytes(response.into_body(), usize::MAX).await.unwrap();+ assert!(String::from_utf8_lossy(&body).contains("Missing or invalid token"));+ }+}