1 # frozen_string_literal: false
4 require_relative 'ruby/test_random_formatter'
6 # This testcase does NOT aim to test cryptographically strongness and randomness.
7 class TestSecureRandom < Test::Unit::TestCase
8 include Random::Formatter::FormatterTest
9 include Random::Formatter::NotDefaultTest
15 # This test took 2 minutes on my machine.
16 # And 65536 times loop could not be enough for forcing PID recycle.
18 def test_s_random_bytes_is_fork_safe
24 SecureRandom.random_bytes(8)
25 pid, v1 = forking_random_bytes
26 assert(check_forking_random_bytes(pid, v1), 'Process ID not recycled?')
29 def forking_random_bytes
33 w.write SecureRandom.random_bytes(8)
43 def check_forking_random_bytes(target_pid, target)
47 v2 = SecureRandom.random_bytes(8)
56 pid, status = Process.waitpid2(pid)
57 case status.exitstatus
59 raise 'returned same sequence for same PID'
74 assert_equal(Encoding::ASCII_8BIT, @it.send(:gen_random_openssl, 16).encoding)
76 assert_equal(idx, @it.send(:gen_random_openssl, idx).size)
80 def test_repeated_gen_random
81 assert_nothing_raised NoMethodError, '[ruby-core:92633] [Bug #15847]' do