Changeset 5666
- Timestamp:
- 12/03/06 00:41:22 (2 years ago)
- Files:
-
- plugins/http_authentication/lib/http_authentication/basic.rb (modified) (2 diffs)
- plugins/http_authentication/README (modified) (1 diff)
- plugins/http_authentication/test/http_authentication_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/http_authentication/lib/http_authentication/basic.rb
r5665 r5666 28 28 29 29 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) 35 31 end 36 32 … … 40 36 request.env['X_HTTP_AUTHORIZATION'] 41 37 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 43 47 def authentication_request(controller, realm) 44 48 controller.headers["WWW-Authenticate"] = %(Basic realm="#{realm.gsub(/"/, "")}") plugins/http_authentication/README
r5665 r5666 59 59 60 60 61 In 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 61 72 Todo: 62 73 plugins/http_authentication/test/http_authentication_test.rb
r5665 r5666 17 17 Class.new do 18 18 def env 19 { 'HTTP_AUTHORIZATION' => "Basic " + Base64.encode64("dhh:secret") }19 { 'HTTP_AUTHORIZATION' => HttpAuthentication::Basic.encode_credentials("dhh", "secret") } 20 20 end 21 21 end.new