Sha256: 940c1aeecc8c154d5804a0b862643709f85cc78e5ea5d809bbd76039c45418e9

Contents?: true

Size: 1.93 KB

Versions: 33

Compression:

Stored size: 1.93 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe ApplicationController do
  
  # ----------------- HTTP BASIC AUTH -----------------------
  describe ApplicationController, "with http basic auth features" do
    before(:all) do
      sorcery_reload!([:http_basic_auth])
      create_new_user
    end
    
    after(:each) do
      logout_user
    end
    
    it "requests basic authentication when before_filter is used" do
      get :test_http_basic_auth
      response.code.should == "401"
    end
    
    it "authenticates from http basic if credentials are sent" do
      @request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{@user.username}:secret")
      get :test_http_basic_auth, nil, :http_authentication_used => true
      response.should be_a_success
    end
    
    it "fails authentication if credentials are wrong" do
      @request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{@user.username}:wrong!")
      get :test_http_basic_auth, nil, :http_authentication_used => true
      response.code.should redirect_to root_url
    end
    
    it "should allow configuration option 'controller_to_realm_map'" do
      sorcery_controller_property_set(:controller_to_realm_map, {"1" => "2"})
      Sorcery::Controller::Config.controller_to_realm_map.should == {"1" => "2"}
    end
    
    it "should display the correct realm name configured for the controller" do
      sorcery_controller_property_set(:controller_to_realm_map, {"application" => "Salad"})
      get :test_http_basic_auth
      response.headers["WWW-Authenticate"].should == "Basic realm=\"Salad\""
    end
    
    it "should sign in the user's session on successful login" do
      @request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{@user.username}:secret")
      get :test_http_basic_auth, nil, :http_authentication_used => true
      session[:user_id].should == User.find_by_username(@user.username).id
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
sorcery-0.8.4 spec/rails3/spec/controller_http_basic_auth_spec.rb
sorcery-0.8.2 spec/rails3/spec/controller_http_basic_auth_spec.rb
sorcery-0.8.1 spec/rails3/spec/controller_http_basic_auth_spec.rb
sorcery-0.8.0 spec/rails3/spec/controller_http_basic_auth_spec.rb
sorcery-0.7.13 spec/rails3/spec/controller_http_basic_auth_spec.rb
sorcery-0.7.12 spec/rails3/spec/controller_http_basic_auth_spec.rb
sorcery-0.7.11 spec/rails3/spec/controller_http_basic_auth_spec.rb
sorcery-0.7.10 spec/rails3/spec/controller_http_basic_auth_spec.rb
sorcery-0.7.9 spec/rails3/spec/controller_http_basic_auth_spec.rb
sorcery-0.7.8 spec/rails3/spec/controller_http_basic_auth_spec.rb
sorcery-0.7.7 spec/rails3/spec/controller_http_basic_auth_spec.rb
sorcery-0.7.6 spec/rails3/spec/controller_http_basic_auth_spec.rb
sorcery-0.7.5 spec/rails3/spec/controller_http_basic_auth_spec.rb
sorcery-0.7.4 spec/rails3/spec/controller_http_basic_auth_spec.rb
sorcery-0.7.3 spec/rails3/spec/controller_http_basic_auth_spec.rb
sorcery-0.7.2 spec/rails3/spec/controller_http_basic_auth_spec.rb
sorcery-0.7.1 spec/rails3/spec/controller_http_basic_auth_spec.rb
sorcery-0.7.0 spec/rails3/spec/controller_http_basic_auth_spec.rb
sorcery-0.6.1 spec/rails3/spec/controller_http_basic_auth_spec.rb
sorcery-0.6.0 spec/rails3/spec/controller_http_basic_auth_spec.rb