Permalink
Browse files

Allow to generate a sid using another secure random provider

  • Loading branch information...
1 parent ccfdaf3 commit 585d88daed7d62752b7b64e3140f64006c830c71 @spastorino spastorino 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 585d88d

Please sign in to comment.