Skip to content

Commit

Permalink
Do not validate credentials are provided
Browse files Browse the repository at this point in the history
Also removes the authenticate option as a way to bypass credential
validation.
  • Loading branch information
jacegu committed Apr 21, 2016
1 parent d63ec2b commit 5114059
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 23 deletions.
8 changes: 2 additions & 6 deletions lib/dnsimple/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,8 @@ def request(method, path, data = nil, options = {})
private

def request_options(custom_options = {})
authenticate = custom_options.delete(:authenticate) { true }

options = base_options
Extra.deep_merge!(options, auth_options(authenticate))
Extra.deep_merge!(options, auth_options)
Extra.deep_merge!(options, proxy_options)
Extra.deep_merge!(custom_options, options)
end
Expand All @@ -198,15 +196,13 @@ def proxy_options
options
end

def auth_options(authenticate)
def auth_options
options = {}

if password
options = { basic_auth: { username: username, password: password } }
elsif access_token
options = { headers: { HEADER_AUTHORIZATION => "Bearer #{access_token}" } }
else
!authenticate or raise Error, "A password, domain API token or access token is required."
end

options
Expand Down
18 changes: 1 addition & 17 deletions spec/dnsimple/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,6 @@
expect(WebMock).to have_requested(:get, "https://api.dnsimple.com/test").
with { |req| req.headers["Authorization"] == "Bearer access-token" }
end

it "raises an error if there's no password, domain token or access token provided" do
subject = described_class.new(username: "user", oauth_client_id: "id", oauth_client_secret: "secret")

expect {
subject.execute(:get, "test", {})
}.to raise_error(Dnsimple::Error, "A password, domain API token or access token is required.")
end

it "can perform requests without requiring authentication" do
stub_request(:any, %r{/test})

expect {
subject.execute(:get, "test", nil, authenticate: false)
}.not_to raise_error
end
end

describe "#get" do
Expand Down Expand Up @@ -192,7 +176,7 @@
and_return(double('response', code: 200))

subject = described_class.new(proxy: "example-proxy.com:4321")
subject.request(:get, "test", nil, authenticate: false)
subject.request(:get, "test", nil, {})
end
end

Expand Down

0 comments on commit 5114059

Please sign in to comment.