Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Allow realm to be passed to auth handler's initialize method

Signed-off-by: Ryan Tomayko <rtomayko@gmail.com>
  • Loading branch information...
commit ebb03fac2da1eb4d6baa6fe676f3f9e67241d7e3 1 parent db1c378
Brian Candler authored February 26, 2009 rtomayko committed February 27, 2009
2  example/protectedlobster.ru
... ...
@@ -1,7 +1,7 @@
1 1
 require 'rack/lobster'
2 2
 
3 3
 use Rack::ShowExceptions
4  
-use Rack::Auth::Basic do |username, password|
  4
+use Rack::Auth::Basic, "Lobster 2.0" do |username, password|
5 5
   'secret' == password
6 6
 end
7 7
 
4  lib/rack/auth/abstract/handler.rb
@@ -8,8 +8,8 @@ class AbstractHandler
8 8
 
9 9
       attr_accessor :realm
10 10
 
11  
-      def initialize(app, &authenticator)
12  
-        @app, @authenticator = app, authenticator
  11
+      def initialize(app, realm=nil, &authenticator)
  12
+        @app, @realm, @authenticator = app, realm, authenticator
13 13
       end
14 14
 
15 15
 
2  lib/rack/auth/digest/md5.rb
@@ -21,7 +21,7 @@ class MD5 < AbstractHandler
21 21
 
22 22
         attr_writer :passwords_hashed
23 23
 
24  
-        def initialize(app)
  24
+        def initialize(*args)
25 25
           super
26 26
           @passwords_hashed = nil
27 27
         end
6  test/spec_rack_auth_basic.rb
@@ -35,7 +35,7 @@ def assert_basic_auth_challenge(response)
35 35
     response.should.be.a.client_error
36 36
     response.status.should.equal 401
37 37
     response.should.include 'WWW-Authenticate'
38  
-    response.headers['WWW-Authenticate'].should =~ /Basic realm="/
  38
+    response.headers['WWW-Authenticate'].should =~ /Basic realm="#{Regexp.escape(realm)}"/
39 39
     response.body.should.be.empty
40 40
   end
41 41
 
@@ -66,4 +66,8 @@ def assert_basic_auth_challenge(response)
66 66
     end
67 67
   end
68 68
 
  69
+  specify 'realm as optional constructor arg' do
  70
+    app = Rack::Auth::Basic.new(unprotected_app, realm) { true }
  71
+    assert_equal realm, app.realm
  72
+  end
69 73
 end
5  test/spec_rack_auth_digest.rb
@@ -218,4 +218,9 @@ def assert_bad_request(response)
218 218
       response.body.to_s.should.equal 'Hi Alice'
219 219
     end
220 220
   end
  221
+
  222
+  specify 'realm as optional constructor arg' do
  223
+    app = Rack::Auth::Digest::MD5.new(unprotected_app, realm) { true }
  224
+    assert_equal realm, app.realm
  225
+  end
221 226
 end

0 notes on commit ebb03fa

Please sign in to comment.
Something went wrong with that request. Please try again.