Skip to content

Commit

Permalink
Allow to generate a sid using another secure random provider
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Oct 16, 2012
1 parent ccfdaf3 commit 585d88d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rack/session/abstract/id.rb
Expand Up @@ -229,7 +229,7 @@ def initialize_sid

def generate_sid(secure = @sid_secure)
if secure
SecureRandom.hex(@sid_length)
secure.hex(@sid_length)
else
"%0#{@sid_length}x" % Kernel.rand(2**@sidbits - 1)
end
Expand Down
12 changes: 11 additions & 1 deletion test/spec_session_abstract_id.rb
Expand Up @@ -40,4 +40,14 @@ def reload_id
end
end

end
should "allow to use another securerandom provider" do
secure_random = Class.new do
def hex(*args)
'fake_hex'
end
end
id = Rack::Session::Abstract::ID.new nil, :secure_random => secure_random.new
id.send(:generate_sid).should.eql 'fake_hex'
end

end

0 comments on commit 585d88d

Please sign in to comment.