Test failure with ruby 3.1 - expected nil to match /\Ahttps:\/\/custom.example.com\/custom\/authorize\/path\?/
This was noticed in debian package when we updated ruby to 3.1 (it also fails with 3.0).
Log here https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1019643
I was also able to reproduce the bug when updating .ruby-version to 3.1.2 and running bundle exec rspec
$ bundle install
Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies....
Fetching rake 13.0.6
Installing rake 13.0.6
Using bundler 2.3.15
Fetching public_suffix 5.0.1
Fetching rexml 3.2.5
Installing rexml 3.2.5
Installing public_suffix 5.0.1
Fetching diff-lcs 1.5.0
Fetching faraday-net_http 3.0.2
Installing diff-lcs 1.5.0
Using ruby2_keywords 0.0.5
Using hashdiff 1.0.1
Fetching hashie 5.0.0
Installing faraday-net_http 3.0.2
Installing diff-lcs 1.5.0
Using ruby2_keywords 0.0.5
Using hashdiff 1.0.1
Fetching hashie 5.0.0
Installing faraday-net_http 3.0.2
Fetching jwt 2.7.0
Installing hashie 5.0.0
Installing jwt 2.7.0
Using multi_xml 0.6.0
Fetching rack 3.0.7
Fetching version_gem 1.1.2
Installing rack 3.0.7
Installing version_gem 1.1.2
Fetching rspec-support 3.12.0
Fetching crack 0.4.5
Installing rspec-support 3.12.0
Fetching addressable 2.8.1
Installing crack 0.4.5
Fetching faraday 2.7.4
Installing addressable 2.8.1
Installing crack 0.4.5
Fetching faraday 2.7.4
Installing addressable 2.8.1
Fetching snaky_hash 2.0.1
Installing faraday 2.7.4
Installing snaky_hash 2.0.1
Fetching rack-protection 3.0.5
Installing rack-protection 3.0.5
Fetching rack-test 2.1.0
Fetching rspec-core 3.12.1
Installing rack-test 2.1.0
Fetching rspec-expectations 3.12.2
Installing rspec-expectations 3.12.2
Installing rspec-core 3.12.1
Fetching rspec-mocks 3.12.4
Installing rspec-mocks 3.12.4
Fetching webmock 3.18.1
Fetching omniauth 2.1.1
Installing omniauth 2.1.1
Fetching oauth2 2.0.9
Installing oauth2 2.0.9
Installing webmock 3.18.1
Fetching rspec 3.12.0
Installing rspec 3.12.0
Fetching omniauth-oauth2 1.8.0
Installing omniauth-oauth2 1.8.0
Using omniauth-oauth2-generic 0.2.8 from source at `.`
Bundle complete! 5 Gemfile dependencies, 29 gems now installed.
Bundled gems are installed into `./vendor/bundle`
Post-install message from oauth2:
You have installed oauth2 version 2.0.9, congratulations!
There are BREAKING changes if you are upgrading from < v2, but most will not encounter them, and updating your code should be easy!
We have made two other major migrations:
1. master branch renamed to main
2. Github has been replaced with Gitlab
Please see:
• https://gitlab.com/oauth-xx/oauth2#what-is-new-for-v20
• https://gitlab.com/oauth-xx/oauth2/-/blob/main/CHANGELOG.md
• https://groups.google.com/g/oauth-ruby/c/QA_dtrXWXaE
Please report issues, and support the project! Thanks, |7eter l-|. l3oling
$ bundle exec rspec
OmniAuth::Strategies::OAuth2Generic
using default options
responds to the default auth URL (oauth2_generic) (FAILED - 1)
with custom provider settings
the auth endpoint (/auth/{name})
responds to the custom auth URL (FAILED - 2)
runs lambdas in authorize_params option and includes the result (FAILED - 3)
redirects to the correct custom authorize URL (FAILED - 4)
passes the correct redirect URL (FAILED - 5)
the callback (/auth/{name}/callback)
D, [2023-03-22T13:27:24.441448 #99715] DEBUG -- omniauth: (custom) Callback phase initiated.
responds to the custom callback URL and fetches a token from the custom token path
D, [2023-03-22T13:27:24.550383 #99715] DEBUG -- omniauth: (custom) Callback phase initiated.
fetches user info from the custom user info path
D, [2023-03-22T13:27:24.650263 #99715] DEBUG -- omniauth: (custom) Callback phase initiated.
sets up the auth hash for the client app
D, [2023-03-22T13:27:24.744615 #99715] DEBUG -- omniauth: (custom) Callback phase initiated.
parses user info correctly from the custom format
Failures:
1) OmniAuth::Strategies::OAuth2Generic using default options responds to the default auth URL (oauth2_generic)
Failure/Error: expect(last_response).to be_redirect
expected `#<Rack::MockResponse:0x00007f15d3491f48 @original_headers={"Content-Type"=>"text/plain"}, @errors="",...3.0.7/lib/rack/response.rb:351>, @block=nil, @body=["false"], @buffered=nil, @length=5, @cookies={}>.redirect?` to be truthy, got false
# ./spec/strategies/oauth2_generic_spec.rb:19:in `block (3 levels) in <top (required)>'
# ./vendor/bundle/ruby/3.1.0/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 level
s) in <top (required)>'
2) OmniAuth::Strategies::OAuth2Generic with custom provider settings the auth endpoint (/auth/{name}) responds to the custom auth URL
Failure/Error: expect(last_response).to be_redirect
expected `#<Rack::MockResponse:0x00007f15d2ed5500 @original_headers={"Content-Type"=>"application/json"}, @erro...-3.0.7/lib/rack/response.rb:351>, @block=nil, @body=["null"], @buffered=nil, @length=4, @cookies={}>.redirect?` to be truthy, got false
# ./spec/strategies/oauth2_generic_spec.rb:51:in `block (4 levels) in <top (required)>'
# ./vendor/bundle/ruby/3.1.0/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'
3) OmniAuth::Strategies::OAuth2Generic with custom provider settings the auth endpoint (/auth/{name}) runs lambdas in authorize_params option and includes the result
Failure/Error: redirect = URI.parse(last_response.headers['Location'])
URI::InvalidURIError:
bad URI(is not URI?): nil
# ./spec/strategies/oauth2_generic_spec.rb:55:in `block (4 levels) in <top (required)>'
# ./vendor/bundle/ruby/3.1.0/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# NoMethodError:
# undefined method `to_str' for nil:NilClass
#
# uri = uri.to_str
# ^^^^^^^
# ./spec/strategies/oauth2_generic_spec.rb:55:in `block (4 levels) in <top (required)>'
4) OmniAuth::Strategies::OAuth2Generic with custom provider settings the auth endpoint (/auth/{name}) redirects to the correct custom authorize URL
Failure/Error:
expect(last_response.headers['Location'])
.to match(%r{\Ahttps://custom.example.com/custom/authorize/path\?})
expected nil to match /\Ahttps:\/\/custom.example.com\/custom\/authorize\/path\?/
# ./spec/strategies/oauth2_generic_spec.rb:60:in `block (4 levels) in <top (required)>'
# ./vendor/bundle/ruby/3.1.0/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 level
s) in <top (required)>'
5) OmniAuth::Strategies::OAuth2Generic with custom provider settings the auth endpoint (/auth/{name}) passes the correct redirect URL
Failure/Error:
expect(last_response.headers['Location'])
.to match(/redirect_uri=https%3A%2F%2Fmy_server.com%2Foauth%2Fcallback&/)
expected nil to match /redirect_uri=https%3A%2F%2Fmy_server.com%2Foauth%2Fcallback&/
# ./spec/strategies/oauth2_generic_spec.rb:65:in `block (4 levels) in <top (required)>'
# ./vendor/bundle/ruby/3.1.0/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'
Finished in 0.51304 seconds (files took 1.12 seconds to load)
9 examples, 5 failures
Failed examples:
rspec ./spec/strategies/oauth2_generic_spec.rb:17 # OmniAuth::Strategies::OAuth2Generic using default options responds to the default auth URL (oauth2_generic)
rspec ./spec/strategies/oauth2_generic_spec.rb:50 # OmniAuth::Strategies::OAuth2Generic with custom provider settings the auth endpoint (/auth/{name}) responds to the custom auth URL
rspec ./spec/strategies/oauth2_generic_spec.rb:54 # OmniAuth::Strategies::OAuth2Generic with custom provider settings the auth endpoint (/auth/{name}) runs lambdas in authorize_params option and includes the result
rspec ./spec/strategies/oauth2_generic_spec.rb:59 # OmniAuth::Strategies::OAuth2Generic with custom provider settings the auth endpoint (/auth/{name}) redirects to the correct custom authorize URL
rspec ./spec/strategies/oauth2_generic_spec.rb:64 # OmniAuth::Strategies::OAuth2Generic with custom provider settings the auth endpoint (/auth/{name}) passes the correct redirect URL