mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Secret key generator. You are gone.
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
require 'active_support/deprecation'
|
||||
|
||||
module Rails
|
||||
# A class for creating random secret keys. This class will do its best to create a
|
||||
# random secret key that's as secure as possible, using whatever methods are
|
||||
# available on the current platform. For example:
|
||||
#
|
||||
# generator = Rails::SecretKeyGenerator("some unique identifier, such as the application name")
|
||||
# generator.generate_secret # => "f3f1be90053fa851... (some long string)"
|
||||
#
|
||||
# This class is *deprecated* in Rails 2.2 in favor of ActiveSupport::SecureRandom.
|
||||
# It is currently a wrapper around ActiveSupport::SecureRandom.
|
||||
class SecretKeyGenerator
|
||||
def initialize(identifier)
|
||||
end
|
||||
|
||||
# Generate a random secret key with the best possible method available on
|
||||
# the current platform.
|
||||
def generate_secret
|
||||
ActiveSupport::SecureRandom.hex(64)
|
||||
end
|
||||
deprecate :generate_secret=>"You should use ActiveSupport::SecureRandom.hex(64)"
|
||||
end
|
||||
end
|
||||
@@ -1,38 +0,0 @@
|
||||
require 'abstract_unit'
|
||||
|
||||
# Must set before requiring generator libs.
|
||||
if defined?(RAILS_ROOT)
|
||||
RAILS_ROOT.replace "#{File.dirname(__FILE__)}/fixtures"
|
||||
else
|
||||
RAILS_ROOT = "#{File.dirname(__FILE__)}/fixtures"
|
||||
end
|
||||
|
||||
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
||||
|
||||
require 'initializer'
|
||||
|
||||
# Mocks out the configuration
|
||||
module Rails
|
||||
def self.configuration
|
||||
Rails::Configuration.new
|
||||
end
|
||||
end
|
||||
|
||||
require 'rails_generator'
|
||||
require 'rails_generator/secret_key_generator'
|
||||
require 'rails_generator/generators/applications/app/app_generator'
|
||||
|
||||
class SecretKeyGenerationTest < ActiveSupport::TestCase
|
||||
SECRET_KEY_MIN_LENGTH = 128
|
||||
APP_NAME = "foo"
|
||||
|
||||
def setup
|
||||
@generator = Rails::SecretKeyGenerator.new(APP_NAME)
|
||||
end
|
||||
|
||||
def test_secret_key_generation
|
||||
assert_deprecated /ActiveSupport::SecureRandom\.hex\(64\)/ do
|
||||
assert @generator.generate_secret.length >= SECRET_KEY_MIN_LENGTH
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user