Skip to content

Commit

Permalink
Fixing test case to check empty permission and fixing config regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazim-crim committed Nov 28, 2023
1 parent 3357504 commit f1d8e94
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions config/config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ sync_permissions:
- "process_job_status : read -> job_status : read"
# different permission (match), otherwise all jobs/outputs become available.
- "process_job_status : read -> process_description : read-match"
stac_permissions:
stac_permissions:
services:
api:
stac_collection:
Expand Down Expand Up @@ -216,8 +216,8 @@ stac_permissions:
- name: thredds
type: service
- type: directory
regex: '(?<=:)[\w\/]+' # Match everything after ":" but before last "/" (ex: thredds:birdhouse/testdata/xclim/cmip6 will match to : birdhouse/testdata/xclim/cmip6)
# It would be equivalent as matching any number of directory using "**"
regex: '(?<=:)[\w\/]+' # Match everything after ":" but before last "/" (ex: thredds:birdhouse/testdata/xclim/cmip6/sic_SImon_CCCma-CanESM5_ssp245_r13i1p2f1_2020.nc
# will match to : birdhouse/testdata/xclim/cmip6). It would be equivalent as matching any number of directory using "**".
thredd_item:
- name: thredds
type: service
Expand Down
21 changes: 14 additions & 7 deletions tests/test_permissions_synchronizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ def test_webhooks_valid_regex(self):
"Thredds_file_src": [
{"name": self.test_service_name, "type": Service.resource_type_name},
{"name": "private", "type": Directory.resource_type_name},
{"name": "directory1", "type": Directory.resource_type_name},
{"name": "directory", "type": Directory.resource_type_name},
{"field": "resource_display_name",
"regex": r"[\w]+:[\w\/.-]+",
"type": File.resource_type_name}],
Expand Down Expand Up @@ -713,11 +713,12 @@ def test_webhooks_valid_regex(self):
side_effect=utils.MockAnyHandler))

# Create test resources
dir_src_res_id = self.magpie.create_resource("private", Directory.resource_type_name, self.test_service_id)
parent_res_id = self.magpie.create_resource("directory", Directory.resource_type_name, dir_src_res_id,
private_src_res_id = self.magpie.create_resource("private", Directory.resource_type_name,
self.test_service_id)
parent_res_id = self.magpie.create_resource("directory", Directory.resource_type_name, private_src_res_id,
f"{self.test_service_name}:directory")
dir1_src_res_id = parent_res_id
file_src_res_id = self.magpie.create_resource("workspace_file.nc", File.resource_type_name, parent_res_id,
dir_src_res_id = parent_res_id
file_src_res_id = self.magpie.create_resource("file.nc", File.resource_type_name, parent_res_id,
f"{self.test_service_name}:directory/file.nc")

parent_res_id = self.magpie.create_resource("directory", Directory.resource_type_name, self.test_service_id)
Expand All @@ -729,7 +730,7 @@ def test_webhooks_valid_regex(self):
"event": ValidOperations.CreateOperation.value,
"service_name": None,
"service_type": ServiceTHREDDS.service_type,
"resource_id": dir1_src_res_id,
"resource_id": dir_src_res_id,
"resource_full_name": f"/{self.test_service_name}/private/directory",
"resource_display_name": f"{self.test_service_name}:directory",
"name": Permission.READ.value,
Expand All @@ -738,6 +739,9 @@ def test_webhooks_valid_regex(self):
"user": self.usr,
"group": None
}
# Check permission are initialy empty
self.check_user_permissions(dir_target_res_id, [])

resp = utils.test_request(app, "POST", "/webhooks/permissions", json=data)
utils.check_response_basic_info(resp, 200, expected_method="POST")

Expand All @@ -751,7 +755,10 @@ def test_webhooks_valid_regex(self):
data["resource_full_name"] = f"/{self.test_service_name}/private/directory/file.nc"
data["resource_display_name_name"] = f"{self.test_service_name}:directory/file.nc"

# check permissions with first mapping case
# Check permission are initialy empty before 2nd mapping case
self.check_user_permissions(file_target_res_id, [])

# check permissions with 2nd mapping case
resp = utils.test_request(app, "POST", "/webhooks/permissions", json=data)
utils.check_response_basic_info(resp, 200, expected_method="POST")
self.check_user_permissions(file_target_res_id,
Expand Down

0 comments on commit f1d8e94

Please sign in to comment.