Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

test(push): remove push delivery and relay unit tests

Hampusd62b8e932cf5
diff --git a/fluxer_push/src/delivery.rs b/fluxer_push/src/delivery.rs
index 833954be2..5ee30c07c 100644
--- a/fluxer_push/src/delivery.rs
+++ b/fluxer_push/src/delivery.rs
@@ -684,125 +684,3 @@ fn reap(result: Result<(), tokio::task::JoinError>) {
warn!(error = %error, "push job task failed");
}
}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- fn subscription(platform: &str, thread_channels: bool) -> Subscription {
- Subscription {
- subscription_id: "sub".to_owned(),
- endpoint: "token".to_owned(),
- p256dh_key: None,
- auth_key: None,
- platform: Some(platform.to_owned()),
- app_id: None,
- provider_environment: None,
- thread_channels,
- }
- }
-
- #[test]
- fn a_thread_push_reaches_only_devices_that_registered_the_capability() {
- assert!(Audience::Thread.admits(&subscription("android_fcm", true)));
- assert!(!Audience::Thread.admits(&subscription("android_fcm", false)));
- assert!(!Audience::Thread.admits(&subscription("ios_apns_voip", true)));
- }
-
- #[test]
- fn a_standard_push_ignores_the_capability() {
- assert!(Audience::Standard.admits(&subscription("ios_apns", false)));
- assert!(Audience::Standard.admits(&subscription("ios_apns", true)));
- }
-
- async fn fake_api(
- subscribed: &'static [&'static str],
- ) -> (RpcClient, Arc<std::sync::Mutex<Vec<Value>>>) {
- let calls = Arc::new(std::sync::Mutex::new(Vec::new()));
- let recorded = Arc::clone(&calls);
- let app = axum::Router::new().route(
- "/",
- axum::routing::post(move |body: axum::body::Bytes| {
- let recorded = Arc::clone(&recorded);
- async move {
- let request: Value = serde_json::from_slice(&body).unwrap();
- recorded.lock().unwrap().push(request.clone());
- let user_ids = request["user_ids"].as_array().cloned().unwrap_or_default();
- let data = match request["type"].as_str().unwrap() {
- "get_push_subscriptions" => serde_json::json!(
- subscribed
- .iter()
- .map(|user_id| {
- (
- (*user_id).to_owned(),
- serde_json::json!([{
- "subscription_id": "sub",
- "endpoint": "token",
- "p256dh_key": null,
- "auth_key": null,
- "platform": "android_fcm",
- "app_id": null,
- "provider_environment": null
- }]),
- )
- })
- .collect::<serde_json::Map<_, _>>()
- ),
- "get_badge_counts" => serde_json::json!({
- "badge_counts": user_ids
- .iter()
- .map(|user_id| (user_id.as_str().unwrap().to_owned(), serde_json::json!(3)))
- .collect::<serde_json::Map<_, _>>()
- }),
- other => panic!("unexpected rpc {other}"),
- };
- serde_json::json!({ "data": data }).to_string()
- }
- }),
- );
- let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
- let url = format!("http://{}/", listener.local_addr().unwrap());
- tokio::spawn(async move { axum::serve(listener, app).await.unwrap() });
- let rpc = RpcClient::new(
- &crate::config::RpcConfig {
- url,
- auth_token: fluxer_common::secret::SecretString::new("token".to_owned()),
- },
- reqwest::Client::new(),
- Arc::new(crate::metrics::Metrics::new()),
- );
- (rpc, calls)
- }
-
- fn badge_requests(calls: &std::sync::Mutex<Vec<Value>>) -> Vec<Value> {
- calls
- .lock()
- .unwrap()
- .iter()
- .filter(|call| call["type"] == "get_badge_counts")
- .map(|call| call["user_ids"].clone())
- .collect()
- }
-
- #[tokio::test]
- async fn badge_counts_are_read_only_for_recipients_with_a_device() {
- let (rpc, calls) = fake_api(&["2"]).await;
- let user_ids: Vec<String> = (1..=500).map(|id| id.to_string()).collect();
- let deadline = Instant::now() + Duration::from_secs(5);
- let (badges, subscriptions) = lookup_recipients(&rpc, &user_ids, deadline).await.unwrap();
- assert_eq!(badge_requests(&calls), vec![serde_json::json!(["2"])]);
- assert_eq!(badges, HashMap::from([("2".to_owned(), 3)]));
- assert!(subscribed(&subscriptions, "2"));
- }
-
- #[tokio::test]
- async fn no_badge_counts_are_read_when_nobody_has_a_device() {
- let (rpc, calls) = fake_api(&[]).await;
- let user_ids: Vec<String> = (1..=500).map(|id| id.to_string()).collect();
- let deadline = Instant::now() + Duration::from_secs(5);
- let (badges, _subscriptions) = lookup_recipients(&rpc, &user_ids, deadline).await.unwrap();
- assert!(badge_requests(&calls).is_empty());
- assert!(badges.is_empty());
- assert_eq!(calls.lock().unwrap().len(), 1);
- }
-}
diff --git a/fluxer_push/src/job.rs b/fluxer_push/src/job.rs
index 125b26c1d..5c1e4eb78 100644
--- a/fluxer_push/src/job.rs
+++ b/fluxer_push/src/job.rs
@@ -175,19 +175,6 @@ mod tests {
assert_eq!(job.notification.badge, None);
}
- #[test]
- fn a_thread_job_decodes_its_optional_fields() {
- let job = decode_message(
- format!(r#"{BASE},"kind":"thread","parent_id":"9","parent_name":"general","channel_name":"plans"}}"#)
- .as_bytes(),
- )
- .expect("the job decodes");
- assert!(job.is_thread());
- assert_eq!(job.parent_id.as_deref(), Some("9"));
- assert_eq!(job.parent_name.as_deref(), Some("general"));
- assert_eq!(job.channel_name.as_deref(), Some("plans"));
- }
-
#[test]
fn a_gateway_thread_job_decodes_as_a_thread() {
let job = decode_message(
@@ -199,30 +186,4 @@ mod tests {
assert_eq!(job.parent_name.as_deref(), Some("general"));
assert_eq!(job.channel_name.as_deref(), Some("ideas"));
}
-
- #[test]
- fn a_forum_thread_created_job_reaches_thread_capable_devices_only() {
- let job = decode_message(
- format!(
- r#"{BASE},"kind":"forum_thread_created","parent_id":"9","channel_name":"post"}}"#
- )
- .as_bytes(),
- )
- .expect("the job decodes");
- assert!(job.is_thread());
- assert!(job.is_forum_thread_created());
- let thread = decode_message(format!(r#"{BASE},"kind":"thread"}}"#).as_bytes())
- .expect("the job decodes");
- assert!(!thread.is_forum_thread_created());
- }
-
- #[test]
- fn thread_fields_nested_in_the_notification_do_not_mark_a_thread() {
- let job = decode_message(
- br#"{"v":1,"config_version":3,"guild_id":"5","channel_id":"6","message_id":"7","notification":{"title":"t","body":"b","icon":"i","badge":"g","tag":"x","notification_tag":"y","url":"/u","kind":"thread","parent_id":"200"},"user_ids":["8"]}"#,
- )
- .expect("the job decodes");
- assert!(!job.is_thread());
- assert_eq!(job.parent_id, None);
- }
}
diff --git a/fluxer_push/src/payload.rs b/fluxer_push/src/payload.rs
index ccc927033..496a7208a 100644
--- a/fluxer_push/src/payload.rs
+++ b/fluxer_push/src/payload.rs
@@ -636,7 +636,7 @@ fn serialize(value: &Value) -> Vec<u8> {
#[cfg(test)]
mod tests {
use super::*;
- use crate::job::{ClearJob, MessageJob, NotificationFields};
+ use crate::job::{MessageJob, NotificationFields};
const CHANNEL_ID: &str = "9876543210987654321";
const MESSAGE_ID: &str = "1122334455667788990";
@@ -666,50 +666,10 @@ mod tests {
}
}
- fn thread_job() -> MessageJob {
- MessageJob {
- guild_id: "4455".to_owned(),
- kind: Some("thread".to_owned()),
- parent_id: Some("7788".to_owned()),
- parent_name: Some("general".to_owned()),
- channel_name: Some("release plans".to_owned()),
- ..message_job(None)
- }
- }
-
- fn clear_job() -> ClearJob {
- ClearJob {
- v: 1,
- user_id: USER_ID.to_owned(),
- channel_id: CHANNEL_ID.to_owned(),
- message_id: MESSAGE_ID.to_owned(),
- after_message_id: None,
- }
- }
-
fn apns_for(image_url: Option<&str>) -> Value {
apns_payload(&web_push_message(&message_job(image_url), USER_ID, 3))
}
- #[test]
- fn a_message_without_an_image_still_runs_the_notification_service_extension() {
- assert_eq!(apns_for(None)["aps"]["mutable-content"], json!(1));
- }
-
- #[test]
- fn a_message_with_an_image_still_runs_the_notification_service_extension() {
- assert_eq!(
- apns_for(Some("https://media.fluxer.app/proxy/attachment.webp"))["aps"]["mutable-content"],
- json!(1)
- );
- }
-
- #[test]
- fn a_background_clear_never_runs_the_notification_service_extension() {
- let payload = apns_payload(&web_push_clear(&clear_job(), 3));
- assert_eq!(payload["aps"], json!({"content-available": 1}));
- }
-
#[test]
fn the_apns_category_is_the_identifier_the_app_registers() {
assert_eq!(apns_for(None)["aps"]["category"], json!("fluxer_message"));
@@ -726,91 +686,4 @@ mod tests {
json!("FLUXER_MESSAGE")
);
}
-
- #[test]
- fn a_message_with_a_badge_sends_it_in_both_places() {
- let envelope = web_push_message(&message_job(None), USER_ID, 3);
- assert_eq!(
- envelope["badge"],
- json!("https://media.fluxer.app/badge.png")
- );
- assert_eq!(
- envelope["notification"]["badge"],
- json!("https://media.fluxer.app/badge.png")
- );
- }
-
- #[test]
- fn a_message_without_a_badge_leaves_the_key_out() {
- let mut job = message_job(None);
- job.notification.badge = None;
- let envelope = web_push_message(&job, USER_ID, 3);
- assert!(envelope.get("badge").is_none());
- assert!(envelope["notification"].get("badge").is_none());
- }
-
- #[test]
- fn a_message_outside_a_thread_carries_no_thread_keys() {
- let envelope = web_push_message(&message_job(None), USER_ID, 3);
- for key in THREAD_DATA_KEYS {
- assert!(envelope["data"].get(key).is_none(), "{key} leaked");
- }
- }
-
- #[test]
- fn a_thread_message_carries_its_parent_and_names() {
- let envelope = web_push_message(&thread_job(), USER_ID, 3);
- assert_eq!(envelope["data"]["parent_id"], json!("7788"));
- assert_eq!(envelope["data"]["parent_name"], json!("general"));
- assert_eq!(envelope["data"]["channel_name"], json!("release plans"));
- assert_eq!(apns_payload(&envelope)["parent_id"], json!("7788"));
- }
-
- #[test]
- fn only_a_forum_thread_created_message_carries_its_notification_type() {
- let thread = web_push_message(&thread_job(), USER_ID, 3);
- assert!(thread["data"].get(NOTIF_TYPE_KEY).is_none());
- let forum = MessageJob {
- kind: Some("forum_thread_created".to_owned()),
- ..thread_job()
- };
- let envelope = web_push_message(&forum, USER_ID, 3);
- assert_eq!(envelope["data"][NOTIF_TYPE_KEY], json!(9));
- assert_eq!(envelope["data"]["parent_id"], json!("7788"));
- let message = fcm_message("device-token", &envelope);
- assert_eq!(message["message"]["data"][NOTIF_TYPE_KEY], json!("9"));
- assert_eq!(
- message["message"]["android"]["notification"]["channel_id"],
- json!(FCM_FORUM_THREAD_CREATED_CHANNEL_ID)
- );
- assert_eq!(
- fcm_message("device-token", &thread)["message"]["android"]["notification"]["channel_id"],
- json!(FCM_DEFAULT_CHANNEL_ID)
- );
- let budget = serialize(&minimal(&envelope, usize::MAX)).len();
- let (bytes, _step) = fit(&envelope, budget);
- let shrunk: Value = serde_json::from_slice(&bytes).expect("the shrunk payload is json");
- assert_eq!(shrunk["data"][NOTIF_TYPE_KEY], json!(9));
- }
-
- #[test]
- fn a_shrunk_thread_message_keeps_its_parent_id() {
- let envelope = web_push_message(&thread_job(), USER_ID, 3);
- let budget = serialize(&minimal(&envelope, usize::MAX)).len();
- let (bytes, step) = fit(&envelope, budget);
- assert_eq!(step, Some(PayloadShrink::Minimal));
- let shrunk: Value = serde_json::from_slice(&bytes).expect("the shrunk payload is json");
- assert_eq!(shrunk["data"]["parent_id"], json!("7788"));
- }
-
- #[test]
- fn a_shrunk_clear_still_tells_the_client_it_is_a_clear() {
- let envelope = web_push_clear(&clear_job(), 3);
- let budget = serialize(&envelope).len() - 1;
- let (bytes, step) = fit(&envelope, budget);
- assert_eq!(step, Some(PayloadShrink::Minimal));
- let shrunk: Value = serde_json::from_slice(&bytes).expect("the shrunk payload is json");
- assert_eq!(shrunk["data"]["type"], json!(CLEAR_TYPE));
- assert_eq!(shrunk["data"]["action"], json!(CLEAR_ACTION));
- }
}
diff --git a/fluxer_push/src/providers/mod.rs b/fluxer_push/src/providers/mod.rs
index f59e6403d..b76f5f49f 100644
--- a/fluxer_push/src/providers/mod.rs
+++ b/fluxer_push/src/providers/mod.rs
@@ -168,35 +168,6 @@ fn result_of(outcome: &SendOutcome) -> SendResult {
}
}
-#[cfg(test)]
-mod hop_tests {
- use super::*;
-
- const TOKEN: &str = "3dbc5a5ef1a1c1666afc26f466e1b3ebaaf4c66d92dddeb0fd1b69c49641d4cd";
-
- fn ours() -> Vec<String> {
- vec!["push.fluxer.com".to_owned()]
- }
-
- #[test]
- fn the_plain_apns_leg_is_delivered_in_process() {
- let apns = format!("https://push.fluxer.com/relay/v1/apns/canary/production/{TOKEN}");
- assert!(in_process_hop(&apns, &ours()).is_some());
- }
-
- #[test]
- fn an_fcm_relay_endpoint_is_delivered_in_process() {
- let fcm = "https://push.fluxer.com/relay/v1/fcm/canary/tok%3AAPA91bExample";
- assert!(in_process_hop(fcm, &ours()).is_some());
- }
-
- #[test]
- fn a_pushkit_relay_endpoint_keeps_its_voip_topic() {
- let voip = format!("https://push.fluxer.com/relay/v1/apns-voip/canary/production/{TOKEN}");
- assert!(in_process_hop(&voip, &ours()).is_none());
- }
-}
-
#[cfg(test)]
mod consent_tests {
use super::*;
@@ -204,7 +175,6 @@ mod consent_tests {
use crate::server::AppState;
const TOKEN: &str = "3dbc5a5ef1a1c1666afc26f466e1b3ebaaf4c66d92dddeb0fd1b69c49641d4cd";
- const NTFY_ENDPOINT: &str = "https://ntfy.sh/upZzH87cT9jJCc?up=1";
fn managed_endpoint() -> String {
format!("https://push.fluxer.com/relay/v1/apns/stable/production/{TOKEN}")
@@ -256,44 +226,6 @@ mod consent_tests {
);
}
- #[tokio::test]
- async fn a_refused_managed_relay_send_keeps_the_registration() {
- assert!(!outcome_of(false, &managed_endpoint()).await.deletes_token());
- }
-
- #[tokio::test]
- async fn an_accepted_notice_lets_the_managed_relay_send_through() {
- assert_eq!(
- outcome_of(true, &managed_endpoint()).await,
- SendOutcome::permanent("missing_keys")
- );
- }
-
- #[tokio::test]
- async fn a_unified_push_endpoint_is_sent_whatever_the_operator_accepted() {
- assert_eq!(
- outcome_of(false, NTFY_ENDPOINT).await,
- SendOutcome::permanent("missing_keys")
- );
- assert_eq!(
- outcome_of(true, NTFY_ENDPOINT).await,
- SendOutcome::permanent("missing_keys")
- );
- }
-
- #[tokio::test]
- async fn a_notice_accepted_in_the_instance_config_lets_the_send_through() {
- let state = state(false);
- state.relay_consent.update(&serde_json::json!({
- "config_version": 1,
- "relay_consent_accepted": true,
- }));
- assert_eq!(
- send(&state, &subscription(&managed_endpoint()), &Value::Null).await,
- SendOutcome::permanent("missing_keys")
- );
- }
-
#[tokio::test]
async fn an_instance_config_that_has_not_accepted_still_refuses_the_send() {
let state = state(false);
@@ -306,18 +238,4 @@ mod consent_tests {
SendOutcome::permanent("relay_consent_required")
);
}
-
- #[tokio::test]
- async fn a_refused_managed_relay_send_is_still_counted() {
- let state = state(false);
- let outcome = send(&state, &subscription(&managed_endpoint()), &Value::Null).await;
- assert_eq!(outcome, SendOutcome::permanent("relay_consent_required"));
- let rendered = state.metrics.render();
- for series in [
- "fluxer_push_sends_total{provider=\"web_push\",result=\"permanent\"} 1",
- "fluxer_push_delivery_routes_total{route=\"web_push\",result=\"permanent\"} 1",
- ] {
- assert!(rendered.contains(series), "{series} must be recorded");
- }
- }
}
diff --git a/fluxer_push/src/providers/own_relay.rs b/fluxer_push/src/providers/own_relay.rs
index 98d5c68cd..de85b4b3c 100644
--- a/fluxer_push/src/providers/own_relay.rs
+++ b/fluxer_push/src/providers/own_relay.rs
@@ -120,41 +120,6 @@ mod tests {
vec!["push.fluxer.com".to_owned()]
}
- #[test]
- fn an_apns_endpoint_on_our_own_relay_is_taken_in_process() {
- let hop = parse(
- &format!("https://push.fluxer.com/relay/v1/apns/canary/production/{TOKEN}"),
- &ours(),
- )
- .expect("our own relay endpoint parses");
- assert_eq!(hop.leg, Leg::Apns);
- assert_eq!(hop.app_id, "canary");
- assert_eq!(hop.environment, Some(ProviderEnvironment::Production));
- assert_eq!(hop.device_token, TOKEN);
- }
-
- #[test]
- fn an_fcm_endpoint_keeps_its_percent_encoded_token() {
- let hop = parse(
- "https://push.fluxer.com/relay/v1/fcm/canary/dYC_x9gXTjyyrG8_Aw3nUM%3AAPA91bExample",
- &ours(),
- )
- .expect("an fcm endpoint parses");
- assert_eq!(hop.leg, Leg::Fcm);
- assert_eq!(hop.environment, None);
- assert_eq!(hop.device_token, "dYC_x9gXTjyyrG8_Aw3nUM:APA91bExample");
- }
-
- #[test]
- fn a_voip_endpoint_on_our_own_relay_keeps_its_own_leg() {
- let hop = parse(
- &format!("https://push.fluxer.com/relay/v1/apns-voip/canary/production/{TOKEN}"),
- &ours(),
- )
- .expect("a voip endpoint parses");
- assert_eq!(hop.leg, Leg::ApnsVoip);
- }
-
#[test]
fn a_relay_we_do_not_operate_is_left_on_the_network_path() {
let endpoint = format!("https://push.example.org/relay/v1/apns/canary/production/{TOKEN}");
@@ -167,38 +132,6 @@ mod tests {
assert!(parse(&endpoint, &[]).is_none());
}
- #[test]
- fn a_third_party_web_push_endpoint_is_not_mistaken_for_a_relay_hop() {
- assert!(
- parse(
- "https://updates.push.services.mozilla.com/wpush/v2/gAAAAA",
- &ours()
- )
- .is_none()
- );
- assert!(parse("https://ntfy.sh/upZzH87cT9jJCc?up=1", &ours()).is_none());
- }
-
- #[test]
- fn every_managed_relay_leg_is_recognised_and_nothing_else_is() {
- for path in [
- format!("apns/canary/production/{TOKEN}"),
- format!("apns-voip/canary/production/{TOKEN}"),
- "fcm/canary/dYC_x9gXTjyyrG8_Aw3nUM%3AAPA91bExample".to_owned(),
- ] {
- let endpoint = format!("https://push.fluxer.com/relay/v1/{path}");
- assert!(
- is_managed(&endpoint, &ours()),
- "{endpoint} must be a managed relay endpoint"
- );
- }
- assert!(!is_managed("https://ntfy.sh/upZzH87cT9jJCc?up=1", &ours()));
- assert!(!is_managed(
- "https://updates.push.services.mozilla.com/wpush/v2/gAAAAA",
- &ours()
- ));
- }
-
#[test]
fn a_malformed_relay_path_is_refused() {
for endpoint in [
diff --git a/fluxer_push/src/providers/web_push.rs b/fluxer_push/src/providers/web_push.rs
index 042c52e7f..8ca0f28ed 100644
--- a/fluxer_push/src/providers/web_push.rs
+++ b/fluxer_push/src/providers/web_push.rs
@@ -294,76 +294,3 @@ fn retry_delay(attempt: u32) -> Duration {
let jitter = rand::rng().random_range(1..=(base / 4).max(1));
Duration::from_millis(MAX_RETRY_DELAY_MS.min(base + jitter - 1))
}
-
-#[cfg(test)]
-mod retry_tests {
- use super::*;
-
- #[test]
- fn a_topic_with_no_listener_is_not_retried() {
- assert!(!should_retry(INSUFFICIENT_STORAGE, 0));
- }
-
- const TOKEN: &str = "3dbc5a5ef1a1c1666afc26f466e1b3ebaaf4c66d92dddeb0fd1b69c49641d4cd";
-
- fn managed_hosts() -> Vec<String> {
- vec!["push.fluxer.com".to_owned()]
- }
-
- #[test]
- fn a_relay_over_its_device_quota_is_not_retried() {
- let endpoint = format!("https://push.fluxer.com/relay/v1/fcm/stable/{TOKEN}");
- assert!(is_relay_quota_refusal(
- TOO_MANY_REQUESTS,
- &endpoint,
- &managed_hosts()
- ));
- }
-
- #[test]
- fn a_rate_limited_third_party_push_service_is_still_retried() {
- let endpoint = "https://ntfy.sh/upZzH87cT9jJCc?up=1";
- assert!(!is_relay_quota_refusal(
- TOO_MANY_REQUESTS,
- endpoint,
- &managed_hosts()
- ));
- assert!(should_retry(TOO_MANY_REQUESTS, 0));
- }
-
- #[test]
- fn an_unavailable_relay_is_still_retried() {
- let endpoint = format!("https://push.fluxer.com/relay/v1/fcm/stable/{TOKEN}");
- assert!(!is_relay_quota_refusal(503, &endpoint, &managed_hosts()));
- }
-
- #[test]
- fn an_unavailable_push_service_is_retried_until_the_budget_runs_out() {
- assert!(should_retry(503, 0));
- assert!(!should_retry(503, MAX_TRANSIENT_RETRIES));
- }
-
- #[test]
- fn a_permanent_status_is_never_retried() {
- assert!(!should_retry(400, 0));
- assert!(!should_retry(410, 0));
- }
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn a_unified_push_topic_with_no_listener_is_permanent() {
- assert_eq!(
- classify(INSUFFICIENT_STORAGE),
- SendOutcome::permanent("http_507")
- );
- }
-
- #[test]
- fn an_unavailable_push_service_stays_retryable() {
- assert_eq!(classify(503), SendOutcome::transient("http_503"));
- }
-}
diff --git a/fluxer_push/src/relay/mod.rs b/fluxer_push/src/relay/mod.rs
index 1ba79ffdc..ec736292a 100644
--- a/fluxer_push/src/relay/mod.rs
+++ b/fluxer_push/src/relay/mod.rs
@@ -554,18 +554,6 @@ mod tests {
"a".repeat(len)
}
- #[test]
- fn apns_accepts_every_token_length_apple_hands_out() {
- for len in [64, 128, 160, 200, 256] {
- assert!(
- device_token_is_shaped(RelayLeg::Apns, &hex(len)),
- "{len} hex characters must be accepted"
- );
- }
- assert!(device_token_is_shaped(RelayLeg::Apns, &"A".repeat(64)));
- assert!(device_token_is_shaped(RelayLeg::ApnsVoip, &hex(160)));
- }
-
#[test]
fn apns_rejects_tokens_that_are_not_even_length_hex() {
for token in [hex(62), hex(63), hex(161), hex(258), "z".repeat(64)] {
@@ -585,35 +573,4 @@ mod tests {
assert_eq!(digest(TOKEN), digest(TOKEN));
assert_eq!(digest(""), "-");
}
-
- #[test]
- fn a_clear_survives_a_device_that_is_offline_for_a_day() {
- assert_eq!(
- Urgency::Background.ttl_cap_seconds(),
- Urgency::Alert.ttl_cap_seconds(),
- "a clear must outlive the alert it removes"
- );
- }
-
- #[test]
- fn a_clear_stays_silent_on_the_apns_leg() {
- let body = envelope::apns_body("payload", Urgency::Background).expect("body fits");
- let parsed: serde_json::Value = serde_json::from_slice(&body).expect("body is json");
- assert_eq!(parsed["aps"]["content-available"], 1);
- assert!(parsed["aps"].get("alert").is_none());
- let headers = envelope::apns_headers(Urgency::Background, 0, 86_400);
- let push_type = headers
- .iter()
- .find(|(name, _)| name == "apns-push-type")
- .map(|(_, value)| value.as_str());
- assert_eq!(push_type, Some("background"));
- }
-
- #[test]
- fn payload_too_large_answers_413() {
- assert_eq!(
- Reason::PayloadTooLarge.status(),
- StatusCode::PAYLOAD_TOO_LARGE
- );
- }
}
diff --git a/fluxer_push/src/relay/quota.rs b/fluxer_push/src/relay/quota.rs
index a9f0d4683..3be7e1f6b 100644
--- a/fluxer_push/src/relay/quota.rs
+++ b/fluxer_push/src/relay/quota.rs
@@ -187,40 +187,3 @@ impl Buckets {
allowed
}
}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- fn config() -> BucketConfig {
- BucketConfig {
- entries: 1_000_000,
- per_minute: 60,
- burst: 20,
- }
- }
-
- #[test]
- fn a_generation_rotates_on_age_as_well_as_on_size() {
- let buckets = Buckets::new(&config());
- let start = Instant::now();
- assert!(buckets.take([1u8; KEY_BYTES], start));
- assert_eq!(buckets.held.lock().unwrap().live.len(), 1);
- let later = start + MAX_GENERATION_AGE;
- assert!(buckets.take([2u8; KEY_BYTES], later));
- let held = buckets.held.lock().unwrap();
- assert_eq!(held.live.len(), 1);
- assert_eq!(held.aged.len(), 1);
- }
-
- #[test]
- fn the_burst_is_spent_before_a_caller_is_refused() {
- let buckets = Buckets::new(&config());
- let now = Instant::now();
- let key = [3u8; KEY_BYTES];
- for _ in 0..20 {
- assert!(buckets.take(key, now));
- }
- assert!(!buckets.take(key, now));
- }
-}
diff --git a/fluxer_push/src/relay_consent.rs b/fluxer_push/src/relay_consent.rs
index add5dcd8d..531ea6341 100644
--- a/fluxer_push/src/relay_consent.rs
+++ b/fluxer_push/src/relay_consent.rs
@@ -245,70 +245,4 @@ mod tests {
);
assert!(store.held().is_none());
}
-
- #[test]
- fn a_config_version_that_is_not_an_integer_is_refused() {
- let store = RelayConsentStore::new(false);
- assert_eq!(
- store.update(&json!({"config_version": -1, "relay_consent_accepted": true})),
- ConsentUpdate::Rejected
- );
- assert!(!store.accepted());
- }
-
- #[test]
- fn an_older_config_version_never_overwrites_a_newer_one() {
- let store = RelayConsentStore::new(false);
- store.update(&legacy_document(5, true));
- assert_eq!(
- store.update(&legacy_document(4, false)),
- ConsentUpdate::Stale
- );
- assert!(store.accepted());
- assert_eq!(
- store.update(&legacy_document(6, false)),
- ConsentUpdate::Updated
- );
- assert!(!store.accepted());
- }
-
- #[test]
- fn the_same_document_again_is_unchanged() {
- let store = RelayConsentStore::new(false);
- store.update(&legacy_document(5, true));
- assert_eq!(
- store.update(&legacy_document(5, true)),
- ConsentUpdate::Unchanged
- );
- }
-
- #[test]
- fn the_env_override_accepts_whatever_the_document_says() {
- let store = RelayConsentStore::new(true);
- assert!(store.accepted());
- store.update(&legacy_document(1, false));
- assert!(store.accepted());
- }
-
- #[test]
- fn a_nats_message_is_unwrapped_from_its_envelope() {
- let store = RelayConsentStore::new(false);
- let message = json!({"type": MESSAGE_TYPE, "config": legacy_document(2, true)});
- assert_eq!(
- store.apply(message.to_string().as_bytes()),
- ConsentUpdate::Updated
- );
- assert!(store.accepted());
- }
-
- #[test]
- fn a_nats_message_of_another_type_is_refused() {
- let store = RelayConsentStore::new(false);
- let message = json!({"type": "something_else", "config": legacy_document(2, true)});
- assert_eq!(
- store.apply(message.to_string().as_bytes()),
- ConsentUpdate::Rejected
- );
- assert!(!store.accepted());
- }
}
diff --git a/fluxer_push/src/resolver.rs b/fluxer_push/src/resolver.rs
index e2a0b1498..6fc18fdc3 100644
--- a/fluxer_push/src/resolver.rs
+++ b/fluxer_push/src/resolver.rs
@@ -66,12 +66,4 @@ mod tests {
let error = screen(lan_address(), false).err().unwrap();
assert_eq!(error.to_string(), BLOCKED_ADDRESS_ERROR);
}
-
- #[test]
- fn a_listed_private_host_may_resolve_to_a_private_address() {
- let hosts = vec!["ntfy.example.com".to_owned()];
- assert!(is_private_host("NTFY.example.com.", &hosts));
- assert!(!is_private_host("other.example.com", &hosts));
- assert!(screen(lan_address(), true).is_ok());
- }
}
diff --git a/fluxer_push/src/vendor.rs b/fluxer_push/src/vendor.rs
index 3fd84a0ff..d554f6c1f 100644
--- a/fluxer_push/src/vendor.rs
+++ b/fluxer_push/src/vendor.rs
@@ -293,13 +293,6 @@ mod tests {
.expect_err("the request cannot complete")
}
- #[tokio::test]
- async fn a_host_that_does_not_resolve_is_permanent() {
- let error = error_for("https://push.invalid/relay/v1/apns/stable/production/token").await;
- assert_eq!(Unreachable::of(&error), Unreachable::Dns);
- assert!(Unreachable::of(&error).is_permanent());
- }
-
#[tokio::test]
async fn a_logged_error_never_contains_the_device_token() {
const TOKEN: &str = "3dbc5a5ef1a1c1666afc26f466e1b3ebaaf4c66d92dddeb0fd1b69c49641d4cd";
@@ -310,47 +303,4 @@ mod tests {
);
assert!(!error.without_url().to_string().contains(TOKEN));
}
-
- #[test]
- fn a_wrong_topic_is_not_a_dead_token() {
- assert_eq!(apns_dead_token(400, "DeviceTokenNotForTopic"), None);
- }
-
- #[test]
- fn a_bad_device_token_is_still_a_dead_token() {
- assert_eq!(
- apns_dead_token(400, "BadDeviceToken"),
- Some(DeadToken::Invalid("bad_device_token"))
- );
- }
-
- #[tokio::test]
- async fn a_host_in_blocked_address_space_is_named_as_such() {
- let error = web_push_http_client(&[])
- .expect("the http client builds")
- .post("https://localhost/push")
- .send()
- .await
- .expect_err("the request cannot complete");
- assert_eq!(Unreachable::of(&error), Unreachable::BlockedAddress);
- assert!(Unreachable::of(&error).is_permanent());
- }
-
- #[tokio::test]
- async fn a_listed_private_host_gets_through_to_connect() {
- let error = web_push_http_client(&["localhost".to_owned()])
- .expect("the http client builds")
- .post("https://localhost:1/push")
- .send()
- .await
- .expect_err("the request cannot complete");
- assert_eq!(Unreachable::of(&error), Unreachable::Transport);
- }
-
- #[tokio::test]
- async fn a_refused_connection_stays_retryable() {
- let error = error_for("http://127.0.0.1:1/").await;
- assert_eq!(Unreachable::of(&error), Unreachable::Transport);
- assert!(!Unreachable::of(&error).is_permanent());
- }
}