Skip to content

Commit

Permalink
SCA resolver fixes for linux. CxOrigin double headers fix. (#185)
Browse files Browse the repository at this point in the history
* Fix bug number

* Sca resolver fixes for linux

Co-authored-by: Margarital <[email protected]>
  • Loading branch information
umeshwaghode and Margarital authored Dec 13, 2021
1 parent 7d653ba commit b919866
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
11 changes: 4 additions & 7 deletions src/main/java/com/cx/restclient/ast/AstScaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,15 @@ private HttpResponse submitScaResolverEvidenceFile(AstScaConfig scaConfig) throw
String pathToResultJSONFile = "";
File zipFile = new File("");
pathToResultJSONFile = getScaResolverResultFilePathFromAdditionalParams(scaConfig.getScaResolverAddParameters());

log.info("Path to the evidence file" + pathToResultJSONFile);
int exitCode = SpawnScaResolver.runScaResolver(scaConfig.getPathToScaResolver(), scaConfig.getScaResolverAddParameters(),pathToResultJSONFile);
if (exitCode == 0) {
log.info("Sca Resolver Evidence File Generated.");
log.info("Path of Evidence File" + pathToResultJSONFile);
log.info("SCA resolution completed successfully.");
File resultFilePath = new File(pathToResultJSONFile);
zipFile = zipEvidenceFile(resultFilePath);

}else{
throw new CxClientException("Error while running sca resolver executable.");
throw new CxClientException("Error while running sca resolver executable. Exit code:"+exitCode);
}
return initiateScanForUpload(projectId, FileUtils.readFileToByteArray(zipFile), config.getAstScaConfig());
}
Expand Down Expand Up @@ -435,9 +434,7 @@ private File zipEvidenceFile(File filePath) throws IOException {
long maxZipSizeBytes = config.getMaxZipSize() != null ? config.getMaxZipSize() * 1024 * 1024 : MAX_ZIP_SIZE_BYTES;

List<String> paths = new ArrayList <String>();
paths.add(filePath.getName());
log.info("Paths Variable: " + paths.get(0));

paths.add(filePath.getName());

try (NewCxZipFile zipper = new NewCxZipFile(tempUploadFile, maxZipSizeBytes, log)) {
zipper.addMultipleFilesToArchive(new File(sourceDir), paths);
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/com/cx/restclient/ast/SpawnScaResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.commons.lang3.SystemUtils;
import org.slf4j.Logger;

/**
Expand All @@ -14,7 +16,7 @@

public class SpawnScaResolver {

public static final String SCA_RESOLVER_EXE = "ScaResolver.exe";
public static final String SCA_RESOLVER_EXE = "ScaResolver";
public static final String OFFLINE = "offline";

/**
Expand All @@ -34,7 +36,12 @@ protected static int runScaResolver(String pathToScaResolver, String scaResolver
*/
arguments = scaResolverAddParams.split(" ");
scaResolverCommand = new String[arguments.length + 2];
scaResolverCommand[0] = pathToScaResolver + File.separator + SCA_RESOLVER_EXE;

pathToScaResolver = pathToScaResolver + File.separator + SCA_RESOLVER_EXE;
if(!SystemUtils.IS_OS_UNIX)
pathToScaResolver = pathToScaResolver + ".exe";

scaResolverCommand[0] = pathToScaResolver;
scaResolverCommand[1] = OFFLINE;
for (int i = 0 ; i < arguments.length ; i++){

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/cx/restclient/httpClient/CxHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,9 @@ public TokenLoginResponse generateToken(LoginSettings settings) throws IOExcepti
}
ClientType.RESOURCE_OWNER.setScopes("sast_rest_api");
settings.setClientTypeForPasswordAuth(ClientType.RESOURCE_OWNER);
requestEntity = getAuthRequest(settings);
return request(post, ContentType.APPLICATION_FORM_URLENCODED.toString(), requestEntity,
UrlEncodedFormEntity requestEntityForSecondLoginRetry = getAuthRequest(settings);
HttpPost post_1 = new HttpPost(settings.getAccessControlBaseUrl());
return request(post_1, ContentType.APPLICATION_FORM_URLENCODED.toString(), requestEntityForSecondLoginRetry,
TokenLoginResponse.class, HttpStatus.SC_OK, AUTH_MESSAGE, false, false);
}
}
Expand Down

0 comments on commit b919866

Please sign in to comment.