aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_securerandom.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_securerandom.rb')
-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