Permalink
Browse files

Allow Basic authentication to be turned off

  • Loading branch information...
francois committed Aug 4, 2009
1 parent aad5a30 commit c33a0a015af50aa3cbf7cc4071e24ec91cfbedb9
Showing with 19 additions and 2 deletions.
  1. +7 −2 activeresource/lib/active_resource/connection.rb
  2. +12 −0 activeresource/test/connection_test.rb
@@ -17,7 +17,7 @@ class Connection
}
attr_reader :site, :user, :password, :timeout
attr_accessor :format
attr_accessor :format, :use_basic_authentication
class << self
def requests
@@ -32,6 +32,7 @@ def initialize(site, format = ActiveResource::Formats::XmlFormat)
@user = @password = nil
self.site = site
self.format = format
self.use_basic_authentication = true
end
# Set URI for remote service.
@@ -150,7 +151,11 @@ def build_request_headers(headers, http_method=nil)
# Sets authorization header
def authorization_header
(@user || @password ? { 'Authorization' => 'Basic ' + ["#{@user}:#{ @password}"].pack('m').delete("\r\n") } : {})
if self.use_basic_authentication then
(@user || @password ? { 'Authorization' => 'Basic ' + ["#{@user}:#{ @password}"].pack('m').delete("\r\n") } : {})
else
{}
end
end
def http_format_header(http_method)
@@ -183,6 +183,18 @@ def test_accept_http_header
assert_nothing_raised(Mocha::ExpectationError) { @conn.get(path, {'Accept' => 'application/xhtml+xml'}) }
end
def test_when_use_basic_authentication_is_false_no_authorization_header_is_sent
@http = mock('new Net::HTTP')
@conn.stubs(:http).returns(@http)
@conn.use_basic_authentication = false
@conn.user = "francois"
@conn.password = "life is good"
@http.expects(:get).with("/people/1.xml", Not(has_key("Authorization"))).returns(stub_everything("HTTP response", :code => "200"))
@conn.get("/people/1.xml")
end
protected
def assert_response_raises(klass, code)
assert_raise(klass, "Expected response code #{code} to raise #{klass}") do

0 comments on commit c33a0a0

Please sign in to comment.