Skip to content

Commit e10b2b6

Browse files
author
Mithilesh Pawar
authored
Renamed the format flag to support the new name 'scan-info-format' (#64)
* Renamed the format flag to support the new name 'scan-info-format' * Github Actions: JDK Distributions set to 'temurin'. Previously used 'adopt' wont be receving any updates. * Added encoding property to avoid the warning in the log. * Removed the redundant test * Changed the name of the AST project for tests. Also added an agent name for the same project. * Updated the logger messages. * Tests migrated to Junit5 * Updated maven-source-plugin to 3.2.1 * Updated nexus-staging-maven-plugin from 1.6.7 to 1.6.8
1 parent a2015f2 commit e10b2b6

File tree

13 files changed

+83
-96
lines changed

13 files changed

+83
-96
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
- name: Set up JDK 8
1313
uses: actions/[email protected]
1414
with:
15+
distribution: 'temurin'
1516
java-version: 8
1617

1718
- name: Cache local Maven repository

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
uses: actions/[email protected]
3030
with:
3131
java-version: '11'
32-
distribution: 'adopt'
32+
distribution: 'temurin'
3333
server-id: ossrh
3434
server-username: MAVEN_USERNAME
3535
server-password: MAVEN_PASSWORD

pom.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<url>https://www.checkmarx.com</url>
1414

1515
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1617
<ast.wrapper.version>dev</ast.wrapper.version>
1718
<maven.compiler.source>8</maven.compiler.source>
1819
<maven.compiler.target>8</maven.compiler.target>
@@ -40,12 +41,6 @@
4041
<version>1.2.6</version>
4142
<scope>test</scope>
4243
</dependency>
43-
<dependency>
44-
<groupId>junit</groupId>
45-
<artifactId>junit</artifactId>
46-
<version>4.13.1</version>
47-
<scope>test</scope>
48-
</dependency>
4944
<dependency>
5045
<groupId>org.projectlombok</groupId>
5146
<artifactId>lombok</artifactId>
@@ -64,13 +59,18 @@
6459
<dependency>
6560
<groupId>org.junit.jupiter</groupId>
6661
<artifactId>junit-jupiter</artifactId>
67-
<version>5.7.2</version>
62+
<version>5.8.2</version>
6863
<scope>test</scope>
6964
</dependency>
7065
</dependencies>
7166

7267
<build>
7368
<plugins>
69+
<plugin>
70+
<groupId>org.apache.maven.plugins</groupId>
71+
<artifactId>maven-surefire-plugin</artifactId>
72+
<version>2.22.2</version>
73+
</plugin>
7474
<plugin>
7575
<groupId>org.codehaus.mojo</groupId>
7676
<artifactId>exec-maven-plugin</artifactId>
@@ -99,7 +99,7 @@
9999
<plugin>
100100
<groupId>org.apache.maven.plugins</groupId>
101101
<artifactId>maven-source-plugin</artifactId>
102-
<version>3.0.1</version>
102+
<version>3.2.1</version>
103103
<executions>
104104
<execution>
105105
<id>attach-sources</id>
@@ -112,7 +112,7 @@
112112
<plugin>
113113
<groupId>org.sonatype.plugins</groupId>
114114
<artifactId>nexus-staging-maven-plugin</artifactId>
115-
<version>1.6.7</version>
115+
<version>1.6.8</version>
116116
<extensions>true</extensions>
117117
<configuration>
118118
<serverId>ossrh</serverId>

src/main/java/com/checkmarx/ast/wrapper/CxConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public final class CxConstants {
3030
static final String SUB_CMD_UPDATE = "update";
3131
static final String CMD_RESULT = "result";
3232
static final String FORMAT = "--format";
33+
static final String SCAN_INFO_FORMAT = "--scan-info-format";
3334
static final String FORMAT_JSON = "json";
3435
static final String FILTER = "--filter";
3536
static final String SCAN_ID = "--scan-id";

src/main/java/com/checkmarx/ast/wrapper/CxThinWrapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ public CxThinWrapper() throws IOException {
2323
public CxThinWrapper(@NonNull Logger logger) throws IOException {
2424
this.logger = logger;
2525
this.executable = Execution.getTempBinary();
26-
this.logger.info("using executable: " + executable);
26+
this.logger.info("Executable path: " + executable);
2727
}
2828

2929
public String run(@NonNull String arguments) throws CxException, IOException, InterruptedException {
30-
this.logger.info("executing thin wrapper command");
30+
this.logger.info("Executing commands with thin wrapper.");
3131
List<String> argv = new ArrayList<>();
3232
argv.add(executable);
3333
argv.addAll(Arrays.asList(arguments.split(" ")));

src/main/java/com/checkmarx/ast/wrapper/CxWrapper.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ public CxWrapper(@NonNull CxConfig cxConfig, @NonNull Logger logger) throws CxCo
4646
this.executable = StringUtils.isBlank(this.cxConfig.getPathToExecutable())
4747
? Execution.getTempBinary()
4848
: this.cxConfig.getPathToExecutable();
49-
this.logger.info("using executable: " + executable);
49+
this.logger.info("Executable path: " + executable);
5050
}
5151

5252
public String authValidate() throws IOException, InterruptedException, CxException {
53-
this.logger.info("initialized authentication validation command");
53+
this.logger.info("Executing 'auth validate' command using the CLI.");
5454

5555
List<String> arguments = new ArrayList<>();
5656
arguments.add(CxConstants.CMD_AUTH);
@@ -60,7 +60,7 @@ public String authValidate() throws IOException, InterruptedException, CxExcepti
6060
}
6161

6262
public Scan scanShow(@NonNull UUID scanId) throws IOException, InterruptedException, CxException {
63-
this.logger.info("initialized scan retrieval for id: {}", scanId);
63+
this.logger.info("Retrieving the details for scan id: {}", scanId);
6464

6565
List<String> arguments = new ArrayList<>();
6666
arguments.add(CxConstants.CMD_SCAN);
@@ -77,7 +77,7 @@ public List<Scan> scanList() throws IOException, InterruptedException, CxExcepti
7777
}
7878

7979
public List<Scan> scanList(String filter) throws IOException, InterruptedException, CxException {
80-
this.logger.info("initialized retrieval for scan list {}", filter);
80+
this.logger.info("Fetching the scan list using the filter: {}", filter);
8181

8282
List<String> arguments = new ArrayList<>();
8383
arguments.add(CxConstants.CMD_SCAN);
@@ -94,12 +94,13 @@ public Scan scanCreate(@NonNull Map<String, String> params) throws IOException,
9494

9595
public Scan scanCreate(@NonNull Map<String, String> params, String additionalParameters)
9696
throws IOException, InterruptedException, CxException {
97-
this.logger.info("initialized scan create command");
97+
this.logger.info("Executing 'scan create' command using the CLI.");
9898

9999
List<String> arguments = new ArrayList<>();
100100
arguments.add(CxConstants.CMD_SCAN);
101101
arguments.add(CxConstants.SUB_CMD_CREATE);
102-
arguments.addAll(jsonArguments());
102+
arguments.add(CxConstants.SCAN_INFO_FORMAT);
103+
arguments.add(CxConstants.FORMAT_JSON);
103104

104105
for (Map.Entry<String, String> param : params.entrySet()) {
105106
arguments.add(param.getKey());
@@ -112,7 +113,8 @@ public Scan scanCreate(@NonNull Map<String, String> params, String additionalPar
112113
}
113114

114115
public List<Predicate> triageShow(@NonNull UUID projectId, String similarityId, String scanType) throws IOException, InterruptedException, CxException {
115-
this.logger.info("initialized triage for project with id: {}", projectId);
116+
this.logger.info("Executing 'triage show' command using the CLI.");
117+
this.logger.info("Fetching the list of predicates for projectId {} , similarityId {} and scan-type {}.,", projectId, similarityId, scanType);
116118

117119
List<String> arguments = new ArrayList<>();
118120
arguments.add(CxConstants.CMD_TRIAGE);
@@ -130,7 +132,8 @@ public List<Predicate> triageShow(@NonNull UUID projectId, String similarityId,
130132
}
131133

132134
public void triageUpdate(@NonNull UUID projectId, String similarityId, String scanType, String state, String comment, String severity) throws IOException, InterruptedException, CxException {
133-
this.logger.info("initialized triage update project with id: {}", projectId);
135+
this.logger.info("Executing 'triage update' command using the CLI.");
136+
this.logger.info("Updating the similarityId {} with state {} and severity {}.", similarityId, state, severity);
134137

135138
List<String> arguments = new ArrayList<>();
136139
arguments.add(CxConstants.CMD_TRIAGE);
@@ -154,7 +157,7 @@ public void triageUpdate(@NonNull UUID projectId, String similarityId, String sc
154157
}
155158

156159
public Project projectShow(@NonNull UUID projectId) throws IOException, InterruptedException, CxException {
157-
this.logger.info("initialized project retrieval for id: {}", projectId);
160+
this.logger.info("Retrieving the details for project id: {}", projectId);
158161

159162
List<String> arguments = new ArrayList<>();
160163
arguments.add(CxConstants.CMD_PROJECT);
@@ -171,7 +174,7 @@ public List<Project> projectList() throws IOException, InterruptedException, CxE
171174
}
172175

173176
public List<Project> projectList(String filter) throws IOException, InterruptedException, CxException {
174-
this.logger.info("initialized retrieval for project list {}", filter);
177+
this.logger.info("Fetching the project list using the filter: {}", filter);
175178

176179
List<String> arguments = new ArrayList<>();
177180
arguments.add(CxConstants.CMD_PROJECT);
@@ -184,7 +187,7 @@ public List<Project> projectList(String filter) throws IOException, InterruptedE
184187

185188
public List<String> projectBranches(@NonNull UUID projectId, String filter)
186189
throws CxException, IOException, InterruptedException {
187-
this.logger.info("initialized retrieval for project branches {}", filter);
190+
this.logger.info("Fetching the branches for project id {} using the filter: {}", projectId, filter);
188191

189192
List<String> arguments = new ArrayList<>();
190193
arguments.add(CxConstants.CMD_PROJECT);
@@ -212,7 +215,7 @@ public Results results(@NonNull UUID scanId) throws IOException, InterruptedExce
212215

213216
public String results(@NonNull UUID scanId, ReportFormat reportFormat)
214217
throws IOException, InterruptedException, CxException {
215-
this.logger.info("initialized results command {}", reportFormat);
218+
this.logger.info("Retrieving the scan result for scan id {}", scanId);
216219

217220
String tempDir = Files.createTempDirectory("cx").toAbsolutePath().toString();
218221
String fileName = Long.toString(System.nanoTime());

src/test/java/com/checkmarx/ast/AuthTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@
44
import com.checkmarx.ast.wrapper.CxException;
55
import com.checkmarx.ast.wrapper.CxWrapper;
66
import org.junit.Assert;
7-
import org.junit.Test;
7+
import org.junit.jupiter.api.Assertions;
8+
import org.junit.jupiter.api.Test;
89

910
import java.io.IOException;
1011

1112
public class AuthTest extends BaseTest {
1213

1314
@Test
1415
public void testAuthValidate() throws CxException, IOException, InterruptedException {
15-
Assert.assertNotNull(wrapper.authValidate());
16+
Assertions.assertNotNull(wrapper.authValidate());
1617
}
1718

1819
@Test
1920
public void testAuthFailure() {
2021
CxConfig cxConfig = getConfig();
2122
cxConfig.setBaseAuthUri("wrongAuth");
22-
Assert.assertThrows(CxException.class, () -> new CxWrapper(cxConfig, getLogger()).authValidate());
23+
Assertions.assertThrows(CxException.class, () -> new CxWrapper(cxConfig, getLogger()).authValidate());
2324
}
2425
}

src/test/java/com/checkmarx/ast/BaseTest.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.checkmarx.ast.wrapper.CxConfig;
44
import com.checkmarx.ast.wrapper.CxConstants;
55
import com.checkmarx.ast.wrapper.CxWrapper;
6-
import org.junit.Before;
6+
import org.junit.jupiter.api.BeforeEach;
77
import org.slf4j.Logger;
88
import org.slf4j.LoggerFactory;
99

@@ -13,8 +13,9 @@
1313
public abstract class BaseTest {
1414

1515
protected CxWrapper wrapper;
16+
private String projectId;
1617

17-
@Before
18+
@BeforeEach
1819
public void init() throws Exception {
1920
wrapper = new CxWrapper(getConfig(), getLogger());
2021
}
@@ -35,15 +36,15 @@ protected Logger getLogger() {
3536

3637
protected static CxConfig getConfig() {
3738
return CxConfig.builder()
38-
.baseUri(CX_BASE_URI)
39-
.baseAuthUri(CX_BASE_AUTH_URI)
40-
.tenant(CX_TENANT)
41-
.apiKey(CX_APIKEY)
42-
.clientId(CX_CLIENT_ID)
43-
.clientSecret(CX_CLIENT_SECRET)
44-
.additionalParameters(CX_ADDITIONAL_PARAMETERS)
45-
.pathToExecutable(PATH_TO_EXECUTABLE)
46-
.build();
39+
.baseUri(CX_BASE_URI)
40+
.baseAuthUri(CX_BASE_AUTH_URI)
41+
.tenant(CX_TENANT)
42+
.apiKey(CX_APIKEY)
43+
.clientId(CX_CLIENT_ID)
44+
.clientSecret(CX_CLIENT_SECRET)
45+
.additionalParameters(CX_ADDITIONAL_PARAMETERS)
46+
.pathToExecutable(PATH_TO_EXECUTABLE)
47+
.build();
4748
}
4849

4950
private static String getEnvOrNull(String key) {
@@ -52,11 +53,12 @@ private static String getEnvOrNull(String key) {
5253

5354
protected Map<String, String> commonParams() {
5455
Map<String, String> params = new HashMap<>();
55-
params.put(CxConstants.PROJECT_NAME, "JavaWrapperTestCases");
56+
params.put(CxConstants.PROJECT_NAME, "AST-CLI-Java-Wrapper-Tests");
5657
params.put(CxConstants.SOURCE, ".");
57-
params.put(CxConstants.FILE_FILTER, "*.java");
58+
params.put(CxConstants.FILE_FILTER, "!test");
5859
params.put(CxConstants.BRANCH, "main");
5960
params.put(CxConstants.SAST_PRESET_NAME, "Checkmarx Default");
61+
params.put(CxConstants.AGENT, "AST-CLI-Java-Wrapper");
6062
return params;
6163
}
6264
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package com.checkmarx.ast;
22

33
import com.checkmarx.ast.predicate.Predicate;
4-
import com.checkmarx.ast.project.Project;
54
import com.checkmarx.ast.results.Results;
65
import com.checkmarx.ast.results.result.Result;
76
import com.checkmarx.ast.scan.Scan;
87
import com.checkmarx.ast.wrapper.CxConstants;
9-
import org.junit.Assert;
10-
import org.junit.Test;
8+
import org.junit.jupiter.api.Assertions;
9+
import org.junit.jupiter.api.Test;
1110

1211
import java.util.List;
1312
import java.util.UUID;
@@ -20,22 +19,22 @@ public class PredicateTest extends BaseTest {
2019
public void testTriageShow() throws Exception {
2120
List<Scan> scanList = wrapper.scanList(String.format("statuses=Completed"));
2221
Scan scan = scanList.get(0);
23-
Assert.assertTrue(scanList.size() > 0);
22+
Assertions.assertTrue(scanList.size() > 0);
2423
String scanId = scanList.get(0).getID();
2524

2625
Results results = wrapper.results(UUID.fromString(scanId));
2726
Result result = results.getResults().stream().filter(res -> res.getType().equalsIgnoreCase(CxConstants.SAST)).findFirst().get();
2827

2928
List<Predicate> predicates = wrapper.triageShow(UUID.fromString(scan.getProjectID()), result.getSimilarityId(), result.getType());
3029

31-
Assert.assertNotNull(predicates);
30+
Assertions.assertNotNull(predicates);
3231
}
3332

3433
@Test
3534
public void testTriageUpdate() throws Exception {
3635
List<Scan> scanList = wrapper.scanList(String.format("statuses=Completed"));
3736
Scan scan = scanList.get(0);
38-
Assert.assertTrue(scanList.size() > 0);
37+
Assertions.assertTrue(scanList.size() > 0);
3938
String scanId = scanList.get(0).getID();
4039

4140
Results results = wrapper.results(UUID.fromString(scanId));
@@ -44,7 +43,7 @@ public void testTriageUpdate() throws Exception {
4443
try {
4544
wrapper.triageUpdate(UUID.fromString(scan.getProjectID()), result.getSimilarityId(), result.getType(), "to_verify", "Edited via Java Wrapper", "high");
4645
} catch (Exception e) {
47-
fail("Triage update failed. Should not throw exception");
46+
Assertions.fail("Triage update failed. Should not throw exception");
4847
}
4948
}
5049
}

src/test/java/com/checkmarx/ast/ProjectTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import com.checkmarx.ast.project.Project;
44
import com.checkmarx.ast.scan.Scan;
55
import com.checkmarx.ast.wrapper.CxConstants;
6-
import org.junit.Assert;
7-
import org.junit.Test;
6+
import org.junit.jupiter.api.Assertions;
7+
import org.junit.jupiter.api.Test;
88

99
import java.util.List;
1010
import java.util.Map;
@@ -15,15 +15,15 @@ public class ProjectTest extends BaseTest {
1515
@Test
1616
public void testProjectShow() throws Exception {
1717
List<Project> projectList = wrapper.projectList();
18-
Assert.assertTrue(projectList.size() > 0);
18+
Assertions.assertTrue(projectList.size() > 0);
1919
Project project = wrapper.projectShow(UUID.fromString(projectList.get(0).getID()));
20-
Assert.assertEquals(projectList.get(0).getID(), project.getID());
20+
Assertions.assertEquals(projectList.get(0).getID(), project.getID());
2121
}
2222

2323
@Test
2424
public void testProjectList() throws Exception {
2525
List<Project> projectList = wrapper.projectList("limit=10");
26-
Assert.assertTrue(projectList.size() <= 10);
26+
Assertions.assertTrue(projectList.size() <= 10);
2727
}
2828

2929
@Test
@@ -32,7 +32,7 @@ public void testProjectBranches() throws Exception {
3232
params.put(CxConstants.BRANCH, "test");
3333
Scan scan = wrapper.scanCreate(params);
3434
List<String> branches = wrapper.projectBranches(UUID.fromString(scan.getProjectID()), "");
35-
Assert.assertTrue(branches.size() >= 1);
36-
Assert.assertTrue(branches.contains("test"));
35+
Assertions.assertTrue(branches.size() >= 1);
36+
Assertions.assertTrue(branches.contains("test"));
3737
}
3838
}

0 commit comments

Comments
 (0)