Permalink
Browse files

Merge pull request #441 from spastorino/master

Allow to generate a sid using another secure random provider
  • Loading branch information...
2 parents ccfdaf3 + 585d88d commit 869c4c346a2b6bfd55a41947039b5b217b57d398 @rkh rkh committed Oct 16, 2012
Showing with 12 additions and 2 deletions.
  1. +1 −1 lib/rack/session/abstract/id.rb
  2. +11 −1 test/spec_session_abstract_id.rb
@@ -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
@@ -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 869c4c3

Please sign in to comment.