Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@candlerb candlerb authored rtomayko committed
View
2  example/protectedlobster.ru
@@ -1,7 +1,7 @@
require 'rack/lobster'
use Rack::ShowExceptions
-use Rack::Auth::Basic do |username, password|
+use Rack::Auth::Basic, "Lobster 2.0" do |username, password|
'secret' == password
end
View
4 lib/rack/auth/abstract/handler.rb
@@ -8,8 +8,8 @@ class AbstractHandler
attr_accessor :realm
- def initialize(app, &authenticator)
- @app, @authenticator = app, authenticator
+ def initialize(app, realm=nil, &authenticator)
+ @app, @realm, @authenticator = app, realm, authenticator
end
View
2  lib/rack/auth/digest/md5.rb
@@ -21,7 +21,7 @@ class MD5 < AbstractHandler
attr_writer :passwords_hashed
- def initialize(app)
+ def initialize(*args)
super
@passwords_hashed = nil
end
View
6 test/spec_rack_auth_basic.rb
@@ -35,7 +35,7 @@ def assert_basic_auth_challenge(response)
response.should.be.a.client_error
response.status.should.equal 401
response.should.include 'WWW-Authenticate'
- response.headers['WWW-Authenticate'].should =~ /Basic realm="/
+ response.headers['WWW-Authenticate'].should =~ /Basic realm="#{Regexp.escape(realm)}"/
response.body.should.be.empty
end
@@ -66,4 +66,8 @@ def assert_basic_auth_challenge(response)
end
end
+ specify 'realm as optional constructor arg' do
+ app = Rack::Auth::Basic.new(unprotected_app, realm) { true }
+ assert_equal realm, app.realm
+ end
end
View
5 test/spec_rack_auth_digest.rb
@@ -218,4 +218,9 @@ def assert_bad_request(response)
response.body.to_s.should.equal 'Hi Alice'
end
end
+
+ specify 'realm as optional constructor arg' do
+ app = Rack::Auth::Digest::MD5.new(unprotected_app, realm) { true }
+ assert_equal realm, app.realm
+ end
end

0 comments on commit ebb03fa

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