Skip to content

Commit

Permalink
Merge pull request #39 from jasinai/AddAuthorizationHeader
Browse files Browse the repository at this point in the history
Adds the authorization header
  • Loading branch information
audax committed Mar 2, 2016
2 parents e2faddc + 3214ca6 commit 1b3fa5a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
17 changes: 12 additions & 5 deletions tests/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,31 +110,38 @@ def test_head_no_messages_posted_since(self):
#######POST
def test_post_empty_message(self):
response = self.app.post('/abcdefghijklmnopqrstuvwxyzabcdefghijklmnopo', data=b'',
headers={'Content-Type': 'application/octet-stream'})
headers={'Content-Type': 'application/octet-stream', 'Authorization': 'Client Qabel'})
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.data == b''

def test_post_no_message(self):
response = self.app.post('/abcdefghijklmnopqrstuvwxyzabcdefghijklmnopo',
headers={'Content-Type': 'application/octet-stream'})
headers={'Content-Type': 'application/octet-stream', 'Authorization': 'Client Qabel'})
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.data == b''

def test_post_to_invalid_drop_id(self):
response = self.app.post('/fail', data=b'Yay', headers={'Content-Type': 'application/octet-stream'})
response = self.app.post('/fail', data=b'Yay',
headers={'Content-Type': 'application/octet-stream', 'Authorization': 'Client Qabel'})
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.data == b''

def test_post_message_is_too_long(self):
response = self.app.post('/abcdefghijklmnopqrstuvwxyzabcdefghijklmnopo', data=2574 * b'x',
headers={'Content-Type': 'application/octet-stream'})
headers={'Content-Type': 'application/octet-stream', 'Authorization': 'Client Qabel'})
assert response.status_code == status.HTTP_413_REQUEST_ENTITY_TOO_LARGE
assert response.data == b''

def test_post_message(self):
response = self.app.post('/abcdefghijklmnopqrstuvwxyzabcdefghijklmpost', data=b'Yay',
headers={'Content-Type': 'application/octet-stream'})
headers={'Content-Type': 'application/octet-stream', 'Authorization': 'Client Qabel'})
assert response.status_code == status.HTTP_200_OK
assert response.data == b''
response = self.app.get('/abcdefghijklmnopqrstuvwxyzabcdefghijklmpost')
assert 'Yay' in response.data.decode()

def test_post_message_without_headers(self):
response = self.app.post('/abcdefghijklmnopqrstuvwxyzabcdefghijklmpost', data=b'Yay',
headers={'Content-Type': 'application/octet-stream'})
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.data == b''
3 changes: 3 additions & 0 deletions views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def post_message(drop_id):
return '', status.HTTP_400_BAD_REQUEST

message = request.data
authorization_header = request.headers.get('Authorization')
if authorization_header != 'Client Qabel':
return '', status.HTTP_400_BAD_REQUEST
if message == b'' or message is None:
return '', status.HTTP_400_BAD_REQUEST
if len(message) > MESSAGE_SIZE_LIMIT:
Expand Down

0 comments on commit 1b3fa5a

Please sign in to comment.