Skip to content

Commit

Permalink
CBL-6495: Fix missing roles when pushing tasks in test-fest tests (#101)
Browse files Browse the repository at this point in the history
* Problem: The contributor role required by the task in the tasks' sync function is assigned to the user when the list is pushed in lists' sync function. However, the list doc and its task docs are pushed independenly and there is no order guaranteed that the list will be pushed first. As a result, if the task doc is pushed first,  the task doc will be rejected by the sync function as the contributor for the user is missing.

* Instead of using sync function to assign the contributor role to the user, assign the required roles to the users using SG REST API at the beginning of the test where the roles are being created now.

* Sync test and test spec
  • Loading branch information
pasin authored Nov 25, 2024
1 parent 5ded51b commit 7ea0db5
Show file tree
Hide file tree
Showing 5 changed files with 280 additions and 199 deletions.
3 changes: 3 additions & 0 deletions client/src/cbltest/api/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def _wait_for_all_indexed_removed(self, bucket: str) -> None:
async def create_role(self, db_name: str, role: str, collection_access: dict) -> None:
await self.__sync_gateway.add_role(db_name, role, collection_access)

async def assign_roles(self, db_name: str, name: str, roles: List[str]) -> None:
await self.__sync_gateway.assign_roles(db_name, name, roles)

async def configure_dataset(self, dataset_path: Path, dataset_name: str,
sg_config_options: Optional[List[str]] = None) -> None:
"""
Expand Down
12 changes: 12 additions & 0 deletions client/src/cbltest/api/syncgateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,18 @@ async def add_role(self, db_name: str, role: str, collection_access: dict) -> No
else:
raise

async def assign_roles(self, db_name: str, name: str, roles: List[str]) -> None:
"""
Assign the roles to a user.
:param db_name: The name of the Database.
:param name: The username to assign the roles to.
:param roles: A list of roles to be assigned.
"""
with self.__tracer.start_as_current_span("assign_role", attributes={"cbl.user.name": name}):
body = { "admin_roles": roles }
await self._send_request("put", f"/{db_name}/_user/{name}", JSONDictionary(body))

def _analyze_dataset_response(self, response: list) -> None:
assert isinstance(response, list), "Invalid bulk docs response (not a list)"
typed_response = cast(list, response)
Expand Down
2 changes: 1 addition & 1 deletion dataset/sg/todo-sg-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"_default": {
"collections": {
"lists": {
"sync": "function foo(doc,oldDoc,meta){var owner=doc._deleted?oldDoc.owner:doc.owner;requireUser(owner);var listChannel='lists.'+owner+'.'+doc._id;var contributorRole='role:'+listChannel+'.contributor';role(owner,contributorRole);access(contributorRole,listChannel);channel(listChannel)}"
"sync": "function foo(doc,oldDoc,meta){var owner=doc._deleted?oldDoc.owner:doc.owner;requireUser(owner);var listChannel='lists.'+owner+'.'+doc._id;var contributorRoleName=listChannel+'.contributor';var contributorRole='role:'+contributorRoleName;requireRole(contributorRoleName);access(contributorRole,listChannel);channel(listChannel)}"
},
"tasks": {
"sync": "function foo(doc,oldDoc,meta){var listId=doc._deleted?oldDoc.taskList.id:doc.taskList.id;var listOwner=doc._deleted?oldDoc.taskList.owner:doc.taskList.owner;var listChannel='lists.'+listOwner+'.'+listId;var contributorRoleName=listChannel+'.contributor';var contributorRole='role:'+contributorRoleName;requireRole(contributorRoleName);var tasksChannel=listChannel+'.tasks';access(contributorRole,tasksChannel);channel(tasksChannel)}"
Expand Down
Loading

0 comments on commit 7ea0db5

Please sign in to comment.