Skip to content

Commit

Permalink
Merge pull request rack#406 from dayflower/fix-time-limit
Browse files Browse the repository at this point in the history
Fix request loop on non-stale nonce with time_limit parameter.
  • Loading branch information
raggi committed Aug 26, 2012
2 parents 5a4c691 + 4f81156 commit d749c46
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rack/auth/digest/nonce.rb
Expand Up @@ -38,7 +38,7 @@ def valid?
end

def stale?
!self.class.time_limit.nil? && (@timestamp - Time.now.to_i) < self.class.time_limit
!self.class.time_limit.nil? && (Time.now.to_i - @timestamp) > self.class.time_limit
end

def fresh?
Expand Down
14 changes: 14 additions & 0 deletions test/spec_auth_digest.rb
Expand Up @@ -153,6 +153,20 @@ def assert_bad_request(response)
end
end

should 'not rechallenge if nonce is not stale' do
begin
Rack::Auth::Digest::Nonce.time_limit = 10

request_with_digest_auth 'GET', '/', 'Alice', 'correct-password', :wait => 1 do |response|
response.status.should.equal 200
response.body.to_s.should.equal 'Hi Alice'
response.headers['WWW-Authenticate'].should.not =~ /\bstale=true\b/
end
ensure
Rack::Auth::Digest::Nonce.time_limit = nil
end
end

should 'rechallenge with stale parameter if nonce is stale' do
begin
Rack::Auth::Digest::Nonce.time_limit = 1
Expand Down

0 comments on commit d749c46

Please sign in to comment.