Skip to content

Commit

Permalink
ISSUE #1
Browse files Browse the repository at this point in the history
  • Loading branch information
vladyslav-fenchak committed Feb 16, 2022
1 parent 6eddd0d commit af3108c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
28 changes: 13 additions & 15 deletions minos/auth/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ async def get_token_user(request: web.Request, token: str, auth_type: AuthType):

if response.status == 200:
resp_json = json.loads(response.text)
resp_json['role'] = role
resp_json["role"] = role
return web.json_response(resp_json)
return response # pragma: no cover

Expand Down Expand Up @@ -225,26 +225,24 @@ async def validate_token(request: web.Request) -> web.Response:
token_resp = await validate_token_call(request)

if token_resp.status == 200:
response = await get_user_call(request, r.user_uuid)

if response.status == 200:
resp_json = json.loads(response.text)
resp_json['role'] = role
return web.json_response(resp_json)
return response # pragma: no cover
return await user_call(request, r.user_uuid, role)

if r.auth_type == AuthType.CREDENTIAL.value:
response = await get_user_call(request, r.user_uuid)

if response.status == 200:
resp_json = json.loads(response.text)
resp_json['role'] = role
return web.json_response(resp_json)
return response # pragma: no cover
return await user_call(request, r.user_uuid, role)

return web.json_response({"error": "Please provide correct Token."}, status=400)


async def user_call(request: web.Request, user_uuid, role):
response = await get_user_call(request, user_uuid)

if response.status == 200:
resp_json = json.loads(response.text)
resp_json["role"] = role
return web.json_response(resp_json)
return response # pragma: no cover


async def get_user_call(request: web.Request, user_uuid: str) -> web.Response:
""" Get User by Session token """
user_host = request.app["config"].user_service.host
Expand Down
14 changes: 5 additions & 9 deletions tests/test_auth/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
BASE_PATH,
)

CONFIG_FILE_PATH = BASE_PATH / "config.yml"

class TestAuthRestService(AioHTTPTestCase):
CONFIG_FILE_PATH = BASE_PATH / "config.yml"

class TestAuthRestService(AioHTTPTestCase):
def setUp(self) -> None:
self.config = AuthConfig(self.CONFIG_FILE_PATH)
self.config = AuthConfig(CONFIG_FILE_PATH)

self.user = MockServer(host=self.config.user_service.host, port=self.config.user_service.port,)
self.user.add_json_response(
Expand Down Expand Up @@ -212,10 +212,8 @@ async def test_login_without_token(self):


class TestRolesRestService(AioHTTPTestCase):
CONFIG_FILE_PATH = BASE_PATH / "config.yml"

def setUp(self) -> None:
self.config = AuthConfig(self.CONFIG_FILE_PATH)
self.config = AuthConfig(CONFIG_FILE_PATH)
super().setUp()

def tearDown(self) -> None:
Expand All @@ -237,10 +235,8 @@ async def test_create_credentials(self):


class TestAuthenticationRestService(AioHTTPTestCase):
CONFIG_FILE_PATH = BASE_PATH / "config.yml"

def setUp(self) -> None:
self.config = AuthConfig(self.CONFIG_FILE_PATH)
self.config = AuthConfig(CONFIG_FILE_PATH)
super().setUp()

def tearDown(self) -> None:
Expand Down

0 comments on commit af3108c

Please sign in to comment.