From 8bbabd43a9f9ac62e1f8e48981913d45ed485eb7 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Mon, 18 Feb 2008 00:21:18 +0000 Subject: 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 --- activeresource/test/authorization_test.rb | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'activeresource/test/authorization_test.rb') 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"] -- cgit v1.2.3