diff --git a/caldav/davclient.py b/caldav/davclient.py index b9325e7..ce9183a 100644 --- a/caldav/davclient.py +++ b/caldav/davclient.py @@ -616,11 +616,9 @@ def delete(self, url: str) -> DAVResponse: def options(self, url: str) -> DAVResponse: return self.request(url, "OPTIONS") - 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.split(" ")[0], auth_types) - return list(filter(lambda auth_type: auth_type, auth_types)) + def extract_auth_types(self, header: str): + # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/WWW-Authenticate#syntax + return {h.split()[0] for h in header.lower().split(",")} def request( self, diff --git a/tests/test_caldav_unit.py b/tests/test_caldav_unit.py index a4486be..9321294 100644 --- a/tests/test_caldav_unit.py +++ b/tests/test_caldav_unit.py @@ -1293,12 +1293,12 @@ def testExtractAuth(self): """ 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"') == [ + 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") == [ + } + assert client.extract_auth_types("Basic,dIGEST Realm=foo") == { "basic", "digest", - ] + }