From 007f77dae044ab96c335f76cf9d8636e308d71ce Mon Sep 17 00:00:00 2001 From: rubiii Date: Wed, 5 Jun 2013 11:51:01 +0200 Subject: [PATCH] quickfix to prevent import recursion /cc savonrb/wasabi#27 --- lib/savon/importer.rb | 10 +- spec/fixtures/wsdl/rio2/rio2.wsdl | 74 ++++++++++ spec/fixtures/wsdl/rio2/rio2_0.wsdl | 55 +++++++ spec/fixtures/wsdl/rio2/rio2_0.xsd | 58 ++++++++ spec/fixtures/wsdl/rio2/rio2_1.xsd | 41 +++++ spec/fixtures/wsdl/rio2/rio2_2.xsd | 222 ++++++++++++++++++++++++++++ spec/fixtures/wsdl/rio2/rio2_3.xsd | 10 ++ spec/integration/rio2_spec.rb | 35 +++++ 8 files changed, 504 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/wsdl/rio2/rio2.wsdl create mode 100644 spec/fixtures/wsdl/rio2/rio2_0.wsdl create mode 100644 spec/fixtures/wsdl/rio2/rio2_0.xsd create mode 100644 spec/fixtures/wsdl/rio2/rio2_1.xsd create mode 100644 spec/fixtures/wsdl/rio2/rio2_2.xsd create mode 100644 spec/fixtures/wsdl/rio2/rio2_3.xsd create mode 100644 spec/integration/rio2_spec.rb diff --git a/lib/savon/importer.rb b/lib/savon/importer.rb index ddcc9b39..663b1246 100644 --- a/lib/savon/importer.rb +++ b/lib/savon/importer.rb @@ -14,6 +14,8 @@ def initialize(resolver, wsdl) end def import(location) + @import_locations = [] + documents = WSDL::DocumentCollection.new schemas = XS::SchemaCollection.new @@ -38,9 +40,15 @@ def import(location) private def import_document(location, &block) + if @import_locations.include? location + @logger.info("Skipping already imported location #{location.inspect}.") + return + end + xml = @resolver.resolve(location) - document = WSDL::Document.new Nokogiri.XML(xml), @wsdl + @import_locations << location + document = WSDL::Document.new Nokogiri.XML(xml), @wsdl block.call(document) # resolve wsdl imports diff --git a/spec/fixtures/wsdl/rio2/rio2.wsdl b/spec/fixtures/wsdl/rio2/rio2.wsdl new file mode 100644 index 00000000..c4938466 --- /dev/null +++ b/spec/fixtures/wsdl/rio2/rio2.wsdl @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spec/fixtures/wsdl/rio2/rio2_0.wsdl b/spec/fixtures/wsdl/rio2/rio2_0.wsdl new file mode 100644 index 00000000..abb5fd7b --- /dev/null +++ b/spec/fixtures/wsdl/rio2/rio2_0.wsdl @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spec/fixtures/wsdl/rio2/rio2_0.xsd b/spec/fixtures/wsdl/rio2/rio2_0.xsd new file mode 100644 index 00000000..1694fa6b --- /dev/null +++ b/spec/fixtures/wsdl/rio2/rio2_0.xsd @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spec/fixtures/wsdl/rio2/rio2_1.xsd b/spec/fixtures/wsdl/rio2/rio2_1.xsd new file mode 100644 index 00000000..8e260444 --- /dev/null +++ b/spec/fixtures/wsdl/rio2/rio2_1.xsd @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spec/fixtures/wsdl/rio2/rio2_2.xsd b/spec/fixtures/wsdl/rio2/rio2_2.xsd new file mode 100644 index 00000000..22f09323 --- /dev/null +++ b/spec/fixtures/wsdl/rio2/rio2_2.xsd @@ -0,0 +1,222 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spec/fixtures/wsdl/rio2/rio2_3.xsd b/spec/fixtures/wsdl/rio2/rio2_3.xsd new file mode 100644 index 00000000..cfc66222 --- /dev/null +++ b/spec/fixtures/wsdl/rio2/rio2_3.xsd @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/spec/integration/rio2_spec.rb b/spec/integration/rio2_spec.rb new file mode 100644 index 00000000..08a2e8f6 --- /dev/null +++ b/spec/integration/rio2_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe 'Integration with Rio II' do + + subject(:client) { Savon.new(wsdl_url) } + + let(:wsdl_url) { 'http://193.155.1.72/MyCentral-RioII-Services/SecurityService.svc?wsdl' } + let(:wsdl0_url) { 'http://193.155.1.72/MyCentral-RioII-Services/SecurityService.svc?wsdl=wsdl0' } + + before do + http_mock.fake_request(wsdl_url, 'wsdl/rio2/rio2.wsdl') + http_mock.fake_request(wsdl0_url, 'wsdl/rio2/rio2_0.wsdl') + + # 4 schemas to import + schema_import_base = 'http://193.155.1.72/MyCentral-RioII-Services/SecurityService.svc?xsd=xsd%d' + (0..3).each do |i| + url = schema_import_base % i + http_mock.fake_request(url, "wsdl/rio2/rio2_#{i}.xsd") + end + end + + it 'only downloads WSDL and XML Schema imports once per location' do + expect(client.services).to eq( + 'SecurityService' => { + ports: { + 'BasicHttpBinding_ISecurityService' => { + type: 'http://schemas.xmlsoap.org/wsdl/soap/', + location: 'http://193.155.1.72/MyCentral-RioII-Services/SecurityService.svc/soap' + } + } + } + ) + end + +end