diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-05-08 05:48:18 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-05-08 05:48:18 +0000 |
commit | 20eb59ad8a9e97a5bbb68df1ba2f15914c26a358 (patch) | |
tree | b8821fba747df8e787897101bafc5916b3df5d7a /actionpack/test/controller | |
parent | 5a9dc1231c337f20a53e22d01dcddf7953ec549d (diff) | |
download | rails-20eb59ad8a9e97a5bbb68df1ba2f15914c26a358.tar.gz rails-20eb59ad8a9e97a5bbb68df1ba2f15914c26a358.tar.bz2 rails-20eb59ad8a9e97a5bbb68df1ba2f15914c26a358.zip |
Included the HttpAuthentication plugin as part of core (ActionController::HttpAuthentication::Basic) [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6699 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/http_authentication_test.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/actionpack/test/controller/http_authentication_test.rb b/actionpack/test/controller/http_authentication_test.rb new file mode 100644 index 0000000000..e08bc7b94b --- /dev/null +++ b/actionpack/test/controller/http_authentication_test.rb @@ -0,0 +1,42 @@ +require File.dirname(__FILE__) + '/../abstract_unit' + +class HttpBasicAuthenticationTest < Test::Unit::TestCase + include ActionController::HttpAuthentication::Basic + + def setup + @controller = Class.new do + attr_accessor :headers, :renders + + def initialize + @headers, @renders = {}, [] + end + + def request + Class.new do + def env + { 'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Basic.encode_credentials("dhh", "secret") } + end + end.new + end + + def render(options) + self.renders << options + end + end.new + end + + def test_successful_authentication + assert authenticate(@controller) { |user_name, password| user_name == "dhh" && password == "secret" } + end + + + def test_failing_authentication + assert !authenticate(@controller) { |user_name, password| user_name == "dhh" && password == "secret!!" } + end + + def test_authentication_request + authentication_request(@controller, "Megaglobalapp") + assert_equal 'Basic realm="Megaglobalapp"', @controller.headers["WWW-Authenticate"] + assert_equal :unauthorized, @controller.renders.first[:status] + end +end |