Search in sources :

Example 61 with HttpUrl

use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.

the class ProxyTestService method pingHost.

public ConfigurationTestResult pingHost(String testUrl, SettingsProxyModel settingsProxyModel) {
    ProxyInfo proxyInfo = proxyManager.createProxyInfo(settingsProxyModel);
    IntHttpClient client = createIntHttpClient(proxyInfo);
    try {
        HttpUrl httpUrl = new HttpUrl(testUrl);
        Request testRequest = new Request.Builder(httpUrl).build();
        Response response = client.execute(testRequest);
        if (RestConstants.OK_200 >= response.getStatusCode() && response.getStatusCode() < RestConstants.MULT_CHOICE_300) {
            logger.info("Successfully pinged {}!", testUrl);
            return ConfigurationTestResult.success();
        } else {
            return ConfigurationTestResult.failure(String.format("Could not ping: %s. Status Message: %s. Status code: %s", testUrl, response.getStatusMessage(), response.getStatusCode()));
        }
    } catch (IntegrationException e) {
        logger.error(e.getMessage(), e);
        return ConfigurationTestResult.failure(e.getMessage());
    }
}
Also used : Response(com.synopsys.integration.rest.response.Response) ProxyInfo(com.synopsys.integration.rest.proxy.ProxyInfo) IntegrationException(com.synopsys.integration.exception.IntegrationException) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) Request(com.synopsys.integration.rest.request.Request) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 62 with HttpUrl

use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.

the class NotificationContentProcessorTest method createRuleViolationNotificationMessageExtractor.

private RuleViolationNotificationMessageExtractor createRuleViolationNotificationMessageExtractor() throws IntegrationException {
    BlackDuckProviderKey providerKey = new BlackDuckProviderKey();
    NotificationExtractorBlackDuckServicesFactoryCache servicesFactoryCache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
    BlackDuckPolicySeverityConverter blackDuckPolicySeverityConverter = new BlackDuckPolicySeverityConverter();
    BlackDuckPolicyComponentConcernCreator blackDuckPolicyComponentConcernCreator = new BlackDuckPolicyComponentConcernCreator(blackDuckPolicySeverityConverter);
    BlackDuckComponentVulnerabilityDetailsCreator vulnerabilityDetailsCreator = new BlackDuckComponentVulnerabilityDetailsCreator();
    BlackDuckComponentPolicyDetailsCreatorFactory blackDuckComponentPolicyDetailsCreatorFactory = new BlackDuckComponentPolicyDetailsCreatorFactory(blackDuckPolicySeverityConverter);
    BlackDuckMessageBomComponentDetailsCreatorFactory detailsCreatorFactory = new BlackDuckMessageBomComponentDetailsCreatorFactory(vulnerabilityDetailsCreator, blackDuckComponentPolicyDetailsCreatorFactory);
    // Mocks for AbstractRuleViolationNotificationMessageExtractor
    BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
    BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
    Mockito.when(servicesFactoryCache.retrieveBlackDuckServicesFactory(Mockito.any())).thenReturn(blackDuckServicesFactory);
    Mockito.when(blackDuckServicesFactory.getBlackDuckHttpClient()).thenReturn(blackDuckHttpClient);
    Mockito.when(blackDuckHttpClient.getBlackDuckUrl()).thenReturn(new HttpUrl(PROVIDER_DETAILS.getProvider().getUrl().get()));
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
    ProjectVersionComponentVersionView projectVersionComponentVersionView = blackDuckResponseTestUtility.createProjectVersionComponentVersionView();
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(), Mockito.eq(ProjectVersionComponentVersionView.class))).thenReturn(projectVersionComponentVersionView);
    BomComponent404Handler bomComponent404Handler = new BomComponent404Handler();
    return new RuleViolationNotificationMessageExtractor(providerKey, servicesFactoryCache, blackDuckPolicyComponentConcernCreator, detailsCreatorFactory, bomComponent404Handler);
}
Also used : BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) BlackDuckPolicyComponentConcernCreator(com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckPolicyComponentConcernCreator) BlackDuckComponentPolicyDetailsCreatorFactory(com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckComponentPolicyDetailsCreatorFactory) BomComponent404Handler(com.synopsys.integration.alert.provider.blackduck.processor.message.service.BomComponent404Handler) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) HttpUrl(com.synopsys.integration.rest.HttpUrl) BlackDuckMessageBomComponentDetailsCreatorFactory(com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreatorFactory) BlackDuckComponentVulnerabilityDetailsCreator(com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckComponentVulnerabilityDetailsCreator) BlackDuckPolicySeverityConverter(com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckPolicySeverityConverter) RuleViolationNotificationMessageExtractor(com.synopsys.integration.alert.provider.blackduck.processor.message.RuleViolationNotificationMessageExtractor) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)

Example 63 with HttpUrl

use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.

the class JobNotificationProcessorTest method createRuleViolationNotificationMessageExtractor.

private RuleViolationNotificationMessageExtractor createRuleViolationNotificationMessageExtractor() throws IntegrationException {
    BlackDuckProviderKey providerKey = new BlackDuckProviderKey();
    NotificationExtractorBlackDuckServicesFactoryCache servicesFactoryCache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
    BlackDuckPolicySeverityConverter blackDuckPolicySeverityConverter = new BlackDuckPolicySeverityConverter();
    BlackDuckPolicyComponentConcernCreator blackDuckPolicyComponentConcernCreator = new BlackDuckPolicyComponentConcernCreator(blackDuckPolicySeverityConverter);
    BlackDuckComponentVulnerabilityDetailsCreator vulnerabilityDetailsCreator = new BlackDuckComponentVulnerabilityDetailsCreator();
    BlackDuckComponentPolicyDetailsCreatorFactory blackDuckComponentPolicyDetailsCreatorFactory = new BlackDuckComponentPolicyDetailsCreatorFactory(blackDuckPolicySeverityConverter);
    BlackDuckMessageBomComponentDetailsCreatorFactory detailsCreatorFactory = new BlackDuckMessageBomComponentDetailsCreatorFactory(vulnerabilityDetailsCreator, blackDuckComponentPolicyDetailsCreatorFactory);
    // Mocks for AbstractRuleViolationNotificationMessageExtractor
    BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
    BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
    Mockito.when(servicesFactoryCache.retrieveBlackDuckServicesFactory(Mockito.any())).thenReturn(blackDuckServicesFactory);
    Mockito.when(blackDuckServicesFactory.getBlackDuckHttpClient()).thenReturn(blackDuckHttpClient);
    Mockito.when(blackDuckHttpClient.getBlackDuckUrl()).thenReturn(new HttpUrl(PROVIDER_DETAILS.getProvider().getUrl().get()));
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
    ProjectVersionComponentVersionView projectVersionComponentVersionView = blackDuckResponseTestUtility.createProjectVersionComponentVersionView();
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(), Mockito.eq(ProjectVersionComponentVersionView.class))).thenReturn(projectVersionComponentVersionView);
    BomComponent404Handler bomComponent404Handler = new BomComponent404Handler();
    return new RuleViolationNotificationMessageExtractor(providerKey, servicesFactoryCache, blackDuckPolicyComponentConcernCreator, detailsCreatorFactory, bomComponent404Handler);
}
Also used : BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) BlackDuckPolicyComponentConcernCreator(com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckPolicyComponentConcernCreator) BlackDuckComponentPolicyDetailsCreatorFactory(com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckComponentPolicyDetailsCreatorFactory) BomComponent404Handler(com.synopsys.integration.alert.provider.blackduck.processor.message.service.BomComponent404Handler) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) HttpUrl(com.synopsys.integration.rest.HttpUrl) BlackDuckMessageBomComponentDetailsCreatorFactory(com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreatorFactory) BlackDuckComponentVulnerabilityDetailsCreator(com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckComponentVulnerabilityDetailsCreator) BlackDuckPolicySeverityConverter(com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckPolicySeverityConverter) RuleViolationNotificationMessageExtractor(com.synopsys.integration.alert.provider.blackduck.processor.message.RuleViolationNotificationMessageExtractor) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)

Example 64 with HttpUrl

use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.

the class NotificationGeneratorUtils method createVulnerabilityList.

public static List<VulnerabilityView> createVulnerabilityList() throws IntegrationException {
    VulnerabilityView vuln_1 = new VulnerabilityView();
    vuln_1.setName("1");
    vuln_1.setSeverity(VulnerabilitySeverityType.LOW);
    vuln_1.setMeta(new ResourceMetadata());
    vuln_1.getMeta().setHref(new HttpUrl("href_1"));
    VulnerabilityView vuln_2 = new VulnerabilityView();
    vuln_2.setName("2");
    vuln_2.setSeverity(VulnerabilitySeverityType.LOW);
    vuln_2.setMeta(new ResourceMetadata());
    vuln_2.getMeta().setHref(new HttpUrl("href_2"));
    VulnerabilityView vuln_3 = new VulnerabilityView();
    vuln_3.setName("3");
    vuln_3.setSeverity(VulnerabilitySeverityType.LOW);
    vuln_3.setMeta(new ResourceMetadata());
    vuln_3.getMeta().setHref(new HttpUrl("href_3"));
    VulnerabilityView vuln_4 = new VulnerabilityView();
    vuln_4.setName("4");
    vuln_4.setSeverity(VulnerabilitySeverityType.MEDIUM);
    vuln_4.setMeta(new ResourceMetadata());
    vuln_4.getMeta().setHref(new HttpUrl("href_4"));
    VulnerabilityView vuln_5 = new VulnerabilityView();
    vuln_5.setName("5");
    vuln_5.setSeverity(VulnerabilitySeverityType.HIGH);
    vuln_5.setMeta(new ResourceMetadata());
    vuln_5.getMeta().setHref(new HttpUrl("href_5"));
    VulnerabilityView vuln_6 = new VulnerabilityView();
    vuln_6.setName("6");
    vuln_6.setSeverity(VulnerabilitySeverityType.HIGH);
    vuln_6.setMeta(new ResourceMetadata());
    vuln_6.getMeta().setHref(new HttpUrl("href_6"));
    VulnerabilityView vuln_7 = new VulnerabilityView();
    vuln_7.setName("7");
    vuln_7.setSeverity(VulnerabilitySeverityType.HIGH);
    vuln_7.setMeta(new ResourceMetadata());
    vuln_7.getMeta().setHref(new HttpUrl("href_7"));
    VulnerabilityView vuln_8 = new VulnerabilityView();
    vuln_8.setName("8");
    vuln_8.setSeverity(VulnerabilitySeverityType.HIGH);
    vuln_8.setMeta(new ResourceMetadata());
    vuln_8.getMeta().setHref(new HttpUrl("href_8"));
    VulnerabilityView vuln_9 = new VulnerabilityView();
    vuln_9.setName("9");
    vuln_9.setSeverity(VulnerabilitySeverityType.HIGH);
    vuln_9.setMeta(new ResourceMetadata());
    vuln_9.getMeta().setHref(new HttpUrl("href_9"));
    VulnerabilityView vuln_10 = new VulnerabilityView();
    vuln_10.setName("10");
    vuln_10.setSeverity(VulnerabilitySeverityType.HIGH);
    vuln_10.setMeta(new ResourceMetadata());
    vuln_10.getMeta().setHref(new HttpUrl("href_10"));
    VulnerabilityView vuln_11 = new VulnerabilityView();
    vuln_11.setName("11");
    vuln_11.setSeverity(VulnerabilitySeverityType.HIGH);
    vuln_11.setMeta(new ResourceMetadata());
    vuln_11.getMeta().setHref(new HttpUrl("href_11"));
    return Arrays.asList(vuln_1, vuln_2, vuln_3, vuln_4, vuln_5, vuln_6, vuln_7, vuln_8, vuln_9, vuln_10, vuln_11);
}
Also used : VulnerabilityView(com.synopsys.integration.blackduck.api.generated.view.VulnerabilityView) ResourceMetadata(com.synopsys.integration.blackduck.api.core.ResourceMetadata) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 65 with HttpUrl

use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.

the class IntegrationAlertRequestUtility method executeRequest.

private String executeRequest(HttpMethod httpMethod, MockHttpServletRequestBuilder requestBuilder, String error) throws IntegrationException {
    MockHttpServletRequestBuilder request = requestBuilder.with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
    try {
        MvcResult mvcResult = mockMvc.perform(request).andReturn();
        String responseContent = mvcResult.getResponse().getContentAsString();
        int status = mvcResult.getResponse().getStatus();
        if (status >= RestConstants.BAD_REQUEST_400) {
            intLogger.error(String.format("Error code: %s", status));
            intLogger.error(String.format("Response: %s", responseContent));
            intLogger.error(error);
            throw new IntegrationRestException(httpMethod, new HttpUrl("https://google.com"), status, "Bad Request", responseContent, error);
        }
        return responseContent;
    } catch (IntegrationRestException e) {
        throw e;
    } catch (Exception e) {
        throw new IntegrationException(e.getMessage(), e);
    }
}
Also used : IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) IntegrationException(com.synopsys.integration.exception.IntegrationException) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) MvcResult(org.springframework.test.web.servlet.MvcResult) HttpUrl(com.synopsys.integration.rest.HttpUrl) IntegrationException(com.synopsys.integration.exception.IntegrationException) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException)

Aggregations

HttpUrl (com.synopsys.integration.rest.HttpUrl)65 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)35 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)29 Test (org.junit.jupiter.api.Test)28 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)23 ResourceMetadata (com.synopsys.integration.blackduck.api.core.ResourceMetadata)21 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)18 IntegrationException (com.synopsys.integration.exception.IntegrationException)15 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)15 ComponentUpgradeGuidance (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance)13 ResourceLink (com.synopsys.integration.blackduck.api.core.ResourceLink)9 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)9 UrlSingleResponse (com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse)7 ProjectVersionComponentVersionLicensesView (com.synopsys.integration.blackduck.api.generated.component.ProjectVersionComponentVersionLicensesView)7 ComponentPolicy (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentPolicy)6 ComponentVersionUpgradeGuidanceView (com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView)6 ComponentPolicyRulesView (com.synopsys.integration.blackduck.api.generated.view.ComponentPolicyRulesView)6 PolicyRuleView (com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)6 BlackDuckMessageBomComponentDetailsCreator (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreator)5 ComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView)5