Sha256: 6b914fcf0d01cffa7f6f508436fe0a2565223440f7287b05c7a4344a224da616

Contents?: true

Size: 1.82 KB

Versions: 22

Compression:

Stored size: 1.82 KB

Contents

require 'test/test_helper'

class HttpAuthenticationTest < ActionController::IntegrationTest

  test 'sign in should authenticate with http' do
    sign_in_as_new_user_with_http
    assert_response :success
    assert_template 'users/index'
    assert_contain 'Welcome'
    assert warden.authenticated?(:user)
  end

  test 'returns a custom response with www-authenticate header on failures' do
    sign_in_as_new_user_with_http("unknown")
    assert_equal 401, status
    assert_equal 'Basic realm="Application"', headers["WWW-Authenticate"]
  end

  test 'uses the request format as response content type' do
    sign_in_as_new_user_with_http("unknown", "123456", :xml)
    assert_equal 401, status
    assert_equal "application/xml", headers["Content-Type"]
    # Cannot assert this due to a bug between integration tests and rack on 2.3
    # assert response.body.include?("<error>HTTP Basic: Access denied.</error>")
  end

  test 'returns a custom response with www-authenticate and chosen realm' do
    swap Devise, :http_authentication_realm => "MyApp" do
      sign_in_as_new_user_with_http("unknown")
      assert_equal 401, status
      assert_equal 'Basic realm="MyApp"', headers["WWW-Authenticate"]
    end
  end

  test 'sign in should authenticate with http even with specific authentication keys' do
    swap Devise, :authentication_keys => [:username] do
      sign_in_as_new_user_with_http "usertest"
      assert_response :success
      assert_template 'users/index'
      assert_contain 'Welcome'
      assert warden.authenticated?(:user)
    end
  end

  private

    def sign_in_as_new_user_with_http(username="user@test.com", password="123456", format=:html)
      user = create_user
      get users_path(:format => format), {}, :authorization => "Basic #{ActiveSupport::Base64.encode64("#{username}:#{password}")}"
      user
    end
end

Version data entries

22 entries across 17 versions & 5 rubygems

Version Path
graffititracker_devise-1.0.11 test/integration/http_authenticatable_test.rb
devise-1.0.11 test/integration/http_authenticatable_test.rb
devise-1.0.10 test/integration/http_authenticatable_test.rb
devise_ennder-1.4.1.0.9 test/rails_app/vendor/plugins/devise/test/integration/http_authenticatable_test.rb
devise_ennder-1.4.1.0.9 test/integration/http_authenticatable_test.rb
devise_ennder-1.3.1.0.9 test/rails_app/vendor/plugins/devise/test/integration/http_authenticatable_test.rb
devise_ennder-1.3.1.0.9 test/integration/http_authenticatable_test.rb
devise_ennder-1.2.1.0.9 test/rails_app/vendor/plugins/devise/test/integration/http_authenticatable_test.rb
devise_ennder-1.2.1.0.9 test/integration/http_authenticatable_test.rb
devise_ennder-1.1.1.0.9 test/rails_app/vendor/plugins/devise/test/integration/http_authenticatable_test.rb
devise_ennder-1.1.1.0.9 test/integration/http_authenticatable_test.rb
devise_ennder-1.0.1.0.9 test/integration/http_authenticatable_test.rb
devise_ennder-1.0.1.0.9 test/rails_app/vendor/plugins/devise/test/integration/http_authenticatable_test.rb
devise-1.0.9 test/integration/http_authenticatable_test.rb
dcu-devise-1.0.7 test/integration/http_authenticatable_test.rb
devise-1.0.8 test/integration/http_authenticatable_test.rb
ivanvc-devise-1.0.7.1 test/integration/http_authenticatable_test.rb
devise-1.0.7 test/integration/http_authenticatable_test.rb
devise-1.0.6 test/integration/http_authenticatable_test.rb
devise-1.0.5 test/integration/http_authenticatable_test.rb