mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-21 09:40:13 +01:00
Changes you will need to make: * In your environment.rb, you will need to update references to a few files per environment.rb.tmpl * In your environment.rb, you will need to specify the local time zone of the computer that is running your Tracks install. Other notes on my changes: * Modified our code to take advantage of Rails 2.1's slick time zone support. * Upgraded will_paginate for compatibility * Hacked the Selenium on Rails plugin, which has not been updated in some time and does not support Rails 2.1 * Verified that all tests pass on my machine, including Selenium tests -- I'd like confirmation from others, too.
54 lines
1.5 KiB
Ruby
54 lines
1.5 KiB
Ruby
require 'abstract_unit'
|
|
|
|
class HttpBasicAuthenticationTest < Test::Unit::TestCase
|
|
include ActionController::HttpAuthentication::Basic
|
|
|
|
class DummyController
|
|
attr_accessor :headers, :renders, :request
|
|
|
|
def initialize
|
|
@headers, @renders = {}, []
|
|
@request = ActionController::TestRequest.new
|
|
end
|
|
|
|
def render(options)
|
|
self.renders << options
|
|
end
|
|
end
|
|
|
|
def setup
|
|
@controller = DummyController.new
|
|
@credentials = ActionController::HttpAuthentication::Basic.encode_credentials("dhh", "secret")
|
|
end
|
|
|
|
def test_successful_authentication
|
|
login = Proc.new { |user_name, password| user_name == "dhh" && password == "secret" }
|
|
set_headers
|
|
assert authenticate(@controller, &login)
|
|
|
|
set_headers ''
|
|
assert_nothing_raised do
|
|
assert !authenticate(@controller, &login)
|
|
end
|
|
|
|
set_headers nil
|
|
set_headers @credentials, 'REDIRECT_X_HTTP_AUTHORIZATION'
|
|
assert authenticate(@controller, &login)
|
|
end
|
|
|
|
def test_failing_authentication
|
|
set_headers
|
|
assert !authenticate(@controller) { |user_name, password| user_name == "dhh" && password == "incorrect" }
|
|
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
|
|
|
|
private
|
|
def set_headers(value = @credentials, name = 'HTTP_AUTHORIZATION')
|
|
@controller.request.env[name] = value
|
|
end
|
|
end
|