Skip to content

Commit 9c1e514

Browse files
author
Jon Elverkilde
committed
Use TLS by default
1 parent e7a549d commit 9c1e514

File tree

2 files changed

+45
-32
lines changed

2 files changed

+45
-32
lines changed

lib/pusher/client.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ def self.from_url(url)
2929
end
3030

3131
def initialize(options = {})
32-
@scheme = "http"
33-
@port = options[:port] || 80
32+
@scheme = "https"
33+
@port = options[:port] || 443
3434

35-
if options[:use_tls] || options[:encrypted]
36-
@scheme = "https"
37-
@port = options[:port] || 443
35+
if options.key?(:encrypted)
36+
warn "[DEPRECATION] `encrypted` is deprecated and will be removed in the next major version. Use `use_tls` instead."
37+
end
38+
39+
if options[:use_tls] == false || options[:encrypted] == false
40+
@scheme = "http"
41+
@port = options[:port] || 80
3842
end
3943

4044
@app_id = options[:app_id]

spec/client_spec.rb

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
expect(@client.host).to eq('api-mt1.pusher.com')
2121
end
2222

23-
it 'should be preconfigured for port 80' do
24-
expect(@client.port).to eq(80)
23+
it 'should be preconfigured for port 443' do
24+
expect(@client.port).to eq(443)
2525
end
2626

2727
it 'should use standard logger if no other logger if defined' do
@@ -116,26 +116,26 @@
116116
end
117117

118118
describe 'configuring TLS' do
119-
it 'should set port and scheme if "use_tls" enabled' do
119+
it 'should set port and scheme if "use_tls" disabled' do
120120
client = Pusher::Client.new({
121-
:use_tls => true,
121+
:use_tls => false,
122122
})
123-
expect(client.scheme).to eq('https')
124-
expect(client.port).to eq(443)
123+
expect(client.scheme).to eq('http')
124+
expect(client.port).to eq(80)
125125
end
126126

127-
it 'should set port and scheme if "encrypted" enabled' do
127+
it 'should set port and scheme if "encrypted" disabled' do
128128
client = Pusher::Client.new({
129-
:encrypted => true,
129+
:encrypted => false,
130130
})
131-
expect(client.scheme).to eq('https')
132-
expect(client.port).to eq(443)
131+
expect(client.scheme).to eq('http')
132+
expect(client.port).to eq(80)
133133
end
134134

135-
it 'should use non-TLS port and scheme if "encrypted" or "use_tls" are not set' do
135+
it 'should use TLS port and scheme if "encrypted" or "use_tls" are not set' do
136136
client = Pusher::Client.new
137-
expect(client.scheme).to eq('http')
138-
expect(client.port).to eq(80)
137+
expect(client.scheme).to eq('https')
138+
expect(client.port).to eq(443)
139139
end
140140

141141
it 'should override port if "use_tls" option set but a different port is specified' do
@@ -147,6 +147,15 @@
147147
expect(client.port).to eq(8443)
148148
end
149149

150+
it 'should override port if "use_tls" option set but a different port is specified' do
151+
client = Pusher::Client.new({
152+
:use_tls => false,
153+
:port => 8000
154+
})
155+
expect(client.scheme).to eq('http')
156+
expect(client.port).to eq(8000)
157+
end
158+
150159
end
151160

152161
describe 'configuring a http proxy' do
@@ -535,15 +544,15 @@
535544

536545
let(:call_api) { @client.send(verb, '/path') }
537546

538-
it "should use http by default" do
547+
it "should use https by default" do
539548
call_api
540-
expect(WebMock).to have_requested(verb, %r{http://api-mt1.pusher.com/apps/20/path})
549+
expect(WebMock).to have_requested(verb, %r{https://api-mt1.pusher.com/apps/20/path})
541550
end
542551

543552
it "should use https if configured" do
544-
@client.encrypted = true
553+
@client.encrypted = false
545554
call_api
546-
expect(WebMock).to have_requested(verb, %r{https://api-mt1.pusher.com})
555+
expect(WebMock).to have_requested(verb, %r{http://api-mt1.pusher.com})
547556
end
548557

549558
it "should format the respose hash with symbols at first level" do
@@ -622,15 +631,15 @@
622631
}
623632
}
624633

625-
it "should use http by default" do
634+
it "should use https by default" do
626635
call_api
627-
expect(WebMock).to have_requested(verb, %r{http://api-mt1.pusher.com/apps/20/path})
636+
expect(WebMock).to have_requested(verb, %r{https://api-mt1.pusher.com/apps/20/path})
628637
end
629638

630-
it "should use https if configured" do
631-
@client.encrypted = true
639+
it "should use http if configured" do
640+
@client.encrypted = false
632641
call_api
633-
expect(WebMock).to have_requested(verb, %r{https://api-mt1.pusher.com})
642+
expect(WebMock).to have_requested(verb, %r{http://api-mt1.pusher.com})
634643
end
635644

636645
# Note that the raw httpclient connection object is returned and
@@ -657,20 +666,20 @@
657666

658667
let(:call_api) { @client.send(method, '/path') }
659668

660-
it "should use http by default" do
669+
it "should use https by default" do
661670
EM.run {
662671
call_api.callback {
663-
expect(WebMock).to have_requested(verb, %r{http://api-mt1.pusher.com/apps/20/path})
672+
expect(WebMock).to have_requested(verb, %r{https://api-mt1.pusher.com/apps/20/path})
664673
EM.stop
665674
}
666675
}
667676
end
668677

669-
it "should use https if configured" do
678+
it "should use http if configured" do
670679
EM.run {
671-
@client.encrypted = true
680+
@client.encrypted = false
672681
call_api.callback {
673-
expect(WebMock).to have_requested(verb, %r{https://api-mt1.pusher.com})
682+
expect(WebMock).to have_requested(verb, %r{http://api-mt1.pusher.com})
674683
EM.stop
675684
}
676685
}

0 commit comments

Comments
 (0)