Skip to content

Commit

Permalink
added global :ssl_verify_mode options. fixes #297.
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiii committed Dec 19, 2012
1 parent dec5772 commit cd94583
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
## 2.0.2 (UPCOMING)

* Fix: [#297](https://github.com/savonrb/savon/issues/297#issuecomment-11536517) added the global
`:ssl_verify_mode` option set the verify mode to use for SOAP requests.

## 2.0.1 (2012-12-19)

* Fix [#342](https://github.com/savonrb/savon/issues/342) fixes an issue where namespaces could
Expand Down
5 changes: 5 additions & 0 deletions lib/savon/options.rb
Expand Up @@ -180,6 +180,11 @@ def last_response(last_response)
@options[:last_response] = last_response
end

# Whether and how to to verify the connection.
def ssl_verify_mode(verify_mode)
@options[:ssl_verify_mode] = verify_mode
end

# HTTP basic auth credentials.
def basic_auth(*credentials)
@options[:basic_auth] = credentials.flatten
Expand Down
1 change: 1 addition & 0 deletions lib/savon/request.rb
Expand Up @@ -48,6 +48,7 @@ def create_http_client
http.headers["SOAPAction"] ||= %{"#{soap_action}"} if soap_action
http.headers["Content-Type"] = CONTENT_TYPE[@globals[:soap_version]] % @globals[:encoding]

http.auth.ssl.verify_mode = @globals[:ssl_verify_mode] if @globals.include? :ssl_verify_mode
http.auth.basic(*@globals[:basic_auth]) if @globals.include? :basic_auth
http.auth.digest(*@globals[:digest_auth]) if @globals.include? :digest_auth

Expand Down
9 changes: 9 additions & 0 deletions spec/savon/options_spec.rb
Expand Up @@ -255,6 +255,15 @@
end
end

context "global :ssl_verify_mode" do
it "sets the verify mode to use" do
HTTPI::Auth::SSL.any_instance.expects(:verify_mode=).with(:none)

client = new_client(:endpoint => @server.url, :ssl_verify_mode => :none)
client.call(:authenticate)
end
end

context "global :basic_auth" do
it "sets the basic auth credentials" do
client = new_client(:endpoint => @server.url(:basic_auth), :basic_auth => ["admin", "secret"])
Expand Down

2 comments on commit cd94583

@garcialopezco
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still having troubles with this, when I did:

client = Savon.client( wsdl: "https://t1demo.facturacionmoderna.com/timbrado/wsdl", ssl_verify_mode: :none)

and tried

client.operations 

I got:

D, [2012-12-20T21:46:43.920644 #5369] DEBUG -- : HTTPI GET request to t1demo.facturacionmoderna.com (net_http)
/home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/httpi-2.0.0/lib/httpi/adapter/net_http.rb:36:in `rescue in request': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (HTTPI::SSLError)
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/httpi-2.0.0/lib/httpi/adapter/net_http.rb:27:in `request'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/httpi-2.0.0/lib/httpi.rb:137:in `request'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/httpi-2.0.0/lib/httpi.rb:103:in `get'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/wasabi-3.0.0/lib/wasabi/resolver.rb:36:in `load_from_remote'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/wasabi-3.0.0/lib/wasabi/resolver.rb:26:in `resolve'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/wasabi-3.0.0/lib/wasabi/document.rb:113:in `xml'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/wasabi-3.0.0/lib/wasabi/document.rb:131:in `parse'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/wasabi-3.0.0/lib/wasabi/document.rb:118:in `parser'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/wasabi-3.0.0/lib/wasabi/document.rb:61:in `soap_actions'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/savon-2.0.2/lib/savon/client.rb:28:in `operations'
    from test.rb:47:in `<main>'

After some tests I figured out method names and tried to test one of them

client.call(:request_timbrar_cfdi)

and got:

D, [2012-12-20T20:16:51.322247 #1130] DEBUG -- : HTTPI GET request to t1demo.facturacionmoderna.com (net_http)
/home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/httpi-2.0.0/lib/httpi/adapter/net_http.rb:36:in `rescue in request': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (HTTPI::SSLError)
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/httpi-2.0.0/lib/httpi/adapter/net_http.rb:27:in `request'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/httpi-2.0.0/lib/httpi.rb:137:in `request'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/httpi-2.0.0/lib/httpi.rb:103:in `get'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/wasabi-3.0.0/lib/wasabi/resolver.rb:36:in `load_from_remote'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/wasabi-3.0.0/lib/wasabi/resolver.rb:26:in `resolve'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/wasabi-3.0.0/lib/wasabi/document.rb:113:in `xml'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/wasabi-3.0.0/lib/wasabi/document.rb:131:in `parse'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/wasabi-3.0.0/lib/wasabi/document.rb:118:in `parser'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/wasabi-3.0.0/lib/wasabi/document.rb:61:in `soap_actions'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/savon-2.0.2/lib/savon/operation.rb:19:in `ensure_exists!'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/savon-2.0.2/lib/savon/operation.rb:12:in `create'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/savon-2.0.2/lib/savon/client.rb:32:in `operation'
    from /home/carlos/.rvm/gems/ruby-1.9.3-p286@prueba_fm/gems/savon-2.0.2/lib/savon/client.rb:36:in `call'
    from test.rb:48:in `<main>'

In both cases the failure comes from 'load_from_remote' of wasabi's resolver class, looking at wasabi's code seems the problem reside in that global options aren't passed to request

From: https://github.com/savonrb/wasabi/blob/master/lib/wasabi/resolver.rb
def load_from_remote
      request.url = document
      response = HTTPI.get(request)

      raise HTTPError, response if response.error?
      response.body
end

I'll be doing some more tests. ;)

@rubiii
Copy link
Contributor Author

@rubiii rubiii commented on cd94583 Dec 21, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you're right. i opened #349 to discuss this problem.

Please sign in to comment.