sharing/test: per db extension

This commit is contained in:
Peter Bieringer
2026-02-28 07:39:42 +01:00
parent fae972d25c
commit 3efd405382

View File

@@ -76,25 +76,56 @@ class TestSharingApiSanity(BaseTest):
# disabled # disabled
for path in ["/.sharing", "/.sharing/"]: for path in ["/.sharing", "/.sharing/"]:
_, headers, _ = self.request("POST", path, check=404) _, headers, _ = self.request("POST", path, check=404)
# enabled (permutations)
path = "/.sharing/"
# no database is active
logging.info("\n*** check API hook base: map=True token=False")
self.configure({"sharing": { self.configure({"sharing": {
"collection_by_map": "True", "collection_by_map": "True",
"collection_by_token": "False"} "collection_by_token": "False"}
}) })
path = "/.sharing/" _, headers, _ = self.request("POST", path, check=404)
_, headers, _ = self.request("POST", path, check=401)
logging.info("\n*** check API hook base: map=False token=True")
self.configure({"sharing": { self.configure({"sharing": {
"collection_by_map": "False", "collection_by_map": "False",
"collection_by_token": "True"} "collection_by_token": "True"}
}) })
path = "/.sharing/" _, headers, _ = self.request("POST", path, check=404)
_, headers, _ = self.request("POST", path, check=401)
logging.info("\n*** check API hook base: map=True token=True")
self.configure({"sharing": { self.configure({"sharing": {
"collection_by_map": "True", "collection_by_map": "True",
"collection_by_token": "True"} "collection_by_token": "True"}
}) })
path = "/.sharing/" _, headers, _ = self.request("POST", path, check=404)
_, headers, _ = self.request("POST", path, check=401)
for db_type in list(filter(lambda item: item != "none", sharing.INTERNAL_TYPES)):
logging.info("\n*** test: %s", db_type)
self.configure({"sharing": {"type": db_type}})
# no database is active
logging.info("\n*** check API hook base: map=True token=False")
self.configure({"sharing": {
"collection_by_map": "True",
"collection_by_token": "False"}
})
_, headers, _ = self.request("POST", path, check=401)
logging.info("\n*** check API hook base: map=False token=True")
self.configure({"sharing": {
"collection_by_map": "False",
"collection_by_token": "True"}
})
_, headers, _ = self.request("POST", path, check=401)
logging.info("\n*** check API hook base: map=True token=True")
self.configure({"sharing": {
"collection_by_map": "True",
"collection_by_token": "True"}
})
_, headers, _ = self.request("POST", path, check=401)
def test_sharing_api_base_with_auth(self) -> None: def test_sharing_api_base_with_auth(self) -> None:
"""POST request at '/.sharing' with authentication.""" """POST request at '/.sharing' with authentication."""
@@ -108,75 +139,82 @@ class TestSharingApiSanity(BaseTest):
json_dict: dict json_dict: dict
# path with no valid API hook for db_type in list(filter(lambda item: item != "none", sharing.INTERNAL_TYPES)):
for path in ["/.sharing/", "/.sharing/v9/"]: logging.info("\n*** test: %s", db_type)
_, headers, _ = self.request("POST", path, check=404, login="owner:ownerpw") self.configure({"sharing": {"type": db_type}})
# path with valid API but no hook for path in ["/.sharing/", "/.sharing/v9/"]:
for path in ["/.sharing/v1/"]: logging.info("\n*** check invalid API URI: %r", path)
_, headers, _ = self.request("POST", path, check=404, login="owner:ownerpw") _, headers, _ = self.request("POST", path, check=404, login="owner:ownerpw")
# path with valid API and hook but not enabled "map" # path with valid API but no hook
self.configure({"sharing": { for path in ["/.sharing/v1/"]:
"collection_by_map": "False", logging.info("\n*** check valid API URI without hook: %r", path)
"collection_by_token": "True"} _, headers, _ = self.request("POST", path, check=404, login="owner:ownerpw")
})
sharetype = "map"
for action in sharing.API_HOOKS_V1:
path = "/.sharing/v1/" + sharetype + "/" + action
_, headers, _ = self.request("POST", path, check=404, login="owner:ownerpw")
# path with valid API and hook but not enabled "token" # path with valid API and hook but not enabled "map"
self.configure({"sharing": { self.configure({"sharing": {
"collection_by_map": "True", "collection_by_map": "False",
"collection_by_token": "False"} "collection_by_token": "True"}
}) })
sharetype = "token" sharetype = "map"
for action in sharing.API_HOOKS_V1: for action in sharing.API_HOOKS_V1:
path = "/.sharing/v1/" + sharetype + "/" + action path = "/.sharing/v1/" + sharetype + "/" + action
_, headers, _ = self.request("POST", path, check=404, login="owner:ownerpw") logging.info("\n*** check valid API URI hook (but not enabled): %r", path)
_, headers, _ = self.request("POST", path, check=404, login="owner:ownerpw")
# check info hook # path with valid API and hook but not enabled "token"
logging.info("\n*** check API hook: info/all") self.configure({"sharing": {
json_dict = {} "collection_by_map": "True",
_, headers, answer = self._sharing_api_json("all", "info", check=200, login="owner:ownerpw", json_dict=json_dict) "collection_by_token": "False"}
answer_dict = json.loads(answer) })
assert answer_dict['FeatureEnabledCollectionByMap'] is True sharetype = "token"
assert answer_dict['FeatureEnabledCollectionByToken'] is False for action in sharing.API_HOOKS_V1:
assert answer_dict['PermittedCreateCollectionByMap'] is True path = "/.sharing/v1/" + sharetype + "/" + action
assert answer_dict['PermittedCreateCollectionByToken'] is True logging.info("\n*** check valid API URI hook (but not enabled): %r", path)
_, headers, _ = self.request("POST", path, check=404, login="owner:ownerpw")
logging.info("\n*** check API hook: info/map") # check info hook
json_dict = {} logging.info("\n*** check API hook: info/all")
_, headers, answer = self._sharing_api_json("map", "info", check=200, login="owner:ownerpw", json_dict=json_dict) json_dict = {}
answer_dict = json.loads(answer) _, headers, answer = self._sharing_api_json("all", "info", check=200, login="owner:ownerpw", json_dict=json_dict)
assert answer_dict['FeatureEnabledCollectionByMap'] is True answer_dict = json.loads(answer)
assert 'FeatureEnabledCollectionByToken' not in answer_dict assert answer_dict['FeatureEnabledCollectionByMap'] is True
assert 'PermittedCreateCollectionByToken' not in answer_dict assert answer_dict['FeatureEnabledCollectionByToken'] is False
assert answer_dict['PermittedCreateCollectionByMap'] is True
assert answer_dict['PermittedCreateCollectionByToken'] is True
logging.info("\n*** check API hook: info/token -> 404 (not enabled)") logging.info("\n*** check API hook: info/map")
json_dict = {} json_dict = {}
_, headers, answer = self._sharing_api_json("token", "info", check=404, login="owner:ownerpw", json_dict=json_dict) _, headers, answer = self._sharing_api_json("map", "info", check=200, login="owner:ownerpw", json_dict=json_dict)
answer_dict = json.loads(answer)
assert answer_dict['FeatureEnabledCollectionByMap'] is True
assert 'FeatureEnabledCollectionByToken' not in answer_dict
assert 'PermittedCreateCollectionByToken' not in answer_dict
# path with valid API and hook and all enabled logging.info("\n*** check API hook: info/token -> 404 (not enabled)")
self.configure({"sharing": { json_dict = {}
"collection_by_map": "True", _, headers, answer = self._sharing_api_json("token", "info", check=404, login="owner:ownerpw", json_dict=json_dict)
"collection_by_token": "True"}
})
for sharetype in sharing.SHARE_TYPES:
path = "/.sharing/v1/" + sharetype + "/" + action
# invalid API
_, headers, _ = self.request("POST", path + "NA", check=404, login="owner:ownerpw")
# valid API
_, headers, _ = self.request("POST", path, check=400, login="owner:ownerpw")
logging.info("\n*** check API hook: info/token -> 200") # path with valid API and hook and all enabled
json_dict = {} self.configure({"sharing": {
_, headers, answer = self._sharing_api_json("token", "info", check=200, login="owner:ownerpw", json_dict=json_dict) "collection_by_map": "True",
answer_dict = json.loads(answer) "collection_by_token": "True"}
assert answer_dict['FeatureEnabledCollectionByToken'] is True })
assert 'FeatureEnabledCollectionByMap' not in answer_dict for sharetype in sharing.SHARE_TYPES:
assert 'PermittedCreateCollectionByMap' not in answer_dict path = "/.sharing/v1/" + sharetype + "/" + action
# invalid API
_, headers, _ = self.request("POST", path + "NA", check=404, login="owner:ownerpw")
# valid API
_, headers, _ = self.request("POST", path, check=400, login="owner:ownerpw")
logging.info("\n*** check API hook: info/token -> 200")
json_dict = {}
_, headers, answer = self._sharing_api_json("token", "info", check=200, login="owner:ownerpw", json_dict=json_dict)
answer_dict = json.loads(answer)
assert answer_dict['FeatureEnabledCollectionByToken'] is True
assert 'FeatureEnabledCollectionByMap' not in answer_dict
assert 'PermittedCreateCollectionByMap' not in answer_dict
def test_sharing_api_list_with_auth(self) -> None: def test_sharing_api_list_with_auth(self) -> None:
"""POST/list with authentication.""" """POST/list with authentication."""