mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-02 07:27:04 +00:00
[sys] Add force 2FA option
This commit is contained in:
@@ -2,6 +2,7 @@ import os
|
||||
import pytest
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
from seahub.options.models import (UserOptions, KEY_FORCE_2FA, VAL_FORCE_2FA)
|
||||
from seahub.test_utils import BaseTestCase
|
||||
from seahub.two_factor.models import TOTPDevice, devices_for_user
|
||||
|
||||
@@ -37,3 +38,27 @@ class TwoFactorAuthViewTest(BaseTestCase):
|
||||
device.delete()
|
||||
except:
|
||||
pass
|
||||
|
||||
def test_force_2fa(self):
|
||||
assert len(UserOptions.objects.filter(email=self.user.email,
|
||||
option_key=KEY_FORCE_2FA)) == 0
|
||||
|
||||
resp = self.client.put(
|
||||
reverse('two-factor-auth-view', args=[self.user.username]),
|
||||
'force_2fa=1',
|
||||
'application/x-www-form-urlencoded',
|
||||
)
|
||||
self.assertEqual(200, resp.status_code)
|
||||
|
||||
assert len(UserOptions.objects.filter(email=self.user.email,
|
||||
option_key=KEY_FORCE_2FA)) == 1
|
||||
|
||||
resp = self.client.put(
|
||||
reverse('two-factor-auth-view', args=[self.user.username]),
|
||||
'force_2fa=0',
|
||||
'application/x-www-form-urlencoded',
|
||||
)
|
||||
self.assertEqual(200, resp.status_code)
|
||||
|
||||
assert len(UserOptions.objects.filter(email=self.user.email,
|
||||
option_key=KEY_FORCE_2FA)) == 0
|
||||
|
Reference in New Issue
Block a user