From d700411d471f82a629d077c0e6a4cefde10a51da Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 9 Apr 2024 20:57:49 -0400 Subject: [PATCH 01/24] feat: FCM v1 --- Cargo.lock | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++---- Cargo.toml | 1 + 2 files changed, 78 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8be4fa04..1d3f7cdb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,7 +8,7 @@ version = "0.7.0" source = "git+https://github.com/WalletConnect/a2?rev=d0236c3#d0236c317751f45305d96433e816e6d9272a32b1" dependencies = [ "base64 0.20.0", - "erased-serde", + "erased-serde 0.3.31", "http", "hyper", "hyper-alpn", @@ -1208,7 +1208,16 @@ version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" dependencies = [ - "dirs-sys", + "dirs-sys 0.3.7", +] + +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys 0.4.1", ] [[package]] @@ -1222,6 +1231,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys", +] + [[package]] name = "dotenv" version = "0.15.0" @@ -1255,7 +1276,8 @@ dependencies = [ "dotenv", "ed25519-dalek 2.0.0", "envy", - "fcm", + "fcm 0.9.2", + "fcm 1.0.0", "futures-util", "hex", "hyper", @@ -1378,6 +1400,15 @@ dependencies = [ "serde", ] +[[package]] +name = "erased-serde" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4adbf0983fe06bd3a5c19c8477a637c2389feb0994eca7a59e3b961054aa7c0a" +dependencies = [ + "serde", +] + [[package]] name = "errno" version = "0.3.3" @@ -1427,7 +1458,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d8d0da8a6bd63bdec888b6d7a87c5698230005c1800823d28ddd5adb6f2550f" dependencies = [ "chrono", - "erased-serde", + "erased-serde 0.3.31", + "log", + "reqwest", + "serde", + "serde_json", +] + +[[package]] +name = "fcm" +version = "1.0.0" +source = "git+https://github.com/rj76/fcm-rust.git#4f9dedb6423c84f62f5f759593a9ebf774097527" +dependencies = [ + "chrono", + "dotenv", + "erased-serde 0.4.1", + "gauth", "log", "reqwest", "serde", @@ -1623,6 +1669,25 @@ dependencies = [ "slab", ] +[[package]] +name = "gauth" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b32329a7788126e9388c64f261174d2e2161d0c7cd28b55935ccc0da96920d8" +dependencies = [ + "anyhow", + "base64 0.21.4", + "chrono", + "dirs 5.0.1", + "reqwest", + "ring", + "serde", + "serde_derive", + "serde_json", + "thiserror", + "url", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -2572,6 +2637,12 @@ dependencies = [ "tokio-stream", ] +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "ordered-float" version = "2.10.0" @@ -3369,6 +3440,7 @@ version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" dependencies = [ + "indexmap 2.0.1", "itoa", "ryu", "serde", @@ -3602,7 +3674,7 @@ dependencies = [ "chrono", "crc", "crossbeam-queue", - "dirs", + "dirs 4.0.0", "dotenvy", "either", "event-listener", diff --git a/Cargo.toml b/Cargo.toml index eac5d024..47b7563f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,6 +61,7 @@ atty = "0.2" # Push a2 = { git = "https://github.com/WalletConnect/a2", rev = "d0236c3", features = ["tracing", "openssl"] } fcm = "0.9" +fcm_v1 = { git = "https://github.com/rj76/fcm-rust.git", package = "fcm" } # Signature validation ed25519-dalek = "2.0.0-rc.2" From 0caa7e28ea0f2a19cff9167719cabaaddda645a6 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 15 Apr 2024 21:39:51 -0400 Subject: [PATCH 02/24] chore: lots of boilerplate --- .env.example | 1 + .env.single-tenant-example | 3 +- .github/workflows/cd.yml | 4 +- .github/workflows/ci.yml | 1 + .github/workflows/ci_terraform.yml | 2 +- Cargo.toml | 2 +- migrations/README.md | 2 +- src/config.rs | 6 + src/error.rs | 3 + src/handlers/mod.rs | 2 + src/handlers/push_message.rs | 1 + src/handlers/update_fcm_v1.rs | 115 +++++++++++++ src/metrics/mod.rs | 14 ++ src/providers/fcm_v1.rs | 217 ++++++++++++++++++++++++ src/providers/mod.rs | 11 +- src/stores/tenant.rs | 53 +++++- tenant_migrations/1713226293_fcm-v1.sql | 2 + tenant_migrations/README.md | 2 +- terraform/README.md | 1 + terraform/provider.tf | 4 +- terraform/variables.tf | 4 + tests/context/mod.rs | 2 + tests/functional/multitenant/fcm_v1.rs | 95 +++++++++++ tests/functional/stores/tenant.rs | 27 ++- 24 files changed, 561 insertions(+), 13 deletions(-) create mode 100644 src/handlers/update_fcm_v1.rs create mode 100644 src/providers/fcm_v1.rs create mode 100644 tenant_migrations/1713226293_fcm-v1.sql create mode 100644 tests/functional/multitenant/fcm_v1.rs diff --git a/.env.example b/.env.example index d856a884..f0c4f0e8 100644 --- a/.env.example +++ b/.env.example @@ -35,6 +35,7 @@ TELEMETRY_PROMETHEUS_PORT=3001 # FCM FCM_API_KEY= +FCM_V1_CREDENTIALS= # APNS APNS_CERTIFICATE= # base64 encoded .p12 APNS Certificate diff --git a/.env.single-tenant-example b/.env.single-tenant-example index 3f8fb3a1..9d9a936f 100644 --- a/.env.single-tenant-example +++ b/.env.single-tenant-example @@ -18,8 +18,9 @@ TELEMETRY_PROMETHEUS_PORT=3001 # FCM FCM_API_KEY= # Firebase Cloud Messaging Server Key +FCM_V1_CREDENTIALS= # Firebase Cloud Messaging Service Account Credentials # APNS APNS_CERTIFICATE= # base64 encoded .p12 APNS Certificate APNS_CERTIFICATE_PASSWORD= # Password for provided certificate -APNS_TOPIC= # bundle ID/app ID \ No newline at end of file +APNS_TOPIC= # bundle ID/app ID diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 5d3df508..fb6a314e 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -81,7 +81,7 @@ jobs: id: tf-apply uses: WalletConnect/actions/terraform/apply/@1.0.3 env: - GRAFANA_AUTH: ${{ steps.grafana-get-key.outputs.key }} + TF_VAR_grafana_auth: ${{ steps.grafana-get-key.outputs.key }} TF_VAR_grafana_endpoint: ${{ steps.grafana-get-details.outputs.endpoint }} TF_VAR_cloud_api_key: ${{ secrets.CLOUD_API_KEY }} TF_VAR_jwt_secret: ${{ secrets.JWT_SECRET }} @@ -152,7 +152,7 @@ jobs: id: tf-apply uses: WalletConnect/actions/terraform/apply/@1.0.3 env: - GRAFANA_AUTH: ${{ steps.grafana-get-key.outputs.key }} + TF_VAR_grafana_auth: ${{ steps.grafana-get-key.outputs.key }} TF_VAR_grafana_endpoint: ${{ steps.grafana-get-details.outputs.endpoint }} TF_VAR_cloud_api_key: ${{ secrets.CLOUD_API_KEY }} TF_VAR_jwt_secret: ${{ secrets.JWT_SECRET }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 82c658b3..9cecd854 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -170,6 +170,7 @@ jobs: args: ${{ matrix.cargo.args }} env: ECHO_TEST_FCM_KEY: ${{ secrets.ECHO_TEST_FCM_KEY }} + ECHO_TEST_FCM_V1_CREDENTIALS: ${{ secrets.ECHO_TEST_FCM_V1_CREDENTIALS }} ECHO_TEST_APNS_P8_KEY_ID: ${{ secrets.ECHO_TEST_APNS_P8_KEY_ID }} ECHO_TEST_APNS_P8_TEAM_ID: ${{ secrets.ECHO_TEST_APNS_P8_TEAM_ID }} ECHO_TEST_APNS_P8_PEM: ${{ secrets.ECHO_TEST_APNS_P8_PEM }} diff --git a/.github/workflows/ci_terraform.yml b/.github/workflows/ci_terraform.yml index 32259b95..25e90a60 100644 --- a/.github/workflows/ci_terraform.yml +++ b/.github/workflows/ci_terraform.yml @@ -122,7 +122,7 @@ jobs: id: tf-plan-staging uses: WalletConnect/actions/terraform/plan/@1.0.3 env: - GRAFANA_AUTH: ${{ steps.grafana-get-key.outputs.key }} + TF_VAR_grafana_auth: ${{ steps.grafana-get-key.outputs.key }} TF_VAR_grafana_endpoint: ${{ steps.grafana-get-details.outputs.endpoint }} TF_VAR_cloud_api_key: ${{ secrets.CLOUD_API_KEY }} TF_VAR_jwt_secret: ${{ secrets.JWT_SECRET }} diff --git a/Cargo.toml b/Cargo.toml index 47b7563f..64b695a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ build = "build.rs" resolver = "2" [features] -full= ["functional_tests", "multitenant", "analytics", "geoblock", "cloud"] +full = ["functional_tests", "multitenant", "analytics", "geoblock", "cloud"] # Used to enable functional tests functional_tests = [] # Multi-tenancy mode diff --git a/migrations/README.md b/migrations/README.md index fc7e1fda..4936e71a 100644 --- a/migrations/README.md +++ b/migrations/README.md @@ -8,4 +8,4 @@ This folder contains migrations for Echo Server and they are automatically calle ``` ## Contributors -To create a new migration run `./new.sh [description]` to make a new migration \ No newline at end of file +To create a new migration run `./new.sh [description]` to make a new migration diff --git a/src/config.rs b/src/config.rs index dc5cddf9..46dd7db5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -61,6 +61,8 @@ pub struct Config { // FCM #[cfg(not(feature = "multitenant"))] pub fcm_api_key: Option, + #[cfg(not(feature = "multitenant"))] + pub fcm_v1_credentials: Option, // Multi-tenancy pub tenant_database_url: String, @@ -132,6 +134,10 @@ impl Config { supported.push(ProviderKind::Fcm); } + if self.fcm_v1_credentials.is_some() { + supported.push(ProviderKind::FcmV1); + } + // Only available in debug/testing #[cfg(any(debug_assertions, test))] supported.push(ProviderKind::Noop); diff --git a/src/error.rs b/src/error.rs index de55b4a7..db9d101c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -37,6 +37,9 @@ pub enum Error { #[error(transparent)] Fcm(#[from] fcm::FcmError), + #[error(transparent)] + FcmV1(#[from] fcm_v1::Error), + #[error("FCM Responded with an error")] FcmResponse(fcm::ErrorReason), diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 5c8c253d..87118057 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -46,6 +46,8 @@ pub mod health; pub mod update_apns; #[cfg(feature = "multitenant")] pub mod update_fcm; +#[cfg(feature = "multitenant")] +pub mod update_fcm_v1; pub const DECENTRALIZED_IDENTIFIER_PREFIX: &str = "did:key:"; diff --git a/src/handlers/push_message.rs b/src/handlers/push_message.rs index 86d092b1..f009d7b3 100644 --- a/src/handlers/push_message.rs +++ b/src/handlers/push_message.rs @@ -463,6 +463,7 @@ pub async fn handler_internal( // Provider specific metrics match provider { Provider::Fcm(_) => increment_counter!(state.metrics, sent_fcm_notifications), + Provider::FcmV1(_) => increment_counter!(state.metrics, sent_fcm_v1_notifications), Provider::Apns(_) => increment_counter!(state.metrics, sent_apns_notifications), #[cfg(any(debug_assertions, test))] Provider::Noop(_) => {} diff --git a/src/handlers/update_fcm_v1.rs b/src/handlers/update_fcm_v1.rs new file mode 100644 index 00000000..6fb79b14 --- /dev/null +++ b/src/handlers/update_fcm_v1.rs @@ -0,0 +1,115 @@ +use { + crate::{ + error::{Error, Error::InvalidMultipartBody}, + handlers::validate_tenant_request, + increment_counter, + state::AppState, + stores::tenant::TenantFcmV1UpdateParams, + }, + axum::{ + extract::{Multipart, Path, State}, + http::HeaderMap, + Json, + }, + serde::Serialize, + std::sync::Arc, + tracing::{error, instrument}, +}; + +pub struct FcmV1UpdateBody { + credentials: String, + /// Used to ensure that at least one value has changed + value_changed_: bool, +} + +#[derive(Serialize)] +pub struct UpdateTenantFcmV1Response { + success: bool, +} + +#[instrument(skip_all, name = "update_fcm_v1_handler")] +pub async fn handler( + State(state): State>, + Path(id): Path, + headers: HeaderMap, + mut form_body: Multipart, +) -> Result, Error> { + // -- check if tenant is real + let _existing_tenant = state.tenant_store.get_tenant(&id).await?; + + // JWT token verification + #[cfg(feature = "cloud")] + let jwt_verification_result = validate_tenant_request( + &state.registry_client, + &state.gotrue_client, + &headers, + id.clone(), + None, + ) + .await; + + #[cfg(not(feature = "cloud"))] + let jwt_verification_result = validate_tenant_request(&state.gotrue_client, &headers); + + if let Err(e) = jwt_verification_result { + error!( + tenant_id = %id, + err = ?e, + "JWT verification failed" + ); + return Err(e); + } + + // ---- retrieve body from form + let mut body = FcmV1UpdateBody { + credentials: Default::default(), + value_changed_: false, + }; + while let Some(field) = form_body.next_field().await? { + let name = field.name().unwrap_or("unknown").to_string(); + let data = field.text().await?; + + if name.to_lowercase().as_str() == "credentials" { + body.credentials = data; + body.value_changed_ = true; + }; + } + if !body.value_changed_ { + return Err(InvalidMultipartBody); + } + + // ---- checks + // TODO + // let fcm_credentials = body.credentials.clone(); + // let mut test_message_builder = fcm_v1::Message::new(&fcm_credentials, "wc-notification-test"); + // test_message_builder.dry_run(true); + // let test_message = test_message_builder.finalize(); + // let test_notification = fcm::Client::new().send(test_message).await; + // match test_notification { + // Err(e) => match e { + // FcmError::Unauthorized => Err(BadFcmApiKey), + // _ => Ok(()), + // }, + // Ok(_) => Ok(()), + // }?; + + // ---- handler + let update_body = TenantFcmV1UpdateParams { + fcm_v1_credentials: body.credentials, + }; + + let new_tenant = state + .tenant_store + .update_tenant_fcm_v1(&id, update_body) + .await?; + + if new_tenant.suspended { + // If suspended, it can be restored now because valid credentials have been + // provided + state.tenant_store.unsuspend_tenant(&new_tenant.id).await?; + } + + increment_counter!(state.metrics, tenant_fcm_v1_updates); + + Ok(Json(UpdateTenantFcmV1Response { success: true })) +} diff --git a/src/metrics/mod.rs b/src/metrics/mod.rs index 1703fd26..1deda837 100644 --- a/src/metrics/mod.rs +++ b/src/metrics/mod.rs @@ -19,6 +19,7 @@ pub struct Metrics { pub received_notifications: Counter, pub sent_fcm_notifications: Counter, + pub sent_fcm_v1_notifications: Counter, pub sent_apns_notifications: Counter, pub registered_clients: UpDownCounter, @@ -26,6 +27,7 @@ pub struct Metrics { pub tenant_apns_updates: Counter, pub tenant_fcm_updates: Counter, + pub tenant_fcm_v1_updates: Counter, pub tenant_suspensions: Counter, pub client_suspensions: Counter, @@ -71,6 +73,11 @@ impl Metrics { .with_description("The number of notifications sent to FCM") .init(); + let sent_fcm_v1_notification_counter = meter + .u64_counter("sent_fcm_v1_notifications") + .with_description("The number of notifications sent to FCM") + .init(); + let sent_apns_notification_counter = meter .u64_counter("sent_apns_notifications") .with_description("The number of notifications sent to APNS") @@ -86,6 +93,11 @@ impl Metrics { .with_description("The number of times tenants have updated their FCM") .init(); + let tenant_fcm_v1_updates_counter = meter + .u64_counter("tenant_fcm_v1_updates") + .with_description("The number of times tenants have updated their FCM") + .init(); + let tenant_suspensions_counter = meter .u64_counter("tenant_suspensions") .with_description("The number of tenants that have been suspended") @@ -101,10 +113,12 @@ impl Metrics { registered_clients: clients_counter, received_notifications: received_notification_counter, sent_fcm_notifications: sent_fcm_notification_counter, + sent_fcm_v1_notifications: sent_fcm_v1_notification_counter, sent_apns_notifications: sent_apns_notification_counter, registered_tenants: tenants_counter, tenant_apns_updates: tenant_apns_updates_counter, tenant_fcm_updates: tenant_fcm_updates_counter, + tenant_fcm_v1_updates: tenant_fcm_v1_updates_counter, tenant_suspensions: tenant_suspensions_counter, client_suspensions: client_suspensions_counter, }) diff --git a/src/providers/fcm_v1.rs b/src/providers/fcm_v1.rs new file mode 100644 index 00000000..6238b9aa --- /dev/null +++ b/src/providers/fcm_v1.rs @@ -0,0 +1,217 @@ +use { + super::{LegacyPushMessage, PushMessage}, + crate::{blob::DecryptedPayloadBlob, error::Error, providers::PushProvider}, + async_trait::async_trait, + fcm_v1::{ + AndroidConfig, AndroidMessagePriority, AndroidNotification, Client, Error as FcmError, + Message, Notification, Target, WebpushConfig, + }, + std::fmt::{Debug, Formatter}, + tracing::{debug, instrument}, +}; + +pub struct FcmV1Provider { + credentials: String, + client: Client, +} + +impl FcmV1Provider { + pub fn new(credentials: String) -> Self { + Self { + credentials, + client: Client::new(), + } + } +} + +#[async_trait] +impl PushProvider for FcmV1Provider { + #[instrument(name = "send_fcm_v1_notification")] + async fn send_notification( + &mut self, + token: String, + body: PushMessage, + ) -> crate::error::Result<()> { + let result = match body { + PushMessage::RawPushMessage(message) => { + // Sending `always_raw` encrypted message + debug!("Sending raw encrypted message"); + let message = Message { + data: Some(serde_json::to_value(message)?), + notification: None, + target: Target::Token(token), + android: Some(AndroidConfig { + priority: Some(AndroidMessagePriority::High), + collapse_key: None, + ttl: None, + restricted_package_name: None, + data: None, + notification: None, + fcm_options: None, + direct_boot_ok: None, + }), + // TODO + webpush: Some(WebpushConfig { + headers: None, + data: None, + notification: None, + fcm_options: None, + }), + // TODO do we need to set this for iOS React Native? We are missing content_available equivalent + apns: None, + fcm_options: None, + }; + self.client.send(message).await + } + PushMessage::LegacyPushMessage(LegacyPushMessage { id: _, payload }) => { + if payload.is_encrypted() { + debug!("Sending legacy `is_encrypted` message"); + let message = Message { + data: Some(serde_json::to_value(payload)?), + notification: None, + target: Target::Token(token), + android: Some(AndroidConfig { + priority: Some(AndroidMessagePriority::High), + collapse_key: None, + ttl: None, + restricted_package_name: None, + data: None, + notification: None, + fcm_options: None, + direct_boot_ok: None, + }), + // TODO + webpush: Some(WebpushConfig { + headers: None, + data: None, + notification: None, + fcm_options: None, + }), + // TODO do we need to set this for iOS React Native? We are missing content_available equivalent + apns: None, + fcm_options: None, + }; + self.client.send(message).await + } else { + debug!("Sending plain message"); + let blob = DecryptedPayloadBlob::from_base64_encoded(&payload.blob)?; + + let message = Message { + data: Some(serde_json::to_value(payload.to_owned())?), + notification: Some(Notification { + title: Some(blob.title.clone()), + body: Some(blob.body.clone()), + image: None, + }), + target: Target::Token(token), + android: Some(AndroidConfig { + priority: Some(AndroidMessagePriority::High), + collapse_key: None, + ttl: None, + restricted_package_name: None, + data: None, + notification: Some(AndroidNotification { + notification_priority: None, + // TODO do we need to override this of already set in `notification` above? + title: Some(blob.title), + body: Some(blob.body), + icon: None, + color: None, + sound: None, + tag: None, + click_action: None, + body_loc_key: None, + body_loc_args: None, + title_loc_key: None, + title_loc_args: None, + channel_id: None, + ticker: None, + sticky: None, + event_time: None, + local_only: None, + default_sound: None, + default_vibrate_timings: None, + default_light_settings: None, + vibrate_timings: None, + visibility: None, + notification_count: None, + light_settings: None, + image: None, + }), + fcm_options: None, + direct_boot_ok: None, + }), + // TODO + webpush: Some(WebpushConfig { + headers: None, + data: None, + notification: None, + fcm_options: None, + }), + // TODO do we need to set this for iOS React Native? We are missing content_available equivalent + apns: None, + fcm_options: None, + }; + self.client.send(message).await + } + } + }; + + match result { + Ok(_val) => { + // FIXME + // let FcmResponse { error, .. } = val; + // if let Some(error) = error { + // match error { + // ErrorReason::MissingRegistration => Err(Error::BadDeviceToken( + // "Missing registration for token".into(), + // )), + // ErrorReason::InvalidRegistration => { + // Err(Error::BadDeviceToken("Invalid token registration".into())) + // } + // ErrorReason::NotRegistered => { + // Err(Error::BadDeviceToken("Token is not registered".into())) + // } + // ErrorReason::InvalidApnsCredential => Err(Error::BadApnsCredentials), + // e => Err(Error::FcmResponse(e)), + // } + // } else { + Ok(()) + // } + } + Err(e) => match e { + FcmError::Unauthorized => Err(Error::BadFcmApiKey), + e => Err(Error::FcmV1(e)), + }, + } + } +} + +// Manual Impl Because `fcm::Client` does not derive anything and doesn't need +// to be accounted for + +impl Clone for FcmV1Provider { + fn clone(&self) -> Self { + FcmV1Provider { + credentials: self.credentials.clone(), + client: Client::new(), + } + } + + fn clone_from(&mut self, source: &Self) { + self.credentials = source.credentials.clone(); + self.client = Client::new(); + } +} + +impl PartialEq for FcmV1Provider { + fn eq(&self, other: &Self) -> bool { + self.credentials == other.credentials + } +} + +impl Debug for FcmV1Provider { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "[FcmV1Provider] api_key = {}", self.credentials) + } +} diff --git a/src/providers/mod.rs b/src/providers/mod.rs index 07f39236..7d2993bc 100644 --- a/src/providers/mod.rs +++ b/src/providers/mod.rs @@ -1,12 +1,14 @@ pub mod apns; pub mod fcm; +pub mod fcm_v1; #[cfg(any(debug_assertions, test))] pub mod noop; use { + self::fcm_v1::FcmV1Provider, crate::{ blob::ENCRYPTED_FLAG, - error::{self}, + error, providers::{apns::ApnsProvider, fcm::FcmProvider}, }, async_trait::async_trait, @@ -82,6 +84,7 @@ pub trait PushProvider { const PROVIDER_APNS: &str = "apns"; const PROVIDER_APNS_SANDBOX: &str = "apns-sandbox"; const PROVIDER_FCM: &str = "fcm"; +const PROVIDER_FCM_V1: &str = "fcm_v1"; #[cfg(any(debug_assertions, test))] const PROVIDER_NOOP: &str = "noop"; @@ -92,6 +95,7 @@ pub enum ProviderKind { Apns, ApnsSandbox, Fcm, + FcmV1, #[cfg(any(debug_assertions, test))] Noop, } @@ -102,6 +106,7 @@ impl ProviderKind { Self::Apns => PROVIDER_APNS, Self::ApnsSandbox => PROVIDER_APNS_SANDBOX, Self::Fcm => PROVIDER_FCM, + Self::FcmV1 => PROVIDER_FCM_V1, #[cfg(any(debug_assertions, test))] Self::Noop => PROVIDER_NOOP, } @@ -139,7 +144,7 @@ impl TryFrom<&str> for ProviderKind { match value.to_lowercase().as_str() { PROVIDER_APNS => Ok(Self::Apns), PROVIDER_APNS_SANDBOX => Ok(Self::ApnsSandbox), - PROVIDER_FCM => Ok(Self::Fcm), + PROVIDER_FCM => Ok(Self::FcmV1), #[cfg(any(debug_assertions, test))] PROVIDER_NOOP => Ok(Self::Noop), _ => Err(error::Error::ProviderNotFound(value.to_owned())), @@ -151,6 +156,7 @@ impl TryFrom<&str> for ProviderKind { #[derive(Debug)] pub enum Provider { Fcm(FcmProvider), + FcmV1(FcmV1Provider), Apns(ApnsProvider), #[cfg(any(debug_assertions, test))] Noop(NoopProvider), @@ -162,6 +168,7 @@ impl PushProvider for Provider { async fn send_notification(&mut self, token: String, body: PushMessage) -> error::Result<()> { match self { Provider::Fcm(p) => p.send_notification(token, body).await, + Provider::FcmV1(p) => p.send_notification(token, body).await, Provider::Apns(p) => p.send_notification(token, body).await, #[cfg(any(debug_assertions, test))] Provider::Noop(p) => p.send_notification(token, body).await, diff --git a/src/stores/tenant.rs b/src/stores/tenant.rs index d858a552..bef7b982 100644 --- a/src/stores/tenant.rs +++ b/src/stores/tenant.rs @@ -10,7 +10,8 @@ use { providers::{ apns::ApnsProvider, fcm::FcmProvider, - Provider::{self, Apns, Fcm}, + fcm_v1::FcmV1Provider, + Provider::{self, Apns, Fcm, FcmV1}, ProviderKind, }, }, @@ -82,6 +83,7 @@ pub struct Tenant { pub id: String, pub fcm_api_key: Option, + pub fcm_v1_credentials: Option, pub apns_type: Option, pub apns_topic: Option, @@ -113,6 +115,11 @@ pub struct TenantFcmUpdateParams { pub fcm_api_key: String, } +#[derive(Debug, Eq, PartialEq, Clone)] +pub struct TenantFcmV1UpdateParams { + pub fcm_v1_credentials: String, +} + #[derive(Deserialize, Clone, Debug)] pub enum TenantApnsUpdateAuth { Certificate { @@ -144,6 +151,10 @@ impl Tenant { supported.push(ProviderKind::Fcm); } + if self.fcm_v1_credentials.is_some() { + supported.push(ProviderKind::FcmV1); + } + // Only available in debug/testing #[cfg(any(debug_assertions, test))] supported.push(ProviderKind::Noop); @@ -244,6 +255,14 @@ impl Tenant { } None => Err(ProviderNotAvailable(provider.into())), }, + ProviderKind::FcmV1 => match self.fcm_v1_credentials.clone() { + Some(fcm_v1_credentials) => { + debug!("fcm v1 provider is matched"); + let fcm = FcmV1Provider::new(fcm_v1_credentials); + Ok(FcmV1(fcm)) + } + None => Err(ProviderNotAvailable(provider.into())), + }, #[cfg(any(debug_assertions, test))] ProviderKind::Noop => { debug!("noop provider is matched"); @@ -259,6 +278,11 @@ pub trait TenantStore { async fn delete_tenant(&self, id: &str) -> Result<()>; async fn create_tenant(&self, params: TenantUpdateParams) -> Result; async fn update_tenant_fcm(&self, id: &str, params: TenantFcmUpdateParams) -> Result; + async fn update_tenant_fcm_v1( + &self, + id: &str, + params: TenantFcmV1UpdateParams, + ) -> Result; async fn update_tenant_apns(&self, id: &str, params: TenantApnsUpdateParams) -> Result; async fn update_tenant_apns_auth( &self, @@ -328,6 +352,24 @@ impl TenantStore for PgPool { Ok(res) } + #[instrument(skip(self))] + async fn update_tenant_fcm_v1( + &self, + id: &str, + params: TenantFcmV1UpdateParams, + ) -> Result { + let res = sqlx::query_as::( + "UPDATE public.tenants SET fcm_v1_credentials = $2, updated_at = NOW() WHERE id = $1 \ + RETURNING *;", + ) + .bind(id) + .bind(params.fcm_v1_credentials) + .fetch_one(self) + .await?; + + Ok(res) + } + #[instrument(skip(self))] async fn update_tenant_apns(&self, id: &str, params: TenantApnsUpdateParams) -> Result { let res = sqlx::query_as::( @@ -419,6 +461,7 @@ impl DefaultTenantStore { Ok(DefaultTenantStore(Tenant { id: DEFAULT_TENANT_ID.to_string(), fcm_api_key: config.fcm_api_key.clone(), + fcm_v1_credentials: config.fcm_v1_credentials.clone(), apns_type: config.apns_type, apns_topic: config.apns_topic.clone(), apns_certificate: config.apns_certificate.clone(), @@ -453,6 +496,14 @@ impl TenantStore for DefaultTenantStore { panic!("Shouldn't have run in single tenant mode") } + async fn update_tenant_fcm_v1( + &self, + _id: &str, + _params: TenantFcmV1UpdateParams, + ) -> Result { + panic!("Shouldn't have run in single tenant mode") + } + async fn update_tenant_apns( &self, _id: &str, diff --git a/tenant_migrations/1713226293_fcm-v1.sql b/tenant_migrations/1713226293_fcm-v1.sql new file mode 100644 index 00000000..1e8ccf40 --- /dev/null +++ b/tenant_migrations/1713226293_fcm-v1.sql @@ -0,0 +1,2 @@ +ALTER TABLE public.tenants + ADD COLUMN fcm_v1_credentials TEXT NULLABLE DEFAULT NULL; diff --git a/tenant_migrations/README.md b/tenant_migrations/README.md index fc7e1fda..4936e71a 100644 --- a/tenant_migrations/README.md +++ b/tenant_migrations/README.md @@ -8,4 +8,4 @@ This folder contains migrations for Echo Server and they are automatically calle ``` ## Contributors -To create a new migration run `./new.sh [description]` to make a new migration \ No newline at end of file +To create a new migration run `./new.sh [description]` to make a new migration diff --git a/terraform/README.md b/terraform/README.md index 4a287b3f..e8d958d9 100644 --- a/terraform/README.md +++ b/terraform/README.md @@ -95,6 +95,7 @@ No outputs. | [azs](#input\_azs) | n/a |
list(string)
|
[
"eu-central-1a",
"eu-central-1b",
"eu-central-1c"
]
| no | | [cloud\_api\_key](#input\_cloud\_api\_key) | n/a |
string
|
n/a
| yes | | [geoip\_db\_key](#input\_geoip\_db\_key) | The key to the GeoIP database |
string
|
"GeoLite2-City.mmdb"
| no | + | [grafana\_auth](#input\_grafana\_auth) | n/a |
string
|
n/a
| yes | | [grafana\_endpoint](#input\_grafana\_endpoint) | n/a |
string
|
n/a
| yes | | [image\_version](#input\_image\_version) | n/a |
string
|
""
| no | | [jwt\_secret](#input\_jwt\_secret) | n/a |
string
|
n/a
| yes | diff --git a/terraform/provider.tf b/terraform/provider.tf index 0f844f83..f7404ba7 100644 --- a/terraform/provider.tf +++ b/terraform/provider.tf @@ -12,9 +12,9 @@ provider "aws" { } } -# Expects GRAFANA_AUTH env variable to be set provider "grafana" { - url = "https://${var.grafana_endpoint}" + url = "https://${var.grafana_endpoint}" + auth = var.grafana_endpoint } provider "random" {} diff --git a/terraform/variables.tf b/terraform/variables.tf index 778c0ca9..6bc29320 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -17,6 +17,10 @@ variable "grafana_endpoint" { type = string } +variable "grafana_auth" { + type = string +} + variable "image_version" { type = string default = "" diff --git a/tests/context/mod.rs b/tests/context/mod.rs index d294307d..a4d07488 100644 --- a/tests/context/mod.rs +++ b/tests/context/mod.rs @@ -66,6 +66,8 @@ impl TestContext for ConfigContext { apns_topic: None, #[cfg(not(feature = "multitenant"))] fcm_api_key: None, + #[cfg(not(feature = "multitenant"))] + fcm_v1_credentials: None, #[cfg(any(feature = "analytics", feature = "geoblock"))] s3_endpoint: None, #[cfg(any(feature = "analytics", feature = "geoblock"))] diff --git a/tests/functional/multitenant/fcm_v1.rs b/tests/functional/multitenant/fcm_v1.rs new file mode 100644 index 00000000..aa21f1bf --- /dev/null +++ b/tests/functional/multitenant/fcm_v1.rs @@ -0,0 +1,95 @@ +use { + crate::{context::EchoServerContext, functional::multitenant::ClaimsForValidation}, + echo_server::handlers::create_tenant::TenantRegisterBody, + jsonwebtoken::{encode, EncodingKey, Header}, + random_string::generate, + std::{env, time::SystemTime}, + test_context::test_context, +}; + +#[test_context(EchoServerContext)] +#[tokio::test] +async fn tenant_update_fcm_valid(ctx: &mut EchoServerContext) { + let charset = "1234567890"; + let random_tenant_id = generate(12, charset); + let payload = TenantRegisterBody { + id: random_tenant_id.clone(), + }; + let unix_timestamp = SystemTime::now() + .duration_since(SystemTime::UNIX_EPOCH) + .unwrap() + .as_secs() as usize; + let token_claims = ClaimsForValidation { + sub: random_tenant_id.clone(), + aud: "authenticated".to_string(), + role: "authenticated".to_string(), + exp: unix_timestamp + 60 * 60, // Add an hour for expiration + }; + let jwt_token = encode( + &Header::default(), + &token_claims, + &EncodingKey::from_secret(ctx.config.jwt_secret.as_bytes()), + ) + .expect("Failed to encode jwt token"); + + // Register tenant + let client = reqwest::Client::new(); + let register_response = client + .post(format!("http://{}/tenants", ctx.server.public_addr)) + .json(&payload) + .header("AUTHORIZATION", jwt_token.clone()) + .send() + .await + .expect("Call failed"); + assert_eq!(register_response.status(), reqwest::StatusCode::OK); + + // Send valid API Key + let credentials = env::var("ECHO_TEST_FCM_V1_CREDENTIALS").unwrap(); + let form = reqwest::multipart::Form::new().text("credentials", credentials); + + let response_fcm_update = client + .post(format!( + "http://{}/tenants/{}/fcm", + ctx.server.public_addr, &random_tenant_id + )) + .header("AUTHORIZATION", jwt_token.clone()) + .multipart(form) + .send() + .await + .expect("Call failed"); + assert_eq!(response_fcm_update.status(), reqwest::StatusCode::OK); +} + +#[test_context(EchoServerContext)] +#[tokio::test] +async fn tenant_update_fcm_bad(ctx: &mut EchoServerContext) { + let charset = "1234567890"; + let random_tenant_id = generate(12, charset); + let payload = TenantRegisterBody { + id: random_tenant_id.clone(), + }; + + // Register tenant + let client = reqwest::Client::new(); + client + .post(format!("http://{}/tenants", ctx.server.public_addr)) + .json(&payload) + .send() + .await + .expect("Call failed"); + + // Send invalid API Key + let form = reqwest::multipart::Form::new().text("credentials", "invalid-key"); + + let response = client + .post(format!( + "http://{}/tenants/{}/fcm", + ctx.server.public_addr, &random_tenant_id + )) + .multipart(form) + .send() + .await + .expect("Call failed"); + + assert!(!response.status().is_success(), "Response was successful"); +} diff --git a/tests/functional/stores/tenant.rs b/tests/functional/stores/tenant.rs index 08701c29..a1c82833 100644 --- a/tests/functional/stores/tenant.rs +++ b/tests/functional/stores/tenant.rs @@ -1,7 +1,8 @@ use { crate::context::StoreContext, echo_server::stores::tenant::{ - TenantApnsUpdateAuth, TenantApnsUpdateParams, TenantFcmUpdateParams, TenantUpdateParams, + TenantApnsUpdateAuth, TenantApnsUpdateParams, TenantFcmUpdateParams, + TenantFcmV1UpdateParams, TenantUpdateParams, }, test_context::test_context, uuid::Uuid, @@ -82,6 +83,30 @@ async fn tenant_fcm(ctx: &mut StoreContext) { assert!(res.is_ok()) } +#[test_context(StoreContext)] +#[tokio::test] +async fn tenant_fcm_v1(ctx: &mut StoreContext) { + let tenant = ctx + .tenants + .create_tenant(TenantUpdateParams { + id: Uuid::new_v4().to_string(), + }) + .await + .expect("creation failed"); + + let res = ctx + .tenants + .update_tenant_fcm_v1( + &tenant.id, + TenantFcmV1UpdateParams { + fcm_v1_credentials: "test-credentials".to_string(), + }, + ) + .await; + + assert!(res.is_ok()) +} + #[test_context(StoreContext)] #[tokio::test] async fn tenant_apns(ctx: &mut StoreContext) { From 3fa153822fdcc51c29f9849c8f1dde6bb74ea6c5 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 15 Apr 2024 21:44:59 -0400 Subject: [PATCH 03/24] fix: bad match --- src/providers/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/providers/mod.rs b/src/providers/mod.rs index 7d2993bc..3f4fce4d 100644 --- a/src/providers/mod.rs +++ b/src/providers/mod.rs @@ -144,7 +144,8 @@ impl TryFrom<&str> for ProviderKind { match value.to_lowercase().as_str() { PROVIDER_APNS => Ok(Self::Apns), PROVIDER_APNS_SANDBOX => Ok(Self::ApnsSandbox), - PROVIDER_FCM => Ok(Self::FcmV1), + PROVIDER_FCM => Ok(Self::Fcm), + PROVIDER_FCM_V1 => Ok(Self::FcmV1), #[cfg(any(debug_assertions, test))] PROVIDER_NOOP => Ok(Self::Noop), _ => Err(error::Error::ProviderNotFound(value.to_owned())), From 0484caf4063c1bea997864db9f8222d129295dd0 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 15 Apr 2024 21:47:33 -0400 Subject: [PATCH 04/24] fix: missing route --- src/lib.rs | 1 + tests/functional/multitenant/fcm_v1.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2467e6e7..10d0549a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -219,6 +219,7 @@ pub async fn bootstap(mut shutdown: broadcast::Receiver<()>, config: Config) -> get(handlers::get_tenant::handler).delete(handlers::delete_tenant::handler), ) .route("/:id/fcm", post(handlers::update_fcm::handler)) + .route("/:id/fcm_v1", post(handlers::update_fcm_v1::handler)) .route("/:id/apns", post(handlers::update_apns::handler)) .layer( global_middleware.clone().layer( diff --git a/tests/functional/multitenant/fcm_v1.rs b/tests/functional/multitenant/fcm_v1.rs index aa21f1bf..209f073a 100644 --- a/tests/functional/multitenant/fcm_v1.rs +++ b/tests/functional/multitenant/fcm_v1.rs @@ -49,7 +49,7 @@ async fn tenant_update_fcm_valid(ctx: &mut EchoServerContext) { let response_fcm_update = client .post(format!( - "http://{}/tenants/{}/fcm", + "http://{}/tenants/{}/fcm_v1", ctx.server.public_addr, &random_tenant_id )) .header("AUTHORIZATION", jwt_token.clone()) @@ -83,7 +83,7 @@ async fn tenant_update_fcm_bad(ctx: &mut EchoServerContext) { let response = client .post(format!( - "http://{}/tenants/{}/fcm", + "http://{}/tenants/{}/fcm_v1", ctx.server.public_addr, &random_tenant_id )) .multipart(form) From fe90937c318485b9d86c4faff5cf066b88e595c6 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 15 Apr 2024 21:48:38 -0400 Subject: [PATCH 05/24] chore: rename test case --- tests/functional/multitenant/fcm_v1.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/multitenant/fcm_v1.rs b/tests/functional/multitenant/fcm_v1.rs index 209f073a..4f044793 100644 --- a/tests/functional/multitenant/fcm_v1.rs +++ b/tests/functional/multitenant/fcm_v1.rs @@ -9,7 +9,7 @@ use { #[test_context(EchoServerContext)] #[tokio::test] -async fn tenant_update_fcm_valid(ctx: &mut EchoServerContext) { +async fn tenant_update_fcm_v1_valid(ctx: &mut EchoServerContext) { let charset = "1234567890"; let random_tenant_id = generate(12, charset); let payload = TenantRegisterBody { @@ -62,7 +62,7 @@ async fn tenant_update_fcm_valid(ctx: &mut EchoServerContext) { #[test_context(EchoServerContext)] #[tokio::test] -async fn tenant_update_fcm_bad(ctx: &mut EchoServerContext) { +async fn tenant_update_fcm_v1_bad(ctx: &mut EchoServerContext) { let charset = "1234567890"; let random_tenant_id = generate(12, charset); let payload = TenantRegisterBody { From eb78db09c9edaa41b3f1ccb8dc45bba32550c4b6 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 15 Apr 2024 22:04:06 -0400 Subject: [PATCH 06/24] fix: var.grafana_auth --- terraform/provider.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/provider.tf b/terraform/provider.tf index f7404ba7..965bdb46 100644 --- a/terraform/provider.tf +++ b/terraform/provider.tf @@ -14,7 +14,7 @@ provider "aws" { provider "grafana" { url = "https://${var.grafana_endpoint}" - auth = var.grafana_endpoint + auth = var.grafana_auth } provider "random" {} From bef12c8e2d4f828165e02029bcd6ce81c7d75ad5 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 15 Apr 2024 22:22:27 -0400 Subject: [PATCH 07/24] fix: nullability constraint --- tenant_migrations/1713226293_fcm-v1.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tenant_migrations/1713226293_fcm-v1.sql b/tenant_migrations/1713226293_fcm-v1.sql index 1e8ccf40..958766be 100644 --- a/tenant_migrations/1713226293_fcm-v1.sql +++ b/tenant_migrations/1713226293_fcm-v1.sql @@ -1,2 +1,2 @@ ALTER TABLE public.tenants - ADD COLUMN fcm_v1_credentials TEXT NULLABLE DEFAULT NULL; + ADD COLUMN fcm_v1_credentials TEXT NULL DEFAULT NULL; From b5f74d0f0ea1c110b02733dc6a26c3c25871693c Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 15 Apr 2024 22:34:13 -0400 Subject: [PATCH 08/24] feat: use FCM v1 instead if configured --- src/handlers/get_tenant.rs | 11 ++++++++++- src/providers/mod.rs | 4 ---- src/stores/tenant.rs | 25 ++++++++++--------------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/handlers/get_tenant.rs b/src/handlers/get_tenant.rs index 21757751..77f5e300 100644 --- a/src/handlers/get_tenant.rs +++ b/src/handlers/get_tenant.rs @@ -57,7 +57,16 @@ pub async fn handler( let mut res = GetTenantResponse { url: format!("{}/{}", state.config.public_url, tenant.id), - enabled_providers: tenant.providers().iter().map(Into::into).collect(), + enabled_providers: tenant + .providers() + .iter() + .map(Into::into) + .chain(if tenant.fcm_v1_credentials.is_some() { + vec!["fcm_v1".to_string()] + } else { + vec![] + }) + .collect(), apns_topic: None, apns_type: None, suspended: tenant.suspended, diff --git a/src/providers/mod.rs b/src/providers/mod.rs index 3f4fce4d..8f55d1aa 100644 --- a/src/providers/mod.rs +++ b/src/providers/mod.rs @@ -84,7 +84,6 @@ pub trait PushProvider { const PROVIDER_APNS: &str = "apns"; const PROVIDER_APNS_SANDBOX: &str = "apns-sandbox"; const PROVIDER_FCM: &str = "fcm"; -const PROVIDER_FCM_V1: &str = "fcm_v1"; #[cfg(any(debug_assertions, test))] const PROVIDER_NOOP: &str = "noop"; @@ -95,7 +94,6 @@ pub enum ProviderKind { Apns, ApnsSandbox, Fcm, - FcmV1, #[cfg(any(debug_assertions, test))] Noop, } @@ -106,7 +104,6 @@ impl ProviderKind { Self::Apns => PROVIDER_APNS, Self::ApnsSandbox => PROVIDER_APNS_SANDBOX, Self::Fcm => PROVIDER_FCM, - Self::FcmV1 => PROVIDER_FCM_V1, #[cfg(any(debug_assertions, test))] Self::Noop => PROVIDER_NOOP, } @@ -145,7 +142,6 @@ impl TryFrom<&str> for ProviderKind { PROVIDER_APNS => Ok(Self::Apns), PROVIDER_APNS_SANDBOX => Ok(Self::ApnsSandbox), PROVIDER_FCM => Ok(Self::Fcm), - PROVIDER_FCM_V1 => Ok(Self::FcmV1), #[cfg(any(debug_assertions, test))] PROVIDER_NOOP => Ok(Self::Noop), _ => Err(error::Error::ProviderNotFound(value.to_owned())), diff --git a/src/stores/tenant.rs b/src/stores/tenant.rs index bef7b982..2cc81425 100644 --- a/src/stores/tenant.rs +++ b/src/stores/tenant.rs @@ -147,14 +147,10 @@ impl Tenant { supported.push(ProviderKind::ApnsSandbox); } - if self.fcm_api_key.is_some() { + if self.fcm_api_key.is_some() || self.fcm_v1_credentials.is_some() { supported.push(ProviderKind::Fcm); } - if self.fcm_v1_credentials.is_some() { - supported.push(ProviderKind::FcmV1); - } - // Only available in debug/testing #[cfg(any(debug_assertions, test))] supported.push(ProviderKind::Noop); @@ -247,21 +243,20 @@ impl Tenant { None => Err(ProviderNotAvailable(provider.into())), } } - ProviderKind::Fcm => match self.fcm_api_key.clone() { - Some(api_key) => { - debug!("fcm provider is matched"); - let fcm = FcmProvider::new(api_key); - Ok(Fcm(fcm)) - } - None => Err(ProviderNotAvailable(provider.into())), - }, - ProviderKind::FcmV1 => match self.fcm_v1_credentials.clone() { + ProviderKind::Fcm => match self.fcm_v1_credentials.clone() { Some(fcm_v1_credentials) => { debug!("fcm v1 provider is matched"); let fcm = FcmV1Provider::new(fcm_v1_credentials); Ok(FcmV1(fcm)) } - None => Err(ProviderNotAvailable(provider.into())), + None => match self.fcm_api_key.clone() { + Some(api_key) => { + debug!("fcm provider is matched"); + let fcm = FcmProvider::new(api_key); + Ok(Fcm(fcm)) + } + None => Err(ProviderNotAvailable(provider.into())), + }, }, #[cfg(any(debug_assertions, test))] ProviderKind::Noop => { From ff4b6a95ad94a39f24c227f7f35fb815ff8fd36d Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 15 Apr 2024 22:44:09 -0400 Subject: [PATCH 09/24] fix: tests --- .github/workflows/ci.yml | 2 +- justfile | 4 ++-- src/config.rs | 6 +----- tests/functional/multitenant/mod.rs | 1 + 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9cecd854..0386913a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,7 +75,7 @@ jobs: rustc: stable - name: "Clippy all features" cmd: clippy - args: --all-features --tests -- -D warnings + args: --all-features --all-targets -- -D warnings cache: {} rustc: stable - name: "Formatting" diff --git a/justfile b/justfile index 7f1fb4ee..f4fd5f10 100644 --- a/justfile +++ b/justfile @@ -7,10 +7,10 @@ devloop: unit fmt-imports test := "" test: - RUST_BACKTRACE=1 cargo test --lib --bins -- {{test}} + RUST_BACKTRACE=1 cargo test --all-targets -- {{test}} test-all: - RUST_BACKTRACE=1 cargo test --all-features --lib --bins -- {{test}} + RUST_BACKTRACE=1 cargo test --all-features --all-targets -- {{test}} clippy: #!/bin/bash diff --git a/src/config.rs b/src/config.rs index 46dd7db5..a7f3f4a8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -130,14 +130,10 @@ impl Config { supported.push(ProviderKind::ApnsSandbox); } - if self.fcm_api_key.is_some() { + if self.fcm_api_key.is_some() || self.fcm_v1_credentials.is_some() { supported.push(ProviderKind::Fcm); } - if self.fcm_v1_credentials.is_some() { - supported.push(ProviderKind::FcmV1); - } - // Only available in debug/testing #[cfg(any(debug_assertions, test))] supported.push(ProviderKind::Noop); diff --git a/tests/functional/multitenant/mod.rs b/tests/functional/multitenant/mod.rs index cf0a6a95..8df0fec2 100644 --- a/tests/functional/multitenant/mod.rs +++ b/tests/functional/multitenant/mod.rs @@ -3,6 +3,7 @@ use {crate::context::EchoServerContext, serde::Serialize, test_context::test_con mod apns; mod fcm; +mod fcm_v1; mod tenancy; /// Struct to hold claims for JWT validation From 3fcc91f55437bfc45cf3da98465046ce6f817821 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 18 Apr 2024 16:08:11 -0400 Subject: [PATCH 10/24] chore: various fixes/improvements to use new version of fcm-rust --- Cargo.lock | 373 +++++++++++++++++++++++++++++------ Cargo.toml | 4 +- src/blob.rs | 12 +- src/error.rs | 26 ++- src/handlers/push_message.rs | 9 +- src/providers/apns.rs | 2 +- src/providers/fcm.rs | 14 +- src/providers/fcm_v1.rs | 101 ++++------ src/providers/mod.rs | 6 +- src/providers/noop.rs | 24 ++- src/state.rs | 6 + src/stores/tenant.rs | 25 ++- tests/unit/messages.rs | 19 -- 13 files changed, 443 insertions(+), 178 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1d3f7cdb..0b623779 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -133,6 +133,15 @@ dependencies = [ "futures-core", ] +[[package]] +name = "async-lock" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" +dependencies = [ + "event-listener", +] + [[package]] name = "async-recursion" version = "1.0.5" @@ -141,7 +150,7 @@ checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.60", ] [[package]] @@ -163,7 +172,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.60", ] [[package]] @@ -174,7 +183,7 @@ checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.60", ] [[package]] @@ -766,7 +775,7 @@ dependencies = [ "base64 0.21.4", "bincode", "build-info-common", - "cargo_metadata", + "cargo_metadata 0.18.0", "chrono", "git2", "glob", @@ -805,7 +814,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.37", + "syn 2.0.60", "xz2", ] @@ -815,6 +824,12 @@ version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +[[package]] +name = "bytecount" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1e5f035d16fc623ae5f74981db80a439803888314e3a555fd6f04acd51a3205" + [[package]] name = "byteorder" version = "1.4.3" @@ -855,6 +870,19 @@ dependencies = [ "serde", ] +[[package]] +name = "cargo_metadata" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", +] + [[package]] name = "cargo_metadata" version = "0.18.0" @@ -900,9 +928,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.31" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", @@ -910,7 +938,7 @@ dependencies = [ "num-traits", "serde", "wasm-bindgen", - "windows-targets", + "windows-targets 0.52.5", ] [[package]] @@ -1033,6 +1061,19 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "crossbeam-epoch" +version = "0.9.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + [[package]] name = "crossbeam-queue" version = "0.3.8" @@ -1106,7 +1147,7 @@ checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.60", ] [[package]] @@ -1240,7 +1281,7 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1284,6 +1325,7 @@ dependencies = [ "ipnet", "is-variant-derive", "jsonwebtoken", + "moka", "once_cell", "opentelemetry", "opentelemetry-otlp", @@ -1417,7 +1459,7 @@ checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" dependencies = [ "errno-dragonfly", "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -1430,6 +1472,15 @@ dependencies = [ "libc", ] +[[package]] +name = "error-chain" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" +dependencies = [ + "version_check", +] + [[package]] name = "event-listener" version = "2.5.3" @@ -1468,7 +1519,7 @@ dependencies = [ [[package]] name = "fcm" version = "1.0.0" -source = "git+https://github.com/rj76/fcm-rust.git#4f9dedb6423c84f62f5f759593a9ebf774097527" +source = "git+https://github.com/WalletConnect/fcm-rust.git?branch=feat/key-not-from-file#6e419ada5319d728a476ee8434ca9228481b41a8" dependencies = [ "chrono", "dotenv", @@ -1630,7 +1681,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.60", ] [[package]] @@ -1672,8 +1723,7 @@ dependencies = [ [[package]] name = "gauth" version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b32329a7788126e9388c64f261174d2e2161d0c7cd28b55935ccc0da96920d8" +source = "git+https://github.com/WalletConnect/gauth-rs.git?branch=feat/key-not-from-file#d3ed7c956ae49bd53c1b347f4199c9fca219d9e8" dependencies = [ "anyhow", "base64 0.21.4", @@ -1685,6 +1735,7 @@ dependencies = [ "serde_derive", "serde_json", "thiserror", + "tokio", "url", ] @@ -1862,7 +1913,7 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" dependencies = [ - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2177,9 +2228,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.148" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "libgit2-sys" @@ -2281,6 +2332,15 @@ version = "2.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + [[package]] name = "mime" version = "0.3.17" @@ -2314,13 +2374,37 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.8" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "windows-sys 0.48.0", +] + +[[package]] +name = "moka" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1911e88d5831f748a4097a43862d129e3c6fca831eecac9b8db6d01d93c9de2" +dependencies = [ + "async-lock", + "async-trait", + "crossbeam-channel", + "crossbeam-epoch", + "crossbeam-utils", + "futures-util", + "once_cell", + "parking_lot 0.12.1", + "quanta", + "rustc_version", + "skeptic", + "smallvec", + "tagptr", + "thiserror", + "triomphe", + "uuid", ] [[package]] @@ -2525,7 +2609,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.60", ] [[package]] @@ -2715,7 +2799,7 @@ dependencies = [ "libc", "redox_syscall 0.3.5", "smallvec", - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -2744,7 +2828,7 @@ dependencies = [ "parquet", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.60", ] [[package]] @@ -2795,7 +2879,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.60", ] [[package]] @@ -2922,9 +3006,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" [[package]] name = "proc-macro2" -version = "1.0.67" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" dependencies = [ "unicode-ident", ] @@ -3004,11 +3088,37 @@ version = "2.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" +[[package]] +name = "pulldown-cmark" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57206b407293d2bcd3af849ce869d52068623f19e1b5ff8e8778e3309439682b" +dependencies = [ + "bitflags 2.4.0", + "memchr", + "unicase", +] + +[[package]] +name = "quanta" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5167a477619228a0b284fac2674e3c388cba90631d7b7de620e6f1fcd08da5" +dependencies = [ + "crossbeam-utils", + "libc", + "once_cell", + "raw-cpuid", + "wasi 0.11.0+wasi-snapshot-preview1", + "web-sys", + "winapi", +] + [[package]] name = "quote" -version = "1.0.33" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -3093,6 +3203,15 @@ dependencies = [ "fastrand 1.9.0", ] +[[package]] +name = "raw-cpuid" +version = "11.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d86a7c4638d42c44551f4791a20e687dbb4c3de1f33c43dd71e355cd429def1" +dependencies = [ + "bitflags 2.4.0", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -3271,7 +3390,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -3341,13 +3460,22 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "schannel" version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" dependencies = [ - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -3431,7 +3559,7 @@ checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.60", ] [[package]] @@ -3581,6 +3709,21 @@ dependencies = [ "time", ] +[[package]] +name = "skeptic" +version = "0.13.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16d23b015676c90a0f01c197bfdc786c20342c73a0afdda9025adb0bc42940a8" +dependencies = [ + "bytecount", + "cargo_metadata 0.14.2", + "error-chain", + "glob", + "pulldown-cmark", + "tempfile", + "walkdir", +] + [[package]] name = "slab" version = "0.4.9" @@ -3608,12 +3751,12 @@ dependencies = [ [[package]] name = "socket2" -version = "0.5.4" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e" +checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -3778,9 +3921,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.37" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ "proc-macro2", "quote", @@ -3793,6 +3936,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "tagptr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" + [[package]] name = "tap" version = "1.0.1" @@ -3809,7 +3958,7 @@ dependencies = [ "fastrand 2.0.1", "redox_syscall 0.3.5", "rustix", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -3835,22 +3984,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.49" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.49" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.60", ] [[package]] @@ -3928,9 +4077,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.32.0" +version = "1.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", "bytes", @@ -3940,9 +4089,9 @@ dependencies = [ "parking_lot 0.12.1", "pin-project-lite", "signal-hook-registry", - "socket2 0.5.4", + "socket2 0.5.6", "tokio-macros", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -3957,13 +4106,13 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.60", ] [[package]] @@ -4152,7 +4301,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.60", ] [[package]] @@ -4219,6 +4368,12 @@ dependencies = [ "tracing-log", ] +[[package]] +name = "triomphe" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859eb650cfee7434994602c3a68b25d77ad9e68c8a6cd491616ef86661382eb3" + [[package]] name = "try-lock" version = "0.2.4" @@ -4346,6 +4501,16 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "want" version = "0.3.1" @@ -4388,7 +4553,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.60", "wasm-bindgen-shared", ] @@ -4422,7 +4587,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.60", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4509,6 +4674,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -4521,7 +4695,7 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -4530,7 +4704,16 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", ] [[package]] @@ -4539,13 +4722,29 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] [[package]] @@ -4554,42 +4753,90 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" + [[package]] name = "winreg" version = "0.50.0" @@ -4597,7 +4844,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ "cfg-if", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 64b695a2..533426bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,7 +61,8 @@ atty = "0.2" # Push a2 = { git = "https://github.com/WalletConnect/a2", rev = "d0236c3", features = ["tracing", "openssl"] } fcm = "0.9" -fcm_v1 = { git = "https://github.com/rj76/fcm-rust.git", package = "fcm" } +# fcm_v1 = { git = "https://github.com/rj76/fcm-rust.git", package = "fcm" } +fcm_v1 = { git = "https://github.com/WalletConnect/fcm-rust.git", package = "fcm", branch = "feat/key-not-from-file" } # TODO use above version once released # Signature validation ed25519-dalek = "2.0.0-rc.2" @@ -93,6 +94,7 @@ cerberus = { git = "https://github.com/WalletConnect/cerberus.git", tag = "v0.5. async-recursion = "1.0.4" tap = "1.0.1" wiremock = "0.5.21" +moka = { version = "0.12", features = ["future"] } [dev-dependencies] serial_test = "1.0" diff --git a/src/blob.rs b/src/blob.rs index 0ae8a250..aca129e5 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -1,5 +1,5 @@ use { - crate::error::Result, + crate::error::{Error, Result}, base64::Engine as _, serde::{Deserialize, Serialize}, }; @@ -16,12 +16,10 @@ pub struct DecryptedPayloadBlob { } impl DecryptedPayloadBlob { - pub fn from_json_string(blob_string: String) -> Result { - Ok(serde_json::from_str(&blob_string)?) - } - pub fn from_base64_encoded(blob_string: &str) -> Result { - let blob_decoded = base64::engine::general_purpose::STANDARD.decode(blob_string)?; - Ok(serde_json::from_slice(&blob_decoded)?) + let blob_decoded = base64::engine::general_purpose::STANDARD + .decode(blob_string) + .map_err(Error::DecryptedNotificationDecode)?; + serde_json::from_slice(&blob_decoded).map_err(Error::DecryptedNotificationParse) } } diff --git a/src/error.rs b/src/error.rs index db9d101c..9b4be031 100644 --- a/src/error.rs +++ b/src/error.rs @@ -43,6 +43,9 @@ pub enum Error { #[error("FCM Responded with an error")] FcmResponse(fcm::ErrorReason), + #[error("FCM v1 Responded with an error")] + FcmV1Response(fcm_v1::ErrorReason), + #[error(transparent)] Io(#[from] std::io::Error), @@ -61,8 +64,17 @@ pub enum Error { #[error(transparent)] Base64Decode(#[from] base64::DecodeError), - #[error(transparent)] - Json(#[from] serde_json::Error), + #[error("Failed to decode legacy decrypted message: {0}")] + DecryptedNotificationDecode(base64::DecodeError), + + #[error("Failed to parse legacy decrypted message as JSON: {0}")] + DecryptedNotificationParse(serde_json::Error), + + #[error("Invalid ServiceServiceAccount key: {0}")] + InvalidServiceAccountKey(serde_json::Error), + + #[error("Failed to perform internal serialization: {0}")] + InternalSerializationError(serde_json::Error), #[error(transparent)] Store(#[from] StoreError), @@ -431,10 +443,16 @@ impl IntoResponse for Error { message: "failed to perform io task, this should not have occurred, please report at: https://github.com/walletconnect/echo-server".to_string(), }, ], vec![]), - Error::Json(_) => crate::handlers::Response::new_failure(StatusCode::BAD_REQUEST, vec![ + Error::DecryptedNotificationDecode(_) => crate::handlers::Response::new_failure(StatusCode::ACCEPTED, vec![ + ResponseError { + name: "json".to_string(), + message: "Decrypted notification does not decode as base64".to_string(), + }, + ], vec![]), + Error::DecryptedNotificationParse(_) => crate::handlers::Response::new_failure(StatusCode::ACCEPTED, vec![ ResponseError { name: "json".to_string(), - message: "received invalid json payload, please ensure all fields that contain json are valid".to_string(), + message: "Decrypted notification does not parse as JSON".to_string(), }, ], vec![]), Error::ToStr(_) => crate::handlers::Response::new_failure(StatusCode::INTERNAL_SERVER_ERROR, vec![ diff --git a/src/handlers/push_message.rs b/src/handlers/push_message.rs index f009d7b3..596b0314 100644 --- a/src/handlers/push_message.rs +++ b/src/handlers/push_message.rs @@ -364,8 +364,13 @@ pub async fn handler_internal( return Err((Error::TenantSuspended, analytics.clone())); } - let mut provider = tenant - .provider(&client.push_type) + let provider = tenant + .provider( + &client.push_type, + state.http_client.clone(), + &state.provider_cache, + ) + .await .tap_err(|e| warn!("error fetching provider: {e:?}")) .map_err(|e| (e, analytics.clone()))?; debug!( diff --git a/src/providers/apns.rs b/src/providers/apns.rs index 42b7a3ea..6dd1790d 100644 --- a/src/providers/apns.rs +++ b/src/providers/apns.rs @@ -50,7 +50,7 @@ impl ApnsProvider { impl PushProvider for ApnsProvider { #[instrument(name = "send_apns_notification")] async fn send_notification( - &mut self, + &self, token: String, body: PushMessage, ) -> crate::error::Result<()> { diff --git a/src/providers/fcm.rs b/src/providers/fcm.rs index 6352002c..e037d794 100644 --- a/src/providers/fcm.rs +++ b/src/providers/fcm.rs @@ -25,7 +25,7 @@ impl FcmProvider { impl PushProvider for FcmProvider { #[instrument(name = "send_fcm_notification")] async fn send_notification( - &mut self, + &self, token: String, body: PushMessage, ) -> crate::error::Result<()> { @@ -35,7 +35,9 @@ impl PushProvider for FcmProvider { PushMessage::RawPushMessage(message) => { // Sending `always_raw` encrypted message debug!("Sending raw encrypted message"); - message_builder.data(&message)?; + message_builder + .data(&message) + .map_err(Error::InternalSerializationError)?; set_message_priority_high(&mut message_builder); let fcm_message = message_builder.finalize(); self.client.send(fcm_message).await @@ -43,7 +45,9 @@ impl PushProvider for FcmProvider { PushMessage::LegacyPushMessage(LegacyPushMessage { id: _, payload }) => { if payload.is_encrypted() { debug!("Sending legacy `is_encrypted` message"); - message_builder.data(&payload)?; + message_builder + .data(&payload) + .map_err(Error::InternalSerializationError)?; set_message_priority_high(&mut message_builder); let fcm_message = message_builder.finalize(); self.client.send(fcm_message).await @@ -57,7 +61,9 @@ impl PushProvider for FcmProvider { let notification = notification_builder.finalize(); message_builder.notification(notification); - message_builder.data(&payload.to_owned())?; + message_builder + .data(&payload.to_owned()) + .map_err(Error::InternalSerializationError)?; let fcm_message = message_builder.finalize(); self.client.send(fcm_message).await } diff --git a/src/providers/fcm_v1.rs b/src/providers/fcm_v1.rs index 6238b9aa..e3145fcb 100644 --- a/src/providers/fcm_v1.rs +++ b/src/providers/fcm_v1.rs @@ -3,32 +3,33 @@ use { crate::{blob::DecryptedPayloadBlob, error::Error, providers::PushProvider}, async_trait::async_trait, fcm_v1::{ - AndroidConfig, AndroidMessagePriority, AndroidNotification, Client, Error as FcmError, - Message, Notification, Target, WebpushConfig, + gauth::serv_account::ServiceAccountKey, AndroidConfig, AndroidMessagePriority, + AndroidNotification, Client, Error as FcmError, ErrorReason, Message, Notification, + Response, Target, WebpushConfig, }, - std::fmt::{Debug, Formatter}, tracing::{debug, instrument}, }; +#[derive(Debug, Clone)] pub struct FcmV1Provider { - credentials: String, client: Client, } impl FcmV1Provider { - pub fn new(credentials: String) -> Self { + pub fn new(credentials: ServiceAccountKey, http_client: reqwest::Client) -> Self { Self { - credentials, - client: Client::new(), + client: Client::builder() + .http_client(http_client) + .build(credentials), } } } #[async_trait] impl PushProvider for FcmV1Provider { - #[instrument(name = "send_fcm_v1_notification")] + #[instrument(name = "send_fcm_v1_notification", skip_all)] async fn send_notification( - &mut self, + &self, token: String, body: PushMessage, ) -> crate::error::Result<()> { @@ -37,7 +38,9 @@ impl PushProvider for FcmV1Provider { // Sending `always_raw` encrypted message debug!("Sending raw encrypted message"); let message = Message { - data: Some(serde_json::to_value(message)?), + data: Some( + serde_json::to_value(message).map_err(Error::InternalSerializationError)?, + ), notification: None, target: Target::Token(token), android: Some(AndroidConfig { @@ -67,7 +70,10 @@ impl PushProvider for FcmV1Provider { if payload.is_encrypted() { debug!("Sending legacy `is_encrypted` message"); let message = Message { - data: Some(serde_json::to_value(payload)?), + data: Some( + serde_json::to_value(payload) + .map_err(Error::InternalSerializationError)?, + ), notification: None, target: Target::Token(token), android: Some(AndroidConfig { @@ -97,7 +103,10 @@ impl PushProvider for FcmV1Provider { let blob = DecryptedPayloadBlob::from_base64_encoded(&payload.blob)?; let message = Message { - data: Some(serde_json::to_value(payload.to_owned())?), + data: Some( + serde_json::to_value(payload.to_owned()) + .map_err(Error::InternalSerializationError)?, + ), notification: Some(Notification { title: Some(blob.title.clone()), body: Some(blob.body.clone()), @@ -158,26 +167,25 @@ impl PushProvider for FcmV1Provider { }; match result { - Ok(_val) => { - // FIXME - // let FcmResponse { error, .. } = val; - // if let Some(error) = error { - // match error { - // ErrorReason::MissingRegistration => Err(Error::BadDeviceToken( - // "Missing registration for token".into(), - // )), - // ErrorReason::InvalidRegistration => { - // Err(Error::BadDeviceToken("Invalid token registration".into())) - // } - // ErrorReason::NotRegistered => { - // Err(Error::BadDeviceToken("Token is not registered".into())) - // } - // ErrorReason::InvalidApnsCredential => Err(Error::BadApnsCredentials), - // e => Err(Error::FcmResponse(e)), - // } - // } else { - Ok(()) - // } + Ok(val) => { + let Response { error, .. } = val; + if let Some(error) = error { + match error { + ErrorReason::MissingRegistration => Err(Error::BadDeviceToken( + "Missing registration for token".into(), + )), + ErrorReason::InvalidRegistration => { + Err(Error::BadDeviceToken("Invalid token registration".into())) + } + ErrorReason::NotRegistered => { + Err(Error::BadDeviceToken("Token is not registered".into())) + } + ErrorReason::InvalidApnsCredential => Err(Error::BadApnsCredentials), + e => Err(Error::FcmV1Response(e)), + } + } else { + Ok(()) + } } Err(e) => match e { FcmError::Unauthorized => Err(Error::BadFcmApiKey), @@ -186,32 +194,3 @@ impl PushProvider for FcmV1Provider { } } } - -// Manual Impl Because `fcm::Client` does not derive anything and doesn't need -// to be accounted for - -impl Clone for FcmV1Provider { - fn clone(&self) -> Self { - FcmV1Provider { - credentials: self.credentials.clone(), - client: Client::new(), - } - } - - fn clone_from(&mut self, source: &Self) { - self.credentials = source.credentials.clone(); - self.client = Client::new(); - } -} - -impl PartialEq for FcmV1Provider { - fn eq(&self, other: &Self) -> bool { - self.credentials == other.credentials - } -} - -impl Debug for FcmV1Provider { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "[FcmV1Provider] api_key = {}", self.credentials) - } -} diff --git a/src/providers/mod.rs b/src/providers/mod.rs index 8f55d1aa..4ebcabed 100644 --- a/src/providers/mod.rs +++ b/src/providers/mod.rs @@ -78,7 +78,7 @@ pub struct RawPushMessage { #[async_trait] pub trait PushProvider { - async fn send_notification(&mut self, token: String, body: PushMessage) -> error::Result<()>; + async fn send_notification(&self, token: String, body: PushMessage) -> error::Result<()>; } const PROVIDER_APNS: &str = "apns"; @@ -150,7 +150,7 @@ impl TryFrom<&str> for ProviderKind { } #[allow(clippy::large_enum_variant)] -#[derive(Debug)] +#[derive(Debug, Clone)] pub enum Provider { Fcm(FcmProvider), FcmV1(FcmV1Provider), @@ -162,7 +162,7 @@ pub enum Provider { #[async_trait] impl PushProvider for Provider { #[instrument(name = "send_notification")] - async fn send_notification(&mut self, token: String, body: PushMessage) -> error::Result<()> { + async fn send_notification(&self, token: String, body: PushMessage) -> error::Result<()> { match self { Provider::Fcm(p) => p.send_notification(token, body).await, Provider::FcmV1(p) => p.send_notification(token, body).await, diff --git a/src/providers/noop.rs b/src/providers/noop.rs index 89b63fdd..b6b51fb1 100644 --- a/src/providers/noop.rs +++ b/src/providers/noop.rs @@ -1,11 +1,16 @@ use { - super::PushMessage, crate::providers::PushProvider, async_trait::async_trait, reqwest::Url, - std::collections::HashMap, tracing::instrument, + super::PushMessage, + crate::providers::PushProvider, + async_trait::async_trait, + reqwest::Url, + std::{collections::HashMap, sync::Arc}, + tokio::sync::RwLock, + tracing::instrument, }; -#[derive(Debug, Default, PartialEq, Eq, Clone)] +#[derive(Debug, Default, Clone)] pub struct NoopProvider { - notifications: HashMap>, + notifications: Arc>>>, } impl NoopProvider { @@ -18,13 +23,14 @@ impl NoopProvider { impl PushProvider for NoopProvider { #[instrument(name = "send_noop_notification")] async fn send_notification( - &mut self, + &self, token: String, body: PushMessage, ) -> crate::error::Result<()> { - self.bootstrap(token.clone()); + self.bootstrap(token.clone()).await; - let notifications = self.notifications.get_mut(&token).unwrap(); + let mut lock = self.notifications.write().await; + let notifications = lock.get_mut(&token).unwrap(); notifications.append(&mut vec![body]); if let Ok(url) = token.parse::() { @@ -38,7 +44,7 @@ impl PushProvider for NoopProvider { // Utils impl NoopProvider { /// Insert empty notifications for a new token - fn bootstrap(&mut self, token: String) { - self.notifications.entry(token).or_default(); + async fn bootstrap(&self, token: String) { + self.notifications.write().await.entry(token).or_default(); } } diff --git a/src/state.rs b/src/state.rs index 5ae5e331..d4341005 100644 --- a/src/state.rs +++ b/src/state.rs @@ -5,10 +5,12 @@ use { config::Config, metrics::Metrics, networking, + providers::Provider, relay::RelayClient, stores::{client::ClientStore, notification::NotificationStore, tenant::TenantStore}, }, build_info::BuildInfo, + moka::future::Cache, std::{net::IpAddr, sync::Arc}, wc::geoip::{block::middleware::GeoBlockLayer, MaxMindResolver}, }; @@ -57,6 +59,8 @@ pub struct AppState { pub instance_id: uuid::Uuid, /// Service instance uptime measurement pub uptime: std::time::Instant, + pub http_client: reqwest::Client, + pub provider_cache: Cache, } build_info::build_info!(fn build_info); @@ -106,6 +110,8 @@ pub fn new_state( geoblock: None, instance_id: uuid::Uuid::new_v4(), uptime: std::time::Instant::now(), + http_client: reqwest::Client::new(), + provider_cache: Cache::new(100), }) } diff --git a/src/stores/tenant.rs b/src/stores/tenant.rs index 2cc81425..03b2b396 100644 --- a/src/stores/tenant.rs +++ b/src/stores/tenant.rs @@ -4,7 +4,7 @@ use { crate::{ error::{ self, - Error::{InvalidTenantId, ProviderNotAvailable}, + Error::{self, InvalidTenantId, ProviderNotAvailable}, Result, }, providers::{ @@ -18,6 +18,8 @@ use { async_trait::async_trait, base64::Engine as _, chrono::{DateTime, Utc}, + moka::future::Cache, + reqwest::Client, serde::{Deserialize, Serialize}, sqlx::{Executor, PgPool}, tracing::{debug, instrument}, @@ -186,7 +188,12 @@ impl Tenant { } #[instrument(skip_all, fields(tenant_id = %self.id, provider = %provider.as_str()))] - pub fn provider(&self, provider: &ProviderKind) -> Result { + pub async fn provider( + &self, + provider: &ProviderKind, + http_client: Client, + provider_cache: &Cache, + ) -> Result { if !self.providers().contains(provider) { return Err(ProviderNotAvailable(provider.into())); } @@ -246,8 +253,18 @@ impl Tenant { ProviderKind::Fcm => match self.fcm_v1_credentials.clone() { Some(fcm_v1_credentials) => { debug!("fcm v1 provider is matched"); - let fcm = FcmV1Provider::new(fcm_v1_credentials); - Ok(FcmV1(fcm)) + if let Some(provider) = provider_cache.get(&fcm_v1_credentials).await { + return Ok(provider); + } + let fcm = FcmV1(FcmV1Provider::new( + serde_json::from_str(&fcm_v1_credentials) + .map_err(Error::InvalidServiceAccountKey)?, + http_client, + )); + provider_cache + .insert(fcm_v1_credentials.clone(), fcm.clone()) + .await; + Ok(fcm) } None => match self.fcm_api_key.clone() { Some(api_key) => { diff --git a/tests/unit/messages.rs b/tests/unit/messages.rs index cb55082c..8dac370f 100644 --- a/tests/unit/messages.rs +++ b/tests/unit/messages.rs @@ -11,9 +11,6 @@ const EXAMPLE_CLEARTEXT_ENCODED_BLOB: &str = "eyJ0aXRsZSI6IllvdSBoYXZlIGEgc2lnbi // json string const EXAMPLE_CLEARTEXT_BLOB_TITLE: &str = "You have a sign request"; const EXAMPLE_CLEARTEXT_BLOB_BODY: &str = "example-dapp has sent you a request to sign a message"; -const EXAMPLE_CLEARTEXT_BLOB: &str = "{\"title\":\"You have a sign \ - request\",\"body\":\"example-dapp has sent you a request to \ - sign a message\"}"; // This can be any text as echo-server doesn't mutate or read it const EXAMPLE_ENCRYPTED_BLOB: &str = "encrypted-blob"; @@ -77,19 +74,3 @@ pub fn parse_encoded_blob() { } ) } - -#[test] -pub fn parse_blob() { - let blob = DecryptedPayloadBlob::from_json_string(EXAMPLE_CLEARTEXT_BLOB.to_string()) - .expect("Failed to parse blob"); - - assert_eq!( - blob, - DecryptedPayloadBlob { - title: EXAMPLE_CLEARTEXT_BLOB_TITLE.to_string(), - body: EXAMPLE_CLEARTEXT_BLOB_BODY.to_string(), - image: None, - url: None - } - ) -} From 37f019f546c8a340f75eaca923db522521000316 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 18 Apr 2024 16:16:06 -0400 Subject: [PATCH 11/24] chore: update --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0b623779..c3c31104 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1722,8 +1722,8 @@ dependencies = [ [[package]] name = "gauth" -version = "0.7.0" -source = "git+https://github.com/WalletConnect/gauth-rs.git?branch=feat/key-not-from-file#d3ed7c956ae49bd53c1b347f4199c9fca219d9e8" +version = "0.8.0" +source = "git+https://github.com/WalletConnect/gauth-rs.git?branch=feat/key-not-from-file#b422162a1c07e276a7ebcd5def28f4c5ba20e1d0" dependencies = [ "anyhow", "base64 0.21.4", From 377e73daad71896f8f12ef6b670417a1eb2e9527 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 22 Apr 2024 19:36:10 -0400 Subject: [PATCH 12/24] fix: wrong variable --- src/handlers/update_fcm_v1.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/handlers/update_fcm_v1.rs b/src/handlers/update_fcm_v1.rs index 6fb79b14..3d22de7a 100644 --- a/src/handlers/update_fcm_v1.rs +++ b/src/handlers/update_fcm_v1.rs @@ -41,7 +41,7 @@ pub async fn handler( #[cfg(feature = "cloud")] let jwt_verification_result = validate_tenant_request( &state.registry_client, - &state.gotrue_client, + &state.jwt_validation_client, &headers, id.clone(), None, @@ -49,7 +49,7 @@ pub async fn handler( .await; #[cfg(not(feature = "cloud"))] - let jwt_verification_result = validate_tenant_request(&state.gotrue_client, &headers); + let jwt_verification_result = validate_tenant_request(&state.jwt_validation_client, &headers); if let Err(e) = jwt_verification_result { error!( From 81029d1b913c3297dbf4efc80b9e3e840f9aef32 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 22 Apr 2024 19:56:26 -0400 Subject: [PATCH 13/24] fix: remove removed fields --- tests/functional/multitenant/fcm_v1.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/functional/multitenant/fcm_v1.rs b/tests/functional/multitenant/fcm_v1.rs index 4f044793..df42c118 100644 --- a/tests/functional/multitenant/fcm_v1.rs +++ b/tests/functional/multitenant/fcm_v1.rs @@ -21,8 +21,6 @@ async fn tenant_update_fcm_v1_valid(ctx: &mut EchoServerContext) { .as_secs() as usize; let token_claims = ClaimsForValidation { sub: random_tenant_id.clone(), - aud: "authenticated".to_string(), - role: "authenticated".to_string(), exp: unix_timestamp + 60 * 60, // Add an hour for expiration }; let jwt_token = encode( From 7106639e7d9a1b4dfe5bdd81429b73cd5cbf04aa Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 22 Apr 2024 19:56:33 -0400 Subject: [PATCH 14/24] chore: document secrets --- .github/SECRETS.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/SECRETS.md diff --git a/.github/SECRETS.md b/.github/SECRETS.md new file mode 100644 index 00000000..3022dcfa --- /dev/null +++ b/.github/SECRETS.md @@ -0,0 +1,15 @@ +## `PROD_JWT_SECRET` & `STAGING_JWT_SECRET` + +From 1Password: `cloud/push-server-jwt/prod` and `cloud/push-server-jwt/staging` + +Generated randomly and used by Cloud app to sign JWTs. + +## `ECHO_TEST_FCM_V1_CREDENTIALS` + +FCM v1 service account credentials for test cases. + +Setup: +- Go to the Push Server Tests Firebase project: https://console.firebase.google.com/project/push-server-tests-cc0f7/settings/cloudmessaging +- On Cloud Messaging tab, under the "Firebase Cloud Messaging API (V1)" header, click the "Manage Service Accounts" link +- Select the service account and click "Manage keys" +- Click "Add key" and select "Create new key" and pick JSON From e1400cc7bb3b9782a70d456513967c36e5a6794f Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 22 Apr 2024 20:13:28 -0400 Subject: [PATCH 15/24] fix: compile errors --- src/handlers/create_tenant.rs | 3 +-- src/handlers/delete_tenant.rs | 2 +- src/handlers/get_tenant.rs | 2 +- src/handlers/mod.rs | 2 +- src/handlers/update_apns.rs | 2 +- src/handlers/update_fcm.rs | 2 +- src/handlers/update_fcm_v1.rs | 17 +++++++++-------- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/handlers/create_tenant.rs b/src/handlers/create_tenant.rs index cb91656d..dfce4539 100644 --- a/src/handlers/create_tenant.rs +++ b/src/handlers/create_tenant.rs @@ -28,8 +28,7 @@ pub async fn handler( Json(body): Json, ) -> Result, Error> { #[cfg(feature = "cloud")] - if let Err(e) = - validate_tenant_request(&state.jwt_validation_client, &headers, body.id.clone()).await + if let Err(e) = validate_tenant_request(&state.jwt_validation_client, &headers, &body.id).await { error!( tenant_id = %body.id, diff --git a/src/handlers/delete_tenant.rs b/src/handlers/delete_tenant.rs index 3cdb885d..fcb96ab7 100644 --- a/src/handlers/delete_tenant.rs +++ b/src/handlers/delete_tenant.rs @@ -26,7 +26,7 @@ pub async fn handler( ) -> Result, Error> { #[cfg(feature = "cloud")] let verification_res = - validate_tenant_request(&state.jwt_validation_client, &headers, id.clone()).await; + validate_tenant_request(&state.jwt_validation_client, &headers, &id).await; #[cfg(not(feature = "cloud"))] let verification_res = validate_tenant_request(&state.jwt_validation_client, &headers); diff --git a/src/handlers/get_tenant.rs b/src/handlers/get_tenant.rs index e3e9a1fe..1a145af8 100644 --- a/src/handlers/get_tenant.rs +++ b/src/handlers/get_tenant.rs @@ -31,7 +31,7 @@ pub async fn handler( ) -> Result, Error> { #[cfg(feature = "cloud")] let verification_res = - validate_tenant_request(&state.jwt_validation_client, &headers, id.clone()).await; + validate_tenant_request(&state.jwt_validation_client, &headers, &id).await; #[cfg(not(feature = "cloud"))] let verification_res = validate_tenant_request(&state.jwt_validation_client, &headers); diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 897204f6..870d7565 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -160,7 +160,7 @@ impl Default for Response { pub async fn validate_tenant_request( jwt_validation_client: &JwtValidationClient, headers: &HeaderMap, - project_id: String, + project_id: &str, ) -> Result { if let Some(token_value) = headers.get(AUTHORIZATION) { Ok(match jwt_validation_client diff --git a/src/handlers/update_apns.rs b/src/handlers/update_apns.rs index d01a3ae4..477b29fc 100644 --- a/src/handlers/update_apns.rs +++ b/src/handlers/update_apns.rs @@ -126,7 +126,7 @@ pub async fn handler( // JWT verification #[cfg(feature = "cloud")] let jwt_verification_result = - validate_tenant_request(&state.jwt_validation_client, &headers, id.clone()).await; + validate_tenant_request(&state.jwt_validation_client, &headers, &id).await; #[cfg(not(feature = "cloud"))] let jwt_verification_result = validate_tenant_request(&state.jwt_validation_client, &headers); diff --git a/src/handlers/update_fcm.rs b/src/handlers/update_fcm.rs index f373a269..b8837bdf 100644 --- a/src/handlers/update_fcm.rs +++ b/src/handlers/update_fcm.rs @@ -41,7 +41,7 @@ pub async fn handler( // JWT token verification #[cfg(feature = "cloud")] let jwt_verification_result = - validate_tenant_request(&state.jwt_validation_client, &headers, id.clone()).await; + validate_tenant_request(&state.jwt_validation_client, &headers, &id).await; #[cfg(not(feature = "cloud"))] let jwt_verification_result = validate_tenant_request(&state.jwt_validation_client, &headers); diff --git a/src/handlers/update_fcm_v1.rs b/src/handlers/update_fcm_v1.rs index 3d22de7a..67e0d605 100644 --- a/src/handlers/update_fcm_v1.rs +++ b/src/handlers/update_fcm_v1.rs @@ -1,3 +1,4 @@ +use crate::providers::fcm_v1::FcmV1Provider; use { crate::{ error::{Error, Error::InvalidMultipartBody}, @@ -39,14 +40,8 @@ pub async fn handler( // JWT token verification #[cfg(feature = "cloud")] - let jwt_verification_result = validate_tenant_request( - &state.registry_client, - &state.jwt_validation_client, - &headers, - id.clone(), - None, - ) - .await; + let jwt_verification_result = + validate_tenant_request(&state.jwt_validation_client, &headers, &id).await; #[cfg(not(feature = "cloud"))] let jwt_verification_result = validate_tenant_request(&state.jwt_validation_client, &headers); @@ -78,6 +73,12 @@ pub async fn handler( return Err(InvalidMultipartBody); } + // TODO consider using the provider cache here. Remove from cache if invalid. + let _fcm = FcmV1Provider::new( + serde_json::from_str(&body.credentials).map_err(Error::InvalidServiceAccountKey)?, + reqwest::Client::new(), + ); + // ---- checks // TODO // let fcm_credentials = body.credentials.clone(); From 52b4cf6972321a3dba4f225af47ea2d33d59573d Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 22 Apr 2024 21:01:10 -0400 Subject: [PATCH 16/24] fix: provide valid JWTs to credentials tests --- src/handlers/update_fcm_v1.rs | 6 +-- tests/functional/multitenant/apns.rs | 53 +++++++++----------------- tests/functional/multitenant/fcm.rs | 40 ++++++------------- tests/functional/multitenant/fcm_v1.rs | 44 +++++++-------------- tests/functional/multitenant/mod.rs | 20 ++++++++++ 5 files changed, 67 insertions(+), 96 deletions(-) diff --git a/src/handlers/update_fcm_v1.rs b/src/handlers/update_fcm_v1.rs index 67e0d605..3b769280 100644 --- a/src/handlers/update_fcm_v1.rs +++ b/src/handlers/update_fcm_v1.rs @@ -1,4 +1,3 @@ -use crate::providers::fcm_v1::FcmV1Provider; use { crate::{ error::{Error, Error::InvalidMultipartBody}, @@ -73,10 +72,9 @@ pub async fn handler( return Err(InvalidMultipartBody); } - // TODO consider using the provider cache here. Remove from cache if invalid. - let _fcm = FcmV1Provider::new( + // Client will validate the key on startup + let _fcm = fcm_v1::Client::from_key( serde_json::from_str(&body.credentials).map_err(Error::InvalidServiceAccountKey)?, - reqwest::Client::new(), ); // ---- checks diff --git a/tests/functional/multitenant/apns.rs b/tests/functional/multitenant/apns.rs index f5432814..484bb8eb 100644 --- a/tests/functional/multitenant/apns.rs +++ b/tests/functional/multitenant/apns.rs @@ -11,31 +11,16 @@ use { #[test_context(EchoServerContext)] #[tokio::test] async fn tenant_update_apns_valid_token(ctx: &mut EchoServerContext) { - let tenant_id = Uuid::new_v4().to_string(); - let payload = TenantRegisterBody { - id: tenant_id.clone(), - }; - let unix_timestamp = SystemTime::now() - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap() - .as_secs() as usize; - let token_claims = ClaimsForValidation { - sub: tenant_id.clone(), - exp: unix_timestamp + 60 * 60, // Add an hour for expiration - }; - let jwt_token = encode( - &Header::default(), - &token_claims, - &EncodingKey::from_secret(ctx.config.jwt_secret.as_bytes()), - ) - .expect("Failed to encode jwt token"); + let (tenant_id, jwt_token) = generate_random_tenant_id(); // Register new tenant let client = reqwest::Client::new(); let create_tenant_result = client .post(format!("http://{}/tenants", ctx.server.public_addr)) - .header("AUTHORIZATION", jwt_token.clone()) - .json(&payload) + .bearer_auth(jwt_token) + .json(&TenantRegisterBody { + id: tenant_id.clone(), + }) .send() .await .expect("Failed to create a new tenant"); @@ -62,7 +47,7 @@ async fn tenant_update_apns_valid_token(ctx: &mut EchoServerContext) { "http://{}/tenants/{}/apns", ctx.server.public_addr, &tenant_id )) - .header("AUTHORIZATION", jwt_token.clone()) + .bearer_auth(jwt_token) .multipart(form) .send() .await @@ -73,17 +58,16 @@ async fn tenant_update_apns_valid_token(ctx: &mut EchoServerContext) { #[test_context(EchoServerContext)] #[tokio::test] async fn tenant_update_apns_bad_token(ctx: &mut EchoServerContext) { - let charset = "1234567890"; - let random_tenant_id = generate(12, charset); - let payload = TenantRegisterBody { - id: random_tenant_id.clone(), - }; + let (tenant_id, jwt_token) = generate_random_tenant_id(); // Register tenant let client = reqwest::Client::new(); client .post(format!("http://{}/tenants", ctx.server.public_addr)) - .json(&payload) + .bearer_auth(jwt_token) + .json(&TenantRegisterBody { + id: tenant_id.clone(), + }) .send() .await .expect("Call failed"); @@ -97,8 +81,9 @@ async fn tenant_update_apns_bad_token(ctx: &mut EchoServerContext) { let response = client .post(format!( "http://{}/tenants/{}/apns", - ctx.server.public_addr, &random_tenant_id + ctx.server.public_addr, tenant_id )) + .bearer_auth(jwt_token) .multipart(form) .send() .await @@ -110,17 +95,16 @@ async fn tenant_update_apns_bad_token(ctx: &mut EchoServerContext) { #[test_context(EchoServerContext)] #[tokio::test] async fn tenant_update_apns_bad_certificate(ctx: &mut EchoServerContext) { - let charset = "1234567890"; - let random_tenant_id = generate(12, charset); - let payload = TenantRegisterBody { - id: random_tenant_id.clone(), - }; + let (tenant_id, jwt_token) = generate_random_tenant_id(); // Register tenant let client = reqwest::Client::new(); client .post(format!("http://{}/tenants", ctx.server.public_addr)) - .json(&payload) + .bearer_auth(jwt_token) + .json(&TenantRegisterBody { + id: tenant_id.clone(), + }) .send() .await .expect("Call failed"); @@ -135,6 +119,7 @@ async fn tenant_update_apns_bad_certificate(ctx: &mut EchoServerContext) { "http://{}/tenants/{}/apns", ctx.server.public_addr, &random_tenant_id )) + .bearer_auth(jwt_token) .multipart(form) .send() .await diff --git a/tests/functional/multitenant/fcm.rs b/tests/functional/multitenant/fcm.rs index 6ecd694f..2dd36ebe 100644 --- a/tests/functional/multitenant/fcm.rs +++ b/tests/functional/multitenant/fcm.rs @@ -10,32 +10,16 @@ use { #[test_context(EchoServerContext)] #[tokio::test] async fn tenant_update_fcm_valid(ctx: &mut EchoServerContext) { - let charset = "1234567890"; - let random_tenant_id = generate(12, charset); - let payload = TenantRegisterBody { - id: random_tenant_id.clone(), - }; - let unix_timestamp = SystemTime::now() - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap() - .as_secs() as usize; - let token_claims = ClaimsForValidation { - sub: random_tenant_id.clone(), - exp: unix_timestamp + 60 * 60, // Add an hour for expiration - }; - let jwt_token = encode( - &Header::default(), - &token_claims, - &EncodingKey::from_secret(ctx.config.jwt_secret.as_bytes()), - ) - .expect("Failed to encode jwt token"); + let (tenant_id, jwt_token) = generate_random_tenant_id(); // Register tenant let client = reqwest::Client::new(); let register_response = client .post(format!("http://{}/tenants", ctx.server.public_addr)) - .json(&payload) - .header("AUTHORIZATION", jwt_token.clone()) + .bearer_auth(jwt_token) + .json(&TenantRegisterBody { + id: tenant_id.clone(), + }) .send() .await .expect("Call failed"); @@ -50,7 +34,7 @@ async fn tenant_update_fcm_valid(ctx: &mut EchoServerContext) { "http://{}/tenants/{}/fcm", ctx.server.public_addr, &random_tenant_id )) - .header("AUTHORIZATION", jwt_token.clone()) + .bearer_auth(jwt_token) .multipart(form) .send() .await @@ -61,17 +45,16 @@ async fn tenant_update_fcm_valid(ctx: &mut EchoServerContext) { #[test_context(EchoServerContext)] #[tokio::test] async fn tenant_update_fcm_bad(ctx: &mut EchoServerContext) { - let charset = "1234567890"; - let random_tenant_id = generate(12, charset); - let payload = TenantRegisterBody { - id: random_tenant_id.clone(), - }; + let (tenant_id, jwt_token) = generate_random_tenant_id(); // Register tenant let client = reqwest::Client::new(); client .post(format!("http://{}/tenants", ctx.server.public_addr)) - .json(&payload) + .bearer_auth(jwt_token) + .json(&TenantRegisterBody { + id: tenant_id.clone(), + }) .send() .await .expect("Call failed"); @@ -84,6 +67,7 @@ async fn tenant_update_fcm_bad(ctx: &mut EchoServerContext) { "http://{}/tenants/{}/fcm", ctx.server.public_addr, &random_tenant_id )) + .bearer_auth(jwt_token) .multipart(form) .send() .await diff --git a/tests/functional/multitenant/fcm_v1.rs b/tests/functional/multitenant/fcm_v1.rs index df42c118..62fdfeb5 100644 --- a/tests/functional/multitenant/fcm_v1.rs +++ b/tests/functional/multitenant/fcm_v1.rs @@ -10,32 +10,16 @@ use { #[test_context(EchoServerContext)] #[tokio::test] async fn tenant_update_fcm_v1_valid(ctx: &mut EchoServerContext) { - let charset = "1234567890"; - let random_tenant_id = generate(12, charset); - let payload = TenantRegisterBody { - id: random_tenant_id.clone(), - }; - let unix_timestamp = SystemTime::now() - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap() - .as_secs() as usize; - let token_claims = ClaimsForValidation { - sub: random_tenant_id.clone(), - exp: unix_timestamp + 60 * 60, // Add an hour for expiration - }; - let jwt_token = encode( - &Header::default(), - &token_claims, - &EncodingKey::from_secret(ctx.config.jwt_secret.as_bytes()), - ) - .expect("Failed to encode jwt token"); + let (tenant_id, jwt_token) = generate_random_tenant_id(); // Register tenant let client = reqwest::Client::new(); let register_response = client .post(format!("http://{}/tenants", ctx.server.public_addr)) - .json(&payload) - .header("AUTHORIZATION", jwt_token.clone()) + .bearer_auth(jwt_token) + .json(&TenantRegisterBody { + id: tenant_id.clone(), + }) .send() .await .expect("Call failed"); @@ -48,9 +32,9 @@ async fn tenant_update_fcm_v1_valid(ctx: &mut EchoServerContext) { let response_fcm_update = client .post(format!( "http://{}/tenants/{}/fcm_v1", - ctx.server.public_addr, &random_tenant_id + ctx.server.public_addr, tenant_id )) - .header("AUTHORIZATION", jwt_token.clone()) + .bearer_auth(jwt_token) .multipart(form) .send() .await @@ -61,17 +45,16 @@ async fn tenant_update_fcm_v1_valid(ctx: &mut EchoServerContext) { #[test_context(EchoServerContext)] #[tokio::test] async fn tenant_update_fcm_v1_bad(ctx: &mut EchoServerContext) { - let charset = "1234567890"; - let random_tenant_id = generate(12, charset); - let payload = TenantRegisterBody { - id: random_tenant_id.clone(), - }; + let (tenant_id, jwt_token) = generate_random_tenant_id(); // Register tenant let client = reqwest::Client::new(); client .post(format!("http://{}/tenants", ctx.server.public_addr)) - .json(&payload) + .bearer_auth(jwt_token) + .json(&TenantRegisterBody { + id: tenant_id.clone(), + }) .send() .await .expect("Call failed"); @@ -82,8 +65,9 @@ async fn tenant_update_fcm_v1_bad(ctx: &mut EchoServerContext) { let response = client .post(format!( "http://{}/tenants/{}/fcm_v1", - ctx.server.public_addr, &random_tenant_id + ctx.server.public_addr, &tenant_id )) + .bearer_auth(jwt_token) .multipart(form) .send() .await diff --git a/tests/functional/multitenant/mod.rs b/tests/functional/multitenant/mod.rs index 22cb748e..e2fa2aae 100644 --- a/tests/functional/multitenant/mod.rs +++ b/tests/functional/multitenant/mod.rs @@ -22,3 +22,23 @@ async fn test_health(ctx: &mut EchoServerContext) { .status(); assert!(body.is_success()); } + +pub fn generate_random_tenant_id() -> (String, String) { + let charset = "1234567890"; + let random_tenant_id = generate(12, charset); + let unix_timestamp = SystemTime::now() + .duration_since(SystemTime::UNIX_EPOCH) + .unwrap() + .as_secs() as usize; + let token_claims = ClaimsForValidation { + sub: random_tenant_id.clone(), + exp: unix_timestamp + 60 * 60, // Add an hour for expiration + }; + let jwt_token = encode( + &Header::default(), + &token_claims, + &EncodingKey::from_secret(ctx.config.jwt_secret.as_bytes()), + ) + .expect("Failed to encode jwt token"); + (random_tenant_id, jwt_token) +} From 4b12842101e24b1375de41d35090e94216a2cb0d Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 13 May 2024 11:07:41 -0400 Subject: [PATCH 17/24] fix: error handling --- .github/workflows/ci.yml | 2 +- Cargo.lock | 1293 ++++++++++++----------- Cargo.toml | 13 +- docker-compose.storage.yml | 16 + justfile | 5 +- src/error.rs | 36 +- src/handlers/register_client.rs | 6 +- src/handlers/update_fcm_v1.rs | 28 +- src/middleware/validate_signature.rs | 2 +- src/providers/fcm.rs | 2 +- src/providers/fcm_v1.rs | 20 +- src/relay/mod.rs | 2 +- src/stores/tenant.rs | 19 +- tests/context/mod.rs | 5 +- tests/functional/multitenant/apns.rs | 29 +- tests/functional/multitenant/fcm.rs | 22 +- tests/functional/multitenant/fcm_v1.rs | 71 +- tests/functional/multitenant/mod.rs | 23 +- tests/functional/multitenant/tenancy.rs | 46 +- 19 files changed, 883 insertions(+), 757 deletions(-) create mode 100644 docker-compose.storage.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0386913a..fafbaf4a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,7 +85,7 @@ jobs: rustc: nightly - name: "Unit Tests" cmd: test - args: --features multitenant,analytics,geoblock,functional_tests + args: --features multitenant,analytics,geoblock,functional_tests,apns_tests,fcm_tests,fcmv1_tests cache: { sharedKey: "tests" } rustc: stable - name: "Single-tenant functional tests" diff --git a/Cargo.lock b/Cargo.lock index 2ab15122..db93161b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,42 +36,43 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.7.6" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" dependencies = [ - "getrandom 0.2.10", + "getrandom 0.2.15", "once_cell", "version_check", ] [[package]] name = "ahash" -version = "0.8.3" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", "const-random", - "getrandom 0.2.10", + "getrandom 0.2.15", "once_cell", "version_check", + "zerocopy", ] [[package]] name = "aho-corasick" -version = "1.1.1" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea5d730647d4fadd988536d06fecce94b7b4f2a7efdae548f1cf4b63205518ab" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] [[package]] name = "allocator-api2" -version = "0.2.16" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "analytics" @@ -108,9 +109,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" [[package]] name = "assert-json-diff" @@ -129,17 +130,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" dependencies = [ "concurrent-queue", - "event-listener", + "event-listener 2.5.3", "futures-core", ] [[package]] name = "async-lock" -version = "2.8.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" +checksum = "d034b430882f8381900d3fe6f0aaa3ad94f2cb4ac519b429692a1bc2dda4ae7b" dependencies = [ - "event-listener", + "event-listener 4.0.3", + "event-listener-strategy", + "pin-project-lite", ] [[package]] @@ -161,18 +164,18 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] name = "async-trait" -version = "0.1.73" +version = "0.1.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" +checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -197,9 +200,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "aws-config" @@ -219,11 +222,11 @@ dependencies = [ "aws-smithy-types", "aws-types", "bytes", - "fastrand 2.0.1", + "fastrand 2.1.0", "hex", "http", "hyper", - "ring", + "ring 0.16.20", "time", "tokio", "tower", @@ -239,7 +242,7 @@ checksum = "70a66ac8ef5fa9cf01c2d999f39d16812e90ec1467bd382cbbb74ba23ea86201" dependencies = [ "aws-smithy-async", "aws-smithy-types", - "fastrand 2.0.1", + "fastrand 2.1.0", "tokio", "tracing", "zeroize", @@ -279,7 +282,7 @@ dependencies = [ "aws-smithy-runtime-api", "aws-smithy-types", "aws-types", - "fastrand 2.0.1", + "fastrand 2.1.0", "http", "percent-encoding", "tracing", @@ -431,14 +434,14 @@ dependencies = [ "aws-smithy-http-tower", "aws-smithy-types", "bytes", - "fastrand 2.0.1", + "fastrand 2.1.0", "http", "http-body", "hyper", "hyper-rustls", "lazy_static", "pin-project-lite", - "rustls 0.21.7", + "rustls 0.21.12", "tokio", "tower", "tracing", @@ -525,7 +528,7 @@ dependencies = [ "aws-smithy-runtime-api", "aws-smithy-types", "bytes", - "fastrand 2.0.1", + "fastrand 2.1.0", "http", "http-body", "once_cell", @@ -652,9 +655,9 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.69" +version = "0.3.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" dependencies = [ "addr2line", "cc", @@ -679,9 +682,9 @@ checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5" [[package]] name = "base64" -version = "0.21.4" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "base64-simd" @@ -716,9 +719,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "block-buffer" @@ -746,39 +749,40 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "build-info" -version = "0.0.33" +version = "0.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1add148a02352a8149c1ae42528988427aeb0438f808df66f393cb9948006ec" +checksum = "bc978ce446e6cd132434049d6a3e9b92982228fd27e0ae11437b8e121b50e7e4" dependencies = [ + "bincode", "build-info-common", "build-info-proc", ] [[package]] name = "build-info-build" -version = "0.0.33" +version = "0.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a9cddd0655ecb60d7a500f30d3ae4e69b798026d76c3d16b2f464a72913066e" +checksum = "02216ebb53a94c78f65d93293607c5bb1b3e9c156c456791c4aabf45a7d9d55d" dependencies = [ "anyhow", - "base64 0.21.4", + "base64 0.21.7", "bincode", "build-info-common", - "cargo_metadata 0.18.0", + "cargo_metadata", "chrono", "git2", "glob", "pretty_assertions", "rustc_version", "serde_json", - "xz2", + "zstd", ] [[package]] name = "build-info-common" -version = "0.0.33" +version = "0.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3b772d111f4cc62aa9018ba5cad5a1748a6d9a286d91a69b748cd233e43cdbd" +checksum = "c212154d5082e4f891f6750a791f83731bdbf706c97f8e0c3d16c53723e4881e" dependencies = [ "chrono", "derive_more", @@ -788,12 +792,12 @@ dependencies = [ [[package]] name = "build-info-proc" -version = "0.0.33" +version = "0.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39fc1a191a93dd7d72c21007a3d65cbfd88204bc744ecccac21858812bc06988" +checksum = "9ff68aa3f555464fa21e676884d6ef00c1f97ce5b42e65ae9b49f9cacdb87ae3" dependencies = [ "anyhow", - "base64 0.21.4", + "base64 0.21.7", "bincode", "build-info-common", "chrono", @@ -803,39 +807,33 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.60", - "xz2", + "syn 2.0.61", + "zstd", ] [[package]] name = "bumpalo" -version = "3.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" - -[[package]] -name = "bytecount" -version = "0.6.7" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1e5f035d16fc623ae5f74981db80a439803888314e3a555fd6f04acd51a3205" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "bytes-utils" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e47d3a8076e283f3acd27400535992edb3ba4b5bb72f8891ad8fbe7932a7d4b9" +checksum = "7dafe3a8757b027e2be6e4e5601ed563c55989fcf1546e933c66c8eb3a058d35" dependencies = [ "bytes", "either", @@ -852,31 +850,18 @@ dependencies = [ [[package]] name = "cargo-platform" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cfa25e60aea747ec7e1124f238816749faa93759c6ff5b31f1ccdda137f4479" -dependencies = [ - "serde", -] - -[[package]] -name = "cargo_metadata" -version = "0.14.2" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" +checksum = "24b1f0365a6c6bb4020cd05806fd0d33c44d38046b8bd7f0e40814b9763cabfc" dependencies = [ - "camino", - "cargo-platform", - "semver", "serde", - "serde_json", ] [[package]] name = "cargo_metadata" -version = "0.18.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb9ac64500cc83ce4b9f8dafa78186aa008c8dea77a09b94cd307fd0cd5022a8" +checksum = "2d886547e41f740c616ae73108f6eb70afe6d940c7bc697cb30f13daec073037" dependencies = [ "camino", "cargo-platform", @@ -888,12 +873,13 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.83" +version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" dependencies = [ "jobserver", "libc", + "once_cell", ] [[package]] @@ -919,38 +905,36 @@ dependencies = [ [[package]] name = "concurrent-queue" -version = "2.3.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f057a694a54f12365049b0958a1685bb52d567f5593b355fbf685838e873d400" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" dependencies = [ "crossbeam-utils", ] [[package]] name = "const-oid" -version = "0.9.5" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" [[package]] name = "const-random" -version = "0.1.15" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368a7a772ead6ce7e1de82bfb04c485f3db8ec744f72925af5735e29a22cc18e" +checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359" dependencies = [ "const-random-macro", - "proc-macro-hack", ] [[package]] name = "const-random-macro" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d7d6ab3c3a2282db210df5f02c4dab6e0a7057af0fb7ebd4070f30fe05c0ddb" +checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" dependencies = [ - "getrandom 0.2.10", + "getrandom 0.2.15", "once_cell", - "proc-macro-hack", "tiny-keccak", ] @@ -971,9 +955,9 @@ dependencies = [ [[package]] name = "core-foundation" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" dependencies = [ "core-foundation-sys", "libc", @@ -981,93 +965,84 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.4" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "cpufeatures" -version = "0.2.9" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] [[package]] name = "crc" -version = "3.0.1" +version = "3.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" +checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" dependencies = [ "crc-catalog", ] [[package]] name = "crc-catalog" -version = "2.2.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" [[package]] name = "crc32c" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8f48d60e5b4d2c53d5c2b1d8a58c849a70ae5e5509b08a48d047e3b65714a74" +checksum = "89254598aa9b9fa608de44b3ae54c810f0f06d755e24c50177f1f8f31ff50ce2" dependencies = [ "rustc_version", ] [[package]] name = "crc32fast" -version = "1.3.2" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" dependencies = [ "cfg-if", ] [[package]] name = "crossbeam-channel" -version = "0.5.8" +version = "0.5.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95" dependencies = [ - "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-epoch" -version = "0.9.15" +version = "0.9.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" dependencies = [ - "autocfg", - "cfg-if", "crossbeam-utils", - "memoffset", - "scopeguard", ] [[package]] name = "crossbeam-queue" -version = "0.3.8" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add" +checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" dependencies = [ - "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.16" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" -dependencies = [ - "cfg-if", -] +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" [[package]] name = "crunchy" @@ -1100,9 +1075,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.1.1" +version = "4.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89b8c6a2e4b1f45971ad09761aafb85514a84744b67a95e32c3cc1352d1f65c" +checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348" dependencies = [ "cfg-if", "cpufeatures", @@ -1117,13 +1092,13 @@ dependencies = [ [[package]] name = "curve25519-dalek-derive" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -1133,17 +1108,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ "cfg-if", - "hashbrown 0.14.1", + "hashbrown 0.14.5", "lock_api", "once_cell", - "parking_lot_core 0.9.8", + "parking_lot_core 0.9.10", ] [[package]] name = "data-encoding" -version = "2.4.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" +checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" [[package]] name = "deadpool" @@ -1160,15 +1135,15 @@ dependencies = [ [[package]] name = "deadpool-runtime" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63dfa964fe2a66f3fde91fc70b267fe193d822c7e603e2a675a49a7f46ad3f49" +checksum = "092966b41edc516079bdf31ec78a2e0588d1d0c08f78b91d8307215928642b2b" [[package]] name = "der" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" dependencies = [ "const-oid", "zeroize", @@ -1176,9 +1151,12 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.8" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] [[package]] name = "derive_more" @@ -1283,16 +1261,16 @@ dependencies = [ "aws-sdk-s3", "axum", "axum-client-ip", - "base64 0.21.4", + "base64 0.21.7", "build-info", "build-info-build", "chrono", "data-encoding", "dotenv", - "ed25519-dalek 2.0.0", + "ed25519-dalek 2.1.1", "envy", + "fcm 0.10.0", "fcm 0.9.2", - "fcm 1.0.0", "futures-util", "hex", "hyper", @@ -1342,12 +1320,12 @@ dependencies = [ [[package]] name = "ed25519" -version = "2.2.2" +version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60f6d271ca33075c88028be6f04d502853d63a5ece419d269c15315d4fc1cf1d" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" dependencies = [ "pkcs8", - "signature 2.1.0", + "signature 2.2.0", ] [[package]] @@ -1365,29 +1343,30 @@ dependencies = [ [[package]] name = "ed25519-dalek" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7277392b266383ef8396db7fdeb1e77b6c52fed775f5df15bb24f35b72156980" +checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" dependencies = [ - "curve25519-dalek 4.1.1", - "ed25519 2.2.2", + "curve25519-dalek 4.1.2", + "ed25519 2.2.3", "rand_core 0.6.4", "serde", "sha2 0.10.8", + "subtle", "zeroize", ] [[package]] name = "either" -version = "1.9.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" [[package]] name = "encoding_rs" -version = "0.8.33" +version = "0.8.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" dependencies = [ "cfg-if", ] @@ -1418,48 +1397,60 @@ dependencies = [ [[package]] name = "erased-serde" -version = "0.4.1" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4adbf0983fe06bd3a5c19c8477a637c2389feb0994eca7a59e3b961054aa7c0a" +checksum = "2b73807008a3c7f171cc40312f37d95ef0396e048b5848d775f54b1a4dd4a0d3" dependencies = [ "serde", ] [[package]] name = "errno" -version = "0.3.3" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ - "errno-dragonfly", "libc", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] -name = "errno-dragonfly" -version = "0.1.2" +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "event-listener" +version = "4.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +checksum = "67b215c49b2b248c855fb73579eb1f4f26c38ffdc12973e20e07b91d78d5646e" dependencies = [ - "cc", - "libc", + "concurrent-queue", + "parking", + "pin-project-lite", ] [[package]] -name = "error-chain" -version = "0.12.4" +name = "event-listener" +version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" +checksum = "6d9944b8ca13534cdfb2800775f8dd4902ff3fc75a50101466decadfdf322a24" dependencies = [ - "version_check", + "concurrent-queue", + "parking", + "pin-project-lite", ] [[package]] -name = "event-listener" -version = "2.5.3" +name = "event-listener-strategy" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" +checksum = "958e4d70b6d5e81971bebec42271ec641e7ff4e170a6fa605f2b8a8b65cb97d3" +dependencies = [ + "event-listener 4.0.3", + "pin-project-lite", +] [[package]] name = "fastrand" @@ -1472,9 +1463,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.1" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] name = "fcm" @@ -1492,24 +1483,23 @@ dependencies = [ [[package]] name = "fcm" -version = "1.0.0" -source = "git+https://github.com/WalletConnect/fcm-rust.git?branch=feat/key-not-from-file#6e419ada5319d728a476ee8434ca9228481b41a8" +version = "0.10.0" dependencies = [ "chrono", - "dotenv", - "erased-serde 0.4.1", + "erased-serde 0.4.4", "gauth", "log", "reqwest", "serde", "serde_json", + "thiserror", ] [[package]] name = "fiat-crypto" -version = "0.2.1" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0870c84016d4b481be5c9f323c24f65e31e901ae618f0e80f4308fb00de1d2d" +checksum = "38793c55593b33412e3ae40c2c9781ffaa6f438f6f8c10f24e71846fbd7ae01e" [[package]] name = "finl_unicode" @@ -1525,9 +1515,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.27" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6c98ee8095e9d1dcbf2fcc6d95acccb90d1c81db1e44725c6a984b1dbdfb010" +checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" dependencies = [ "crc32fast", "miniz_oxide", @@ -1556,9 +1546,9 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "form_urlencoded" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" dependencies = [ "percent-encoding", ] @@ -1575,9 +1565,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" dependencies = [ "futures-channel", "futures-core", @@ -1590,9 +1580,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", "futures-sink", @@ -1600,15 +1590,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" [[package]] name = "futures-executor" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" dependencies = [ "futures-core", "futures-task", @@ -1628,9 +1618,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-lite" @@ -1649,38 +1639,38 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] name = "futures-sink" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" [[package]] name = "futures-task" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-timer" -version = "3.0.2" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" +checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" [[package]] name = "futures-util" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-channel", "futures-core", @@ -1696,15 +1686,14 @@ dependencies = [ [[package]] name = "gauth" -version = "0.8.0" -source = "git+https://github.com/WalletConnect/gauth-rs.git?branch=feat/key-not-from-file#b422162a1c07e276a7ebcd5def28f4c5ba20e1d0" +version = "0.9.0" dependencies = [ "anyhow", - "base64 0.21.4", + "base64 0.21.7", "chrono", "dirs 5.0.1", "reqwest", - "ring", + "ring 0.16.20", "serde", "serde_derive", "serde_json", @@ -1730,7 +1719,7 @@ source = "git+https://github.com/WalletConnect/utils-rs.git?tag=v0.7.0#5f636b8f7 dependencies = [ "aws-sdk-s3", "axum-client-ip", - "bitflags 2.4.0", + "bitflags 2.5.0", "bytes", "futures", "http-body", @@ -1755,9 +1744,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.10" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -1766,17 +1755,17 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "git2" -version = "0.18.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbf97ba92db08df386e10c8ede66a2a0369bd277090afd8710e19e38de9ec0cd" +checksum = "232e6a7bfe35766bf715e55a88b39a700596c0ccfd88cd3680b4cdb40d66ef70" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.5.0", "libc", "libgit2-sys", "log", @@ -1791,9 +1780,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "h2" -version = "0.3.21" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" dependencies = [ "bytes", "fnv", @@ -1801,7 +1790,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap 1.9.3", + "indexmap 2.2.6", "slab", "tokio", "tokio-util", @@ -1816,11 +1805,11 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.14.1" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ - "ahash 0.8.3", + "ahash 0.8.11", "allocator-api2", ] @@ -1830,7 +1819,7 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" dependencies = [ - "hashbrown 0.14.1", + "hashbrown 0.14.5", ] [[package]] @@ -1853,9 +1842,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.3" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "hex" @@ -1865,9 +1854,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hkdf" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" dependencies = [ "hmac", ] @@ -1883,18 +1872,18 @@ dependencies = [ [[package]] name = "home" -version = "0.5.5" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "http" -version = "0.2.9" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" dependencies = [ "bytes", "fnv", @@ -1903,9 +1892,9 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", "http", @@ -1953,9 +1942,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" -version = "0.14.27" +version = "0.14.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" dependencies = [ "bytes", "futures-channel", @@ -1968,7 +1957,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.9", + "socket2", "tokio", "tower-service", "tracing", @@ -1991,15 +1980,15 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.24.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d78e1e73ec14cf7375674f74d7dde185c8206fd9dea6fb6295e8a98098aaa97" +checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", "http", "hyper", "log", - "rustls 0.21.7", + "rustls 0.21.12", "rustls-native-certs", "tokio", "tokio-rustls 0.24.1", @@ -2032,16 +2021,16 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.57" +version = "0.1.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows", + "windows-core", ] [[package]] @@ -2055,9 +2044,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -2075,12 +2064,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.1" +version = "2.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad227c3af19d4914570ad36d30409928b75967c298feb9ea1969db3a610bb14e" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", - "hashbrown 0.14.1", + "hashbrown 0.14.5", ] [[package]] @@ -2106,9 +2095,9 @@ checksum = "8bb03732005da905c88227371639bf1ad885cc712789c011c31c5fb3ab3ccf02" [[package]] name = "ipnet" -version = "2.8.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "ipnetwork" @@ -2149,33 +2138,33 @@ dependencies = [ [[package]] name = "itertools" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" dependencies = [ "either", ] [[package]] name = "itoa" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jobserver" -version = "0.1.26" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e" dependencies = [ "libc", ] [[package]] name = "js-sys" -version = "0.3.64" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" dependencies = [ "wasm-bindgen", ] @@ -2186,9 +2175,9 @@ version = "8.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6971da4d9c3aa03c3d8f3ff0f4155b534aad021292003895a469716b2a230378" dependencies = [ - "base64 0.21.4", + "base64 0.21.7", "pem", - "ring", + "ring 0.16.20", "serde", "serde_json", "simple_asn1", @@ -2202,15 +2191,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" [[package]] name = "libgit2-sys" -version = "0.16.1+1.7.1" +version = "0.16.2+1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2a2bb3680b094add03bb3732ec520ece34da31a8cd2d633d1389d0f0fb60d0c" +checksum = "ee4126d8b4ee5c9d9ea891dd875cfdc1e9d0950437179104b183d7d8a74d24e8" dependencies = [ "cc", "libc", @@ -2218,11 +2207,21 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags 2.5.0", + "libc", +] + [[package]] name = "libz-sys" -version = "1.1.12" +version = "1.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d97137b25e321a73eef1418d1d5d2eda4d77e12813f8e6dead84bc52c5870a7b" +checksum = "5e143b5e666b2695d28f6bca6497720813f699c9602dd7f5cac91008b8ada7f9" dependencies = [ "cc", "libc", @@ -2232,15 +2231,15 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.7" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lock_api" -version = "0.4.10" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -2248,20 +2247,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "lzma-sys" -version = "0.1.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fda04ab3764e6cde78b9974eec4f779acaba7c4e84b36eca3cf77c581b85d27" -dependencies = [ - "cc", - "libc", - "pkg-config", -] +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "matchers" @@ -2302,18 +2290,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.6.3" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" - -[[package]] -name = "memoffset" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" -dependencies = [ - "autocfg", -] +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "mime" @@ -2339,9 +2318,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" dependencies = [ "adler", ] @@ -2359,21 +2338,21 @@ dependencies = [ [[package]] name = "moka" -version = "0.12.5" +version = "0.12.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1911e88d5831f748a4097a43862d129e3c6fca831eecac9b8db6d01d93c9de2" +checksum = "9e0d88686dc561d743b40de8269b26eaf0dc58781bde087b0984646602021d08" dependencies = [ "async-lock", "async-trait", "crossbeam-channel", "crossbeam-epoch", "crossbeam-utils", + "event-listener 5.3.0", "futures-util", "once_cell", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "quanta", "rustc_version", - "skeptic", "smallvec", "tagptr", "thiserror", @@ -2457,9 +2436,9 @@ dependencies = [ [[package]] name = "num" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af" +checksum = "3135b08af27d103b0a51f2ae0f8632117b7b185ccf931445affa8df530576a41" dependencies = [ "num-complex", "num-integer", @@ -2470,39 +2449,43 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" dependencies = [ - "autocfg", "num-integer", "num-traits", ] [[package]] name = "num-complex" -version = "0.4.4" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ba157ca0885411de85d6ca030ba7e2a83a28636056c7c699b07c8b6f7383214" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" -version = "0.1.45" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg", "num-traits", ] [[package]] name = "num-iter" -version = "0.1.43" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" dependencies = [ "autocfg", "num-integer", @@ -2511,20 +2494,19 @@ dependencies = [ [[package]] name = "num-rational" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" dependencies = [ - "autocfg", "num-integer", "num-traits", ] [[package]] name = "num-traits" -version = "0.2.16" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -2535,38 +2517,38 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.3", + "hermit-abi 0.3.9", "libc", ] [[package]] name = "object" -version = "0.32.1" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "opaque-debug" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "openssl" -version = "0.10.57" +version = "0.10.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" +checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.5.0", "cfg-if", "foreign-types", "libc", @@ -2583,7 +2565,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -2594,9 +2576,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.93" +version = "0.9.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d" +checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" dependencies = [ "cc", "libc", @@ -2703,9 +2685,9 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" [[package]] name = "ordered-float" -version = "2.10.0" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7940cf2ca942593318d07fcf2596cdca60a85c9e7fab408a5e21a4f9dcd40d87" +checksum = "68f19d67e5a2795c94e73e0bb1cc1a7edeb2e28efd39e2e1c9b7a40c1108b11c" dependencies = [ "num-traits", ] @@ -2741,12 +2723,12 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" dependencies = [ "lock_api", - "parking_lot_core 0.9.8", + "parking_lot_core 0.9.10", ] [[package]] @@ -2765,15 +2747,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.8" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.3.5", + "redox_syscall 0.5.1", "smallvec", - "windows-targets 0.48.5", + "windows-targets 0.52.5", ] [[package]] @@ -2781,11 +2763,11 @@ name = "parquet" version = "42.0.0" source = "git+https://github.com/WalletConnect/arrow-rs.git?rev=99a1cc3#99a1cc36bce8d55e411dd441f2219d0689a82bee" dependencies = [ - "ahash 0.8.3", + "ahash 0.8.11", "bytes", "chrono", "flate2", - "hashbrown 0.14.1", + "hashbrown 0.14.5", "num", "num-bigint", "paste", @@ -2802,14 +2784,14 @@ dependencies = [ "parquet", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] name = "paste" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "pem" @@ -2822,45 +2804,45 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "petgraph" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" +checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.0.1", + "indexmap 2.2.6", ] [[package]] name = "pin-project" -version = "1.1.3" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.3" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] name = "pin-project-lite" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" [[package]] name = "pin-utils" @@ -2880,15 +2862,15 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.27" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "platforms" -version = "3.1.2" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4503fa043bf02cee09a9582e9554b4c6403b2ef55e4612e96561d294419429f8" +checksum = "db23d408679286588f4d4644f965003d056e3dd5abcaaa938116871d7ce2fee7" [[package]] name = "pnet_base" @@ -2922,6 +2904,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2972,32 +2960,26 @@ dependencies = [ "version_check", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.20+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" - [[package]] name = "proc-macro2" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" dependencies = [ "unicode-ident", ] [[package]] name = "prometheus" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "449811d15fbdf5ceb5c1144416066429cf82316e2ec8ce0c1f6f8a02e7bbcf8c" +checksum = "3d33c28a30771f7f96db69893f78b857f7450d7e0237e9c8fc6427a81bae7ed1" dependencies = [ "cfg-if", "fnv", "lazy_static", "memchr", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "protobuf", "thiserror", ] @@ -3062,17 +3044,6 @@ version = "2.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" -[[package]] -name = "pulldown-cmark" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57206b407293d2bcd3af849ce869d52068623f19e1b5ff8e8778e3309439682b" -dependencies = [ - "bitflags 2.4.0", - "memchr", - "unicase", -] - [[package]] name = "quanta" version = "0.12.3" @@ -3156,7 +3127,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.10", + "getrandom 0.2.15", ] [[package]] @@ -3170,20 +3141,20 @@ dependencies = [ [[package]] name = "random-string" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4e63111ec5292d8af9c220f06fe3bb87991cc78b6f1f7e291d1ae6b8a60817" +checksum = "f70fd13c3024ae3f17381bb5c4d409c6dc9ea6895c08fa2147aba305bea3c4af" dependencies = [ "fastrand 1.9.0", ] [[package]] name = "raw-cpuid" -version = "11.0.1" +version = "11.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d86a7c4638d42c44551f4791a20e687dbb4c3de1f33c43dd71e355cd429def1" +checksum = "e29830cbb1290e404f24c73af91c5d8d631ce7e128691e9477556b540cd01ecd" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.5.0", ] [[package]] @@ -3197,34 +3168,43 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.3.5" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_syscall" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +dependencies = [ + "bitflags 2.5.0", +] + [[package]] name = "redox_users" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" dependencies = [ - "getrandom 0.2.10", - "redox_syscall 0.2.16", + "getrandom 0.2.15", + "libredox", "thiserror", ] [[package]] name = "regex" -version = "1.9.5" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "697061221ea1b4a94a624f67d0ae2bfe4e22b8a17b6a192afb11046542cc8c47" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.3.8", - "regex-syntax 0.7.5", + "regex-automata 0.4.6", + "regex-syntax 0.8.3", ] [[package]] @@ -3238,13 +3218,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.8" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.7.5", + "regex-syntax 0.8.3", ] [[package]] @@ -3255,9 +3235,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.7.5" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "relay_rpc" @@ -3282,11 +3262,11 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.20" +version = "0.11.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1" +checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" dependencies = [ - "base64 0.21.4", + "base64 0.21.7", "bytes", "encoding_rs", "futures-core", @@ -3305,9 +3285,12 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", + "rustls-pemfile", "serde", "serde_json", "serde_urlencoded", + "sync_wrapper", + "system-configuration", "tokio", "tokio-native-tls", "tower-service", @@ -3334,16 +3317,31 @@ dependencies = [ "libc", "once_cell", "spin 0.5.2", - "untrusted", + "untrusted 0.7.1", "web-sys", "winapi", ] +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.15", + "libc", + "spin 0.9.8", + "untrusted 0.9.0", + "windows-sys 0.52.0", +] + [[package]] name = "rustc-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustc_version" @@ -3356,15 +3354,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.14" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "747c788e9ce8e92b12cd485c49ddf90723550b654b32508f979b71a7b1ecda4f" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.5.0", "errno", "libc", "linux-raw-sys", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -3374,19 +3372,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" dependencies = [ "log", - "ring", + "ring 0.16.20", "sct", "webpki", ] [[package]] name = "rustls" -version = "0.21.7" +version = "0.21.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd8d6c9f025a446bc4d18ad9632e69aec8f287aa84499ee335599fabd20c3fd8" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", - "ring", + "ring 0.17.8", "rustls-webpki", "sct", ] @@ -3405,51 +3403,42 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "base64 0.21.4", + "base64 0.21.7", ] [[package]] name = "rustls-webpki" -version = "0.101.6" +version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c7d5dece342910d9ba34d259310cae3e0154b873b35408b787b59bce53d34fe" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ - "ring", - "untrusted", + "ring 0.17.8", + "untrusted 0.9.0", ] [[package]] name = "rustversion" -version = "1.0.14" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +checksum = "092474d1a01ea8278f69e6a358998405fae5b8b963ddaeb2b0b04a128bf1dfb0" [[package]] name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "same-file" -version = "1.0.6" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "schannel" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -3460,21 +3449,21 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "sct" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "ring", - "untrusted", + "ring 0.17.8", + "untrusted 0.9.0", ] [[package]] name = "security-framework" -version = "2.9.2" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" +checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", "core-foundation", "core-foundation-sys", "libc", @@ -3483,9 +3472,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.9.1" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" +checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" dependencies = [ "core-foundation-sys", "libc", @@ -3493,9 +3482,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.19" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad977052201c6de01a8ef2aa3378c4bd23217a056337d1d6da40468d267a4fb0" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" dependencies = [ "serde", ] @@ -3508,18 +3497,18 @@ checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4" [[package]] name = "serde" -version = "1.0.188" +version = "1.0.201" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" dependencies = [ "serde_derive", ] [[package]] name = "serde-aux" -version = "4.2.0" +version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3dfe1b7eb6f9dcf011bd6fad169cdeaae75eda0d61b1a99a3f015b41b0cae39" +checksum = "0d2e8bfba469d06512e11e3311d4d051a4a387a5b42d010404fecf3200321c95" dependencies = [ "serde", "serde_json", @@ -3527,22 +3516,22 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.201" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] name = "serde_json" -version = "1.0.107" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ - "indexmap 2.0.1", + "indexmap 2.2.6", "itoa", "ryu", "serde", @@ -3550,9 +3539,9 @@ dependencies = [ [[package]] name = "serde_path_to_error" -version = "0.1.14" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4beec8bce849d58d06238cb50db2e1c417cfeafa4c63f692b15c82b7c80f8335" +checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6" dependencies = [ "itoa", "serde", @@ -3591,7 +3580,7 @@ dependencies = [ "futures", "lazy_static", "log", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "serial_test_derive", ] @@ -3643,18 +3632,18 @@ dependencies = [ [[package]] name = "sharded-slab" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1b21f559e07218024e7e9f90f96f601825397de0e25420135f7f952453fed0b" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" dependencies = [ "lazy_static", ] [[package]] name = "signal-hook-registry" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" dependencies = [ "libc", ] @@ -3667,9 +3656,12 @@ checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" [[package]] name = "signature" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "rand_core 0.6.4", +] [[package]] name = "simple_asn1" @@ -3683,21 +3675,6 @@ dependencies = [ "time", ] -[[package]] -name = "skeptic" -version = "0.13.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16d23b015676c90a0f01c197bfdc786c20342c73a0afdda9025adb0bc42940a8" -dependencies = [ - "bytecount", - "cargo_metadata 0.14.2", - "error-chain", - "glob", - "pulldown-cmark", - "tempfile", - "walkdir", -] - [[package]] name = "slab" version = "0.4.9" @@ -3709,25 +3686,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" -version = "0.4.9" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "socket2" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", "windows-sys 0.52.0", @@ -3747,9 +3714,9 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "spki" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" dependencies = [ "base64ct", "der", @@ -3757,11 +3724,11 @@ dependencies = [ [[package]] name = "sqlformat" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b7b278788e7be4d0d29c0f39497a0eef3fba6bbc8e70d8bf7fde46edeaa9e85" +checksum = "ce81b7bd7c4493975347ef60d8c7e8b742d4694f4c49f93e0a12ea263938176c" dependencies = [ - "itertools 0.11.0", + "itertools 0.12.1", "nom", "unicode_categories", ] @@ -3782,7 +3749,7 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa8241483a83a3f33aa5fff7e7d9def398ff9990b2752b6c6112b83c6d246029" dependencies = [ - "ahash 0.7.6", + "ahash 0.7.8", "atoi", "base64 0.13.1", "bitflags 1.3.2", @@ -3794,7 +3761,7 @@ dependencies = [ "dirs 4.0.0", "dotenvy", "either", - "event-listener", + "event-listener 2.5.3", "futures-channel", "futures-core", "futures-intrusive", @@ -3895,9 +3862,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.60" +version = "2.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +checksum = "c993ed8ccba56ae856363b1845da7266a7cb78e1d146c8a32d54b45a8b831fc9" dependencies = [ "proc-macro2", "quote", @@ -3910,6 +3877,27 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "tagptr" version = "0.2.0" @@ -3924,22 +3912,21 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tempfile" -version = "3.8.0" +version = "3.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if", - "fastrand 2.0.1", - "redox_syscall 0.3.5", + "fastrand 2.1.0", "rustix", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "test-context" -version = "0.1.4" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "055831a02a4f5aa28fede67f2902014273eb8c21b958ac5ebbd59b71ef30dbc3" +checksum = "b7b6965c21232186af0092233c18030fe607cfc3960dbabb209325272458eeea" dependencies = [ "async-trait", "futures", @@ -3948,39 +3935,39 @@ dependencies = [ [[package]] name = "test-context-macros" -version = "0.1.4" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8901a55b0a7a06ebc4a674dcca925170da8e613fa3b163a1df804ed10afb154d" +checksum = "d506c7664333e246f564949bee4ed39062aa0f11918e6f5a95f553cdad65c274" dependencies = [ "quote", - "syn 1.0.109", + "syn 2.0.61", ] [[package]] name = "thiserror" -version = "1.0.58" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.58" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] name = "thread_local" -version = "1.1.7" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" dependencies = [ "cfg-if", "once_cell", @@ -3999,12 +3986,14 @@ dependencies = [ [[package]] name = "time" -version = "0.3.29" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "426f806f4089c493dcac0d24c29c01e2c38baf8e30f1b716ee37e83d200b18fe" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", + "num-conv", + "powerfmt", "serde", "time-core", "time-macros", @@ -4018,10 +4007,11 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.15" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ + "num-conv", "time-core", ] @@ -4060,10 +4050,10 @@ dependencies = [ "libc", "mio", "num_cpus", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "pin-project-lite", "signal-hook-registry", - "socket2 0.5.6", + "socket2", "tokio-macros", "windows-sys 0.48.0", ] @@ -4086,7 +4076,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] @@ -4116,15 +4106,15 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "rustls 0.21.7", + "rustls 0.21.12", "tokio", ] [[package]] name = "tokio-stream" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" dependencies = [ "futures-core", "pin-project-lite", @@ -4133,16 +4123,15 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.9" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d68074620f57a0b21594d9735eb2e98ab38b17f80d3fcb189fca266771ca60d" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" dependencies = [ "bytes", "futures-core", "futures-sink", "pin-project-lite", "tokio", - "tracing", ] [[package]] @@ -4216,7 +4205,7 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61c5bb1d698276a2443e5ecfabc1008bf15a36c12e6a7176e7bf089ea9131140" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.5.0", "bytes", "futures-core", "futures-util", @@ -4245,11 +4234,10 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.37" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "cfg-if", "log", "pin-project-lite", "tracing-attributes", @@ -4258,31 +4246,32 @@ dependencies = [ [[package]] name = "tracing-appender" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d48f71a791638519505cefafe162606f706c25592e4bde4d97600c0195312e" +checksum = "3566e8ce28cc0a3fe42519fc80e6b4c943cc4c8cef275620eb8dac2d3d4e06cf" dependencies = [ "crossbeam-channel", + "thiserror", "time", "tracing-subscriber", ] [[package]] name = "tracing-attributes" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", ] [[package]] name = "tracing-core" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", "valuable", @@ -4300,12 +4289,23 @@ dependencies = [ [[package]] name = "tracing-log" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +checksum = "f751112709b4e791d8ce53e32c4ed2d353565a795ce84da2285393f41557bdf2" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" dependencies = [ - "lazy_static", "log", + "once_cell", "tracing-core", ] @@ -4319,27 +4319,27 @@ dependencies = [ "opentelemetry", "tracing", "tracing-core", - "tracing-log", + "tracing-log 0.1.4", "tracing-subscriber", ] [[package]] name = "tracing-subscriber" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" dependencies = [ "matchers", "nu-ansi-term", "once_cell", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "regex", "sharded-slab", "smallvec", "thread_local", "tracing", "tracing-core", - "tracing-log", + "tracing-log 0.2.0", ] [[package]] @@ -4350,9 +4350,9 @@ checksum = "859eb650cfee7434994602c3a68b25d77ad9e68c8a6cd491616ef86661382eb3" [[package]] name = "try-lock" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "twox-hash" @@ -4381,9 +4381,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.13" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" @@ -4393,18 +4393,18 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" dependencies = [ "tinyvec", ] [[package]] name = "unicode-segmentation" -version = "1.10.1" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" [[package]] name = "unicode_categories" @@ -4418,11 +4418,17 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ "form_urlencoded", "idna", @@ -4438,11 +4444,11 @@ checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" [[package]] name = "uuid" -version = "1.4.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" +checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" dependencies = [ - "getrandom 0.2.10", + "getrandom 0.2.15", ] [[package]] @@ -4475,16 +4481,6 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" -[[package]] -name = "walkdir" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" -dependencies = [ - "same-file", - "winapi-util", -] - [[package]] name = "want" version = "0.3.1" @@ -4506,11 +4502,17 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + [[package]] name = "wasm-bindgen" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -4518,24 +4520,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.37" +version = "0.4.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" +checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" dependencies = [ "cfg-if", "js-sys", @@ -4545,9 +4547,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -4555,22 +4557,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.61", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "wc" @@ -4583,9 +4585,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.64" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" dependencies = [ "js-sys", "wasm-bindgen", @@ -4593,12 +4595,12 @@ dependencies = [ [[package]] name = "webpki" -version = "0.22.1" +version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0e74f82d49d545ad128049b7e88f6576df2da6b02e9ce565c6f533be576957e" +checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" dependencies = [ - "ring", - "untrusted", + "ring 0.17.8", + "untrusted 0.9.0", ] [[package]] @@ -4624,11 +4626,12 @@ dependencies = [ [[package]] name = "whoami" -version = "1.4.1" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22fc3756b8a9133049b26c7f61ab35416c130e8c09b660f5b3958b446f52cc50" +checksum = "a44ab49fad634e88f55bf8f9bb3abd2f27d7204172a112c7c9987e01c1c94ea9" dependencies = [ - "wasm-bindgen", + "redox_syscall 0.4.1", + "wasite", "web-sys", ] @@ -4648,15 +4651,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -4664,12 +4658,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] -name = "windows" -version = "0.48.0" +name = "windows-core" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.48.5", + "windows-targets 0.52.5", ] [[package]] @@ -4823,13 +4817,13 @@ dependencies = [ [[package]] name = "wiremock" -version = "0.5.21" +version = "0.5.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "079aee011e8a8e625d16df9e785de30a6b77f80a6126092d76a57375f96448da" +checksum = "13a3a53eaf34f390dd30d7b1b078287dd05df2aa2e21a589ccb80f5c7253c2e9" dependencies = [ "assert-json-diff", "async-trait", - "base64 0.21.4", + "base64 0.21.7", "deadpool", "futures", "futures-timer", @@ -4845,27 +4839,66 @@ dependencies = [ [[package]] name = "xmlparser" -version = "0.13.5" +version = "0.13.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d25c75bf9ea12c4040a97f829154768bbbce366287e2dc044af160cd79a13fd" +checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" [[package]] -name = "xz2" -version = "0.1.7" +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" + +[[package]] +name = "zerocopy" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2" +checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" dependencies = [ - "lzma-sys", + "zerocopy-derive", ] [[package]] -name = "yansi" -version = "0.5.1" +name = "zerocopy-derive" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" +checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.61", +] [[package]] name = "zeroize" -version = "1.6.0" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" + +[[package]] +name = "zstd" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" +checksum = "2d789b1514203a1120ad2429eae43a7bd32b90976a7bb8a05f7ec02fa88cc23a" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "7.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd99b45c6bc03a018c8b8a86025678c87e55526064e38f9df301989dce7ec0a" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.10+zstd.1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c253a4914af5bafc8fa8c86ee400827e83cf6ec01195ec1f1ed8441bf00d65aa" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/Cargo.toml b/Cargo.toml index 761efbef..1710d17c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ build = "build.rs" resolver = "2" [features] -full = ["functional_tests", "multitenant", "analytics", "geoblock", "cloud"] +full = ["functional_tests", "multitenant", "analytics", "geoblock", "cloud", "apns_tests", "fcm_tests", "fcmv1_tests"] # Used to enable functional tests functional_tests = [] # Multi-tenancy mode @@ -20,6 +20,9 @@ analytics = [] geoblock = [] # Enable cloud app validations cloud = [] +apns_tests = [] +fcm_tests = [] +fcmv1_tests = [] [dependencies] wc = { git = "https://github.com/WalletConnect/utils-rs.git", tag = "v0.7.0", features = ["analytics", "geoip", "geoblock"] } @@ -62,7 +65,7 @@ atty = "0.2" a2 = { git = "https://github.com/WalletConnect/a2", rev = "d0236c3", features = ["tracing", "openssl"] } fcm = "0.9" # fcm_v1 = { git = "https://github.com/rj76/fcm-rust.git", package = "fcm" } -fcm_v1 = { git = "https://github.com/WalletConnect/fcm-rust.git", package = "fcm", branch = "feat/key-not-from-file" } # TODO use above version once released +fcm_v1 = { git = "https://github.com/WalletConnect/fcm-rust.git", package = "fcm", branch = "feat/key-not-from-file", default-features = false, features = ["native-tls"] } # TODO use above version once released # Signature validation ed25519-dalek = "2.0.0-rc.2" @@ -104,3 +107,9 @@ ed25519-dalek = { version = "2.0.0-rc.2", features = ["rand_core"] } [build-dependencies] build-info-build = "0.0" + +[patch.'https://github.com/WalletConnect/fcm-rust.git'] +fcm = { path = "../fcm-rust" } + +[patch.'https://github.com/WalletConnect/gauth-rs.git'] +gauth = { path = "../gauth-rs" } diff --git a/docker-compose.storage.yml b/docker-compose.storage.yml new file mode 100644 index 00000000..e1f8570d --- /dev/null +++ b/docker-compose.storage.yml @@ -0,0 +1,16 @@ +version: '3.9' +services: + + postgres: + image: postgres + environment: + - POSTGRES_PASSWORD=root + ports: + - "5432:5432" + + postgres-tenant: + image: postgres + environment: + - POSTGRES_PASSWORD=root + ports: + - "5433:5432" diff --git a/justfile b/justfile index f4fd5f10..747df7e5 100644 --- a/justfile +++ b/justfile @@ -10,7 +10,10 @@ test: RUST_BACKTRACE=1 cargo test --all-targets -- {{test}} test-all: - RUST_BACKTRACE=1 cargo test --all-features --all-targets -- {{test}} + RUST_BACKTRACE=1 cargo test --all-targets --features=multitenant,analytics,geoblock,functional_tests,fcmv1_tests -- {{test}} + +test-all-providers: + RUST_BACKTRACE=1 cargo test --all-targets --features=multitenant,analytics,geoblock,functional_tests,apns_tests,fcm_tests,fcmv1_tests -- {{test}} clippy: #!/bin/bash diff --git a/src/error.rs b/src/error.rs index 7ce0a3f5..202b7340 100644 --- a/src/error.rs +++ b/src/error.rs @@ -38,7 +38,7 @@ pub enum Error { Fcm(#[from] fcm::FcmError), #[error(transparent)] - FcmV1(#[from] fcm_v1::Error), + FcmV1(#[from] fcm_v1::SendError), #[error("FCM Responded with an error")] FcmResponse(fcm::ErrorReason), @@ -53,7 +53,7 @@ pub enum Error { Database(#[from] sqlx::Error), #[error(transparent)] - Hex(#[from] hex::FromHexError), + Hex(hex::FromHexError), #[error(transparent)] Ed25519(#[from] ed25519_dalek::ed25519::Error), @@ -71,7 +71,10 @@ pub enum Error { DecryptedNotificationParse(serde_json::Error), #[error("Invalid ServiceServiceAccount key: {0}")] - InvalidServiceAccountKey(serde_json::Error), + FcmV1InvalidServiceAccountKey(serde_json::Error), + + #[error("Internal: Invalid ServiceServiceAccount key: {0}")] + InternalFcmV1InvalidServiceAccountKey(serde_json::Error), #[error("Failed to perform internal serialization: {0}")] InternalSerializationError(serde_json::Error), @@ -184,6 +187,9 @@ pub enum Error { #[error("Invalid FCM API key")] BadFcmApiKey, + #[error("Invalid FCM v1 credentials")] + BadFcmV1Credentials, + #[error("Invalid APNs creds")] BadApnsCredentials, @@ -254,6 +260,30 @@ impl IntoResponse for Error { location: ErrorLocation::Body, } ]), + Error::FcmV1InvalidServiceAccountKey(e) => crate::handlers::Response::new_failure(StatusCode::BAD_REQUEST, vec![ + ResponseError { + name: "fcm_v1_invalid_service_account_key".to_string(), + message: format!("The provided Service Account Key was not valid: {e}"), + } + ], vec![ + ErrorField { + field: "fcm_v1_credentials".to_string(), + description: "FCM V1 credentials".to_string(), + location: ErrorLocation::Body, + } + ]), + Error::BadFcmV1Credentials => crate::handlers::Response::new_failure(StatusCode::BAD_REQUEST, vec![ + ResponseError { + name: "bad_fcm_v1_credentials".to_string(), + message: "The provided credentials were not valid".to_string(), + } + ], vec![ + ErrorField { + field: "fcm_v1_credentials".to_string(), + description: "FCM V1 credentials".to_string(), + location: ErrorLocation::Body, + } + ]), Error::Database(e) => crate::handlers::Response::new_failure(StatusCode::INTERNAL_SERVER_ERROR, vec![ ResponseError { name: "sqlx".to_string(), diff --git a/src/handlers/register_client.rs b/src/handlers/register_client.rs index 67ac743d..9b826e91 100644 --- a/src/handlers/register_client.rs +++ b/src/handlers/register_client.rs @@ -78,9 +78,9 @@ pub async fn handler( return Err(EmptyField("token".to_string())); } - let mut client_id = body.client_id.to_string(); - - client_id = client_id + let client_id = body + .client_id + .as_ref() .trim_start_matches(DECENTRALIZED_IDENTIFIER_PREFIX) .to_owned(); diff --git a/src/handlers/update_fcm_v1.rs b/src/handlers/update_fcm_v1.rs index 3b769280..55ad9c69 100644 --- a/src/handlers/update_fcm_v1.rs +++ b/src/handlers/update_fcm_v1.rs @@ -13,7 +13,7 @@ use { }, serde::Serialize, std::sync::Arc, - tracing::{error, instrument}, + tracing::{error, instrument, debug}, }; pub struct FcmV1UpdateBody { @@ -73,24 +73,14 @@ pub async fn handler( } // Client will validate the key on startup - let _fcm = fcm_v1::Client::from_key( - serde_json::from_str(&body.credentials).map_err(Error::InvalidServiceAccountKey)?, - ); - - // ---- checks - // TODO - // let fcm_credentials = body.credentials.clone(); - // let mut test_message_builder = fcm_v1::Message::new(&fcm_credentials, "wc-notification-test"); - // test_message_builder.dry_run(true); - // let test_message = test_message_builder.finalize(); - // let test_notification = fcm::Client::new().send(test_message).await; - // match test_notification { - // Err(e) => match e { - // FcmError::Unauthorized => Err(BadFcmApiKey), - // _ => Ok(()), - // }, - // Ok(_) => Ok(()), - // }?; + fcm_v1::Client::from_key( + serde_json::from_str(&body.credentials).map_err(Error::FcmV1InvalidServiceAccountKey)?, + ) + .await + .map_err(|e| { + debug!("Failed credential validation: {e}"); + Error::BadFcmV1Credentials + })?; // ---- handler let update_body = TenantFcmV1UpdateParams { diff --git a/src/middleware/validate_signature.rs b/src/middleware/validate_signature.rs index 286e91e5..a0c46655 100644 --- a/src/middleware/validate_signature.rs +++ b/src/middleware/validate_signature.rs @@ -84,7 +84,7 @@ pub async fn signature_is_valid( ) -> Result { let sig_body = format!("{}.{}.{}", timestamp, body.len(), body); - let sig_bytes = hex::decode(signature)?; + let sig_bytes = hex::decode(signature).map_err(crate::error::Error::Hex)?; let sig = Signature::try_from(sig_bytes.as_slice())?; Ok(public_key.verify_strict(sig_body.as_bytes(), &sig).is_ok()) diff --git a/src/providers/fcm.rs b/src/providers/fcm.rs index e037d794..2512c723 100644 --- a/src/providers/fcm.rs +++ b/src/providers/fcm.rs @@ -111,7 +111,7 @@ impl Clone for FcmProvider { } fn clone_from(&mut self, source: &Self) { - self.api_key = source.api_key.clone(); + self.api_key.clone_from(&source.api_key); self.client = fcm::Client::new(); } } diff --git a/src/providers/fcm_v1.rs b/src/providers/fcm_v1.rs index e3145fcb..ad6f1b44 100644 --- a/src/providers/fcm_v1.rs +++ b/src/providers/fcm_v1.rs @@ -4,7 +4,7 @@ use { async_trait::async_trait, fcm_v1::{ gauth::serv_account::ServiceAccountKey, AndroidConfig, AndroidMessagePriority, - AndroidNotification, Client, Error as FcmError, ErrorReason, Message, Notification, + AndroidNotification, Client, ClientBuildError, ErrorReason, Message, Notification, Response, Target, WebpushConfig, }, tracing::{debug, instrument}, @@ -16,12 +16,15 @@ pub struct FcmV1Provider { } impl FcmV1Provider { - pub fn new(credentials: ServiceAccountKey, http_client: reqwest::Client) -> Self { - Self { - client: Client::builder() - .http_client(http_client) - .build(credentials), - } + pub async fn new( + credentials: ServiceAccountKey, + http_client: reqwest::Client, + ) -> Result { + let client = Client::builder() + .http_client(http_client) + .build(credentials) + .await?; + Ok(Self { client }) } } @@ -166,6 +169,7 @@ impl PushProvider for FcmV1Provider { } }; + #[allow(clippy::match_single_binding)] match result { Ok(val) => { let Response { error, .. } = val; @@ -188,7 +192,7 @@ impl PushProvider for FcmV1Provider { } } Err(e) => match e { - FcmError::Unauthorized => Err(Error::BadFcmApiKey), + // SendError::Unauthorized => Err(Error::BadFcmV1Credentials), e => Err(Error::FcmV1(e)), }, } diff --git a/src/relay/mod.rs b/src/relay/mod.rs index 9da31482..095e230d 100644 --- a/src/relay/mod.rs +++ b/src/relay/mod.rs @@ -18,7 +18,7 @@ impl RelayClient { } fn string_to_verifying_key(string_key: &str) -> crate::error::Result { - let key_bytes = hex::decode(string_key)?; + let key_bytes = hex::decode(string_key).map_err(crate::error::Error::Hex)?; Ok(VerifyingKey::from_bytes( <&[u8; 32]>::try_from(key_bytes.as_slice()).unwrap(), )?) diff --git a/src/stores/tenant.rs b/src/stores/tenant.rs index 03b2b396..166b563c 100644 --- a/src/stores/tenant.rs +++ b/src/stores/tenant.rs @@ -256,11 +256,20 @@ impl Tenant { if let Some(provider) = provider_cache.get(&fcm_v1_credentials).await { return Ok(provider); } - let fcm = FcmV1(FcmV1Provider::new( - serde_json::from_str(&fcm_v1_credentials) - .map_err(Error::InvalidServiceAccountKey)?, - http_client, - )); + #[allow(clippy::match_single_binding)] + let fcm = FcmV1( + FcmV1Provider::new( + serde_json::from_str(&fcm_v1_credentials) + .map_err(Error::InternalFcmV1InvalidServiceAccountKey)?, + http_client, + ) + .await + .map_err(|e| match e { + // TODO check specific error + // ServiceAccountError::Unauthorized => Error::BadFcmV1Credentials, + _ => Error::BadFcmV1Credentials, + })?, + ); provider_cache .insert(fcm_v1_credentials.clone(), fcm.clone()) .await; diff --git a/tests/context/mod.rs b/tests/context/mod.rs index 9f155d32..269538f9 100644 --- a/tests/context/mod.rs +++ b/tests/context/mod.rs @@ -41,7 +41,10 @@ impl TestContext for ConfigContext { log_level_otel: "info,echo-server=trace".into(), disable_header: true, validate_signatures: false, - relay_public_key: env::var("RELAY_PUBLIC_KEY").unwrap_or("none".to_string()), + // TODO setting this to avoid hex parsing errors; I don't think it's used + relay_public_key: env::var("RELAY_PUBLIC_KEY").unwrap_or( + "ff469faa970df23c23a6542765ce8dba2a907538522833b2327a153e365d138e".to_string(), + ), database_url: env::var("DATABASE_URL") .expect("DATABASE_URL environment variable is not set"), tenant_database_url: env::var("TENANT_DATABASE_URL") diff --git a/tests/functional/multitenant/apns.rs b/tests/functional/multitenant/apns.rs index 484bb8eb..215a55b5 100644 --- a/tests/functional/multitenant/apns.rs +++ b/tests/functional/multitenant/apns.rs @@ -1,23 +1,20 @@ use { - crate::{context::EchoServerContext, functional::multitenant::ClaimsForValidation}, + crate::{context::EchoServerContext, functional::multitenant::generate_random_tenant_id}, echo_server::handlers::create_tenant::TenantRegisterBody, - jsonwebtoken::{encode, EncodingKey, Header}, - random_string::generate, - std::{env, time::SystemTime}, + std::env, test_context::test_context, - uuid::Uuid, }; #[test_context(EchoServerContext)] #[tokio::test] async fn tenant_update_apns_valid_token(ctx: &mut EchoServerContext) { - let (tenant_id, jwt_token) = generate_random_tenant_id(); + let (tenant_id, jwt_token) = generate_random_tenant_id(&ctx.config.jwt_secret); // Register new tenant let client = reqwest::Client::new(); let create_tenant_result = client .post(format!("http://{}/tenants", ctx.server.public_addr)) - .bearer_auth(jwt_token) + .bearer_auth(&jwt_token) .json(&TenantRegisterBody { id: tenant_id.clone(), }) @@ -45,9 +42,9 @@ async fn tenant_update_apns_valid_token(ctx: &mut EchoServerContext) { let apns_update_result = client .post(format!( "http://{}/tenants/{}/apns", - ctx.server.public_addr, &tenant_id + ctx.server.public_addr, tenant_id )) - .bearer_auth(jwt_token) + .bearer_auth(&jwt_token) .multipart(form) .send() .await @@ -58,13 +55,13 @@ async fn tenant_update_apns_valid_token(ctx: &mut EchoServerContext) { #[test_context(EchoServerContext)] #[tokio::test] async fn tenant_update_apns_bad_token(ctx: &mut EchoServerContext) { - let (tenant_id, jwt_token) = generate_random_tenant_id(); + let (tenant_id, jwt_token) = generate_random_tenant_id(&ctx.config.jwt_secret); // Register tenant let client = reqwest::Client::new(); client .post(format!("http://{}/tenants", ctx.server.public_addr)) - .bearer_auth(jwt_token) + .bearer_auth(&jwt_token) .json(&TenantRegisterBody { id: tenant_id.clone(), }) @@ -83,7 +80,7 @@ async fn tenant_update_apns_bad_token(ctx: &mut EchoServerContext) { "http://{}/tenants/{}/apns", ctx.server.public_addr, tenant_id )) - .bearer_auth(jwt_token) + .bearer_auth(&jwt_token) .multipart(form) .send() .await @@ -95,13 +92,13 @@ async fn tenant_update_apns_bad_token(ctx: &mut EchoServerContext) { #[test_context(EchoServerContext)] #[tokio::test] async fn tenant_update_apns_bad_certificate(ctx: &mut EchoServerContext) { - let (tenant_id, jwt_token) = generate_random_tenant_id(); + let (tenant_id, jwt_token) = generate_random_tenant_id(&ctx.config.jwt_secret); // Register tenant let client = reqwest::Client::new(); client .post(format!("http://{}/tenants", ctx.server.public_addr)) - .bearer_auth(jwt_token) + .bearer_auth(&jwt_token) .json(&TenantRegisterBody { id: tenant_id.clone(), }) @@ -117,9 +114,9 @@ async fn tenant_update_apns_bad_certificate(ctx: &mut EchoServerContext) { let response = client .post(format!( "http://{}/tenants/{}/apns", - ctx.server.public_addr, &random_tenant_id + ctx.server.public_addr, tenant_id )) - .bearer_auth(jwt_token) + .bearer_auth(&jwt_token) .multipart(form) .send() .await diff --git a/tests/functional/multitenant/fcm.rs b/tests/functional/multitenant/fcm.rs index 2dd36ebe..63485bdb 100644 --- a/tests/functional/multitenant/fcm.rs +++ b/tests/functional/multitenant/fcm.rs @@ -1,22 +1,20 @@ use { - crate::{context::EchoServerContext, functional::multitenant::ClaimsForValidation}, + crate::{context::EchoServerContext, functional::multitenant::generate_random_tenant_id}, echo_server::handlers::create_tenant::TenantRegisterBody, - jsonwebtoken::{encode, EncodingKey, Header}, - random_string::generate, - std::{env, time::SystemTime}, + std::env, test_context::test_context, }; #[test_context(EchoServerContext)] #[tokio::test] async fn tenant_update_fcm_valid(ctx: &mut EchoServerContext) { - let (tenant_id, jwt_token) = generate_random_tenant_id(); + let (tenant_id, jwt_token) = generate_random_tenant_id(&ctx.config.jwt_secret); // Register tenant let client = reqwest::Client::new(); let register_response = client .post(format!("http://{}/tenants", ctx.server.public_addr)) - .bearer_auth(jwt_token) + .bearer_auth(&jwt_token) .json(&TenantRegisterBody { id: tenant_id.clone(), }) @@ -32,9 +30,9 @@ async fn tenant_update_fcm_valid(ctx: &mut EchoServerContext) { let response_fcm_update = client .post(format!( "http://{}/tenants/{}/fcm", - ctx.server.public_addr, &random_tenant_id + ctx.server.public_addr, tenant_id )) - .bearer_auth(jwt_token) + .bearer_auth(&jwt_token) .multipart(form) .send() .await @@ -45,13 +43,13 @@ async fn tenant_update_fcm_valid(ctx: &mut EchoServerContext) { #[test_context(EchoServerContext)] #[tokio::test] async fn tenant_update_fcm_bad(ctx: &mut EchoServerContext) { - let (tenant_id, jwt_token) = generate_random_tenant_id(); + let (tenant_id, jwt_token) = generate_random_tenant_id(&ctx.config.jwt_secret); // Register tenant let client = reqwest::Client::new(); client .post(format!("http://{}/tenants", ctx.server.public_addr)) - .bearer_auth(jwt_token) + .bearer_auth(&jwt_token) .json(&TenantRegisterBody { id: tenant_id.clone(), }) @@ -65,9 +63,9 @@ async fn tenant_update_fcm_bad(ctx: &mut EchoServerContext) { let response = client .post(format!( "http://{}/tenants/{}/fcm", - ctx.server.public_addr, &random_tenant_id + ctx.server.public_addr, tenant_id )) - .bearer_auth(jwt_token) + .bearer_auth(&jwt_token) .multipart(form) .send() .await diff --git a/tests/functional/multitenant/fcm_v1.rs b/tests/functional/multitenant/fcm_v1.rs index 62fdfeb5..f9b316f5 100644 --- a/tests/functional/multitenant/fcm_v1.rs +++ b/tests/functional/multitenant/fcm_v1.rs @@ -1,22 +1,20 @@ use { - crate::{context::EchoServerContext, functional::multitenant::ClaimsForValidation}, + crate::{context::EchoServerContext, functional::multitenant::generate_random_tenant_id}, echo_server::handlers::create_tenant::TenantRegisterBody, - jsonwebtoken::{encode, EncodingKey, Header}, - random_string::generate, - std::{env, time::SystemTime}, + std::env, test_context::test_context, }; #[test_context(EchoServerContext)] #[tokio::test] async fn tenant_update_fcm_v1_valid(ctx: &mut EchoServerContext) { - let (tenant_id, jwt_token) = generate_random_tenant_id(); + let (tenant_id, jwt_token) = generate_random_tenant_id(&ctx.config.jwt_secret); // Register tenant let client = reqwest::Client::new(); let register_response = client .post(format!("http://{}/tenants", ctx.server.public_addr)) - .bearer_auth(jwt_token) + .bearer_auth(&jwt_token) .json(&TenantRegisterBody { id: tenant_id.clone(), }) @@ -34,7 +32,7 @@ async fn tenant_update_fcm_v1_valid(ctx: &mut EchoServerContext) { "http://{}/tenants/{}/fcm_v1", ctx.server.public_addr, tenant_id )) - .bearer_auth(jwt_token) + .bearer_auth(&jwt_token) .multipart(form) .send() .await @@ -44,14 +42,14 @@ async fn tenant_update_fcm_v1_valid(ctx: &mut EchoServerContext) { #[test_context(EchoServerContext)] #[tokio::test] -async fn tenant_update_fcm_v1_bad(ctx: &mut EchoServerContext) { - let (tenant_id, jwt_token) = generate_random_tenant_id(); +async fn tenant_update_fcm_v1_wrong_format(ctx: &mut EchoServerContext) { + let (tenant_id, jwt_token) = generate_random_tenant_id(&ctx.config.jwt_secret); // Register tenant let client = reqwest::Client::new(); client .post(format!("http://{}/tenants", ctx.server.public_addr)) - .bearer_auth(jwt_token) + .bearer_auth(&jwt_token) .json(&TenantRegisterBody { id: tenant_id.clone(), }) @@ -65,9 +63,58 @@ async fn tenant_update_fcm_v1_bad(ctx: &mut EchoServerContext) { let response = client .post(format!( "http://{}/tenants/{}/fcm_v1", - ctx.server.public_addr, &tenant_id + ctx.server.public_addr, tenant_id + )) + .bearer_auth(&jwt_token) + .multipart(form) + .send() + .await + .expect("Call failed"); + + assert!(!response.status().is_success(), "Response was successful"); +} + +#[test_context(EchoServerContext)] +#[tokio::test] +async fn tenant_update_fcm_v1_invalidated(ctx: &mut EchoServerContext) { + let (tenant_id, jwt_token) = generate_random_tenant_id(&ctx.config.jwt_secret); + + // Register tenant + let client = reqwest::Client::new(); + client + .post(format!("http://{}/tenants", ctx.server.public_addr)) + .bearer_auth(&jwt_token) + .json(&TenantRegisterBody { + id: tenant_id.clone(), + }) + .send() + .await + .expect("Call failed"); + + // Revoked key + let credentials = r#" + { + "type": "service_account", + "project_id": "push-server-tests-cc0f7", + "private_key_id": "2a2d7c139c2d426be391d9003f2687a8f6f1fff2", + "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCeTJvksCrIC3pY\nOqHkIn2L5ZX11GO50pBE65U3Ik99Eh01puRPXitgdJZZIgcJEvSkDwcpq7ieuxe1\nSc35Le+STr8YM62Clp7KBIaTW4yiLxIN0PuLCgMBnTHKrcxwzCTOCog9rlYdGOj8\nnLd69FA9GUPiYvT+HToKRonm1N3kcAVLeUBj6z48qf4PxHAu0dpuGTfMcUUZfPZc\no6BXGrf2+eMTz0j7W6MCnpK1uVQu3rxjrvW2POgdHu31OvH9IAr8+CPuI3CTn/NF\n//uJOSYJmwysGyB/Fa6UqmCjd9u9VXLxOuIMOHXt54OegCuwb8/Y0GNZK4RBc4TS\nmAFramKvAgMBAAECggEAAupu5c8sUWpm/jdT+TJYS/FfgOSKCbVVLvRf6c6jH5yi\nqRl5AWL1zZQqdoAez1ce5nWPQsmE8neIUkLPwd05UCqWAxKuUqG9UUz9wQP0GueD\nn54Y9lCpwF63b8kiB75tKWiw03RPeAkqSFF08yevvPTwLbwumenvVJrWTJFOnQEa\noC4HCPXKNck2LDgnrfSynjYxhrICfXKwZ1Uhl8YYP5iSRf242nGjTyh2FwCM5nqx\nHbk3q/9RCb1VJoDBuSN7AcGm1mipqeJz5fTIGxAXcV0CJrkw3Betl0FYddj5Mc9I\n+koZf2HZbNkB4gF0SqnAakp3hNNqUOiFJPhavC4RoQKBgQDdbgmdUk+NyH57RDgx\nOSchoWgPVYLnQ9ZyDxXnxhzxdMPIDhKcCQpMEo7NR3SyzxcJNibDu3PeeAE5cw1L\n3nd2rFAdPUtSEnVgGxVN0hqAKWKfkCLtwOVznuilQVd1Px+4WJPJmsjQNWWWoGWE\nDcNEyg1lAhD4kiPHLrMPVea5CQKBgQC3A2jlY5h43CWU6Vmc2nEZQCEBYE7CShmc\np/6WvvxwDJxZ+qZR5xCPDwMV1Buw6N1LuGXoSOu4C9yP4qj3NrNVdiTmn/wI4OBl\nZQ/O5FcDHvVVO37cXrP2mKvMKBQfIbSu7oZrzlctyHj8KwWghXWpKai8sAk3dEyz\nNJKK9vzD9wKBgBnLAY+z0NSBMEqHjcweDjLarFZs7Yym2En8+949s41kvpGFIiHO\n48YsuzmqQyu498P47NcL9NlLPUlF35yg02WdeM+PHkD3KXkCbp7cBH49U+GmVos/\nVvr63bqyO8/KhJVirARl5VJrhePf1zNkrwRKTPkhHnz1+PjwtabpqLCRAoGANUL/\nxyqaGCpxoYnb86M7IQ8hy+W8ZhzsoUPe+v4wN2fkJOemedWWYxwKWNL3ECBlLwFG\nXzjBqTmCgjmD1RaNUITmrlvHHMpdZATqedrIW/cpjRmYjQfethiufub3HCxSCksO\nwdc2VfOvCix3IcVVfdrK6ccNl574J3tYXqsM2vcCgYBQKIHoaMfig1C7K6GVj04t\n7L5+hGoGkV3tbarWlN2f3fy+E8N8jNF0zcyy3DNy+nte8L525wV40rv0iUY7UUOD\nEYtL9cKJiAMVHBrmcxYYSKamDokUNYdbL6G/BiyAutDu5dvG/coVhY2DtlpUBuc6\nEZ5GAEY7kywLFZNd54/I2w==\n-----END PRIVATE KEY-----\n", + "client_email": "firebase-adminsdk-eyh3f@push-server-tests-cc0f7.iam.gserviceaccount.com", + "client_id": "102142178126793688289", + "auth_uri": "https://accounts.google.com/o/oauth2/auth", + "token_uri": "https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-eyh3f%40push-server-tests-cc0f7.iam.gserviceaccount.com", + "universe_domain": "googleapis.com" + } + "#; + let form = reqwest::multipart::Form::new().text("credentials", credentials); + + let response = client + .post(format!( + "http://{}/tenants/{}/fcm_v1", + ctx.server.public_addr, tenant_id )) - .bearer_auth(jwt_token) + .bearer_auth(&jwt_token) .multipart(form) .send() .await diff --git a/tests/functional/multitenant/mod.rs b/tests/functional/multitenant/mod.rs index e2fa2aae..aec2ffa6 100644 --- a/tests/functional/multitenant/mod.rs +++ b/tests/functional/multitenant/mod.rs @@ -1,8 +1,17 @@ -/// Tests against the handlers -use {crate::context::EchoServerContext, serde::Serialize, test_context::test_context}; +use { + crate::context::EchoServerContext, + jsonwebtoken::{encode, EncodingKey, Header}, + random_string::generate, + serde::Serialize, + std::time::SystemTime, + test_context::test_context, +}; +#[cfg(feature = "apns_tests")] mod apns; +#[cfg(feature = "fcm_tests")] mod fcm; +#[cfg(feature = "fcmv1_tests")] mod fcm_v1; mod tenancy; @@ -23,22 +32,22 @@ async fn test_health(ctx: &mut EchoServerContext) { assert!(body.is_success()); } -pub fn generate_random_tenant_id() -> (String, String) { +pub fn generate_random_tenant_id(jwt_secret: &str) -> (String, String) { let charset = "1234567890"; - let random_tenant_id = generate(12, charset); + let tenant_id = generate(12, charset); let unix_timestamp = SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .unwrap() .as_secs() as usize; let token_claims = ClaimsForValidation { - sub: random_tenant_id.clone(), + sub: tenant_id.clone(), exp: unix_timestamp + 60 * 60, // Add an hour for expiration }; let jwt_token = encode( &Header::default(), &token_claims, - &EncodingKey::from_secret(ctx.config.jwt_secret.as_bytes()), + &EncodingKey::from_secret(jwt_secret.as_bytes()), ) .expect("Failed to encode jwt token"); - (random_tenant_id, jwt_token) + (tenant_id, jwt_token) } diff --git a/tests/functional/multitenant/tenancy.rs b/tests/functional/multitenant/tenancy.rs index e5bf7abf..614fbb91 100644 --- a/tests/functional/multitenant/tenancy.rs +++ b/tests/functional/multitenant/tenancy.rs @@ -1,41 +1,22 @@ use { - crate::{context::EchoServerContext, functional::multitenant::ClaimsForValidation}, + crate::{context::EchoServerContext, functional::multitenant::generate_random_tenant_id}, echo_server::handlers::create_tenant::TenantRegisterBody, - jsonwebtoken::{encode, EncodingKey, Header}, - random_string::generate, - std::time::SystemTime, test_context::test_context, }; #[test_context(EchoServerContext)] #[tokio::test] async fn tenant_register_get_delete(ctx: &mut EchoServerContext) { - let charset = "1234567890"; - let random_tenant_id = generate(12, charset); - let payload = TenantRegisterBody { - id: random_tenant_id.clone(), - }; - let unix_timestamp = SystemTime::now() - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap() - .as_secs() as usize; - let token_claims = ClaimsForValidation { - sub: random_tenant_id.clone(), - exp: unix_timestamp + 60 * 60, // Add an hour for expiration - }; - let jwt_token = encode( - &Header::default(), - &token_claims, - &EncodingKey::from_secret(ctx.config.jwt_secret.as_bytes()), - ) - .expect("Failed to encode jwt token"); + let (tenant_id, jwt_token) = generate_random_tenant_id(&ctx.config.jwt_secret); // Register tenant let client = reqwest::Client::new(); let response = client .post(format!("http://{}/tenants", ctx.server.public_addr)) - .json(&payload) - .header("AUTHORIZATION", jwt_token.clone()) + .bearer_auth(&jwt_token) + .json(&TenantRegisterBody { + id: tenant_id.clone(), + }) .send() .await .expect("Call failed"); @@ -45,10 +26,9 @@ async fn tenant_register_get_delete(ctx: &mut EchoServerContext) { let response = client .get(format!( "http://{}/tenants/{}", - ctx.server.public_addr, - random_tenant_id.clone() + ctx.server.public_addr, tenant_id )) - .header("AUTHORIZATION", jwt_token.clone()) + .bearer_auth(&jwt_token) .send() .await .expect("Call failed"); @@ -68,10 +48,9 @@ async fn tenant_register_get_delete(ctx: &mut EchoServerContext) { let response = client .delete(format!( "http://{}/tenants/{}", - ctx.server.public_addr, - random_tenant_id.clone() + ctx.server.public_addr, tenant_id )) - .header("AUTHORIZATION", jwt_token.clone()) + .bearer_auth(&jwt_token) .send() .await .expect("Call failed"); @@ -81,10 +60,9 @@ async fn tenant_register_get_delete(ctx: &mut EchoServerContext) { let response = client .get(format!( "http://{}/tenants/{}", - ctx.server.public_addr, - random_tenant_id.clone() + ctx.server.public_addr, tenant_id )) - .header("AUTHORIZATION", jwt_token.clone()) + .bearer_auth(&jwt_token) .send() .await .expect("Call failed"); From 3f7a8c5e925d4d9fea43becffc125de94cf3ce10 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 13 May 2024 11:19:08 -0400 Subject: [PATCH 18/24] chore: remove patches --- Cargo.lock | 2 ++ Cargo.toml | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index db93161b..4b6ee290 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1484,6 +1484,7 @@ dependencies = [ [[package]] name = "fcm" version = "0.10.0" +source = "git+https://github.com/WalletConnect/fcm-rust.git?branch=feat/key-not-from-file#8bc9c381a5d72a0c43f13e676283f14f8def83c8" dependencies = [ "chrono", "erased-serde 0.4.4", @@ -1687,6 +1688,7 @@ dependencies = [ [[package]] name = "gauth" version = "0.9.0" +source = "git+https://github.com/WalletConnect/gauth-rs.git?branch=feat/key-not-from-file#10c114c4e01318a1f2d3ca969a677e8d59b9b6ae" dependencies = [ "anyhow", "base64 0.21.7", diff --git a/Cargo.toml b/Cargo.toml index 1710d17c..c0afb2b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -108,8 +108,8 @@ ed25519-dalek = { version = "2.0.0-rc.2", features = ["rand_core"] } [build-dependencies] build-info-build = "0.0" -[patch.'https://github.com/WalletConnect/fcm-rust.git'] -fcm = { path = "../fcm-rust" } +# [patch.'https://github.com/WalletConnect/fcm-rust.git'] +# fcm = { path = "../fcm-rust" } -[patch.'https://github.com/WalletConnect/gauth-rs.git'] -gauth = { path = "../gauth-rs" } +# [patch.'https://github.com/WalletConnect/gauth-rs.git'] +# gauth = { path = "../gauth-rs" } From c717e970401d380f84c17c4b27e4438809cc3280 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 13 May 2024 13:02:38 -0400 Subject: [PATCH 19/24] fix: fmt --- src/handlers/update_fcm_v1.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers/update_fcm_v1.rs b/src/handlers/update_fcm_v1.rs index 55ad9c69..27c3eccf 100644 --- a/src/handlers/update_fcm_v1.rs +++ b/src/handlers/update_fcm_v1.rs @@ -13,7 +13,7 @@ use { }, serde::Serialize, std::sync::Arc, - tracing::{error, instrument, debug}, + tracing::{debug, error, instrument}, }; pub struct FcmV1UpdateBody { From 6a20d9d5e7b6c640cac15b34b6b631cd5e5e26ff Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 14 May 2024 11:12:16 -0400 Subject: [PATCH 20/24] fix: FCM v1 enabled_providers test --- Cargo.toml | 1 + README.md | 20 ++++----- justfile | 4 +- src/handlers/get_tenant.rs | 19 +++++---- src/providers/mod.rs | 2 + tests/functional/multitenant/fcm_v1.rs | 57 +++++++++++++++++++++++++- 6 files changed, 79 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 65dcdbf0..c8aa7ab5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ build = "build.rs" resolver = "2" [features] +# default = ["full"] full = ["functional_tests", "multitenant", "analytics", "geoblock", "cloud", "apns_tests", "fcm_tests", "fcmv1_tests"] # Used to enable functional tests functional_tests = [] diff --git a/README.md b/README.md index 30afdfdc..fbe6d04e 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,10 @@ -# Echo Server -Push server for the WalletConnect v2 Protocol - -> **Note** This is only available for WalletConnect v2 and is a breaking change from the Push supported in v1. +# Push Server +Push server for the WalletConnect V2 Protocol ## Notification Providers This list contains both supported and potentially planned providers - [x] FCM (API Key) -- [ ] FCM (Google Services) +- [x] FCM V1 (Google Service Accounts) - [x] APNS (Certificate Based) - [x] APNS (Token Based) - [ ] Web Push @@ -30,7 +28,7 @@ You also have to register the device with the instance of Echo Server once when generated. By sending a POST request to `/clients` as per the [spec](./spec/spec.md). ## Multi-tenancy -Echo Server supports multi-tenancy. To enable multi-tenancy you need to specify a `TENANT_DATABASE_URL` which will then disable +Echo Server supports multi-tenancy. To enable multi-tenancy you need to specify a `TENANT_DATABASE_URL` which will then disable the single-tenant endpoints in favour of endpoints with a `/:tenant_id` prefix e.g. `/:tenant_id/client/:id` > **Warning** @@ -39,12 +37,8 @@ the single-tenant endpoints in favour of endpoints with a `/:tenant_id` prefix e ## Running locally ``` -# Run a postgres db for functional tests -# This will be removed in future revisions -# such that you can run functional tests without -# any prerequisites -docker run -p 5432:5432 --name some-postgres2 -e POSTGRES_HOST_AUTH_METHOD=trust -d postgres -cargo test +docker compose -f docker-compose.storage.yml up -d +just test-all ``` ## Running tests locally @@ -71,7 +65,7 @@ If you wish to integrate Push functionality into your Wallet (only available on ## Contributing To get started with contributing to Echo Server, look at the [open issues](https://github.com/WalletConnect/echo-server/issues?q=is:issue+is:open+label:%22help+wanted%22). -New contributors can also look at the [issues labeled with "good first issue"](https://github.com/WalletConnect/echo-server/issues?q=is:issue+is:open+label:%22good+first+issue%22) +New contributors can also look at the [issues labeled with "good first issue"](https://github.com/WalletConnect/echo-server/issues?q=is:issue+is:open+label:%22good+first+issue%22) as they should be suitable to people who are looking at the project for the first time. ## License diff --git a/justfile b/justfile index 975e589c..caa1ad82 100644 --- a/justfile +++ b/justfile @@ -1,3 +1,5 @@ +set dotenv-load + lint: clippy fmt unit: lint test test-all test-single-tenant lint-tf @@ -10,7 +12,7 @@ test: RUST_BACKTRACE=1 cargo test --all-targets -- {{test}} test-all: - RUST_BACKTRACE=1 cargo test --all-targets --features=multitenant,analytics,geoblock,functional_tests,fcmv1_tests -- {{test}} + RUST_BACKTRACE=1 cargo test --all-targets --features=multitenant,analytics,geoblock,functional_tests -- {{test}} test-all-providers: RUST_BACKTRACE=1 cargo test --all-targets --features=multitenant,analytics,geoblock,functional_tests,apns_tests,fcm_tests,fcmv1_tests -- {{test}} diff --git a/src/handlers/get_tenant.rs b/src/handlers/get_tenant.rs index 1a145af8..ef010ade 100644 --- a/src/handlers/get_tenant.rs +++ b/src/handlers/get_tenant.rs @@ -1,6 +1,6 @@ use { crate::{ - error::Error, handlers::validate_tenant_request, log::prelude::*, providers::ProviderKind, + error::Error, handlers::validate_tenant_request, log::prelude::*, providers::{ProviderKind, PROVIDER_FCM_V1}, state::AppState, stores::tenant::ApnsType, }, axum::{ @@ -13,14 +13,14 @@ use { tracing::instrument, }; -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] pub struct GetTenantResponse { - url: String, - enabled_providers: Vec, - apns_topic: Option, - apns_type: Option, - suspended: bool, - suspended_reason: Option, + pub url: String, + pub enabled_providers: Vec, + pub apns_topic: Option, + pub apns_type: Option, + pub suspended: bool, + pub suspended_reason: Option, } #[instrument(skip_all, name = "get_tenant_handler")] @@ -55,8 +55,9 @@ pub async fn handler( .providers() .iter() .map(Into::into) + // Special case on fcm_v1 for credentials because providers() is also used for token management (of which FCM and FCM V1 tokens are the same) .chain(if tenant.fcm_v1_credentials.is_some() { - vec!["fcm_v1".to_string()] + vec![PROVIDER_FCM_V1.to_string()] } else { vec![] }) diff --git a/src/providers/mod.rs b/src/providers/mod.rs index 4ebcabed..10f206cd 100644 --- a/src/providers/mod.rs +++ b/src/providers/mod.rs @@ -84,6 +84,7 @@ pub trait PushProvider { const PROVIDER_APNS: &str = "apns"; const PROVIDER_APNS_SANDBOX: &str = "apns-sandbox"; const PROVIDER_FCM: &str = "fcm"; +pub const PROVIDER_FCM_V1: &str = "fcm_v1"; #[cfg(any(debug_assertions, test))] const PROVIDER_NOOP: &str = "noop"; @@ -94,6 +95,7 @@ pub enum ProviderKind { Apns, ApnsSandbox, Fcm, + // Intentionally no FcmV1 variant because ProviderKind is also used to determine token type (of which FCM and FCM V1 are the same) #[cfg(any(debug_assertions, test))] Noop, } diff --git a/tests/functional/multitenant/fcm_v1.rs b/tests/functional/multitenant/fcm_v1.rs index f9b316f5..2ee94d67 100644 --- a/tests/functional/multitenant/fcm_v1.rs +++ b/tests/functional/multitenant/fcm_v1.rs @@ -1,6 +1,9 @@ use { crate::{context::EchoServerContext, functional::multitenant::generate_random_tenant_id}, - echo_server::handlers::create_tenant::TenantRegisterBody, + echo_server::{ + handlers::{create_tenant::TenantRegisterBody, get_tenant::GetTenantResponse}, + providers::PROVIDER_FCM_V1, + }, std::env, test_context::test_context, }; @@ -40,6 +43,58 @@ async fn tenant_update_fcm_v1_valid(ctx: &mut EchoServerContext) { assert_eq!(response_fcm_update.status(), reqwest::StatusCode::OK); } +#[test_context(EchoServerContext)] +#[tokio::test] +async fn tenant_enabled_providers(ctx: &mut EchoServerContext) { + let (tenant_id, jwt_token) = generate_random_tenant_id(&ctx.config.jwt_secret); + + // Register tenant + let client = reqwest::Client::new(); + let register_response = client + .post(format!("http://{}/tenants", ctx.server.public_addr)) + .bearer_auth(&jwt_token) + .json(&TenantRegisterBody { + id: tenant_id.clone(), + }) + .send() + .await + .expect("Call failed"); + assert_eq!(register_response.status(), reqwest::StatusCode::OK); + + // Send valid API Key + let credentials = env::var("ECHO_TEST_FCM_V1_CREDENTIALS").unwrap(); + let form = reqwest::multipart::Form::new().text("credentials", credentials); + + let response_fcm_update = client + .post(format!( + "http://{}/tenants/{}/fcm_v1", + ctx.server.public_addr, tenant_id + )) + .bearer_auth(&jwt_token) + .multipart(form) + .send() + .await + .expect("Call failed"); + assert_eq!(response_fcm_update.status(), reqwest::StatusCode::OK); + + // Get tenant + let response = client + .get(format!( + "http://{}/tenants/{}", + ctx.server.public_addr, tenant_id + )) + .bearer_auth(&jwt_token) + .send() + .await + .expect("Call failed"); + assert!(response.status().is_success()); + let response = response.json::().await.unwrap(); + println!("response: {response:?}"); + assert!(response + .enabled_providers + .contains(&PROVIDER_FCM_V1.to_owned())); +} + #[test_context(EchoServerContext)] #[tokio::test] async fn tenant_update_fcm_v1_wrong_format(ctx: &mut EchoServerContext) { From ef99f83ddd397cf7ebba29937239fb28b91c8310 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 14 May 2024 11:15:27 -0400 Subject: [PATCH 21/24] fix: more enabled_providers tests --- src/handlers/get_tenant.rs | 8 +++- src/providers/mod.rs | 8 ++-- tests/functional/multitenant/apns.rs | 69 +++++++++++++++++++++++++++- tests/functional/multitenant/fcm.rs | 57 ++++++++++++++++++++++- 4 files changed, 134 insertions(+), 8 deletions(-) diff --git a/src/handlers/get_tenant.rs b/src/handlers/get_tenant.rs index ef010ade..2361315c 100644 --- a/src/handlers/get_tenant.rs +++ b/src/handlers/get_tenant.rs @@ -1,7 +1,11 @@ use { crate::{ - error::Error, handlers::validate_tenant_request, log::prelude::*, providers::{ProviderKind, PROVIDER_FCM_V1}, - state::AppState, stores::tenant::ApnsType, + error::Error, + handlers::validate_tenant_request, + log::prelude::*, + providers::{ProviderKind, PROVIDER_FCM_V1}, + state::AppState, + stores::tenant::ApnsType, }, axum::{ extract::{Path, State}, diff --git a/src/providers/mod.rs b/src/providers/mod.rs index 10f206cd..b9dc33e6 100644 --- a/src/providers/mod.rs +++ b/src/providers/mod.rs @@ -81,12 +81,12 @@ pub trait PushProvider { async fn send_notification(&self, token: String, body: PushMessage) -> error::Result<()>; } -const PROVIDER_APNS: &str = "apns"; -const PROVIDER_APNS_SANDBOX: &str = "apns-sandbox"; -const PROVIDER_FCM: &str = "fcm"; +pub const PROVIDER_APNS: &str = "apns"; +pub const PROVIDER_APNS_SANDBOX: &str = "apns-sandbox"; +pub const PROVIDER_FCM: &str = "fcm"; pub const PROVIDER_FCM_V1: &str = "fcm_v1"; #[cfg(any(debug_assertions, test))] -const PROVIDER_NOOP: &str = "noop"; +pub const PROVIDER_NOOP: &str = "noop"; #[derive(Debug, Copy, Clone, PartialEq, Eq, sqlx::Type)] #[sqlx(type_name = "provider")] diff --git a/tests/functional/multitenant/apns.rs b/tests/functional/multitenant/apns.rs index 215a55b5..da08626e 100644 --- a/tests/functional/multitenant/apns.rs +++ b/tests/functional/multitenant/apns.rs @@ -1,6 +1,9 @@ use { crate::{context::EchoServerContext, functional::multitenant::generate_random_tenant_id}, - echo_server::handlers::create_tenant::TenantRegisterBody, + echo_server::{ + handlers::{create_tenant::TenantRegisterBody, get_tenant::GetTenantResponse}, + providers::PROVIDER_APNS, + }, std::env, test_context::test_context, }; @@ -52,6 +55,70 @@ async fn tenant_update_apns_valid_token(ctx: &mut EchoServerContext) { assert_eq!(apns_update_result.status(), reqwest::StatusCode::OK); } +#[test_context(EchoServerContext)] +#[tokio::test] +async fn tenant_enabled_providers(ctx: &mut EchoServerContext) { + let (tenant_id, jwt_token) = generate_random_tenant_id(&ctx.config.jwt_secret); + + // Register new tenant + let client = reqwest::Client::new(); + let create_tenant_result = client + .post(format!("http://{}/tenants", ctx.server.public_addr)) + .bearer_auth(&jwt_token) + .json(&TenantRegisterBody { + id: tenant_id.clone(), + }) + .send() + .await + .expect("Failed to create a new tenant"); + assert_eq!(create_tenant_result.status(), reqwest::StatusCode::OK); + + // Send valid APNS p8 Key + let form = reqwest::multipart::Form::new() + .text("apns_type", "token") + .text("apns_topic", "app.test") + .text("apns_key_id", env::var("ECHO_TEST_APNS_P8_KEY_ID").unwrap()) + .text( + "apns_team_id", + env::var("ECHO_TEST_APNS_P8_TEAM_ID").unwrap(), + ) + .part( + "apns_pkcs8_pem", + reqwest::multipart::Part::text(env::var("ECHO_TEST_APNS_P8_PEM").unwrap()) + .file_name("apns.p8") + .mime_str("text/plain") + .expect("Error on passing multipart stream to the form request"), + ); + let apns_update_result = client + .post(format!( + "http://{}/tenants/{}/apns", + ctx.server.public_addr, tenant_id + )) + .bearer_auth(&jwt_token) + .multipart(form) + .send() + .await + .expect("Failed to call update tenant endpoint"); + assert_eq!(apns_update_result.status(), reqwest::StatusCode::OK); + + // Get tenant + let response = client + .get(format!( + "http://{}/tenants/{}", + ctx.server.public_addr, tenant_id + )) + .bearer_auth(&jwt_token) + .send() + .await + .expect("Call failed"); + assert!(response.status().is_success()); + let response = response.json::().await.unwrap(); + println!("response: {response:?}"); + assert!(response + .enabled_providers + .contains(&PROVIDER_APNS.to_owned())); +} + #[test_context(EchoServerContext)] #[tokio::test] async fn tenant_update_apns_bad_token(ctx: &mut EchoServerContext) { diff --git a/tests/functional/multitenant/fcm.rs b/tests/functional/multitenant/fcm.rs index 63485bdb..5f865dfd 100644 --- a/tests/functional/multitenant/fcm.rs +++ b/tests/functional/multitenant/fcm.rs @@ -1,6 +1,9 @@ use { crate::{context::EchoServerContext, functional::multitenant::generate_random_tenant_id}, - echo_server::handlers::create_tenant::TenantRegisterBody, + echo_server::{ + handlers::{create_tenant::TenantRegisterBody, get_tenant::GetTenantResponse}, + providers::PROVIDER_FCM, + }, std::env, test_context::test_context, }; @@ -40,6 +43,58 @@ async fn tenant_update_fcm_valid(ctx: &mut EchoServerContext) { assert_eq!(response_fcm_update.status(), reqwest::StatusCode::OK); } +#[test_context(EchoServerContext)] +#[tokio::test] +async fn tenant_enabled_providers(ctx: &mut EchoServerContext) { + let (tenant_id, jwt_token) = generate_random_tenant_id(&ctx.config.jwt_secret); + + // Register tenant + let client = reqwest::Client::new(); + let register_response = client + .post(format!("http://{}/tenants", ctx.server.public_addr)) + .bearer_auth(&jwt_token) + .json(&TenantRegisterBody { + id: tenant_id.clone(), + }) + .send() + .await + .expect("Call failed"); + assert_eq!(register_response.status(), reqwest::StatusCode::OK); + + // Send valid API Key + let api_key = env::var("ECHO_TEST_FCM_KEY").unwrap(); + let form = reqwest::multipart::Form::new().text("api_key", api_key); + + let response_fcm_update = client + .post(format!( + "http://{}/tenants/{}/fcm", + ctx.server.public_addr, tenant_id + )) + .bearer_auth(&jwt_token) + .multipart(form) + .send() + .await + .expect("Call failed"); + assert_eq!(response_fcm_update.status(), reqwest::StatusCode::OK); + + // Get tenant + let response = client + .get(format!( + "http://{}/tenants/{}", + ctx.server.public_addr, tenant_id + )) + .bearer_auth(&jwt_token) + .send() + .await + .expect("Call failed"); + assert!(response.status().is_success()); + let response = response.json::().await.unwrap(); + println!("response: {response:?}"); + assert!(response + .enabled_providers + .contains(&PROVIDER_FCM.to_owned())); +} + #[test_context(EchoServerContext)] #[tokio::test] async fn tenant_update_fcm_bad(ctx: &mut EchoServerContext) { From c6a64d852621a423ed0c5ca74c338c4c15c295e4 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 14 May 2024 11:18:23 -0400 Subject: [PATCH 22/24] fix: secrets --- .github/SECRETS.md | 2 ++ Cargo.toml | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/SECRETS.md b/.github/SECRETS.md index 3022dcfa..fbca417a 100644 --- a/.github/SECRETS.md +++ b/.github/SECRETS.md @@ -6,6 +6,8 @@ Generated randomly and used by Cloud app to sign JWTs. ## `ECHO_TEST_FCM_V1_CREDENTIALS` +From 1Password: `Firebase Push Server Tests Service Account` + FCM v1 service account credentials for test cases. Setup: diff --git a/Cargo.toml b/Cargo.toml index c8aa7ab5..65dcdbf0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,6 @@ build = "build.rs" resolver = "2" [features] -# default = ["full"] full = ["functional_tests", "multitenant", "analytics", "geoblock", "cloud", "apns_tests", "fcm_tests", "fcmv1_tests"] # Used to enable functional tests functional_tests = [] From e0c138b60167d7ab118b4a8a0cc5f1dbe438b276 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 14 May 2024 11:24:29 -0400 Subject: [PATCH 23/24] chore: comment, reorder --- src/handlers/update_fcm_v1.rs | 6 +++--- tests/context/mod.rs | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/handlers/update_fcm_v1.rs b/src/handlers/update_fcm_v1.rs index 27c3eccf..3a8ddd3e 100644 --- a/src/handlers/update_fcm_v1.rs +++ b/src/handlers/update_fcm_v1.rs @@ -34,14 +34,14 @@ pub async fn handler( headers: HeaderMap, mut form_body: Multipart, ) -> Result, Error> { - // -- check if tenant is real - let _existing_tenant = state.tenant_store.get_tenant(&id).await?; - // JWT token verification #[cfg(feature = "cloud")] let jwt_verification_result = validate_tenant_request(&state.jwt_validation_client, &headers, &id).await; + // -- check if tenant is real + let _existing_tenant = state.tenant_store.get_tenant(&id).await?; + #[cfg(not(feature = "cloud"))] let jwt_verification_result = validate_tenant_request(&state.jwt_validation_client, &headers); diff --git a/tests/context/mod.rs b/tests/context/mod.rs index 269538f9..9cad39e6 100644 --- a/tests/context/mod.rs +++ b/tests/context/mod.rs @@ -41,8 +41,9 @@ impl TestContext for ConfigContext { log_level_otel: "info,echo-server=trace".into(), disable_header: true, validate_signatures: false, - // TODO setting this to avoid hex parsing errors; I don't think it's used relay_public_key: env::var("RELAY_PUBLIC_KEY").unwrap_or( + // Default relay public key if env not set + // TODO I don't think this is used in the tests, so this should be refactored/removed "ff469faa970df23c23a6542765ce8dba2a907538522833b2327a153e365d138e".to_string(), ), database_url: env::var("DATABASE_URL") From 310cc1c62e560c5eb4dff977ddba4df2e963d74f Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 14 May 2024 11:27:30 -0400 Subject: [PATCH 24/24] chore: comment --- src/handlers/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 870d7565..573491e5 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -193,6 +193,7 @@ pub fn validate_tenant_request( headers: &HeaderMap, ) -> Result { if let Some(token_data) = headers.get(AUTHORIZATION) { + // TODO Clients should always use `Bearer`, migrate them (if not already) and remove this optionality if jwt_validation_client .is_valid_token(token_data.to_str()?.to_string().replace("Bearer ", "")) .is_ok()