Skip to content

Commit

Permalink
fix visibility of SecureRandom.gen_random
Browse files Browse the repository at this point in the history
Aliasing a method preserves its visibility.  These aliases turn
formerly-public methods into private.  Should make them public
again.  [Bug #15847]
  • Loading branch information
shyouhei committed May 14, 2019
1 parent af1f3f1 commit 5bab130
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/securerandom.rb
Expand Up @@ -85,6 +85,7 @@ def gen_random(n)
class << self
remove_method :gen_random
alias gen_random gen_random_openssl
public :gen_random
end
end
return gen_random(n)
Expand All @@ -94,6 +95,7 @@ class << self
class << self
remove_method :gen_random
alias gen_random gen_random_urandom
public :gen_random
end
end
return gen_random(n)
Expand Down
7 changes: 7 additions & 0 deletions test/test_securerandom.rb
Expand Up @@ -184,4 +184,11 @@ def test_with_openssl
assert_equal(idx, @it.send(:gen_random_openssl, idx).size)
end
end

def test_repeated_gen_random
assert_nothing_raised NoMethodError, '[ruby-core:92633] [Bug #15847]' do
@it.gen_random(1)
@it.gen_random(1)
end
end
end

0 comments on commit 5bab130

Please sign in to comment.