From fcbf63e62c627deae76c1b8cb8c0876c536ed811 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 16 Mar 2020 18:49:26 +0900 Subject: Fresh start --- jni/ruby/test/xmlrpc/data/blog.xml | 18 ++ jni/ruby/test/xmlrpc/data/bug_bool.expected | 3 + jni/ruby/test/xmlrpc/data/bug_bool.xml | 8 + jni/ruby/test/xmlrpc/data/bug_cdata.expected | 3 + jni/ruby/test/xmlrpc/data/bug_cdata.xml | 8 + jni/ruby/test/xmlrpc/data/bug_covert.expected | 10 + jni/ruby/test/xmlrpc/data/bug_covert.xml | 6 + jni/ruby/test/xmlrpc/data/datetime_iso8601.xml | 8 + jni/ruby/test/xmlrpc/data/fault.xml | 16 ++ jni/ruby/test/xmlrpc/data/value.expected | 7 + jni/ruby/test/xmlrpc/data/value.xml | 22 ++ jni/ruby/test/xmlrpc/data/xml1.expected | 243 +++++++++++++++++++ jni/ruby/test/xmlrpc/data/xml1.xml | 1 + jni/ruby/test/xmlrpc/htpasswd | 2 + jni/ruby/test/xmlrpc/test_client.rb | 317 +++++++++++++++++++++++++ jni/ruby/test/xmlrpc/test_cookie.rb | 96 ++++++++ jni/ruby/test/xmlrpc/test_datetime.rb | 161 +++++++++++++ jni/ruby/test/xmlrpc/test_features.rb | 50 ++++ jni/ruby/test/xmlrpc/test_marshal.rb | 110 +++++++++ jni/ruby/test/xmlrpc/test_parser.rb | 93 ++++++++ jni/ruby/test/xmlrpc/test_webrick_server.rb | 135 +++++++++++ jni/ruby/test/xmlrpc/webrick_testing.rb | 55 +++++ 22 files changed, 1372 insertions(+) create mode 100644 jni/ruby/test/xmlrpc/data/blog.xml create mode 100644 jni/ruby/test/xmlrpc/data/bug_bool.expected create mode 100644 jni/ruby/test/xmlrpc/data/bug_bool.xml create mode 100644 jni/ruby/test/xmlrpc/data/bug_cdata.expected create mode 100644 jni/ruby/test/xmlrpc/data/bug_cdata.xml create mode 100644 jni/ruby/test/xmlrpc/data/bug_covert.expected create mode 100644 jni/ruby/test/xmlrpc/data/bug_covert.xml create mode 100644 jni/ruby/test/xmlrpc/data/datetime_iso8601.xml create mode 100644 jni/ruby/test/xmlrpc/data/fault.xml create mode 100644 jni/ruby/test/xmlrpc/data/value.expected create mode 100644 jni/ruby/test/xmlrpc/data/value.xml create mode 100644 jni/ruby/test/xmlrpc/data/xml1.expected create mode 100644 jni/ruby/test/xmlrpc/data/xml1.xml create mode 100644 jni/ruby/test/xmlrpc/htpasswd create mode 100644 jni/ruby/test/xmlrpc/test_client.rb create mode 100644 jni/ruby/test/xmlrpc/test_cookie.rb create mode 100644 jni/ruby/test/xmlrpc/test_datetime.rb create mode 100644 jni/ruby/test/xmlrpc/test_features.rb create mode 100644 jni/ruby/test/xmlrpc/test_marshal.rb create mode 100644 jni/ruby/test/xmlrpc/test_parser.rb create mode 100644 jni/ruby/test/xmlrpc/test_webrick_server.rb create mode 100644 jni/ruby/test/xmlrpc/webrick_testing.rb (limited to 'jni/ruby/test/xmlrpc') diff --git a/jni/ruby/test/xmlrpc/data/blog.xml b/jni/ruby/test/xmlrpc/data/blog.xml new file mode 100644 index 0000000..cb325f1 --- /dev/null +++ b/jni/ruby/test/xmlrpc/data/blog.xml @@ -0,0 +1,18 @@ + + + + + + + + isAdmin1 + urlhttp://tenderlovemaking.com/ + blogid1 + blogNameTender Lovemaking + xmlrpchttp://tenderlovemaking.com/xmlrpc.php + + + + + + diff --git a/jni/ruby/test/xmlrpc/data/bug_bool.expected b/jni/ruby/test/xmlrpc/data/bug_bool.expected new file mode 100644 index 0000000..121e3a8 --- /dev/null +++ b/jni/ruby/test/xmlrpc/data/bug_bool.expected @@ -0,0 +1,3 @@ +--- +- true +- false \ No newline at end of file diff --git a/jni/ruby/test/xmlrpc/data/bug_bool.xml b/jni/ruby/test/xmlrpc/data/bug_bool.xml new file mode 100644 index 0000000..04ed007 --- /dev/null +++ b/jni/ruby/test/xmlrpc/data/bug_bool.xml @@ -0,0 +1,8 @@ + + + + + 0 + + + diff --git a/jni/ruby/test/xmlrpc/data/bug_cdata.expected b/jni/ruby/test/xmlrpc/data/bug_cdata.expected new file mode 100644 index 0000000..17d7861 --- /dev/null +++ b/jni/ruby/test/xmlrpc/data/bug_cdata.expected @@ -0,0 +1,3 @@ +--- +- true +- test \ No newline at end of file diff --git a/jni/ruby/test/xmlrpc/data/bug_cdata.xml b/jni/ruby/test/xmlrpc/data/bug_cdata.xml new file mode 100644 index 0000000..ba990e0 --- /dev/null +++ b/jni/ruby/test/xmlrpc/data/bug_cdata.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/jni/ruby/test/xmlrpc/data/bug_covert.expected b/jni/ruby/test/xmlrpc/data/bug_covert.expected new file mode 100644 index 0000000..a9ac103 --- /dev/null +++ b/jni/ruby/test/xmlrpc/data/bug_covert.expected @@ -0,0 +1,10 @@ +--- +- true +- > + Site,SANs,Array + + Configured Capacity,Array Reserved Capacity,Array Ava + + ilable Capacity,Array % Reserved,Host Allocated,Host Used,Host Free,Host % + + Used diff --git a/jni/ruby/test/xmlrpc/data/bug_covert.xml b/jni/ruby/test/xmlrpc/data/bug_covert.xml new file mode 100644 index 0000000..1d9abd2 --- /dev/null +++ b/jni/ruby/test/xmlrpc/data/bug_covert.xml @@ -0,0 +1,6 @@ +Site,SANs,Array +Configured Capacity,Array Reserved Capacity,Array Ava +ilable Capacity,Array % Reserved,Host Allocated,Host Used,Host Free,Host % +Used + diff --git a/jni/ruby/test/xmlrpc/data/datetime_iso8601.xml b/jni/ruby/test/xmlrpc/data/datetime_iso8601.xml new file mode 100644 index 0000000..43d8da6 --- /dev/null +++ b/jni/ruby/test/xmlrpc/data/datetime_iso8601.xml @@ -0,0 +1,8 @@ + + + + + 20041105T01:15:23Z + + + diff --git a/jni/ruby/test/xmlrpc/data/fault.xml b/jni/ruby/test/xmlrpc/data/fault.xml new file mode 100644 index 0000000..041c464 --- /dev/null +++ b/jni/ruby/test/xmlrpc/data/fault.xml @@ -0,0 +1,16 @@ + + + + + + faultCode + 4 + + + faultString + an error message + + + + + diff --git a/jni/ruby/test/xmlrpc/data/value.expected b/jni/ruby/test/xmlrpc/data/value.expected new file mode 100644 index 0000000..9463d02 --- /dev/null +++ b/jni/ruby/test/xmlrpc/data/value.expected @@ -0,0 +1,7 @@ +--- +- Test +- + - Hallo Leute + - " Hallo " + - '' + - " " \ No newline at end of file diff --git a/jni/ruby/test/xmlrpc/data/value.xml b/jni/ruby/test/xmlrpc/data/value.xml new file mode 100644 index 0000000..1978616 --- /dev/null +++ b/jni/ruby/test/xmlrpc/data/value.xml @@ -0,0 +1,22 @@ + + + Test + + + Hallo Leute + + + Hallo + + + + + + + + + + + + + diff --git a/jni/ruby/test/xmlrpc/data/xml1.expected b/jni/ruby/test/xmlrpc/data/xml1.expected new file mode 100644 index 0000000..ff96de8 --- /dev/null +++ b/jni/ruby/test/xmlrpc/data/xml1.expected @@ -0,0 +1,243 @@ +--- +- true +- + - + subscriber: MegaCorp + lastName: Baker + telephone1: 1-508-791-1267 + telephone2: 1-800-445-2588 + password: p1111 + OID: "1" + email: hbaker@yahoo.com + adminId: hbaker + objectName: AdministratorDO + - + subscriber: CornerStore + lastName: Dragon + telephone1: 1-781-789-9089 + telephone2: 1-800-445-2588 + password: p3333 + OID: "3" + email: adragon@yahoo.com + adminId: adragon + objectName: AdministratorDO + - + subscriber: Cyberdyne + lastName: Rodman + telephone1: 1-617-789-1890 + telephone2: 1-800-445-2588 + password: p4444 + OID: "4" + email: mrodman@yahoo.com + adminId: mrodman + objectName: AdministratorDO + - + subscriber: StarSports + lastName: Jordan + telephone1: 1-617-890-7897 + telephone2: 1-800-445-2588 + password: p5555 + OID: "5" + email: mjordan@yahoo.com + adminId: mjordan + objectName: AdministratorDO + - + subscriber: GreatBooks + lastName: Pippen + telephone1: 1-781-789-9876 + telephone2: 1-800-445-2588 + password: p6666 + OID: "6" + email: gpippen@yahoo.com + adminId: gpippen + objectName: AdministratorDO + - + subscriber: AxisChemicals + lastName: Andhrew + telephone1: 1-781-678-8970 + telephone2: 1-800-445-2588 + password: p7777 + OID: "7" + email: aandrew@yahoo.com + adminId: aandrew + objectName: AdministratorDO + - + subscriber: MediaShop + lastName: Vincent + telephone1: 1-786-897-8908 + telephone2: 1-800-445-2588 + password: p8888 + OID: "8" + email: tvincent@yahoo.com + adminId: tvincent + objectName: AdministratorDO + - + subscriber: SmartShop + lastName: Richard + telephone1: 1-508-789-6789 + telephone2: 1-800-445-2588 + password: p9999 + OID: "9" + email: krichard@yahoo.com + adminId: krichard + objectName: AdministratorDO + - + subscriber: HomeNeeds + lastName: Cornell + telephone1: 1-617-789-8979 + telephone2: 1-800-445-2588 + password: paaaa + OID: "10" + email: gconell@yahoo.com + adminId: gcornell + objectName: AdministratorDO + - + subscriber: MegaCorp + lastName: HorstMann + telephone1: 1-508-791-1267 + telephone2: 1-800-445-2588 + password: p1111 + OID: "11" + email: shorstmann@yahoo.com + adminId: shorstmann + objectName: AdministratorDO + - + subscriber: CornerStore + lastName: Bob + telephone1: 1-781-789-9089 + telephone2: 1-800-445-2588 + password: p3333 + OID: "13" + email: rbob@yahoo.com + adminId: rbob + objectName: AdministratorDO + - + subscriber: Cyberdyne + lastName: Peter + telephone1: 1-617-789-1890 + telephone2: 1-800-445-2588 + password: p4444 + OID: "14" + email: speter@yahoo.com + adminId: speter + objectName: AdministratorDO + - + subscriber: StarSports + lastName: Novak + telephone1: 1-617-890-7897 + telephone2: 1-800-445-2588 + password: p5555 + OID: "15" + email: pnovak@yahoo.com + adminId: pnovak + objectName: AdministratorDO + - + subscriber: GreatBooks + lastName: Nancy + telephone1: 1-781-789-9876 + telephone2: 1-800-445-2588 + password: p6666 + OID: "16" + email: pnancy@yahoo.com + adminId: pnancy + objectName: AdministratorDO + - + subscriber: AxisChemicals + lastName: Michel + telephone1: 1-781-678-8970 + telephone2: 1-800-445-2588 + password: p7777 + OID: "17" + email: hmichel@yahoo.com + adminId: hmichel + objectName: AdministratorDO + - + subscriber: MediaShop + lastName: David + telephone1: 1-786-897-8908 + telephone2: 1-800-445-2588 + password: p8888 + OID: "18" + email: kdavid@yahoo.com + adminId: kdavid + objectName: AdministratorDO + - + subscriber: SmartShop + lastName: Valnoor + telephone1: 1-508-789-6789 + telephone2: 1-800-445-2588 + password: p9999 + OID: "19" + email: pvalnoor@yahoo.com + adminId: pvalnoor + objectName: AdministratorDO + - + subscriber: HomeNeeds + lastName: Smith + telephone1: 1-617-789-8979 + telephone2: 1-800-445-2588 + password: paaaa + OID: "20" + email: wsmith@yahoo.com + adminId: wsmith + objectName: AdministratorDO + - + subscriber: MegaCorp + lastName: Caral + telephone1: 1-781-789-9876 + telephone2: 1-800-445-2588 + password: p6666 + OID: "21" + email: gcaral@yahoo.com + adminId: gcaral + objectName: AdministratorDO + - + subscriber: CornerStore + lastName: Hillary + telephone1: 1-786-897-8908 + telephone2: 1-800-445-2588 + password: p8888 + OID: "23" + email: phillary@yahoo.com + adminId: phillary + objectName: AdministratorDO + - + subscriber: Cyberdyne + lastName: Philip + telephone1: 1-508-789-6789 + telephone2: 1-800-445-2588 + password: p9999 + OID: "24" + email: bphilip@yahoo.com + adminId: bphilip + objectName: AdministratorDO + - + subscriber: StarSports + lastName: Andrea + telephone1: 1-617-789-8979 + telephone2: 1-800-445-2588 + password: paaaa + OID: "25" + email: sandrea@yahoo.com + adminId: sandrea + objectName: AdministratorDO + - + subscriber: s4 + lastName: "null" + telephone1: "null" + telephone2: "null" + password: s4 + OID: "26" + email: "null" + adminId: s4 + objectName: AdministratorDO + - + subscriber: BigBank + lastName: administrator + telephone1: '' + telephone2: '' + password: admin + OID: "82" + email: '' + adminId: admin + objectName: AdministratorDO \ No newline at end of file diff --git a/jni/ruby/test/xmlrpc/data/xml1.xml b/jni/ruby/test/xmlrpc/data/xml1.xml new file mode 100644 index 0000000..10aa554 --- /dev/null +++ b/jni/ruby/test/xmlrpc/data/xml1.xml @@ -0,0 +1 @@ +objectNameAdministratorDOadminIdhbakeremailhbaker@yahoo.comtelephone21-800-445-2588telephone11-508-791-1267OID1passwordp1111lastNameBakersubscriberMegaCorpobjectNameAdministratorDOadminIdadragonemailadragon@yahoo.comtelephone21-800-445-2588telephone11-781-789-9089OID3passwordp3333lastNameDragonsubscriberCornerStoreobjectNameAdministratorDOadminIdmrodmanemailmrodman@yahoo.comtelephone21-800-445-2588telephone11-617-789-1890OID4passwordp4444lastNameRodmansubscriberCyberdyneobjectNameAdministratorDOadminIdmjordanemailmjordan@yahoo.comtelephone21-800-445-2588telephone11-617-890-7897OID5passwordp5555lastNameJordansubscriberStarSportsobjectNameAdministratorDOadminIdgpippenemailgpippen@yahoo.comtelephone21-800-445-2588telephone11-781-789-9876OID6passwordp6666lastNamePippensubscriberGreatBooksobjectNameAdministratorDOadminIdaandrewemailaandrew@yahoo.comtelephone21-800-445-2588telephone11-781-678-8970OID7passwordp7777lastNameAndhrewsubscriberAxisChemicalsobjectNameAdministratorDOadminIdtvincentemailtvincent@yahoo.comtelephone21-800-445-2588telephone11-786-897-8908OID8passwordp8888lastNameVincentsubscriberMediaShopobjectNameAdministratorDOadminIdkrichardemailkrichard@yahoo.comtelephone21-800-445-2588telephone11-508-789-6789OID9passwordp9999lastNameRichardsubscriberSmartShopobjectNameAdministratorDOadminIdgcornellemailgconell@yahoo.comtelephone21-800-445-2588telephone11-617-789-8979OID10passwordpaaaalastNameCornellsubscriberHomeNeedsobjectNameAdministratorDOadminIdshorstmannemailshorstmann@yahoo.comtelephone21-800-445-2588telephone11-508-791-1267OID11passwordp1111lastNameHorstMannsubscriberMegaCorpobjectNameAdministratorDOadminIdrbobemailrbob@yahoo.comtelephone21-800-445-2588telephone11-781-789-9089OID13passwordp3333lastNameBobsubscriberCornerStoreobjectNameAdministratorDOadminIdspeteremailspeter@yahoo.comtelephone21-800-445-2588telephone11-617-789-1890OID14passwordp4444lastNamePetersubscriberCyberdyneobjectNameAdministratorDOadminIdpnovakemailpnovak@yahoo.comtelephone21-800-445-2588telephone11-617-890-7897OID15passwordp5555lastNameNovaksubscriberStarSportsobjectNameAdministratorDOadminIdpnancyemailpnancy@yahoo.comtelephone21-800-445-2588telephone11-781-789-9876OID16passwordp6666lastNameNancysubscriberGreatBooksobjectNameAdministratorDOadminIdhmichelemailhmichel@yahoo.comtelephone21-800-445-2588telephone11-781-678-8970OID17passwordp7777lastNameMichelsubscriberAxisChemicalsobjectNameAdministratorDOadminIdkdavidemailkdavid@yahoo.comtelephone21-800-445-2588telephone11-786-897-8908OID18passwordp8888lastNameDavidsubscriberMediaShopobjectNameAdministratorDOadminIdpvalnooremailpvalnoor@yahoo.comtelephone21-800-445-2588telephone11-508-789-6789OID19passwordp9999lastNameValnoorsubscriberSmartShopobjectNameAdministratorDOadminIdwsmithemailwsmith@yahoo.comtelephone21-800-445-2588telephone11-617-789-8979OID20passwordpaaaalastNameSmithsubscriberHomeNeedsobjectNameAdministratorDOadminIdgcaralemailgcaral@yahoo.comtelephone21-800-445-2588telephone11-781-789-9876OID21passwordp6666lastNameCaralsubscriberMegaCorpobjectNameAdministratorDOadminIdphillaryemailphillary@yahoo.comtelephone21-800-445-2588telephone11-786-897-8908OID23passwordp8888lastNameHillarysubscriberCornerStoreobjectNameAdministratorDOadminIdbphilipemailbphilip@yahoo.comtelephone21-800-445-2588telephone11-508-789-6789OID24passwordp9999lastNamePhilipsubscriberCyberdyneobjectNameAdministratorDOadminIdsandreaemailsandrea@yahoo.comtelephone21-800-445-2588telephone11-617-789-8979OID25passwordpaaaalastNameAndreasubscriberStarSportsobjectNameAdministratorDOadminIds4emailnulltelephone2nulltelephone1nullOID26passwords4lastNamenullsubscribers4objectNameAdministratorDOadminIdadminemailtelephone2telephone1OID82passwordadminlastNameadministratorsubscriberBigBank diff --git a/jni/ruby/test/xmlrpc/htpasswd b/jni/ruby/test/xmlrpc/htpasswd new file mode 100644 index 0000000..898fc86 --- /dev/null +++ b/jni/ruby/test/xmlrpc/htpasswd @@ -0,0 +1,2 @@ +admin:Qg266hq/YYKe2 +01234567890123456789012345678901234567890123456789012345678901234567890123456789:Yl.SJmoFETpS2 diff --git a/jni/ruby/test/xmlrpc/test_client.rb b/jni/ruby/test/xmlrpc/test_client.rb new file mode 100644 index 0000000..83f8c6b --- /dev/null +++ b/jni/ruby/test/xmlrpc/test_client.rb @@ -0,0 +1,317 @@ +require 'minitest/autorun' +require 'xmlrpc/client' +require 'net/http' +begin + require 'openssl' +rescue LoadError +end + +module XMLRPC + class ClientTest < MiniTest::Unit::TestCase + module Fake + class HTTP + attr_accessor :read_timeout, :open_timeout, :use_ssl + + def initialize responses = {} + @started = false + @responses = responses + end + + def started? + @started + end + + def start + @started = true + if block_given? + begin + return yield(self) + ensure + @started = false + end + end + self + end + + def request_post path, request, headers + @responses[path].shift + end + end + + class Client < XMLRPC::Client + attr_reader :args, :http + + def initialize(*args) + @args = args + super + end + + private + def net_http host, port, proxy_host, proxy_port + HTTP.new + end + end + + class Response + def self.new body, fields = [], status = '200' + klass = Class.new(Net::HTTPResponse::CODE_TO_OBJ[status]) { + def initialize(*args) + super + @read = true + end + } + + resp = klass.new '1.1', status, 'OK' + resp.body = body + fields.each do |k,v| + resp.add_field k, v + end + resp + end + end + end + + def test_new2_host_path_port + client = Fake::Client.new2 'http://example.org/foo' + host, path, port, *rest = client.args + + assert_equal 'example.org', host + assert_equal '/foo', path + assert_equal 80, port + + rest.each { |x| refute x } + end + + def test_new2_custom_port + client = Fake::Client.new2 'http://example.org:1234/foo' + host, path, port, *rest = client.args + + assert_equal 'example.org', host + assert_equal '/foo', path + assert_equal 1234, port + + rest.each { |x| refute x } + end + + def test_new2_ssl + client = Fake::Client.new2 'https://example.org/foo' + host, path, port, proxy_host, proxy_port, user, password, use_ssl, timeout = client.args + + assert_equal 'example.org', host + assert_equal '/foo', path + assert_equal 443, port + assert use_ssl + + refute proxy_host + refute proxy_port + refute user + refute password + refute timeout + end if defined?(OpenSSL) + + def test_new2_ssl_custom_port + client = Fake::Client.new2 'https://example.org:1234/foo' + host, path, port, proxy_host, proxy_port, user, password, use_ssl, timeout = client.args + + assert_equal 'example.org', host + assert_equal '/foo', path + assert_equal 1234, port + assert use_ssl + + refute proxy_host + refute proxy_port + refute user + refute password + refute timeout + end if defined?(OpenSSL) + + def test_new2_user_password + client = Fake::Client.new2 'http://aaron:tenderlove@example.org/foo' + host, path, port, proxy_host, proxy_port, user, password, use_ssl, timeout = client.args + + [ host, path, port ].each { |x| assert x } + assert_equal 'aaron', user + assert_equal 'tenderlove', password + + [ proxy_host, proxy_port, use_ssl, timeout ].each { |x| refute x } + end + + def test_new2_proxy_host + client = Fake::Client.new2 'http://example.org/foo', 'example.com' + host, path, port, proxy_host, proxy_port, user, password, use_ssl, timeout = client.args + + [ host, path, port ].each { |x| assert x } + + assert_equal 'example.com', proxy_host + + [ user, password, proxy_port, use_ssl, timeout ].each { |x| refute x } + end + + def test_new2_proxy_port + client = Fake::Client.new2 'http://example.org/foo', 'example.com:1234' + host, path, port, proxy_host, proxy_port, user, password, use_ssl, timeout = client.args + + [ host, path, port ].each { |x| assert x } + + assert_equal 'example.com', proxy_host + assert_equal 1234, proxy_port + + [ user, password, use_ssl, timeout ].each { |x| refute x } + end + + def test_new2_no_path + client = Fake::Client.new2 'http://example.org' + host, path, port, *rest = client.args + + assert_equal 'example.org', host + assert_nil path + assert port + + rest.each { |x| refute x } + end + + def test_new2_slash_path + client = Fake::Client.new2 'http://example.org/' + host, path, port, *rest = client.args + + assert_equal 'example.org', host + assert_equal '/', path + assert port + + rest.each { |x| refute x } + end + + def test_new2_bad_protocol + assert_raises(ArgumentError) do + XMLRPC::Client.new2 'ftp://example.org' + end + end + + def test_new2_bad_uri + assert_raises(ArgumentError) do + XMLRPC::Client.new2 ':::::' + end + end + + def test_new2_path_with_query + client = Fake::Client.new2 'http://example.org/foo?bar=baz' + host, path, port, *rest = client.args + + assert_equal 'example.org', host + assert_equal '/foo?bar=baz', path + assert port + + rest.each { |x| refute x } + end + + def test_request + fh = read 'blog.xml' + + responses = { + '/foo' => [ Fake::Response.new(fh, [['Content-Type', 'text/xml']]) ] + } + + client = fake_client(responses).new2 'http://example.org/foo' + + resp = client.call('wp.getUsersBlogs', 'tlo', 'omg') + + expected = [{ + "isAdmin" => true, + "url" => "http://tenderlovemaking.com/", + "blogid" => "1", + "blogName" => "Tender Lovemaking", + "xmlrpc" => "http://tenderlovemaking.com/xmlrpc.php" + }] + + assert_equal expected, resp + end + + def test_async_request + fh = read 'blog.xml' + + responses = { + '/foo' => [ Fake::Response.new(fh, [['Content-Type', 'text/xml']]) ] + } + + client = fake_client(responses).new2 'http://example.org/foo' + + resp = client.call_async('wp.getUsersBlogs', 'tlo', 'omg') + + expected = [{ + "isAdmin" => true, + "url" => "http://tenderlovemaking.com/", + "blogid" => "1", + "blogName" => "Tender Lovemaking", + "xmlrpc" => "http://tenderlovemaking.com/xmlrpc.php" + }] + + assert_equal expected, resp + end + + # make a request without content-type header + def test_bad_content_type + fh = read 'blog.xml' + + responses = { + '/foo' => [ Fake::Response.new(fh) ] + } + + client = fake_client(responses).new2 'http://example.org/foo' + + resp = client.call('wp.getUsersBlogs', 'tlo', 'omg') + + expected = [{ + "isAdmin" => true, + "url" => "http://tenderlovemaking.com/", + "blogid" => "1", + "blogName" => "Tender Lovemaking", + "xmlrpc" => "http://tenderlovemaking.com/xmlrpc.php" + }] + + assert_equal expected, resp + end + + def test_i8_tag + fh = read('blog.xml').gsub(/string/, 'i8') + + responses = { + '/foo' => [ Fake::Response.new(fh) ] + } + + client = fake_client(responses).new2 'http://example.org/foo' + + resp = client.call('wp.getUsersBlogs', 'tlo', 'omg') + + assert_equal 1, resp.first['blogid'] + end + + def test_cookie_simple + client = Fake::Client.new2('http://example.org/cookie') + assert_nil(client.cookie) + client.send(:parse_set_cookies, ["param1=value1", "param2=value2"]) + assert_equal("param1=value1; param2=value2", client.cookie) + end + + def test_cookie_override + client = Fake::Client.new2('http://example.org/cookie') + client.send(:parse_set_cookies, + [ + "param1=value1", + "param2=value2", + "param1=value3", + ]) + assert_equal("param2=value2; param1=value3", client.cookie) + end + + private + def read filename + File.read File.expand_path(File.join(__FILE__, '..', 'data', filename)) + end + + def fake_client responses + Class.new(Fake::Client) { + define_method(:net_http) { |*_| Fake::HTTP.new(responses) } + } + end + end +end diff --git a/jni/ruby/test/xmlrpc/test_cookie.rb b/jni/ruby/test/xmlrpc/test_cookie.rb new file mode 100644 index 0000000..cfcfe4c --- /dev/null +++ b/jni/ruby/test/xmlrpc/test_cookie.rb @@ -0,0 +1,96 @@ +require 'test/unit' +require 'time' +require 'webrick' +require_relative 'webrick_testing' +require "xmlrpc/server" +require 'xmlrpc/client' + +module TestXMLRPC +class TestCookie < Test::Unit::TestCase + include WEBrick_Testing + + def create_servlet + s = XMLRPC::WEBrickServlet.new + + def s.logged_in_users + @logged_in_users ||= {} + end + def s.request + @request + end + def s.response + @response + end + def s.service(request, response) + @request = request + @response = response + super + ensure + @request = nil + @response = nil + end + + key = Time.now.to_i.to_s + valid_user = "valid-user" + s.add_handler("test.login") do |user, password| + ok = (user == valid_user and password == "secret") + if ok + s.logged_in_users[key] = user + expires = (Time.now + 60 * 60).httpdate + cookies = s.response.cookies + cookies << "key=\"#{key}\"; path=\"/RPC2\"; expires=#{expires}" + cookies << "user=\"#{user}\"; path=\"/RPC2\"" + end + ok + end + + s.add_handler("test.require_authenticate_echo") do |string| + cookies = {} + s.request.cookies.each do |cookie| + cookies[cookie.name] = cookie.value + end + if cookies == {"key" => key, "user" => valid_user} + string + else + raise XMLRPC::FaultException.new(29, "Authentication required") + end + end + + s.set_default_handler do |name, *args| + raise XMLRPC::FaultException.new(-99, "Method #{name} missing" + + " or wrong number of parameters!") + end + + s.add_introspection + + s + end + + def setup_http_server_option + option = {:Port => 0} + end + + def test_cookie + option = setup_http_server_option + with_server(option, create_servlet) {|addr| + begin + @s = XMLRPC::Client.new3(:host => addr.ip_address, :port => addr.ip_port) + do_test + ensure + @s.http.finish + end + } + end + + def do_test + assert(!@s.call("test.login", "invalid-user", "invalid-password")) + exception = assert_raise(XMLRPC::FaultException) do + @s.call("test.require_authenticate_echo", "Hello") + end + assert_equal(29, exception.faultCode) + + assert(@s.call("test.login", "valid-user", "secret")) + assert_equal("Hello", @s.call("test.require_authenticate_echo", "Hello")) + end +end +end diff --git a/jni/ruby/test/xmlrpc/test_datetime.rb b/jni/ruby/test/xmlrpc/test_datetime.rb new file mode 100644 index 0000000..d6bb95d --- /dev/null +++ b/jni/ruby/test/xmlrpc/test_datetime.rb @@ -0,0 +1,161 @@ +require 'test/unit' +require "xmlrpc/datetime" + +module TestXMLRPC +class Test_DateTime < Test::Unit::TestCase + + def test_new + dt = createDateTime() + + assert_instance_of(XMLRPC::DateTime, dt) + end + + def test_new_exception + assert_raise(ArgumentError) { XMLRPC::DateTime.new(4.5, 13, 32, 25, 60, 60) } + assert_raise(ArgumentError) { XMLRPC::DateTime.new(2001, 12, 32, 25, 60, 60) } + assert_raise(ArgumentError) { XMLRPC::DateTime.new(2001, 12, 31, 25, 60, 60) } + assert_raise(ArgumentError) { XMLRPC::DateTime.new(2001, 12, 31, 24, 60, 60) } + assert_raise(ArgumentError) { XMLRPC::DateTime.new(2001, 12, 31, 24, 59, 60) } + assert_nothing_raised(ArgumentError) { XMLRPC::DateTime.new(2001, 12, 31, 24, 59, 59) } + + assert_raise(ArgumentError) { XMLRPC::DateTime.new(2001, 0, 0, -1, -1, -1) } + assert_raise(ArgumentError) { XMLRPC::DateTime.new(2001, 1, 0, -1, -1, -1) } + assert_raise(ArgumentError) { XMLRPC::DateTime.new(2001, 1, 1, -1, -1, -1) } + assert_raise(ArgumentError) { XMLRPC::DateTime.new(2001, 1, 1, 0, -1, -1) } + assert_raise(ArgumentError) { XMLRPC::DateTime.new(2001, 1, 1, 0, 0, -1) } + assert_nothing_raised(ArgumentError) { XMLRPC::DateTime.new(2001, 1, 1, 0, 0, 0) } + end + + + def test_get_values + y, m, d, h, mi, s = 1970, 3, 24, 12, 0, 5 + dt = XMLRPC::DateTime.new(y, m, d, h, mi, s) + + assert_equal(y, dt.year) + assert_equal(m, dt.month) + assert_equal(m, dt.mon) + assert_equal(d, dt.day) + + assert_equal(h, dt.hour) + assert_equal(mi,dt.min) + assert_equal(s, dt.sec) + end + + def test_set_values + dt = createDateTime() + y, m, d, h, mi, s = 1950, 12, 9, 8, 52, 30 + + dt.year = y + dt.month = m + dt.day = d + dt.hour = h + dt.min = mi + dt.sec = s + + assert_equal(y, dt.year) + assert_equal(m, dt.month) + assert_equal(m, dt.mon) + assert_equal(d, dt.day) + + assert_equal(h, dt.hour) + assert_equal(mi,dt.min) + assert_equal(s, dt.sec) + + dt.mon = 5 + assert_equal(5, dt.month) + assert_equal(5, dt.mon) + end + + def test_set_exception + dt = createDateTime() + + assert_raise(ArgumentError) { dt.year = 4.5 } + assert_nothing_raised(ArgumentError) { dt.year = -2000 } + + assert_raise(ArgumentError) { dt.month = 0 } + assert_raise(ArgumentError) { dt.month = 13 } + assert_nothing_raised(ArgumentError) { dt.month = 7 } + + assert_raise(ArgumentError) { dt.mon = 0 } + assert_raise(ArgumentError) { dt.mon = 13 } + assert_nothing_raised(ArgumentError) { dt.mon = 7 } + + assert_raise(ArgumentError) { dt.day = 0 } + assert_raise(ArgumentError) { dt.day = 32 } + assert_nothing_raised(ArgumentError) { dt.day = 16 } + + assert_raise(ArgumentError) { dt.hour = -1 } + assert_raise(ArgumentError) { dt.hour = 25 } + assert_nothing_raised(ArgumentError) { dt.hour = 12 } + + assert_raise(ArgumentError) { dt.min = -1 } + assert_raise(ArgumentError) { dt.min = 60 } + assert_nothing_raised(ArgumentError) { dt.min = 30 } + + assert_raise(ArgumentError) { dt.sec = -1 } + assert_raise(ArgumentError) { dt.sec = 60 } + assert_nothing_raised(ArgumentError) { dt.sec = 30 } + end + + def test_to_a + y, m, d, h, mi, s = 1970, 3, 24, 12, 0, 5 + dt = XMLRPC::DateTime.new(y, m, d, h, mi, s) + a = dt.to_a + + assert_instance_of(Array, a) + assert_equal(6, a.size, "Returned array has wrong size") + + assert_equal(y, a[0]) + assert_equal(m, a[1]) + assert_equal(d, a[2]) + assert_equal(h, a[3]) + assert_equal(mi, a[4]) + assert_equal(s, a[5]) + end + + def test_to_time1 + y, m, d, h, mi, s = 1970, 3, 24, 12, 0, 5 + dt = XMLRPC::DateTime.new(y, m, d, h, mi, s) + time = dt.to_time + + assert_not_nil(time) + + assert_equal(y, time.year) + assert_equal(m, time.month) + assert_equal(d, time.day) + assert_equal(h, time.hour) + assert_equal(mi, time.min) + assert_equal(s, time.sec) + end + + def test_to_time2 + dt = createDateTime() + dt.year = 1969 + + assert_nil(dt.to_time) + end + + def test_to_date1 + y, m, d, h, mi, s = 1970, 3, 24, 12, 0, 5 + dt = XMLRPC::DateTime.new(y, m, d, h, mi, s) + date = dt.to_date + + assert_equal(y, date.year) + assert_equal(m, date.month) + assert_equal(d, date.day) + end + + def test_to_date2 + dt = createDateTime() + dt.year = 666 + + assert_equal(666, dt.to_date.year) + end + + + def createDateTime + XMLRPC::DateTime.new(1970, 3, 24, 12, 0, 5) + end + +end +end diff --git a/jni/ruby/test/xmlrpc/test_features.rb b/jni/ruby/test/xmlrpc/test_features.rb new file mode 100644 index 0000000..48bb0d4 --- /dev/null +++ b/jni/ruby/test/xmlrpc/test_features.rb @@ -0,0 +1,50 @@ +require 'test/unit' +require "xmlrpc/create" +require "xmlrpc/parser" +require "xmlrpc/config" + +module TestXMLRPC +class Test_Features < Test::Unit::TestCase + + def setup + @params = [nil, {"test" => nil}, [nil, 1, nil]] + end + + def test_nil_create + XMLRPC::XMLWriter.each_installed_writer do |writer| + c = XMLRPC::Create.new(writer) + + XMLRPC::Config.module_eval {remove_const(:ENABLE_NIL_CREATE)} + XMLRPC::Config.const_set(:ENABLE_NIL_CREATE, false) + assert_raise(RuntimeError) { c.methodCall("test", *@params) } + + XMLRPC::Config.module_eval {remove_const(:ENABLE_NIL_CREATE)} + XMLRPC::Config.const_set(:ENABLE_NIL_CREATE, true) + assert_nothing_raised { c.methodCall("test", *@params) } + end + end + + def test_nil_parse + XMLRPC::Config.module_eval {remove_const(:ENABLE_NIL_CREATE)} + XMLRPC::Config.const_set(:ENABLE_NIL_CREATE, true) + + XMLRPC::XMLWriter.each_installed_writer do |writer| + c = XMLRPC::Create.new(writer) + str = c.methodCall("test", *@params) + XMLRPC::XMLParser.each_installed_parser do |parser| + para = nil + + XMLRPC::Config.module_eval {remove_const(:ENABLE_NIL_PARSER)} + XMLRPC::Config.const_set(:ENABLE_NIL_PARSER, false) + assert_raise(RuntimeError) { para = parser.parseMethodCall(str) } + + XMLRPC::Config.module_eval {remove_const(:ENABLE_NIL_PARSER)} + XMLRPC::Config.const_set(:ENABLE_NIL_PARSER, true) + assert_nothing_raised { para = parser.parseMethodCall(str) } + assert_equal(para[1], @params) + end + end + end + +end +end diff --git a/jni/ruby/test/xmlrpc/test_marshal.rb b/jni/ruby/test/xmlrpc/test_marshal.rb new file mode 100644 index 0000000..34ddfa9 --- /dev/null +++ b/jni/ruby/test/xmlrpc/test_marshal.rb @@ -0,0 +1,110 @@ +require 'test/unit' +require "xmlrpc/marshal" + +module TestXMLRPC +class Test_Marshal < Test::Unit::TestCase + # for test_parser_values + class Person + include XMLRPC::Marshallable + attr_reader :name + def initialize(name) + @name = name + end + end + + + def test1_dump_response + assert_nothing_raised(NameError) { + XMLRPC::Marshal.dump_response('arg') + } + end + + def test1_dump_call + assert_nothing_raised(NameError) { + XMLRPC::Marshal.dump_call('methodName', 'arg') + } + end + + def test2_dump_load_response + value = [1, 2, 3, {"test" => true}, 3.4] + res = XMLRPC::Marshal.dump_response(value) + + assert_equal(value, XMLRPC::Marshal.load_response(res)) + end + + def test2_dump_load_call + methodName = "testMethod" + value = [1, 2, 3, {"test" => true}, 3.4] + exp = [methodName, [value, value]] + + res = XMLRPC::Marshal.dump_call(methodName, value, value) + + assert_equal(exp, XMLRPC::Marshal.load_call(res)) + end + + def test_parser_values + v1 = [ + 1, -7778, -(2**31), 2**31-1, # integers + 1.0, 0.0, -333.0, 2343434343.0, # floats + false, true, true, false, # booleans + "Hallo", "with < and >", "" # strings + ] + + v2 = [ + [v1, v1, v1], + {"a" => v1} + ] + + v3 = [ + XMLRPC::Base64.new("\001"*1000), # base64 + :aSymbol, :anotherSym # symbols (-> string) + ] + v3_exp = [ + "\001"*1000, + "aSymbol", "anotherSym" + ] + person = Person.new("Michael") + + XMLRPC::XMLParser.each_installed_parser do |parser| + m = XMLRPC::Marshal.new(parser) + + assert_equal( v1, m.load_response(m.dump_response(v1)) ) + assert_equal( v2, m.load_response(m.dump_response(v2)) ) + assert_equal( v3_exp, m.load_response(m.dump_response(v3)) ) + + pers = m.load_response(m.dump_response(person)) + + assert( pers.is_a?(Person) ) + assert( person.name == pers.name ) + end + + # missing, Date, Time, DateTime + # Struct + end + + def test_parser_invalid_values + values = [ + -1-(2**31), 2**31, + Float::INFINITY, -Float::INFINITY, Float::NAN + ] + XMLRPC::XMLParser.each_installed_parser do |parser| + m = XMLRPC::Marshal.new(parser) + + values.each do |v| + assert_raise(RuntimeError, "#{v} shouldn't be dumped, but dumped") \ + { m.dump_response(v) } + end + end + end + + def test_no_params_tag + # bug found by Idan Sofer + + expect = %{myMethod\n} + + str = XMLRPC::Marshal.dump_call("myMethod") + assert_equal(expect, str) + end + +end +end diff --git a/jni/ruby/test/xmlrpc/test_parser.rb b/jni/ruby/test/xmlrpc/test_parser.rb new file mode 100644 index 0000000..5591645 --- /dev/null +++ b/jni/ruby/test/xmlrpc/test_parser.rb @@ -0,0 +1,93 @@ +require 'test/unit' +require 'xmlrpc/datetime' +require "xmlrpc/parser" +require 'yaml' + +module TestXMLRPC +module GenericParserTest + def datafile(base) + File.join(File.dirname(__FILE__), "data", base) + end + + def load_data(name) + [File.read(datafile(name) + ".xml"), YAML.load(File.read(datafile(name) + ".expected"))] + end + + def setup + @xml1, @expected1 = load_data('xml1') + @xml2, @expected2 = load_data('bug_covert') + @xml3, @expected3 = load_data('bug_bool') + @xml4, @expected4 = load_data('value') + + @cdata_xml, @cdata_expected = load_data('bug_cdata') + + @datetime_xml = File.read(datafile('datetime_iso8601.xml')) + @datetime_expected = XMLRPC::DateTime.new(2004, 11, 5, 1, 15, 23) + + @fault_doc = File.read(datafile('fault.xml')) + end + + # test parseMethodResponse -------------------------------------------------- + + def test_parseMethodResponse1 + assert_equal(@expected1, @p.parseMethodResponse(@xml1)) + end + + def test_parseMethodResponse2 + assert_equal(@expected2, @p.parseMethodResponse(@xml2)) + end + + def test_parseMethodResponse3 + assert_equal(@expected3, @p.parseMethodResponse(@xml3)) + end + + def test_cdata + assert_equal(@cdata_expected, @p.parseMethodResponse(@cdata_xml)) + end + + def test_dateTime + assert_equal(@datetime_expected, @p.parseMethodResponse(@datetime_xml)[1]) + end + + # test parseMethodCall ------------------------------------------------------ + + def test_parseMethodCall + assert_equal(@expected4, @p.parseMethodCall(@xml4)) + end + + # test fault ---------------------------------------------------------------- + + def test_fault + flag, fault = @p.parseMethodResponse(@fault_doc) + assert_equal(flag, false) + unless fault.is_a? XMLRPC::FaultException + assert(false, "must be an instance of class XMLRPC::FaultException") + end + assert_equal(fault.faultCode, 4) + assert_equal(fault.faultString, "an error message") + end + + def test_fault_message + fault = XMLRPC::FaultException.new(1234, 'an error message') + assert_equal('an error message', fault.to_s) + assert_equal('#', fault.inspect) + end +end + +# create test class for each installed parser +XMLRPC::XMLParser.each_installed_parser do |parser| + klass = parser.class + name = klass.to_s.split("::").last + + eval %{ + class Test_#{name} < Test::Unit::TestCase + include GenericParserTest + + def setup + super + @p = #{klass}.new + end + end + } +end +end diff --git a/jni/ruby/test/xmlrpc/test_webrick_server.rb b/jni/ruby/test/xmlrpc/test_webrick_server.rb new file mode 100644 index 0000000..bc10239 --- /dev/null +++ b/jni/ruby/test/xmlrpc/test_webrick_server.rb @@ -0,0 +1,135 @@ +# coding: utf-8 + +require 'test/unit' +require 'webrick' +require_relative 'webrick_testing' +require "xmlrpc/server" +require 'xmlrpc/client' +require 'logger' + +module TestXMLRPC +class Test_Webrick < Test::Unit::TestCase + include WEBrick_Testing + + def create_servlet(server) + s = XMLRPC::WEBrickServlet.new + + basic_auth = WEBrick::HTTPAuth::BasicAuth.new( + :Realm => 'auth', + :UserDB => WEBrick::HTTPAuth::Htpasswd.new(File.expand_path('./htpasswd', File.dirname(__FILE__))), + :Logger => server.logger, + ) + + class << s; self end.send(:define_method, :service) {|req, res| + basic_auth.authenticate(req, res) + super(req, res) + } + + s.add_handler("test.add") do |a,b| + a + b + end + + s.add_handler("test.div") do |a,b| + if b == 0 + raise XMLRPC::FaultException.new(1, "division by zero") + else + a / b + end + end + + s.set_default_handler do |name, *args| + raise XMLRPC::FaultException.new(-99, "Method #{name} missing" + + " or wrong number of parameters!") + end + + s.add_introspection + + return s + end + + def setup_http_server_option(use_ssl) + option = { + :BindAddress => "localhost", + :Port => 0, + :SSLEnable => use_ssl, + } + if use_ssl + require 'webrick/https' + option.update( + :SSLVerifyClient => ::OpenSSL::SSL::VERIFY_NONE, + :SSLCertName => [] + ) + end + + option + end + + def test_client_server + # NOTE: I don't enable SSL testing as this hangs + [false].each do |use_ssl| + option = setup_http_server_option(use_ssl) + with_server(option, method(:create_servlet)) {|addr| + @s = XMLRPC::Client.new3(:host => addr.ip_address, :port => addr.ip_port, :use_ssl => use_ssl) + @s.user = 'admin' + @s.password = 'admin' + silent do + do_test + end + @s.http.finish + @s = XMLRPC::Client.new3(:host => addr.ip_address, :port => addr.ip_port, :use_ssl => use_ssl) + @s.user = '01234567890123456789012345678901234567890123456789012345678901234567890123456789' + @s.password = 'guest' + silent do + do_test + end + @s.http.finish + } + end + end + + def silent + begin + back, $VERBOSE = $VERBOSE, nil + yield + ensure + $VERBOSE = back + end + end + + def do_test + # simple call + assert_equal 9, @s.call('test.add', 4, 5) + + # fault exception + assert_raise(XMLRPC::FaultException) { @s.call('test.div', 1, 0) } + + # fault exception via call2 + ok, param = @s.call2('test.div', 1, 0) + assert_equal false, ok + assert_instance_of XMLRPC::FaultException, param + assert_equal 1, param.faultCode + assert_equal 'division by zero', param.faultString + + # call2 without fault exception + ok, param = @s.call2('test.div', 10, 5) + assert_equal true, ok + assert_equal param, 2 + + # introspection + assert_equal ["test.add", "test.div", "system.listMethods", "system.methodSignature", "system.methodHelp"], @s.call("system.listMethods") + + # default handler (missing handler) + ok, param = @s.call2('test.nonexisting') + assert_equal false, ok + assert_equal(-99, param.faultCode) + + # default handler (wrong number of arguments) + ok, param = @s.call2('test.add', 1, 2, 3) + assert_equal false, ok + assert_equal(-99, param.faultCode) + + # multibyte characters + assert_equal "あいうえおかきくけこ", @s.call('test.add', "あいうえお", "かきくけこ") + end +end +end diff --git a/jni/ruby/test/xmlrpc/webrick_testing.rb b/jni/ruby/test/xmlrpc/webrick_testing.rb new file mode 100644 index 0000000..37c0b69 --- /dev/null +++ b/jni/ruby/test/xmlrpc/webrick_testing.rb @@ -0,0 +1,55 @@ +require 'timeout' + +module TestXMLRPC +module WEBrick_Testing + def start_server(logger, config={}) + raise "already started" if defined?(@__server) && @__server + @__started = false + + @__server = WEBrick::HTTPServer.new( + { + :BindAddress => "localhost", + :Logger => logger, + :AccessLog => [], + }.update(config)) + yield @__server + @__started = true + + addr = @__server.listeners.first.connect_address + + @__server_thread = Thread.new { + begin + @__server.start + rescue IOError => e + assert_match(/closed/, e.message) + ensure + @__started = false + end + } + + addr + end + + def with_server(config, servlet) + log = [] + logger = WEBrick::Log.new(log, WEBrick::BasicLog::WARN) + addr = start_server(logger, config) {|w| + servlet = servlet.call(w) if servlet.respond_to? :call + w.mount('/RPC2', servlet) + } + client_thread = Thread.new { + begin + yield addr + ensure + @__server.shutdown + end + } + server_thread = Thread.new { + @__server_thread.join + @__server = nil + assert_equal([], log) + } + assert_join_threads([client_thread, server_thread]) + end +end +end -- cgit v1.2.3-70-g09d2