Search in sources :

Example 1 with ProxyEndpoint

use of com.sequenceiq.environment.api.v1.proxy.endpoint.ProxyEndpoint in project cloudbreak by hortonworks.

the class ProxyConfigDtoServiceTest method testGetWhenSecretCouldNotBeFetchedFromVault.

@Test
void testGetWhenSecretCouldNotBeFetchedFromVault() {
    String name = "aProxyConfig";
    String host = "https://test.cloudera.com";
    Integer port = 8443;
    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))).thenThrow(new VaultException("Vault token is invalid!"));
    CloudbreakServiceException exception = assertThrows(CloudbreakServiceException.class, () -> underTest.getByCrn("crn:cdp:environments:us-west-1:cloudera:proxyconfig:a2f0bee2-059e-433f-a9d0-2893c53419ad"));
    assertEquals("Failed to get Proxy config related secret due to: 'Vault token is invalid!' ", exception.getMessage());
}
Also used : SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) ProxyResponse(com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse) VaultException(org.springframework.vault.VaultException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ProxyEndpoint

use of com.sequenceiq.environment.api.v1.proxy.endpoint.ProxyEndpoint in project cloudbreak by hortonworks.

the class ProxyConfigDtoServiceTest method testGetWhenProxyConfigCouldBeFetched.

@Test
void testGetWhenProxyConfigCouldBeFetched() {
    String name = "aProxyConfig";
    String host = "https://test.cloudera.com";
    Integer port = 8443;
    String decryptedSecretValue = "decrypted-secret-value";
    String noProxyList = "noproxy.com";
    SecretResponse secretResponse = new SecretResponse();
    ProxyResponse proxyResponse = new ProxyResponse();
    proxyResponse.setName(name);
    proxyResponse.setHost(host);
    proxyResponse.setPort(port);
    proxyResponse.setUserName(secretResponse);
    proxyResponse.setPassword(secretResponse);
    proxyResponse.setNoProxyHosts(noProxyList);
    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(decryptedSecretValue);
    ProxyConfig proxyConfig = underTest.getByCrn("crn:cdp:environments:us-west-1:cloudera:proxyconfig:a2f0bee2-059e-433f-a9d0-2893c53419ad");
    verify(secretService, times(2)).getByResponse(secretResponse);
    assertEquals(proxyConfig.getName(), name);
    assertEquals(proxyConfig.getServerHost(), host);
    assertEquals(proxyConfig.getServerPort(), port);
    assertTrue(proxyConfig.getProxyAuthentication().isPresent());
    assertEquals(proxyConfig.getProxyAuthentication().get().getUserName(), decryptedSecretValue);
    assertEquals(proxyConfig.getProxyAuthentication().get().getPassword(), decryptedSecretValue);
    assertEquals(proxyConfig.getNoProxyHosts(), noProxyList);
}
Also used : SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) ProxyResponse(com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with ProxyEndpoint

use of com.sequenceiq.environment.api.v1.proxy.endpoint.ProxyEndpoint 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());
}
Also used : SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) ProxyResponse(com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with ProxyEndpoint

use of com.sequenceiq.environment.api.v1.proxy.endpoint.ProxyEndpoint in project cloudbreak by hortonworks.

the class ProxyConfigDtoServiceTest method testGetWhenProxyConfigUserPasswordSecretsAreEmpty.

@ParameterizedTest
@MethodSource("invalidUserPasswordSecrets")
void testGetWhenProxyConfigUserPasswordSecretsAreEmpty(SecretResponse user, SecretResponse password) {
    String name = "aProxyConfig";
    String host = "https://test.cloudera.com";
    Integer port = 8443;
    ProxyResponse proxyResponse = new ProxyResponse();
    proxyResponse.setName(name);
    proxyResponse.setHost(host);
    proxyResponse.setPort(port);
    proxyResponse.setUserName(user);
    proxyResponse.setPassword(password);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(environmentServiceCrnClient.withCrn(anyString()).proxyV1Endpoint()).thenReturn(proxyEndpoint);
    when(proxyEndpoint.getByResourceCrn(anyString())).thenReturn(proxyResponse);
    ProxyConfig proxyConfig = underTest.getByCrn("crn:cdp:environments:us-west-1:cloudera:proxyconfig:a2f0bee2-059e-433f-a9d0-2893c53419ad");
    assertFalse(proxyConfig.getProxyAuthentication().isPresent());
}
Also used : ProxyResponse(com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ProxyResponse (com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 ProxyConfig (com.sequenceiq.cloudbreak.dto.ProxyConfig)3 SecretResponse (com.sequenceiq.cloudbreak.service.secret.model.SecretResponse)3 Test (org.junit.jupiter.api.Test)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 VaultException (org.springframework.vault.VaultException)1