use of bio.terra.testrunner.runner.config.TestUserSpecification in project terra-workspace-manager by DataBiosphere.
the class EnumerateResources method doSetup.
@Override
public void doSetup(List<TestUserSpecification> testUsers, WorkspaceApi workspaceApi) throws Exception {
// initialize workspace
super.doSetup(testUsers, workspaceApi);
assertThat("There must be two test users defined for this test.", testUsers != null && testUsers.size() == 2);
TestUserSpecification workspaceOwner = testUsers.get(0);
workspaceReader = testUsers.get(1);
// static assumptions
assertThat(PAGE_SIZE * 2, lessThan(RESOURCE_COUNT));
assertThat(PAGE_SIZE * 3, greaterThan(RESOURCE_COUNT));
ApiClient ownerApiClient = ClientTestUtils.getClientForTestUser(workspaceOwner, server);
ownerControlledGcpResourceApi = new ControlledGcpResourceApi(ownerApiClient);
ownerReferencedGcpResourceApi = new ReferencedGcpResourceApi(ownerApiClient);
ownerResourceApi = new ResourceApi(ownerApiClient);
ApiClient readerApiClient = ClientTestUtils.getClientForTestUser(workspaceReader, server);
readerResourceApi = new ResourceApi(readerApiClient);
// Create a cloud context for the workspace
CloudContextMaker.createGcpCloudContext(getWorkspaceId(), workspaceApi);
// create the resources for the test
logger.info("Creating {} resources", RESOURCE_COUNT);
resourceList = MultiResourcesUtils.makeResources(ownerReferencedGcpResourceApi, ownerControlledGcpResourceApi, getWorkspaceId());
logger.info("Created {} resources", resourceList.size());
}
use of bio.terra.testrunner.runner.config.TestUserSpecification in project terra-workspace-manager by DataBiosphere.
the class EnumerateJobs method doSetup.
@Override
public void doSetup(List<TestUserSpecification> testUsers, WorkspaceApi workspaceApi) throws Exception {
// initialize workspace
super.doSetup(testUsers, workspaceApi);
TestUserSpecification workspaceOwner = testUsers.get(0);
// If we like the alpha1 API for job enumeration, then we can maybe piggyback on
// the EnumerateResources test instead of creating our own set.
ApiClient ownerApiClient = ClientTestUtils.getClientForTestUser(workspaceOwner, server);
ownerControlledGcpResourceApi = new ControlledGcpResourceApi(ownerApiClient);
ownerReferencedGcpResourceApi = new ReferencedGcpResourceApi(ownerApiClient);
alpha1Api = new Alpha1Api(ownerApiClient);
// Create a cloud context for the workspace
CloudContextMaker.createGcpCloudContext(getWorkspaceId(), workspaceApi);
// create the resources for the test
logger.info("Creating {} resources", RESOURCE_COUNT);
resourceList = MultiResourcesUtils.makeResources(ownerReferencedGcpResourceApi, ownerControlledGcpResourceApi, getWorkspaceId());
logger.info("Created {} resources", resourceList.size());
logger.info("Cleaning up {} resources", resourceList.size());
MultiResourcesUtils.cleanupResources(resourceList, ownerControlledGcpResourceApi, getWorkspaceId());
logger.info("Cleaned up {} resources", resourceList.size());
}
use of bio.terra.testrunner.runner.config.TestUserSpecification in project terra-workspace-manager by DataBiosphere.
the class GetRoles method doSetup.
@Override
public void doSetup(List<TestUserSpecification> testUsers, WorkspaceApi workspaceApi) throws Exception {
super.doSetup(testUsers, workspaceApi);
for (TestUserSpecification testUser : testUsers) {
logger.info("Granting role {} for user {} on workspace id {}", IAM_ROLE.toString(), testUser.userEmail, getWorkspaceId().toString());
final var body = new GrantRoleRequestBody().memberEmail(testUser.userEmail);
// grant the role
workspaceApi.grantRole(body, getWorkspaceId(), IAM_ROLE);
}
}
use of bio.terra.testrunner.runner.config.TestUserSpecification in project terra-workspace-manager by DataBiosphere.
the class RemoveUser method doSetup.
@Override
protected void doSetup(List<TestUserSpecification> testUsers, WorkspaceApi ownerWorkspaceApi) throws Exception {
super.doSetup(testUsers, ownerWorkspaceApi);
assertThat("There must be at least three test users defined for this test.", testUsers != null && testUsers.size() > 2);
TestUserSpecification workspaceOwner = testUsers.get(0);
this.privateResourceUser = testUsers.get(1);
this.sharedResourceUser = testUsers.get(2);
assertNotEquals(privateResourceUser.userEmail, sharedResourceUser.userEmail, "The two test users are distinct");
// Add one user as a reader, and one as both a reader and writer.
ownerWorkspaceApi.grantRole(new GrantRoleRequestBody().memberEmail(privateResourceUser.userEmail), getWorkspaceId(), IamRole.READER);
ownerWorkspaceApi.grantRole(new GrantRoleRequestBody().memberEmail(privateResourceUser.userEmail), getWorkspaceId(), IamRole.WRITER);
ownerWorkspaceApi.grantRole(new GrantRoleRequestBody().memberEmail(sharedResourceUser.userEmail), getWorkspaceId(), IamRole.WRITER);
// Create a GCP cloud context.
projectId = CloudContextMaker.createGcpCloudContext(getWorkspaceId(), ownerWorkspaceApi);
// Create a shared GCS bucket with one object inside.
ControlledGcpResourceApi ownerResourceApi = ClientTestUtils.getControlledGcpResourceClient(workspaceOwner, server);
String sharedBucketName = BUCKET_PREFIX + UUID.randomUUID();
sharedBucket = makeControlledGcsBucketUserShared(ownerResourceApi, getWorkspaceId(), sharedBucketName, CloningInstructionsEnum.NOTHING);
GcsBucketUtils.addFileToBucket(sharedBucket, workspaceOwner, projectId);
// Create a private GCS bucket for privateResourceUser with one object inside.
String privateBucketName = BUCKET_PREFIX + UUID.randomUUID();
ControlledGcpResourceApi privateUserResourceApi = ClientTestUtils.getControlledGcpResourceClient(privateResourceUser, server);
privateBucket = makeControlledGcsBucketUserPrivate(privateUserResourceApi, getWorkspaceId(), privateBucketName, CloningInstructionsEnum.NOTHING);
GcsBucketUtils.addFileToBucket(privateBucket, privateResourceUser, projectId);
// Create a private BQ dataset for privateResourceUser and populate it.
String datasetResourceName = RandomStringUtils.randomAlphabetic(8).toLowerCase();
privateDataset = BqDatasetUtils.makeControlledBigQueryDatasetUserPrivate(privateUserResourceApi, getWorkspaceId(), datasetResourceName, null, CloningInstructionsEnum.NOTHING);
BqDatasetUtils.populateBigQueryDataset(privateDataset, privateResourceUser, projectId);
// Create a private notebook for privateResourceUser.
String notebookInstanceId = RandomStringUtils.randomAlphabetic(8).toLowerCase();
privateNotebook = NotebookUtils.makeControlledNotebookUserPrivate(getWorkspaceId(), notebookInstanceId, /*location=*/
null, privateUserResourceApi);
}
use of bio.terra.testrunner.runner.config.TestUserSpecification in project terra-workspace-manager by DataBiosphere.
the class EnumerateResources method doUserJourney.
@Override
public void doUserJourney(TestUserSpecification testUser, WorkspaceApi workspaceApi) throws Exception {
// Add second user to the workspace as a reader
workspaceApi.grantRole(new GrantRoleRequestBody().memberEmail(workspaceReader.userEmail), getWorkspaceId(), IamRole.READER);
// Case 1: fetch all
ResourceList enumList = ownerResourceApi.enumerateResources(getWorkspaceId(), 0, RESOURCE_COUNT, null, null);
logResult("fetchall", enumList);
// Make sure we got all of the expected ids
matchFullResourceList(enumList.getResources());
// Repeat case 1 as the workspace reader.
// As this is the first operation after modifying workspace IAM groups, retry here to compensate
// for the delay in GCP IAM propagation.
ResourceList readerEnumList = ClientTestUtils.getWithRetryOnException(() -> readerResourceApi.enumerateResources(getWorkspaceId(), 0, RESOURCE_COUNT, null, null));
logResult("fetchall reader", readerEnumList);
matchFullResourceList(readerEnumList.getResources());
// Case 2: fetch by pages
ResourceList page1List = ownerResourceApi.enumerateResources(getWorkspaceId(), 0, PAGE_SIZE, null, null);
logResult("page1", page1List);
assertThat(page1List.getResources().size(), equalTo(PAGE_SIZE));
ResourceList page2List = ownerResourceApi.enumerateResources(getWorkspaceId(), PAGE_SIZE, PAGE_SIZE, null, null);
logResult("page2", page2List);
assertThat(page2List.getResources().size(), equalTo(PAGE_SIZE));
ResourceList page3List = ownerResourceApi.enumerateResources(getWorkspaceId(), 2 * PAGE_SIZE, PAGE_SIZE, null, null);
logResult("page3", page3List);
assertThat(page3List.getResources().size(), lessThan(PAGE_SIZE));
List<ResourceDescription> descriptionList = new ArrayList<>();
descriptionList.addAll(page1List.getResources());
descriptionList.addAll(page2List.getResources());
descriptionList.addAll(page3List.getResources());
matchFullResourceList(descriptionList);
// Case 3: no results if offset is too high
ResourceList enumEmptyList = ownerResourceApi.enumerateResources(getWorkspaceId(), 10 * PAGE_SIZE, PAGE_SIZE, null, null);
assertThat(enumEmptyList.getResources().size(), equalTo(0));
// Case 4: filter by resource type
ResourceList buckets = ownerResourceApi.enumerateResources(getWorkspaceId(), 0, RESOURCE_COUNT, ResourceType.GCS_BUCKET, null);
logResult("buckets", buckets);
long expectedBuckets = resourceList.stream().filter(m -> m.getResourceType() == ResourceType.GCS_BUCKET).count();
logger.info("Counted {} buckets created", expectedBuckets);
// Note - assertThat exits out on an int -> long compare, so just don't do that.
long actualBuckets = buckets.getResources().size();
assertThat(actualBuckets, equalTo(expectedBuckets));
// Case 5: filter by stewardship type
ResourceList referencedList = ownerResourceApi.enumerateResources(getWorkspaceId(), 0, RESOURCE_COUNT, null, StewardshipType.REFERENCED);
logResult("referenced", referencedList);
long expectedReferenced = resourceList.stream().filter(m -> m.getStewardshipType() == StewardshipType.REFERENCED).count();
logger.info("Counted {} referenced created", expectedReferenced);
long actualReferenced = referencedList.getResources().size();
assertThat(actualReferenced, equalTo(expectedReferenced));
// Case 6: filter by resource and stewardship
ResourceList controlledBucketList = ownerResourceApi.enumerateResources(getWorkspaceId(), 0, RESOURCE_COUNT, ResourceType.GCS_BUCKET, StewardshipType.CONTROLLED);
logResult("controlledBucket", controlledBucketList);
long expectedControlledBuckets = resourceList.stream().filter(m -> (m.getStewardshipType() == StewardshipType.CONTROLLED && m.getResourceType() == ResourceType.GCS_BUCKET)).count();
logger.info("Counted {} controlled buckets created", expectedControlledBuckets);
long actualControlledBuckets = controlledBucketList.getResources().size();
assertThat(actualControlledBuckets, equalTo(expectedControlledBuckets));
// Case 7: validate error on invalid pagination params
ApiException invalidPaginationException = assertThrows(ApiException.class, () -> ownerResourceApi.enumerateResources(getWorkspaceId(), -11, 2, ResourceType.GCS_BUCKET, StewardshipType.CONTROLLED));
assertThat(invalidPaginationException.getMessage(), containsString("Invalid pagination"));
invalidPaginationException = assertThrows(ApiException.class, () -> ownerResourceApi.enumerateResources(getWorkspaceId(), 0, 0, ResourceType.GCS_BUCKET, StewardshipType.CONTROLLED));
assertThat(invalidPaginationException.getMessage(), containsString("Invalid pagination"));
}
Aggregations