Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACAS-699: Tests for restricting /api/experiments/protocolCodename/:code by project acls #138

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions tests/test_acasclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -1376,18 +1376,46 @@ def test_015_get_protocols_by_label(self, experiment):
@requires_basic_experiment_load
def test_016_get_experiments_by_protocol_code(self, experiment):
"""Test get experiments by protocol code."""
protocols = self.client.get_protocols_by_label("Test Protocol")
experiments = self.client.\
get_experiments_by_protocol_code(protocols[0]["codeName"])
get_experiments_by_protocol_code(experiment["protocol"]["codeName"])
self.assertGreater(len(experiments), 0)
# Filter experiments and get the one matching our codeName
experiments = [e for e in experiments if e['codeName'] == experiment['codeName']]
self.assertEqual(len(experiments), 1)
self.assertIn('codeName', experiments[0])
self.assertIn('lsLabels', experiments[0])

self.assertEqual(experiments[0]["lsLabels"][0]["labelText"],
"Test Experiment")
experiment["lsLabels"][0]["labelText"])
brianbolt marked this conversation as resolved.
Show resolved Hide resolved
experiments = self.client.\
get_experiments_by_protocol_code("FAKECODE")
self.assertIsNone(experiments)

# Verify project restrictions work
brianbolt marked this conversation as resolved.
Show resolved Hide resolved
# Create a restricted project
project = self.create_basic_project_with_roles()

# Load an experiment to the newly created restricted project using the global project lots
file_to_upload = get_basic_experiment_load_file(self.tempdir, project.names[PROJECT_NAME])
response = self.client.\
experiment_loader(file_to_upload, "bob", False)
restricted_experiment_code_name = response['results']['experimentCode']

# Verify admin user can see the experiment
restricted_experiment = self.client.get_experiment_by_code(restricted_experiment_code_name)
experiments = self.client.\
get_experiments_by_protocol_code(restricted_experiment['protocol']['codeName'])
found_restricted_experiments = [e for e in experiments if e['codeName'] == restricted_experiment_code_name]
self.assertEqual(len(found_restricted_experiments), 1)

# Create an acas user with no access to the project
user_client = self.create_and_connect_backdoor_user(acas_user=True, acas_admin=False, creg_user=False, creg_admin=False)

# Fetch experiments from the prtocol code and verify the user cannot see the experiment
experiments = user_client.get_experiments_by_protocol_code(restricted_experiment['protocol']['codeName'])
found_restricted_experiments = [e for e in experiments if e['codeName'] == restricted_experiment_code_name]
self.assertEqual(len(found_restricted_experiments), 0)

@requires_basic_experiment_load
def test_017_get_experiment_by_code(self, experiment):
"""Test get experiment by code."""
Expand Down