From 782b2050b837206d06767d42d0ea5117921247c8 Mon Sep 17 00:00:00 2001 From: mame Date: Sat, 9 Sep 2017 15:12:10 +0000 Subject: 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 --- test/test_securerandom.rb | 46 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) (limited to 'test/test_securerandom.rb') 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 -- cgit v1.2.3