Skip to content

Commit

Permalink
Handled the boolean parameter issue
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalhcl-5960 committed Nov 9, 2023
1 parent a62a8fa commit aaed4ea
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/hcl/appscan/sdk/CoreConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public interface CoreConstants {
String ERROR_UPLOADING_FILE = "error.upload.file"; //$NON-NLS-1$
String ERROR_GETTING_INFO = "error.getting.info"; //$NON-NLS-1$
String ERROR_URL_VALIDATION = "error.url.validation"; //$NON-NLS-1$
String WARNING_SCA = "warning.sca"; //$NON-NLS-1$
String FORMAT_PARAMS = "FormatParams"; //$NON-NLS-1$

// ASE Status Messages
Expand Down
32 changes: 29 additions & 3 deletions src/main/java/com/hcl/appscan/sdk/http/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -170,12 +171,37 @@ public HttpResponse postForm(String url,
return post(url, headerProperties, body);
}

public HttpResponse postFormNew(String url, Map<String, String> headerProperties, Map<String, String> params)
/**
* Submit a form with parameters using the post request, mainly for v4 APIs.
*
* @param url The URL string.
* @param headerProperties An optional Map of header properties.
* @param params An optional Map of parameters.
* @return The response as a byte array.
* @throws IOException If an error occurs.
*/
public HttpResponse postFormV4(String url, Map<String, String> headerProperties, Map<String, String> params)
throws IOException {
JSONObject json = new JSONObject(params);
Map<String, Object> objectMap = new HashMap<>();
for (String key : params.keySet()) {
String value = params.get(key);
if (value != null) {
if (value.equalsIgnoreCase("true")) {
objectMap.put(key, true);
} else if (value.equalsIgnoreCase("false")) {
objectMap.put(key, false);
} else {
// If the string is not "true" or "false," keep it as is
objectMap.put(key, value);
}
} else {
// If the value is not a string, keep it as is
objectMap.put(key, value);
}
}
JSONObject json = new JSONObject(objectMap);
String body = json.toString();
return post(url, headerProperties, body);

}

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/hcl/appscan/sdk/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ error.http=Response Code: {0}\nReason: {1}
error.login.type.deprectated=The specified login type is deprecated. Please use API key and secret.
error.getting.info=An error occurred getting information for {0} with id {1}.
error.url.validation = An error occurred while validating the URL.
warning.sca = Note: To scan open-source files, use the Software Composition Analysis (SCA) scan type. AppScan on Cloud is phasing out open source-only scanning with static analysis scans.

#Presence
error.getting.presence.details=An error occurred retrieving details for Presence with id {0}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ public String createAndExecuteScan(String type, Map<String, String> params) {
Map<String, String> request_headers = m_authProvider.getAuthorizationHeader(true);
String request_url;
if(type.equals("Sca")) {
// To execute the SCA scan we are using the V4 APIs.
request_url = m_authProvider.getServer() + String.format(API_SCANNER_V4, "Sca");
params.remove("EnableMailNotification");
params.remove("FullyAutomatic");
params.remove("acceptInvalidCerts");
request_headers.put("Content-Type", "application/json");
request_headers.put("accept", "application/json");
} else {
Expand All @@ -73,7 +71,7 @@ public String createAndExecuteScan(String type, Map<String, String> params) {
try {
HttpResponse response;
if (type.equals("Sca")) {
response = client.postFormNew(request_url,request_headers,params);
response = client.postFormV4(request_url,request_headers,params);
} else {
response = client.postForm(request_url, request_headers, params);
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/hcl/appscan/sdk/scanners/sast/SASTScan.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.hcl.appscan.sdk.error.ScannerException;
import com.hcl.appscan.sdk.logging.DefaultProgress;
import com.hcl.appscan.sdk.logging.IProgress;
import com.hcl.appscan.sdk.logging.Message;
import com.hcl.appscan.sdk.scan.IScanServiceProvider;
import com.hcl.appscan.sdk.scanners.ASoCScan;
import com.hcl.appscan.sdk.utils.ArchiveUtil;
Expand Down Expand Up @@ -47,6 +48,10 @@ public void run() throws ScannerException, InvalidTargetException {
if(target == null || !(new File(target).exists()))
throw new InvalidTargetException(Messages.getMessage(TARGET_INVALID, target));

if (getProperties().containsKey(OPEN_SOURCE_ONLY)){
getProgress().setStatus(new Message(Message.WARNING, Messages.getMessage(CoreConstants.WARNING_SCA)));
}

try {
if(getProperties().containsKey(CoreConstants.UPLOAD_DIRECT)){
generateZip();
Expand Down

0 comments on commit aaed4ea

Please sign in to comment.