Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-notes-api
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-notes-api
Commits
cbf25263
Commit
cbf25263
authored
Dec 26, 2014
by
Tim Babych
Committed by
Oleg Marshev
Jan 05, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enable more
parent
5fd3ff8c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
79 deletions
+83
-79
notesapi/v1/tests/test_views.py
+83
-79
No files found.
notesapi/v1/tests/test_views.py
View file @
cbf25263
...
@@ -71,6 +71,10 @@ class BaseAnnotationViewTests(APITestCase):
...
@@ -71,6 +71,10 @@ class BaseAnnotationViewTests(APITestCase):
es
.
indices
.
refresh
()
es
.
indices
.
refresh
()
@classmethod
@classmethod
def
setUpClass
(
cls
):
es
.
indices
.
create
(
index
=
settings
.
ES_INDEXES
[
'default'
],
ignore
=
400
)
@classmethod
def
tearDownClass
(
cls
):
def
tearDownClass
(
cls
):
"""
"""
* deletes the test index
* deletes the test index
...
@@ -344,92 +348,92 @@ class AnnotationViewTests(BaseAnnotationViewTests):
...
@@ -344,92 +348,92 @@ class AnnotationViewTests(BaseAnnotationViewTests):
self
.
assertEqual
(
len
(
response
.
data
),
5
,
"five annotations should be returned in response"
)
self
.
assertEqual
(
len
(
response
.
data
),
5
,
"five annotations should be returned in response"
)
#
@patch('django.conf.settings.DISABLE_TOKEN_CHECK', True)
@patch
(
'django.conf.settings.DISABLE_TOKEN_CHECK'
,
True
)
#
class AllowAllAnnotationViewTests(BaseAnnotationViewTests):
class
AllowAllAnnotationViewTests
(
BaseAnnotationViewTests
):
#
"""
"""
#
Test annotator behavior when authorization is not enforced
Test annotator behavior when authorization is not enforced
#
"""
"""
#
def test_create_no_payload(self):
def
test_create_no_payload
(
self
):
#
"""
"""
#
Test if no payload is sent when creating a note.
Test if no payload is sent when creating a note.
#
"""
"""
#
url = reverse('api:v1:annotations')
url
=
reverse
(
'api:v1:annotations'
)
#
response = self.client.post(url, {}, format='json')
response
=
self
.
client
.
post
(
url
,
{},
format
=
'json'
)
#
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
# class TokenTests(BaseAnnotationViewTests):
class
TokenTests
(
BaseAnnotationViewTests
):
# """
"""
# Test token interactions
Test token interactions
# """
"""
# url = reverse('api:v1:annotations')
url
=
reverse
(
'api:v1:annotations'
)
# token_data = {
token_data
=
{
# 'aud': settings.CLIENT_ID,
'aud'
:
settings
.
CLIENT_ID
,
# 'sub': TEST_USER,
'sub'
:
TEST_USER
,
# 'iat': timegm(datetime.utcnow().utctimetuple()),
'iat'
:
timegm
(
datetime
.
utcnow
()
.
utctimetuple
()),
# 'exp': timegm((datetime.utcnow() + timedelta(seconds=300)).utctimetuple()),
'exp'
:
timegm
((
datetime
.
utcnow
()
+
timedelta
(
seconds
=
300
))
.
utctimetuple
()),
# }
}
# def _assert_403(self, token):
# """
# Asserts that request with this token will fail
# """
# self.client.credentials(HTTP_X_ANNOTATOR_AUTH_TOKEN=token)
# response = self.client.get(self.url, self.headers)
# self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
# def test_200(self):
def
_assert_403
(
self
,
token
):
# """
"""
# Ensure we can read list of annotations
Asserts that request with this token will fail
# """
"""
# response = self.client.get(self.url, self.headers)
self
.
client
.
credentials
(
HTTP_X_ANNOTATOR_AUTH_TOKEN
=
token
)
# self.assertEqual(response.status_code, status.HTTP_200_OK)
response
=
self
.
client
.
get
(
self
.
url
,
self
.
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_403_FORBIDDEN
)
# def test_no_token(self):
def
test_200
(
self
):
# """
"""
# 403 when no token is provided
Ensure we can read list of annotations
# """
"""
# self.client._credentials = {}
response
=
self
.
client
.
get
(
self
.
url
,
self
.
headers
)
# response = self.client.get(self.url, self.headers)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
# self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
# def test_malformed_token(self):
def
test_no_token
(
self
):
# """
"""
# 403 when token can not be decoded
403 when no token is provided
# """
"""
# self._assert_403("kuku")
self
.
client
.
_credentials
=
{}
response
=
self
.
client
.
get
(
self
.
url
,
self
.
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_403_FORBIDDEN
)
# def test_expired_token(self):
def
test_malformed_token
(
self
):
# """
"""
# 403 when token is expired
403 when token can not be decoded
# """
"""
# token = self.token_data.copy()
self
.
_assert_403
(
"kuku"
)
# token['exp'] = 1
# token = jwt.encode(token, settings.CLIENT_SECRET)
# self._assert_403(token)
# def test_wrong_issuer
(self):
def
test_expired_token
(
self
):
#
"""
"""
# 403 when token's issuer is wrong
403 when token is expired
#
"""
"""
#
token = self.token_data.copy()
token
=
self
.
token_data
.
copy
()
# token['aud'] = 'not Edx-notes'
token
[
'exp'
]
=
1
#
token = jwt.encode(token, settings.CLIENT_SECRET)
token
=
jwt
.
encode
(
token
,
settings
.
CLIENT_SECRET
)
#
self._assert_403(token)
self
.
_assert_403
(
token
)
# def test_wrong_us
er(self):
def
test_wrong_issu
er
(
self
):
#
"""
"""
# 403 when token's us
er is wrong
403 when token's issu
er is wrong
#
"""
"""
#
token = self.token_data.copy()
token
=
self
.
token_data
.
copy
()
# token['sub'] = 'joe
'
token
[
'aud'
]
=
'not Edx-notes
'
#
token = jwt.encode(token, settings.CLIENT_SECRET)
token
=
jwt
.
encode
(
token
,
settings
.
CLIENT_SECRET
)
#
self._assert_403(token)
self
.
_assert_403
(
token
)
# def test_wrong_secret(self):
def
test_wrong_user
(
self
):
# """
"""
# 403 when token is signed by wrong secret
403 when token's user is wrong
# """
"""
# token = jwt.encode(self.token_data, "some secret")
token
=
self
.
token_data
.
copy
()
# self._assert_403(token)
token
[
'sub'
]
=
'joe'
token
=
jwt
.
encode
(
token
,
settings
.
CLIENT_SECRET
)
self
.
_assert_403
(
token
)
def
test_wrong_secret
(
self
):
"""
403 when token is signed by wrong secret
"""
token
=
jwt
.
encode
(
self
.
token_data
,
"some secret"
)
self
.
_assert_403
(
token
)
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