-
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.
- Loading branch information
1 parent
1deb128
commit c516671
Showing
2 changed files
with
15 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
require 'test_helper' | ||
|
||
class OtpTest < MiniTest::Test | ||
include ActiveSupport::Testing::TimeHelpers | ||
|
||
def setup | ||
@user = User.new | ||
@user.email = '[email protected]' | ||
|
@@ -131,7 +133,7 @@ def test_otp_code_with_specific_length | |
|
||
def test_otp_code_without_specific_length | ||
assert_match(/^\d{6}$/, @user.otp_code(2160).to_s) | ||
assert_operator(@user.otp_code(2160).to_s.length, :<=, 6) | ||
assert @user.otp_code(2160).to_s.length <= 6 | ||
end | ||
|
||
def test_provisioning_uri_with_provided_account | ||
|
@@ -162,13 +164,8 @@ def test_provisioning_uri_with_options | |
&issuer=Example$ | ||
}x | ||
|
||
assert_match( | ||
account, @user.provisioning_uri('roberto', issuer: 'Example') | ||
) | ||
|
||
assert_match( | ||
account, @visitor.provisioning_uri('roberto', issuer: 'Example') | ||
) | ||
assert_match account, @user.provisioning_uri('roberto', issuer: 'Example') | ||
assert_match account, @visitor.provisioning_uri('roberto', issuer: 'Example') | ||
|
||
assert_match email, @user.provisioning_uri(nil, issuer: 'Example') | ||
assert_match email, @visitor.provisioning_uri(nil, issuer: 'Example') | ||
|
@@ -202,17 +199,22 @@ def test_otp_interval | |
@interval_user.run_callbacks :create | ||
otp_code = @interval_user.otp_code | ||
2.times { assert_match(otp_code, @interval_user.otp_code) } | ||
sleep 5 | ||
refute_match(otp_code, @interval_user.otp_code) | ||
|
||
travel 5.seconds do | ||
refute_match(otp_code, @interval_user.otp_code) | ||
end | ||
end | ||
|
||
def test_otp_default_interval | ||
@default_interval_user = DefaultIntervalUser.new | ||
@default_interval_user.email = '[email protected]' | ||
@default_interval_user.run_callbacks :create | ||
otp_code = @default_interval_user.otp_code | ||
|
||
2.times { assert_match(otp_code, @default_interval_user.otp_code) } | ||
sleep 5 | ||
assert_match(otp_code, @default_interval_user.otp_code) | ||
|
||
travel 5.seconds do | ||
assert_match(otp_code, @default_interval_user.otp_code) | ||
end | ||
end | ||
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