Skip to content

Commit

Permalink
Tests for auth
Browse files Browse the repository at this point in the history
  • Loading branch information
kalaspuff committed Jul 24, 2017
1 parent 1f80df9 commit 3bd4bc1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions tests/services/http_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ async def none_data(self, request: web.Request) -> None:
async def forwarded_for(self, request: web.Request) -> str:
return request.request_ip

@http('GET', r'/authorization/?')
async def authorization(self, request: web.Request) -> str:
return request.auth.login if request.auth else ''

@http_error(status_code=404)
async def test_404(self, request: web.Request) -> str:
return 'test 404'
Expand Down
12 changes: 12 additions & 0 deletions tests/test_http_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ async def _async(loop: Any) -> None:
assert response.status == 200
assert await response.text() == '192.168.0.1'

async with aiohttp.ClientSession(loop=loop) as client:
response = await client.get('http://127.0.0.1:{}/authorization'.format(port), headers={'Authorization': 'Basic YXV0aHVzZXI6c2VjcmV0YWY='})
assert response is not None
assert response.status == 200
assert await response.text() == 'authuser'

async with aiohttp.ClientSession(loop=loop) as client:
response = await client.get('http://127.0.0.1:{}/authorization'.format(port), headers={'Authorization': 'Basic 0123456789'})
assert response is not None
assert response.status == 200
assert await response.text() == ''

loop.run_until_complete(_async(loop))
instance.stop_service()
loop.run_until_complete(future)
6 changes: 1 addition & 5 deletions tomodachi/transport/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,7 @@ def get_aiohttp_response(self, context: Dict, default_charset: Optional[str]=Non
body = self._body
try:
body_value = body.encode(charset.lower())
except ValueError as e:
if not context.get('log_level') or context.get('log_level') in ['DEBUG']:
traceback.print_exception(e.__class__, e, e.__traceback__)
raise web.HTTPInternalServerError() from e
except LookupError as e:
except (ValueError, LookupError, UnicodeEncodeError) as e:
if not context.get('log_level') or context.get('log_level') in ['DEBUG']:
traceback.print_exception(e.__class__, e, e.__traceback__)
raise web.HTTPInternalServerError() from e
Expand Down

0 comments on commit 3bd4bc1

Please sign in to comment.