From 51140597a095d4f06dea3823006628774335c616 Mon Sep 17 00:00:00 2001 From: Javier Acero Date: Thu, 21 Apr 2016 11:41:34 +0200 Subject: [PATCH] Do not validate credentials are provided Also removes the authenticate option as a way to bypass credential validation. --- lib/dnsimple/client.rb | 8 ++------ spec/dnsimple/client_spec.rb | 18 +----------------- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/lib/dnsimple/client.rb b/lib/dnsimple/client.rb index b729739e..6361b256 100644 --- a/lib/dnsimple/client.rb +++ b/lib/dnsimple/client.rb @@ -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 @@ -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 diff --git a/spec/dnsimple/client_spec.rb b/spec/dnsimple/client_spec.rb index aebac49d..f017e590 100644 --- a/spec/dnsimple/client_spec.rb +++ b/spec/dnsimple/client_spec.rb @@ -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 @@ -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