use private_methods and protected_methods instead of respond_to? to check
method visibility. [ruby-dev:26616] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
832e2b98f9
commit
6763ac5552
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
||||
Mon Aug 1 01:08:21 2005 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
|
||||
|
||||
* lib/drb/drb.rb (check_insecure_method): use private_methods and
|
||||
protected_methods instead of respond_to? to check method visibility.
|
||||
[ruby-dev:26616]
|
||||
|
||||
* test/drb/drbtest.rb: ditto.
|
||||
|
||||
* test/drb/ut_drb.rb: ditto.
|
||||
|
||||
Sat Jul 30 18:49:44 2005 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
||||
|
||||
* ext/win32ole/win32ole.c: add WIN32OLE_TYPE#ole_typelib,
|
||||
|
@ -1448,7 +1448,9 @@ module DRb
|
||||
# Coerce an object to a string, providing our own representation if
|
||||
# to_s is not defined for the object.
|
||||
def any_to_s(obj)
|
||||
obj.to_s rescue sprintf("#<%s:0x%lx>", obj.class, obj.__id__)
|
||||
obj.to_s + ":#{obj.class}"
|
||||
rescue
|
||||
sprintf("#<%s:0x%lx>", obj.class, obj.__id__)
|
||||
end
|
||||
|
||||
# Check that a method is callable via dRuby.
|
||||
@ -1463,22 +1465,19 @@ module DRb
|
||||
return true if Proc === obj && msg_id == :__drb_yield
|
||||
raise(ArgumentError, "#{any_to_s(msg_id)} is not a symbol") unless Symbol == msg_id.class
|
||||
raise(SecurityError, "insecure method `#{msg_id}'") if insecure_method?(msg_id)
|
||||
unless obj.respond_to?(msg_id)
|
||||
|
||||
if obj.private_methods.include?(msg_id.to_s)
|
||||
desc = any_to_s(obj)
|
||||
if desc.nil? || desc[0] == '#'
|
||||
desc << ":#{obj.class}"
|
||||
end
|
||||
|
||||
if obj.private_methods.include?(msg_id.to_s)
|
||||
raise NameError, "private method `#{msg_id}' called for #{desc}"
|
||||
else
|
||||
raise NameError, "undefined method `#{msg_id}' called for #{desc}"
|
||||
end
|
||||
raise NoMethodError, "private method `#{msg_id}' called for #{desc}"
|
||||
elsif obj.protected_methods.include?(msg_id.to_s)
|
||||
desc = any_to_s(obj)
|
||||
raise NoMethodError, "protected method `#{msg_id}' called for #{desc}"
|
||||
else
|
||||
true
|
||||
end
|
||||
true
|
||||
end
|
||||
public :check_insecure_method
|
||||
|
||||
|
||||
class InvokeMethod # :nodoc:
|
||||
def initialize(drb_server, client)
|
||||
@drb_server = drb_server
|
||||
|
@ -176,24 +176,42 @@ module DRbCore
|
||||
end
|
||||
end
|
||||
|
||||
def test_07_public_private
|
||||
def test_07_public_private_protected_missing
|
||||
assert_nothing_raised() {
|
||||
begin
|
||||
@there.method_missing(:eval)
|
||||
rescue NameError
|
||||
rescue NoMethodError
|
||||
assert_match(/^private method \`eval\'/, $!.message)
|
||||
end
|
||||
}
|
||||
assert_nothing_raised() {
|
||||
begin
|
||||
@there.call_private_method
|
||||
rescue NoMethodError
|
||||
assert_equal(NoMethodError, $!.class)
|
||||
assert_match(/^private method \`call_private_method\'/, $!.message)
|
||||
end
|
||||
}
|
||||
assert_nothing_raised() {
|
||||
begin
|
||||
@there.call_protected_method
|
||||
rescue NoMethodError
|
||||
assert_equal(NoMethodError, $!.class)
|
||||
assert_match(/^protected method \`call_protected_method\'/, $!.message)
|
||||
end
|
||||
}
|
||||
assert_nothing_raised() {
|
||||
begin
|
||||
@there.method_missing(:undefined_method_test)
|
||||
rescue NameError
|
||||
rescue NoMethodError
|
||||
assert_equal(NoMethodError, $!.class)
|
||||
assert_match(/^undefined method \`undefined_method_test\'/, $!.message)
|
||||
end
|
||||
}
|
||||
assert_raises(SecurityError) do
|
||||
@there.method_missing(:__send__, :to_s)
|
||||
end
|
||||
assert_equal(true, @there.missing)
|
||||
end
|
||||
|
||||
def test_08_here
|
||||
|
@ -126,10 +126,23 @@ class DRbEx
|
||||
[self]
|
||||
end
|
||||
|
||||
def method_missing(msg, *a, &b)
|
||||
if msg == :missing
|
||||
return true
|
||||
else
|
||||
super(msg, *a, &b)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def call_private_method
|
||||
true
|
||||
end
|
||||
|
||||
protected
|
||||
def call_protected_method
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
if __FILE__ == $0
|
||||
|
Loading…
x
Reference in New Issue
Block a user