-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There are cases where the auth flow between this service and DSI can get into an inconsistent state, resulting in CSRF and state errors from the auth provider. For example: - authenticate with an unauthorised organisation - open a new tab to attempt a new sign in - submit the form and get a state error from DSI To resolve these cases, and to make the auth flow more robust, we do the following: - Reset the session on the sign in page instead of clearing specific session attributes in the omniauth callback controller. This gives us a simpler baseline state from which to attempt authentication, regardless of how the user arrives at the page (whether through direct navigation, or a redirect following an error). - Add an oauth_failure param when redirecting after an oauth error, so that we can continue to display a flash message on the sign in page despite having reset the session. - Add system specs for this behaviour.
- Loading branch information
1 parent
4918de5
commit ccc8cdf
Showing
5 changed files
with
66 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
class SignInController < ApplicationController | ||
skip_before_action :authenticate_dsi_user! | ||
skip_before_action :handle_expired_session! | ||
before_action :reset_session | ||
before_action :handle_failed_sign_in, if: -> { params[:oauth_failure] == "true" } | ||
|
||
def new | ||
end | ||
|
||
private | ||
|
||
def handle_failed_sign_in | ||
flash.now[:warning] = I18n.t("generic_oauth_failure") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe "DSI authentication", type: :system do | ||
include ActivateFeaturesSteps | ||
include AuthenticationSteps | ||
|
||
before do | ||
given_the_service_is_open | ||
allow(Sentry).to receive(:capture_exception) | ||
end | ||
|
||
scenario "User has oauth error when signing in", test: :with_stubbed_auth do | ||
given_dsi_auth_is_mocked_with_a_failure("invalid_credentials") do | ||
when_i_visit_the_sign_in_page | ||
and_click_the_dsi_sign_in_button | ||
then_i_see_a_sign_in_error | ||
end | ||
end | ||
|
||
scenario "User has sessionexpiry oauth error", test: :with_stubbed_auth do | ||
given_dsi_auth_is_mocked_with_a_failure("sessionexpired") do | ||
when_i_visit_the_sign_in_page | ||
and_click_the_dsi_sign_in_button | ||
then_i_am_redirected_to_sign_in | ||
end | ||
end | ||
|
||
private | ||
|
||
def then_i_see_a_sign_in_error | ||
expect(page).to have_content "There was a problem signing you in. Please try again." | ||
end | ||
|
||
def then_i_am_redirected_to_sign_in | ||
expect(page).to have_current_path(sign_in_path) | ||
end | ||
end |