diff options
Diffstat (limited to 'test/models/user_otp_test.rb')
| -rw-r--r-- | test/models/user_otp_test.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/models/user_otp_test.rb b/test/models/user_otp_test.rb index 81f25575..2044ac18 100644 --- a/test/models/user_otp_test.rb +++ b/test/models/user_otp_test.rb | |||
| @@ -74,6 +74,38 @@ class UserOtpTest < ActiveSupport::TestCase | |||
| 74 | assert_equal @user.login, action.metadata["target_login"] | 74 | assert_equal @user.login, action.metadata["target_login"] |
| 75 | end | 75 | end |
| 76 | 76 | ||
| 77 | test "an admin without a factor can start enrollment" do | ||
| 78 | admin = users(:aaron) | ||
| 79 | assert admin.is_admin? | ||
| 80 | assert_not admin.otp_enrolled? | ||
| 81 | |||
| 82 | uri = admin.begin_otp_enrollment! | ||
| 83 | |||
| 84 | assert admin.reload.otp_pending_secret.present? | ||
| 85 | assert uri.present? | ||
| 86 | end | ||
| 87 | |||
| 88 | test "an admin disabling their factor keeps the role" do | ||
| 89 | admin = users(:aaron) | ||
| 90 | admin.update_column(:otp_secret, ROTP::Base32.random) | ||
| 91 | |||
| 92 | admin.disable_otp!(:actor => admin) | ||
| 93 | |||
| 94 | assert_not admin.reload.otp_enrolled? | ||
| 95 | assert admin.is_admin? | ||
| 96 | end | ||
| 97 | |||
| 98 | test "a fellow admin can reset an admin's factor" do | ||
| 99 | admin = users(:aaron) | ||
| 100 | admin.update_column(:otp_secret, ROTP::Base32.random) | ||
| 101 | actor = users(:redella) | ||
| 102 | |||
| 103 | admin.disable_otp!(:actor => actor) | ||
| 104 | |||
| 105 | assert_not admin.reload.otp_enrolled? | ||
| 106 | assert_equal "otp_reset", NodeAction.last.action | ||
| 107 | end | ||
| 108 | |||
| 77 | private | 109 | private |
| 78 | 110 | ||
| 79 | def enroll!(user) | 111 | def enroll!(user) |
