From df731e37a1953755edfedd1462995fa824ca22bf Mon Sep 17 00:00:00 2001 From: nahi Date: Sat, 3 Jul 2004 13:33:20 +0000 Subject: * added files: * lib/soap/header/* * lib/soap/rpc/httpserver.rb * lib/wsdl/soap/cgiStubCreator.rb * lib/wsdl/soap/classDefCreator.rb * lib/wsdl/soap/classDefCreatorSupport.rb * lib/wsdl/soap/clientSkeltonCreator.rb * lib/wsdl/soap/driverCreator.rb * lib/wsdl/soap/mappingRegistryCreator.rb * lib/wsdl/soap/methodDefCreator.rb * lib/wsdl/soap/servantSkeltonCreator.rb * lib/wsdl/soap/standaloneServerStubCreator.rb * lib/wsdl/xmlSchema/enumeration.rb * lib/wsdl/xmlSchema/simpleRestriction.rb * lib/wsdl/xmlSchema/simpleType.rb * lib/xsd/codegen/* * lib/xsd/codegen.rb * sample/soap/authheader/* * sample/soap/raa2.4/* * sample/soap/ssl/* * sample/soap/swa/* * sample/soap/whois.rb * sample/wsdl/raa2.4/* * test/soap/header/* * test/soap/ssl/* * test/soap/struct/* * test/soap/swa/* * test/soap/wsdlDriver/* * test/wsdl/multiplefault.wsdl * test/wsdl/simpletype/* * test/wsdl/test_multiplefault.rb * modified files: * lib/soap/baseData.rb * lib/soap/element.rb * lib/soap/generator.rb * lib/soap/netHttpClient.rb * lib/soap/parser.rb * lib/soap/property.rb * lib/soap/soap.rb * lib/soap/streamHandler.rb * lib/soap/wsdlDriver.rb * lib/soap/wsdlDriver.rb * lib/soap/encodingstyle/handler.rb * lib/soap/encodingstyle/literalHandler.rb * lib/soap/encodingstyle/soapHandler.rb * lib/soap/mapping/factory.rb * lib/soap/mapping/mapping.rb * lib/soap/mapping/registry.rb * lib/soap/mapping/rubytypeFactory.rb * lib/soap/mapping/wsdlRegistry.rb * lib/soap/rpc/cgistub.rb * lib/soap/rpc/driver.rb * lib/soap/rpc/proxy.rb * lib/soap/rpc/router.rb * lib/soap/rpc/soaplet.rb * lib/soap/rpc/standaloneServer.rb * lib/wsdl/data.rb * lib/wsdl/definitions.rb * lib/wsdl/operation.rb * lib/wsdl/parser.rb * lib/wsdl/soap/definitions.rb * lib/wsdl/xmlSchema/complexContent.rb * lib/wsdl/xmlSchema/complexType.rb * lib/wsdl/xmlSchema/data.rb * lib/wsdl/xmlSchema/parser.rb * lib/wsdl/xmlSchema/schema.rb * lib/xsd/datatypes.rb * lib/xsd/qname.rb * sample/soap/sampleStruct/server.rb * sample/wsdl/amazon/AmazonSearch.rb * sample/wsdl/amazon/AmazonSearchDriver.rb * test/soap/test_property.rb * test/soap/calc/test_calc_cgi.rb * test/wsdl/test_emptycomplextype.rb * summary * add SOAP Header mustUnderstand support. * add HTTP client SSL configuration and Cookies support (works completely with http-access2). * add header handler for handling sending/receiving SOAP Header. * map Ruby's anonymous Struct to common SOAP Struct in SOAP Object Model. it caused error. * add WSDL simpleType support to restrict lexical value space. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/soap/calc/test_calc_cgi.rb | 14 +- test/soap/header/server.cgi | 119 +++++++++++++++ test/soap/header/test_authheader.rb | 247 ++++++++++++++++++++++++++++++++ test/soap/header/test_authheader_cgi.rb | 128 +++++++++++++++++ test/soap/ssl/README | 1 + test/soap/ssl/ca.cert | 23 +++ test/soap/ssl/client.cert | 19 +++ test/soap/ssl/client.key | 15 ++ test/soap/ssl/server.cert | 19 +++ test/soap/ssl/server.key | 15 ++ test/soap/ssl/sslsvr.rb | 56 ++++++++ test/soap/ssl/subca.cert | 21 +++ test/soap/ssl/test_ssl.rb | 212 +++++++++++++++++++++++++++ test/soap/struct/test_struct.rb | 83 +++++++++++ test/soap/swa/test_file.rb | 77 ++++++++++ test/soap/test_property.rb | 70 +++++++-- test/soap/wsdlDriver/README.txt | 2 + test/soap/wsdlDriver/echo_version.rb | 20 +++ test/soap/wsdlDriver/simpletype.wsdl | 63 ++++++++ test/soap/wsdlDriver/test_simpletype.rb | 92 ++++++++++++ test/wsdl/multiplefault.wsdl | 68 +++++++++ test/wsdl/simpletype/simpletype.wsdl | 67 +++++++++ test/wsdl/simpletype/test_simpletype.rb | 81 +++++++++++ test/wsdl/test_emptycomplextype.rb | 2 +- test/wsdl/test_multiplefault.rb | 39 +++++ 25 files changed, 1532 insertions(+), 21 deletions(-) create mode 100644 test/soap/header/server.cgi create mode 100644 test/soap/header/test_authheader.rb create mode 100644 test/soap/header/test_authheader_cgi.rb create mode 100644 test/soap/ssl/README create mode 100644 test/soap/ssl/ca.cert create mode 100644 test/soap/ssl/client.cert create mode 100644 test/soap/ssl/client.key create mode 100644 test/soap/ssl/server.cert create mode 100644 test/soap/ssl/server.key create mode 100644 test/soap/ssl/sslsvr.rb create mode 100644 test/soap/ssl/subca.cert create mode 100644 test/soap/ssl/test_ssl.rb create mode 100644 test/soap/struct/test_struct.rb create mode 100644 test/soap/swa/test_file.rb create mode 100644 test/soap/wsdlDriver/README.txt create mode 100644 test/soap/wsdlDriver/echo_version.rb create mode 100644 test/soap/wsdlDriver/simpletype.wsdl create mode 100644 test/soap/wsdlDriver/test_simpletype.rb create mode 100644 test/wsdl/multiplefault.wsdl create mode 100644 test/wsdl/simpletype/simpletype.wsdl create mode 100644 test/wsdl/simpletype/test_simpletype.rb create mode 100644 test/wsdl/test_multiplefault.rb (limited to 'test') diff --git a/test/soap/calc/test_calc_cgi.rb b/test/soap/calc/test_calc_cgi.rb index accf7b0ae5..d1655b0b01 100644 --- a/test/soap/calc/test_calc_cgi.rb +++ b/test/soap/calc/test_calc_cgi.rb @@ -2,13 +2,7 @@ require 'test/unit' require 'soap/rpc/driver' require 'logger' require 'webrick' -begin - loadpath = $:.dup - $:.replace($: | [File.expand_path("../../ruby", File.dirname(__FILE__))]) - require 'envutil' -ensure - $:.replace(loadpath) -end +require 'rbconfig' module SOAP @@ -16,7 +10,11 @@ module Calc class TestCalcCGI < Test::Unit::TestCase - RUBYBIN = EnvUtil.rubybin + # This test shuld be run after installing ruby. + RUBYBIN = File.join( + Config::CONFIG["bindir"], + Config::CONFIG["ruby_install_name"] + Config::CONFIG["EXEEXT"] + ) RUBYBIN << " -d" if $DEBUG Port = 17171 diff --git a/test/soap/header/server.cgi b/test/soap/header/server.cgi new file mode 100644 index 0000000000..f9739d0d15 --- /dev/null +++ b/test/soap/header/server.cgi @@ -0,0 +1,119 @@ +require 'pstore' +require 'soap/rpc/cgistub' +require 'soap/header/simplehandler' + + +class AuthHeaderPortServer < SOAP::RPC::CGIStub + PortName = 'http://tempuri.org/authHeaderPort' + SupportPortName = 'http://tempuri.org/authHeaderSupportPort' + MyHeaderName = XSD::QName.new("http://tempuri.org/authHeader", "auth") + SessionDB = File.join(File.expand_path(File.dirname(__FILE__)), 'session.pstoredb') + + class AuthHeaderService + def self.create + new + end + + def deposit(amt) + "deposit #{amt} OK" + end + + def withdrawal(amt) + "withdrawal #{amt} OK" + end + end + + class AuthHeaderSupportService + def delete_sessiondb + File.unlink(SessionDB) if File.file?(SessionDB) + backup = SessionDB + "~" + File.unlink(backup) if File.file?(backup) + end + end + + def initialize(*arg) + super + add_rpc_servant(AuthHeaderService.new, PortName) + add_rpc_servant(AuthHeaderSupportService.new, SupportPortName) + add_rpc_headerhandler(ServerAuthHeaderHandler.new) + end + + class ServerAuthHeaderHandler < SOAP::Header::SimpleHandler + Users = { + 'NaHi' => 'passwd', + 'HiNa' => 'wspass' + } + + def initialize + super(MyHeaderName) + @db = PStore.new(SessionDB) + @db.transaction do + @db["root"] = {} unless @db.root?("root") + end + @userid = @sessionid = nil + end + + def login(userid, passwd) + userid and passwd and Users[userid] == passwd + end + + def auth(sessionid) + in_sessiondb do |root| + root[sessionid][0] + end + end + + def create_session(userid) + in_sessiondb do |root| + while true + key = create_sessionkey + break unless root[key] + end + root[key] = [userid] + key + end + end + + def destroy_session(sessionkey) + in_sessiondb do |root| + root.delete(sessionkey) + end + end + + def on_simple_outbound + { "sessionid" => @sessionid } + end + + def on_simple_inbound(my_header, mu) + auth = false + userid = my_header["userid"] + passwd = my_header["passwd"] + if login(userid, passwd) + auth = true + elsif sessionid = my_header["sessionid"] + if userid = auth(sessionid) + destroy_session(sessionid) + auth = true + end + end + raise RuntimeError.new("authentication failed") unless auth + @userid = userid + @sessionid = create_session(userid) + end + + private + + def create_sessionkey + Time.now.usec.to_s + end + + def in_sessiondb + @db.transaction do + yield(@db["root"]) + end + end + end +end + + +status = AuthHeaderPortServer.new('AuthHeaderPortServer', nil).start diff --git a/test/soap/header/test_authheader.rb b/test/soap/header/test_authheader.rb new file mode 100644 index 0000000000..2c04769dd6 --- /dev/null +++ b/test/soap/header/test_authheader.rb @@ -0,0 +1,247 @@ +require 'test/unit' +require 'soap/rpc/driver' +require 'soap/rpc/standaloneServer' +require 'soap/header/simplehandler' + + +module SOAP +module Header + + +class TestAuthHeader < Test::Unit::TestCase + Port = 17171 + PortName = 'http://tempuri.org/authHeaderPort' + MyHeaderName = XSD::QName.new("http://tempuri.org/authHeader", "auth") + DummyHeaderName = XSD::QName.new("http://tempuri.org/authHeader", "dummy") + + class AuthHeaderPortServer < SOAP::RPC::StandaloneServer + class AuthHeaderService + def self.create + new + end + + def deposit(amt) + "deposit #{amt} OK" + end + + def withdrawal(amt) + "withdrawal #{amt} OK" + end + end + + def initialize(*arg) + super + add_rpc_servant(AuthHeaderService.new, PortName) + ServerAuthHeaderHandler.init + add_rpc_request_headerhandler(ServerAuthHeaderHandler) + end + + class ServerAuthHeaderHandler < SOAP::Header::SimpleHandler + class << self + def create + new + end + + def init + @users = { + 'NaHi' => 'passwd', + 'HiNa' => 'wspass' + } + @sessions = {} + end + + def login(userid, passwd) + userid and passwd and @users[userid] == passwd + end + + def auth(sessionid) + @sessions[sessionid][0] + end + + def create_session(userid) + while true + key = create_sessionkey + break unless @sessions[key] + end + @sessions[key] = [userid] + key + end + + def destroy_session(sessionkey) + @sessions.delete(sessionkey) + end + + def sessions + @sessions + end + + private + + def create_sessionkey + Time.now.usec.to_s + end + end + + def initialize + super(MyHeaderName) + @userid = @sessionid = nil + end + + def on_simple_outbound + { "sessionid" => @sessionid } + end + + def on_simple_inbound(my_header, mu) + auth = false + userid = my_header["userid"] + passwd = my_header["passwd"] + if self.class.login(userid, passwd) + auth = true + elsif sessionid = my_header["sessionid"] + if userid = self.class.auth(sessionid) + self.class.destroy_session(sessionid) + auth = true + end + end + raise RuntimeError.new("authentication failed") unless auth + @userid = userid + @sessionid = self.class.create_session(userid) + end + end + end + + class ClientAuthHeaderHandler < SOAP::Header::SimpleHandler + def initialize(userid, passwd, mustunderstand) + super(MyHeaderName) + @sessionid = nil + @userid = userid + @passwd = passwd + @mustunderstand = mustunderstand + end + + def on_simple_outbound + if @sessionid + { "sessionid" => @sessionid } + else + { "userid" => @userid, "passwd" => @passwd } + end + end + + def on_simple_inbound(my_header, mustunderstand) + @sessionid = my_header["sessionid"] + end + + def sessionid + @sessionid + end + end + + class DummyHeaderHandler < SOAP::Header::SimpleHandler + def initialize(mustunderstand) + super(DummyHeaderName) + @mustunderstand = mustunderstand + end + + def on_simple_outbound + { XSD::QName.new("foo", "bar") => nil } + end + + def on_simple_inbound(my_header, mustunderstand) + end + end + + def setup + @endpoint = "http://localhost:#{Port}/" + setup_server + setup_client + end + + def setup_server + @server = AuthHeaderPortServer.new(self.class.name, nil, '0.0.0.0', Port) + @server.level = Logger::Severity::ERROR + @t = Thread.new { + @server.start + } + while @server.status != :Running + sleep 0.1 + unless @t.alive? + @t.join + raise + end + end + end + + def setup_client + @client = SOAP::RPC::Driver.new(@endpoint, PortName) + @client.wiredump_dev = STDERR if $DEBUG + @client.add_method('deposit', 'amt') + @client.add_method('withdrawal', 'amt') + end + + def teardown + teardown_server + teardown_client + end + + def teardown_server + @server.shutdown + @t.kill + @t.join + end + + def teardown_client + @client.reset_stream + end + + def test_success_no_mu + h = ClientAuthHeaderHandler.new('NaHi', 'passwd', false) + @client.headerhandler << h + do_transaction_check(h) + end + + def test_success_mu + h = ClientAuthHeaderHandler.new('NaHi', 'passwd', true) + @client.headerhandler << h + do_transaction_check(h) + end + + def test_no_mu + h = ClientAuthHeaderHandler.new('NaHi', 'passwd', true) + @client.headerhandler << h + @client.headerhandler << DummyHeaderHandler.new(false) + do_transaction_check(h) + end + + def test_mu + h = ClientAuthHeaderHandler.new('NaHi', 'passwd', true) + @client.headerhandler << h + @client.headerhandler << (h2 = DummyHeaderHandler.new(true)) + assert_raise(SOAP::UnhandledMustUnderstandHeaderError) do + assert_equal("deposit 150 OK", @client.deposit(150)) + end + @client.headerhandler.delete(h2) + @client.headerhandler << (h2 = DummyHeaderHandler.new(false)) + do_transaction_check(h) + end + + def do_transaction_check(h) + assert_equal("deposit 150 OK", @client.deposit(150)) + serversess = AuthHeaderPortServer::ServerAuthHeaderHandler.sessions[h.sessionid] + assert_equal("NaHi", serversess[0]) + assert_equal("withdrawal 120 OK", @client.withdrawal(120)) + serversess = AuthHeaderPortServer::ServerAuthHeaderHandler.sessions[h.sessionid] + assert_equal("NaHi", serversess[0]) + end + + def test_authfailure + h = ClientAuthHeaderHandler.new('NaHi', 'pa', false) + @client.headerhandler << h + assert_raises(RuntimeError) do + @client.deposit(150) + end + end +end + + +end +end diff --git a/test/soap/header/test_authheader_cgi.rb b/test/soap/header/test_authheader_cgi.rb new file mode 100644 index 0000000000..03bd1bb965 --- /dev/null +++ b/test/soap/header/test_authheader_cgi.rb @@ -0,0 +1,128 @@ +require 'test/unit' +require 'soap/rpc/driver' +require 'soap/rpc/standaloneServer' +require 'soap/header/simplehandler' +require 'logger' +require 'webrick' +require 'rbconfig' + + +module SOAP +module Header + + +class TestAuthHeaderCGI < Test::Unit::TestCase + # This test shuld be run after installing ruby. + RUBYBIN = File.join( + Config::CONFIG["bindir"], + Config::CONFIG["ruby_install_name"] + Config::CONFIG["EXEEXT"] + ) + RUBYBIN << " -d" if $DEBUG + + Port = 17171 + PortName = 'http://tempuri.org/authHeaderPort' + SupportPortName = 'http://tempuri.org/authHeaderSupportPort' + MyHeaderName = XSD::QName.new("http://tempuri.org/authHeader", "auth") + + class ClientAuthHeaderHandler < SOAP::Header::SimpleHandler + def initialize(userid, passwd) + super(MyHeaderName) + @sessionid = nil + @userid = userid + @passwd = passwd + end + + def on_simple_outbound + if @sessionid + { "sessionid" => @sessionid } + else + { "userid" => @userid, "passwd" => @passwd } + end + end + + def on_simple_inbound(my_header, mustunderstand) + @sessionid = my_header["sessionid"] + end + + def sessionid + @sessionid + end + end + + def setup + @endpoint = "http://localhost:#{Port}/" + setup_server + setup_client + end + + def setup_server + @endpoint = "http://localhost:#{Port}/server.cgi" + logger = Logger.new(STDERR) + logger.level = Logger::Severity::ERROR + @server = WEBrick::HTTPServer.new( + :BindAddress => "0.0.0.0", + :Logger => logger, + :Port => Port, + :AccessLog => [], + :DocumentRoot => File.dirname(File.expand_path(__FILE__)), + :CGIPathEnv => ENV['PATH'], + :CGIInterpreter => RUBYBIN + ) + @t = Thread.new { + Thread.current.abort_on_exception = true + @server.start + } + while @server.status != :Running + sleep 0.1 + unless @t.alive? + @t.join + raise + end + end + end + + def setup_client + @client = SOAP::RPC::Driver.new(@endpoint, PortName) + @client.wiredump_dev = STDERR if $DEBUG + @client.add_method('deposit', 'amt') + @client.add_method('withdrawal', 'amt') + @supportclient = SOAP::RPC::Driver.new(@endpoint, SupportPortName) + @supportclient.add_method('delete_sessiondb') + end + + def teardown + @supportclient.delete_sessiondb + teardown_server + teardown_client + end + + def teardown_server + @server.shutdown + @t.kill + @t.join + end + + def teardown_client + @client.reset_stream + @supportclient.reset_stream + end + + def test_success + h = ClientAuthHeaderHandler.new('NaHi', 'passwd') + @client.headerhandler << h + assert_equal("deposit 150 OK", @client.deposit(150)) + assert_equal("withdrawal 120 OK", @client.withdrawal(120)) + end + + def test_authfailure + h = ClientAuthHeaderHandler.new('NaHi', 'pa') + @client.headerhandler << h + assert_raises(RuntimeError) do + @client.deposit(150) + end + end +end + + +end +end diff --git a/test/soap/ssl/README b/test/soap/ssl/README new file mode 100644 index 0000000000..98ebcf7c23 --- /dev/null +++ b/test/soap/ssl/README @@ -0,0 +1 @@ +* certificates and keys in this directory is copied from http-access2 test. diff --git a/test/soap/ssl/ca.cert b/test/soap/ssl/ca.cert new file mode 100644 index 0000000000..bcabbee4ad --- /dev/null +++ b/test/soap/ssl/ca.cert @@ -0,0 +1,23 @@ +-----BEGIN CERTIFICATE----- +MIID0DCCArigAwIBAgIBADANBgkqhkiG9w0BAQUFADA8MQswCQYDVQQGDAJKUDES +MBAGA1UECgwJSklOLkdSLkpQMQwwCgYDVQQLDANSUlIxCzAJBgNVBAMMAkNBMB4X +DTA0MDEzMDAwNDIzMloXDTM2MDEyMjAwNDIzMlowPDELMAkGA1UEBgwCSlAxEjAQ +BgNVBAoMCUpJTi5HUi5KUDEMMAoGA1UECwwDUlJSMQswCQYDVQQDDAJDQTCCASIw +DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANbv0x42BTKFEQOE+KJ2XmiSdZpR +wjzQLAkPLRnLB98tlzs4xo+y4RyY/rd5TT9UzBJTIhP8CJi5GbS1oXEerQXB3P0d +L5oSSMwGGyuIzgZe5+vZ1kgzQxMEKMMKlzA73rbMd4Jx3u5+jdbP0EDrPYfXSvLY +bS04n2aX7zrN3x5KdDrNBfwBio2/qeaaj4+9OxnwRvYP3WOvqdW0h329eMfHw0pi +JI0drIVdsEqClUV4pebT/F+CPUPkEh/weySgo9wANockkYu5ujw2GbLFcO5LXxxm +dEfcVr3r6t6zOA4bJwL0W/e6LBcrwiG/qPDFErhwtgTLYf6Er67SzLyA66UCAwEA +AaOB3DCB2TAPBgNVHRMBAf8EBTADAQH/MDEGCWCGSAGG+EIBDQQkFiJSdWJ5L09w +ZW5TU0wgR2VuZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQWBBRJ7Xd380KzBV7f +USKIQ+O/vKbhDzAOBgNVHQ8BAf8EBAMCAQYwZAYDVR0jBF0wW4AUSe13d/NCswVe +31EiiEPjv7ym4Q+hQKQ+MDwxCzAJBgNVBAYMAkpQMRIwEAYDVQQKDAlKSU4uR1Iu +SlAxDDAKBgNVBAsMA1JSUjELMAkGA1UEAwwCQ0GCAQAwDQYJKoZIhvcNAQEFBQAD +ggEBAIu/mfiez5XN5tn2jScgShPgHEFJBR0BTJBZF6xCk0jyqNx/g9HMj2ELCuK+ +r/Y7KFW5c5M3AQ+xWW0ZSc4kvzyTcV7yTVIwj2jZ9ddYMN3nupZFgBK1GB4Y05GY +MJJFRkSu6d/Ph5ypzBVw2YMT/nsOo5VwMUGLgS7YVjU+u/HNWz80J3oO17mNZllj +PvORJcnjwlroDnS58KoJ7GDgejv3ESWADvX1OHLE4cRkiQGeLoEU4pxdCxXRqX0U +PbwIkZN9mXVcrmPHq8MWi4eC/V7hnbZETMHuWhUoiNdOEfsAXr3iP4KjyyRdwc7a +d/xgcK06UVQRL/HbEYGiQL056mc= +-----END CERTIFICATE----- diff --git a/test/soap/ssl/client.cert b/test/soap/ssl/client.cert new file mode 100644 index 0000000000..ad13c4b735 --- /dev/null +++ b/test/soap/ssl/client.cert @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIDKDCCAhCgAwIBAgIBAjANBgkqhkiG9w0BAQUFADA8MQswCQYDVQQGDAJKUDES +MBAGA1UECgwJSklOLkdSLkpQMQwwCgYDVQQLDANSUlIxCzAJBgNVBAMMAkNBMB4X +DTA0MDEzMTAzMTQ1OFoXDTM1MDEyMzAzMTQ1OFowZTELMAkGA1UEBgwCSlAxEjAQ +BgNVBAoMCUpJTi5HUi5KUDEMMAoGA1UECwwDUlJSMRAwDgYDVQQDDAdleGFtcGxl +MSIwIAYJKoZIhvcNAQkBDBNleGFtcGxlQGV4YW1wbGUub3JnMIGfMA0GCSqGSIb3 +DQEBAQUAA4GNADCBiQKBgQDRWssrK8Gyr+500hpLjCGR3+AHL8/hEJM5zKi/MgLW +jTkvsgOwbYwXOiNtAbR9y4/ucDq7EY+cMUMHES4uFaPTcOaAV0aZRmk8AgslN1tQ +gNS6ew7/Luq3DcVeWkX8PYgR9VG0mD1MPfJ6+IFA5d3vKpdBkBgN4l46jjO0/2Xf +ewIDAQABo4GPMIGMMAwGA1UdEwEB/wQCMAAwMQYJYIZIAYb4QgENBCQWIlJ1Ynkv +T3BlblNTTCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwHQYDVR0OBBYEFOFvay0H7lr2 +xUx6waYEV2bVDYQhMAsGA1UdDwQEAwIF4DAdBgNVHSUEFjAUBggrBgEFBQcDAgYI +KwYBBQUHAwQwDQYJKoZIhvcNAQEFBQADggEBABd2dYWqbDIWf5sWFvslezxJv8gI +w64KCJBuyJAiDuf+oazr3016kMzAlt97KecLZDusGNagPrq02UX7YMoQFsWJBans +cDtHrkM0al5r6/WGexNMgtYbNTYzt/IwodISGBgZ6dsOuhznwms+IBsTNDAvWeLP +lt2tOqD8kEmjwMgn0GDRuKjs4EoboA3kMULb1p9akDV9ZESU3eOtpS5/G5J5msLI +9WXbYBjcjvkLuJH9VsJhb+R58Vl0ViemvAHhPilSl1SPWVunGhv6FcIkdBEi1k9F +e8BNMmsEjFiANiIRvpdLRbiGBt0KrKTndVfsmoKCvY48oCOvnzxtahFxfs8= +-----END CERTIFICATE----- diff --git a/test/soap/ssl/client.key b/test/soap/ssl/client.key new file mode 100644 index 0000000000..37bc62f259 --- /dev/null +++ b/test/soap/ssl/client.key @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICWwIBAAKBgQDRWssrK8Gyr+500hpLjCGR3+AHL8/hEJM5zKi/MgLWjTkvsgOw +bYwXOiNtAbR9y4/ucDq7EY+cMUMHES4uFaPTcOaAV0aZRmk8AgslN1tQgNS6ew7/ +Luq3DcVeWkX8PYgR9VG0mD1MPfJ6+IFA5d3vKpdBkBgN4l46jjO0/2XfewIDAQAB +AoGAZcz8llWErtsV3QB9gNb3S/PNADGjqBFjReva8n3jG2k4sZSibpwWTwUaTNtT +ZQgjSRKRvH1hk9XwffNAvXAQZNNkuj/16gO2oO45nyLj4dO365ujLptWnVIWDHOE +uN0GeiZO+VzcCisT0WCq4tvtLeH8svrxzA8cbXIEyOK7NiECQQDwo2zPFyKAZ/Cu +lDJ6zKT+RjfWwW7DgWzirAlTrt4ViMaW+IaDH29TmQpb4V4NuR3Xi+2Xl4oicu6S +36TW9+/FAkEA3rgfOQJuLlWSnw1RTGwvnC816a/W7iYYY7B+0U4cDbfWl7IoXT4y +M8nV/HESooviZLqBwzAYSoj3fFKYBKpGPwJAUO8GN5iWWA2dW3ooiDiv/X1sZmRk +dojfMFWgRW747tEzya8Ivq0h6kH8w+5GjeMG8Gn1nRiwsulo6Ckj7dEx6QJACyui +7UIQ8qP6GZ4aYMHgVW4Mvy7Bkeo5OO7GPYs0Xv/EdJFL8vlGnVBXOjUVoS9w6Gpu +TbLg1QQvnX2rADjmEwJANxZO2GUkaWGsEif8aGW0x5g/IdaMGG27pTWk5zqix7P3 +1UDrdo/JOXhptovhRi06EppIxAxYmbh9vd9VN8Itlw== +-----END RSA PRIVATE KEY----- diff --git a/test/soap/ssl/server.cert b/test/soap/ssl/server.cert new file mode 100644 index 0000000000..998ccc5892 --- /dev/null +++ b/test/soap/ssl/server.cert @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIC/zCCAeegAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MQswCQYDVQQGDAJKUDES +MBAGA1UECgwJSklOLkdSLkpQMQwwCgYDVQQLDANSUlIxDjAMBgNVBAMMBVN1YkNB +MB4XDTA0MDEzMTAzMTMxNloXDTMzMDEyMzAzMTMxNlowQzELMAkGA1UEBgwCSlAx +EjAQBgNVBAoMCUpJTi5HUi5KUDEMMAoGA1UECwwDUlJSMRIwEAYDVQQDDAlsb2Nh +bGhvc3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANFJTxWqup3nV9dsJAku +p+WaXnPNIzcpAA3qMGZDJTJsfa8Du7ZxTP0XJK5mETttBrn711cJxAuP3KjqnW9S +vtZ9lY2sXJ6Zj62sN5LwG3VVe25dI28yR1EsbHjJ5Zjf9tmggMC6am52dxuHbt5/ +vHo4ngJuKE/U+eeGRivMn6gFAgMBAAGjgYUwgYIwDAYDVR0TAQH/BAIwADAxBglg +hkgBhvhCAQ0EJBYiUnVieS9PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTAd +BgNVHQ4EFgQUpZIyygD9JxFYHHOTEuWOLbCKfckwCwYDVR0PBAQDAgWgMBMGA1Ud +JQQMMAoGCCsGAQUFBwMBMA0GCSqGSIb3DQEBBQUAA4IBAQBwAIj5SaBHaA5X31IP +CFCJiep96awfp7RANO0cuUj+ZpGoFn9d6FXY0g+Eg5wAkCNIzZU5NHN9xsdOpnUo +zIBbyTfQEPrge1CMWMvL6uGaoEXytq84VTitF/xBTky4KtTn6+es4/e7jrrzeUXQ +RC46gkHObmDT91RkOEGjHLyld2328jo3DIN/VTHIryDeVHDWjY5dENwpwdkhhm60 +DR9IrNBbXWEe9emtguNXeN0iu1ux0lG1Hc6pWGQxMlRKNvGh0yZB9u5EVe38tOV0 +jQaoNyL7qzcQoXD3Dmbi1p0iRmg/+HngISsz8K7k7MBNVsSclztwgCzTZOBiVtkM +rRlQ +-----END CERTIFICATE----- diff --git a/test/soap/ssl/server.key b/test/soap/ssl/server.key new file mode 100644 index 0000000000..9ba2218a03 --- /dev/null +++ b/test/soap/ssl/server.key @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXQIBAAKBgQDRSU8Vqrqd51fXbCQJLqflml5zzSM3KQAN6jBmQyUybH2vA7u2 +cUz9FySuZhE7bQa5+9dXCcQLj9yo6p1vUr7WfZWNrFyemY+trDeS8Bt1VXtuXSNv +MkdRLGx4yeWY3/bZoIDAumpudncbh27ef7x6OJ4CbihP1PnnhkYrzJ+oBQIDAQAB +AoGBAIf4CstW2ltQO7+XYGoex7Hh8s9lTSW/G2vu5Hbr1LTHy3fzAvdq8MvVR12O +rk9fa+lU9vhzPc0NMB0GIDZ9GcHuhW5hD1Wg9OSCbTOkZDoH3CAFqonjh4Qfwv5W +IPAFn9KHukdqGXkwEMdErsUaPTy9A1V/aROVEaAY+HJgq/eZAkEA/BP1QMV04WEZ +Oynzz7/lLizJGGxp2AOvEVtqMoycA/Qk+zdKP8ufE0wbmCE3Qd6GoynavsHb6aGK +gQobb8zDZwJBANSK6MrXlrZTtEaeZuyOB4mAmRzGzOUVkUyULUjEx2GDT93ujAma +qm/2d3E+wXAkNSeRpjUmlQXy/2oSqnGvYbMCQQDRM+cYyEcGPUVpWpnj0shrF/QU +9vSot/X1G775EMTyaw6+BtbyNxVgOIu2J+rqGbn3c+b85XqTXOPL0A2RLYkFAkAm +syhSDtE9X55aoWsCNZY/vi+i4rvaFoQ/WleogVQAeGVpdo7/DK9t9YWoFBIqth0L +mGSYFu9ZhvZkvQNV8eYrAkBJ+rOIaLDsmbrgkeDruH+B/9yrm4McDtQ/rgnOGYnH +LjLpLLOrgUxqpzLWe++EwSLwK2//dHO+SPsQJ4xsyQJy +-----END RSA PRIVATE KEY----- diff --git a/test/soap/ssl/sslsvr.rb b/test/soap/ssl/sslsvr.rb new file mode 100644 index 0000000000..281c1a1a51 --- /dev/null +++ b/test/soap/ssl/sslsvr.rb @@ -0,0 +1,56 @@ +require 'webrick/https' +require 'logger' +require 'rbconfig' + +require 'soap/rpc/httpserver' + +class HelloWorldServer < SOAP::RPC::HTTPServer +private + + def on_init + self.level = Logger::Severity::FATAL + @default_namespace = 'urn:ssltst' + add_method(self, 'hello_world', 'from') + end + + def hello_world(from) + "Hello World, from #{ from }" + end +end + + +if $0 == __FILE__ + PORT = 17171 + DIR = File.dirname(File.expand_path(__FILE__)) + + def cert(filename) + OpenSSL::X509::Certificate.new(File.open(File.join(DIR, filename)) { |f| + f.read + }) + end + + def key(filename) + OpenSSL::PKey::RSA.new(File.open(File.join(DIR, filename)) { |f| + f.read + }) + end + + $server = HelloWorldServer.new( + :BindAddress => "0.0.0.0", + :Port => PORT, + :AccessLog => [], + :SSLEnable => true, + :SSLCACertificateFile => File.join(DIR, 'ca.cert'), + :SSLCertificate => cert('server.cert'), + :SSLPrivateKey => key('server.key'), + :SSLVerifyClient => nil, #OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT|OpenSSL::SSL::VERIFY_PEER, + :SSLClientCA => cert('ca.cert'), + :SSLCertName => nil + ) + trap(:INT) do + $server.shutdown if $server + end + STDOUT.sync = true + STDOUT.puts $$ + $server.start +end diff --git a/test/soap/ssl/subca.cert b/test/soap/ssl/subca.cert new file mode 100644 index 0000000000..1e471851b8 --- /dev/null +++ b/test/soap/ssl/subca.cert @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDaDCCAlCgAwIBAgIBATANBgkqhkiG9w0BAQUFADA8MQswCQYDVQQGDAJKUDES +MBAGA1UECgwJSklOLkdSLkpQMQwwCgYDVQQLDANSUlIxCzAJBgNVBAMMAkNBMB4X +DTA0MDEzMDAwNDMyN1oXDTM1MDEyMjAwNDMyN1owPzELMAkGA1UEBgwCSlAxEjAQ +BgNVBAoMCUpJTi5HUi5KUDEMMAoGA1UECwwDUlJSMQ4wDAYDVQQDDAVTdWJDQTCC +ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJ0Ou7AyRcRXnB/kVHv/6kwe +ANzgg/DyJfsAUqW90m7Lu1nqyug8gK0RBd77yU0w5HOAMHTVSdpjZK0g2sgx4Mb1 +d/213eL9TTl5MRVEChTvQr8q5DVG/8fxPPE7fMI8eOAzd98/NOAChk+80r4Sx7fC +kGVEE1bKwY1MrUsUNjOY2d6t3M4HHV3HX1V8ShuKfsHxgCmLzdI8U+5CnQedFgkm +3e+8tr8IX5RR1wA1Ifw9VadF7OdI/bGMzog/Q8XCLf+WPFjnK7Gcx6JFtzF6Gi4x +4dp1Xl45JYiVvi9zQ132wu8A1pDHhiNgQviyzbP+UjcB/tsOpzBQF8abYzgEkWEC +AwEAAaNyMHAwDwYDVR0TAQH/BAUwAwEB/zAxBglghkgBhvhCAQ0EJBYiUnVieS9P +cGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTAdBgNVHQ4EFgQUlCjXWLsReYzH +LzsxwVnCXmKoB/owCwYDVR0PBAQDAgEGMA0GCSqGSIb3DQEBBQUAA4IBAQCJ/OyN +rT8Cq2Y+G2yA/L1EMRvvxwFBqxavqaqHl/6rwsIBFlB3zbqGA/0oec6MAVnYynq4 +c4AcHTjx3bQ/S4r2sNTZq0DH4SYbQzIobx/YW8PjQUJt8KQdKMcwwi7arHP7A/Ha +LKu8eIC2nsUBnP4NhkYSGhbmpJK+PFD0FVtD0ZIRlY/wsnaZNjWWcnWF1/FNuQ4H +ySjIblqVQkPuzebv3Ror6ZnVDukn96Mg7kP4u6zgxOeqlJGRe1M949SS9Vudjl8X +SF4aZUUB9pQGhsqQJVqaz2OlhGOp9D0q54xko/rekjAIcuDjl1mdX4F2WRrzpUmZ +uY/bPeOBYiVsOYVe +-----END CERTIFICATE----- diff --git a/test/soap/ssl/test_ssl.rb b/test/soap/ssl/test_ssl.rb new file mode 100644 index 0000000000..6678c775ac --- /dev/null +++ b/test/soap/ssl/test_ssl.rb @@ -0,0 +1,212 @@ +require 'test/unit' +begin + require 'http-access2' +rescue LoadError +end +require 'soap/rpc/driver' + +if defined?(HTTPAccess2) + +module SOAP; module SSL + + +class TestSSL < Test::Unit::TestCase + PORT = 17171 + + DIR = File.dirname(File.expand_path(__FILE__)) + require 'rbconfig' + RUBY = File.join( + Config::CONFIG["bindir"], + Config::CONFIG["ruby_install_name"] + Config::CONFIG["EXEEXT"] + ) + + def setup + @url = "https://localhost:#{PORT}/hello" + @serverpid = @client = nil + @verify_callback_called = false + setup_server + setup_client + end + + def teardown + teardown_client + teardown_server + end + + def streamhandler + @client.instance_eval("@servant").instance_eval("@streamhandler").client + end + + def test_options + cfg = streamhandler.ssl_config + assert_nil(cfg.client_cert) + assert_nil(cfg.client_key) + assert_nil(cfg.client_ca) + assert_equal(OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT, cfg.verify_mode) + assert_nil(cfg.verify_callback) + assert_nil(cfg.timeout) + assert_equal(OpenSSL::SSL::OP_ALL | OpenSSL::SSL::OP_NO_SSLv2, cfg.options) + assert_equal("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH", cfg.ciphers) + assert_instance_of(OpenSSL::X509::Store, cfg.cert_store) + # dummy call to ensure sslsvr initialization finished. + assert_raise(OpenSSL::SSL::SSLError) do + @client.hello_world("ssl client") + end + end + + def test_verification + cfg = @client.options + cfg["protocol.http.ssl_config.verify_callback"] = method(:verify_callback).to_proc + begin + @verify_callback_called = false + @client.hello_world("ssl client") + assert(false) + rescue OpenSSL::SSL::SSLError => ssle + assert_equal("certificate verify failed", ssle.message) + assert(@verify_callback_called) + end + # + cfg["protocol.http.ssl_config.client_cert"] = File.join(DIR, "client.cert") + cfg["protocol.http.ssl_config.client_key"] = File.join(DIR, "client.key") + @verify_callback_called = false + begin + @client.hello_world("ssl client") + assert(false) + rescue OpenSSL::SSL::SSLError => ssle + assert_equal("certificate verify failed", ssle.message) + assert(@verify_callback_called) + end + # + cfg["protocol.http.ssl_config.ca_file"] = File.join(DIR, "ca.cert") + @verify_callback_called = false + begin + @client.hello_world("ssl client") + assert(false) + rescue OpenSSL::SSL::SSLError => ssle + assert_equal("certificate verify failed", ssle.message) + assert(@verify_callback_called) + end + # + cfg["protocol.http.ssl_config.ca_file"] = File.join(DIR, "subca.cert") + @verify_callback_called = false + assert_equal("Hello World, from ssl client", @client.hello_world("ssl client")) + assert(@verify_callback_called) + # + cfg["protocol.http.ssl_config.verify_depth"] = "1" + @verify_callback_called = false + begin + @client.hello_world("ssl client") + assert(false) + rescue OpenSSL::SSL::SSLError => ssle + assert_equal("certificate verify failed", ssle.message) + assert(@verify_callback_called) + end + # + cfg["protocol.http.ssl_config.verify_depth"] = "" + cfg["protocol.http.ssl_config.cert_store"] = OpenSSL::X509::Store.new + cfg["protocol.http.ssl_config.verify_mode"] = OpenSSL::SSL::VERIFY_PEER.to_s + begin + @client.hello_world("ssl client") + assert(false) + rescue OpenSSL::SSL::SSLError => ssle + assert_equal("certificate verify failed", ssle.message) + end + # + cfg["protocol.http.ssl_config.verify_mode"] = "" + assert_equal("Hello World, from ssl client", @client.hello_world("ssl client")) + end + + def test_property + testpropertyname = File.join(DIR, 'soapclient.properties') + File.open(testpropertyname, "w") do |f| + f <<<<__EOP__ +protocol.http.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_PEER +# depth: 1 causes an error (intentional) +protocol.http.ssl_config.verify_depth = 1 +protocol.http.ssl_config.client_cert = #{File.join(DIR, 'client.cert')} +protocol.http.ssl_config.client_key = #{File.join(DIR, 'client.key')} +protocol.http.ssl_config.ca_file = #{File.join(DIR, 'ca.cert')} +protocol.http.ssl_config.ca_file = #{File.join(DIR, 'subca.cert')} +protocol.http.ssl_config.ciphers = ALL +__EOP__ + end + begin + @client.loadproperty(testpropertyname) + @client.options["protocol.http.ssl_config.verify_callback"] = method(:verify_callback).to_proc + @verify_callback_called = false + begin + @client.hello_world("ssl client") + assert(false) + rescue OpenSSL::SSL::SSLError => ssle + assert_equal("certificate verify failed", ssle.message) + assert(@verify_callback_called) + end + # + @client.options["protocol.http.ssl_config.verify_depth"] = "" + @verify_callback_called = false + assert_equal("Hello World, from ssl client", @client.hello_world("ssl client")) + assert(@verify_callback_called) + ensure + File.unlink(testpropertyname) + end + end + + def test_ciphers + cfg = @client.options + cfg["protocol.http.ssl_config.client_cert"] = File.join(DIR, 'client.cert') + cfg["protocol.http.ssl_config.client_key"] = File.join(DIR, 'client.key') + cfg["protocol.http.ssl_config.ca_file"] = File.join(DIR, "ca.cert") + cfg["protocol.http.ssl_config.ca_file"] = File.join(DIR, "subca.cert") + #cfg.timeout = 123 + assert_equal("Hello World, from ssl client", @client.hello_world("ssl client")) + # + cfg["protocol.http.ssl_config.ciphers"] = "!ALL" + begin + @client.hello_world("ssl client") + assert(false) + rescue OpenSSL::SSL::SSLError => ssle + assert_equal("no ciphers available", ssle.message) + end + # + cfg["protocol.http.ssl_config.ciphers"] = "ALL" + assert_equal("Hello World, from ssl client", @client.hello_world("ssl client")) + end + +private + + def q(str) + %Q["#{str}"] + end + + def setup_server + svrcmd = "#{q(RUBY)} " + svrcmd << "-d " if $DEBUG + svrcmd << File.join(DIR, "sslsvr.rb") + svrout = IO.popen(svrcmd) + @serverpid = Integer(svrout.gets.chomp) + end + + def setup_client + @client = SOAP::RPC::Driver.new(@url, 'urn:ssltst') + @client.add_method("hello_world", "from") + end + + def teardown_server + Process.kill('INT', @serverpid) + end + + def teardown_client + @client.reset_stream + end + + def verify_callback(ok, cert) + @verify_callback_called = true + p ["client", ok, cert] if $DEBUG + ok + end +end + + +end; end + +end diff --git a/test/soap/struct/test_struct.rb b/test/soap/struct/test_struct.rb new file mode 100644 index 0000000000..71ada31676 --- /dev/null +++ b/test/soap/struct/test_struct.rb @@ -0,0 +1,83 @@ +require 'test/unit' +require 'soap/rpc/httpserver' +require 'soap/rpc/driver' + + +module SOAP; module Struct + + +class TestStruct < Test::Unit::TestCase + Namespace = "urn:example.com:simpletype-rpc" + class Server < ::SOAP::RPC::HTTPServer + @@test_struct = ::Struct.new(:one, :two) + + def on_init + add_method(self, 'a_method') + end + + def a_method + @@test_struct.new("string", 1) + end + end + + Port = 17171 + + def setup + setup_server + setup_client + end + + def setup_server + @server = Server.new( + :Port => Port, + :AccessLog => [], + :SOAPDefaultNamespace => Namespace + ) + @server.level = Logger::Severity::ERROR + @server_thread = start_server_thread(@server) + end + + def setup_client + @client = ::SOAP::RPC::Driver.new("http://localhost:#{Port}/", Namespace) + @client.wiredump_dev = STDERR if $DEBUG + @client.add_method('a_method') + end + + def teardown + teardown_server + teardown_client + end + + def teardown_server + @server.shutdown + @server_thread.kill + @server_thread.join + end + + def teardown_client + @client.reset_stream + end + + def start_server_thread(server) + t = Thread.new { + Thread.current.abort_on_exception = true + server.start + } + while server.status != :Running + sleep 0.1 + unless t.alive? + t.join + raise + end + end + t + end + + def test_struct + assert_equal("string", @client.a_method.one) + assert_equal(1, @client.a_method.two) + end +end + + +end; end diff --git a/test/soap/swa/test_file.rb b/test/soap/swa/test_file.rb new file mode 100644 index 0000000000..29bdf88a3b --- /dev/null +++ b/test/soap/swa/test_file.rb @@ -0,0 +1,77 @@ +require 'test/unit' +require 'soap/rpc/driver' +require 'soap/rpc/standaloneServer' +require 'soap/attachment' + + +module SOAP +module SWA + + +class TestFile < Test::Unit::TestCase + Port = 17171 + THIS_FILE = File.expand_path(__FILE__) + + class SwAService + def get_file + return { + 'name' => $0, + 'file' => SOAP::Attachment.new(File.open(THIS_FILE)) # closed when GCed. + } + end + + def put_file(name, file) + "File '#{name}' was received ok." + end + end + + def setup + @server = SOAP::RPC::StandaloneServer.new('SwAServer', + 'http://www.acmetron.com/soap', '0.0.0.0', Port) + @server.add_servant(SwAService.new) + @server.level = Logger::Severity::ERROR + @t = Thread.new { + @server.start + } + while @server.status != :Running + sleep 0.1 + unless @t.alive? + @t.join + raise + end + end + @endpoint = "http://localhost:#{Port}/" + @client = SOAP::RPC::Driver.new(@endpoint, 'http://www.acmetron.com/soap') + @client.add_method('get_file') + @client.add_method('put_file', 'name', 'file') + @client.wiredump_dev = STDERR if $DEBUG + end + + def teardown + @server.shutdown + @t.kill + @t.join + @client.reset_stream + end + + def test_file + assert_equal( + File.open(THIS_FILE) { |f| f.read }, + @client.get_file['file'].content + ) + assert_equal( + "File 'foo' was received ok.", + @client.put_file('foo', + SOAP::Attachment.new(File.open(THIS_FILE))) + ) + assert_equal( + "File 'bar' was received ok.", + @client.put_file('bar', + SOAP::Attachment.new(File.open(THIS_FILE) { |f| f.read })) + ) + end +end + + +end +end diff --git a/test/soap/test_property.rb b/test/soap/test_property.rb index 82363a83db..1cc826695f 100644 --- a/test/soap/test_property.rb +++ b/test/soap/test_property.rb @@ -59,7 +59,7 @@ __EOP__ prop = Property.new hooked = false prop.add_hook("foo.bar.baz") do |name, value| - assert_equal("foo.bar.baz", name) + assert_equal(["foo", "bar", "baz"], name) assert_equal("123", value) hooked = true end @@ -126,11 +126,24 @@ __EOP__ end end + def test_hook_name + tag = Object.new + tested = false + @prop.add_hook("foo.bar") do |key, value| + assert_raise(TypeError) do + key << "baz" + end + tested = true + end + @prop["foo.bar"] = tag + assert(tested) + end + def test_value_hook tag = Object.new tested = false @prop.add_hook("FOO.BAR.BAZ") do |key, value| - assert_equal("foo.bar.baz", key) + assert_equal(["Foo", "baR", "baZ"], key) assert_equal(tag, value) tested = true end @@ -141,32 +154,65 @@ __EOP__ assert_equal(1, @prop["foo.bar"]) end - def test_key_hook + def test_key_hook_no_cascade tag = Object.new tested = 0 + @prop.add_hook do |key, value| + assert(false) + end + @prop.add_hook(false) do |key, value| + assert(false) + end @prop.add_hook("foo") do |key, value| - assert_equal("foo.bar.baz.qux", key) + assert(false) + end + @prop.add_hook("foo.bar", false) do |key, value| + assert(false) + end + @prop.add_hook("foo.bar.baz") do |key, value| + assert(false) + end + @prop.add_hook("foo.bar.baz.qux", false) do |key, value| + assert_equal(["foo", "bar", "baz", "qux"], key) assert_equal(tag, value) tested += 1 end - @prop.add_hook("foo.bar") do |key, value| - assert_equal("foo.bar.baz.qux", key) + @prop["foo.bar.baz.qux"] = tag + assert_equal(tag, @prop["foo.bar.baz.qux"]) + assert_equal(1, tested) + end + + def test_key_hook_cascade + tag = Object.new + tested = 0 + @prop.add_hook(true) do |key, value| + assert_equal(["foo", "bar", "baz", "qux"], key) assert_equal(tag, value) tested += 1 end - @prop.add_hook("foo.bar.baz") do |key, value| - assert_equal("foo.bar.baz.qux", key) + @prop.add_hook("foo", true) do |key, value| + assert_equal(["foo", "bar", "baz", "qux"], key) assert_equal(tag, value) tested += 1 end - @prop.add_hook("foo.bar.baz.qux") do |key, value| - assert_equal("foo.bar.baz.qux", key) + @prop.add_hook("foo.bar", true) do |key, value| + assert_equal(["foo", "bar", "baz", "qux"], key) + assert_equal(tag, value) + tested += 1 + end + @prop.add_hook("foo.bar.baz", true) do |key, value| + assert_equal(["foo", "bar", "baz", "qux"], key) + assert_equal(tag, value) + tested += 1 + end + @prop.add_hook("foo.bar.baz.qux", true) do |key, value| + assert_equal(["foo", "bar", "baz", "qux"], key) assert_equal(tag, value) tested += 1 end @prop["foo.bar.baz.qux"] = tag assert_equal(tag, @prop["foo.bar.baz.qux"]) - assert_equal(4, tested) + assert_equal(5, tested) end def test_keys @@ -310,7 +356,7 @@ __EOP__ def test_hook_then_lock tested = false @prop.add_hook("a.b.c") do |name, value| - assert_equal("a.b.c", name) + assert_equal(["a", "b", "c"], name) tested = true end @prop["a.b"].lock diff --git a/test/soap/wsdlDriver/README.txt b/test/soap/wsdlDriver/README.txt new file mode 100644 index 0000000000..b4d45a0486 --- /dev/null +++ b/test/soap/wsdlDriver/README.txt @@ -0,0 +1,2 @@ +echo_version.rb is generated by wsdl2ruby.rb; +% wsdl2ruby.rb --wsdl simpletype.wsdl --classdef --force diff --git a/test/soap/wsdlDriver/echo_version.rb b/test/soap/wsdlDriver/echo_version.rb new file mode 100644 index 0000000000..7d76fb7587 --- /dev/null +++ b/test/soap/wsdlDriver/echo_version.rb @@ -0,0 +1,20 @@ +# urn:example.com:simpletype-rpc-type +class Version_struct + @@schema_type = "version_struct" + @@schema_ns = "urn:example.com:simpletype-rpc-type" + + attr_accessor :version + attr_accessor :msg + + def initialize(version = nil, msg = nil) + @version = version + @msg = msg + end +end + +# urn:example.com:simpletype-rpc-type +module Versions + C_16 = "1.6" + C_18 = "1.8" + C_19 = "1.9" +end diff --git a/test/soap/wsdlDriver/simpletype.wsdl b/test/soap/wsdlDriver/simpletype.wsdl new file mode 100644 index 0000000000..7c211a6b2c --- /dev/null +++ b/test/soap/wsdlDriver/simpletype.wsdl @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/soap/wsdlDriver/test_simpletype.rb b/test/soap/wsdlDriver/test_simpletype.rb new file mode 100644 index 0000000000..ed628927cd --- /dev/null +++ b/test/soap/wsdlDriver/test_simpletype.rb @@ -0,0 +1,92 @@ +require 'test/unit' +require 'soap/rpc/httpserver' +require 'soap/wsdlDriver' + + +module SOAP + + +class TestSimpleType < Test::Unit::TestCase + class Server < ::SOAP::RPC::HTTPServer + def on_init + add_method(self, 'echo_version', 'version') + end + + def echo_version(version) + # "2.0" is out of range. + Version_struct.new(version || "2.0", 'checked') + end + end + + DIR = File.dirname(File.expand_path(__FILE__)) + require File.join(DIR, 'echo_version') + + Port = 17171 + + def setup + setup_server + setup_client + end + + def setup_server + @server = Server.new( + :Port => Port, + :AccessLog => [], + :SOAPDefaultNamespace => "urn:example.com:simpletype-rpc" + ) + @server.level = Logger::Severity::ERROR + @server_thread = start_server_thread(@server) + end + + def setup_client + wsdl = File.join(DIR, 'simpletype.wsdl') + @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_driver + @client.endpoint_url = "http://localhost:#{Port}/" + @client.generate_explicit_type = false + end + + def teardown + teardown_server + teardown_client + end + + def teardown_server + @server.shutdown + @server_thread.kill + @server_thread.join + end + + def teardown_client + @client.reset_stream + end + + def start_server_thread(server) + t = Thread.new { + Thread.current.abort_on_exception = true + server.start + } + while server.status != :Running + sleep 0.1 + unless t.alive? + t.join + raise + end + end + t + end + + def test_ping + result = @client.echo_version("1.9") + assert_equal("1.9", result.version) + assert_equal("checked", result.msg) + assert_raise(::XSD::ValueSpaceError) do + @client.echo_version("2.0") + end + assert_raise(::XSD::ValueSpaceError) do + @client.echo_version(nil) # nil => "2.0" => out of range + end + end +end + + +end diff --git a/test/wsdl/multiplefault.wsdl b/test/wsdl/multiplefault.wsdl new file mode 100644 index 0000000000..2d928b60b0 --- /dev/null +++ b/test/wsdl/multiplefault.wsdl @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/wsdl/simpletype/simpletype.wsdl b/test/wsdl/simpletype/simpletype.wsdl new file mode 100644 index 0000000000..ec3266fc14 --- /dev/null +++ b/test/wsdl/simpletype/simpletype.wsdl @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/wsdl/simpletype/test_simpletype.rb b/test/wsdl/simpletype/test_simpletype.rb new file mode 100644 index 0000000000..a46bf5dd78 --- /dev/null +++ b/test/wsdl/simpletype/test_simpletype.rb @@ -0,0 +1,81 @@ +require 'test/unit' +require 'soap/rpc/standaloneServer' +require 'soap/wsdlDriver' + + +module WSDL +module SimpleType + + +class TestSimpleType < Test::Unit::TestCase + class Server < ::SOAP::RPC::StandaloneServer + def on_init + add_method(self, 'ruby', 'version', 'date') + end + + def ruby(version, date) + "#{version} (#{date})" + end + end + + DIR = File.dirname(File.expand_path(__FILE__)) + + Port = 17171 + + def setup + setup_server + setup_client + end + + def setup_server + @server = Server.new('Test', "urn:example.com:simpletype", '0.0.0.0', Port) + @server.level = Logger::Severity::ERROR + @server_thread = start_server_thread(@server) + end + + def setup_client + wsdl = File.join(DIR, 'simpletype.wsdl') + @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_driver + @client.endpoint_url = "http://localhost:#{Port}/" + @client.generate_explicit_type = false + end + + def teardown + teardown_server + teardown_client + end + + def teardown_server + @server.shutdown + @server_thread.kill + @server_thread.join + end + + def teardown_client + @client.reset_stream + end + + def start_server_thread(server) + t = Thread.new { + Thread.current.abort_on_exception = true + server.start + } + while server.status != :Running + sleep 0.1 + unless t.alive? + t.join + raise + end + end + t + end + + def test_ping + header, body = @client.ping(nil, {:version => "1.9", :date => "2004-01-01T00:00:00Z"}) + assert_equal("1.9 (2004-01-01T00:00:00Z)", body) + end +end + + +end +end diff --git a/test/wsdl/test_emptycomplextype.rb b/test/wsdl/test_emptycomplextype.rb index 0c21de8dd2..71d1b8641d 100644 --- a/test/wsdl/test_emptycomplextype.rb +++ b/test/wsdl/test_emptycomplextype.rb @@ -12,7 +12,7 @@ class TestWSDL < Test::Unit::TestCase def test_wsdl @wsdl = WSDL::Parser.new.parse(File.open(@file) { |f| f.read }) - assert_equal("#", @wsdl.inspect) + assert(/\{urn:jp.gr.jin.rrr.example.emptycomplextype\}emptycomplextype/ =~ @wsdl.inspect) end end diff --git a/test/wsdl/test_multiplefault.rb b/test/wsdl/test_multiplefault.rb new file mode 100644 index 0000000000..7004297dc9 --- /dev/null +++ b/test/wsdl/test_multiplefault.rb @@ -0,0 +1,39 @@ +require 'test/unit' +require 'wsdl/parser' +require 'wsdl/soap/classDefCreator' + + +module WSDL + + +class TestMultipleFault < Test::Unit::TestCase + def self.setup(filename) + @@filename = filename + end + + def test_multiplefault + @wsdl = WSDL::Parser.new.parse(File.open(@@filename) { |f| f.read }) + classdefstr = WSDL::SOAP::ClassDefCreator.new(@wsdl).dump + yield_eval_binding(classdefstr) do |b| + assert_equal( + WSDL::TestMultipleFault::AuthenticationError, + eval("AuthenticationError", b) + ) + assert_equal( + WSDL::TestMultipleFault::AuthorizationError, + eval("AuthorizationError", b) + ) + end + end + + def yield_eval_binding(evaled) + b = binding + eval(evaled, b) + yield(b) + end +end + +TestMultipleFault.setup(File.join(File.dirname(__FILE__), 'multiplefault.wsdl')) + + +end -- cgit v1.2.3