Sha256: 4fb13343a23a73e3fdbd1f4bfd5075e87c1dba86b0da537e9476aafde7eea234

Contents?: true

Size: 1.29 KB

Versions: 126

Compression:

Stored size: 1.29 KB

Contents

### WARNING: there be hax in this file.

require 'rack/session/abstract/id'

describe Rack::Session::Abstract::ID do
  id = Rack::Session::Abstract::ID

  def silence_warning
    o, $VERBOSE = $VERBOSE, nil
    yield
  ensure
    $VERBOSE = o
  end

  def reload_id
    $".delete $".find { |part| part =~ %r{session/abstract/id.rb} }
    silence_warning { require 'rack/session/abstract/id' }
  end

  should "use securerandom when available" do
    begin
      fake = false
      silence_warning do
        ::SecureRandom = fake = true unless defined?(SecureRandom)
      end
      reload_id
      id::DEFAULT_OPTIONS[:secure_random].should.eql(fake || SecureRandom)
    ensure
      Object.send(:remove_const, :SecureRandom) if fake
    end
  end

  should "not use securerandom when unavailable" do
    begin
      sr = Object.send(:remove_const, :SecureRandom) if defined?(SecureRandom)
      reload_id
      id::DEFAULT_OPTIONS[:secure_random].should.eql false
    ensure
      ::SecureRandom = sr if defined?(sr)
    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

Version data entries

126 entries across 110 versions & 31 rubygems

Version Path
rack-1.6.0 test/spec_session_abstract_id.rb
rack-1.6.0.beta2 test/spec_session_abstract_id.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/test/spec_session_abstract_id.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/test/spec_session_abstract_id.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/test/spec_session_abstract_id.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/test/spec_session_abstract_id.rb
nanumfont-rails-0.1 vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/test/spec_session_abstract_id.rb
rack-1.6.0.beta test/spec_session_abstract_id.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/test/spec_session_abstract_id.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/rack-1.5.2/test/spec_session_abstract_id.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/rack-1.5.2/test/spec_session_abstract_id.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/rack-1.5.2/test/spec_session_abstract_id.rb
torquebox-console-0.3.0 vendor/bundle/jruby/1.9/gems/rack-1.5.2/test/spec_session_abstract_id.rb
challah-1.0.0 vendor/bundle/gems/rack-1.5.2/test/spec_session_abstract_id.rb
torquebox-console-0.2.5 vendor/bundle/jruby/1.9/gems/rack-1.5.2/test/spec_session_abstract_id.rb
torquebox-console-0.2.5 vendor/bundle/ruby/1.8/gems/rack-1.5.2/test/spec_session_abstract_id.rb
vagrant-actionio-0.0.9 vendor/bundle/gems/rack-1.5.2/test/spec_session_abstract_id.rb
torquebox-console-0.2.4 vendor/bundle/ruby/1.8/gems/rack-1.5.2/test/spec_session_abstract_id.rb
torquebox-console-0.2.4 vendor/bundle/jruby/1.9/gems/rack-1.5.2/test/spec_session_abstract_id.rb
torquebox-console-0.2.3 vendor/bundle/jruby/1.9/gems/rack-1.5.2/test/spec_session_abstract_id.rb