forked from dimagi/commcare-hq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dimagi#33918 from dimagi/gh/django-two-factor-auth…
…/1.15.5 Upgrade django-two-factor-auth from 1.13.2 to 1.16.0
- Loading branch information
Showing
26 changed files
with
308 additions
and
115 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
2 changes: 1 addition & 1 deletion
2
corehq/apps/domain/templates/login_and_password/two_factor/core/login.html
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{% load i18n two_factor %} | ||
{% load i18n phonenumber %} | ||
|
||
{% block focus-content %} | ||
<h2 class="text-center"> | ||
|
6 changes: 3 additions & 3 deletions
6
corehq/apps/domain/templates/login_and_password/two_factor/core/login_form.html
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
7 changes: 4 additions & 3 deletions
7
corehq/apps/domain/templates/login_and_password/two_factor/core/phone_register.html
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
56 changes: 33 additions & 23 deletions
56
corehq/apps/domain/templates/login_and_password/two_factor/core/setup.html
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from django.test import SimpleTestCase, override_settings | ||
|
||
from two_factor.plugins.registry import registry | ||
|
||
from corehq.apps.hqwebapp.apps import register_two_factor_methods | ||
from corehq.apps.hqwebapp.two_factor_methods import ( | ||
HQGeneratorMethod, | ||
HQPhoneCallMethod, | ||
HQSMSMethod, | ||
) | ||
|
||
|
||
@override_settings( | ||
ALLOW_PHONE_AS_DEFAULT_TWO_FACTOR_DEVICE=True, | ||
TWO_FACTOR_SMS_GATEWAY='corehq.apps.hqwebapp.two_factor_gateways.Gateway', | ||
TWO_FACTOR_CALL_GATEWAY='corehq.apps.hqwebapp.two_factor_gateways.Gateway', | ||
) | ||
class RegisterCustom2FAMethodsTests(SimpleTestCase): | ||
|
||
@override_settings( | ||
ALLOW_PHONE_AS_DEFAULT_TWO_FACTOR_DEVICE=False, | ||
TWO_FACTOR_SMS_GATEWAY=None, | ||
TWO_FACTOR_CALL_GATEWAY=None, | ||
) | ||
def test_custom_generator_method_is_registered(self): | ||
register_two_factor_methods() | ||
method = registry.get_method('generator') | ||
self.assertIsInstance(method, HQGeneratorMethod) | ||
|
||
@override_settings(TWO_FACTOR_SMS_GATEWAY=None) | ||
def test_custom_call_method_is_registered_if_relevant_settings_are_true(self): | ||
register_two_factor_methods() | ||
method = registry.get_method('call') | ||
self.assertIsInstance(method, HQPhoneCallMethod) | ||
|
||
@override_settings(TWO_FACTOR_CALL_GATEWAY=None) | ||
def test_custom_sms_method_is_registered_if_relevant_settings_are_true(self): | ||
register_two_factor_methods() | ||
method = registry.get_method('sms') | ||
self.assertIsInstance(method, HQSMSMethod) | ||
|
||
@override_settings(ALLOW_PHONE_AS_DEFAULT_TWO_FACTOR_DEVICE=False) | ||
def test_neither_phone_method_is_registered_if_allow_phone_setting_is_false(self): | ||
register_two_factor_methods() | ||
self.assertIsNone(registry.get_method('call')) | ||
self.assertIsNone(registry.get_method('sms')) |
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
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from django_otp.plugins.otp_totp.models import TOTPDevice | ||
|
||
from two_factor.plugins.phonenumber.method import PhoneCallMethod, SMSMethod | ||
from two_factor.plugins.registry import GeneratorMethod | ||
|
||
from corehq.apps.hqwebapp.forms import HQAuthenticationTokenForm | ||
from corehq.apps.settings.forms import HQPhoneNumberForm, HQTOTPDeviceForm | ||
|
||
|
||
class HQGeneratorMethod(GeneratorMethod): | ||
|
||
# only overriding this because it is set in GeneratorMethod | ||
form_path = 'corehq.apps.settings.forms.HQTOTPDeviceForm' | ||
|
||
def get_setup_forms(self, *args): | ||
return {self.code: HQTOTPDeviceForm} | ||
|
||
def get_token_form_class(self): | ||
return HQAuthenticationTokenForm | ||
|
||
def recognize_device(self, device): | ||
return isinstance(device, TOTPDevice) | ||
|
||
|
||
class HQPhoneCallMethod(PhoneCallMethod): | ||
|
||
def get_setup_forms(self, *args): | ||
return {self.code: HQPhoneNumberForm} | ||
|
||
def get_token_form_class(self): | ||
return HQAuthenticationTokenForm | ||
|
||
|
||
class HQSMSMethod(SMSMethod): | ||
|
||
def get_setup_forms(self, *args): | ||
return {self.code: HQPhoneNumberForm} | ||
|
||
def get_token_form_class(self): | ||
return HQAuthenticationTokenForm |
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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.conf import settings | ||
|
||
|
||
def user_can_use_phone(user): | ||
if not settings.ALLOW_PHONE_AS_DEFAULT_TWO_FACTOR_DEVICE: | ||
return False | ||
|
||
return user.belongs_to_messaging_domain() |
Oops, something went wrong.