Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/main/java/com/checkmarx/ast/wrapper/CxThinWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.checkmarx.ast.wrapper;

import lombok.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class CxThinWrapper {

@NonNull
private final Logger logger;
@NonNull
private final String executable;

public CxThinWrapper() throws IOException {
this(LoggerFactory.getLogger(CxWrapper.class));
}

public CxThinWrapper(@NonNull Logger logger) throws IOException {
this.logger = logger;
this.executable = Execution.getTempBinary();
this.logger.info("using executable: " + executable);
}

public String run(@NonNull String arguments) throws CxException, IOException, InterruptedException {
this.logger.info("executing thin wrapper command");
List<String> argv = new ArrayList<>();
argv.add(executable);
argv.addAll(Arrays.asList(arguments.split(" ")));
return Execution.executeCommand(argv, logger, (line) -> line);
}
}
31 changes: 31 additions & 0 deletions src/test/java/com/checkmarx/ast/ThinWrapperTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.checkmarx.ast;

import com.checkmarx.ast.scan.Scan;
import com.checkmarx.ast.wrapper.CxException;
import com.checkmarx.ast.wrapper.CxThinWrapper;
import lombok.SneakyThrows;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;

public class ThinWrapperTest extends BaseTest {

@SneakyThrows
@Test
public void testThinWrapper() {
CxThinWrapper wrapper = new CxThinWrapper(getLogger());
String result = wrapper.run("scan list --format json --filter limit=10");
List<Scan> scanList = Scan.listFromLine(result);
Assert.assertTrue(scanList.size() <= 10);
}

@SneakyThrows
@Test
public void testThinWrapperFail() {
CxThinWrapper wrapper = new CxThinWrapper(getLogger());
String arguments = "scan create -s . --project-name thin-wrapper-test --sast-preset invalid-preset";
CxException e = Assert.assertThrows(CxException.class, () -> wrapper.run(arguments));
Assert.assertTrue(e.getMessage().contains("--sast-preset"));
}
}