From 2a354a70597dbbe23b203aa7f2693a9388b086d1 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Thu, 1 Jul 2021 21:49:24 +0200 Subject: Fix duplicate url matching --- rwa/support/sessionservice/service.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/rwa/support/sessionservice/service.py b/rwa/support/sessionservice/service.py index 7bb45b2..95c014b 100755 --- a/rwa/support/sessionservice/service.py +++ b/rwa/support/sessionservice/service.py @@ -96,7 +96,7 @@ class RWASupportSessionService(dbus.service.Object): :return: Whether the string is an URL. """ valid = validators.url(url) - logging.debug(f"Is {url} an URL: {valid}") + logging.debug(f"Is '{url}' an URL: {valid}") return valid def _get_web_app_hosts(self) -> str: @@ -224,13 +224,20 @@ class RWASupportSessionService(dbus.service.Object): logging.info('The response to D-Bus caller: "%s"', response) return response - if host_url in self.settings.web_app_hosts: - logging.warning("Given URL is already present!") - logging.debug('Did not add "%s" to "web_app_hosts" in user_settings', host_url) - - response = json.dumps({"status": "error", "type": "duplicate"}) - logging.info('The response to D-Bus caller: "%s"', response) - return response + try: + for uuid, host in self.settings.web_app_hosts.items(): + if host_url in host['url']: + logging.warning("Given URL is already present!") + logging.debug('Did not add "%s" to "web_app_hosts" in user_settings', host_url) + + response = json.dumps({"status": "error", "type": "duplicate"}) + logging.info('The response to D-Bus caller: "%s"', response) + return response + except (KeyError, IndexError): + logging.warning( + 'Got an exception while trying to find given url ' + 'in already existing hosts!' + ) res = self._do_api_handshake(host_url) if res["status"] == "error": -- cgit v1.2.3