diff --git a/test/controllers/api/flat_json_params_test.rb b/test/controllers/api/flat_json_params_test.rb index 77a74f454e..172e11f727 100644 --- a/test/controllers/api/flat_json_params_test.rb +++ b/test/controllers/api/flat_json_params_test.rb @@ -53,7 +53,7 @@ class FlatJsonParamsTest < ActionDispatch::IntegrationTest end test "create push subscription with flat JSON" do - stub_dns_resolution("142.250.185.206") + stub_web_push_dns_resolution post user_push_subscriptions_path(users(:kevin)), params: { endpoint: "https://fcm.googleapis.com/fcm/send/abc123", p256dh_key: "key1", auth_key: "key2" }, diff --git a/test/controllers/users/push_subscriptions_controller_test.rb b/test/controllers/users/push_subscriptions_controller_test.rb index 284d82b77b..b18f4a7f8c 100644 --- a/test/controllers/users/push_subscriptions_controller_test.rb +++ b/test/controllers/users/push_subscriptions_controller_test.rb @@ -1,11 +1,9 @@ require "test_helper" class Users::PushSubscriptionsControllerTest < ActionDispatch::IntegrationTest - PUBLIC_TEST_IP = "142.250.185.206" - setup do sign_in_as :david - stub_dns_resolution(PUBLIC_TEST_IP) + stub_web_push_dns_resolution end test "create new push subscription" do diff --git a/test/integration/notifications_test.rb b/test/integration/notifications_test.rb index f581fb5e94..c7acef0655 100644 --- a/test/integration/notifications_test.rb +++ b/test/integration/notifications_test.rb @@ -16,6 +16,8 @@ class NotificationDeliveryTest < ActiveSupport::TestCase Notification.register_push_target(:web) Notification.register_push_target(push_target_with_tracking) + stub_web_push_dns_resolution + # Give assignee a web push subscription @assignee.push_subscriptions.create!( endpoint: "https://fcm.googleapis.com/fcm/send/test123", diff --git a/test/lib/web_push/persistent_request_test.rb b/test/lib/web_push/persistent_request_test.rb index 649e27b759..41d5572492 100644 --- a/test/lib/web_push/persistent_request_test.rb +++ b/test/lib/web_push/persistent_request_test.rb @@ -1,12 +1,11 @@ require "test_helper" class WebPush::PersistentRequestTest < ActiveSupport::TestCase - PUBLIC_TEST_IP = "142.250.185.206" ENDPOINT = "https://fcm.googleapis.com/fcm/send/test123" test "pins connection to endpoint_ip" do request = stub_request(:post, ENDPOINT) - .with(ipaddr: PUBLIC_TEST_IP) + .with(ipaddr: DnsTestHelper::WEB_PUSH_PUBLIC_TEST_IP) .to_return(status: 201) notification = WebPush::Notification.new( @@ -15,7 +14,7 @@ class WebPush::PersistentRequestTest < ActiveSupport::TestCase url: "/test", badge: 0, endpoint: ENDPOINT, - endpoint_ip: PUBLIC_TEST_IP, + endpoint_ip: DnsTestHelper::WEB_PUSH_PUBLIC_TEST_IP, p256dh_key: "BNcRdreALRFXTkOOUHK1EtK2wtaz5Ry4YfYCA_0QTpQtUbVlUls0VJXg7A8u-Ts1XbjhazAkj7I99e8QcYP7DkM", auth_key: "tBHItJI5svbpez7KI4CCXg" ) diff --git a/test/models/notification/push_target/web_test.rb b/test/models/notification/push_target/web_test.rb index dc09e77bf1..dae683eb95 100644 --- a/test/models/notification/push_target/web_test.rb +++ b/test/models/notification/push_target/web_test.rb @@ -5,7 +5,7 @@ class Notification::PushTarget::WebTest < ActiveSupport::TestCase @user = users(:david) @notification = notifications(:logo_mentioned_david) - stub_dns_resolution("142.250.185.206") + stub_web_push_dns_resolution @user.push_subscriptions.create!( endpoint: "https://fcm.googleapis.com/fcm/send/test123", diff --git a/test/models/push/subscription_test.rb b/test/models/push/subscription_test.rb index 65393c0e90..b654e44988 100644 --- a/test/models/push/subscription_test.rb +++ b/test/models/push/subscription_test.rb @@ -1,10 +1,8 @@ require "test_helper" class Push::SubscriptionTest < ActiveSupport::TestCase - PUBLIC_TEST_IP = "142.250.185.206" # google.com IP - setup do - stub_dns_resolution(PUBLIC_TEST_IP) + stub_web_push_dns_resolution end test "valid subscription with permitted endpoint" do @@ -92,7 +90,7 @@ class Push::SubscriptionTest < ActiveSupport::TestCase auth_key: "test_auth" ) - assert_equal PUBLIC_TEST_IP, subscription.resolved_endpoint_ip + assert_equal DnsTestHelper::WEB_PUSH_PUBLIC_TEST_IP, subscription.resolved_endpoint_ip end test "accepts all permitted push service domains" do diff --git a/test/test_helpers/dns_test_helper.rb b/test/test_helpers/dns_test_helper.rb index 8119ca01e7..34f4c54389 100644 --- a/test/test_helpers/dns_test_helper.rb +++ b/test/test_helpers/dns_test_helper.rb @@ -1,4 +1,6 @@ module DnsTestHelper + WEB_PUSH_PUBLIC_TEST_IP = "142.250.185.206" # stable public IP for web push DNS stubs in tests + private def stub_dns_resolution(*ips) @@ -6,4 +8,8 @@ def stub_dns_resolution(*ips) dns_mock.stubs(:each_address).multiple_yields(*ips) Resolv::DNS.stubs(:open).yields(dns_mock) end + + def stub_web_push_dns_resolution + stub_dns_resolution(WEB_PUSH_PUBLIC_TEST_IP) + end end