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);
}
}
Aggregations