soap_enumerator 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 87bcf7a47e7b7d93a983d5a3f4b23f72baee8157d202ec35fc6af717141778d8
4
+ data.tar.gz: bb5c0b94c5730a1cae3de98854b6776701cc3e75083fe3ae8def5170b865ad63
5
+ SHA512:
6
+ metadata.gz: '08db9a9b13ac4163e02d467ead6fa2a5bf501c2ea61f0cd363a7c14c8dc7f1dee405ff6eb86739c08b9d86e19d9d3d95ab032145ffbc602ff88fe3c36f7f28a0'
7
+ data.tar.gz: f7e16fcfccbe9ca300596430dcaf75d16a588833131ad58d2e38d4bb5a9dfd3e5252d6b5516fa32f50f465e672d0d0422165a384653e74de098c8e8e1150d97d
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .directory
10
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in soap_enumerator.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ soap_enumerator (0.1.0)
5
+ nokogiri (~> 1.8, >= 1.8.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ mini_portile2 (2.3.0)
11
+ nokogiri (1.8.5)
12
+ mini_portile2 (~> 2.3.0)
13
+ rake (10.5.0)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ bundler (~> 1.17)
20
+ rake (~> 10.0)
21
+ soap_enumerator!
22
+
23
+ BUNDLED WITH
24
+ 1.17.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 KING SABRI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # SoapEnumerator (Under heavy development)
2
+
3
+ Soap Enumerator is a Ruby gem for parsing and enumerating WSDL XML documents inspired by SoapUI. It converts the whole document into objects of itself. Using Soap Enumerator is intuitive, you can call its objects the same way you read the document.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ $ gem install soap_enumerator
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ruby
14
+ wsdl_doc = open('http://192.168.100.10:8383/dvws/vulnerabilities/wsdlenum/service.php?wsdl')
15
+
16
+ require 'soap-enumerator'
17
+
18
+ soap_enum = SoapEnumerator::Parse.wsdl(wsdl_doc)
19
+
20
+ # Definition Elements
21
+ definitions = soap_enum.definitions
22
+ definitions.attributes
23
+ definitions.types
24
+ definitions.messages
25
+ definitions.port_types
26
+ definitions.bindings
27
+ definitions.services
28
+
29
+ # Types Elements
30
+ types = soap_enum.types
31
+ schemas = types.schemas
32
+ schema = schemas[0]
33
+ schema.attributes
34
+ schema.target_namespace
35
+ complex_types = schema.complex_types
36
+ complex_type = complex_types[0]
37
+ ctype = complex_type.all[0]
38
+ ctype.attributes
39
+ simple_types = schema.simple_types
40
+ simple_types = simple_types
41
+ simple_type = simple_types[0]
42
+ stype = simple_type.all[0]
43
+ stype.attributes
44
+
45
+ # Message Elements
46
+ soap_enum.messages
47
+ messages = soap_enum.messages.list
48
+ message = messages[0]
49
+ message.attributes
50
+ part = message.parts[0]
51
+ part.name
52
+
53
+ # portType Elements
54
+ soap_enum.port_types
55
+ port_types = soap_enum.port_types.list
56
+ port_type = port_types[0]
57
+ port_type.attributes
58
+ port_type.name
59
+ port_type.operations
60
+ operation = port_type.operations[0]
61
+ operation.name
62
+ operation.attributes
63
+ operation.input
64
+ operation.output
65
+
66
+ # Binding Elements
67
+ soap_enum.bindings
68
+ bindings = soap_enum.bindings.list
69
+ binding = bindings[0]
70
+ binding.attributes
71
+ binding.soap_binding
72
+ operation = binding.operations[0]
73
+ operation.attributes
74
+ operation.name
75
+ operation.input
76
+ operation.output
77
+
78
+ # Services Elements
79
+ soap_enum.services.list
80
+ service = soap_enum.services.list[0]
81
+ service.name
82
+ ports = service.ports
83
+ port = ports[0]
84
+ port.attributes
85
+ port.address
86
+ ```
87
+
88
+
89
+ ## Contributing
90
+ 1. Fork it ( https://github.com/KINGSABRI/soap_enumerator/fork )
91
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
92
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
93
+ 4. Push to the branch (`git push origin my-new-feature`)
94
+ 5. Create a new Pull Request
95
+
96
+ ## License
97
+
98
+ The gem is available as open source under the terms of the [LGPL-3.0 License](https://opensource.org/licenses/LGPL-3.0).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,49 @@
1
+ require_relative 'operation'
2
+
3
+ module SoapEnumerator
4
+ class Bindings
5
+ # Binding class is a class for wsdl:binding elements
6
+ #
7
+ # @example:
8
+ # bindings = soap_enum.bindings.list
9
+ # binding = bindings[0]
10
+ # binding.attributes
11
+ # binding.soap_binding
12
+ # operation = binding.operations[0]
13
+ # operation.attributes
14
+ # operation.name
15
+ # operation.input
16
+ # operation.output
17
+ #
18
+ class Binding
19
+ include GenericHelpers
20
+
21
+ # @!attribute #attributes
22
+ attr_reader :attributes
23
+ # @!attribute #soap_binding
24
+ attr_reader :soap_binding
25
+ # @!attribute #operations
26
+ attr_reader :operations
27
+
28
+ def initialize(binding_doc)
29
+ @attributes = attributes_2_methods(binding_doc)
30
+ @soap_binding = get_soap_binding(binding_doc)
31
+ @operations = get_operations(binding_doc)
32
+ end
33
+
34
+ private
35
+
36
+ def get_soap_binding(binding_doc)
37
+ binding_doc.search('//soap:binding').map do |sb|
38
+ attributes_2_hashes(sb.attributes)
39
+ end.flatten
40
+ end
41
+
42
+ def get_operations(binding_doc)
43
+ binding_doc.search('//wsdl:binding/wsdl:operation').map do |ops|
44
+ Bindings::Binding::Operation.new(ops)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,39 @@
1
+ module SoapEnumerator
2
+ class Bindings
3
+ class Binding
4
+ # Operation class is struct class for wsdl:operation
5
+ # elements (each element is an Operation object)
6
+ class Operation
7
+ include GenericHelpers
8
+
9
+ # @!attribute #attributes
10
+ attr_reader :attributes
11
+ # @!attribute #documentation
12
+ attr_reader :documentation
13
+ # @!attribute #input
14
+ attr_reader :input
15
+ # @!attribute #output
16
+ attr_reader :output
17
+
18
+ def initialize(ops_doc)
19
+ @attributes = attributes_2_methods(ops_doc)
20
+ @input = get_operation(ops_doc, 'input')
21
+ @output = get_operation(ops_doc, 'output')
22
+ @documentation = get_documentation(ops_doc)
23
+ end
24
+
25
+ private
26
+ def get_documentation(doc)
27
+ doc.search('documentation').text
28
+ end
29
+
30
+ def get_operation(doc, operation)
31
+ doc.elements
32
+ .select {|ops| ops.name.include?(operation)}[0]
33
+ .elements.map {|e| attributes_2_hashes(e.attributes) }.flatten
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,44 @@
1
+ require_relative 'bindings/binding'
2
+ # require_relative 'bindings/operation'
3
+
4
+ module SoapEnumerator
5
+
6
+ # Bindings class contains all bindings and its operations
7
+ #
8
+ # @example:
9
+ # doc = Nokogiri::XML(open(https://url/service.php?wsdl))
10
+ # bindings = SoapEnumerator::Bindings.new(doc)
11
+ # binding = bindings.bindings.list[0]
12
+ # pp binding
13
+ # pp binding.operations[0]
14
+ # pp binding.operations[0].name
15
+ # pp binding.operations[0].input
16
+ # pp binding.operations[0].output
17
+ #
18
+ class Bindings
19
+
20
+ attr_reader :list
21
+
22
+ def initialize(doc)
23
+ @list = get_bindings(doc.search('//wsdl:binding'))
24
+ end
25
+
26
+ private
27
+
28
+ # get_bindings method extracts a binding's name
29
+ #
30
+ # @param [Nokogiri::XML::Element] doc
31
+ # Elements of wsdl:binding in the wsdl document
32
+ #
33
+ # @return [Array<Binding>]
34
+ # returns array of Binding objects
35
+ #
36
+ # @note: safe navigation is used.
37
+ # If doc is nil, method returns nil
38
+ def get_bindings(doc)
39
+ doc&.map do |binding_doc|
40
+ Bindings::Binding.new(binding_doc)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,46 @@
1
+ require_relative 'types'
2
+ require_relative 'messages'
3
+ require_relative 'port_types'
4
+ require_relative 'bindings'
5
+ require_relative 'services'
6
+
7
+ module SoapEnumerator
8
+
9
+ # Types class contains all wsdl:definitions elements as objects.
10
+ #
11
+ # @example:
12
+ # doc = Nokogiri::XML(open(https://url/service.php?wsdl))
13
+ # definitions = SoapEnumerator::Definitions.new(doc)
14
+ # definitions.attributes
15
+ # definitions.types
16
+ # definitions.messages
17
+ # definitions.port_types
18
+ # definitions.bindings
19
+ # definitions.services
20
+ #
21
+ class Definitions
22
+ include GenericHelpers
23
+
24
+ # @!attribute #attributes
25
+ attr_reader :attributes
26
+ # @!attribute #types for wsdl schemas elements, it calls [Types] class
27
+ attr_reader :types
28
+ # @!attribute #messages for wsdl Message elements, it calls [Messages] class
29
+ attr_reader :messages
30
+ # @!attribute #port_types for wsdl PortType elements, it calls [PortTypes] class
31
+ attr_reader :port_types
32
+ # @!attribute #bindings for wsdl Binding elements, it calls [Bindings] class
33
+ attr_reader :bindings
34
+ # @!attribute #services for wsdl Service elements, it calls [Services] class
35
+ attr_reader :services
36
+
37
+ def initialize(doc)
38
+ @attributes = attributes_2_methods(doc.search('//wsdl:definitions')[0])
39
+ @types = Types.new(doc)
40
+ @messages = Messages.new(doc)
41
+ @port_types = PortTypes.new(doc)
42
+ @bindings = Bindings.new(doc)
43
+ @services = Services.new(doc)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,4 @@
1
+ module SoapEnumerator
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,58 @@
1
+ module SoapEnumerator
2
+ module GenericHelpers
3
+
4
+ def to_snake_case(string)
5
+ string.gsub(/::/, '/')
6
+ .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
7
+ .gsub(/([a-z\d])([A-Z])/,'\1_\2')
8
+ .tr("-", "_")
9
+ .downcase
10
+ end
11
+
12
+ # get each attribute,
13
+ # convert it to a singleton method.
14
+ # the new method's name comes from the attribute's name. (convert attr' name to snake_case)
15
+ # then get the method's value from the attribute's value
16
+ #
17
+ # @param [Nokogiri::XML::NodeSet] element
18
+ #
19
+ # @return [Array<Symbol>]
20
+ # Array of symbols which actually now are singleton methods with values
21
+ def attributes_2_methods(element)
22
+ element.attributes.map do |_k, attr_v|
23
+ define_singleton_method(to_snake_case(attr_v.name).to_sym) { attr_v.value }
24
+ end
25
+ end
26
+
27
+ def attributes_2_hashes(attributes)
28
+ attributes.values.map {|attr| {attr.name => attr.value}}.flatten
29
+ end
30
+
31
+ # safe_search method
32
+ # Safely search multiple terms in a document or raise exception.
33
+ # @param [Array<String>] search_terms
34
+ # Array of possible search terms to look for.
35
+ #
36
+ # @param [Nokogiri::XML::Document] doc
37
+ # The document to search in using Nokogiri::XML::NodeSet#search method
38
+ #
39
+ # @return [Array<Nokogiri::XML::NodeSet>]
40
+ # return the search's result as an array of [Nokogiri::XML::NodeSet] objects
41
+ def safe_search(search_terms, doc)
42
+ search_terms.map do |term|
43
+ begin
44
+ result = doc.search(term)
45
+ if result.empty? or result.nil?
46
+ next
47
+ else
48
+ return result
49
+ end
50
+ rescue Nokogiri::XML::XPath::SyntaxError
51
+ next
52
+ rescue Exception => e
53
+ puts e.full_message
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,35 @@
1
+ require_relative 'part'
2
+
3
+ module SoapEnumerator
4
+ class Messages
5
+
6
+ # Message class is struct class for wsd:message
7
+ class Message
8
+ include GenericHelpers
9
+
10
+ attr_accessor :attributes
11
+ attr_accessor :parts
12
+
13
+ def initialize(message_doc)
14
+ @attributes = attributes_2_methods(message_doc)
15
+ @parts = get_parts(message_doc)
16
+ end
17
+
18
+ private
19
+
20
+ # get_parts method create an Array of a message's parts
21
+ #
22
+ # @param [Nokogiri::XML::Element] message_doc
23
+ # Elements of wsdl:message in the wsdl document
24
+ #
25
+ # @return [Array<Messages::Message::Part>]
26
+ # returns an array of [Message::Part] objects(@see Message::Part)
27
+ # which contain each element's name and type
28
+ def get_parts(message_doc)
29
+ message_doc.elements&.map do |part_doc|
30
+ Messages::Message::Part.new(part_doc)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,16 @@
1
+ module SoapEnumerator
2
+ class Messages
3
+ class Message
4
+ # Part class is struct class for wsd:part elements (each element is a Part object).
5
+ class Part
6
+ include GenericHelpers
7
+
8
+ attr_reader :attributes
9
+
10
+ def initialize(part_doc)
11
+ @attributes = attributes_2_methods(part_doc)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'messages/message'
2
+
3
+ module SoapEnumerator
4
+
5
+ # Messages class contains all message elements as objects
6
+ #
7
+ # @example:
8
+ # doc = Nokogiri::XML(open(https://url/service.php?wsdl))
9
+ # messages = SoapEnumerator::Messages.new(doc)
10
+ # message = messages.list[0]
11
+ # message.name
12
+ # part = message.parts[0]
13
+ # part.name
14
+ #
15
+ class Messages
16
+
17
+ attr_reader :list
18
+
19
+ def initialize(doc)
20
+ @list = get_messages(doc.search('//wsdl:message'))
21
+ end
22
+
23
+ private
24
+
25
+ # get_messages method generate a list of wsdl:message messages
26
+ #
27
+ # @param [Nokogiri::XML::Document] doc
28
+ #
29
+ # @return <Array[Message]>
30
+ def get_messages(doc)
31
+ doc&.map do |message_doc|
32
+ Message.new(message_doc)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,40 @@
1
+ module SoapEnumerator
2
+ class PortTypes
3
+ class PortType
4
+ # Operation class is a class for wsdl:operation
5
+ class Operation
6
+ include GenericHelpers
7
+
8
+ # @!attribute #attributes
9
+ attr_reader :attributes
10
+ # @!attribute #documentation
11
+ attr_reader :documentation
12
+ # @!attribute #input
13
+ attr_reader :input
14
+ # @!attribute #output
15
+ attr_reader :output
16
+
17
+ def initialize(ops_doc)
18
+ @attributes = attributes_2_methods(ops_doc)
19
+ @documentation = get_documentation(ops_doc)
20
+ @input = get_operation(ops_doc, 'input')
21
+ @output = get_operation(ops_doc, 'output')
22
+ end
23
+
24
+ private
25
+
26
+ def get_documentation(doc)
27
+ doc.search('documentation').text
28
+ end
29
+
30
+ def get_operation(doc, operation)
31
+ attributes_2_hashes(
32
+ doc.elements
33
+ .select {|ops| ops.name.include?(operation)}[0]
34
+ .attributes
35
+ )
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'operation'
2
+
3
+ module SoapEnumerator
4
+
5
+ class PortTypes
6
+ # PortType class is struct class for wsdl:portType
7
+ class PortType
8
+ include GenericHelpers
9
+
10
+ # @!attribute #attributes
11
+ attr_reader :attributes
12
+ # @!attribute #operations
13
+ attr_reader :operations
14
+
15
+ def initialize(port_type_doc)
16
+ @attributes = attributes_2_methods(port_type_doc)
17
+ @operations = get_operations(port_type_doc)
18
+ end
19
+
20
+ private
21
+
22
+ # get_operations method
23
+ #
24
+ # @param [Nokogiri::XML::Document] port_type_doc
25
+ #
26
+ # @return [Array<Operation>]
27
+ # return object of [Operation] contains the name of the Operation
28
+ # and array of all existing operations. (@see #Operation)
29
+ def get_operations(port_type_doc)
30
+ port_type_doc.search('//wsdl:operation')&.map do |operation|
31
+ PortTypes::PortType::Operation.new(operation)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,39 @@
1
+ require_relative 'port_types/port_type'
2
+
3
+ module SoapEnumerator
4
+
5
+ # PortTypes class contains all portType's operation elements as objects
6
+ #
7
+ # @example:
8
+ # doc = Nokogiri::XML(open(https://url/service.php?wsdl))
9
+ # port_types = SoapEnumerator::PortTypes.new(doc)
10
+ # port_type = port_types.list[0]
11
+ # port_type.attributes
12
+ # port_type.name
13
+ # port_type.operations
14
+ # operation = port_type.operations[0]
15
+ # operation.name
16
+ # operation.attributes
17
+ # operation.input
18
+ # operation.output
19
+ #
20
+ class PortTypes
21
+
22
+ # @!attribute #list
23
+ attr_reader :list
24
+
25
+ def initialize(doc)
26
+ begin
27
+ @list = get_port_types(doc.search('//wsdl:portType'))
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def get_port_types(doc)
34
+ doc&.map do |port_type|
35
+ PortTypes::PortType.new(port_type)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,18 @@
1
+ module SoapEnumerator
2
+ class Services
3
+ class Service
4
+ class Port
5
+ class Address
6
+ include GenericHelpers
7
+
8
+ # @!attribute #attributes
9
+ attr_reader :attributes
10
+
11
+ def initialize(addr_doc)
12
+ @attributes = attributes_2_methods(addr_doc)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,35 @@
1
+ require_relative 'address'
2
+
3
+ module SoapEnumerator
4
+ class Services
5
+ class Service
6
+ class Port
7
+ include GenericHelpers
8
+
9
+ # @!attribute #attributes
10
+ attr_reader :attributes
11
+ # @!attribute #address
12
+ attr_reader :address
13
+ # @!attribute #documentation
14
+ attr_reader :documentation
15
+
16
+ def initialize(port_doc)
17
+ @attributes = attributes_2_methods(port_doc)
18
+ @address = get_address(port_doc)
19
+ @documentation = get_documentation(port_doc)
20
+ end
21
+
22
+ private
23
+
24
+ def get_documentation(doc)
25
+ doc.search('documentation').text
26
+ end
27
+
28
+ def get_address(port_doc)
29
+ Services::Service::Port::Address.new(port_doc.elements[0])
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,34 @@
1
+ require_relative 'port'
2
+
3
+ module SoapEnumerator
4
+ class Services
5
+ class Service
6
+ include GenericHelpers
7
+
8
+ # @!attribute #attributes
9
+ attr_reader :attributes
10
+ # @!attribute #ports
11
+ attr_reader :ports
12
+
13
+ attr_reader :documentation
14
+
15
+ def initialize(service_doc)
16
+ @attributes = attributes_2_methods(service_doc)
17
+ @ports = get_ports(service_doc)
18
+ @documentation = get_documentation(service_doc)
19
+ end
20
+
21
+ private
22
+
23
+ def get_documentation(doc)
24
+ doc.search('documentation').text
25
+ end
26
+
27
+ def get_ports(service_doc)
28
+ service_doc.search('//wsdl:port').map do |port|
29
+ Services::Service::Port.new(port)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'services/service'
2
+
3
+ module SoapEnumerator
4
+ class Services
5
+
6
+ attr_reader :list
7
+
8
+ def initialize(doc)
9
+ @list = get_services(doc.search('//wsdl:service'))
10
+ end
11
+
12
+ private
13
+ def get_services(doc)
14
+ doc&.map do |service_doc|
15
+ Services::Service.new(service_doc)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,38 @@
1
+ require_relative 'type'
2
+
3
+ module SoapEnumerator
4
+ class Types
5
+ class Schema
6
+ # ComplexType class is a class for complexType elements
7
+ class ComplexType
8
+ include GenericHelpers
9
+
10
+ # @!attribute #attributes
11
+ attr_reader :attributes
12
+ # @!attribute #all
13
+ attr_reader :all
14
+
15
+ def initialize(comp_type_doc)
16
+ @attributes = attributes_2_methods(comp_type_doc)
17
+ @all = get_type_doc(comp_type_doc)
18
+ end
19
+
20
+ private
21
+
22
+ # get_type_doc method
23
+ #
24
+ # @param [Nokogiri::XML::Document] comp_type_doc
25
+ #
26
+ # @return [Array<Type>]
27
+ # return object of [Type] contains the name of the Type
28
+ # and array of all existing types. (@see #Type)
29
+ def get_type_doc(comp_type_doc)
30
+ search_terms = ['./*/xsd:element', './*/s:element']
31
+ safe_search(search_terms, comp_type_doc)&.map do |element|
32
+ Types::Schema::Type.new(element) unless element.nil?
33
+ end.compact
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,62 @@
1
+ require_relative 'complex_type'
2
+ require_relative 'simple_type'
3
+
4
+ module SoapEnumerator
5
+ class Types
6
+ # Schema class contains all schema elements as objects.
7
+ # It dynamically detects schema attributes then generates
8
+ # attributes for these attributes.
9
+ # Also, it contains the complexType and simpleType objects
10
+ #
11
+ # @example:
12
+ # @see #Types
13
+ #
14
+ class Schema
15
+
16
+ include GenericHelpers
17
+
18
+ # @!attribute #attributes
19
+ attr_reader :attributes
20
+ # @!attribute #complex_types
21
+ attr_reader :complex_types
22
+ # @!attribute #simple_types
23
+ attr_reader :simple_types
24
+
25
+ def initialize(schema_doc)
26
+ @attributes = attributes_2_methods(schema_doc)
27
+ @complex_types = get_complex_types(schema_doc)
28
+ @simple_types = get_simple_types(schema_doc)
29
+ end
30
+
31
+ private
32
+
33
+ # get_complex_types method
34
+ #
35
+ # @param [Nokogiri::XML::Document] schema_doc
36
+ #
37
+ # @return [Array<ComplexType>]
38
+ # return object of [ComplexType] contains the name of the complexType
39
+ # and array of all existing types. (@see #Schema::ComplexType)
40
+ def get_complex_types(schema_doc)
41
+ search_terms = ['//./xsd:complexType', '//./s:complexType', '//./complexType']
42
+ safe_search(search_terms, schema_doc)&.map do |comp_types_doc|
43
+ Types::Schema::ComplexType.new(comp_types_doc) unless comp_types_doc.nil?
44
+ end.compact
45
+ end
46
+
47
+ # get_simple_types method
48
+ #
49
+ # @param [Nokogiri::XML::Document] schema_doc
50
+ #
51
+ # @return [Array<SimpleType>]
52
+ # return object of [SimpleType] contains the name of the simpleType
53
+ # and array of all existing types. (@see #Schema::SimpleType)
54
+ def get_simple_types(schema_doc)
55
+ search_terms = ['//./xsd:simpleType', '//./s:simpleType', '//./simpleType']
56
+ safe_search(search_terms, schema_doc)&.map do |comp_types_doc|
57
+ Types::Schema::SimpleType.new(comp_types_doc) unless comp_types_doc.nil?
58
+ end.compact
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,38 @@
1
+ require_relative 'type'
2
+
3
+ module SoapEnumerator
4
+ class Types
5
+ class Schema
6
+ # SimpleType class is a class for simpleType elements
7
+ class SimpleType
8
+ include GenericHelpers
9
+
10
+ # @!attribute #attributes
11
+ attr_reader :attributes
12
+ # @!attribute #all
13
+ attr_reader :all
14
+
15
+ def initialize(comp_type_doc)
16
+ @attributes = attributes_2_methods(comp_type_doc)
17
+ @all = get_type_doc(comp_type_doc)
18
+ end
19
+
20
+ private
21
+
22
+ # get_type_doc method
23
+ #
24
+ # @param [Nokogiri::XML::Document] comp_type_doc
25
+ #
26
+ # @return [Array<Type>]
27
+ # return object of [Type] contains the name of the Type
28
+ # and array of all existing types. (@see #Type)
29
+ def get_type_doc(comp_type_doc)
30
+ search_terms = ['./*/xsd:element', './*/s:element', './s:restriction']
31
+ safe_search(search_terms, comp_type_doc)&.map do |element|
32
+ Types::Schema::Type.new(element) unless element.nil?
33
+ end.compact
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,17 @@
1
+ module SoapEnumerator
2
+ class Types
3
+ class Schema
4
+ # Type class is struct class for xsd:all elements (each element is a Type object).
5
+ class Type
6
+ include GenericHelpers
7
+
8
+ # @!attribute #attributes
9
+ attr_reader :attributes
10
+
11
+ def initialize(type_doc)
12
+ @attributes = attributes_2_methods(type_doc)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,42 @@
1
+ require_relative 'types/schema'
2
+
3
+ module SoapEnumerator
4
+ # Types class contains all Types elements as objects
5
+ #
6
+ # @example:
7
+ # doc = Nokogiri::XML(open(https://url/service.php?wsdl))
8
+ # types = SoapEnumerator::Types.new(doc)
9
+ # schemas = types.schemas
10
+ # schema = schemas[0]
11
+ # schema.attributes
12
+ # schema.target_namespace
13
+ # complex_types = schema.complex_types
14
+ # complex_type = complex_types[-1]
15
+ # ctype = complex_type.all[0]
16
+ # ctype.attributes
17
+ # simple_types = schema.simple_types
18
+ # simple_types = simple_types
19
+ # simple_type = simple_types[0]
20
+ # stype = simple_type.all[0]
21
+ # stype.attributes
22
+ #
23
+ class Types
24
+ include GenericHelpers
25
+
26
+ # @!attribute #schemas
27
+ attr_reader :schemas
28
+
29
+ # @param [Nokogiri::XML::Document] doc
30
+ def initialize(doc)
31
+ @schemas = get_schemas(doc.search('//wsdl:types'))
32
+ end
33
+
34
+ private
35
+
36
+ def get_schemas(types_doc)
37
+ search_terms = ['//./xsd:schema', '//./s:schema', '//schema']
38
+ schemas = safe_search(search_terms, types_doc)
39
+ schemas.map { |schema| Types::Schema.new(schema) unless schema.nil? }
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module SoapEnumerator
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,44 @@
1
+ lib = File.expand_path('..', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'nokogiri'
5
+ require 'soap_enumerator/version'
6
+ require 'soap_enumerator/helpers/generic_helpers'
7
+ require 'soap_enumerator/definitions'
8
+ require 'soap_enumerator/types'
9
+ require 'soap_enumerator/port_types'
10
+ require 'soap_enumerator/messages'
11
+ require 'soap_enumerator/bindings'
12
+ require 'soap_enumerator/services'
13
+ require 'soap_enumerator/error'
14
+
15
+ module SoapEnumerator
16
+
17
+ class Parse
18
+ singleton_class.send(:alias_method, :wsdl, :new) # an alias for class method #new
19
+
20
+ # @!attribute #definitions for wsdl schemas elements, it calls [Definitions] class
21
+ attr_reader :definitions
22
+ # @!attribute #types for wsdl schemas elements, it calls [Types] class
23
+ attr_reader :types
24
+ # @!attribute #messages for wsdl Message elements, it calls [Messages] class
25
+ attr_reader :messages
26
+ # @!attribute #port_types for wsdl PortType elements, it calls [PortTypes] class
27
+ attr_reader :port_types
28
+ # @!attribute #bindings for wsdl Binding elements, it calls [Bindings] class
29
+ attr_reader :bindings
30
+ # @!attribute #services for wsdl Service elements, it calls [Services] class
31
+ attr_reader :services
32
+
33
+ def initialize(wsdl_doc)
34
+ doc = Nokogiri::XML(wsdl_doc)
35
+
36
+ @definitions = Definitions.new(doc)
37
+ @types = Types.new(doc)
38
+ @messages = Messages.new(doc)
39
+ @port_types = PortTypes.new(doc)
40
+ @bindings = Bindings.new(doc)
41
+ @services = Services.new(doc)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,25 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "soap_enumerator/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "soap_enumerator"
8
+ s.version = SoapEnumerator::VERSION
9
+ s.authors = ["KING SABRI"]
10
+ s.email = ["king.sabri@gmail.com"]
11
+
12
+ s.summary = %q{A gem for SOAP/WSDL enumeration inspired by SoapUI.}
13
+ s.description = %q{A gem for SOAP/WSDL enumeration inspired by SoapUI. It converts all SOAP's document to ruby objects.}
14
+ s.homepage = "https://github.com/KINGSABRI/soap_enumerator"
15
+ s.license = "LGPL-3.0"
16
+
17
+ s.require_paths = ["lib"]
18
+ s.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+
22
+ s.add_runtime_dependency 'nokogiri', '~> 1.8', '>= 1.8.0'
23
+ s.add_development_dependency "bundler", "~> 1.17"
24
+ s.add_development_dependency "rake", "~> 10.0"
25
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soap_enumerator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - KING SABRI
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.8.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.8'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.8.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.17'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.17'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ description: A gem for SOAP/WSDL enumeration inspired by SoapUI. It converts all SOAP's
62
+ document to ruby objects.
63
+ email:
64
+ - king.sabri@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - ".gitignore"
70
+ - Gemfile
71
+ - Gemfile.lock
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - lib/soap_enumerator.rb
76
+ - lib/soap_enumerator/bindings.rb
77
+ - lib/soap_enumerator/bindings/binding.rb
78
+ - lib/soap_enumerator/bindings/operation.rb
79
+ - lib/soap_enumerator/definitions.rb
80
+ - lib/soap_enumerator/error.rb
81
+ - lib/soap_enumerator/helpers/generic_helpers.rb
82
+ - lib/soap_enumerator/messages.rb
83
+ - lib/soap_enumerator/messages/message.rb
84
+ - lib/soap_enumerator/messages/part.rb
85
+ - lib/soap_enumerator/port_types.rb
86
+ - lib/soap_enumerator/port_types/operation.rb
87
+ - lib/soap_enumerator/port_types/port_type.rb
88
+ - lib/soap_enumerator/services.rb
89
+ - lib/soap_enumerator/services/address.rb
90
+ - lib/soap_enumerator/services/port.rb
91
+ - lib/soap_enumerator/services/service.rb
92
+ - lib/soap_enumerator/types.rb
93
+ - lib/soap_enumerator/types/complex_type.rb
94
+ - lib/soap_enumerator/types/schema.rb
95
+ - lib/soap_enumerator/types/simple_type.rb
96
+ - lib/soap_enumerator/types/type.rb
97
+ - lib/soap_enumerator/version.rb
98
+ - soap_enumerator.gemspec
99
+ homepage: https://github.com/KINGSABRI/soap_enumerator
100
+ licenses:
101
+ - LGPL-3.0
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.7.6
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: A gem for SOAP/WSDL enumeration inspired by SoapUI.
123
+ test_files: []