-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
203 additions
and
37 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
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,33 @@ | ||
from django.urls import reverse | ||
|
||
import pytest | ||
|
||
from allauth.account.adapter import get_adapter | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"with_totp,with_password,expected_method_urlnames", | ||
[ | ||
(False, True, ["account_reauthenticate"]), | ||
(True, True, ["account_reauthenticate", "mfa_reauthenticate"]), | ||
(True, False, ["mfa_reauthenticate"]), | ||
], | ||
) | ||
def test_user_with_mfa_only( | ||
user_factory, with_totp, with_password, expected_method_urlnames, client | ||
): | ||
user = user_factory(with_totp=with_totp, password=None if with_password else "!") | ||
assert user.has_usable_password() == with_password | ||
client.force_login(user) | ||
methods = get_adapter().get_reauthentication_methods(user) | ||
assert len(methods) == len(expected_method_urlnames) | ||
assert set([m["url"] for m in methods]) == set( | ||
map(reverse, expected_method_urlnames) | ||
) | ||
for urlname in ["account_reauthenticate", "mfa_reauthenticate"]: | ||
resp = client.get(reverse(urlname) + "?next=/foo") | ||
if urlname in expected_method_urlnames: | ||
assert resp.status_code == 200 | ||
else: | ||
assert resp.status_code == 302 | ||
assert "next=%2Ffoo" in resp["location"] |
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,27 @@ | ||
{% extends "account/base_entrance.html" %} | ||
{% load allauth %} | ||
{% load i18n %} | ||
{% block head_title %} | ||
{% trans "Confirm Access" %} | ||
{% endblock head_title %} | ||
{% block content %} | ||
{% element h1 %} | ||
{% trans "Confirm Access" %} | ||
{% endelement %} | ||
<p>{% blocktranslate %}Please reauthenticate to safeguard your account.{% endblocktranslate %}</p> | ||
{% block reauthenticate_content %}{% endblock %} | ||
{% if reauthentication_alternatives %} | ||
{% element hr %} | ||
{% endelement %} | ||
{% element h2 %} | ||
{% translate "Alternative options" %} | ||
{% endelement %} | ||
<ul> | ||
{% for alt in reauthentication_alternatives %} | ||
<li> | ||
<a href="{{ alt.url }}">{{ alt.description }}</a> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
{% endblock content %} |
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 @@ | ||
<hr> |
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,24 @@ | ||
{% extends "account/base_reauthenticate.html" %} | ||
{% load i18n %} | ||
{% load allauth %} | ||
{% block reauthenticate_content %} | ||
<p>{% blocktranslate %}Enter an authenticator code:{% endblocktranslate %}</p> | ||
{% url 'mfa_reauthenticate' as action_url %} | ||
{% element form form=form method="post" action=action_url %} | ||
{% slot body %} | ||
{% csrf_token %} | ||
{% element fields form=form unlabeled=True %} | ||
{% endelement %} | ||
{% if redirect_field_value %} | ||
<input type="hidden" | ||
name="{{ redirect_field_name }}" | ||
value="{{ redirect_field_value }}" /> | ||
{% endif %} | ||
{% endslot %} | ||
{% slot actions %} | ||
{% element button type="submit" tags="primary,mfa,login" %} | ||
{% trans "Confirm" %} | ||
{% endelement %} | ||
{% endslot %} | ||
{% endelement %} | ||
{% endblock %} |
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