Skip to content

Commit c3075f1

Browse files
committed
Enable OmniAuth testing in RSpec tests
- Created `spec/support/helpers/omniauth_helper.rb` for simulating authentication with providers like Shibboleth - Added OmniAuth test config settings in `spec/rails_helper.rb`.
1 parent f934172 commit c3075f1

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

spec/rails_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,9 @@
7979
config.include Devise::Test::ControllerHelpers, type: :controller
8080
config.include Devise::Test::ControllerHelpers, type: :view
8181
config.include Pundit::Matchers, type: :policy
82+
83+
# Enable test mode for OmniAuth
84+
OmniAuth.config.test_mode = true
85+
# Set the full host to nil to avoid URL generation issues in tests
86+
OmniAuth.config.full_host = nil
8287
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
# Helper module for mocking OmniAuth authentication in tests
4+
module OmniAuthHelper
5+
# This method sets and returns an OmniAuth::AuthHash
6+
# that simulates the authentication data returned by
7+
# an OmniAuth provider (e.g. Shibboleth).
8+
def mock_auth_hash(user, scheme)
9+
Rails.application.env_config['omniauth.auth'] =
10+
OmniAuth::AuthHash.new({
11+
provider: scheme.name,
12+
uid: '12345',
13+
info: {
14+
email: user.email,
15+
first_name: user.firstname,
16+
last_name: user.surname
17+
}
18+
})
19+
Rails.application.env_config['omniauth.auth']
20+
end
21+
end

0 commit comments

Comments
 (0)