Sha256: 177c73a2d46d224735123495560300c3ef751517671af572b46f9d102c1b6fee
Contents?: true
Size: 1.54 KB
Versions: 1
Compression:
Stored size: 1.54 KB
Contents
require "test_helper" class OtpTest < MiniTest::Unit::TestCase def setup @user = User.new @user.email = 'roberto@heapsource.com' @user.run_callbacks :create @visitor = Visitor.new @visitor.email = 'roberto@heapsource.com' @visitor.run_callbacks :create end def test_authenticate_with_otp code = @user.otp_code assert @user.authenticate_otp(code) code = @visitor.otp_code assert @visitor.authenticate_otp(code) end def test_authenticate_with_otp_when_drift_is_allowed code = @user.otp_code(Time.now - 30) assert @user.authenticate_otp(code, drift: 60) code = @visitor.otp_code(Time.now - 30) assert @visitor.authenticate_otp(code, drift: 60) end def test_otp_code assert_match(/^\d{6}$/, @user.otp_code.to_s) assert_match(/^\d{6}$/, @visitor.otp_code.to_s) end def test_otp_code_padding @user.otp_column = 'kw5jhligwqaiw7jc' assert_match(/^\d{6}$/, @user.otp_code(time: 2160, padding: true).to_s) assert_match(/^\d{3}$/, @user.otp_code(time: 2160, padding: false).to_s) end def test_provisioning_uri_with_provided_account assert_match %r{otpauth://totp/roberto\?secret=\w{16}}, @user.provisioning_uri("roberto") assert_match %r{otpauth://totp/roberto\?secret=\w{16}}, @visitor.provisioning_uri("roberto") end def test_provisioning_uri_with_email_field assert_match %r{otpauth://totp/roberto@heapsource\.com\?secret=\w{16}}, @user.provisioning_uri assert_match %r{otpauth://totp/roberto@heapsource\.com\?secret=\w{16}}, @visitor.provisioning_uri end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
active_model_otp-1.0.0 | test/one_time_password_test.rb |