From 345476073110e1d571b5a31aee5a036f6dbd2a1e Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 16 Oct 2020 21:31:12 +0200 Subject: [PATCH] *: ensure TaskResult uid is slugified to prevent URL errors --- passbook/outposts/tasks.py | 9 +++++++-- passbook/sources/ldap/tasks.py | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/passbook/outposts/tasks.py b/passbook/outposts/tasks.py index 181f3edf9..a4b121735 100644 --- a/passbook/outposts/tasks.py +++ b/passbook/outposts/tasks.py @@ -4,6 +4,7 @@ from typing import Any from asgiref.sync import async_to_sync from channels.layers import get_channel_layer from django.db.models.base import Model +from django.utils.text import slugify from structlog import get_logger from passbook.lib.tasks import MonitoredTask, TaskResult, TaskResultStatus @@ -45,10 +46,14 @@ def outpost_controller(self: MonitoredTask, outpost_pk: str): logs = ProxyDockerController(outpost).run_with_logs() except ControllerException as exc: self.set_status( - TaskResult(TaskResultStatus.ERROR, uid=outpost.name).with_error(exc) + TaskResult(TaskResultStatus.ERROR, uid=slugify(outpost.name)).with_error( + exc + ) ) else: - self.set_status(TaskResult(TaskResultStatus.SUCCESSFUL, logs, uid=outpost.name)) + self.set_status( + TaskResult(TaskResultStatus.SUCCESSFUL, logs, uid=slugify(outpost.name)) + ) @CELERY_APP.task() diff --git a/passbook/sources/ldap/tasks.py b/passbook/sources/ldap/tasks.py index fda1fea9f..888247f6a 100644 --- a/passbook/sources/ldap/tasks.py +++ b/passbook/sources/ldap/tasks.py @@ -2,6 +2,7 @@ from time import time from django.core.cache import cache +from django.utils.text import slugify from ldap3.core.exceptions import LDAPException from passbook.lib.tasks import MonitoredTask, TaskResult, TaskResultStatus @@ -32,10 +33,10 @@ def ldap_sync(self: MonitoredTask, source_pk: int): TaskResult( TaskResultStatus.SUCCESSFUL, [f"Synced {user_count} users", f"Synced {group_count} groups"], - uid=source.name, + uid=slugify(source.name), ) ) except LDAPException as exc: self.set_status( - TaskResult(TaskResultStatus.ERROR, uid=source.name).with_error(exc) + TaskResult(TaskResultStatus.ERROR, uid=slugify(source.name)).with_error(exc) )