Skip to content

Commit 302551e

Browse files
authored
Merge pull request #42 from Qualys/develop
QINT-16843: Github for WAS | Build is failing when SEVERITY_CHECK is false or DISCOVERY scan is enabled when timeout is reached after scan is launched
2 parents 20dd338 + daf21e9 commit 302551e

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/main/java/com/example/GitHubActionsQWas/service/QualysWASScanBuilder.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,11 @@ public void launchWebApplicationScan() {
270270
if (result.has("ServiceResponse") && result.get("ServiceResponse").getAsJsonObject().has("responseCode") && result.get("ServiceResponse").getAsJsonObject().get("responseCode").getAsString().equalsIgnoreCase("SUCCESS")) {
271271
data.get("ServiceResponse").getAsJsonObject().getAsJsonArray("data").get(0).getAsJsonObject().get("WasScan").getAsJsonObject().remove("igs").getAsJsonObject();
272272
data.get("ServiceResponse").getAsJsonObject().getAsJsonArray("data").get(0).getAsJsonObject().get("WasScan").getAsJsonObject().addProperty("ScanId", scanId);
273-
if (!status.equalsIgnoreCase("error") && !status.equalsIgnoreCase("canceled") && !status.equalsIgnoreCase("finished") && isFailOnScanError) {
274-
Helper.dumpDataIntoFile(gson.toJson(data), fileName);
275-
System.exit(1);
273+
if (status != null) {
274+
if (!status.equalsIgnoreCase("error") && !status.equalsIgnoreCase("canceled") && !status.equalsIgnoreCase("finished") && isFailOnScanError) {
275+
Helper.dumpDataIntoFile(gson.toJson(data), fileName);
276+
System.exit(1);
277+
}
276278
}
277279
if (isFailConditionConfigured) {
278280
JsonObject failurePolicyEvaluationResult = evaluateFailurePolicy(result);
@@ -339,7 +341,7 @@ public JsonObject evaluateFailurePolicy(JsonObject result) throws Exception {
339341
*/
340342
private String getScanFinishedStatus(String scanId) {
341343
QualysWASScanStatusService statusService = new QualysWASScanStatusService(client);
342-
String status = statusService.fetchScanStatus(scanId, portalServer, interval, timeout);
344+
String status = statusService.fetchScanStatus(scanId, this.scanType, this.severityCheck, this.portalServer, this.interval, this.timeout);
343345
logger.info(status);
344346
return status;
345347
}

src/main/java/com/example/GitHubActionsQWas/service/QualysWASScanStatusService.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,32 @@ public QualysWASScanStatusService(WASClient client) {
1919
* @param scanId
2020
* @return
2121
*/
22-
public String fetchScanStatus(String scanId, String portalUrl, int INTERVAL, int TIMEOUT) {
22+
public String fetchScanStatus(String scanId, String scanType, boolean severityCheck, String portalUrl, int INTERVAL, int TIMEOUT) {
2323
long startTime = System.currentTimeMillis();
2424
long timeoutInMillis = TimeUnit.MINUTES.toMillis(TIMEOUT);
2525
long intervalInMillis = TimeUnit.MINUTES.toMillis(INTERVAL);
26-
String status = null;
26+
String status = "";
27+
boolean failed = false;
2728

2829
try {
2930
while ((status = client.getScanFinishedStatus(scanId)) == null) {
3031
long endTime = System.currentTimeMillis();
3132
if ((endTime - startTime) > timeoutInMillis) {
32-
logger.info("Failed to get scan result; timeout of " + TIMEOUT + " minutes reached.");
3333
String message1 = "Failed to get scan result; timeout of " + TIMEOUT + " minutes reached.";
3434
String message2 = "Please switch to WAS Classic UI and Check for report...";
3535
String message3 = "To check scan result, please follow the url: " + portalUrl + "/portal-front/module/was/#forward=/module/was/&scan-report=" + scanId;
3636
logger.info(message1);
3737
logger.info(message2);
3838
logger.info(message3);
39-
String message = message1 + "\n" + message2 + "\n" + message3;
40-
Helper.dumpDataIntoFile(message, "Qualys_Wasscan_" + scanId + ".txt");
41-
System.exit(1);
39+
if (scanType.equalsIgnoreCase("vulnerability") && severityCheck) {
40+
failed = true;
41+
}
42+
if (failed) {
43+
String message = message1 + "\n" + message2 + "\n" + message3;
44+
Helper.dumpDataIntoFile(message, "Qualys_Wasscan_" + scanId + ".txt");
45+
System.exit(1);
46+
}
47+
break;
4248
} else {
4349
try {
4450
logger.info("Waiting for " + INTERVAL + " minute(s) before making next attempt for scanResult of scanId:" + scanId + "...");

0 commit comments

Comments
 (0)