From 99f4663a5d826de422ba4475f00db1416bada163 Mon Sep 17 00:00:00 2001 From: Chris Smith <1979423+chris13524@users.noreply.github.com> Date: Fri, 23 Feb 2024 10:29:37 -0500 Subject: [PATCH] fix: log whu, sub, aud, and JSON-RPC info (#382) * fix: log whu, sub, aud * chore: refactor * chore: also log JSON-RPC info * chore: regular display formatting --- .../handlers/relay_webhook/handlers/notify_delete.rs | 3 +++ .../handlers/notify_get_notifications.rs | 3 +++ .../relay_webhook/handlers/notify_subscribe.rs | 3 +++ .../handlers/relay_webhook/handlers/notify_update.rs | 3 +++ .../handlers/notify_watch_subscriptions.rs | 3 +++ .../public_http_server/handlers/relay_webhook/mod.rs | 12 +++++++++++- 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/services/public_http_server/handlers/relay_webhook/handlers/notify_delete.rs b/src/services/public_http_server/handlers/relay_webhook/handlers/notify_delete.rs index 403f77c9..4ebcd7f2 100644 --- a/src/services/public_http_server/handlers/relay_webhook/handlers/notify_delete.rs +++ b/src/services/public_http_server/handlers/relay_webhook/handlers/notify_delete.rs @@ -80,6 +80,9 @@ pub async fn handle(msg: RelayIncomingMessage, state: &AppState) -> Result<(), R let msg = decrypt_message::(envelope, &sym_key) .map_err(RelayMessageServerError::NotifyServerError)?; // TODO change to client error? + info!("msg.id: {}", msg.id); + info!("msg.jsonrpc: {}", msg.jsonrpc); // TODO verify this + info!("msg.method: {}", msg.method); // TODO verify this let request_auth = from_jwt::(&msg.params.delete_auth) .map_err(RelayMessageClientError::JwtError)?; diff --git a/src/services/public_http_server/handlers/relay_webhook/handlers/notify_get_notifications.rs b/src/services/public_http_server/handlers/relay_webhook/handlers/notify_get_notifications.rs index c1decc2d..4cb0a5fa 100644 --- a/src/services/public_http_server/handlers/relay_webhook/handlers/notify_get_notifications.rs +++ b/src/services/public_http_server/handlers/relay_webhook/handlers/notify_get_notifications.rs @@ -79,6 +79,9 @@ pub async fn handle(msg: RelayIncomingMessage, state: &AppState) -> Result<(), R let msg = decrypt_message::(envelope, &sym_key) .map_err(RelayMessageServerError::NotifyServerError)?; // TODO change to client error? + info!("msg.id: {}", msg.id); + info!("msg.jsonrpc: {}", msg.jsonrpc); // TODO verify this + info!("msg.method: {}", msg.method); // TODO verify this let request_auth = from_jwt::(&msg.params.auth) .map_err(RelayMessageClientError::JwtError)?; diff --git a/src/services/public_http_server/handlers/relay_webhook/handlers/notify_subscribe.rs b/src/services/public_http_server/handlers/relay_webhook/handlers/notify_subscribe.rs index 94a5f608..a4c8ce48 100644 --- a/src/services/public_http_server/handlers/relay_webhook/handlers/notify_subscribe.rs +++ b/src/services/public_http_server/handlers/relay_webhook/handlers/notify_subscribe.rs @@ -97,6 +97,9 @@ pub async fn handle(msg: RelayIncomingMessage, state: &AppState) -> Result<(), R let msg = decrypt_message::(envelope, &sym_key) .map_err(RelayMessageServerError::NotifyServerError)?; // TODO change to client error? + info!("msg.id: {}", msg.id); + info!("msg.jsonrpc: {}", msg.jsonrpc); // TODO verify this + info!("msg.method: {}", msg.method); // TODO verify this let request_auth = from_jwt::(&msg.params.subscription_auth) .map_err(RelayMessageClientError::JwtError)?; diff --git a/src/services/public_http_server/handlers/relay_webhook/handlers/notify_update.rs b/src/services/public_http_server/handlers/relay_webhook/handlers/notify_update.rs index a87d67c0..b36539fa 100644 --- a/src/services/public_http_server/handlers/relay_webhook/handlers/notify_update.rs +++ b/src/services/public_http_server/handlers/relay_webhook/handlers/notify_update.rs @@ -78,6 +78,9 @@ pub async fn handle(msg: RelayIncomingMessage, state: &AppState) -> Result<(), R let msg = decrypt_message::(envelope, &sym_key) .map_err(RelayMessageServerError::NotifyServerError)?; // TODO change to client error? + info!("msg.id: {}", msg.id); + info!("msg.jsonrpc: {}", msg.jsonrpc); // TODO verify this + info!("msg.method: {}", msg.method); // TODO verify this let request_auth = from_jwt::(&msg.params.update_auth) .map_err(RelayMessageClientError::JwtError)?; diff --git a/src/services/public_http_server/handlers/relay_webhook/handlers/notify_watch_subscriptions.rs b/src/services/public_http_server/handlers/relay_webhook/handlers/notify_watch_subscriptions.rs index abba0e9d..9cebbf47 100644 --- a/src/services/public_http_server/handlers/relay_webhook/handlers/notify_watch_subscriptions.rs +++ b/src/services/public_http_server/handlers/relay_webhook/handlers/notify_watch_subscriptions.rs @@ -74,6 +74,9 @@ pub async fn handle(msg: RelayIncomingMessage, state: &AppState) -> Result<(), R let msg = decrypt_message::(envelope, &response_sym_key) .map_err(RelayMessageServerError::NotifyServerError)?; // TODO change to client error? + info!("msg.id: {}", msg.id); + info!("msg.jsonrpc: {}", msg.jsonrpc); // TODO verify this + info!("msg.method: {}", msg.method); // TODO verify this let id = msg.id; diff --git a/src/services/public_http_server/handlers/relay_webhook/mod.rs b/src/services/public_http_server/handlers/relay_webhook/mod.rs index 4344584d..2c670692 100644 --- a/src/services/public_http_server/handlers/relay_webhook/mod.rs +++ b/src/services/public_http_server/handlers/relay_webhook/mod.rs @@ -120,6 +120,7 @@ pub async fn handler( } // TODO check sub + info!("sub: {}", claims.basic.sub); let event = claims.evt; @@ -132,6 +133,16 @@ pub async fn handler( .await .expect("Batch receive channel should not be closed"); + // Check these after the mailbox cleaner because these + // messages would actually be in the mailbox becuase + // the client ID (sub) matches, meaning we are the one + // that subscribed. However, aud and whu are not valid, + // that's a relay error. We should still clear the mailbox + // TODO check sub + info!("aud: {}", claims.basic.aud); + // TODO check whu + info!("whu: {}", claims.whu); + let incoming_message = RelayIncomingMessage { topic: event.topic, message: event.message, @@ -146,7 +157,6 @@ pub async fn handler( if claims.typ != WatchType::Subscriber { return Err(Error::ClientError(ClientError::WrongWatchType(claims.typ))); } - // TODO check whu if event.status != WatchStatus::Queued { return Err(Error::ClientError(ClientError::WrongWatchStatus(