[deploy] Sets Omniauth full_host config to match the environment (#10419)

* Sets Omniauth full_host config to match the environment

* Fixes tests by passing missing params in omniauth env to mocks

* Default param as nil in omniauth mock helpers
This commit is contained in:
Fernando Valverde 2020-09-22 15:47:50 -06:00 committed by GitHub
parent b0e086346d
commit 779fad25b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 7 deletions

View file

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

View file

@ -71,13 +71,14 @@ module OmniauthHelpers
OmniAuth.config.mock_auth[provider] = :invalid_credentials
end
def omniauth_setup_authentication_error(error)
def omniauth_setup_authentication_error(error, params = nil)
# this hack is needed due to a limitation in how OmniAuth handles
# failures in mocked/testing environments,
# see <https://github.com/omniauth/omniauth/issues/654#issuecomment-610851884>
# for more details
local_failure_handler = lambda do |env|
env["omniauth.error"] = error
env["omniauth.params"] = params unless params.nil?
env
end

View file

@ -117,7 +117,7 @@ RSpec.describe "Authenticating with Facebook" do
"Callback error", "Error reason", "https://example.com/error"
)
omniauth_setup_authentication_error(error)
omniauth_setup_authentication_error(error, params)
visit sign_up_path
click_link(sign_in_link, match: :first)
@ -133,7 +133,7 @@ RSpec.describe "Authenticating with Facebook" do
allow(request).to receive(:code).and_return(401)
allow(request).to receive(:message).and_return("unauthorized")
error = OAuth::Unauthorized.new(request)
omniauth_setup_authentication_error(error)
omniauth_setup_authentication_error(error, params)
visit sign_up_path
click_link(sign_in_link, match: :first)
@ -146,7 +146,7 @@ RSpec.describe "Authenticating with Facebook" do
it "notifies Datadog even with no OmniAuth error present" do
error = nil
omniauth_setup_authentication_error(error)
omniauth_setup_authentication_error(error, params)
visit sign_up_path
click_link(sign_in_link, match: :first)

View file

@ -84,7 +84,7 @@ RSpec.describe "Authenticating with GitHub" do
"Callback error", "Error reason", "https://example.com/error"
)
omniauth_setup_authentication_error(error)
omniauth_setup_authentication_error(error, params)
visit sign_up_path
click_link(sign_in_link, match: :first)
@ -100,7 +100,7 @@ RSpec.describe "Authenticating with GitHub" do
allow(request).to receive(:code).and_return(401)
allow(request).to receive(:message).and_return("unauthorized")
error = OAuth::Unauthorized.new(request)
omniauth_setup_authentication_error(error)
omniauth_setup_authentication_error(error, params)
visit sign_up_path
click_link(sign_in_link, match: :first)
@ -113,7 +113,7 @@ RSpec.describe "Authenticating with GitHub" do
it "notifies Datadog even with no OmniAuth error present" do
error = nil
omniauth_setup_authentication_error(error)
omniauth_setup_authentication_error(error, params)
visit sign_up_path
click_link(sign_in_link, match: :first)