use of com.synopsys.integration.log.BufferedIntLogger in project blackduck-common by blackducksoftware.
the class BlackDuckApiClientTest method testGettingResponseWhenLinkNotPresent.
@Test
public void testGettingResponseWhenLinkNotPresent() throws IOException, IntegrationException {
IntLogger logger = new BufferedIntLogger();
BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
Gson gson = BlackDuckServicesFactory.createDefaultGson();
ObjectMapper objectMapper = BlackDuckServicesFactory.createDefaultObjectMapper();
BlackDuckResponseResolver blackDuckResponseResolver = new BlackDuckResponseResolver(gson);
BlackDuckJsonTransformer blackDuckJsonTransformer = new BlackDuckJsonTransformer(gson, objectMapper, blackDuckResponseResolver, logger);
BlackDuckResponseTransformer blackDuckResponseTransformer = new BlackDuckResponseTransformer(blackDuckHttpClient, blackDuckJsonTransformer);
BlackDuckResponsesTransformer blackDuckResponsesTransformer = new BlackDuckResponsesTransformer(blackDuckHttpClient, blackDuckJsonTransformer);
InputStream inputStream = getClass().getResourceAsStream("/json/ProjectVersionView_not_complete.json");
String incompleteJson = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
ProjectVersionView projectVersionViewWithMissingLink = blackDuckJsonTransformer.getResponseAs(incompleteJson, ProjectVersionView.class);
BlackDuckApiClient blackDuckApiClient = new BlackDuckApiClient(blackDuckHttpClient, blackDuckJsonTransformer, blackDuckResponseTransformer, blackDuckResponsesTransformer);
try {
blackDuckApiClient.getResponse(projectVersionViewWithMissingLink.metaPolicyStatusLink());
fail();
} catch (NoSuchElementException e) {
assertTrue(e.getMessage().contains(ProjectVersionView.POLICY_STATUS_LINK));
assertTrue(e.getMessage().contains("not found"));
}
}
use of com.synopsys.integration.log.BufferedIntLogger in project blackduck-common by blackducksoftware.
the class InstallAndRunSignatureScannerTestIT method testInstallingAndRunningSignatureScanner.
@Test
void testInstallingAndRunningSignatureScanner() throws IOException, InterruptedException, IntegrationException {
// here, we do not want to automatically trust the server's certificate
BlackDuckServerConfigBuilder blackDuckServerConfigBuilder = intHttpClientTestHelper.getBlackDuckServerConfigBuilder();
blackDuckServerConfigBuilder.setTrustCert(false);
BlackDuckServerConfig blackDuckServerConfig = blackDuckServerConfigBuilder.build();
File installDirectory = new File(scannerDirectoryPath, "scanner_install");
File outputDirectory = new File(scannerDirectoryPath, "scanner_output");
ScanBatch scanBatch = createScanBatch(blackDuckServerConfig, outputDirectory);
BufferedIntLogger logger = new BufferedIntLogger();
BlackDuckServicesFactory blackDuckServicesFactory = blackDuckServerConfig.createBlackDuckServicesFactory(logger);
IntEnvironmentVariables environmentVariables = blackDuckServicesFactory.getEnvironmentVariables();
OperatingSystemType operatingSystemType = OperatingSystemType.determineFromSystem();
ExecutorService executorService = BlackDuckServicesFactory.NO_THREAD_EXECUTOR_SERVICE;
BlackDuckHttpClient blackDuckHttpClient = blackDuckServicesFactory.getBlackDuckHttpClient();
BlackDuckRegistrationService blackDuckRegistrationService = blackDuckServicesFactory.createBlackDuckRegistrationService();
CleanupZipExpander cleanupZipExpander = new CleanupZipExpander(logger);
HttpUrl blackDuckServerUrl = blackDuckHttpClient.getBlackDuckUrl();
ScanPathsUtility scanPathsUtility = new ScanPathsUtility(logger, environmentVariables, operatingSystemType);
ScanCommandRunner scanCommandRunner = new ScanCommandRunner(logger, environmentVariables, scanPathsUtility, executorService);
// first, run a scan with an install that will NOT update the embedded keystore, which should fail
KeyStoreHelper noOpKeyStoreHelper = new NoOpKeyStoreHelper();
ScannerZipInstaller installerWithoutKeyStoreManagement = new ScannerZipInstaller(logger, new SignatureScannerClient(blackDuckHttpClient), blackDuckRegistrationService, cleanupZipExpander, scanPathsUtility, noOpKeyStoreHelper, blackDuckServerUrl, operatingSystemType, installDirectory);
ScanBatchRunner scanBatchRunnerWithout = ScanBatchRunner.createComplete(environmentVariables, scanPathsUtility, scanCommandRunner, installerWithoutKeyStoreManagement);
SignatureScannerService signatureScannerServiceWithout = blackDuckServicesFactory.createSignatureScannerService(scanBatchRunnerWithout);
assertScanFailure(logger, blackDuckRegistrationService, signatureScannerServiceWithout, scanBatch);
// now, delete the failed installation
FileUtils.deleteDirectory(installDirectory);
// second, run a scan with an install that DOES update the embedded keystore, which should succeed
logger.resetAllLogs();
KeyStoreHelper keyStoreHelper = new KeyStoreHelper(logger);
ScannerZipInstaller installerWithKeyStoreManagement = new ScannerZipInstaller(logger, new SignatureScannerClient(blackDuckHttpClient), blackDuckRegistrationService, cleanupZipExpander, scanPathsUtility, keyStoreHelper, blackDuckServerUrl, operatingSystemType, installDirectory);
ScanBatchRunner scanBatchRunnerWith = ScanBatchRunner.createComplete(environmentVariables, scanPathsUtility, scanCommandRunner, installerWithKeyStoreManagement);
SignatureScannerService signatureScannerServiceWith = blackDuckServicesFactory.createSignatureScannerService(scanBatchRunnerWith);
assertScanSuccess(logger, signatureScannerServiceWith, scanBatch);
// finally, verify the code location exists and then delete it to clean up
CodeLocationService codeLocationService = blackDuckServicesFactory.createCodeLocationService();
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
ResilientJobConfig jobConfig = new ResilientJobConfig(logger, 120, System.currentTimeMillis(), 10);
WaitJob.waitFor(jobConfig, () -> codeLocationService.getCodeLocationByName(CODE_LOCATION_NAME).isPresent(), "codeLocationTest");
Optional<CodeLocationView> codeLocationViewOptional = codeLocationService.getCodeLocationByName(CODE_LOCATION_NAME);
assertTrue(codeLocationViewOptional.isPresent());
blackDuckApiClient.delete(codeLocationViewOptional.get());
}
use of com.synopsys.integration.log.BufferedIntLogger in project blackduck-common by blackducksoftware.
the class BinaryScanUploadServiceTestIT method testCodeLocationFromBinaryScanUploadWhenNotConfigured.
@Test
public void testCodeLocationFromBinaryScanUploadWhenNotConfigured() throws Exception {
BlackDuckServices blackDuckServices = new BlackDuckServices(intHttpClientTestHelper);
BinaryScanData binaryScanData = createBinaryScanData(blackDuckServices, createTestBinaryScan());
BinaryScanUploadService binaryScanUploadService = blackDuckServices.blackDuckServicesFactory.createBinaryScanUploadService();
BinaryScanBatchOutput binaryScanBatchOutput = binaryScanUploadService.uploadBinaryScanAndWait(binaryScanData.binaryScan, 15 * 60);
BufferedIntLogger logger = new BufferedIntLogger();
try {
binaryScanBatchOutput.throwExceptionForError(logger);
} catch (Exception e) {
assertTrue(e instanceof BlackDuckIntegrationException);
assertTrue(e.getMessage().startsWith("Error when uploading binary scan"));
assertTrue(logger.getOutputString(LogLevel.ERROR).contains(e.getMessage()));
}
}
use of com.synopsys.integration.log.BufferedIntLogger in project blackduck-common by blackducksoftware.
the class CodeLocationWaitJobConditionTest method testMultipleNotificationsExpected.
@Test
public void testMultipleNotificationsExpected() throws ParseException, IntegrationException {
BlackDuckApiClient mockBlackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
ProjectService mockProjectService = Mockito.mock(ProjectService.class);
NotificationService mockNotificationService = Mockito.mock(NotificationService.class);
UserView userView = new UserView();
userView.setUserName("squiggles");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date alanTuringBirth = sdf.parse("1912-06-23");
Date alanTuringUntimelyDeath = sdf.parse("1954-06-07");
NotificationTaskRange notificationTaskRange = new NotificationTaskRange(System.currentTimeMillis(), alanTuringBirth, alanTuringUntimelyDeath);
IntLogger logger = new BufferedIntLogger();
NameVersion projectAndVersion = new NameVersion("BigSpoon", "LittleSpoon");
String codeLocationName = "GraceIsButGloryBegunAndGloryIsButGracePerfected";
Set<String> codeLocationNames = new HashSet<>(Arrays.asList(codeLocationName));
CodeLocationWaitJobCondition codeLocationWaitJobCondition = new CodeLocationWaitJobCondition(logger, mockBlackDuckApiClient, mockProjectService, mockNotificationService, userView, notificationTaskRange, projectAndVersion, codeLocationNames, 2);
ProjectView projectView = new ProjectView();
ResourceLink resourceLink = new ResourceLink();
resourceLink.setRel(ProjectVersionView.CODELOCATIONS_LINK);
resourceLink.setHref(codeLocationsUrl);
ResourceMetadata projectVersionViewMeta = new ResourceMetadata();
projectVersionViewMeta.setLinks(Arrays.asList(resourceLink));
ProjectVersionView projectVersionView = new ProjectVersionView();
projectVersionView.setMeta(projectVersionViewMeta);
ProjectVersionWrapper projectVersionWrapper = new ProjectVersionWrapper(projectView, projectVersionView);
Mockito.when(mockProjectService.getProjectVersion(projectAndVersion)).thenReturn(Optional.of(projectVersionWrapper));
ResourceMetadata resourceMetadata = new ResourceMetadata();
resourceMetadata.setHref(codeLocationUrl);
CodeLocationView foundCodeLocationView = new CodeLocationView();
foundCodeLocationView.setName(codeLocationName);
foundCodeLocationView.setMeta(resourceMetadata);
Mockito.when(mockBlackDuckApiClient.getAllResponses(Mockito.eq(codeLocationResponses))).thenReturn(Arrays.asList(foundCodeLocationView));
NotificationEditor notificationEditor = new NotificationEditor(notificationTaskRange.getStartDate(), notificationTaskRange.getEndDate(), Arrays.asList(NotificationType.VERSION_BOM_CODE_LOCATION_BOM_COMPUTED.name()));
Mockito.when(mockNotificationService.getAllUserNotifications(userView, notificationEditor)).thenReturn(getExpectedNotifications());
assertTrue(codeLocationWaitJobCondition.isComplete());
}
use of com.synopsys.integration.log.BufferedIntLogger in project blackduck-common by blackducksoftware.
the class BlackDuckRedirectStrategyTest method testSimpleRedirect.
@Test
public void testSimpleRedirect() throws IOException, IntegrationException, InterruptedException {
// we need two servers - one to redirect to the other
MockWebServer redirectingServer = new MockWebServer();
MockWebServer destinationServer = new MockWebServer();
String destinationUrl = startDestinationServer(destinationServer);
String redirectingServerUrl = startRedirectingServer(redirectingServer, destinationUrl);
IntLogger testLogger = new BufferedIntLogger();
IntHttpClient redirectingClient = new IntHttpClient(testLogger, gson, 120, false, ProxyInfo.NO_PROXY_INFO) {
@Override
public void addToHttpClientBuilder(HttpClientBuilder httpClientBuilder, RequestConfig.Builder defaultRequestConfigBuilder) {
super.addToHttpClientBuilder(httpClientBuilder, defaultRequestConfigBuilder);
httpClientBuilder.setRedirectStrategy(new BlackDuckRedirectStrategy());
}
};
Request requestToRedirectingServer = new Request.Builder(new HttpUrl(redirectingServerUrl)).method(HttpMethod.POST).bodyContent(new StringBodyContent("the initial request payload", BodyContentConverter.DEFAULT)).build();
Response response = redirectingClient.execute(requestToRedirectingServer);
assertEquals("the final response body", response.getContentString());
RecordedRequest initialRequest = redirectingServer.takeRequest();
RecordedRequest redirectedRequest = destinationServer.takeRequest();
assertEquals(initialRequest.getPath(), redirectedRequest.getPath());
assertEquals("/donkeynoodle", redirectedRequest.getPath());
assertEquals(initialRequest.getBody(), redirectedRequest.getBody());
assertEquals("the initial request payload", redirectedRequest.getBody().readString(StandardCharsets.UTF_8));
shutdownServers(redirectingServer, destinationServer);
}
Aggregations