Skip to content

Conversation

@santiagorodriguez96
Copy link
Collaborator

Motivation

Right now we don't have specific tests for our strategies apart from our system tests, which because of its nature don't really cover all the edge cases. This is leading to weird behaviors such as the one described in #88.

The goal of this PR is to add request specs to test the different authentication flows, which the different edge case, in order to try to test all the strategies and how they work together.

This could in term allow us to stop relying too much in our system tests which have been behaving a little bit flaky.

Details

This PR adds two request specs: spec/requests/devise/passkey_authentication_spec.rb (for testing authentication with passkeys) and spec/requests/devise/two_factor_authentication_spec.rb (for testing authentication with email/password and 2FA).

Base automatically changed from sr--scope-credentials-in-2fa to master January 12, 2026 16:19
challenge = WebAuthn.configuration.encoder.encode(SecureRandom.random_bytes(32))
raw_credential = fake_client.create(challenge: challenge)
webauthn_credential = WebAuthn::Credential.from_create(raw_credential)
webauthn_credential.verify(challenge)
Copy link
Member

@brauliomartinezlm brauliomartinezlm Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it really make sense to verify the credential if it's just for test setup?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah my bad. It's not needed at all 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed it in c9dda01 -> ✅


raw_credential = fake_client.create(challenge: creation_options.challenge)
webauthn_credential = WebAuthn::Credential.from_create(raw_credential)
webauthn_credential.verify(creation_options.challenge)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here.

end
end

describe "sign-in without 2FA" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we maybe reflect something like "sign in with a user with 2FA disabled"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like it!

Updated in d1a25e9 -> ✅

Copy link
Member

@brauliomartinezlm brauliomartinezlm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

Comment on lines +1 to +20
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2026-01-02 20:36:46 UTC using RuboCop version 1.79.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: Max, CountAsOne.
RSpec/ExampleLength:
Exclude:
- 'spec/requests/devise/two_factor_authentication_spec.rb'

# Offense count: 9
# Configuration parameters: Max.
RSpec/MultipleExpectations:
Exclude:
- 'spec/requests/devise/passkey_authentication_spec.rb'
- 'spec/requests/devise/two_factor_authentication_spec.rb'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we disable these cops instead of creating a rubocop_todo?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was planning on disabling them after this PR so that's why I added them to this file

@santiagorodriguez96 santiagorodriguez96 merged commit 44d47d5 into master Jan 19, 2026
37 of 38 checks passed
@santiagorodriguez96 santiagorodriguez96 deleted the sr--add-request-specs-for-auth-flows branch January 19, 2026 18:47
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.

4 participants