-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathreset_token_test.rb
45 lines (33 loc) · 1.01 KB
/
reset_token_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require "test_helper"
require "integration_tests_helper"
class ResetTokenTest < ActionDispatch::IntegrationTest
def setup
# log in 1fa
@user = enable_otp_and_sign_in
assert_equal user_otp_credential_path, current_path
# otp 2fa
fill_in "user_token", with: ROTP::TOTP.new(@user.otp_auth_secret).at(Time.now)
click_button "Submit Token"
assert_equal root_path, current_path
end
def teardown
Capybara.reset_sessions!
end
test "redirects to otp_tokens#edit page" do
reset_otp
assert_equal "/users/otp/token/edit", current_path
end
test "generates new token secrets" do
# get auth secrets
auth_secret = @user.otp_auth_secret
recovery_secret = @user.otp_recovery_secret
# reset otp
reset_otp
# compare auth secrets
@user.reload
assert_not_nil @user.otp_auth_secret
assert_not_equal @user.otp_auth_secret, auth_secret
assert_not_nil @user.otp_recovery_secret
assert_not_equal @user.otp_recovery_secret, recovery_secret
end
end