зеркало из https://github.com/github/ruby.git
Update a test of SecureRandom according to r57384
SecureRandom uses urandom by default. So the test for a case where openssl is unavailable makes no sense. Instead, a simple test for a case where urandom is unavailable is added. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59801 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
0919c05501
Коммит
782b2050b8
|
@ -70,40 +70,6 @@ if false
|
|||
end
|
||||
end
|
||||
|
||||
def test_s_random_bytes_without_openssl
|
||||
begin
|
||||
require 'openssl'
|
||||
rescue LoadError
|
||||
return
|
||||
end
|
||||
begin
|
||||
load_path = $LOAD_PATH.dup
|
||||
loaded_features = $LOADED_FEATURES.dup
|
||||
openssl = Object.instance_eval { remove_const(:OpenSSL) }
|
||||
|
||||
remove_feature('securerandom.rb')
|
||||
remove_feature('openssl.rb')
|
||||
Dir.mktmpdir do |dir|
|
||||
open(File.join(dir, 'openssl.rb'), 'w') { |f|
|
||||
f << 'raise LoadError'
|
||||
}
|
||||
$LOAD_PATH.unshift(dir)
|
||||
v = $VERBOSE
|
||||
begin
|
||||
$VERBOSE = false
|
||||
require 'securerandom'
|
||||
ensure
|
||||
$VERBOSE = v
|
||||
end
|
||||
test_s_random_bytes
|
||||
end
|
||||
ensure
|
||||
$LOADED_FEATURES.replace(loaded_features)
|
||||
$LOAD_PATH.replace(load_path)
|
||||
Object.const_set(:OpenSSL, openssl)
|
||||
end
|
||||
end
|
||||
|
||||
def test_s_hex
|
||||
s = @it.hex
|
||||
assert_equal(16 * 2, s.size)
|
||||
|
@ -198,4 +164,16 @@ end
|
|||
def assert_in_range(range, result, mesg = nil)
|
||||
assert(range.cover?(result), message(mesg) {"Expected #{result} to be in #{range}"})
|
||||
end
|
||||
|
||||
def test_with_openssl
|
||||
begin
|
||||
require 'openssl'
|
||||
rescue LoadError
|
||||
return
|
||||
end
|
||||
assert_equal(Encoding::ASCII_8BIT, @it.send(:gen_random_openssl, 16).encoding)
|
||||
65.times do |idx|
|
||||
assert_equal(idx, @it.send(:gen_random_openssl, idx).size)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче