Skip to content

Commit f1bef17

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 attempts to make sure that the Shibboleth identifier_scheme is created before the corresponding dynamical shibboleth action is triggered during test execution.
1 parent bcc8d1f commit f1bef17

File tree

4 files changed

+55
-35
lines changed

4 files changed

+55
-35
lines changed

spec/factories/identifier_schemes.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,6 @@
2727
context_count { 1 }
2828
end
2929

30-
# Add a trait for Shibboleth
31-
trait :shibboleth do
32-
name { 'shibboleth' }
33-
context { 11 }
34-
description { 'Institutional Sign In (Shibboleth)' }
35-
logo_url { nil }
36-
identifier_prefix { nil }
37-
active { true }
38-
end
39-
4030
after(:create) do |identifier_scheme, evaluator|
4131
(0..evaluator.context_count - 1).each do |idx|
4232
identifier_scheme.update("#{identifier_scheme.all_context[idx]}": true)

spec/features/email_confirmation_spec.rb

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,40 @@
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 = IdentifierScheme.find_by!(name: 'shibboleth')
34+
# Mock OmniAuth authentication hash for Shibboleth via OmniAuthHelper
35+
OmniAuth.config.mock_auth[:shibboleth] = mock_auth_hash(@user, @scheme)
4136

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)
37+
# Create the identifier for the user
38+
Identifier.create(identifier_scheme: @scheme,
39+
value: OmniAuth.config.mock_auth[:shibboleth].uid,
40+
attrs: OmniAuth.config.mock_auth[:shibboleth],
41+
identifiable: @user)
42+
end
4643

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
44+
scenario 'A user attempts to sign in via the "Sign in with your institutional credentials"
45+
button. The email is linked to a user account, however the account is
46+
unconfirmed and has no confirmation token.', :js do
47+
visit root_path
48+
# Sign-in attempt #1 (user is unconfirmed and has no confirmation_token)
49+
click_link SSO_SIGN_IN_BUTTON_TEXT
50+
expectations_for_unconfirmed_user_with_no_confirmation_token_after_sign_in_attempt(@user)
5151

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)
52+
visit root_path
53+
# Sign-in attempt #2 (user still unconfirmed but has a confirmation_token)
54+
click_link SSO_SIGN_IN_BUTTON_TEXT
55+
expectations_for_unconfirmed_user_with_confirmation_token_after_sign_in_attempt
56+
57+
# Sign-in attempt #3 (user is now confirmed)
58+
@user.confirm
59+
click_link SSO_SIGN_IN_BUTTON_TEXT
60+
# The user is signed in
61+
expect(page).to have_current_path(plans_path)
62+
end
5763
end
5864

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

spec/support/helpers/omniauth_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ 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+
Rails.application.env_config['devise.mapping'] = Devise.mappings[:user]
910
Rails.application.env_config['omniauth.auth'] =
1011
OmniAuth::AuthHash.new({
1112
provider: scheme.name,

spec/support/omniauth.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
OmniAuth.config do |config|
4+
# Set the OmniAuth test mode to true
5+
config.test_mode = true
6+
# Set the OmniAuth full host to nil to avoid URL generation issues in tests
7+
config.full_host = nil
8+
end
9+
10+
RSpec.configure do |config|
11+
config.before(:each, type: :feature) do
12+
# Ensure the 'shibboleth' IdentifierScheme exists before each :feature test.
13+
# The dynamic OmniAuth callback method in Users::OmniauthCallbacksController depends
14+
# on this scheme, so it must be created first to ensure the callback works during tests.
15+
unless IdentifierScheme.exists?(name: 'shibboleth')
16+
IdentifierScheme.create(name: 'shibboleth',
17+
context: 11,
18+
description: 'Institutional Sign In (Shibboleth)',
19+
logo_url: nil, identifier_prefix: nil,
20+
active: true)
21+
end
22+
end
23+
end

0 commit comments

Comments
 (0)