Browse Source

Test otp authentication.

master
Matt Mueller 11 years ago
parent
commit
a57329534f
  1. 22
      spec/lib/two_factor_authentication/models/two_factor_authenticatable_spec.rb

22
spec/lib/two_factor_authentication/models/two_factor_authenticatable_spec.rb

@ -30,4 +30,26 @@ describe Devise::Models::TwoFactorAuthenticatable, '#otp_code' do
end
end
end
end
describe Devise::Models::TwoFactorAuthenticatable, '#authenticate_otp' do
let(:instance) { AuthenticatedModelHelper.create_new_user }
before :each do
instance.otp_secret_key = "2z6hxkdwi3uvrnpn"
end
def do_invoke code, options = {}
instance.authenticate_otp(code, options)
end
it "should be able to authenticate a recently created code" do
code = instance.otp_code
expect(do_invoke(code)).to eq(true)
end
it "should not authenticate an old code" do
code = instance.otp_code(1.minutes.ago.to_i)
expect(do_invoke(code)).to eq(false)
end
end
Loading…
Cancel
Save