Skip to content

Commit

Permalink
fix: log whu, sub, aud, and JSON-RPC info (#382)
Browse files Browse the repository at this point in the history
* fix: log whu, sub, aud

* chore: refactor

* chore: also log JSON-RPC info

* chore: regular display formatting
  • Loading branch information
chris13524 authored Feb 23, 2024
1 parent 3f95647 commit 99f4663
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ pub async fn handle(msg: RelayIncomingMessage, state: &AppState) -> Result<(), R

let msg = decrypt_message::<NotifyDelete, _>(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::<SubscriptionDeleteRequestAuth>(&msg.params.delete_auth)
.map_err(RelayMessageClientError::JwtError)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ pub async fn handle(msg: RelayIncomingMessage, state: &AppState) -> Result<(), R

let msg = decrypt_message::<AuthMessage, _>(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::<SubscriptionGetNotificationsRequestAuth>(&msg.params.auth)
.map_err(RelayMessageClientError::JwtError)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ pub async fn handle(msg: RelayIncomingMessage, state: &AppState) -> Result<(), R

let msg = decrypt_message::<NotifySubscribe, _>(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::<SubscriptionRequestAuth>(&msg.params.subscription_auth)
.map_err(RelayMessageClientError::JwtError)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ pub async fn handle(msg: RelayIncomingMessage, state: &AppState) -> Result<(), R

let msg = decrypt_message::<NotifyUpdate, _>(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::<SubscriptionUpdateRequestAuth>(&msg.params.update_auth)
.map_err(RelayMessageClientError::JwtError)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ pub async fn handle(msg: RelayIncomingMessage, state: &AppState) -> Result<(), R

let msg = decrypt_message::<NotifyWatchSubscriptions, _>(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;

Expand Down
12 changes: 11 additions & 1 deletion src/services/public_http_server/handlers/relay_webhook/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ pub async fn handler(
}

// TODO check sub
info!("sub: {}", claims.basic.sub);

let event = claims.evt;

Expand All @@ -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,
Expand All @@ -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(
Expand Down

0 comments on commit 99f4663

Please sign in to comment.