Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/controllers/api/flat_json_params_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
4 changes: 1 addition & 3 deletions test/controllers/users/push_subscriptions_controller_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/integration/notifications_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions test/lib/web_push/persistent_request_test.rb
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion test/models/notification/push_target/web_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 2 additions & 4 deletions test/models/push/subscription_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/test_helpers/dns_test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
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)
dns_mock = mock("dns")
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