Search in sources :

Example 16 with DockerAssertions

use of com.synopsys.integration.detect.battery.docker.util.DockerAssertions in project synopsys-detect by blackducksoftware.

the class DetectOnAlertTest method detectOnAlert.

@Test
@Disabled
// currently adds a lot of time, for I expect little value. If useful, feel free to re-enable.
void detectOnAlert() throws IOException, IntegrationException {
    try (DetectDockerTestRunner test = new DetectDockerTestRunner("detect-on-alert", "alert-6.5.0:1.0.1")) {
        test.withImageProvider(BuildDockerImageProvider.forDockerfilResourceNamed("Alert-6.5.0.dockerfile"));
        BlackDuckTestConnection blackDuckTestConnection = BlackDuckTestConnection.fromEnvironment();
        BlackDuckAssertions blackduckAssertions = blackDuckTestConnection.projectVersionAssertions("blackduck-alert", "6.5.1-SNAPSHOT");
        blackduckAssertions.emptyOnBlackDuck();
        DetectCommandBuilder commandBuilder = new DetectCommandBuilder().defaults().defaultDirectories(test);
        commandBuilder.connectToBlackDuck(blackDuckTestConnection);
        commandBuilder.waitForResults();
        DockerAssertions dockerAssertions = test.run(commandBuilder);
        dockerAssertions.projectVersion(blackduckAssertions.getProjectNameVersion());
        blackduckAssertions.codeLocationCount(16);
    }
}
Also used : DockerAssertions(com.synopsys.integration.detect.battery.docker.util.DockerAssertions) DetectCommandBuilder(com.synopsys.integration.detect.battery.docker.util.DetectCommandBuilder) DetectDockerTestRunner(com.synopsys.integration.detect.battery.docker.util.DetectDockerTestRunner) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 17 with DockerAssertions

use of com.synopsys.integration.detect.battery.docker.util.DockerAssertions in project synopsys-detect by blackducksoftware.

the class DetectOnDetectTest method testDryRunScanWithSnippetMatching.

@Test
@ExtendWith(TempDirectory.class)
public void testDryRunScanWithSnippetMatching(@TempDirectory.TempDir Path tempOutputDirectory) throws Exception {
    try (DetectDockerTestRunner test = new DetectDockerTestRunner("detect-on-detect-dryrun", "detect-7.1.0:1.0.0")) {
        test.withImageProvider(BuildDockerImageProvider.forDockerfilResourceNamed("Detect-7.1.0.dockerfile"));
        String projectName = "synopsys-detect-junit";
        String projectVersionName = "dryrun-scan";
        BlackDuckTestConnection blackDuckTestConnection = BlackDuckTestConnection.fromEnvironment();
        BlackDuckAssertions blackDuckAssertions = blackDuckTestConnection.projectVersionAssertions(projectName, projectVersionName);
        blackDuckAssertions.emptyOnBlackDuck();
        DetectCommandBuilder commandBuilder = new DetectCommandBuilder().defaults().defaultDirectories(test);
        commandBuilder.projectNameVersion(blackDuckAssertions.getProjectNameVersion());
        commandBuilder.connectToBlackDuck(blackDuckTestConnection);
        commandBuilder.property(DetectProperties.DETECT_BLACKDUCK_SIGNATURE_SCANNER_SNIPPET_MATCHING, "SNIPPET_MATCHING");
        commandBuilder.property(DetectProperties.DETECT_BLACKDUCK_SIGNATURE_SCANNER_DRY_RUN, "true");
        DockerAssertions dockerAssertions = test.run(commandBuilder);
        assertDirectoryStructureForOfflineScan(dockerAssertions.getOutputDirectory().toPath());
    }
}
Also used : DockerAssertions(com.synopsys.integration.detect.battery.docker.util.DockerAssertions) DetectCommandBuilder(com.synopsys.integration.detect.battery.docker.util.DetectCommandBuilder) DetectDockerTestRunner(com.synopsys.integration.detect.battery.docker.util.DetectDockerTestRunner) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith)

Example 18 with DockerAssertions

use of com.synopsys.integration.detect.battery.docker.util.DockerAssertions in project synopsys-detect by blackducksoftware.

the class DetectOnDetectTest method riskReportPopulatedAtCustomPath.

@Test
public // Tests that a new project has an empty report, run detect to fill it, tests the report is filled, in a custom location
void riskReportPopulatedAtCustomPath() throws Exception {
    try (DetectDockerTestRunner test = new DetectDockerTestRunner("detect-on-detect-riskreport-custom", "detect-7.1.0:1.0.0")) {
        test.withImageProvider(BuildDockerImageProvider.forDockerfilResourceNamed("Detect-7.1.0.dockerfile"));
        BlackDuckTestConnection blackDuckTestConnection = BlackDuckTestConnection.fromEnvironment();
        ReportService reportService = blackDuckTestConnection.createReportService();
        BlackDuckAssertions blackDuckAssertions = blackDuckTestConnection.projectVersionAssertions("synopsys-detect-junit", "risk-report-custom");
        ProjectVersionWrapper projectVersionWrapper = blackDuckAssertions.emptyOnBlackDuck();
        String reportDirectoryImagePath = "/opt/report";
        File reportDirectory = test.directories().createResultDirectory("report");
        test.directories().withBinding(reportDirectory, reportDirectoryImagePath);
        long initialFileLength = assertEmptyRiskReport(reportDirectory, projectVersionWrapper, reportService);
        DetectCommandBuilder commandBuilder = new DetectCommandBuilder().defaults().defaultDirectories(test);
        commandBuilder.connectToBlackDuck(blackDuckTestConnection);
        commandBuilder.projectNameVersion(blackDuckAssertions.getProjectNameVersion());
        commandBuilder.property(DetectProperties.DETECT_RISK_REPORT_PDF, "true");
        commandBuilder.property(DetectProperties.DETECT_TIMEOUT, "1200");
        commandBuilder.property(DetectProperties.DETECT_RISK_REPORT_PDF_PATH, reportDirectoryImagePath);
        commandBuilder.tools(DetectTool.DETECTOR);
        DockerAssertions dockerAssertions = test.run(commandBuilder);
        dockerAssertions.resultProducedAtLocation("/opt/report/synopsys_detect_junit_risk_report_custom_BlackDuck_RiskReport.pdf");
        List<File> pdfFiles = getPdfFiles(reportDirectory);
        assertEquals(1, pdfFiles.size());
        long postLength = pdfFiles.get(0).length();
        assertTrue(postLength > initialFileLength);
    }
}
Also used : ReportService(com.synopsys.integration.detect.workflow.blackduck.report.service.ReportService) DockerAssertions(com.synopsys.integration.detect.battery.docker.util.DockerAssertions) DetectCommandBuilder(com.synopsys.integration.detect.battery.docker.util.DetectCommandBuilder) DetectDockerTestRunner(com.synopsys.integration.detect.battery.docker.util.DetectDockerTestRunner) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 19 with DockerAssertions

use of com.synopsys.integration.detect.battery.docker.util.DockerAssertions in project synopsys-detect by blackducksoftware.

the class RiskReportTests method riskReportCreatedInCustomDirectoryEvenIfItDoesntExist.

@Test
void riskReportCreatedInCustomDirectoryEvenIfItDoesntExist() throws IOException, InterruptedException, IntegrationException {
    SharedDockerTestRunner test = anyProjectWithRiskReportResultsInBlackDuck("risk-report-directory-does-not-exist", new NameVersion("risk-reports", "directory-does-not-exist"));
    test.command.property(DetectProperties.DETECT_RISK_REPORT_PDF, "true");
    // simply using a directory that does not exist
    test.command.property(DetectProperties.DETECT_RISK_REPORT_PDF_PATH, "/opt/report/");
    DockerAssertions dockerAssertions = test.run();
    dockerAssertions.resultProducedAtLocation("/opt/report/risk_reports_directory_does_not_exist_BlackDuck_RiskReport.pdf");
}
Also used : SharedDockerTestRunner(com.synopsys.integration.detect.battery.docker.util.SharedDockerTestRunner) NameVersion(com.synopsys.integration.util.NameVersion) DockerAssertions(com.synopsys.integration.detect.battery.docker.util.DockerAssertions) Test(org.junit.jupiter.api.Test)

Aggregations

DockerAssertions (com.synopsys.integration.detect.battery.docker.util.DockerAssertions)19 Test (org.junit.jupiter.api.Test)19 DetectCommandBuilder (com.synopsys.integration.detect.battery.docker.util.DetectCommandBuilder)15 DetectDockerTestRunner (com.synopsys.integration.detect.battery.docker.util.DetectDockerTestRunner)15 SharedDockerTestRunner (com.synopsys.integration.detect.battery.docker.util.SharedDockerTestRunner)4 NameVersion (com.synopsys.integration.util.NameVersion)4 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)1 ReportService (com.synopsys.integration.detect.workflow.blackduck.report.service.ReportService)1 File (java.io.File)1 Disabled (org.junit.jupiter.api.Disabled)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1