mirror of
https://github.com/Kozea/Radicale.git
synced 2025-08-01 18:18:31 +00:00
Improve tests
- Parse and verify XML responses - Extract methods for common requests
This commit is contained in:
parent
a03911f954
commit
fc180266d5
6 changed files with 1059 additions and 1134 deletions
|
@ -24,8 +24,8 @@ import shutil
|
|||
import tempfile
|
||||
|
||||
from radicale import Application, config
|
||||
from radicale.tests import BaseTest
|
||||
from radicale.tests.helpers import get_file_content
|
||||
from radicale.tests.test_base import BaseTest
|
||||
|
||||
|
||||
class TestBaseRightsRequests(BaseTest):
|
||||
|
@ -56,69 +56,67 @@ class TestBaseRightsRequests(BaseTest):
|
|||
"htpasswd_encryption": "plain"}}, "test")
|
||||
self.application = Application(self.configuration)
|
||||
for u in ("tmp", "other"):
|
||||
status, _, _ = self.request(
|
||||
"PROPFIND", "/%s" % u, HTTP_AUTHORIZATION="Basic %s" %
|
||||
status, _ = self.propfind(
|
||||
"/%s/" % u, HTTP_AUTHORIZATION="Basic %s" %
|
||||
base64.b64encode(("%s:bepo" % u).encode()).decode())
|
||||
assert status == 207
|
||||
status, _, _ = self.request(
|
||||
"PROPFIND" if mode == "r" else "PROPPATCH", path,
|
||||
HTTP_AUTHORIZATION="Basic %s" % base64.b64encode(
|
||||
("tmp:bepo").encode()).decode() if user else "")
|
||||
status, _ = (self.propfind if mode == "r" else self.proppatch)(
|
||||
path, check=False, HTTP_AUTHORIZATION="Basic %s" %
|
||||
base64.b64encode(("tmp:bepo").encode()).decode() if user else "")
|
||||
assert status == expected_status
|
||||
|
||||
def test_owner_only(self):
|
||||
self._test_rights("owner_only", "", "/", "r", 401)
|
||||
self._test_rights("owner_only", "", "/", "w", 401)
|
||||
self._test_rights("owner_only", "", "/tmp", "r", 401)
|
||||
self._test_rights("owner_only", "", "/tmp", "w", 401)
|
||||
self._test_rights("owner_only", "", "/tmp/", "r", 401)
|
||||
self._test_rights("owner_only", "", "/tmp/", "w", 401)
|
||||
self._test_rights("owner_only", "tmp", "/", "r", 207)
|
||||
self._test_rights("owner_only", "tmp", "/", "w", 403)
|
||||
self._test_rights("owner_only", "tmp", "/tmp", "r", 207)
|
||||
self._test_rights("owner_only", "tmp", "/tmp", "w", 207)
|
||||
self._test_rights("owner_only", "tmp", "/other", "r", 403)
|
||||
self._test_rights("owner_only", "tmp", "/other", "w", 403)
|
||||
self._test_rights("owner_only", "tmp", "/tmp/", "r", 207)
|
||||
self._test_rights("owner_only", "tmp", "/tmp/", "w", 207)
|
||||
self._test_rights("owner_only", "tmp", "/other/", "r", 403)
|
||||
self._test_rights("owner_only", "tmp", "/other/", "w", 403)
|
||||
|
||||
def test_owner_only_without_auth(self):
|
||||
self._test_rights("owner_only", "", "/", "r", 207, False)
|
||||
self._test_rights("owner_only", "", "/", "w", 401, False)
|
||||
self._test_rights("owner_only", "", "/tmp", "r", 207, False)
|
||||
self._test_rights("owner_only", "", "/tmp", "w", 207, False)
|
||||
self._test_rights("owner_only", "", "/tmp/", "r", 207, False)
|
||||
self._test_rights("owner_only", "", "/tmp/", "w", 207, False)
|
||||
|
||||
def test_owner_write(self):
|
||||
self._test_rights("owner_write", "", "/", "r", 401)
|
||||
self._test_rights("owner_write", "", "/", "w", 401)
|
||||
self._test_rights("owner_write", "", "/tmp", "r", 401)
|
||||
self._test_rights("owner_write", "", "/tmp", "w", 401)
|
||||
self._test_rights("owner_write", "", "/tmp/", "r", 401)
|
||||
self._test_rights("owner_write", "", "/tmp/", "w", 401)
|
||||
self._test_rights("owner_write", "tmp", "/", "r", 207)
|
||||
self._test_rights("owner_write", "tmp", "/", "w", 403)
|
||||
self._test_rights("owner_write", "tmp", "/tmp", "r", 207)
|
||||
self._test_rights("owner_write", "tmp", "/tmp", "w", 207)
|
||||
self._test_rights("owner_write", "tmp", "/other", "r", 207)
|
||||
self._test_rights("owner_write", "tmp", "/other", "w", 403)
|
||||
self._test_rights("owner_write", "tmp", "/tmp/", "r", 207)
|
||||
self._test_rights("owner_write", "tmp", "/tmp/", "w", 207)
|
||||
self._test_rights("owner_write", "tmp", "/other/", "r", 207)
|
||||
self._test_rights("owner_write", "tmp", "/other/", "w", 403)
|
||||
|
||||
def test_owner_write_without_auth(self):
|
||||
self._test_rights("owner_write", "", "/", "r", 207, False)
|
||||
self._test_rights("owner_write", "", "/", "w", 401, False)
|
||||
self._test_rights("owner_write", "", "/tmp", "r", 207, False)
|
||||
self._test_rights("owner_write", "", "/tmp", "w", 207, False)
|
||||
self._test_rights("owner_write", "", "/tmp/", "r", 207, False)
|
||||
self._test_rights("owner_write", "", "/tmp/", "w", 207, False)
|
||||
|
||||
def test_authenticated(self):
|
||||
self._test_rights("authenticated", "", "/", "r", 401)
|
||||
self._test_rights("authenticated", "", "/", "w", 401)
|
||||
self._test_rights("authenticated", "", "/tmp", "r", 401)
|
||||
self._test_rights("authenticated", "", "/tmp", "w", 401)
|
||||
self._test_rights("authenticated", "", "/tmp/", "r", 401)
|
||||
self._test_rights("authenticated", "", "/tmp/", "w", 401)
|
||||
self._test_rights("authenticated", "tmp", "/", "r", 207)
|
||||
self._test_rights("authenticated", "tmp", "/", "w", 207)
|
||||
self._test_rights("authenticated", "tmp", "/tmp", "r", 207)
|
||||
self._test_rights("authenticated", "tmp", "/tmp", "w", 207)
|
||||
self._test_rights("authenticated", "tmp", "/other", "r", 207)
|
||||
self._test_rights("authenticated", "tmp", "/other", "w", 207)
|
||||
self._test_rights("authenticated", "tmp", "/tmp/", "r", 207)
|
||||
self._test_rights("authenticated", "tmp", "/tmp/", "w", 207)
|
||||
self._test_rights("authenticated", "tmp", "/other/", "r", 207)
|
||||
self._test_rights("authenticated", "tmp", "/other/", "w", 207)
|
||||
|
||||
def test_authenticated_without_auth(self):
|
||||
self._test_rights("authenticated", "", "/", "r", 207, False)
|
||||
self._test_rights("authenticated", "", "/", "w", 207, False)
|
||||
self._test_rights("authenticated", "", "/tmp", "r", 207, False)
|
||||
self._test_rights("authenticated", "", "/tmp", "w", 207, False)
|
||||
self._test_rights("authenticated", "", "/tmp/", "r", 207, False)
|
||||
self._test_rights("authenticated", "", "/tmp/", "w", 207, False)
|
||||
|
||||
def test_from_file(self):
|
||||
rights_file_path = os.path.join(self.colpath, "rights")
|
||||
|
@ -134,8 +132,8 @@ collection: custom(/.*)?
|
|||
permissions: Rr""")
|
||||
self.configuration.update(
|
||||
{"rights": {"file": rights_file_path}}, "test")
|
||||
self._test_rights("from_file", "", "/other", "r", 401)
|
||||
self._test_rights("from_file", "tmp", "/other", "r", 403)
|
||||
self._test_rights("from_file", "", "/other/", "r", 401)
|
||||
self._test_rights("from_file", "tmp", "/other/", "r", 403)
|
||||
self._test_rights("from_file", "", "/custom/sub", "r", 404)
|
||||
self._test_rights("from_file", "tmp", "/custom/sub", "r", 404)
|
||||
self._test_rights("from_file", "", "/custom/sub", "w", 401)
|
||||
|
@ -144,7 +142,8 @@ permissions: Rr""")
|
|||
def test_custom(self):
|
||||
"""Custom rights management."""
|
||||
self._test_rights("radicale.tests.custom.rights", "", "/", "r", 401)
|
||||
self._test_rights("radicale.tests.custom.rights", "", "/tmp", "r", 207)
|
||||
self._test_rights(
|
||||
"radicale.tests.custom.rights", "", "/tmp/", "r", 207)
|
||||
|
||||
def test_collections_and_items(self):
|
||||
"""Test rights for creation of collections, calendars and items.
|
||||
|
@ -155,33 +154,19 @@ permissions: Rr""")
|
|||
|
||||
"""
|
||||
self.application = Application(self.configuration)
|
||||
status, _, _ = self.request("MKCALENDAR", "/")
|
||||
assert status == 401
|
||||
status, _, _ = self.request("MKCALENDAR", "/user/")
|
||||
assert status == 401
|
||||
status, _, _ = self.request("MKCOL", "/user/")
|
||||
assert status == 201
|
||||
status, _, _ = self.request("MKCOL", "/user/calendar/")
|
||||
assert status == 401
|
||||
status, _, _ = self.request("MKCALENDAR", "/user/calendar/")
|
||||
assert status == 201
|
||||
status, _, _ = self.request("MKCOL", "/user/calendar/item")
|
||||
assert status == 401
|
||||
status, _, _ = self.request("MKCALENDAR", "/user/calendar/item")
|
||||
assert status == 401
|
||||
self.mkcalendar("/", check=401)
|
||||
self.mkcalendar("/user/", check=401)
|
||||
self.mkcol("/user/")
|
||||
self.mkcol("/user/calendar/", check=401)
|
||||
self.mkcalendar("/user/calendar/")
|
||||
self.mkcol("/user/calendar/item", check=401)
|
||||
self.mkcalendar("/user/calendar/item", check=401)
|
||||
|
||||
def test_put_collections_and_items(self):
|
||||
"""Test rights for creation of calendars and items with PUT."""
|
||||
self.application = Application(self.configuration)
|
||||
status, _, _ = self.request(
|
||||
"PUT", "/user/", "BEGIN:VCALENDAR\r\nEND:VCALENDAR")
|
||||
assert status == 401
|
||||
status, _, _ = self.request("MKCOL", "/user/")
|
||||
assert status == 201
|
||||
status, _, _ = self.request(
|
||||
"PUT", "/user/calendar/", "BEGIN:VCALENDAR\r\nEND:VCALENDAR")
|
||||
assert status == 201
|
||||
self.put("/user/", "BEGIN:VCALENDAR\r\nEND:VCALENDAR", check=401)
|
||||
self.mkcol("/user/")
|
||||
self.put("/user/calendar/", "BEGIN:VCALENDAR\r\nEND:VCALENDAR")
|
||||
event1 = get_file_content("event1.ics")
|
||||
status, _, _ = self.request(
|
||||
"PUT", "/user/calendar/event1.ics", event1)
|
||||
assert status == 201
|
||||
self.put("/user/calendar/event1.ics", event1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue