Skip to content

Commit 9209fce

Browse files
committed
Fix failing shibboleth test
This change attempts to resolve the following error: ``` 1) Email Confirmation A user attempts to sign in via the "Sign in with your institutional credentials" button. The email is linked to a user account, however the account is unconfirmed and has no confirmation token. Failure/Error: raise ActionNotFound.new("The action '#{action}' could not be found for #{self.class.name}", self, action) AbstractController::ActionNotFound: The action 'shibboleth' could not be found for Users::OmniauthCallbacksController ``` The Users::OmniauthCallbacksController#shibboleth action is defined dynamically within the controller. Everything is working locally with commit bcc8d1f, but the test is failing when executed as a GitHub Action. This change explicitly defines the shibboleth-related Users::OmniauthCallbacksController action
1 parent bcc8d1f commit 9209fce

File tree

2 files changed

+48
-25
lines changed

2 files changed

+48
-25
lines changed

spec/features/email_confirmation_spec.rb

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,42 @@
2626
expect(page).to have_current_path(plans_path)
2727
end
2828

29-
scenario 'A user attempts to sign in via the "Sign in with your institutional credentials"
30-
button. The email is linked to a user account, however the account is
31-
unconfirmed and has no confirmation token.', :js do
32-
user = create(:user, :unconfirmed_and_no_confirmation_token)
33-
scheme = create(:identifier_scheme, :shibboleth)
34-
# Mock the OmniAuth authentication hash for Shibboleth via OmniAuthHelper
35-
OmniAuth.config.mock_auth[:shibboleth] = mock_auth_hash(user, scheme)
36-
# Create a Shibboleth-related Identifier for the user
37-
Identifier.create(identifier_scheme: scheme,
38-
value: OmniAuth.config.mock_auth[:shibboleth].uid,
39-
attrs: OmniAuth.config.mock_auth[:shibboleth],
40-
identifiable: user)
29+
describe 'Initial setup for shibboleth sign-in' do
30+
before do
31+
# Set up the user and identifier scheme
32+
@user = create(:user, :unconfirmed_and_no_confirmation_token)
33+
scheme = create(:identifier_scheme, :shibboleth)
34+
# Mock OmniAuth authentication hash for Shibboleth via OmniAuthHelper
35+
OmniAuth.config.mock_auth[:shibboleth] = mock_auth_hash(@user, scheme)
36+
# Explicitly define a Users::OmniauthCallbacksController action for the scheme
37+
define_omniauth_callback_for(scheme)
4138

42-
visit root_path
43-
# Sign-in attempt #1 (user is unconfirmed and has no confirmation_token)
44-
click_link SSO_SIGN_IN_BUTTON_TEXT
45-
expectations_for_unconfirmed_user_with_no_confirmation_token_after_sign_in_attempt(user)
39+
# Create the identifier for the user
40+
Identifier.create(identifier_scheme: scheme,
41+
value: OmniAuth.config.mock_auth[:shibboleth].uid,
42+
attrs: OmniAuth.config.mock_auth[:shibboleth],
43+
identifiable: @user)
44+
end
4645

47-
visit root_path
48-
# Sign-in attempt #2 (user still unconfirmed but has a confirmation_token)
49-
click_link SSO_SIGN_IN_BUTTON_TEXT
50-
expectations_for_unconfirmed_user_with_confirmation_token_after_sign_in_attempt
46+
scenario 'A user attempts to sign in via the "Sign in with your institutional credentials"
47+
button. The email is linked to a user account, however the account is
48+
unconfirmed and has no confirmation token.', :js do
49+
visit root_path
50+
# Sign-in attempt #1 (user is unconfirmed and has no confirmation_token)
51+
click_link SSO_SIGN_IN_BUTTON_TEXT
52+
expectations_for_unconfirmed_user_with_no_confirmation_token_after_sign_in_attempt(@user)
5153

52-
# Sign-in attempt #3 (user is now confirmed)
53-
user.confirm
54-
click_link SSO_SIGN_IN_BUTTON_TEXT
55-
# The user is signed in
56-
expect(page).to have_current_path(plans_path)
54+
visit root_path
55+
# Sign-in attempt #2 (user still unconfirmed but has a confirmation_token)
56+
click_link SSO_SIGN_IN_BUTTON_TEXT
57+
expectations_for_unconfirmed_user_with_confirmation_token_after_sign_in_attempt
58+
59+
# Sign-in attempt #3 (user is now confirmed)
60+
@user.confirm
61+
click_link SSO_SIGN_IN_BUTTON_TEXT
62+
# The user is signed in
63+
expect(page).to have_current_path(plans_path)
64+
end
5765
end
5866

5967
scenario 'A user is unconfirmed but has no confirmation token.

spec/support/helpers/omniauth_helper.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ module OmniAuthHelper
66
# that simulates the authentication data returned by
77
# an OmniAuth provider (e.g. Shibboleth).
88
def mock_auth_hash(user, scheme)
9+
# Ensure Devise correctly maps the :user model for OmniAuth in tests.
10+
Rails.application.env_config['devise.mapping'] = Devise.mappings[:user]
911
Rails.application.env_config['omniauth.auth'] =
1012
OmniAuth::AuthHash.new({
1113
provider: scheme.name,
@@ -18,4 +20,17 @@ def mock_auth_hash(user, scheme)
1820
})
1921
Rails.application.env_config['omniauth.auth']
2022
end
23+
24+
# Manually define an action in Users::OmniauthCallbacksController.
25+
# These actions are dynamically defined in the controller (based on IdentifierScheme entries).
26+
# Because required db entries may not yet exist when the controller is loaded in the test environment,
27+
# an action can be explicitly defined here for the test to work.
28+
def define_omniauth_callback_for(scheme)
29+
# Only define the action if it passes the .for_authentication validation
30+
return unless IdentifierScheme.for_authentication.exists?(id: scheme.id)
31+
32+
Users::OmniauthCallbacksController.define_method(scheme.name.downcase) do
33+
handle_omniauth(scheme)
34+
end
35+
end
2136
end

0 commit comments

Comments
 (0)