aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test/authorization_test.rb
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2008-02-18 00:21:18 +0000
committerMichael Koziarski <michael@koziarski.com>2008-02-18 00:21:18 +0000
commit8bbabd43a9f9ac62e1f8e48981913d45ed485eb7 (patch)
tree0a2a37d07906760b6ba76a2332f3196d3244fabd /activeresource/test/authorization_test.rb
parentf2546164d6eb9302d1ff5d36939d128b8f96feb1 (diff)
downloadrails-8bbabd43a9f9ac62e1f8e48981913d45ed485eb7.tar.gz
rails-8bbabd43a9f9ac62e1f8e48981913d45ed485eb7.tar.bz2
rails-8bbabd43a9f9ac62e1f8e48981913d45ed485eb7.zip
Add user and password configuration options to ActiveResource::Base, not all credentials can be specified inline. Closes #11112 [ernesto.jimenez]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8891 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource/test/authorization_test.rb')
-rw-r--r--activeresource/test/authorization_test.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/activeresource/test/authorization_test.rb b/activeresource/test/authorization_test.rb
index fabf4a42c2..05be7e3ef0 100644
--- a/activeresource/test/authorization_test.rb
+++ b/activeresource/test/authorization_test.rb
@@ -45,6 +45,38 @@ class AuthorizationTest < Test::Unit::TestCase
assert_equal ["", "test123"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1]
end
+ def test_authorization_header_explicitly_setting_username_and_password
+ @authenticated_conn = ActiveResource::Connection.new("http://@localhost")
+ @authenticated_conn.user = 'david'
+ @authenticated_conn.password = 'test123'
+ authorization_header = @authenticated_conn.send!(:authorization_header)
+ assert_equal @authorization_request_header['Authorization'], authorization_header['Authorization']
+ authorization = authorization_header["Authorization"].to_s.split
+
+ assert_equal "Basic", authorization[0]
+ assert_equal ["david", "test123"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1]
+ end
+
+ def test_authorization_header_explicitly_setting_username_but_no_password
+ @conn = ActiveResource::Connection.new("http://@localhost")
+ @conn.user = "david"
+ authorization_header = @conn.send!(:authorization_header)
+ authorization = authorization_header["Authorization"].to_s.split
+
+ assert_equal "Basic", authorization[0]
+ assert_equal ["david"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1]
+ end
+
+ def test_authorization_header_explicitly_setting_password_but_no_username
+ @conn = ActiveResource::Connection.new("http://@localhost")
+ @conn.password = "test123"
+ authorization_header = @conn.send!(:authorization_header)
+ authorization = authorization_header["Authorization"].to_s.split
+
+ assert_equal "Basic", authorization[0]
+ assert_equal ["", "test123"], ActiveSupport::Base64.decode64(authorization[1]).split(":")[0..1]
+ end
+
def test_get
david = @authenticated_conn.get("/people/2.xml")
assert_equal "David", david["name"]