From e4a0afcf00529cd88e21675cb39de140fd70ec58 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Fri, 17 Jun 2016 14:35:06 +0200 Subject: [PATCH] Make auth = basic the default again (#477) Fix #461 Fix #457 --- CHANGELOG.rst | 7 +++++++ tests/storage/test_http.py | 9 +++++---- vdirsyncer/storage/http.py | 12 +++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index dded558..c43301f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,13 @@ Package maintainers and users who have to manually update their installation may want to subscribe to `GitHub's tag feed `_. +Version 0.11.3 +============== + +- Default value of ``auth`` parameter was changed from ``guess`` to ``basic`` + to resolve issues with the Apple Calendar Server (:gh:`457`) and improve + performance. See :gh:`461`. + Version 0.11.2 ============== diff --git a/tests/storage/test_http.py b/tests/storage/test_http.py index d0ec9b5..530c4d0 100644 --- a/tests/storage/test_http.py +++ b/tests/storage/test_http.py @@ -83,7 +83,9 @@ def test_readonly_param(): def test_prepare_auth(): assert prepare_auth(None, '', '') is None + assert prepare_auth(None, 'user', 'pwd') == ('user', 'pwd') assert prepare_auth('basic', 'user', 'pwd') == ('user', 'pwd') + with pytest.raises(ValueError) as excinfo: assert prepare_auth('basic', '', 'pwd') assert 'you need to specify username and password' in \ @@ -99,17 +101,16 @@ def test_prepare_auth(): assert 'unknown authentication method' in str(excinfo.value).lower() -@pytest.mark.parametrize('auth', (None, 'guess')) -def test_prepare_auth_guess(monkeypatch, auth): +def test_prepare_auth_guess(monkeypatch): import requests_toolbelt.auth.guess - assert isinstance(prepare_auth(auth, 'user', 'pwd'), + assert isinstance(prepare_auth('guess', 'user', 'pwd'), requests_toolbelt.auth.guess.GuessAuth) monkeypatch.delattr(requests_toolbelt.auth.guess, 'GuessAuth') with pytest.raises(UserError) as excinfo: - prepare_auth(auth, 'user', 'pwd') + prepare_auth('guess', 'user', 'pwd') assert 'requests_toolbelt is too old' in str(excinfo.value).lower() diff --git a/vdirsyncer/storage/http.py b/vdirsyncer/storage/http.py index da5ff07..f3d26eb 100644 --- a/vdirsyncer/storage/http.py +++ b/vdirsyncer/storage/http.py @@ -12,12 +12,12 @@ USERAGENT = 'vdirsyncer' def prepare_auth(auth, username, password): if username and password: - if auth == 'basic': + if auth == 'basic' or auth is None: return (username, password) elif auth == 'digest': from requests.auth import HTTPDigestAuth return HTTPDigestAuth(username, password) - elif auth == 'guess' or auth is None: + elif auth == 'guess': try: from requests_toolbelt.auth.guess import GuessAuth except ImportError: @@ -80,9 +80,11 @@ HTTP_STORAGE_PARAMETERS = ''' :param verify_fingerprint: Optional. SHA1 or MD5 fingerprint of the expected server certificate. See :ref:`ssl-tutorial` for more information. - :param auth: Optional. Either ``basic``, ``digest`` or ``guess``. Default - ``guess``. If you know yours, consider setting it explicitly for - performance. + :param auth: Optional. Either ``basic``, ``digest`` or ``guess``. The + default is preemptive Basic auth, sending credentials even if server + didn't request them. This saves from an additional roundtrip per + request. Consider setting ``guess`` if this causes issues with your + server. :param auth_cert: Optional. Either a path to a certificate with a client certificate and the key or a list of paths to the files with them. :param useragent: Default ``vdirsyncer``.