use of com.sequenceiq.cloudbreak.service.secret.model.SecretResponse in project cloudbreak by hortonworks.
the class HostKeytabServiceTest method testGenerateHostKeytabGetExisting.
@Test
public void testGenerateHostKeytabGetExisting() throws FreeIpaClientException {
HostKeytabRequest request = new HostKeytabRequest();
request.setEnvironmentCrn(ENVIRONMENT_CRN);
request.setRoleRequest(new RoleRequest());
request.setDoNotRecreateKeytab(Boolean.TRUE);
request.setServerHostName("asdf");
Stack stack = new Stack();
when(keytabCommonService.getFreeIpaStackWithMdcContext(request.getEnvironmentCrn(), ACCOUNT_ID)).thenReturn(stack);
FreeIpaClient freeIpaClient = mock(FreeIpaClient.class);
when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
when(roleComponent.privilegesExist(request.getRoleRequest(), freeIpaClient)).thenReturn(Boolean.TRUE);
Host host = new Host();
host.setHasKeytab(Boolean.TRUE);
host.setKrbprincipalname("dfdf");
when(keytabCommonService.addHost(request.getServerHostName(), request.getRoleRequest(), freeIpaClient)).thenReturn(host);
KeytabCache keytabCache = mock(KeytabCache.class);
Secret keytabSecret = new Secret("keytab", "keytabSecret");
Secret principalSecret = new Secret("principal", "principalSecret");
when(keytabCache.getKeytab()).thenReturn(keytabSecret);
when(keytabCache.getPrincipal()).thenReturn(principalSecret);
when(keytabCommonService.getExistingKeytab(request.getEnvironmentCrn(), host.getKrbprincipalname(), request.getServerHostName(), freeIpaClient)).thenReturn(keytabCache);
SecretResponse keytabResponse = new SecretResponse();
keytabResponse.setSecretPath("keytabPath");
when(secretResponseConverter.convert(keytabCache.getKeytab().getSecret())).thenReturn(keytabResponse);
SecretResponse principalResponse = new SecretResponse();
principalResponse.setSecretPath("principalPath");
when(secretResponseConverter.convert(keytabCache.getPrincipal().getSecret())).thenReturn(principalResponse);
HostKeytabResponse response = underTest.generateHostKeytab(request, ACCOUNT_ID);
assertEquals(keytabResponse, response.getKeytab());
assertEquals(principalResponse, response.getHostPrincipal());
}
use of com.sequenceiq.cloudbreak.service.secret.model.SecretResponse in project cloudbreak by hortonworks.
the class DatabaseV4ResponseTest method testGettersAndSetters.
@Test
public void testGettersAndSetters() {
response.setCrn("crn:mydb");
assertEquals("crn:mydb", response.getCrn());
response.setType("hive");
assertEquals("hive", response.getType());
long now = System.currentTimeMillis();
response.setCreationDate(now);
assertEquals(now, response.getCreationDate().longValue());
response.setDatabaseEngine("postgres");
assertEquals("postgres", response.getDatabaseEngine());
response.setConnectionDriver("postgresql.jar");
assertEquals("postgresql.jar", response.getConnectionDriver());
response.setDatabaseEngineDisplayName("PostgreSQL");
assertEquals("PostgreSQL", response.getDatabaseEngineDisplayName());
SecretResponse username = new SecretResponse("engine", "username");
response.setConnectionUserName(username);
verifyEqualSecretResponses(username, response.getConnectionUserName());
SecretResponse password = new SecretResponse("engine", "password");
response.setConnectionPassword(password);
verifyEqualSecretResponses(password, response.getConnectionPassword());
response.setResourceStatus(ResourceStatus.USER_MANAGED);
assertEquals(ResourceStatus.USER_MANAGED, response.getResourceStatus());
}
use of com.sequenceiq.cloudbreak.service.secret.model.SecretResponse in project cloudbreak by hortonworks.
the class ProxyConfigDtoServiceTest method testGetWhenProxyConfigUserPasswordEmpty.
@ParameterizedTest
@MethodSource("invalidUserPasswords")
void testGetWhenProxyConfigUserPasswordEmpty(String user, String password) {
String name = "aProxyConfig";
String host = "https://test.cloudera.com";
Integer port = 8443;
String decryptedSecretValue = "decrypted-secret-value";
SecretResponse secretResponse = new SecretResponse();
ProxyResponse proxyResponse = new ProxyResponse();
proxyResponse.setName(name);
proxyResponse.setHost(host);
proxyResponse.setPort(port);
proxyResponse.setUserName(secretResponse);
proxyResponse.setPassword(secretResponse);
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
when(environmentServiceCrnClient.withCrn(anyString()).proxyV1Endpoint()).thenReturn(proxyEndpoint);
when(proxyEndpoint.getByResourceCrn(anyString())).thenReturn(proxyResponse);
when(secretService.getByResponse(any(SecretResponse.class))).thenReturn(user).thenReturn(password);
ProxyConfig proxyConfig = underTest.getByCrn("crn:cdp:environments:us-west-1:cloudera:proxyconfig:a2f0bee2-059e-433f-a9d0-2893c53419ad");
assertFalse(proxyConfig.getProxyAuthentication().isPresent());
}
use of com.sequenceiq.cloudbreak.service.secret.model.SecretResponse in project cloudbreak by hortonworks.
the class ProxyConfigDtoServiceTest method testGetWhenProxyConfigCouldNotBeFetchedFromEnvironmentMS.
@Test
void testGetWhenProxyConfigCouldNotBeFetchedFromEnvironmentMS() {
SecretResponse secretResponse = new SecretResponse();
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
when(environmentServiceCrnClient.withCrn(anyString()).proxyV1Endpoint()).thenReturn(proxyEndpoint);
when(proxyEndpoint.getByResourceCrn(anyString())).thenThrow(new NotFoundException("The proxy config could not be found!"));
CloudbreakServiceException exception = assertThrows(CloudbreakServiceException.class, () -> underTest.getByCrn("crn:cdp:environments:us-west-1:cloudera:proxyconfig:a2f0bee2-059e-433f-a9d0-2893c53419ad"));
verify(secretService, times(0)).getByResponse(secretResponse);
assertEquals("Failed to get Proxy config from Environment service due to: 'The proxy config could not be found!' ", exception.getMessage());
}
use of com.sequenceiq.cloudbreak.service.secret.model.SecretResponse in project cloudbreak by hortonworks.
the class LdapConfigV1ServiceTest method testDescribe.
@Test
public void testDescribe() {
// GIVEN
LdapConfig ldapConfig = createLdapConfig();
Mockito.when(ldapConfigService.get(ENVID)).thenReturn(ldapConfig);
Mockito.when(stringToSecretResponseConverter.convert(SECRET_BINDDN)).thenReturn(new SecretResponse("enginepath", "binddn-secretpath"));
Mockito.when(stringToSecretResponseConverter.convert(SECRET_PWD)).thenReturn(new SecretResponse("enginepath", "pwd-secretpath"));
// WHEN
DescribeLdapConfigResponse actualResponse = underTest.describe(ENVID);
// THEN
checkResponse(actualResponse);
}
Aggregations