diff --git a/test/controllers/api/flat_json_params_test.rb b/test/controllers/api/flat_json_params_test.rb index 7a9a5ea5d..77a74f454 100644 --- a/test/controllers/api/flat_json_params_test.rb +++ b/test/controllers/api/flat_json_params_test.rb @@ -247,11 +247,4 @@ class FlatJsonParamsTest < ActionDispatch::IntegrationTest assert_response :no_content assert_equal "Flat Join", users(:david).reload.name end - - private - def stub_dns_resolution(*ips) - dns_mock = mock("dns") - dns_mock.stubs(:each_address).multiple_yields(*ips) - Resolv::DNS.stubs(:open).yields(dns_mock) - end end diff --git a/test/controllers/users/push_subscriptions_controller_test.rb b/test/controllers/users/push_subscriptions_controller_test.rb index b9f43ff0a..284d82b77 100644 --- a/test/controllers/users/push_subscriptions_controller_test.rb +++ b/test/controllers/users/push_subscriptions_controller_test.rb @@ -92,11 +92,4 @@ class Users::PushSubscriptionsControllerTest < ActionDispatch::IntegrationTest assert_response :unprocessable_entity end - - private - def stub_dns_resolution(*ips) - dns_mock = mock("dns") - dns_mock.stubs(:each_address).multiple_yields(*ips) - Resolv::DNS.stubs(:open).yields(dns_mock) - end end diff --git a/test/models/notification/push_target/web_test.rb b/test/models/notification/push_target/web_test.rb index 37f23b557..dc09e77bf 100644 --- a/test/models/notification/push_target/web_test.rb +++ b/test/models/notification/push_target/web_test.rb @@ -5,6 +5,8 @@ class Notification::PushTarget::WebTest < ActiveSupport::TestCase @user = users(:david) @notification = notifications(:logo_mentioned_david) + stub_dns_resolution("142.250.185.206") + @user.push_subscriptions.create!( endpoint: "https://fcm.googleapis.com/fcm/send/test123", p256dh_key: "test_key", diff --git a/test/models/push/subscription_test.rb b/test/models/push/subscription_test.rb index 89887599f..65393c0e9 100644 --- a/test/models/push/subscription_test.rb +++ b/test/models/push/subscription_test.rb @@ -115,11 +115,4 @@ class Push::SubscriptionTest < ActiveSupport::TestCase assert subscription.valid?, "Expected #{endpoint} to be valid, got errors: #{subscription.errors.full_messages}" end end - - private - def stub_dns_resolution(*ips) - dns_mock = mock("dns") - dns_mock.stubs(:each_address).multiple_yields(*ips) - Resolv::DNS.stubs(:open).yields(dns_mock) - end end diff --git a/test/models/ssrf_protection_test.rb b/test/models/ssrf_protection_test.rb index 550909f89..fc2828b60 100644 --- a/test/models/ssrf_protection_test.rb +++ b/test/models/ssrf_protection_test.rb @@ -82,11 +82,4 @@ class SsrfProtectionTest < ActiveSupport::TestCase stub_dns_resolution("::93.184.216.34") assert_nil SsrfProtection.resolve_public_ip("compat-public.example.com") end - - private - def stub_dns_resolution(*ips) - dns_mock = mock("dns") - dns_mock.stubs(:each_address).multiple_yields(*ips) - Resolv::DNS.stubs(:open).yields(dns_mock) - end end diff --git a/test/models/webhook/delivery_test.rb b/test/models/webhook/delivery_test.rb index 5c63bc595..4fc6b2870 100644 --- a/test/models/webhook/delivery_test.rb +++ b/test/models/webhook/delivery_test.rb @@ -473,11 +473,4 @@ class Webhook::DeliveryTest < ActiveSupport::TestCase assert_equal 200, delivery.response[:code] assert delivery.succeeded? end - - private - def stub_dns_resolution(*ips) - dns_mock = mock("dns") - dns_mock.stubs(:each_address).multiple_yields(*ips) - Resolv::DNS.stubs(:open).yields(dns_mock) - end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 4d85c51f9..72c8f3b35 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -45,7 +45,7 @@ module ActiveSupport fixtures :all include ActiveJob::TestHelper - include ActionTextTestHelper, CachingTestHelper, CardTestHelper, ChangeTestHelper, SessionTestHelper + include ActionTextTestHelper, CachingTestHelper, CardTestHelper, ChangeTestHelper, DnsTestHelper, SessionTestHelper include Turbo::Broadcastable::TestHelper # Jobs must carry their own account context via AccountTenanted, diff --git a/test/test_helpers/dns_test_helper.rb b/test/test_helpers/dns_test_helper.rb new file mode 100644 index 000000000..8119ca01e --- /dev/null +++ b/test/test_helpers/dns_test_helper.rb @@ -0,0 +1,9 @@ +module DnsTestHelper + private + + def stub_dns_resolution(*ips) + dns_mock = mock("dns") + dns_mock.stubs(:each_address).multiple_yields(*ips) + Resolv::DNS.stubs(:open).yields(dns_mock) + end +end