Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Rspec authentication tests #37

Merged
merged 3 commits into from
Dec 13, 2024
Merged

Added Rspec authentication tests #37

merged 3 commits into from
Dec 13, 2024

Conversation

Warsama-Gabriel
Copy link
Contributor

@Warsama-Gabriel Warsama-Gabriel commented Dec 7, 2024

Added authentication tests for SessionsController and OmniAuth Shibboleth integration

  • Implemented tests for SessionsController actions, covering both production and development environments.
  • Mocked Shibboleth OmniAuth responses to test authentication flows in production.
  • Enhanced User model tests to validate user creation and attributes.
  • Updated OmniAuth configuration tests to ensure provider settings are correctly applied.

@srbbins
Copy link
Contributor

srbbins commented Dec 9, 2024

@mfall3 I think this looks good, but you have a lot more experience writing tests in Rails apps than me. Do you have any feedback on this PR?

@mfall3
Copy link
Contributor

mfall3 commented Dec 11, 2024

It is recommended to use OmniAuth.config.test_mode in the test. https://gorails.com/blog/how-to-test-omniauth-params

@mfall3
Copy link
Contributor

mfall3 commented Dec 11, 2024

As part of authorization, but looking ahead to next tests (authorization-based), we will want to mock sign_in (or login) specifically.
https://github.com/medusa-project/databank/blob/main/spec/support/omniauth_macros.rb
The pattern here should also work for the :shibboleth provider

@Warsama-Gabriel
Copy link
Contributor Author

Warsama-Gabriel commented Dec 11, 2024

@mfall3 That makes sense. Using OmniAuth's add_mock method with config.test_mode = true would better simulate mocking user authentication rather than directly setting the request.env['omniauth.auth'] hash directly. I'll go ahead and update the PR to reflect those changes.

@mfall3
Copy link
Contributor

mfall3 commented Dec 12, 2024

The sign_in or login OmniAuth testing mode method can be added in the future if needed for other tests. I am fine with this pull request going forward.

@srbbins srbbins merged commit a61e5a3 into main Dec 13, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants