From f12dd31b4b8e8ebaaf963d021641def2feed9b4a Mon Sep 17 00:00:00 2001 From: Unrud Date: Wed, 31 May 2017 12:01:33 +0200 Subject: [PATCH 1/4] Small improvements for auth tests --- radicale/tests/test_auth.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/radicale/tests/test_auth.py b/radicale/tests/test_auth.py index 3ac3f08..dc0fadd 100644 --- a/radicale/tests/test_auth.py +++ b/radicale/tests/test_auth.py @@ -21,7 +21,6 @@ Radicale tests with simple requests and authentication. """ import base64 -import logging import os import shutil import tempfile @@ -40,7 +39,6 @@ class TestBaseAuthRequests(BaseTest): """ def setup(self): self.configuration = config.load() - self.logger = logging.getLogger("radicale_test") self.colpath = tempfile.mkdtemp() self.configuration.set("storage", "filesystem_folder", self.colpath) # Disable syncing to disk for better performance @@ -63,14 +61,14 @@ class TestBaseAuthRequests(BaseTest): self.configuration.set("auth", "htpasswd_encryption", htpasswd_encryption) self.application = Application(self.configuration, self.logger) - for user, password, expeced_status in ( + for user, password, expected_status in ( ("tmp", "bepo", 207), ("tmp", "tmp", 401), ("tmp", "", 401), ("unk", "unk", 401), ("unk", "", 401), ("", "", 401)): status, headers, answer = self.request( "PROPFIND", "/", HTTP_AUTHORIZATION="Basic %s" % base64.b64encode( ("%s:%s" % (user, password)).encode()).decode()) - assert status == expeced_status + assert status == expected_status def test_htpasswd_plain(self): self._test_htpasswd("plain", "tmp:bepo") @@ -142,6 +140,6 @@ class TestBaseAuthRequests(BaseTest): self.configuration.set("auth", "type", "tests.custom.auth") self.application = Application(self.configuration, self.logger) status, headers, answer = self.request( - "GET", "/", HTTP_AUTHORIZATION="dG1wOmJlcG8=") - assert status == 200 - assert "Radicale works!" in answer + "PROPFIND", "/tmp", HTTP_AUTHORIZATION="Basic %s" % + base64.b64encode(("tmp:").encode()).decode()) + assert status == 207 From 5704b5021b42f499a89cd072c4d92be90362e49d Mon Sep 17 00:00:00 2001 From: Unrud Date: Wed, 31 May 2017 12:01:35 +0200 Subject: [PATCH 2/4] PATH_INFO might not exist if it's empty --- radicale/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index 5aac750..0ff1bb4 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -334,8 +334,8 @@ class Application: status, client.responses.get(status, "Unknown")) self.logger.info( "%s answer status for %r%s in %.3f seconds: %s", - environ["REQUEST_METHOD"], environ["PATH_INFO"], depthinfo, - (time_end - time_begin).total_seconds(), status) + environ["REQUEST_METHOD"], environ.get("PATH_INFO", ""), + depthinfo, (time_end - time_begin).total_seconds(), status) # Return response content return status, list(headers.items()), [answer] if answer else [] @@ -372,6 +372,7 @@ class Application: environ.get("SCRIPT_NAME", "")).rstrip("/") self.logger.debug("Sanitized script name: %r", environ["SCRIPT_NAME"]) base_prefix = environ["SCRIPT_NAME"] + environ["PATH_INFO"] = environ.get("PATH_INFO", "") # Sanitize request URI (a WSGI server indicates with an empty path, # that the URL targets the application root without a trailing slash) if environ["PATH_INFO"]: From edaf21561d3b2cdae621695473becc55ec685320 Mon Sep 17 00:00:00 2001 From: Unrud Date: Wed, 31 May 2017 12:01:37 +0200 Subject: [PATCH 3/4] Don't strip SCRIPT_NAME from PATH_INFO --- radicale/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index 0ff1bb4..4fff67e 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -378,10 +378,9 @@ class Application: if environ["PATH_INFO"]: environ["PATH_INFO"] = storage.sanitize_path(environ["PATH_INFO"]) self.logger.debug("Sanitized path: %r", environ["PATH_INFO"]) + # SCRIPT_NAME is already removed from PATH_INFO, according to the + # WSGI specification. path = environ["PATH_INFO"] - if base_prefix and path.startswith(base_prefix): - path = path[len(base_prefix):] - self.logger.debug("Stripped script name from path: %s", path) # Get function corresponding to method function = getattr(self, "do_%s" % environ["REQUEST_METHOD"].upper()) From eba6621f176a4e1089aad72d91a2b9be84e98d6a Mon Sep 17 00:00:00 2001 From: Unrud Date: Wed, 31 May 2017 12:01:39 +0200 Subject: [PATCH 4/4] Rename backends from None to none All other backend names are lower case. --- config | 6 +++--- radicale/auth.py | 2 +- radicale/rights.py | 4 ++-- radicale/tests/test_rights.py | 20 ++++++++++---------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/config b/config index bd35574..0925a54 100644 --- a/config +++ b/config @@ -66,8 +66,8 @@ [auth] # Authentication method -# Value: None | htpasswd | remote_user | http_x_remote_user -#type = None +# Value: none | htpasswd | remote_user | http_x_remote_user +#type = none # Htpasswd filename #htpasswd_filename = /etc/radicale/users @@ -85,7 +85,7 @@ [rights] # Rights backend -# Value: None | authenticated | owner_only | owner_write | from_file +# Value: none | authenticated | owner_only | owner_write | from_file #type = owner_only # File for rights management from_file diff --git a/radicale/auth.py b/radicale/auth.py index 63f0f37..20c1399 100644 --- a/radicale/auth.py +++ b/radicale/auth.py @@ -64,7 +64,7 @@ from importlib import import_module def load(configuration, logger): """Load the authentication manager chosen in configuration.""" auth_type = configuration.get("auth", "type") - if auth_type == "None": + if auth_type in ("None", "none"): # DEPRECATED: use "none" class_ = NoneAuth elif auth_type == "remote_user": class_ = RemoteUserAuth diff --git a/radicale/rights.py b/radicale/rights.py index d4c0f6a..ed8745b 100644 --- a/radicale/rights.py +++ b/radicale/rights.py @@ -48,9 +48,9 @@ from . import storage def load(configuration, logger): """Load the rights manager chosen in configuration.""" rights_type = configuration.get("rights", "type") - if configuration.get("auth", "type") == "None": + if configuration.get("auth", "type") in ("None", "none"): # DEPRECATED rights_type = "None" - if rights_type == "None": + if rights_type in ("None", "none"): # DEPRECATED: use "none" rights_class = NoneRights elif rights_type == "authenticated": rights_class = AuthenticatedRights diff --git a/radicale/tests/test_rights.py b/radicale/tests/test_rights.py index f332f5b..4e80c26 100644 --- a/radicale/tests/test_rights.py +++ b/radicale/tests/test_rights.py @@ -102,16 +102,16 @@ class TestBaseAuthRequests(BaseTest): self._test_rights("authenticated", "tmp", "/other", "w", 207) def test_none(self): - self._test_rights("None", "", "/", "r", 207) - self._test_rights("None", "", "/", "w", 207) - self._test_rights("None", "", "/tmp", "r", 207) - self._test_rights("None", "", "/tmp", "w", 207) - self._test_rights("None", "tmp", "/", "r", 207) - self._test_rights("None", "tmp", "/", "w", 207) - self._test_rights("None", "tmp", "/tmp", "r", 207) - self._test_rights("None", "tmp", "/tmp", "w", 207) - self._test_rights("None", "tmp", "/other", "r", 207) - self._test_rights("None", "tmp", "/other", "w", 207) + self._test_rights("none", "", "/", "r", 207) + self._test_rights("none", "", "/", "w", 207) + self._test_rights("none", "", "/tmp", "r", 207) + self._test_rights("none", "", "/tmp", "w", 207) + self._test_rights("none", "tmp", "/", "r", 207) + self._test_rights("none", "tmp", "/", "w", 207) + self._test_rights("none", "tmp", "/tmp", "r", 207) + self._test_rights("none", "tmp", "/tmp", "w", 207) + self._test_rights("none", "tmp", "/other", "r", 207) + self._test_rights("none", "tmp", "/other", "w", 207) def test_from_file(self): rights_file_path = os.path.join(self.colpath, "rights")