Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid port number #116

Closed
ebeigarts opened this issue Jul 20, 2011 · 6 comments
Closed

Invalid port number #116

ebeigarts opened this issue Jul 20, 2011 · 6 comments

Comments

@ebeigarts
Copy link

There is a problem when using authentication that has a password that includes a "#" (e.g. E43xb_d#A):

Addressable::URI::InvalidURIError: Invalid port number: "E43xb_d"

addressable-2.2.6/lib/addressable/uri.rb:1157:in `port='
addressable-2.2.6/lib/addressable/uri.rb:714:in `block in initialize'
addressable-2.2.6/lib/addressable/uri.rb:2151:in `call'
addressable-2.2.6/lib/addressable/uri.rb:2151:in `defer_validation'
addressable-2.2.6/lib/addressable/uri.rb:706:in `initialize'
addressable-2.2.6/lib/addressable/uri.rb:130:in `new'
addressable-2.2.6/lib/addressable/uri.rb:130:in `parse'
addressable-2.2.6/lib/addressable/uri.rb:181:in `heuristic_parse'
webmock-1.6.4/lib/webmock/util/uri.rb:15:in `block in <class:URI>'
webmock-1.6.4/lib/webmock/util/uri.rb:27:in `yield'
webmock-1.6.4/lib/webmock/util/uri.rb:27:in `default'
webmock-1.6.4/lib/webmock/util/uri.rb:27:in `heuristic_parse'
webmock-1.6.4/lib/webmock/util/uri.rb:19:in `block in <class:URI>'
webmock-1.6.4/lib/webmock/util/uri.rb:33:in `yield'
webmock-1.6.4/lib/webmock/util/uri.rb:33:in `default'
webmock-1.6.4/lib/webmock/util/uri.rb:33:in `normalize_uri'
webmock-1.6.4/lib/webmock/request_signature.rb:10:in `initialize'
webmock-1.6.4/lib/webmock/http_lib_adapters/curb.rb:47:in `new'
webmock-1.6.4/lib/webmock/http_lib_adapters/curb.rb:47:in `build_request_signature'
webmock-1.6.4/lib/webmock/http_lib_adapters/curb.rb:6:in `curb_or_webmock'
webmock-1.6.4/lib/webmock/http_lib_adapters/curb.rb:164:in `perform_with_webmock'

Currently I have monkey patched (added URI.encode) it and it works for me:

class WebMock::RequestSignature
  def initialize(method, uri, options = {})
    self.method = method
    self.uri = uri.is_a?(Addressable::URI) ? uri : WebMock::Util::URI.normalize_uri(URI.encode(uri))
    assign_options(options)
  end
end
@bblimke
Copy link
Owner

bblimke commented Jul 31, 2011

It's an issue with Addressable. I created an issue sporkmonger/addressable#42

@bblimke
Copy link
Owner

bblimke commented Aug 2, 2011

Looks like allowing unencoded '#' in password by Addressable could have negative consequences, please see sporkmonger/addressable#42
WebMock allows invalid unencoded uri in stubs or expectation but that's one of the edge cases where it just doesn't work.
Solution you provided - URI.encode of the whole uri in request signature - works in your case, but it means other uris won't be accepted by webmock (URI.parse throws exception on some unescaped uris).
I'm going to close this issue, but I'm happy to accept a patch if someone finds a good solution.

@bblimke bblimke closed this as completed Aug 2, 2011
@ebeigarts
Copy link
Author

Ok, thanks. I will try to create a proper patch when I have time.

@bblimke bblimke reopened this Aug 2, 2011
@bblimke
Copy link
Owner

bblimke commented Aug 2, 2011

I re-opened the issue :)
have a look here https://github.com/bblimke/webmock/blob/master/lib/webmock/util/uri.rb#L4
maybe adding # character to it will be enough.No time now, but I can check tonight unless you do it earlier

@bblimke
Copy link
Owner

bblimke commented Aug 2, 2011

I looked at it again, but I'm not sure this can be fixed.

Let's say we have following uri "us#rn@me:sec//ret?@host.com/". This uri contains forbidden characters in userinfo. We assume that username is us#rn@me and password is sec//ret? But for uri parser it's impossible to recognise where is the start and the end of userinfo.
Even URI.encode method won't help here.

@bblimke
Copy link
Owner

bblimke commented Aug 4, 2011

Closing this issue since there is no fix imo. I'll be happy to reopen it, if it can be fixed.

@bblimke bblimke closed this as completed Aug 4, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants