Skip to content

Commit

Permalink
feat(apns): proper handling of the invalid provider token
Browse files Browse the repository at this point in the history
  • Loading branch information
geekbrother committed Nov 13, 2024
1 parent d3aac48 commit ef50878
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ pub enum Error {
#[error("Unknown CA of APNs certificate")]
ApnsCertificateUnknownCA,

#[error("Invalid APNs provider token")]
ApnsInvalidProviderToken,

#[error("client deleted due to invalid device token")]
ClientDeleted,

Expand Down
17 changes: 17 additions & 0 deletions src/handlers/push_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,23 @@ pub async fn handler_internal(
);
Err(Error::TenantSuspended)
}
Error::ApnsInvalidProviderToken => {
let reason = "APNs certificate invalid provider token";
state
.tenant_store
.suspend_tenant(&tenant_id, reason)
.await
.map_err(|e| (e, analytics.clone()))?;
increment_counter!(state.metrics, tenant_suspensions);
warn!(
%tenant_id,
client_id = %client_id,
notification_id = %notification.id,
push_type = client.push_type.as_str(),
"tenant has been suspended due to: {reason}"
);
Err(Error::TenantSuspended)
}
Error::BadFcmApiKey => {
state
.tenant_store
Expand Down
2 changes: 2 additions & 0 deletions src/providers/apns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ impl PushProvider for ApnsProvider {
"The device token is inactive for the specified topic".to_string(),
)),
ErrorReason::TopicDisallowed => Err(Error::BadApnsCredentials),
// InvalidProviderToken reflecting that APNS certificate must be reissued
ErrorReason::InvalidProviderToken => Err(Error::ApnsInvalidProviderToken),
reason => Err(Error::ApnsResponse(reason)),
},
},
Expand Down

0 comments on commit ef50878

Please sign in to comment.