Fixes Omniauth redirect_uri when SiteConfig.app_domain is updated (#10432)

* Makes Omniauth rely on Proc instead of initializer value for redirect uri

* Adds SiteConfig.app_domain test for OAuth providers callback_url generation

* Fixes protocol mismatch in test

* Fixes URL encoding problem with query params in test
This commit is contained in:
Fernando Valverde 2020-09-24 11:57:51 -06:00 committed by GitHub
parent 3e9b56a7dd
commit 5d110c6fe0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View file

@ -1,2 +1,2 @@
OmniAuth.config.logger = Rails.logger
OmniAuth.config.full_host = URL.url
OmniAuth.config.full_host = proc { URL.url }

View file

@ -0,0 +1,35 @@
require "rails_helper"
RSpec.describe "Omniauth redirect_uri", type: :system do
let!(:test_app_domain) { SiteConfig.app_domain }
# Avoid messing with other tests by resetting back SiteConfig.app_domain
after { SiteConfig.app_domain = test_app_domain }
def provider_redirect_regex(provider_name)
# URL encoding translates the query params (i.e. colons/slashes/etc)
%r{
/users/auth/#{provider_name}
\?callback_url=#{ERB::Util.url_encode(URL.protocol)}
#{ERB::Util.url_encode(SiteConfig.app_domain)}
#{ERB::Util.url_encode("/users/auth/#{provider_name}/callback")}
}x
end
it "relies on SiteConfig.app_domain to generate correct callbacks_url" do
visit sign_up_path
Authentication::Providers.available.each do |provider_name|
provider_auth_url = find("a.crayons-btn--brand-#{provider_name}")["href"]
expect(provider_auth_url).to match(provider_redirect_regex(provider_name))
end
SiteConfig.app_domain = "test.forem.com"
visit sign_up_path
# After an update the callback_url should now match SiteConfig.app_domain
Authentication::Providers.available.each do |provider_name|
provider_auth_url = find("a.crayons-btn--brand-#{provider_name}")["href"]
expect(provider_auth_url).to match(provider_redirect_regex(provider_name))
end
end
end