Search in sources :

Example 1 with GetActorWorkloadCredentialsRequest

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

the class MockUserManagementServiceTest method testGetWorkloadCredentials.

@Test
public void testGetWorkloadCredentials() throws IOException {
    Path sshPublicKeyFilePath = Files.createTempFile("key", ".pub");
    Files.writeString(sshPublicKeyFilePath, SAMPLE_SSH_PUBLIC_KEY);
    ReflectionTestUtils.setField(underTest, "sshPublicKeyFilePath", sshPublicKeyFilePath.toString());
    try {
        underTest.initializeActorWorkloadCredentials();
        when(mockCrnService.createCrn(anyString(), any(), anyString())).thenReturn(CrnTestUtil.getCustomCrnBuilder(CrnResourceDescriptor.PUBLIC_KEY).setResource(UUID.randomUUID().toString()).setAccountId(ACCOUNT_ID).build());
        long currentTime = System.currentTimeMillis();
        GetActorWorkloadCredentialsRequest req = GetActorWorkloadCredentialsRequest.newBuilder().setActorCrn(CrnTestUtil.getUserCrnBuilder().setAccountId(ACCOUNT_ID).setResource(UUID.randomUUID().toString()).build().toString()).build();
        StreamRecorder<GetActorWorkloadCredentialsResponse> observer = StreamRecorder.create();
        underTest.getActorWorkloadCredentials(req, observer);
        assertThat(observer.getValues().size()).isEqualTo(1);
        GetActorWorkloadCredentialsResponse res = observer.getValues().get(0);
        assertThat(res).isNotNull();
        assertThat(res.getPasswordHash()).isNotNull();
        assertThat(res.getKerberosKeysList()).isNotNull();
        assertThat(res.getKerberosKeysList().size()).isEqualTo(2);
        assertThat(res.getPasswordHashExpirationDate() > currentTime).isTrue();
        assertThat(res.getSshPublicKeyCount()).isEqualTo(1);
        assertThat(res.getSshPublicKey(0).getPublicKey()).isEqualTo(SAMPLE_SSH_PUBLIC_KEY);
    } finally {
        Files.delete(sshPublicKeyFilePath);
    }
}
Also used : Path(java.nio.file.Path) GetActorWorkloadCredentialsResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetActorWorkloadCredentialsResponse) GetActorWorkloadCredentialsRequest(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetActorWorkloadCredentialsRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

GetActorWorkloadCredentialsRequest (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetActorWorkloadCredentialsRequest)1 GetActorWorkloadCredentialsResponse (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetActorWorkloadCredentialsResponse)1 Path (java.nio.file.Path)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1