From 0c4562c01dec6c7d9cbcdd0bef2b80de96fa0dc8 Mon Sep 17 00:00:00 2001 From: Matthias Jordan Date: Wed, 15 Aug 2012 23:39:18 +0200 Subject: [PATCH] Using different HTTP status codes in some cases where auth or rights are violated --- radicale/__init__.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index c183663..e8dad06 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -51,9 +51,18 @@ from . import auth, config, ical, log, rights, storage, xmlutils VERSION = "git" -# Standard "not allowed" response +# Standard "not allowed" response that is returned when an authenticated +# user tries to access information they don't have rights to. NOT_ALLOWED = ( client.FORBIDDEN, + {}, + None) + +# Standard "authenticate" response that is returned when a +# user tries to access non-public information w/o submitting +# proper authentication credentials +WRONG_CREDENTIALS = ( + client.UNAUTHORIZED, {"WWW-Authenticate": "Basic realm=\"Radicale - Password Required\""}, None) @@ -284,11 +293,7 @@ class Application(object): # Unknown or unauthorized user log.LOGGER.info( "%s refused" % (user or "Anonymous user")) - status = client.UNAUTHORIZED - headers = { - "WWW-Authenticate": - "Basic realm=\"Radicale Server - Password Required\""} - answer = None + status, headers, answer = WRONG_CREDENTIALS # Set content length if answer: @@ -310,7 +315,7 @@ class Application(object): def delete(self, environ, read_collections, write_collections, content, user): """Manage DELETE request.""" if not len(write_collections): - return NOT_ALLOWED + return client.PRECONDITION_FAILED, {}, None collection = write_collections[0]