Skip to content
This repository
Browse code

Allow to generate a sid using another secure random provider

  • Loading branch information...
commit 585d88daed7d62752b7b64e3140f64006c830c71 1 parent ccfdaf3
Santiago Pastorino authored
2  lib/rack/session/abstract/id.rb
@@ -229,7 +229,7 @@ def initialize_sid
229 229
 
230 230
         def generate_sid(secure = @sid_secure)
231 231
           if secure
232  
-            SecureRandom.hex(@sid_length)
  232
+            secure.hex(@sid_length)
233 233
           else
234 234
             "%0#{@sid_length}x" % Kernel.rand(2**@sidbits - 1)
235 235
           end
12  test/spec_session_abstract_id.rb
@@ -40,4 +40,14 @@ def reload_id
40 40
     end
41 41
   end
42 42
 
43  
-end
  43
+  should "allow to use another securerandom provider" do
  44
+    secure_random = Class.new do
  45
+      def hex(*args)
  46
+        'fake_hex'
  47
+      end
  48
+    end
  49
+    id = Rack::Session::Abstract::ID.new nil, :secure_random => secure_random.new
  50
+    id.send(:generate_sid).should.eql 'fake_hex'
  51
+  end
  52
+
  53
+end

0 notes on commit 585d88d

Please sign in to comment.
Something went wrong with that request. Please try again.