Skip to content

Commit

Permalink
Allow realm to be passed to auth handler's initialize method
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Tomayko <rtomayko@gmail.com>
  • Loading branch information
candlerb authored and rtomayko committed Feb 27, 2009
1 parent db1c378 commit ebb03fa
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 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

Expand Down
4 changes: 2 additions & 2 deletions lib/rack/auth/abstract/handler.rb
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion lib/rack/auth/digest/md5.rb
Expand Up @@ -21,7 +21,7 @@ class MD5 < AbstractHandler

attr_writer :passwords_hashed

def initialize(app)
def initialize(*args)
super
@passwords_hashed = nil
end
Expand Down
6 changes: 5 additions & 1 deletion test/spec_rack_auth_basic.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions test/spec_rack_auth_digest.rb
Expand Up @@ -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.