Skip to content

Commit

Permalink
Fix for #289 - basic auth broken for some servers
Browse files Browse the repository at this point in the history
  • Loading branch information
tobixen committed Feb 25, 2023
1 parent 25db457 commit 4d1beb9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion caldav/davclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={}):
Expand Down
3 changes: 2 additions & 1 deletion caldav/lib/vcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions tests/test_caldav_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,3 +1175,19 @@ def testContextManager(self):
cal_url = "http://me:[email protected]: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:[email protected]: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",
]

0 comments on commit 4d1beb9

Please sign in to comment.