Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 5666

Show
Ignore:
Timestamp:
12/03/06 00:41:22 (2 years ago)
Author:
david
Message:

Added HttpAuthentication::Basic.encode_credentials to assist with testing

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/http_authentication/lib/http_authentication/basic.rb

    r5665 r5666  
    2828 
    2929    def user_name_and_password(request) 
    30       Base64.decode64(credentials(request)).split(/:/, 2) 
    31     end 
    32    
    33     def credentials(request) 
    34       authorization(request).split.last 
     30      decode_credentials(request).split(/:/, 2) 
    3531    end 
    3632   
     
    4036      request.env['X_HTTP_AUTHORIZATION'] 
    4137    end 
    42    
     38     
     39    def decode_credentials(request) 
     40      Base64.decode64(authorization(request).split.last) 
     41    end 
     42 
     43    def encode_credentials(user_name, password) 
     44      "Basic #{Base64.encode64("#{user_name}:#{password}")}" 
     45    end 
     46 
    4347    def authentication_request(controller, realm) 
    4448      controller.headers["WWW-Authenticate"] = %(Basic realm="#{realm.gsub(/"/, "")}") 
  • plugins/http_authentication/README

    r5665 r5666  
    5959 
    6060 
     61In your integration tests, you can do something like this: 
     62   
     63  def test_access_granted_from_xml 
     64    get( 
     65      "/notes/1.xml", nil,  
     66      :authorization => HttpAuthentication::Basic.encode_credentials(users(:dhh).name, users(:dhh).password) 
     67    ) 
     68 
     69    assert_equal 200, status 
     70  end 
     71 
    6172Todo: 
    6273 
  • plugins/http_authentication/test/http_authentication_test.rb

    r5665 r5666  
    1717        Class.new do 
    1818          def env 
    19             { 'HTTP_AUTHORIZATION' => "Basic " + Base64.encode64("dhh:secret") } 
     19            { 'HTTP_AUTHORIZATION' => HttpAuthentication::Basic.encode_credentials("dhh", "secret") } 
    2020          end 
    2121        end.new