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

Clean html description (AST-40454) #164

Merged
merged 11 commits into from
Dec 4, 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
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public static void beforeClass() throws Exception {
SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";

// Used to decrease tests velocity
SWTBotPreferences.PLAYBACK_DELAY = 100;
SWTBotPreferences.PLAYBACK_DELAY = 500;

SWTBotPreferences.TIMEOUT = 8000;
SWTBotPreferences.TIMEOUT = 20000;

_bot = new SWTWorkbenchBot();

Expand Down Expand Up @@ -205,11 +205,11 @@ protected static void waitWhileTreeNodeEqualsTo(String nodeText) throws TimeoutE

while (_bot.tree().getAllItems()[0].getText().equals(nodeText)) {

if (retryIdx == 10) {
if (retryIdx == 20) {
break;
}

_bot.sleep(1000);
_bot.sleep(1500);

retryIdx++;
}
Expand Down Expand Up @@ -238,7 +238,7 @@ protected static void waitUntilBranchComboIsEnabled() throws TimeoutException {

while (!_bot.comboBox(1).isEnabled()) {

if (retryIdx == 10) {
if (retryIdx == 15) {
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,33 +366,95 @@ private List<DisplayModel> addResults(String scanId, Map<String, List<DisplayMod
return returnList;
}


/**
* Creates a clean Result object with decoded HTML entities
*
* @param resultItem Original result object
* @return New Result object with cleaned values
*/
private Result createCleanResult(Result resultItem) {
elchananarb marked this conversation as resolved.
Show resolved Hide resolved
String cleanDescription = resultItem.getDescription() != null ?
elchananarb marked this conversation as resolved.
Show resolved Hide resolved
cleanHtmlEntities(resultItem.getDescription()) : null;

String cleanDescriptionHTML = resultItem.getDescriptionHTML() != null ?
cleanHtmlEntities(resultItem.getDescriptionHTML()) : null;

return new Result(
resultItem.getType(),
resultItem.getLabel(),
resultItem.getId(),
resultItem.getSimilarityId(),
resultItem.getStatus(),
resultItem.getState(),
resultItem.getSeverity(),
resultItem.getCreated(),
resultItem.getFirstFoundAt(),
resultItem.getFoundAt(),
resultItem.getFirstScan(),
resultItem.getFirstScanId(),
resultItem.getPublishedAt(),
resultItem.getRecommendations(),
cleanDescription,
cleanDescriptionHTML,
resultItem.getData(),
resultItem.getComments(),
resultItem.getVulnerabilityDetails(),
resultItem.getScaType()
);
}

/**
* Helper method to clean HTML entities from text
*
* @param input String containing HTML entities
* @return Cleaned string with decoded HTML entities
*/
private String cleanHtmlEntities(String input) {
if (input == null) return null;
return input
.replace("&#34;", "\"")
.replace("&quot;", "\"")
.replace("&#39;", "'")
.replace("&#35;", "#")
.replace("&#38;", "&")
.replace("&lt;", "<")
.replace("&gt;", ">");
}

/**
* Creates a Display Model which represents each result
*
* @param resultItem
* @return
*
* @param resultItem Result object to transform
* @return DisplayModel representing the result
*/
private DisplayModel transform(Result resultItem) {
List<Node> nodes = Optional.ofNullable(resultItem.getData().getNodes()).orElse(Collections.emptyList());
String queryName = resultItem.getData().getQueryName() != null ? resultItem.getData().getQueryName() : resultItem.getSimilarityId();
String displayName = queryName;
if (nodes.size() > 0) {
Node node = nodes.get(0);
displayName += String.format(" (%s:%d)", new File(node.getFileName()).getName(), node.getLine());
}

return new DisplayModel.DisplayModelBuilder(displayName)
.setSeverity(resultItem.getSeverity())
.setType(resultItem.getType())
.setResult(resultItem)
.setSate(resultItem.getState())
.setQueryName(queryName)
.build();
List<Node> nodes = Optional.ofNullable(resultItem.getData().getNodes()).orElse(Collections.emptyList());

Result cleanResult = createCleanResult(resultItem);

String queryName = cleanResult.getData().getQueryName() != null ?
cleanResult.getData().getQueryName() :
cleanResult.getSimilarityId();

String displayName = queryName;
if (nodes.size() > 0) {
Node node = nodes.get(0);
displayName += String.format(" (%s:%d)", new File(node.getFileName()).getName(), node.getLine());
}

return new DisplayModel.DisplayModelBuilder(displayName)
.setSeverity(cleanResult.getSeverity())
.setType(cleanResult.getType())
.setResult(cleanResult)
.setSate(cleanResult.getState())
.setQueryName(queryName)
.build();
}

/**
* Group results by scanner type
*
*
* @param allResultsTransformed
* @return
*/
Expand Down
Loading