wsdl_validator 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a26cd53860d077be92fa6ce8805acbfe00a5197
4
- data.tar.gz: 0be7f70752fd4f9fb777d409891e92025e1fd922
3
+ metadata.gz: a5721216e68fd329ead13d82fec5844311619ca1
4
+ data.tar.gz: 664b2b8714a805638a1a007abfe4b99074017346
5
5
  SHA512:
6
- metadata.gz: 424cacf768ad17fefe1e16be4a1e29a774610ba307663ca1962946730fef0fac2dd2f115c7b06cf121a2adf9bf556e9d76031fa29c384a498d210bd43776224c
7
- data.tar.gz: bfba1e7cffc896465e8051c93a04f507573e4c3327ceb63494aa28232c8eefb555e1ee9d13559a228edf67e7f348cb6d98206e82c912aa2fd0e24b294f676358
6
+ metadata.gz: 99de3efea0b7c0eb1ab80ba1197dc478eee9aed2b2986ed16d7538d8a093867842637fdc45d03d128d10e990b50b461ffc6319b2baeb203bb84db669c6045f30
7
+ data.tar.gz: 3dde01fa78cb78f157d245e2b2af649320cd45a30fd6c608e5e6b91950491864cfad3805e00d6fe0c1f7e799f4459d02e9112bdfcc43bc1784c483fe6bf6934d
data/README.md CHANGED
@@ -28,11 +28,7 @@ Or install it yourself as:
28
28
  wsdl = WsdlValidator.new('http://localhost:3333/single_schema?wsdl')
29
29
  wsdl.valid? xml_message
30
30
  ```
31
- => Returns true or false
32
-
33
- # TODO
34
- * Look up schemas that need to be imported
35
- * Basic authentication for reading schemas
31
+ => Returns true or raises an exception
36
32
 
37
33
  ## Development
38
34
 
@@ -1,3 +1,3 @@
1
1
  class WsdlValidator
2
- VERSION = '0.1.6'.freeze
2
+ VERSION = '0.1.7'.freeze
3
3
  end
@@ -3,6 +3,9 @@ require_relative 'error'
3
3
  # Helps to validate xml against schemas contained in a WSDL
4
4
  class WsdlValidator
5
5
 
6
+ # [String] Schemas found within WSDL
7
+ attr_accessor :show_schemas
8
+ # [Nokogiri::XML::Schema]
6
9
  attr_accessor :schemas
7
10
  attr_accessor :basic_auth
8
11
  attr_accessor :doc
@@ -12,7 +15,8 @@ class WsdlValidator
12
15
  def initialize(wsdl_url)
13
16
  self.basic_auth = extract_auth(wsdl_url)
14
17
  self.doc = Wasabi.document wsdl_url
15
- self.schemas = Nokogiri::XML::Schema(parse_wsdl_schemas)
18
+ self.show_schemas = parse_wsdl_schemas
19
+ self.schemas = Nokogiri::XML::Schema(show_schemas)
16
20
  rescue Wasabi::Resolver::HTTPError => e
17
21
  raise WsdlValidator::Error, "Unauthorized for basic auth #{basic_auth}" if e.response.code == 401
18
22
  raise e
@@ -30,22 +34,31 @@ class WsdlValidator
30
34
  Nokogiri::XML root_element.to_s # Convert to Xml Document
31
35
  end
32
36
 
37
+ # Returns a list of syntax errors. Empty list indicates valid xml
33
38
  # @param [String, Nokogiri::XML::NodeSet] xml
34
- # @return [Boolean] Whether xml is valid according to WSDL of class
35
- def valid?(xml)
39
+ # @return [Array] List of Nokogiri::XML::SyntaxError objects
40
+ def errors_for(xml)
36
41
  raise "Incorrect type #{xml.class}" unless [String, Nokogiri::XML::Document, Nokogiri::XML::NodeSet].include? xml.class
37
42
  xml_under_test = Nokogiri::XML(xml.to_s)
38
43
  soap_envelope = xml_under_test.children.find { |e| e.name == 'Envelope' }
39
44
  xml_under_test = extract_root_from_soap(soap_envelope) if soap_envelope
40
- validator = schemas.validate(xml_under_test)
45
+ schemas.validate(xml_under_test)
46
+ end
47
+
48
+ # @param [String, Nokogiri::XML::NodeSet] xml
49
+ # @return [Boolean, Exception] Whether xml is valid according to WSDL of class
50
+ def valid?(xml)
51
+ validator = errors_for xml
41
52
  raise WsdlValidator::Error, validator.join unless validator.empty?
42
53
  true
43
54
  end
44
55
 
56
+ alias validate valid?
57
+
45
58
  private
46
59
 
47
- # Returns a string used to prefix a URL for basic auth
48
- # @return [Array] Format is 'user_name:password@' or empty string
60
+ # Returns an Array with basic auth in it
61
+ # @return [Array] Format is [user_name, password] or []
49
62
  def extract_auth(wsdl_location)
50
63
  return [] unless wsdl_location.to_s =~ /^http|socks/
51
64
  url = wsdl_location.is_a?(URI) ? wsdl_location : URI(wsdl_location)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wsdl_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Garratt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-29 00:00:00.000000000 Z
11
+ date: 2018-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpi