use of bio.terra.workspace.service.iam.AuthenticatedUserRequest in project terra-workspace-manager by DataBiosphere.
the class CreateGcpContextFlightV2Test method successCreatesProjectAndContext.
@Test
@DisabledIfEnvironmentVariable(named = "TEST_ENV", matches = BUFFER_SERVICE_DISABLED_ENVS_REG_EX)
void successCreatesProjectAndContext() throws Exception {
UUID workspaceId = createWorkspace(spendUtils.defaultSpendId());
AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest();
assertTrue(testUtils.getAuthorizedGcpCloudContext(workspaceId, userRequest).isEmpty());
// Retry steps once to validate idempotency.
Map<String, StepStatus> retrySteps = getStepNameToStepStatusMap();
FlightDebugInfo debugInfo = FlightDebugInfo.newBuilder().doStepFailures(retrySteps).build();
FlightState flightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), CreateGcpContextFlightV2.class, createInputParameters(workspaceId, userRequest), STAIRWAY_FLIGHT_TIMEOUT, debugInfo);
assertEquals(FlightStatus.SUCCESS, flightState.getFlightStatus());
String projectId = flightState.getResultMap().get().get(WorkspaceFlightMapKeys.GCP_PROJECT_ID, String.class);
assertTrue(testUtils.getAuthorizedGcpCloudContext(workspaceId, userRequest).isPresent());
String contextProjectId = workspaceService.getAuthorizedRequiredGcpProject(workspaceId, userRequest);
assertEquals(projectId, contextProjectId);
// Verify that the policies were properly stored
Optional<GcpCloudContext> optionalCloudContext = testUtils.getAuthorizedGcpCloudContext(workspaceId, userRequest);
assertTrue(optionalCloudContext.isPresent(), "has cloud context");
GcpCloudContext cloudContext = optionalCloudContext.get();
assertTrue(cloudContext.getSamPolicyOwner().isPresent(), "has owner policy");
assertTrue(cloudContext.getSamPolicyWriter().isPresent(), "has writer policy");
assertTrue(cloudContext.getSamPolicyReader().isPresent(), "has reader policy");
assertTrue(cloudContext.getSamPolicyApplication().isPresent(), "has application policy");
Project project = crl.getCloudResourceManagerCow().projects().get(projectId).execute();
assertEquals(projectId, project.getProjectId());
assertEquals("billingAccounts/" + spendUtils.defaultBillingAccountId(), crl.getCloudBillingClientCow().getProjectBillingInfo("projects/" + projectId).getBillingAccountName());
assertRolesExist(project);
assertPolicyGroupsSynced(workspaceId, project);
}
use of bio.terra.workspace.service.iam.AuthenticatedUserRequest in project terra-workspace-manager by DataBiosphere.
the class CreateGcpContextFlightV2Test method createsProjectAndContext_noBillingAccount_flightFailsAndGcpProjectNotCreated.
@Test
@DisabledIfEnvironmentVariable(named = "TEST_ENV", matches = BUFFER_SERVICE_DISABLED_ENVS_REG_EX)
void createsProjectAndContext_noBillingAccount_flightFailsAndGcpProjectNotCreated() throws Exception {
UUID workspaceId = createWorkspace(spendUtils.noBillingAccount());
AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest();
assertTrue(testUtils.getAuthorizedGcpCloudContext(workspaceId, userRequest).isEmpty());
FlightState flightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), CreateGcpContextFlightV2.class, createInputParameters(workspaceId, userRequest), STAIRWAY_FLIGHT_TIMEOUT, FlightDebugInfo.newBuilder().build());
assertEquals(FlightStatus.ERROR, flightState.getFlightStatus());
assertEquals(NoBillingAccountException.class, flightState.getException().get().getClass());
assertTrue(testUtils.getAuthorizedGcpCloudContext(workspaceId, userRequest).isEmpty());
assertFalse(flightState.getResultMap().get().containsKey(WorkspaceFlightMapKeys.GCP_PROJECT_ID));
}
use of bio.terra.workspace.service.iam.AuthenticatedUserRequest in project terra-workspace-manager by DataBiosphere.
the class CreateGcpContextFlightV2Test method errorRevertsChanges.
@Test
@DisabledIfEnvironmentVariable(named = "TEST_ENV", matches = BUFFER_SERVICE_DISABLED_ENVS_REG_EX)
void errorRevertsChanges() throws Exception {
UUID workspaceId = createWorkspace(spendUtils.defaultSpendId());
AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest();
assertTrue(testUtils.getAuthorizedGcpCloudContext(workspaceId, userRequest).isEmpty());
// Submit a flight class that always errors.
Map<String, StepStatus> retrySteps = getStepNameToStepStatusMap();
FlightDebugInfo debugInfo = FlightDebugInfo.newBuilder().undoStepFailures(retrySteps).lastStepFailure(true).build();
FlightState flightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), CreateGcpContextFlightV2.class, createInputParameters(workspaceId, userRequest), STAIRWAY_FLIGHT_TIMEOUT, debugInfo);
assertEquals(FlightStatus.ERROR, flightState.getFlightStatus());
assertTrue(testUtils.getAuthorizedGcpCloudContext(workspaceId, userRequest).isEmpty());
String projectId = flightState.getResultMap().get().get(WorkspaceFlightMapKeys.GCP_PROJECT_ID, String.class);
// The Project should exist, but requested to be deleted.
Project project = crl.getCloudResourceManagerCow().projects().get(projectId).execute();
assertEquals(projectId, project.getProjectId());
assertEquals("DELETE_REQUESTED", project.getState());
}
use of bio.terra.workspace.service.iam.AuthenticatedUserRequest in project terra-workspace-manager by DataBiosphere.
the class CreateAzureContextFlightTest method errorRevertsChanges.
@Test
void errorRevertsChanges() throws Exception {
UUID workspaceId = azureTestUtils.createWorkspace(workspaceService);
AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest();
// There should be no cloud context initially.
assertTrue(workspaceService.getAuthorizedAzureCloudContext(workspaceId, userRequest).isEmpty());
// Submit a flight class that always errors.
FlightDebugInfo debugInfo = FlightDebugInfo.newBuilder().lastStepFailure(true).build();
FlightState flightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), CreateAzureContextFlight.class, azureTestUtils.createAzureContextInputParameters(workspaceId, userRequest), STAIRWAY_FLIGHT_TIMEOUT, debugInfo);
assertEquals(FlightStatus.ERROR, flightState.getFlightStatus());
// There should be no cloud context created.
assertTrue(workspaceService.getAuthorizedAzureCloudContext(workspaceId, userRequest).isEmpty());
}
use of bio.terra.workspace.service.iam.AuthenticatedUserRequest in project terra-workspace-manager by DataBiosphere.
the class CreateGcpContextFlightTest method createsProjectAndContext_emptySpendProfile_flightFailsAndGcpProjectNotCreated.
@Test
@DisabledIfEnvironmentVariable(named = "TEST_ENV", matches = BUFFER_SERVICE_DISABLED_ENVS_REG_EX)
void createsProjectAndContext_emptySpendProfile_flightFailsAndGcpProjectNotCreated() throws Exception {
UUID workspaceId = createWorkspace(null);
AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest();
assertTrue(testUtils.getAuthorizedGcpCloudContext(workspaceId, userRequest).isEmpty());
FlightState flightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), CreateGcpContextFlight.class, createInputParameters(workspaceId, userRequest), STAIRWAY_FLIGHT_TIMEOUT, FlightDebugInfo.newBuilder().build());
assertEquals(FlightStatus.ERROR, flightState.getFlightStatus());
assertEquals(MissingSpendProfileException.class, flightState.getException().get().getClass());
assertTrue(testUtils.getAuthorizedGcpCloudContext(workspaceId, userRequest).isEmpty());
assertFalse(flightState.getResultMap().get().containsKey(WorkspaceFlightMapKeys.GCP_PROJECT_ID));
}
Aggregations