Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the logic for getting the scan id #41

Merged
merged 1 commit into from
Sep 9, 2024
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
15 changes: 8 additions & 7 deletions src/client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022, 2023 HCL America, Inc.
Copyright 2022, 2024 HCL America, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -160,19 +160,20 @@ function analysisTimedOut() {
}

function getScanId(output) {
return new Promise((resolve, reject) => {
let lines = eol.split(output);
let scanId = lines[lines.length - 2];
return new Promise((resolve) => {
let lines = eol.split(output.trim());
let scanId = lines[lines.length - 1];
//Make sure we have a valid scan id.
let regex = /[0-9a-fA-f]{8}-[0-9a-fA-f]{4}-[0-9a-fA-f]{4}-[0-9a-fA-f]{4}-[0-9a-fA-f]{12}/;
let matches = scanId.match(regex);

if(!matches) {
//If we didn't get a match, check the next line
scanId = lines[lines.length - 1];
//If we didn't get a match, check the previous line
scanId = lines[lines.length - 2];
matches = scanId.match(regex);
if(!matches) {
return reject(constants.ERROR_BAD_SCAN_ID);
//If still no match, log it.
return resolve(constants.NO_SCAN_ID);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const _TOTAL_ISSUES = 'Total issues: ';
export { _TOTAL_ISSUES as TOTAL_ISSUES };
const _ISSUES_COLON = ' issues: ';
export { _ISSUES_COLON as ISSUES_COLON };
const _NO_SCAN_ID = 'The scan was submitted, but a problem occurred retrieving the scan id.';
export { _NO_SCAN_ID as NO_SCAN_ID };

//Error messages:
const _ERROR_DOWNLOADING_CLIENT = 'An error occurred downloading the SAClientUtil. Status code ';
Expand Down
Loading