Skip to content

Commit

Permalink
Method authenticate_otp must return falsey if code is nil or empty st…
Browse files Browse the repository at this point in the history
…ring (#96)
  • Loading branch information
pedrofurtado authored Oct 22, 2021
1 parent a7fee70 commit fb8b178
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/active_model/one_time_password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def otp_regenerate_counter
end

def authenticate_otp(code, options = {})
return false if code.nil? || code.empty?
return true if backup_codes_enabled? && authenticate_backup_code(code)

if otp_counter_based
Expand Down
17 changes: 17 additions & 0 deletions test/one_time_password_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ def test_authenticate_with_otp
assert @visitor.authenticate_otp(code)
end

def test_authenticate_with_otp_passing_false_or_empty_codes
refute @user.authenticate_otp(nil)
refute @user.authenticate_otp('')

refute @visitor.authenticate_otp(nil)
refute @visitor.authenticate_otp('')

refute @member.authenticate_otp(nil)
refute @member.authenticate_otp('')

refute @ar_user.authenticate_otp(nil)
refute @ar_user.authenticate_otp('')

refute @opt_in.authenticate_otp(nil)
refute @opt_in.authenticate_otp('')
end

def test_counter_based_otp
code = @member.otp_code
assert @member.authenticate_otp(code)
Expand Down

0 comments on commit fb8b178

Please sign in to comment.