-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent reuse of OTP code with ROTP
after
option (#99)
ROTP reference: https://github.com/mdp/rotp/blob/2be11551ac4982670d526ceef4a5db985d0f626a/README.md#preventing-reuse-of-time-based-otps
- Loading branch information
1 parent
4e92e51
commit 6859113
Showing
5 changed files
with
67 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class AfterUser < ActiveRecord::Base | ||
has_one_time_password after_column_name: :last_otp_at | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,10 @@ def setup | |
@opt_in = OptInTwoFactor.new | ||
@opt_in.email = '[email protected]' | ||
@opt_in.run_callbacks :create | ||
|
||
@after_user = AfterUser.new | ||
@after_user.email = '[email protected]' | ||
@after_user.run_callbacks :create | ||
end | ||
|
||
def test_authenticate_with_otp | ||
|
@@ -88,6 +92,18 @@ def test_authenticate_with_otp_when_drift_is_allowed | |
assert_equal true, @visitor.authenticate_otp(code, drift: 60) | ||
end | ||
|
||
def test_authenticate_with_otp_when_after_is_allowed | ||
code = @user.otp_code | ||
assert_equal true, @user.authenticate_otp(code) | ||
assert_equal true, @user.authenticate_otp(code) | ||
|
||
code = @after_user.otp_code | ||
assert_equal true, @after_user.authenticate_otp(code) | ||
assert_equal false, @after_user.authenticate_otp(code) | ||
assert_equal false, @after_user.authenticate_otp('1111111') | ||
assert_equal false, @after_user.authenticate_otp(code) | ||
end | ||
|
||
def test_authenticate_with_backup_code | ||
backup_code = @user.public_send(@user.otp_backup_codes_column_name).first | ||
assert_equal true, @user.authenticate_otp(backup_code) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters