Sha256: f89266c131bbc43a8dd53d5fd7a774d4b2e39f808ac2fddc77512fc760a81ebf
Contents?: true
Size: 1.89 KB
Versions: 4
Compression:
Stored size: 1.89 KB
Contents
# Copyright: Copyright (c) 2004 Nicolas Despres. All rights reserved. # Author: Nicolas Despres <polrop@lrde.epita.fr>. # License: Gnu General Public License. # $LastChangedBy: polrop $ # $Id: insecure_protected_methods.rb 88 2005-01-09 21:11:26Z polrop $ require 'drb/drb' module DRb class DRbServer alias_method :ori_check_insecure_method, :check_insecure_method def check_insecure_method(obj, msg_id) ori_check_insecure_method(obj, msg_id) if obj.protected_methods.include?(msg_id.to_s) desc = any_to_s(obj) if desc.nil? || desc[0] == '#' desc << ":#{obj.class}" end raise NameError, "protected method `#{msg_id}' called for #{desc}" end true end end # class DRbServer end # module DRb # # Unit test suite # if defined? TEST_MODE or $0 == __FILE__ require 'test/unit/ui/yaml/testrunner' module DRb class InsecureProtectedMethodsTest < Test::Unit::TestCase class SrvFoo def public_request end protected def protected_request end end # class Foo def setup rd, wr = IO.pipe unless @srv_pid = fork # son rd.close DRb.start_service("druby://localhost:42000", SrvFoo.new) wr.puts('ready') wr.close DRb.thread.join else # father wr.close rd.gets @drb_srv = DRb.start_service @drb_obj = DRbObject.new(nil, "druby://localhost:42000") rd.close end end def teardown @drb_srv.stop_service Process.kill('TERM', @srv_pid) Process.waitpid(@srv_pid) end # # Test # def test_simple assert_raises(NameError) { @drb_obj.send(:protected_resquest) } assert_nothing_raised { @drb_obj.public_request } end # # Tools # def server_request(req) end end # class InsecureProtectedMethodsTest end # module DRb end
Version data entries
4 entries across 4 versions & 2 rubygems