Search in sources :

Example 6 with ProxyManager

use of com.synopsys.integration.alert.common.rest.proxy.ProxyManager in project hub-alert by blackducksoftware.

the class ChannelRestConnectionFactoryTest method testConnectionFields.

@Test
void testConnectionFields() {
    String baseUrl = "https://example-base-url";
    final String host = "host";
    final int port = 1;
    CredentialsBuilder builder = Credentials.newBuilder();
    builder.setUsername("username");
    builder.setPassword("password");
    Credentials credentials = builder.build();
    ProxyInfoBuilder proxyBuilder = ProxyInfo.newBuilder();
    proxyBuilder.setHost(host);
    proxyBuilder.setPort(port);
    proxyBuilder.setCredentials(credentials);
    proxyBuilder.setNtlmDomain(null);
    proxyBuilder.setNtlmWorkstation(null);
    ProxyInfo expectedProxyInfo = proxyBuilder.build();
    MockAlertProperties testAlertProperties = new MockAlertProperties();
    testAlertProperties.setAlertTrustCertificate(true);
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    Mockito.when(proxyManager.createProxyInfoForHost(baseUrl)).thenReturn(expectedProxyInfo);
    ChannelRestConnectionFactory channelRestConnectionFactory = new ChannelRestConnectionFactory(testAlertProperties, proxyManager, gson);
    IntHttpClient intHttpClient = channelRestConnectionFactory.createIntHttpClient(baseUrl);
    assertNotNull(intHttpClient);
    assertEquals(expectedProxyInfo, intHttpClient.getProxyInfo());
}
Also used : ProxyInfo(com.synopsys.integration.rest.proxy.ProxyInfo) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) CredentialsBuilder(com.synopsys.integration.rest.credentials.CredentialsBuilder) Credentials(com.synopsys.integration.rest.credentials.Credentials) ProxyInfoBuilder(com.synopsys.integration.rest.proxy.ProxyInfoBuilder) Test(org.junit.jupiter.api.Test)

Example 7 with ProxyManager

use of com.synopsys.integration.alert.common.rest.proxy.ProxyManager in project hub-alert by blackducksoftware.

the class SystemValidatorTest method testValidateHubValidProviderWithProxy.

@Test
public void testValidateHubValidProviderWithProxy() throws Exception {
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    CredentialsBuilder builder = Credentials.newBuilder();
    builder.setUsername("AUser");
    builder.setPassword("aPassword");
    Credentials credentials = builder.build();
    ProxyInfoBuilder proxyBuilder = ProxyInfo.newBuilder();
    proxyBuilder.setHost("google.com");
    proxyBuilder.setPort(3218);
    proxyBuilder.setCredentials(credentials);
    proxyBuilder.setNtlmDomain(null);
    proxyBuilder.setNtlmWorkstation(null);
    ProxyInfo expectedProxyInfo = proxyBuilder.build();
    Mockito.when(proxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(expectedProxyInfo);
    BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
    Mockito.when(blackDuckProperties.getBlackDuckUrl()).thenReturn(Optional.of("Black Duck URL"));
    Mockito.when(blackDuckProperties.getApiToken()).thenReturn("Black Duck API Token");
    Mockito.when(blackDuckProperties.getBlackDuckTimeout()).thenReturn(BlackDuckProperties.DEFAULT_TIMEOUT);
    BlackDuckServerConfig serverConfig = Mockito.mock(BlackDuckServerConfig.class);
    Mockito.when(serverConfig.canConnect(Mockito.any(IntLogger.class))).thenReturn(false);
    DefaultSystemMessageAccessor defaultSystemMessageUtility = Mockito.mock(DefaultSystemMessageAccessor.class);
    StatefulProvider statefulProvider = Mockito.mock(StatefulProvider.class);
    BlackDuckProvider provider = Mockito.mock(BlackDuckProvider.class);
    Mockito.when(provider.createStatefulProvider(Mockito.any())).thenReturn(statefulProvider);
    Mockito.when(statefulProvider.getProperties()).thenReturn(blackDuckProperties);
    BlackDuckSystemValidator blackDuckSystemValidator = new BlackDuckSystemValidator(defaultSystemMessageUtility);
    blackDuckSystemValidator.validate(blackDuckProperties);
    Mockito.verify(defaultSystemMessageUtility, Mockito.times(0)).addSystemMessage(Mockito.anyString(), Mockito.any(SystemMessageSeverity.class), Mockito.any(SystemMessageType.class));
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) IntLogger(com.synopsys.integration.log.IntLogger) BlackDuckSystemValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) ProxyInfo(com.synopsys.integration.rest.proxy.ProxyInfo) CredentialsBuilder(com.synopsys.integration.rest.credentials.CredentialsBuilder) SystemMessageSeverity(com.synopsys.integration.alert.common.enumeration.SystemMessageSeverity) SystemMessageType(com.synopsys.integration.alert.common.enumeration.SystemMessageType) DefaultSystemMessageAccessor(com.synopsys.integration.alert.database.system.DefaultSystemMessageAccessor) BlackDuckProvider(com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider) Credentials(com.synopsys.integration.rest.credentials.Credentials) ProxyInfoBuilder(com.synopsys.integration.rest.proxy.ProxyInfoBuilder) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider) Test(org.junit.jupiter.api.Test)

Example 8 with ProxyManager

use of com.synopsys.integration.alert.common.rest.proxy.ProxyManager in project hub-alert by blackducksoftware.

the class SystemValidatorTest method testvalidateBlackDuckProviderLocalhostURL.

@Test
public void testvalidateBlackDuckProviderLocalhostURL() throws Exception {
    long configId = 1L;
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    Mockito.when(proxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(ProxyInfo.NO_PROXY_INFO);
    BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
    Mockito.when(blackDuckProperties.getBlackDuckUrl()).thenReturn(Optional.of("https://localhost:443"));
    Mockito.when(blackDuckProperties.getBlackDuckTimeout()).thenReturn(BlackDuckProperties.DEFAULT_TIMEOUT);
    Mockito.when(blackDuckProperties.getConfigName()).thenReturn(DEFAULT_CONFIG_NAME);
    Mockito.when(blackDuckProperties.getConfigId()).thenReturn(configId);
    BlackDuckServerConfig blackDuckServerConfig = Mockito.mock(BlackDuckServerConfig.class);
    Mockito.when(blackDuckProperties.createBlackDuckServerConfig(Mockito.any(IntLogger.class))).thenReturn(blackDuckServerConfig);
    StatefulProvider statefulProvider = Mockito.mock(StatefulProvider.class);
    BlackDuckProvider provider = Mockito.mock(BlackDuckProvider.class);
    Mockito.when(provider.createStatefulProvider(Mockito.any())).thenReturn(statefulProvider);
    Mockito.when(statefulProvider.getProperties()).thenReturn(blackDuckProperties);
    DefaultSystemMessageAccessor defaultSystemMessageUtility = Mockito.mock(DefaultSystemMessageAccessor.class);
    String localhostMessageType = BlackDuckSystemValidator.createProviderSystemMessageType(blackDuckProperties, SystemMessageType.BLACKDUCK_PROVIDER_LOCALHOST);
    BlackDuckSystemValidator blackDuckSystemValidator = new BlackDuckSystemValidator(defaultSystemMessageUtility);
    blackDuckSystemValidator.validate(blackDuckProperties);
    Mockito.verify(defaultSystemMessageUtility).addSystemMessage(Mockito.eq(String.format(BlackDuckSystemValidator.BLACKDUCK_LOCALHOST_ERROR_FORMAT, DEFAULT_CONFIG_NAME)), Mockito.eq(SystemMessageSeverity.WARNING), Mockito.eq(localhostMessageType));
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) IntLogger(com.synopsys.integration.log.IntLogger) BlackDuckSystemValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator) BlackDuckProvider(com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider) DefaultSystemMessageAccessor(com.synopsys.integration.alert.database.system.DefaultSystemMessageAccessor) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider) Test(org.junit.jupiter.api.Test)

Example 9 with ProxyManager

use of com.synopsys.integration.alert.common.rest.proxy.ProxyManager in project hub-alert by blackducksoftware.

the class TestBlackDuckProperties method createMockedProxyManger.

public static ProxyManager createMockedProxyManger() {
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    ProxyInfo proxyInfo = Mockito.mock(ProxyInfo.class);
    Mockito.when(proxyInfo.getHost()).thenReturn(Optional.empty());
    Mockito.when(proxyInfo.getPort()).thenReturn(-1);
    Mockito.when(proxyInfo.getUsername()).thenReturn(Optional.empty());
    Mockito.when(proxyInfo.getPassword()).thenReturn(Optional.empty());
    Mockito.when(proxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(proxyInfo);
    return proxyManager;
}
Also used : ProxyInfo(com.synopsys.integration.rest.proxy.ProxyInfo) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager)

Example 10 with ProxyManager

use of com.synopsys.integration.alert.common.rest.proxy.ProxyManager in project hub-alert by blackducksoftware.

the class StartupLogTest method testLogConfiguration.

@Test
void testLogConfiguration() throws Exception {
    SettingsProxyModel settingsProxyModel = new SettingsProxyModel();
    settingsProxyModel.setProxyHost("google.com");
    settingsProxyModel.setProxyPort(3218);
    settingsProxyModel.setProxyUsername("AUser");
    settingsProxyModel.setIsProxyPasswordSet(true);
    settingsProxyModel.setProxyPassword("aPassword");
    SettingsUtility mockSettingsUtility = Mockito.mock(SettingsUtility.class);
    Mockito.when(mockSettingsUtility.getConfiguration()).thenReturn(Optional.of(settingsProxyModel));
    ProxyManager proxyManager = new ProxyManager(mockSettingsUtility);
    MockAlertProperties testAlertProperties = new MockAlertProperties();
    ConfigurationLogger configurationLogger = new ConfigurationLogger(proxyManager, testAlertProperties);
    configurationLogger.initializeComponent();
    assertTrue(outputLogger.isLineContainingText("Alert Proxy Authenticated: true"));
}
Also used : SettingsUtility(com.synopsys.integration.alert.common.descriptor.accessor.SettingsUtility) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) Test(org.junit.jupiter.api.Test)

Aggregations

ProxyManager (com.synopsys.integration.alert.common.rest.proxy.ProxyManager)16 Test (org.junit.jupiter.api.Test)9 MockAlertProperties (com.synopsys.integration.alert.test.common.MockAlertProperties)7 BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)6 Gson (com.google.gson.Gson)4 StatefulProvider (com.synopsys.integration.alert.api.provider.state.StatefulProvider)4 DefaultSystemMessageAccessor (com.synopsys.integration.alert.database.system.DefaultSystemMessageAccessor)4 BlackDuckProvider (com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider)4 BlackDuckSystemValidator (com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator)4 BlackDuckServerConfig (com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig)4 IntLogger (com.synopsys.integration.log.IntLogger)4 ChannelRestConnectionFactory (com.synopsys.integration.alert.api.channel.rest.ChannelRestConnectionFactory)3 ProxyInfo (com.synopsys.integration.rest.proxy.ProxyInfo)3 AlertProperties (com.synopsys.integration.alert.common.AlertProperties)2 SystemMessageSeverity (com.synopsys.integration.alert.common.enumeration.SystemMessageSeverity)2 SystemMessageType (com.synopsys.integration.alert.common.enumeration.SystemMessageType)2 JobAccessor (com.synopsys.integration.alert.common.persistence.accessor.JobAccessor)2 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)2 Credentials (com.synopsys.integration.rest.credentials.Credentials)2 CredentialsBuilder (com.synopsys.integration.rest.credentials.CredentialsBuilder)2