summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-09 15:12:10 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-09 15:12:10 +0000
commit782b2050b837206d06767d42d0ea5117921247c8 (patch)
treeef1d817f62369a9e88e33df751bf06ab7498790c
parent0919c05501c6fca8733af06863517b88643c2910 (diff)
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
-rw-r--r--test/test_securerandom.rb46
1 files changed, 12 insertions, 34 deletions
diff --git a/test/test_securerandom.rb b/test/test_securerandom.rb
index cd5cb1dee2..f2cc7f553b 100644
--- a/test/test_securerandom.rb
+++ b/test/test_securerandom.rb
@@ -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