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
cd6b971d
Commit
cd6b971d
authored
Oct 23, 2014
by
Will Daly
Committed by
Zia Fazal
Apr 07, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disable auth for login and registration end-points
parent
da00d3be
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
+24
-0
common/djangoapps/user_api/tests/test_views.py
+16
-0
common/djangoapps/user_api/views.py
+8
-0
No files found.
common/djangoapps/user_api/tests/test_views.py
View file @
cd6b971d
...
@@ -111,6 +111,14 @@ class ApiTestCase(TestCase):
...
@@ -111,6 +111,14 @@ class ApiTestCase(TestCase):
"""Assert that the given response has the status code 405"""
"""Assert that the given response has the status code 405"""
self
.
assertEqual
(
response
.
status_code
,
405
)
self
.
assertEqual
(
response
.
status_code
,
405
)
def
assertAuthDisabled
(
self
,
method
,
uri
):
# Django rest framework interprets basic auth headers
# as an attempt to authenticate with the API.
# We don't want this for views available to anonymous users.
basic_auth_header
=
"Basic "
+
base64
.
b64encode
(
'username:password'
)
response
=
getattr
(
self
.
client
,
method
)(
uri
,
HTTP_AUTHORIZATION
=
basic_auth_header
)
self
.
assertNotEqual
(
response
.
status_code
,
403
)
class
EmptyUserTestCase
(
ApiTestCase
):
class
EmptyUserTestCase
(
ApiTestCase
):
def
test_get_list_empty
(
self
):
def
test_get_list_empty
(
self
):
...
@@ -561,6 +569,10 @@ class LoginSessionViewTest(ApiTestCase):
...
@@ -561,6 +569,10 @@ class LoginSessionViewTest(ApiTestCase):
super
(
LoginSessionViewTest
,
self
)
.
setUp
()
super
(
LoginSessionViewTest
,
self
)
.
setUp
()
self
.
url
=
reverse
(
"user_api_login_session"
)
self
.
url
=
reverse
(
"user_api_login_session"
)
@ddt.data
(
"get"
,
"post"
)
def
test_auth_disabled
(
self
,
method
):
self
.
assertAuthDisabled
(
method
,
self
.
url
)
def
test_allowed_methods
(
self
):
def
test_allowed_methods
(
self
):
self
.
assertAllowedMethods
(
self
.
url
,
[
"GET"
,
"POST"
,
"HEAD"
,
"OPTIONS"
])
self
.
assertAllowedMethods
(
self
.
url
,
[
"GET"
,
"POST"
,
"HEAD"
,
"OPTIONS"
])
...
@@ -725,6 +737,10 @@ class RegistrationViewTest(ApiTestCase):
...
@@ -725,6 +737,10 @@ class RegistrationViewTest(ApiTestCase):
super
(
RegistrationViewTest
,
self
)
.
setUp
()
super
(
RegistrationViewTest
,
self
)
.
setUp
()
self
.
url
=
reverse
(
"user_api_registration"
)
self
.
url
=
reverse
(
"user_api_registration"
)
@ddt.data
(
"get"
,
"post"
)
def
test_auth_disabled
(
self
,
method
):
self
.
assertAuthDisabled
(
method
,
self
.
url
)
def
test_allowed_methods
(
self
):
def
test_allowed_methods
(
self
):
self
.
assertAllowedMethods
(
self
.
url
,
[
"GET"
,
"POST"
,
"HEAD"
,
"OPTIONS"
])
self
.
assertAllowedMethods
(
self
.
url
,
[
"GET"
,
"POST"
,
"HEAD"
,
"OPTIONS"
])
...
...
common/djangoapps/user_api/views.py
View file @
cd6b971d
...
@@ -50,6 +50,10 @@ class ApiKeyHeaderPermission(permissions.BasePermission):
...
@@ -50,6 +50,10 @@ class ApiKeyHeaderPermission(permissions.BasePermission):
class
LoginSessionView
(
APIView
):
class
LoginSessionView
(
APIView
):
"""HTTP end-points for logging in users. """
"""HTTP end-points for logging in users. """
# This end-point is available to anonymous users,
# so do not require authentication.
authentication_classes
=
[]
def
get
(
self
,
request
):
def
get
(
self
,
request
):
"""Return a description of the login form.
"""Return a description of the login form.
...
@@ -143,6 +147,10 @@ class RegistrationView(APIView):
...
@@ -143,6 +147,10 @@ class RegistrationView(APIView):
"honor_code"
,
"terms_of_service"
,
"honor_code"
,
"terms_of_service"
,
]
]
# This end-point is available to anonymous users,
# so do not require authentication.
authentication_classes
=
[]
def
_is_field_visible
(
self
,
field_name
):
def
_is_field_visible
(
self
,
field_name
):
"""Check whether a field is visible based on Django settings. """
"""Check whether a field is visible based on Django settings. """
return
self
.
_extra_fields_setting
.
get
(
field_name
)
in
[
"required"
,
"optional"
]
return
self
.
_extra_fields_setting
.
get
(
field_name
)
in
[
"required"
,
"optional"
]
...
...
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