Skip to content
Snippets Groups Projects
Commit 0146d8ef authored by Jörn Künsemöller's avatar Jörn Künsemöller
Browse files

TMSS-2601: bugfix, reduce log level

parent 31774a72
No related branches found
No related tags found
1 merge request!1122Resolve TMSS-2601
...@@ -66,13 +66,11 @@ class TMSSWebSocket(WebSocket): ...@@ -66,13 +66,11 @@ class TMSSWebSocket(WebSocket):
self.user = token_obj.user self.user = token_obj.user
self.authenticated = True self.authenticated = True
logger.info('Client authenticated. User: %s from IP: %s' % (self.user, self.address[0])) logger.info('Client authenticated. User: %s from IP: %s' % (self.user, self.address[0]))
self.sendMessage(JSONdumps([u'Your websocket connection was successfully authenticated.']))
else: else:
logger.info('Client not authenticated. IP: %s' % (self.address[0])) logger.info('Client not authenticated. IP: %s' % (self.address[0]))
self.close(1011, u'Please login, so you have a token, and please submit the token in the 1st message after the connection was made.') self.close(1011, u'Please login, so you have a token, and please submit the token in the 1st message after the connection was made.')
else: else:
logger.info('Client already authenticated, ignoring incoming message. User: %s from IP: %s' % (self.user, self.address[0])) logger.debug('Client already authenticated, ignoring incoming message. User: %s from IP: %s' % (self.user, self.address[0]))
self.sendMessage(JSONdumps([u'Your websocket connection is already authenticated.']))
# NOTE: We just ignore incoming messages as we treat the communication as one-way only, except for the auth msg. # NOTE: We just ignore incoming messages as we treat the communication as one-way only, except for the auth msg.
except Exception as e: except Exception as e:
logger.exception('Error when handling websocket message of User: %s from IP: %s' % (self.user, self.address[0])) logger.exception('Error when handling websocket message of User: %s from IP: %s' % (self.user, self.address[0]))
...@@ -140,18 +138,18 @@ class TMSSEventMessageHandlerForWebsocket(TMSSEventMessageHandler): ...@@ -140,18 +138,18 @@ class TMSSEventMessageHandlerForWebsocket(TMSSEventMessageHandler):
from lofar.sas.tmss.tmss.tmssapp.models import ProjectRole from lofar.sas.tmss.tmss.tmssapp.models import ProjectRole
auth_clients = [] auth_clients = []
logger.info('Checking which of these users should receive websocket update for obj=%s: %s' % (obj, [ws.user for ws in list(self._ws_server.connections.values())])) logger.debug('Checking which of these users should receive websocket update for obj=%s: %s' % (obj, [ws.user for ws in list(self._ws_server.connections.values())]))
for ws in list(self._ws_server.connections.values()): for ws in list(self._ws_server.connections.values()):
if ws.authenticated: # Check user permissions for the object if ws.authenticated: # Check user permissions for the object
user = User.objects.get(username=ws.user) user = User.objects.get(username=ws.user)
if user.is_superuser: if user.is_superuser:
logger.info('User=%s is superuser and will receive websocket update for obj=%s' % (user, obj)) logger.debug('User=%s is superuser and will receive websocket update for obj=%s' % (user, obj))
auth_clients.append(ws) auth_clients.append(ws)
elif user.has_perm("tmssapp.view_%s" % type(obj).__name__.lower()): elif user.has_perm("tmssapp.view_%s" % type(obj).__name__.lower()):
logger.info('User=%s has permission=%s and will receive websocket update for obj=%s' % (user, "tmssapp.view_%s" % type(obj).__name__.lower(), obj)) logger.debug('User=%s has permission=%s and will receive websocket update for obj=%s' % (user, "tmssapp.view_%s" % type(obj).__name__.lower(), obj))
auth_clients.append(ws) auth_clients.append(ws)
else: else:
logger.info('User=%s has no permission=%s, checking for project-based permission to receive websocket update for obj=%s' % (user, "tmssapp.view_%s" % type(obj).__name__.lower(), obj)) logger.debug('User=%s has no permission=%s, checking for project-based permission to receive websocket update for obj=%s' % (user, "tmssapp.view_%s" % type(obj).__name__.lower(), obj))
# project-based permission # project-based permission
permitted_project_roles = get_project_roles_with_permission(type(obj).__name__.lower(), 'GET') permitted_project_roles = get_project_roles_with_permission(type(obj).__name__.lower(), 'GET')
user_project_roles = get_project_roles_for_user(user) user_project_roles = get_project_roles_for_user(user)
...@@ -161,10 +159,10 @@ class TMSSEventMessageHandlerForWebsocket(TMSSEventMessageHandler): ...@@ -161,10 +159,10 @@ class TMSSEventMessageHandlerForWebsocket(TMSSEventMessageHandler):
if project_role['project'].lower() == related_project.name.lower() and \ if project_role['project'].lower() == related_project.name.lower() and \
ProjectRole.objects.get(value=project_role['role']) in permitted_project_roles: ProjectRole.objects.get(value=project_role['role']) in permitted_project_roles:
auth_clients.append(ws) auth_clients.append(ws)
logger.info("User=%s has project-based permission for project=%s and will receive websocket update for obj=%s" % (user, project_role['project'].lower(), obj)) logger.debug("User=%s has project-based permission for project=%s and will receive websocket update for obj=%s" % (user, project_role['project'].lower(), obj))
break break
else: else:
logger.info("%s websocket is not authenticated and will not receive websocket update for obj=%s" % (ws.user, obj)) logger.debug("%s websocket is not authenticated and will not receive websocket update for obj=%s" % (ws.user, obj))
return auth_clients return auth_clients
def _broadcast_notify_to_clients_websocket(self, msg, clients): def _broadcast_notify_to_clients_websocket(self, msg, clients):
......
...@@ -115,7 +115,6 @@ class TestSubtaskSchedulingService(unittest.TestCase): ...@@ -115,7 +115,6 @@ class TestSubtaskSchedulingService(unittest.TestCase):
cls.tmss_test_env.stop() cls.tmss_test_env.stop()
cls.tmp_exchange.close() cls.tmp_exchange.close()
@unittest.skip('Skipped until TMSS-2601 is resolved and we do not send unexpected debug messages to the clients any more')
def test_01(self): def test_01(self):
''' '''
This test starts a websocket service and tmss. Creates, updates and deletes objects to check if json_blobs from the ws service are properly received. This test starts a websocket service and tmss. Creates, updates and deletes objects to check if json_blobs from the ws service are properly received.
......
...@@ -70,11 +70,14 @@ def authentication_state(request): ...@@ -70,11 +70,14 @@ def authentication_state(request):
if not request.user.is_authenticated: if not request.user.is_authenticated:
return JsonResponse({'is_authenticated': False}) return JsonResponse({'is_authenticated': False})
token_obj = Token.objects.filter(user=request.user).first()
token = token_obj.key if token_obj else None
return JsonResponse({'is_authenticated': True, return JsonResponse({'is_authenticated': True,
'username': request.user.username, 'username': request.user.username,
'email': request.user.email, 'email': request.user.email,
'id': request.user.id, 'id': request.user.id,
'websocket_token': Token.objects.filter(user=request.user).first()}) 'websocket_token': token})
# Allow everybody to GET our publicly available template-json-schema's # Allow everybody to GET our publicly available template-json-schema's
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment