Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
874d7360
Commit
874d7360
authored
Feb 21, 2014
by
Waheed Ahmed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added validation for username and email max length.
LMS-1479
parent
663671ec
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
10 deletions
+73
-10
common/djangoapps/student/tests/test_long_username_email.py
+53
-0
common/djangoapps/student/tests/test_password_policy.py
+3
-4
common/djangoapps/student/views.py
+13
-0
lms/djangoapps/courseware/tests/test_registration_extra_vars.py
+4
-6
No files found.
common/djangoapps/student/tests/test_long_username_email.py
0 → 100644
View file @
874d7360
# -*- coding: utf-8 -*-
import
json
from
django.test
import
TestCase
from
django.core.urlresolvers
import
reverse
class
TestLongUsernameEmail
(
TestCase
):
def
setUp
(
self
):
self
.
url
=
reverse
(
'create_account'
)
self
.
url_params
=
{
'username'
:
'username'
,
'email'
:
'foo_bar'
+
'@bar.com'
,
'name'
:
'foo bar'
,
'password'
:
'123'
,
'terms_of_service'
:
'true'
,
'honor_code'
:
'true'
,
}
def
test_long_username
(
self
):
"""
Test username cannot be more than 30 characters long.
"""
self
.
url_params
[
'username'
]
=
'username'
*
4
response
=
self
.
client
.
post
(
self
.
url
,
self
.
url_params
)
# Status code should be 400.
self
.
assertEqual
(
response
.
status_code
,
400
)
obj
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
obj
[
'value'
],
"Username cannot be more than 30 characters long"
,
)
def
test_long_email
(
self
):
"""
Test email cannot be more than 75 characters long.
"""
self
.
url_params
[
'email'
]
=
'{0}@bar.com'
.
format
(
'foo_bar'
*
15
)
response
=
self
.
client
.
post
(
self
.
url
,
self
.
url_params
)
# Status code should be 400.
self
.
assertEqual
(
response
.
status_code
,
400
)
obj
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
obj
[
'value'
],
"Email cannot be more than 75 characters long"
,
)
common/djangoapps/student/tests/test_password_policy.py
View file @
874d7360
...
@@ -3,8 +3,6 @@
...
@@ -3,8 +3,6 @@
This test file will verify proper password policy enforcement, which is an option feature
This test file will verify proper password policy enforcement, which is an option feature
"""
"""
import
json
import
json
import
uuid
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
mock
import
patch
from
mock
import
patch
...
@@ -19,9 +17,10 @@ class TestPasswordPolicy(TestCase):
...
@@ -19,9 +17,10 @@ class TestPasswordPolicy(TestCase):
def
setUp
(
self
):
def
setUp
(
self
):
super
(
TestPasswordPolicy
,
self
)
.
setUp
()
super
(
TestPasswordPolicy
,
self
)
.
setUp
()
self
.
url
=
reverse
(
'create_account'
)
self
.
url
=
reverse
(
'create_account'
)
self
.
url_params
=
{
self
.
url_params
=
{
'username'
:
'
foo_bar'
+
uuid
.
uuid4
()
.
hex
,
'username'
:
'
username'
,
'email'
:
'foo
'
+
uuid
.
uuid4
()
.
hex
+
'
@bar.com'
,
'email'
:
'foo
_bar
@bar.com'
,
'name'
:
'username'
,
'name'
:
'username'
,
'terms_of_service'
:
'true'
,
'terms_of_service'
:
'true'
,
'honor_code'
:
'true'
,
'honor_code'
:
'true'
,
...
...
common/djangoapps/student/views.py
View file @
874d7360
...
@@ -1080,6 +1080,19 @@ def create_account(request, post_override=None):
...
@@ -1080,6 +1080,19 @@ def create_account(request, post_override=None):
js
[
'field'
]
=
field_name
js
[
'field'
]
=
field_name
return
JsonResponse
(
js
,
status
=
400
)
return
JsonResponse
(
js
,
status
=
400
)
max_length
=
75
if
field_name
==
'username'
:
max_length
=
30
if
field_name
in
(
'email'
,
'username'
)
and
len
(
post_vars
[
field_name
])
>
max_length
:
error_str
=
{
'username'
:
_
(
'Username cannot be more than {0} characters long'
)
.
format
(
max_length
),
'email'
:
_
(
'Email cannot be more than {0} characters long'
)
.
format
(
max_length
)
}
js
[
'value'
]
=
error_str
[
field_name
]
js
[
'field'
]
=
field_name
return
JsonResponse
(
js
,
status
=
400
)
try
:
try
:
validate_email
(
post_vars
[
'email'
])
validate_email
(
post_vars
[
'email'
])
except
ValidationError
:
except
ValidationError
:
...
...
lms/djangoapps/courseware/tests/test_registration_extra_vars.py
View file @
874d7360
...
@@ -3,8 +3,6 @@
...
@@ -3,8 +3,6 @@
Tests for extra registration variables
Tests for extra registration variables
"""
"""
import
json
import
json
import
uuid
from
django.conf
import
settings
from
django.conf
import
settings
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
...
@@ -18,11 +16,11 @@ class TestExtraRegistrationVariables(TestCase):
...
@@ -18,11 +16,11 @@ class TestExtraRegistrationVariables(TestCase):
def
setUp
(
self
):
def
setUp
(
self
):
super
(
TestExtraRegistrationVariables
,
self
)
.
setUp
()
super
(
TestExtraRegistrationVariables
,
self
)
.
setUp
()
self
.
url
=
reverse
(
'create_account'
)
self
.
url
=
reverse
(
'create_account'
)
username
=
'foo_bar'
+
uuid
.
uuid4
()
.
hex
self
.
url_params
=
{
self
.
url_params
=
{
'username'
:
username
,
'username'
:
'username'
,
'name'
:
username
,
'name'
:
'name'
,
'email'
:
'foo
'
+
uuid
.
uuid4
()
.
hex
+
'
@bar.com'
,
'email'
:
'foo
_bar
@bar.com'
,
'password'
:
'password'
,
'password'
:
'password'
,
'terms_of_service'
:
'true'
,
'terms_of_service'
:
'true'
,
'honor_code'
:
'true'
,
'honor_code'
:
'true'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment