Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
code.vt.edu will be down for maintenance from 0530-0630 EDT Wednesday, March 26th
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
74bc970e
Commit
74bc970e
authored
4 years ago
by
Waheed Ahmed
Browse files
Options
Downloads
Patches
Plain Diff
Rate limit logistration endpoints.
PROD-1506
parent
2d2015f4
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
openedx/core/djangoapps/user_authn/views/login_form.py
+10
-0
10 additions, 0 deletions
openedx/core/djangoapps/user_authn/views/login_form.py
openedx/core/djangoapps/user_authn/views/tests/test_logistration.py
+22
-1
22 additions, 1 deletion
...re/djangoapps/user_authn/views/tests/test_logistration.py
with
32 additions
and
1 deletion
openedx/core/djangoapps/user_authn/views/login_form.py
+
10
−
0
View file @
74bc970e
...
...
@@ -7,6 +7,7 @@ import logging
import
six
from
django.conf
import
settings
from
django.contrib
import
messages
from
django.http
import
HttpResponseForbidden
from
django.shortcuts
import
redirect
from
django.urls
import
reverse
from
django.utils.translation
import
ugettext
as
_
...
...
@@ -34,6 +35,7 @@ from student.helpers import get_next_url_for_login_page
from
third_party_auth
import
pipeline
from
third_party_auth.decorators
import
xframe_allow_whitelisted
from
util.password_policy_validators
import
DEFAULT_MAX_PASSWORD_LENGTH
from
util.request_rate_limiter
import
BadRequestRateLimiter
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -135,6 +137,12 @@ def login_and_registration_form(request, initial_mode="login"):
initial_mode (string): Either
"
login
"
or
"
register
"
.
"""
limiter
=
BadRequestRateLimiter
()
if
limiter
.
is_rate_limit_exceeded
(
request
):
log
.
warning
(
"
Rate limit exceeded in login and registration with initial mode [%s]
"
,
initial_mode
)
return
HttpResponseForbidden
(
"
Rate limit exceeded
"
)
# Determine the URL to redirect to following login/registration/third_party_auth
redirect_to
=
get_next_url_for_login_page
(
request
)
...
...
@@ -230,6 +238,8 @@ def login_and_registration_form(request, initial_mode="login"):
response
=
render_to_response
(
'
student_account/login_and_register.html
'
,
context
)
handle_enterprise_cookies_for_logistration
(
request
,
response
,
context
)
limiter
.
tick_request_counter
(
request
)
return
response
...
...
This diff is collapsed.
Click to expand it.
openedx/core/djangoapps/user_authn/views/tests/test_logistration.py
+
22
−
1
View file @
74bc970e
# -*- coding: utf-8 -*-
"""
Tests for Logistration views.
"""
from
datetime
import
datetime
,
timedelta
from
http.cookies
import
SimpleCookie
import
ddt
...
...
@@ -17,6 +17,8 @@ from django.test.client import RequestFactory
from
django.test.utils
import
override_settings
from
django.urls
import
reverse
from
django.utils.translation
import
ugettext
as
_
from
freezegun
import
freeze_time
from
pytz
import
UTC
from
six.moves.urllib.parse
import
urlencode
# pylint: disable=import-error
from
course_modes.models
import
CourseMode
...
...
@@ -71,6 +73,25 @@ class LoginAndRegistrationTest(ThirdPartyAuthTestMixin, UrlResetMixin, ModuleSto
expected_data
=
u
'"
initial_mode
"
:
"
{mode}
"'
.
format
(
mode
=
initial_mode
)
self
.
assertContains
(
response
,
expected_data
)
def
test_login_and_registration_form_ratelimited
(
self
):
"""
Test that login enpoint allow only 30 requests for every 5 minutes.
"""
login_url
=
reverse
(
'
signin_user
'
)
for
i
in
range
(
30
):
response
=
self
.
client
.
get
(
login_url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
# then the rate limiter should kick in and give a HttpForbidden response
response
=
self
.
client
.
get
(
login_url
)
self
.
assertEqual
(
response
.
status_code
,
403
)
# now reset the time to 6 mins from now in future in order to unblock
reset_time
=
datetime
.
now
(
UTC
)
+
timedelta
(
seconds
=
361
)
with
freeze_time
(
reset_time
):
response
=
self
.
client
.
get
(
login_url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
@ddt.data
(
"
signin_user
"
,
"
register_user
"
)
def
test_login_and_registration_form_already_authenticated
(
self
,
url_name
):
# call the account registration api that sets the login cookies
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment