Skip to content

Commit

Permalink
Ensure the protocol used for the connection is used in internet up ch…
Browse files Browse the repository at this point in the history
…ecks
  • Loading branch information
mattheworiordan committed Jan 23, 2015
1 parent 007e3b4 commit 12b8e8a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/ably/modules/ably.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Ably
#
FALLBACK_HOSTS = %w(A.ably-realtime.com B.ably-realtime.com C.ably-realtime.com D.ably-realtime.com E.ably-realtime.com)
INTERNET_CHECK = {
url: 'http://internet-up.ably-realtime.com/is-the-internet-up.txt',
url: '//internet-up.ably-realtime.com/is-the-internet-up.txt',
ok_text: 'yes'
}
end
2 changes: 1 addition & 1 deletion lib/ably/realtime/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def ping
# @api private
def internet_up?
EventMachine::DefaultDeferrable.new.tap do |deferrable|
EventMachine::HttpRequest.new(Ably::INTERNET_CHECK.fetch(:url)).get.tap do |http|
EventMachine::HttpRequest.new("http#{'s' if client.use_tls?}:#{Ably::INTERNET_CHECK.fetch(:url)}").get.tap do |http|
http.errback do
yield false if block_given?
deferrable.fail
Expand Down
26 changes: 25 additions & 1 deletion spec/acceptance/realtime/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,30 @@ def self.available_states
stop_reactor
end

context 'internet up URL protocol' do
let(:http_request) { double('EventMachine::HttpRequest', get: EventMachine::DefaultDeferrable.new) }

context 'when using TLS for the connection' do
let(:client_options) { default_options.merge(tls: true) }

it 'uses TLS for the Internet check to https://internet-up.ably-realtime.com/is-the-internet-up.txt' do
expect(EventMachine::HttpRequest).to receive(:new).with('https://internet-up.ably-realtime.com/is-the-internet-up.txt').and_return(http_request)
connection.internet_up?
stop_reactor
end
end

context 'when using a non-secured connection' do
let(:client_options) { default_options.merge(tls: false, use_token_auth: true) }

it 'uses TLS for the Internet check to http://internet-up.ably-realtime.com/is-the-internet-up.txt' do
expect(EventMachine::HttpRequest).to receive(:new).with('http://internet-up.ably-realtime.com/is-the-internet-up.txt').and_return(http_request)
connection.internet_up?
stop_reactor
end
end
end

context 'when the Internet is up' do
it 'calls the block with true' do
connection.internet_up? do |result|
Expand All @@ -739,7 +763,7 @@ def self.available_states

context 'when the Internet is down' do
before do
stub_const 'Ably::INTERNET_CHECK', { url: 'http://does.not.exist.com', ok_text: 'no.way.this.will.match' }
stub_const 'Ably::INTERNET_CHECK', { url: '//does.not.exist.com', ok_text: 'no.way.this.will.match' }
end

it 'calls the block with false' do
Expand Down

0 comments on commit 12b8e8a

Please sign in to comment.