From 2c73164fe8d04072dc17022d8bec93ec78c44cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Tue, 28 May 2024 12:03:34 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=94=A8=20Ensure=20a=20trailing=20slas?= =?UTF-8?q?h=20for=20CalDAV=20urls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/appointment/routes/api.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/src/appointment/routes/api.py b/backend/src/appointment/routes/api.py index 6a12c350d..21ee1cabc 100644 --- a/backend/src/appointment/routes/api.py +++ b/backend/src/appointment/routes/api.py @@ -135,6 +135,10 @@ def create_my_calendar( google_tkn=external_connection.token, ) else: + # make sure, the CalDAV url has a trailing slash + if calendar.url[-1] != '/': + calendar.url += '/' + con = CalDavConnector( redis_instance=None, url=calendar.url, @@ -190,6 +194,10 @@ def update_my_calendar( if not repo.calendar.is_owned(db, calendar_id=id, subscriber_id=subscriber.id): raise validation.CalendarNotAuthorizedException() + # make sure, the CalDAV url has a trailing slash + if calendar.provider == CalendarProvider.caldav and calendar.url[-1] != '/': + calendar.url += '/' + cal = repo.calendar.update(db=db, calendar=calendar, calendar_id=id) return schemas.CalendarOut(id=cal.id, title=cal.title, color=cal.color, connected=cal.connected) From ed625ff626076d26c7d4773df2e26710a82f0b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Tue, 28 May 2024 12:10:40 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=94=A8=20Quick=20fix=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/test/integration/test_calendar.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/test/integration/test_calendar.py b/backend/test/integration/test_calendar.py index d9d4a8566..5b84eac4c 100644 --- a/backend/test/integration/test_calendar.py +++ b/backend/test/integration/test_calendar.py @@ -361,7 +361,7 @@ def test_update_existing_caldav_calendar_with_password(self, with_client, with_d with with_db() as db: cal = db.scalars(query).one() - assert cal.url == os.getenv("CALDAV_TEST_CALENDAR_URL") + "x" + assert cal.url == os.getenv("CALDAV_TEST_CALENDAR_URL") + "x/" assert cal.user == os.getenv("CALDAV_TEST_USER") + "x" assert cal.password == os.getenv("CALDAV_TEST_PASS") + "x" @@ -394,6 +394,6 @@ def test_update_existing_caldav_calendar_without_password(self, with_client, wit with with_db() as db: cal = db.scalars(query).one() - assert cal.url == os.getenv("CALDAV_TEST_CALENDAR_URL") + assert cal.url == os.getenv("CALDAV_TEST_CALENDAR_URL") + "/" assert cal.user == os.getenv("CALDAV_TEST_USER") assert cal.password == '' From 382cc8a0c92ae7cf8412871a3d1699757004fe9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Tue, 28 May 2024 16:03:15 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=94=A8=20Set=20trailing=20slash=20for?= =?UTF-8?q?=20CalDAV=20urls=20only=20on=20runtime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/appointment/controller/calendar.py | 5 +++-- backend/src/appointment/routes/api.py | 8 -------- backend/test/integration/test_calendar.py | 4 ++-- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/backend/src/appointment/controller/calendar.py b/backend/src/appointment/controller/calendar.py index d82c9a2fd..1d02a3d3c 100644 --- a/backend/src/appointment/controller/calendar.py +++ b/backend/src/appointment/controller/calendar.py @@ -249,10 +249,11 @@ def __init__(self, subscriber_id: int, calendar_id: int, redis_instance, url: st super().__init__(subscriber_id, calendar_id, redis_instance) self.provider = CalendarProvider.caldav - self.url = url + self.url = url if url[-1] == '/' else url + '/' self.password = password self.user = user - # connect to CalDAV server + + # connect to the CalDAV server self.client = DAVClient(url=url, username=user, password=password) def test_connection(self) -> bool: diff --git a/backend/src/appointment/routes/api.py b/backend/src/appointment/routes/api.py index 21ee1cabc..6a12c350d 100644 --- a/backend/src/appointment/routes/api.py +++ b/backend/src/appointment/routes/api.py @@ -135,10 +135,6 @@ def create_my_calendar( google_tkn=external_connection.token, ) else: - # make sure, the CalDAV url has a trailing slash - if calendar.url[-1] != '/': - calendar.url += '/' - con = CalDavConnector( redis_instance=None, url=calendar.url, @@ -194,10 +190,6 @@ def update_my_calendar( if not repo.calendar.is_owned(db, calendar_id=id, subscriber_id=subscriber.id): raise validation.CalendarNotAuthorizedException() - # make sure, the CalDAV url has a trailing slash - if calendar.provider == CalendarProvider.caldav and calendar.url[-1] != '/': - calendar.url += '/' - cal = repo.calendar.update(db=db, calendar=calendar, calendar_id=id) return schemas.CalendarOut(id=cal.id, title=cal.title, color=cal.color, connected=cal.connected) diff --git a/backend/test/integration/test_calendar.py b/backend/test/integration/test_calendar.py index 5b84eac4c..d9d4a8566 100644 --- a/backend/test/integration/test_calendar.py +++ b/backend/test/integration/test_calendar.py @@ -361,7 +361,7 @@ def test_update_existing_caldav_calendar_with_password(self, with_client, with_d with with_db() as db: cal = db.scalars(query).one() - assert cal.url == os.getenv("CALDAV_TEST_CALENDAR_URL") + "x/" + assert cal.url == os.getenv("CALDAV_TEST_CALENDAR_URL") + "x" assert cal.user == os.getenv("CALDAV_TEST_USER") + "x" assert cal.password == os.getenv("CALDAV_TEST_PASS") + "x" @@ -394,6 +394,6 @@ def test_update_existing_caldav_calendar_without_password(self, with_client, wit with with_db() as db: cal = db.scalars(query).one() - assert cal.url == os.getenv("CALDAV_TEST_CALENDAR_URL") + "/" + assert cal.url == os.getenv("CALDAV_TEST_CALENDAR_URL") assert cal.user == os.getenv("CALDAV_TEST_USER") assert cal.password == ''