[前][次][番号順一覧][スレッド一覧]

ruby-changes:47685

From: mame <ko1@a...>
Date: Sun, 10 Sep 2017 00:12:15 +0900 (JST)
Subject: [ruby-changes:47685] mame:r59801 (trunk): Update a test of SecureRandom according to r57384

mame	2017-09-10 00:12:10 +0900 (Sun, 10 Sep 2017)

  New Revision: 59801

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59801

  Log:
    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.

  Modified files:
    trunk/test/test_securerandom.rb
Index: test/test_securerandom.rb
===================================================================
--- test/test_securerandom.rb	(revision 59800)
+++ test/test_securerandom.rb	(revision 59801)
@@ -70,40 +70,6 @@ if false https://github.com/ruby/ruby/blob/trunk/test/test_securerandom.rb#L70
   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 https://github.com/ruby/ruby/blob/trunk/test/test_securerandom.rb#L164
   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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]