Skip to content

Commit feecd2a

Browse files
committed
Refine https check for URL
1. Disallow multiline url where one of the lines starts with `https` 2. Check for `https://` instead of `https` 3. Allow objects responding to `#to_str` like `Addressable::URI`
1 parent f183aef commit feecd2a

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/zendesk_api/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def method_as_class(method)
198198
end
199199

200200
def check_url
201-
if !config.allow_http && config.url !~ /^https/
201+
if !config.allow_http && !config.url.start_with?('https://')
202202
raise ArgumentError, "zendesk_api is ssl only; url must begin with https://"
203203
end
204204
end

spec/core/client_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ def build_connection
2222
end.to raise_error(ArgumentError)
2323
end
2424

25+
it "should raise an exception when url is multiline and ssl" do
26+
expect do
27+
ZendeskAPI::Client.new do |config|
28+
config.url = "garbage\nhttps://www.google.com"
29+
end
30+
end.to raise_error(ArgumentError)
31+
end
32+
2533
it "should not raise an exception when url isn't ssl and allow_http is set to true" do
2634
expect do
2735
ZendeskAPI::Client.new do |config|
@@ -39,6 +47,20 @@ def build_connection
3947
end
4048
end
4149

50+
it "should handle valid url as a stringlike" do
51+
expect do
52+
url = Object.new
53+
54+
def url.to_str
55+
"https://example.zendesk.com/api/v2"
56+
end
57+
58+
ZendeskAPI::Client.new do |config|
59+
config.url = url
60+
end.to_not raise_error
61+
end
62+
end
63+
4264
context "basic_auth" do
4365
subject do
4466
ZendeskAPI::Client.new do |config|

0 commit comments

Comments
 (0)