Search in sources :

Example 6 with DetectableExecutableRunner

use of com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner in project synopsys-detect by blackducksoftware.

the class DockerExtractorTest method testExtractTarReturningOriginalTar.

@Test
@DisabledOnOs(WINDOWS)
public void testExtractTarReturningOriginalTar() throws ExecutableRunnerException, IOException {
    String image = null;
    String imageId = null;
    String tar = fakeDockerTarFile.getAbsolutePath();
    DetectableExecutableRunner executableRunner = getDetectableExecutableRunner();
    Extraction extraction = extract(image, imageId, tar, null, null, fakeResultsFile, executableRunner);
    // No returned .tar.gz: scan given docker tar instead
    assertTrue(extraction.getMetaData(DockerExtractor.DOCKER_IMAGE_NAME_META_DATA).get().endsWith("testDockerTarfile.tar"));
    assertTrue(extraction.getMetaData(DockerExtractor.DOCKER_TAR_META_DATA).get().getName().endsWith("testDockerTarfile.tar"));
    ArgumentCaptor<Executable> executableArgumentCaptor = ArgumentCaptor.forClass(Executable.class);
    Mockito.verify(executableRunner).execute(executableArgumentCaptor.capture());
    Executable executableToVerify = executableArgumentCaptor.getValue();
    List<String> command = executableToVerify.getCommandWithArguments();
    assertTrue(command.get(0).endsWith("/fake/test/java"));
    assertEquals("-jar", command.get(1));
    assertTrue(command.get(2).endsWith("/fake/test/dockerinspector.jar"));
    assertTrue(command.get(3).startsWith("--spring.config.location="));
    assertTrue(command.get(3).endsWith("/application.properties"));
    assertTrue(command.get(4).startsWith("--docker.tar="));
    assertTrue(command.get(4).endsWith("testDockerTarfile.tar"));
}
Also used : DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) Extraction(com.synopsys.integration.detectable.extraction.Extraction) Executable(com.synopsys.integration.executable.Executable) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test)

Example 7 with DetectableExecutableRunner

use of com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner in project synopsys-detect by blackducksoftware.

the class DpkgPackageManagerTest method testEpoch.

@Test
public void testEpoch() throws ExecutableRunnerException, NotOwnedByAnyPkgException {
    StringBuilder sb = new StringBuilder();
    sb.append("garbage\n");
    sb.append("nonsense\n");
    sb.append("login:amd64: /usr/include/stdlib.h\n");
    String pkgMgrOwnedByOutput = sb.toString();
    sb = new StringBuilder();
    sb.append("Package: login\n");
    sb.append("Essential: yes\n");
    sb.append("Status: install ok installed\n");
    sb.append("Priority: required\n");
    sb.append("Section: admin\n");
    sb.append("Installed-Size: 1212\n");
    sb.append("Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>\n");
    sb.append("Architecture: amd64\n");
    sb.append("Source: shadow\n");
    sb.append("Version: 1:4.5-1ubuntu1\n");
    sb.append("Replaces: manpages-de (<< 0.5-3), manpages-tr (<< 1.0.5), manpages-zh (<< 1.5.1-1)\n");
    sb.append("Pre-Depends: libaudit1 (>= 1:2.2.1), libc6 (>= 2.14), libpam0g (>= 0.99.7.1), libpam-runtime, libpam-modules (>= 1.1.8-1)\n");
    sb.append("Conflicts: amavisd-new (<< 2.3.3-8), backupninja (<< 0.9.3-5), echolot (<< 2.1.8-4), gnunet (<< 0.7.0c-2), python-4suite (<< 0.99cvs20060405-1)\n");
    sb.append("Conffiles:\n");
    sb.append(" /etc/login.defs 2a8f6cd8e00f54df72dc345a23f9db20\n");
    sb.append(" /etc/pam.d/login 1fd6cb4d4267a68148ee9973510a9d3e\n");
    sb.append(" /etc/pam.d/su ce6dcfda3b190a27a455bb38a45ff34a\n");
    sb.append(" /etc/securetty d0124b1d2fb22d4ac9a91aa02ae6d6db\n");
    sb.append("Description: system login tools\n");
    sb.append(" These tools are required to be able to login and use your system. The\n");
    sb.append(" login program invokes your user shell and enables command execution. The\n");
    sb.append(" newgrp program is used to change your effective group ID (useful for\n");
    sb.append(" workgroup type situations). The su program allows changing your effective\n");
    sb.append(" user ID (useful being able to execute commands as another user).\n");
    sb.append("Homepage: https://github.com/shadow-maint/shadow\n");
    sb.append("Original-Maintainer: Shadow package maintainers <pkg-shadow-devel@lists.alioth.debian.org>\n");
    String pkgMgrVersionOutput = sb.toString();
    final String packageNameWithArch = "login:amd64";
    DetectableExecutableRunner executableRunner = Mockito.mock(DetectableExecutableRunner.class);
    Mockito.when(executableRunner.execute(null, "dpkg", Arrays.asList("-s", packageNameWithArch))).thenReturn(new ExecutableOutput(0, pkgMgrVersionOutput, ""));
    DpkgPkgDetailsResolver dpkgVersionResolver = new DpkgPkgDetailsResolver();
    DpkgPackageManagerResolver pkgMgr = new DpkgPackageManagerResolver(dpkgVersionResolver);
    List<PackageDetails> pkgs = pkgMgr.resolvePackages(new ClangPackageManagerInfoFactory().dpkg(), executableRunner, null, pkgMgrOwnedByOutput);
    assertEquals(1, pkgs.size());
    assertEquals("login", pkgs.get(0).getPackageName());
    assertEquals("1:4.5-1ubuntu1", pkgs.get(0).getPackageVersion());
    assertEquals("amd64", pkgs.get(0).getPackageArch());
}
Also used : ClangPackageManagerInfoFactory(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerInfoFactory) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) DpkgPackageManagerResolver(com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.DpkgPackageManagerResolver) DpkgPkgDetailsResolver(com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.DpkgPkgDetailsResolver) PackageDetails(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails) Test(org.junit.jupiter.api.Test)

Example 8 with DetectableExecutableRunner

use of com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner in project synopsys-detect by blackducksoftware.

the class DpkgPackageManagerTest method test.

// TODO: Split into 2 tests - one for VersionResolution and one for FullResolution
@Test
public void test() throws ExecutableRunnerException, NotOwnedByAnyPkgException {
    StringBuilder sb = new StringBuilder();
    sb.append("garbage\n");
    sb.append("nonsense\n");
    sb.append("libc6-dev:amd64: /usr/include/stdlib.h\n");
    String pkgMgrOwnedByOutput = sb.toString();
    sb = new StringBuilder();
    sb.append("Package: libc6-dev\n");
    sb.append("Status: install ok installed\n");
    sb.append("Priority: optional\n");
    sb.append("Section: libdevel\n");
    sb.append("Installed-Size: 18812\n");
    sb.append("Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>\n");
    sb.append("Architecture: amd64\n");
    sb.append("Multi-Arch: same\n");
    sb.append("Source: glibc\n");
    sb.append("Version: 2.27-3ubuntu1\n");
    sb.append("Provides: libc-dev\n");
    sb.append("Depends: libc6 (= 2.27-3ubuntu1), libc-dev-bin (= 2.27-3ubuntu1), linux-libc-dev\n");
    sb.append("Suggests: glibc-doc, manpages-dev\n");
    sb.append("Breaks: binutils (<< 2.26), binutils-gold (<< 2.20.1-11), cmake (<< 2.8.4+dfsg.1-5), gcc-4.4 (<< 4.4.6-4), gcc-4.5 (<< 4.5.3-2), gcc-4.6 (<< 4.6.0-12), libhwloc-dev (<< 1.2-3), libjna-java (<< 3.2.7-4), liblouis-dev (<< 2.3.0-2), liblouisxml-dev (<< 2.4.0-2), libperl5.26 (<< 5.26.1-3), make (<< 3.81-8.1), pkg-config (<< 0.26-1)\n");
    sb.append("Conflicts: libc0.1-dev, libc0.3-dev, libc6.1-dev\n");
    sb.append("Description: GNU C Library: Development Libraries and Header Files\n");
    sb.append(" Contains the symlinks, headers, and object files needed to compile\n");
    sb.append(" and link programs which use the standard C library.\n");
    sb.append("Homepage: https://www.gnu.org/software/libc/libc.html\n");
    sb.append("Original-Maintainer: GNU Libc Maintainers <debian-glibc@lists.debian.org>\n");
    String pkgMgrVersionOutput = sb.toString();
    final String packageNameWithArch = "libc6-dev:amd64";
    DetectableExecutableRunner executableRunner = Mockito.mock(DetectableExecutableRunner.class);
    Mockito.when(executableRunner.execute(null, "dpkg", Arrays.asList("-s", packageNameWithArch))).thenReturn(new ExecutableOutput(0, pkgMgrVersionOutput, ""));
    DpkgPkgDetailsResolver dpkgVersionResolver = new DpkgPkgDetailsResolver();
    DpkgPackageManagerResolver pkgMgr = new DpkgPackageManagerResolver(dpkgVersionResolver);
    List<PackageDetails> pkgs = pkgMgr.resolvePackages(new ClangPackageManagerInfoFactory().dpkg(), executableRunner, null, pkgMgrOwnedByOutput);
    assertEquals(1, pkgs.size());
    assertEquals("libc6-dev", pkgs.get(0).getPackageName());
    assertEquals("2.27-3ubuntu1", pkgs.get(0).getPackageVersion());
    assertEquals("amd64", pkgs.get(0).getPackageArch());
}
Also used : ClangPackageManagerInfoFactory(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerInfoFactory) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) DpkgPackageManagerResolver(com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.DpkgPackageManagerResolver) DpkgPkgDetailsResolver(com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.DpkgPkgDetailsResolver) PackageDetails(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails) Test(org.junit.jupiter.api.Test)

Example 9 with DetectableExecutableRunner

use of com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner in project synopsys-detect by blackducksoftware.

the class LernaPackageDiscovererTest method discoverLernaPackages.

@Test
void discoverLernaPackages() throws ExecutableRunnerException {
    File workingDirectory = new File("workingDir");
    ExecutableTarget lernaExecutable = ExecutableTarget.forCommand("lerna");
    DetectableExecutableRunner executableRunner = Mockito.mock(DetectableExecutableRunner.class);
    Mockito.when(executableRunner.execute(Mockito.any(Executable.class))).thenReturn(new ExecutableOutput(0, String.join(System.lineSeparator(), "[", "  {", "    \"name\": \"@lerna/packageA\",", "    \"version\": \"1.2.3\",", "    \"private\": false,", "    \"location\": \"/source/packages/packageA\"", "  },", "  {", "    \"name\": \"@lerna/packageB\",", "    \"version\": \"3.2.1\",", "    \"private\": true,", "    \"location\": \"/source/packages/packageB\"", "  },", "  {", "    \"name\": \"@lerna/packageC\",", "    \"version\": \"1.1.1\",", "    \"private\": true,", "    \"location\": \"/source/packages/packageC\"", "  }", "]"), ""));
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    LernaPackageDiscoverer lernaPackageDiscoverer = new LernaPackageDiscoverer(executableRunner, gson, Collections.singletonList("@lerna/packageC"), new LinkedList<>());
    List<LernaPackage> lernaPackages = lernaPackageDiscoverer.discoverLernaPackages(workingDirectory, lernaExecutable);
    Assertions.assertEquals(2, lernaPackages.size(), "Expected to find two Lerna packages.");
    LernaPackage lernaPackageA = lernaPackages.get(0);
    Assertions.assertEquals("@lerna/packageA", lernaPackageA.getName());
    Assertions.assertEquals("1.2.3", lernaPackageA.getVersion());
    Assertions.assertFalse(lernaPackageA.isPrivate());
    Assertions.assertEquals("/source/packages/packageA", lernaPackageA.getLocation());
    LernaPackage lernaPackageB = lernaPackages.get(1);
    Assertions.assertEquals("@lerna/packageB", lernaPackageB.getName());
    Assertions.assertEquals("3.2.1", lernaPackageB.getVersion());
    Assertions.assertTrue(lernaPackageB.isPrivate());
    Assertions.assertEquals("/source/packages/packageB", lernaPackageB.getLocation());
}
Also used : DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) GsonBuilder(com.google.gson.GsonBuilder) LernaPackageDiscoverer(com.synopsys.integration.detectable.detectables.lerna.LernaPackageDiscoverer) Gson(com.google.gson.Gson) LernaPackage(com.synopsys.integration.detectable.detectables.lerna.model.LernaPackage) Executable(com.synopsys.integration.executable.Executable) File(java.io.File) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) Test(org.junit.jupiter.api.Test)

Example 10 with DetectableExecutableRunner

use of com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner in project synopsys-detect by blackducksoftware.

the class IntermediateStepExecuteBazelOnEachLineTest method testNoInput.

@Test
public void testNoInput() throws ExecutableRunnerException, IntegrationException, ExecutableFailedException {
    File workspaceDir = new File(".");
    DetectableExecutableRunner executableRunner = Mockito.mock(DetectableExecutableRunner.class);
    ExecutableTarget bazelExe = ExecutableTarget.forCommand("/usr/bin/bazel");
    ExecutableOutput bazelCmdExecutableOutput = Mockito.mock(ExecutableOutput.class);
    Mockito.when(bazelCmdExecutableOutput.getReturnCode()).thenReturn(0);
    Mockito.when(bazelCmdExecutableOutput.getStandardOutput()).thenReturn("@org_apache_commons_commons_io//jar:jar\n@com_google_guava_guava//jar:jar");
    Mockito.when(executableRunner.executeSuccessfully(Mockito.any(Executable.class))).thenReturn(bazelCmdExecutableOutput);
    BazelCommandExecutor bazelCommandExecutor = new BazelCommandExecutor(executableRunner, workspaceDir, bazelExe);
    BazelVariableSubstitutor bazelVariableSubstitutor = new BazelVariableSubstitutor("//:ProjectRunner", null);
    IntermediateStep executor = new IntermediateStepExecuteBazelOnEachLine(bazelCommandExecutor, bazelVariableSubstitutor, Arrays.asList("cquery", "filter(\\\"@.*:jar\\\", deps(${detect.bazel.target}))"), false);
    List<String> input = new ArrayList<>(0);
    List<String> output = executor.process(input);
    assertEquals(1, output.size());
    assertEquals("@org_apache_commons_commons_io//jar:jar\n@com_google_guava_guava//jar:jar", output.get(0));
}
Also used : DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) IntermediateStep(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.IntermediateStep) ArrayList(java.util.ArrayList) BazelVariableSubstitutor(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelVariableSubstitutor) Executable(com.synopsys.integration.executable.Executable) File(java.io.File) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) BazelCommandExecutor(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.BazelCommandExecutor) IntermediateStepExecuteBazelOnEachLine(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.IntermediateStepExecuteBazelOnEachLine) Test(org.junit.jupiter.api.Test)

Aggregations

DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)17 Test (org.junit.jupiter.api.Test)14 Executable (com.synopsys.integration.executable.Executable)9 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)9 Extraction (com.synopsys.integration.detectable.extraction.Extraction)7 File (java.io.File)7 DisabledOnOs (org.junit.jupiter.api.condition.DisabledOnOs)5 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)4 ClangPackageManagerInfoFactory (com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerInfoFactory)3 PackageDetails (com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails)3 ArrayList (java.util.ArrayList)3 Gson (com.google.gson.Gson)2 FileFinder (com.synopsys.integration.common.util.finder.FileFinder)2 ClangPackageManager (com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManager)2 ClangPackageManagerRunner (com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerRunner)2 DpkgPackageManagerResolver (com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.DpkgPackageManagerResolver)2 DpkgPkgDetailsResolver (com.synopsys.integration.detectable.detectables.clang.packagemanager.resolver.DpkgPkgDetailsResolver)2 GoModCliExtractor (com.synopsys.integration.detectable.detectables.go.gomod.GoModCliExtractor)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2