Search in sources :

Example 1 with GetAccountResponse

use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetAccountResponse in project cloudbreak by hortonworks.

the class MockUserManagementServiceTest method getAccountTestIncludesFixedEntitlements.

@Test
void getAccountTestIncludesFixedEntitlements() {
    ReflectionTestUtils.setField(underTest, "cbLicense", VALID_LICENSE);
    underTest.initializeWorkloadPasswordPolicy();
    GetAccountRequest req = GetAccountRequest.getDefaultInstance();
    StreamRecorder<GetAccountResponse> observer = StreamRecorder.create();
    underTest.getAccount(req, observer);
    assertThat(observer.getValues().size()).isEqualTo(1);
    GetAccountResponse res = observer.getValues().get(0);
    assertThat(res.hasAccount()).isTrue();
    Account account = res.getAccount();
    List<String> entitlements = account.getEntitlementsList().stream().map(Entitlement::getEntitlementName).collect(Collectors.toList());
    assertThat(entitlements).contains("CDP_AZURE", "CDP_GCP", "CDP_AUTOMATIC_USERSYNC_POLLER", "CLOUDERA_INTERNAL_ACCOUNT", "DATAHUB_AZURE_AUTOSCALING", "DATAHUB_AWS_AUTOSCALING", "DATAHUB_GCP_AUTOSCALING", "LOCAL_DEV", "DATAHUB_FLOW_SCALING", "DATAHUB_STREAMING_SCALING", "CDP_CM_ADMIN_CREDENTIALS");
}
Also used : GetAccountResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetAccountResponse) Account(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Account) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) GetAccountRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetAccountRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with GetAccountResponse

use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetAccountResponse in project cloudbreak by hortonworks.

the class MockUserManagementServiceTest method getAccountTestIncludesConditionalEntitlement.

@ParameterizedTest(name = "{0}")
@MethodSource("conditionalEntitlementDataProvider")
void getAccountTestIncludesConditionalEntitlement(String testCaseName, String conditionFieldName, boolean condition, String entitlementName, boolean entitlementPresentExpected) {
    ReflectionTestUtils.setField(underTest, "cbLicense", VALID_LICENSE);
    underTest.initializeWorkloadPasswordPolicy();
    ReflectionTestUtils.setField(underTest, conditionFieldName, condition);
    GetAccountRequest req = GetAccountRequest.getDefaultInstance();
    StreamRecorder<GetAccountResponse> observer = StreamRecorder.create();
    underTest.getAccount(req, observer);
    assertThat(observer.getValues().size()).isEqualTo(1);
    GetAccountResponse res = observer.getValues().get(0);
    assertThat(res.hasAccount()).isTrue();
    Account account = res.getAccount();
    List<String> entitlements = account.getEntitlementsList().stream().map(Entitlement::getEntitlementName).collect(Collectors.toList());
    if (entitlementPresentExpected) {
        assertThat(entitlements).contains(entitlementName);
    } else {
        assertThat(entitlements).doesNotContain(entitlementName);
    }
}
Also used : GetAccountResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetAccountResponse) Account(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Account) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) GetAccountRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetAccountRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with GetAccountResponse

use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetAccountResponse in project cloudbreak by hortonworks.

the class MockUserManagementServiceTest method testGetAccountIncludesPasswordPolicy.

@Test
public void testGetAccountIncludesPasswordPolicy() throws IOException {
    Path licenseFilePath = Files.createTempFile("license", "txt");
    Files.writeString(licenseFilePath, VALID_LICENSE);
    ReflectionTestUtils.setField(underTest, "cmLicenseFilePath", licenseFilePath.toString());
    try {
        underTest.init();
        GetAccountRequest req = GetAccountRequest.getDefaultInstance();
        StreamRecorder<GetAccountResponse> observer = StreamRecorder.create();
        underTest.getAccount(req, observer);
        assertThat(observer.getValues().size()).isEqualTo(1);
        GetAccountResponse res = observer.getValues().get(0);
        assertThat(res.hasAccount()).isTrue();
        Account account = res.getAccount();
        assertThat(account.hasGlobalPasswordPolicy()).isTrue();
        WorkloadPasswordPolicy passwordPolicy = account.getGlobalPasswordPolicy();
        assertThat(passwordPolicy.getWorkloadPasswordMaxLifetime()).isEqualTo(MockUserManagementService.PASSWORD_LIFETIME);
    } finally {
        Files.delete(licenseFilePath);
    }
}
Also used : Path(java.nio.file.Path) GetAccountResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetAccountResponse) Account(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Account) WorkloadPasswordPolicy(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.WorkloadPasswordPolicy) GetAccountRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetAccountRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with GetAccountResponse

use of com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetAccountResponse in project cloudbreak by hortonworks.

the class MockUserManagementServiceTest method getAccountTestIncludesIds.

@Test
void getAccountTestIncludesIds() {
    ReflectionTestUtils.setField(underTest, "cbLicense", VALID_LICENSE);
    underTest.initializeWorkloadPasswordPolicy();
    GetAccountRequest req = GetAccountRequest.newBuilder().setAccountId(ACCOUNT_ID).build();
    StreamRecorder<GetAccountResponse> observer = StreamRecorder.create();
    underTest.getAccount(req, observer);
    assertThat(observer.getValues().size()).isEqualTo(1);
    GetAccountResponse res = observer.getValues().get(0);
    assertThat(res.hasAccount()).isTrue();
    Account account = res.getAccount();
    assertThat(account.getAccountId()).isEqualTo(ACCOUNT_ID);
    assertThat(account.getExternalAccountId()).isEqualTo("external-" + ACCOUNT_ID);
}
Also used : GetAccountResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetAccountResponse) Account(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Account) GetAccountRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetAccountRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Account (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Account)4 GetAccountRequest (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetAccountRequest)4 GetAccountResponse (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetAccountResponse)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 Test (org.junit.jupiter.api.Test)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 WorkloadPasswordPolicy (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.WorkloadPasswordPolicy)1 Path (java.nio.file.Path)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1