From bfe5cfdd08f8d94988fd081b26e3c493857fceea Mon Sep 17 00:00:00 2001 From: Richard Pattinson Date: Fri, 10 Jan 2025 10:00:21 +0000 Subject: [PATCH] Redirect sign in page --- .env.development | 2 + .env.test | 1 + Gemfile | 1 + Gemfile.lock | 2 + app/controllers/sign_in_controller.rb | 5 +++ app/controllers/sign_out_controller.rb | 3 +- spec/support/system/authentication_steps.rb | 8 ++-- .../user_has_oauth_error_signing_in_spec.rb | 39 ------------------- spec/system/user_signs_out_spec.rb | 2 +- 9 files changed, 18 insertions(+), 45 deletions(-) delete mode 100644 spec/system/user_has_oauth_error_signing_in_spec.rb diff --git a/.env.development b/.env.development index e607f870..9fd49a10 100644 --- a/.env.development +++ b/.env.development @@ -2,6 +2,8 @@ BYPASS_DSI=true HOSTING_DOMAIN=http://localhost:3000 HOSTING_ENVIRONMENT=local +CHECK_CHILDRENS_BARRED_LIST_GUIDANCE_URL=https://www.gov.uk/guidance/check-the-childrens-barred-list + DFE_SIGN_IN_API_BASE_URL=https://dev-api.signin.education.gov.uk DFE_SIGN_IN_API_SECRET=override-locally DFE_SIGN_IN_API_AUDIENCE=signin.education.gov.uk diff --git a/.env.test b/.env.test index 8a9560b2..8d0c77a4 100644 --- a/.env.test +++ b/.env.test @@ -1,3 +1,4 @@ +CHECK_CHILDRENS_BARRED_LIST_GUIDANCE_URL=https://www.gov.uk/guidance/check-the-childrens-barred-list DFE_SIGN_IN_API_BASE_URL=https://dev-api.signin.education.gov.uk DFE_SIGN_IN_API_SECRET=test DFE_SIGN_IN_API_AUDIENCE=signin.education.gov.uk diff --git a/Gemfile b/Gemfile index 6c98e456..6de2dfd0 100644 --- a/Gemfile +++ b/Gemfile @@ -36,6 +36,7 @@ gem "govuk_markdown" # Provide endpoint for server healthchecks gem "okcomputer" +gem "repost" # Sentry error reporting gem "sentry-rails" gem "sentry-ruby" diff --git a/Gemfile.lock b/Gemfile.lock index f1f1822c..82c3e3fe 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -419,6 +419,7 @@ GEM regexp_parser (2.9.2) reline (0.5.9) io-console (~> 0.5) + repost (0.4.2) representable (3.2.0) declarative (< 0.1.0) trailblazer-option (>= 0.1.1, < 0.2.0) @@ -629,6 +630,7 @@ DEPENDENCIES puma (~> 6.4) rails (~> 7.1.3) rails_semantic_logger + repost rladr rspec rspec-rails diff --git a/app/controllers/sign_in_controller.rb b/app/controllers/sign_in_controller.rb index fb22b198..aeb0c793 100644 --- a/app/controllers/sign_in_controller.rb +++ b/app/controllers/sign_in_controller.rb @@ -7,6 +7,11 @@ class SignInController < ApplicationController before_action :handle_failed_sign_in, if: -> { params[:oauth_failure] == "true" } def new + if DfESignIn.bypass? + redirect_post "/auth/developer/callback", options: { authenticity_token: :auto } + else + redirect_post "/auth/dfe", options: { authenticity_token: :auto } + end end private diff --git a/app/controllers/sign_out_controller.rb b/app/controllers/sign_out_controller.rb index 129c8437..acaed4a1 100644 --- a/app/controllers/sign_out_controller.rb +++ b/app/controllers/sign_out_controller.rb @@ -5,6 +5,7 @@ class SignOutController < ApplicationController before_action :reset_session def new - redirect_to sign_in_path + redirect_to ENV.fetch("CHECK_RECORDS_GUIDANCE_URL", "https://www.gov.uk/guidance/check-the-childrens-barred-list"), + allow_other_host: true end end diff --git a/spec/support/system/authentication_steps.rb b/spec/support/system/authentication_steps.rb index 96024e34..e897a5e6 100644 --- a/spec/support/system/authentication_steps.rb +++ b/spec/support/system/authentication_steps.rb @@ -2,7 +2,7 @@ module AuthenticationSteps def when_i_sign_in_via_dsi(authorised: true, orgs: [organisation], accept_terms_and_conditions: true) given_dsi_auth_is_mocked(authorised:, orgs:) when_i_visit_the_sign_in_page - and_click_the_dsi_sign_in_button + and_wait_for_the_page_to_load and_i_accept_the_terms_and_conditions(accept_terms_and_conditions) end alias_method :and_i_am_signed_in_via_dsi, :when_i_sign_in_via_dsi @@ -10,7 +10,7 @@ def when_i_sign_in_via_dsi(authorised: true, orgs: [organisation], accept_terms_ def when_i_sign_in_as_an_internal_user_via_dsi given_dsi_auth_is_mocked(authorised: true, internal: true) when_i_visit_the_sign_in_page - and_click_the_dsi_sign_in_button + and_wait_for_the_page_to_load and_i_accept_the_terms_and_conditions(true) end alias_method :and_i_am_signed_in_as_an_internal_user_via_dsi, :when_i_sign_in_as_an_internal_user_via_dsi @@ -96,8 +96,8 @@ def when_i_visit_the_sign_in_page visit sign_in_path end - def and_click_the_dsi_sign_in_button - click_button "Start now" + def and_wait_for_the_page_to_load + page.driver.refresh end def organisations_endpoint diff --git a/spec/system/user_has_oauth_error_signing_in_spec.rb b/spec/system/user_has_oauth_error_signing_in_spec.rb deleted file mode 100644 index 233d6ccd..00000000 --- a/spec/system/user_has_oauth_error_signing_in_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -# 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 diff --git a/spec/system/user_signs_out_spec.rb b/spec/system/user_signs_out_spec.rb index b1180722..e76902e7 100644 --- a/spec/system/user_signs_out_spec.rb +++ b/spec/system/user_signs_out_spec.rb @@ -20,6 +20,6 @@ def when_i_sign_out end def then_i_am_redirected_to_the_sign_in_page - expect(page).to have_button "Start now" + expect(page).to have_current_path(ENV.fetch("CHECK_CHILDRENS_BARRED_LIST_GUIDANCE_URL")) end end