Replace references to ActiveSupport::SecureRandom with just SecureRandom, and require 'securerandom' from the stdlib when active support is required.
This commit is contained in:
parent
a5fb1c6175
commit
d411c85a65
|
@ -96,7 +96,7 @@ module ActionController #:nodoc:
|
|||
|
||||
# Sets the token value for the current session.
|
||||
def form_authenticity_token
|
||||
session[:_csrf_token] ||= ActiveSupport::SecureRandom.base64(32)
|
||||
session[:_csrf_token] ||= SecureRandom.base64(32)
|
||||
end
|
||||
|
||||
# The form's authenticity parameter. Override to provide your own.
|
||||
|
|
|
@ -130,7 +130,7 @@ module ActionController
|
|||
super
|
||||
|
||||
self.session = TestSession.new
|
||||
self.session_options = TestSession::DEFAULT_OPTIONS.merge(:id => ActiveSupport::SecureRandom.hex(16))
|
||||
self.session_options = TestSession::DEFAULT_OPTIONS.merge(:id => SecureRandom.hex(16))
|
||||
end
|
||||
|
||||
class Result < ::Array #:nodoc:
|
||||
|
|
|
@ -305,7 +305,7 @@ module ActionDispatch
|
|||
|
||||
if secret.length < SECRET_MIN_LENGTH
|
||||
raise ArgumentError, "Secret should be something secure, " +
|
||||
"like \"#{ActiveSupport::SecureRandom.hex(16)}\". The value you " +
|
||||
"like \"#{SecureRandom.hex(16)}\". The value you " +
|
||||
"provided, \"#{secret}\", is shorter than the minimum length " +
|
||||
"of #{SECRET_MIN_LENGTH} characters"
|
||||
end
|
||||
|
|
|
@ -29,7 +29,7 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def generate_sid
|
||||
sid = ActiveSupport::SecureRandom.hex(16)
|
||||
sid = SecureRandom.hex(16)
|
||||
sid.encode!('UTF-8') if sid.respond_to?(:encode!)
|
||||
sid
|
||||
end
|
||||
|
|
|
@ -80,7 +80,7 @@ module RequestForgeryProtectionTests
|
|||
def setup
|
||||
@token = "cf50faa3fe97702ca1ae"
|
||||
|
||||
ActiveSupport::SecureRandom.stubs(:base64).returns(@token)
|
||||
SecureRandom.stubs(:base64).returns(@token)
|
||||
ActionController::Base.request_forgery_protection_token = :custom_authenticity_token
|
||||
end
|
||||
|
||||
|
@ -184,7 +184,7 @@ class RequestForgeryProtectionControllerTest < ActionController::TestCase
|
|||
end
|
||||
|
||||
test 'should emit a csrf-param meta tag and a csrf-token meta tag' do
|
||||
ActiveSupport::SecureRandom.stubs(:base64).returns(@token + '<=?')
|
||||
SecureRandom.stubs(:base64).returns(@token + '<=?')
|
||||
get :meta
|
||||
assert_select 'meta[name=?][content=?]', 'csrf-param', 'custom_authenticity_token'
|
||||
assert_select 'meta[name=?][content=?]', 'csrf-token', 'cf50faa3fe97702ca1ae<=?'
|
||||
|
@ -207,7 +207,7 @@ class FreeCookieControllerTest < ActionController::TestCase
|
|||
@response = ActionController::TestResponse.new
|
||||
@token = "cf50faa3fe97702ca1ae"
|
||||
|
||||
ActiveSupport::SecureRandom.stubs(:base64).returns(@token)
|
||||
SecureRandom.stubs(:base64).returns(@token)
|
||||
end
|
||||
|
||||
def test_should_not_render_form_with_token_tag
|
||||
|
|
|
@ -6,7 +6,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest
|
|||
SessionSecret = 'b3c631c314c0bbca50c1b2843150fe33'
|
||||
|
||||
Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, 'SHA1')
|
||||
SignedBar = Verifier.generate(:foo => "bar", :session_id => ActiveSupport::SecureRandom.hex(16))
|
||||
SignedBar = Verifier.generate(:foo => "bar", :session_id => SecureRandom.hex(16))
|
||||
|
||||
class TestController < ActionController::Base
|
||||
def no_session_access
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
#++
|
||||
|
||||
require 'securerandom'
|
||||
|
||||
module ActiveSupport
|
||||
class << self
|
||||
attr_accessor :load_all_hooks
|
||||
|
@ -30,7 +32,7 @@ module ActiveSupport
|
|||
self.load_all_hooks = []
|
||||
|
||||
on_load_all do
|
||||
[Dependencies, Deprecation, Gzip, MessageVerifier, Multibyte, SecureRandom]
|
||||
[Dependencies, Deprecation, Gzip, MessageVerifier, Multibyte]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ require 'active_support/time'
|
|||
|
||||
class MessageEncryptorTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@encryptor = ActiveSupport::MessageEncryptor.new(ActiveSupport::SecureRandom.hex(64))
|
||||
@encryptor = ActiveSupport::MessageEncryptor.new(SecureRandom.hex(64))
|
||||
@data = { :some => "data", :now => Time.local(2010) }
|
||||
end
|
||||
|
||||
|
|
|
@ -215,7 +215,7 @@ module Notifications
|
|||
|
||||
protected
|
||||
def random_id
|
||||
@random_id ||= ActiveSupport::SecureRandom.hex(10)
|
||||
@random_id ||= SecureRandom.hex(10)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,18 +2,18 @@ require 'abstract_unit'
|
|||
|
||||
class SecureRandomTest < Test::Unit::TestCase
|
||||
def test_random_bytes
|
||||
b1 = ActiveSupport::SecureRandom.random_bytes(64)
|
||||
b2 = ActiveSupport::SecureRandom.random_bytes(64)
|
||||
b1 = SecureRandom.random_bytes(64)
|
||||
b2 = SecureRandom.random_bytes(64)
|
||||
assert_not_equal b1, b2
|
||||
end
|
||||
|
||||
def test_hex
|
||||
b1 = ActiveSupport::SecureRandom.hex(64)
|
||||
b2 = ActiveSupport::SecureRandom.hex(64)
|
||||
b1 = SecureRandom.hex(64)
|
||||
b2 = SecureRandom.hex(64)
|
||||
assert_not_equal b1, b2
|
||||
end
|
||||
|
||||
def test_random_number
|
||||
assert ActiveSupport::SecureRandom.random_number(5000) < 5000
|
||||
assert SecureRandom.random_number(5000) < 5000
|
||||
end
|
||||
end
|
||||
|
|
|
@ -272,7 +272,7 @@ module Rails
|
|||
end
|
||||
|
||||
def app_secret
|
||||
ActiveSupport::SecureRandom.hex(64)
|
||||
SecureRandom.hex(64)
|
||||
end
|
||||
|
||||
def mysql_socket
|
||||
|
|
|
@ -10,7 +10,7 @@ end
|
|||
desc 'Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions).'
|
||||
task :secret do
|
||||
require 'active_support/secure_random'
|
||||
puts ActiveSupport::SecureRandom.hex(64)
|
||||
puts SecureRandom.hex(64)
|
||||
end
|
||||
|
||||
desc 'List versions of all Rails frameworks and the environment'
|
||||
|
|
|
@ -16,7 +16,7 @@ module ApplicationTests
|
|||
class ExpiresController < ApplicationController
|
||||
def expires_header
|
||||
expires_in 10, :public => !params[:private]
|
||||
render :text => ActiveSupport::SecureRandom.hex(16)
|
||||
render :text => SecureRandom.hex(16)
|
||||
end
|
||||
|
||||
def expires_etag
|
||||
|
@ -30,7 +30,7 @@ module ApplicationTests
|
|||
private
|
||||
def render_conditionally(headers)
|
||||
if stale?(headers.merge(:public => !params[:private]))
|
||||
render :text => ActiveSupport::SecureRandom.hex(16)
|
||||
render :text => SecureRandom.hex(16)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue