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

Cannot stub OPTIONS * requests #982

Open
postmodern opened this issue Jul 16, 2022 · 2 comments
Open

Cannot stub OPTIONS * requests #982

postmodern opened this issue Jul 16, 2022 · 2 comments

Comments

@postmodern
Copy link
Contributor

It does not appear to be possible to stub an OPTIONS request where the path is *.

Example

require 'spec_helper'
require 'webmock/rspec'

describe Test do
  it "must stub a OPTIONS request with path '*'" do
    stub_request(:options,"example.com*")

    http = Net::HTTP.new('example.com',80)
    req = Net::HTTP::Options.new('*')
    http.request(req)
  end
end

Result

Test
  must stub a OPTIONS request with path '*' (FAILED - 1)

Failures:

  1) Test must stub a OPTIONS request with path '*'
     Failure/Error: http.request(req)
     
     Addressable::URI::InvalidURIError:
       Invalid port number: "80*"
     # ./vendor/bundle/ruby/3.1.0/gems/addressable-2.8.0/lib/addressable/uri.rb:1430:in `port='
     # ./vendor/bundle/ruby/3.1.0/gems/addressable-2.8.0/lib/addressable/uri.rb:848:in `block in initialize'
     # ./vendor/bundle/ruby/3.1.0/gems/addressable-2.8.0/lib/addressable/uri.rb:2419:in `defer_validation'
     # ./vendor/bundle/ruby/3.1.0/gems/addressable-2.8.0/lib/addressable/uri.rb:840:in `initialize'
     # ./vendor/bundle/ruby/3.1.0/gems/addressable-2.8.0/lib/addressable/uri.rb:147:in `new'
     # ./vendor/bundle/ruby/3.1.0/gems/addressable-2.8.0/lib/addressable/uri.rb:147:in `parse'
     # ./vendor/bundle/ruby/3.1.0/gems/addressable-2.8.0/lib/addressable/uri.rb:225:in `heuristic_parse'
     # ./vendor/bundle/ruby/3.1.0/gems/webmock-3.14.0/lib/webmock/util/uri.rb:11:in `block in <class:URI>'
     # ./vendor/bundle/ruby/3.1.0/gems/webmock-3.14.0/lib/webmock/util/uri.rb:27:in `heuristic_parse'
     # ./vendor/bundle/ruby/3.1.0/gems/webmock-3.14.0/lib/webmock/util/uri.rb:15:in `block in <class:URI>'
     # ./vendor/bundle/ruby/3.1.0/gems/webmock-3.14.0/lib/webmock/util/uri.rb:33:in `normalize_uri'
     # ./vendor/bundle/ruby/3.1.0/gems/webmock-3.14.0/lib/webmock/request_signature.rb:10:in `initialize'
     # ./vendor/bundle/ruby/3.1.0/gems/webmock-3.14.0/lib/webmock/http_lib_adapters/net_http.rb:341:in `new'
     # ./vendor/bundle/ruby/3.1.0/gems/webmock-3.14.0/lib/webmock/http_lib_adapters/net_http.rb:341:in `request_signature_from_request'
     # ./vendor/bundle/ruby/3.1.0/gems/webmock-3.14.0/lib/webmock/http_lib_adapters/net_http.rb:75:in `request'
     # ./spec/test_spec.rb:10:in `block (2 levels) in <top (required)>'
     # ./vendor/bundle/ruby/3.1.0/gems/webmock-3.14.0/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'
@bblimke
Copy link
Owner

bblimke commented Aug 2, 2022

Thank you for raising. Indeed, it expects a valid path path string and does not accept *. Do you know if *, single character, is the only exception?

@postmodern
Copy link
Contributor Author

AFAIK, only OPTIONS * and CONNECT host:port are the only examples of when HTTP methods do not accept an absolute path. Normally, OPTIONS accepts an absolute path, but * indicates requesting the allowed options for the entire server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants