Sha256: fb1f5dbb84fb9b1f899269cd3b511df0d4006e33387fc9fc4eb5d99b36fabd99

Contents?: true

Size: 1.17 KB

Versions: 56

Compression:

Stored size: 1.17 KB

Contents

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

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
backlog-0.0.0 vendor/rails/actionpack/test/controller/http_authentication_test.rb
backlog-0.0.1 vendor/rails/actionpack/test/controller/http_authentication_test.rb
backlog-0.0.2 vendor/rails/actionpack/test/controller/http_authentication_test.rb
backlog-0.0.4 vendor/rails/actionpack/test/controller/http_authentication_test.rb
backlog-0.0.5 vendor/rails/actionpack/test/controller/http_authentication_test.rb
backlog-0.1.1 vendor/rails/actionpack/test/controller/http_authentication_test.rb
backlog-0.1.0 vendor/rails/actionpack/test/controller/http_authentication_test.rb
backlog-0.1.2 vendor/rails/actionpack/test/controller/http_authentication_test.rb
backlog-0.2.0 vendor/rails/actionpack/test/controller/http_authentication_test.rb
backlog-0.2.1 vendor/rails/actionpack/test/controller/http_authentication_test.rb
backlog-0.3.0 vendor/rails/actionpack/test/controller/http_authentication_test.rb
backlog-0.3.3 vendor/rails/actionpack/test/controller/http_authentication_test.rb
backlog-0.3.2 vendor/rails/actionpack/test/controller/http_authentication_test.rb
backlog-0.3.1 vendor/rails/actionpack/test/controller/http_authentication_test.rb
backlog-0.3.4 vendor/rails/actionpack/test/controller/http_authentication_test.rb
backlog-0.3.5 vendor/rails/actionpack/test/controller/http_authentication_test.rb
backlog-0.3.6 vendor/rails/actionpack/test/controller/http_authentication_test.rb
backlog-0.3.7 vendor/rails/actionpack/test/controller/http_authentication_test.rb
backlog-0.3.8 vendor/rails/actionpack/test/controller/http_authentication_test.rb
backlog-0.3.9 vendor/rails/actionpack/test/controller/http_authentication_test.rb