闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.6 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Settings::TwoFactorAuthenticationsController do
  4. render_views
  5. let(:user) { Fabricate(:user) }
  6. before do
  7. sign_in user, scope: :user
  8. end
  9. describe 'GET #show' do
  10. describe 'when user requires otp for login already' do
  11. it 'returns http success' do
  12. user.update(otp_required_for_login: true)
  13. get :show
  14. expect(response).to have_http_status(:success)
  15. end
  16. end
  17. describe 'when user does not require otp for login' do
  18. it 'returns http success' do
  19. user.update(otp_required_for_login: false)
  20. get :show
  21. expect(response).to have_http_status(:success)
  22. end
  23. end
  24. end
  25. describe 'POST #create' do
  26. describe 'when user requires otp for login already' do
  27. it 'redirects to show page' do
  28. user.update(otp_required_for_login: true)
  29. post :create
  30. expect(response).to redirect_to(settings_two_factor_authentication_path)
  31. end
  32. end
  33. describe 'when creation succeeds' do
  34. it 'updates user secret' do
  35. before = user.otp_secret
  36. post :create
  37. expect(user.reload.otp_secret).not_to eq(before)
  38. expect(response).to redirect_to(new_settings_two_factor_authentication_confirmation_path)
  39. end
  40. end
  41. end
  42. describe 'POST #destroy' do
  43. before do
  44. user.update(otp_required_for_login: true)
  45. end
  46. it 'turns off otp requirement' do
  47. post :destroy
  48. expect(response).to redirect_to(settings_two_factor_authentication_path)
  49. user.reload
  50. expect(user.otp_required_for_login).to eq(false)
  51. end
  52. end
  53. end