20eb59ad8a
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6699 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
43 lines
1.2 KiB
Ruby
43 lines
1.2 KiB
Ruby
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
|