Skip to content

Commit

Permalink
πŸžπŸ”¨ Authentication: Don't explode when OTP or OTP secrets are nil
Browse files Browse the repository at this point in the history
- #1809

There's a couple things happening, one of which is if an
`AuthenticationMethod` does not have a One Time Password Secret, it
can't actually do the verification.

So i've added a check to make sure it returns false in cases when the
OTP secret has not been set yet; as well as when a nil OTP is provided.
  • Loading branch information
zspencer committed Oct 12, 2023
1 parent 2c1a024 commit c4446ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/authentication_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def contact_location=(contact_location)
end

def verify?(one_time_password)
return false if one_time_password.blank? || one_time_password_secret.blank?
totp.verify(one_time_password).present?
end

Expand Down
9 changes: 9 additions & 0 deletions spec/models/authentication_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@

expect(authentication_method).not_to be_verify(one_time_password)
end

it "is false when the OTP is nil" do
expect(authentication_method).not_to be_verify(nil)
end

it "is false when the OTPS is nil" do
authentication_method.one_time_password_secret = nil
expect(authentication_method).not_to be_verify("an otp")
end
end

describe "#send_one_time_password!(space)" do
Expand Down

0 comments on commit c4446ba

Please sign in to comment.