From 4d1beb95e05fc31f0961bae72e56d481a3d00739 Mon Sep 17 00:00:00 2001 From: Tobias Brox Date: Sat, 25 Feb 2023 20:09:56 +0100 Subject: [PATCH] Fix for https://github.com/python-caldav/caldav/issues/289 - basic auth broken for some servers --- caldav/davclient.py | 2 +- caldav/lib/vcal.py | 3 ++- tests/test_caldav_unit.py | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/caldav/davclient.py b/caldav/davclient.py index a3091157..f5378ee8 100644 --- a/caldav/davclient.py +++ b/caldav/davclient.py @@ -550,7 +550,7 @@ def options(self, url): def extract_auth_types(self, header): auth_types = header.lower().split(",") auth_types = map(lambda auth_type: auth_type.strip(), auth_types) - auth_types = map(lambda auth_type: auth_type[: auth_type.find(" ")], auth_types) + auth_types = map(lambda auth_type: auth_type.split(" ")[0], auth_types) return list(filter(lambda auth_type: auth_type, auth_types)) def request(self, url, method="GET", body="", headers={}): diff --git a/caldav/lib/vcal.py b/caldav/lib/vcal.py index 9aa0d27e..0bd1b2a5 100644 --- a/caldav/lib/vcal.py +++ b/caldav/lib/vcal.py @@ -105,7 +105,8 @@ def fix(event): else: log = logging.debug log( - "Ical data was modified to avoid compatibility issues. (error count: %i - this error is ratelimited)" % fixup_error_loggings, + "Ical data was modified to avoid compatibility issues. (error count: %i - this error is ratelimited)" + % fixup_error_loggings, exc_info=True, ) try: diff --git a/tests/test_caldav_unit.py b/tests/test_caldav_unit.py index 19049c47..4cbf6e99 100644 --- a/tests/test_caldav_unit.py +++ b/tests/test_caldav_unit.py @@ -1175,3 +1175,19 @@ def testContextManager(self): cal_url = "http://me:hunter2@calendar.example:80/" with DAVClient(url=cal_url) as client_ctx_mgr: assert isinstance(client_ctx_mgr, DAVClient) + + def testExtractAuth(self): + """ + ref https://github.com/python-caldav/caldav/issues/289 + """ + cal_url = "http://me:hunter2@calendar.example:80/" + with DAVClient(url=cal_url) as client: + assert client.extract_auth_types("Basic\n") == ["basic"] + assert client.extract_auth_types("Basic") == ["basic"] + assert client.extract_auth_types('Basic Realm=foo;charset="UTF-8"') == [ + "basic" + ] + assert client.extract_auth_types("Basic,dIGEST Realm=foo") == [ + "basic", + "digest", + ]