fix: Removed usage of djangoratelimitbackend. (#30116)
* fix: Removed usage of djangoratelimitbackend.
This commit is contained in:
@@ -6,9 +6,6 @@ This is not inside a django app because it is a global property of the system.
|
||||
import ddt
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
from edx_toggles.toggles.testutils import override_waffle_flag
|
||||
|
||||
from openedx.core.djangoapps.user_authn.config.waffle import ADMIN_AUTH_REDIRECT_TO_LMS
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
@@ -16,17 +13,8 @@ class TestAdminView(TestCase):
|
||||
"""
|
||||
Tests of the admin view.
|
||||
"""
|
||||
@override_waffle_flag(ADMIN_AUTH_REDIRECT_TO_LMS, True)
|
||||
@ddt.data('/admin/', '/admin/login', reverse('admin:login'))
|
||||
def test_admin_login_redirect(self, admin_url):
|
||||
"""Admin login will redirect towards the site login page."""
|
||||
response = self.client.get(admin_url, follow=True)
|
||||
assert any('/login/edx-oauth2/?next=' in r[0] for r in response.redirect_chain)
|
||||
|
||||
def test_admin_login_default(self):
|
||||
"""Without flag Admin login will redirect towards the admin default login page."""
|
||||
response = self.client.get('/admin/', follow=True)
|
||||
assert response.status_code == 200
|
||||
self.assertIn('/admin/login/?next=/admin/', response.redirect_chain[0])
|
||||
assert len(response.redirect_chain) == 1
|
||||
assert response.template_name == ['admin/login.html']
|
||||
|
||||
@@ -7,10 +7,8 @@ from django.conf import settings
|
||||
from django.shortcuts import redirect
|
||||
from urllib.parse import quote_plus # lint-amnesty, pylint: disable=wrong-import-order
|
||||
from waffle.decorators import waffle_switch
|
||||
from django.contrib import admin
|
||||
|
||||
from common.djangoapps.edxmako.shortcuts import render_to_response
|
||||
from openedx.core.djangoapps.user_authn.config.waffle import ADMIN_AUTH_REDIRECT_TO_LMS
|
||||
|
||||
from ..config import waffle
|
||||
|
||||
@@ -48,10 +46,7 @@ def redirect_to_lms_login_for_admin(request):
|
||||
"""
|
||||
This view redirect the admin/login url to the site's login page.
|
||||
"""
|
||||
if ADMIN_AUTH_REDIRECT_TO_LMS.is_enabled():
|
||||
return redirect('/login?next=/admin')
|
||||
else:
|
||||
return admin.site.login(request)
|
||||
return redirect('/login?next=/admin')
|
||||
|
||||
|
||||
def _build_next_param(request):
|
||||
|
||||
@@ -17,10 +17,7 @@
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% flag "user_authn.admin_auth_redirect_to_lms" %}
|
||||
<a href="/logout/">{% trans 'Log out' as tmsg %} {{tmsg|force_escape}}</a>
|
||||
{% else %}
|
||||
<a href="{% url 'admin:logout' %}">{% trans 'Log out' as tmsg %} {{tmsg|force_escape}}</a>
|
||||
{% endflag %}
|
||||
<a href="/logout/">{% trans 'Log out' as tmsg %} {{tmsg|force_escape}}</a>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
"""
|
||||
A utility class which wraps the RateLimitMixin 3rd party class to do bad request counting
|
||||
which can be used for rate limiting
|
||||
"""
|
||||
@@ -1,6 +1,5 @@
|
||||
{% extends "admin/base.html" %}
|
||||
{% load i18n admin_urls %}
|
||||
{% load waffle_tags %}
|
||||
{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}
|
||||
{% block branding %}
|
||||
<h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('Django administration') }}</a></h1>
|
||||
@@ -17,10 +16,7 @@
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% flag "user_authn.admin_auth_redirect_to_lms" %}
|
||||
<a href="{% url 'logout' %}">{% trans 'Log out' as tmsg%}{{tmsg|force_escape}}</a>
|
||||
{% else %}
|
||||
<a href="{% url 'admin:logout' %}">{% trans 'Log out' as tmsg%}{{tmsg|force_escape}}</a>
|
||||
{% endflag %}
|
||||
<a href="{% url 'logout' %}">{% trans 'Log out' as tmsg%}{{tmsg|force_escape}}</a>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
"""
|
||||
Custom authentication backends.
|
||||
"""
|
||||
@@ -3,7 +3,7 @@ Waffle flags and switches for user authn.
|
||||
"""
|
||||
|
||||
|
||||
from edx_toggles.toggles import LegacyWaffleSwitch, LegacyWaffleSwitchNamespace, WaffleFlag
|
||||
from edx_toggles.toggles import LegacyWaffleSwitch, LegacyWaffleSwitchNamespace
|
||||
|
||||
_WAFFLE_NAMESPACE = 'user_authn'
|
||||
_WAFFLE_SWITCH_NAMESPACE = LegacyWaffleSwitchNamespace(name=_WAFFLE_NAMESPACE, log_prefix='UserAuthN: ')
|
||||
@@ -37,16 +37,3 @@ ENABLE_PWNED_PASSWORD_API = LegacyWaffleSwitch(
|
||||
'enable_pwned_password_api',
|
||||
__name__
|
||||
)
|
||||
|
||||
|
||||
# .. toggle_name: ADMIN_AUTH_REDIRECT_TO_LMS
|
||||
# .. toggle_implementation: WaffleFlag
|
||||
# .. toggle_default: False
|
||||
# .. toggle_description: Set this to True if you want to redirect cms-admin login to lms login.
|
||||
# In case of logout it will use lms logout also.
|
||||
# .. toggle_use_cases: open_edx
|
||||
# .. toggle_creation_date: 2022-02-08
|
||||
# .. toggle_target_removal_date: None
|
||||
ADMIN_AUTH_REDIRECT_TO_LMS = WaffleFlag( # lint-amnesty, pylint: disable=toggle-missing-annotation
|
||||
"user_authn.admin_auth_redirect_to_lms", module_name=__name__
|
||||
)
|
||||
|
||||
@@ -11,7 +11,6 @@ import re
|
||||
import urllib
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth import authenticate, get_user_model
|
||||
from django.contrib.auth import login as django_login
|
||||
from django.contrib.auth.decorators import login_required
|
||||
@@ -43,10 +42,7 @@ from common.djangoapps.util.password_policy_validators import normalize_password
|
||||
from openedx.core.djangoapps.password_policy import compliance as password_policy_compliance
|
||||
from openedx.core.djangoapps.safe_sessions.middleware import mark_user_change_as_expected
|
||||
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
|
||||
from openedx.core.djangoapps.user_authn.config.waffle import (
|
||||
ENABLE_LOGIN_USING_THIRDPARTY_AUTH_ONLY,
|
||||
ADMIN_AUTH_REDIRECT_TO_LMS
|
||||
)
|
||||
from openedx.core.djangoapps.user_authn.config.waffle import ENABLE_LOGIN_USING_THIRDPARTY_AUTH_ONLY
|
||||
from openedx.core.djangoapps.user_authn.cookies import get_response_with_refreshed_jwt_cookies, set_logged_in_cookies
|
||||
from openedx.core.djangoapps.user_authn.exceptions import AuthFailedError
|
||||
from openedx.core.djangoapps.user_authn.toggles import (
|
||||
@@ -658,10 +654,7 @@ def redirect_to_lms_login(request):
|
||||
This view redirect the admin/login url to the site's login page if
|
||||
waffle switch is on otherwise returns the admin site's login view.
|
||||
"""
|
||||
if ENABLE_LOGIN_USING_THIRDPARTY_AUTH_ONLY.is_enabled() or ADMIN_AUTH_REDIRECT_TO_LMS.is_enabled():
|
||||
return redirect('/login?next=/admin')
|
||||
else:
|
||||
return admin.site.login(request)
|
||||
return redirect('/login?next=/admin')
|
||||
|
||||
|
||||
class LoginSessionView(APIView):
|
||||
|
||||
@@ -6,9 +6,8 @@ This is not inside a django app because it is a global property of the system.
|
||||
|
||||
from django.test import Client, TestCase
|
||||
from django.urls import reverse
|
||||
from edx_toggles.toggles.testutils import override_waffle_switch, override_waffle_flag
|
||||
from edx_toggles.toggles.testutils import override_waffle_switch
|
||||
from common.djangoapps.student.tests.factories import UserFactory, TEST_PASSWORD
|
||||
from openedx.core.djangoapps.user_authn.config.waffle import ADMIN_AUTH_REDIRECT_TO_LMS
|
||||
|
||||
from openedx.core.djangoapps.user_authn.views.login import ENABLE_LOGIN_USING_THIRDPARTY_AUTH_ONLY
|
||||
|
||||
@@ -44,16 +43,3 @@ class TestAdminView(TestCase):
|
||||
response = self.client.get(reverse('admin:login'))
|
||||
assert response.url == '/login?next=/admin'
|
||||
assert response.status_code == 302
|
||||
|
||||
with override_waffle_flag(ADMIN_AUTH_REDIRECT_TO_LMS, True):
|
||||
response = self.client.get(reverse('admin:login'))
|
||||
assert response.url == '/login?next=/admin'
|
||||
assert response.status_code == 302
|
||||
|
||||
with override_waffle_switch(ENABLE_LOGIN_USING_THIRDPARTY_AUTH_ONLY, False):
|
||||
response = self.client.get(reverse('admin:login'))
|
||||
assert response.template_name == ['admin/login.html']
|
||||
|
||||
with override_waffle_flag(ADMIN_AUTH_REDIRECT_TO_LMS, False):
|
||||
response = self.client.get(reverse('admin:login'))
|
||||
assert response.template_name == ['admin/login.html']
|
||||
|
||||
@@ -89,5 +89,5 @@ sympy==1.6.2
|
||||
# -c requirements/edx-sandbox/../constraints.txt
|
||||
# -r requirements/edx-sandbox/py38.in
|
||||
# openedx-calc
|
||||
tqdm==4.63.0
|
||||
tqdm==4.63.1
|
||||
# via nltk
|
||||
|
||||
@@ -47,7 +47,9 @@ appdirs==1.4.4
|
||||
asgiref==3.5.0
|
||||
# via django
|
||||
async-timeout==4.0.2
|
||||
# via aiohttp
|
||||
# via
|
||||
# aiohttp
|
||||
# redis
|
||||
attrs==21.4.0
|
||||
# via
|
||||
# -r requirements/edx/base.in
|
||||
@@ -195,7 +197,6 @@ django==3.2.12
|
||||
# django-mysql
|
||||
# django-oauth-toolkit
|
||||
# django-pyfs
|
||||
# django-ratelimit-backend
|
||||
# django-sekizai
|
||||
# django-ses
|
||||
# django-splash
|
||||
@@ -330,8 +331,6 @@ django-pyfs==3.2.0
|
||||
# via -r requirements/edx/base.in
|
||||
django-ratelimit==3.0.1
|
||||
# via -r requirements/edx/base.in
|
||||
django-ratelimit-backend @ git+https://github.com/edx/django-ratelimit-backend.git@6e1a0c6ea1d27062c16e9fb94d3c44475146877e
|
||||
# via -r requirements/edx/github.in
|
||||
django-require @ git+https://github.com/edx/django-require.git@0c54adb167142383b26ea6b3edecc3211822a776
|
||||
# via -r requirements/edx/github.in
|
||||
django-sekizai==3.0.1
|
||||
@@ -913,7 +912,7 @@ ruamel-yaml==0.17.21
|
||||
# via drf-yasg
|
||||
ruamel-yaml-clib==0.2.6
|
||||
# via ruamel-yaml
|
||||
rules==3.2.1
|
||||
rules==3.3
|
||||
# via
|
||||
# -r requirements/edx/base.in
|
||||
# edx-enterprise
|
||||
@@ -1019,10 +1018,12 @@ testfixtures==6.18.5
|
||||
# via edx-enterprise
|
||||
text-unidecode==1.3
|
||||
# via python-slugify
|
||||
tqdm==4.63.0
|
||||
tqdm==4.63.1
|
||||
# via nltk
|
||||
typing-extensions==4.1.1
|
||||
# via django-countries
|
||||
# via
|
||||
# django-countries
|
||||
# redis
|
||||
unicodecsv==0.14.1
|
||||
# via
|
||||
# -r requirements/edx/base.in
|
||||
|
||||
@@ -74,6 +74,7 @@ async-timeout==4.0.2
|
||||
# via
|
||||
# -r requirements/edx/testing.txt
|
||||
# aiohttp
|
||||
# redis
|
||||
attrs==21.4.0
|
||||
# via
|
||||
# -r requirements/edx/testing.txt
|
||||
@@ -279,7 +280,6 @@ django==3.2.12
|
||||
# django-mysql
|
||||
# django-oauth-toolkit
|
||||
# django-pyfs
|
||||
# django-ratelimit-backend
|
||||
# django-sekizai
|
||||
# django-ses
|
||||
# django-splash
|
||||
@@ -426,8 +426,6 @@ django-pyfs==3.2.0
|
||||
# via -r requirements/edx/testing.txt
|
||||
django-ratelimit==3.0.1
|
||||
# via -r requirements/edx/testing.txt
|
||||
django-ratelimit-backend @ git+https://github.com/edx/django-ratelimit-backend.git@6e1a0c6ea1d27062c16e9fb94d3c44475146877e
|
||||
# via -r requirements/edx/testing.txt
|
||||
django-require @ git+https://github.com/edx/django-require.git@0c54adb167142383b26ea6b3edecc3211822a776
|
||||
# via -r requirements/edx/testing.txt
|
||||
django-sekizai==3.0.1
|
||||
@@ -660,7 +658,7 @@ execnet==1.9.0
|
||||
# pytest-xdist
|
||||
factory-boy==3.2.1
|
||||
# via -r requirements/edx/testing.txt
|
||||
faker==13.3.2
|
||||
faker==13.3.3
|
||||
# via
|
||||
# -r requirements/edx/testing.txt
|
||||
# factory-boy
|
||||
@@ -1279,7 +1277,7 @@ ruamel-yaml-clib==0.2.6
|
||||
# via
|
||||
# -r requirements/edx/testing.txt
|
||||
# ruamel-yaml
|
||||
rules==3.2.1
|
||||
rules==3.3
|
||||
# via
|
||||
# -r requirements/edx/testing.txt
|
||||
# edx-enterprise
|
||||
@@ -1471,7 +1469,7 @@ tox==3.24.5
|
||||
# tox-battery
|
||||
tox-battery==0.6.1
|
||||
# via -r requirements/edx/testing.txt
|
||||
tqdm==4.63.0
|
||||
tqdm==4.63.1
|
||||
# via
|
||||
# -r requirements/edx/testing.txt
|
||||
# nltk
|
||||
@@ -1485,6 +1483,7 @@ typing-extensions==4.1.1
|
||||
# mypy
|
||||
# pydantic
|
||||
# pylint
|
||||
# redis
|
||||
unicodecsv==0.14.1
|
||||
# via
|
||||
# -r requirements/edx/testing.txt
|
||||
|
||||
@@ -59,10 +59,6 @@
|
||||
git+https://github.com/edx/MongoDBProxy.git@d92bafe9888d2940f647a7b2b2383b29c752f35a#egg=MongoDBProxy==0.1.0+edx.2
|
||||
-e git+https://github.com/jazkarta/edx-jsme.git@690dbf75441fa91c7c4899df0b83d77f7deb5458#egg=edx-jsme
|
||||
|
||||
# This is a temporary fork until https://github.com/brutasse/django-ratelimit-backend/pull/50 is merged
|
||||
# back into the upstream code.
|
||||
git+https://github.com/edx/django-ratelimit-backend.git@6e1a0c6ea1d27062c16e9fb94d3c44475146877e#egg=django-ratelimit-backend
|
||||
|
||||
# original repo is not maintained any more.
|
||||
git+https://github.com/edx/django-require.git@0c54adb167142383b26ea6b3edecc3211822a776#egg=django-require==1.0.12
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ async-timeout==4.0.2
|
||||
# via
|
||||
# -r requirements/edx/base.txt
|
||||
# aiohttp
|
||||
# redis
|
||||
attrs==21.4.0
|
||||
# via
|
||||
# -r requirements/edx/base.txt
|
||||
@@ -267,7 +268,6 @@ distlib==0.3.4
|
||||
# django-mysql
|
||||
# django-oauth-toolkit
|
||||
# django-pyfs
|
||||
# django-ratelimit-backend
|
||||
# django-sekizai
|
||||
# django-ses
|
||||
# django-splash
|
||||
@@ -412,8 +412,6 @@ django-pyfs==3.2.0
|
||||
# via -r requirements/edx/base.txt
|
||||
django-ratelimit==3.0.1
|
||||
# via -r requirements/edx/base.txt
|
||||
django-ratelimit-backend @ git+https://github.com/edx/django-ratelimit-backend.git@6e1a0c6ea1d27062c16e9fb94d3c44475146877e
|
||||
# via -r requirements/edx/base.txt
|
||||
django-require @ git+https://github.com/edx/django-require.git@0c54adb167142383b26ea6b3edecc3211822a776
|
||||
# via -r requirements/edx/base.txt
|
||||
django-sekizai==3.0.1
|
||||
@@ -641,7 +639,7 @@ execnet==1.9.0
|
||||
# via pytest-xdist
|
||||
factory-boy==3.2.1
|
||||
# via -r requirements/edx/testing.in
|
||||
faker==13.3.2
|
||||
faker==13.3.3
|
||||
# via factory-boy
|
||||
fastapi==0.75.0
|
||||
# via pact-python
|
||||
@@ -1203,7 +1201,7 @@ ruamel-yaml-clib==0.2.6
|
||||
# via
|
||||
# -r requirements/edx/base.txt
|
||||
# ruamel-yaml
|
||||
rules==3.2.1
|
||||
rules==3.3
|
||||
# via
|
||||
# -r requirements/edx/base.txt
|
||||
# edx-enterprise
|
||||
@@ -1359,7 +1357,7 @@ tox==3.24.5
|
||||
# tox-battery
|
||||
tox-battery==0.6.1
|
||||
# via -r requirements/edx/testing.in
|
||||
tqdm==4.63.0
|
||||
tqdm==4.63.1
|
||||
# via
|
||||
# -r requirements/edx/base.txt
|
||||
# nltk
|
||||
@@ -1372,6 +1370,7 @@ typing-extensions==4.1.1
|
||||
# django-countries
|
||||
# pydantic
|
||||
# pylint
|
||||
# redis
|
||||
unicodecsv==0.14.1
|
||||
# via
|
||||
# -r requirements/edx/base.txt
|
||||
|
||||
Reference in New Issue
Block a user