Skip to content
Closed
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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,9 @@
"copymedia": "copyfiles \"media/icons/*\" out/ -E",
"configure-husky": "npx husky install && npx husky add .husky/pre-commit \"npx --no-install lint-staged\"",
"test": "export TEST=true && npm run compile && extest setup-and-run './out/test/**/*test.js' -c 1.87.2 -i -r .",
"test1": "export TEST=true && npm run compile && extest setup-and-run './out/test/1.settings.test.js' './out/test/5.customActions.test.js' -c 1.87.2 -i -r .",
"win-test": "set TEST=true&& npm run compile && extest setup-and-run './out/test/**/*test.js' -c 1.87.2 -i -r .",
"win-test1": "set TEST=true&& npm run compile && extest setup-and-run './out/test/1.settings.test.js' './out/test/5.customActions.test.js' -c 1.87.2 -i -r .",
"unit-test": "mocha --require ts-node/register './src/unit/**/*.test.ts'",
"unit-coverage": "npx nyc npm run unit-test",
"test:ui-end-to-end": "export TEST=uiEndToEnd && npm run compile && extest setup-and-run './out/e2e/getScan.test.js' -c 1.87.2 -i -r .",
Expand Down
133 changes: 77 additions & 56 deletions src/test/5.customActions.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { CustomTreeSection, InputBox, VSBrowser, WebDriver, Workbench } from 'vscode-extension-tester';
import { expect } from 'chai';
import { initialize, sleep, validateRootNode, validateSeverities } from './utils/utils';
import { initialize, validateRootNode, validateSeverities } from './utils/utils';
import { CX_CLEAR, CX_FILTER_CONFIRMED, CX_FILTER_HIGH, CX_FILTER_INFO, CX_FILTER_LOW, CX_FILTER_MEDIUM, CX_FILTER_NOT_EXPLOITABLE, CX_FILTER_NOT_IGNORED, CX_FILTER_PROPOSED_NOT_EXPLOITABLE, CX_FILTER_TO_VERIFY, CX_FILTER_URGENT, CX_GROUP_FILE, CX_GROUP_LANGUAGE, CX_GROUP_QUERY_NAME, CX_GROUP_STATE, CX_GROUP_STATUS, CX_LOOK_SCAN, SAST_TYPE, SCAN_KEY_TREE_LABEL } from './utils/constants';
import { SCAN_ID } from './utils/envs';
import { stringify } from 'querystring';

describe("filter and groups actions tests", () => {
let bench: Workbench;
Expand All @@ -22,7 +23,6 @@ describe("filter and groups actions tests", () => {
});

it("should click on all filter severity", async function () {
treeScans = await initialize();
await bench.executeCommand(CX_LOOK_SCAN);
let input = await InputBox.create();
await input.setText(
Expand All @@ -32,7 +32,8 @@ describe("filter and groups actions tests", () => {
const commands = [{ command: CX_FILTER_INFO, text: "INFO" }, { command: CX_FILTER_LOW, text: "LOW" }, { command: CX_FILTER_MEDIUM, text: "MEDIUM" }, { command: CX_FILTER_HIGH, text: "HIGH" }, { command: CX_FILTER_HIGH, text: "CRITICAL" }];
for (var index in commands) {
await bench.executeCommand(commands[index].command);
treeScans = await initialize();
console.log("treeScans:", treeScans);
console.log("treeScans(Json):", JSON.stringify(treeScans));
let scan = await treeScans?.findItem(
SCAN_KEY_TREE_LABEL
);
Expand All @@ -41,6 +42,8 @@ describe("filter and groups actions tests", () => {
SCAN_KEY_TREE_LABEL
);
}
console.log("scan:", scan);
console.log("scan(Json):", JSON.stringify(scan));
let isValidated = await validateSeverities(scan, commands[index].text);

expect(isValidated).to.equal(true);
Expand All @@ -49,7 +52,7 @@ describe("filter and groups actions tests", () => {
}
});

it.skip("should click on all group by", async function () {
it("should click on all group by", async function () {
const commands = [
CX_GROUP_LANGUAGE,
CX_GROUP_STATUS,
Expand All @@ -58,89 +61,107 @@ describe("filter and groups actions tests", () => {
CX_GROUP_FILE,
];
// Get scan node
const treeScans = await initialize();
// Ensure the Checkmarx Results tree view is focused
console.log("[GroupBy Test 1] Focusing Checkmarx Results view via command:", CX_LOOK_SCAN);
await bench.executeCommand(CX_LOOK_SCAN);


console.log("treeScans:", treeScans);
console.log("treeScans(Json):", JSON.stringify(treeScans));
console.log("[GroupBy Test 1] initialize() returned treeScans:", !!treeScans);
let scan = await treeScans?.findItem(SCAN_KEY_TREE_LABEL);
while (scan === undefined) {
scan = await treeScans?.findItem(SCAN_KEY_TREE_LABEL);
{
const start = Date.now();
console.log("[GroupBy Test 1] Searching for scan node:", SCAN_KEY_TREE_LABEL);
while (scan === undefined && Date.now() - start < 15000) {
scan = await treeScans?.findItem(SCAN_KEY_TREE_LABEL);
}
console.log("[GroupBy Test 1] scan node found:", !!scan, "elapsed(ms):", Date.now() - start);
expect(scan).to.not.be.undefined;
}
console.log("scan:", scan);
console.log("scan(Json):", JSON.stringify(scan));
// Expand and validate scan node to obtain engine nodes
console.log("[GroupBy Test 1] Validating root node and expanding engines...");
let tuple = await validateRootNode(scan);
console.log("tuple:", tuple);
console.log("tuple(Json):", JSON.stringify(tuple));
//let level = 0;
// Get the sast results node, because it is the only one affected by all the group by commands
let sastNode = await scan?.findChildItem(SAST_TYPE);
while (sastNode === undefined) {
sastNode = await scan?.findChildItem(SAST_TYPE);
{
const start = Date.now();
console.log("[GroupBy Test 1] Searching for SAST node:", SAST_TYPE);
while (sastNode === undefined && Date.now() - start < 15000) {
sastNode = await scan?.findChildItem(SAST_TYPE);
}
console.log("sastNode ............:", sastNode);
console.log("sastNode(Json) ............:", JSON.stringify(sastNode));
console.log("[GroupBy Test 1] SAST node found:", sastNode, "elapsed(ms):", Date.now() - start);
expect(sastNode).to.not.be.undefined;
}
console.log("sastNode:", sastNode);
console.log("sastNode(Json):", JSON.stringify(sastNode));
// Validate for all commands the nested tree elements
for (var index in commands) {
// Execute the group by command for each command
console.log("[GroupBy Test 1] Executing group by:", commands[index]);
await bench.executeCommand(commands[index]);
}
// Size must not be bigger than 3 because there are at most 3 engines in the first node
console.log("[GroupBy Test 1] Engine count (tuple[0]):", tuple[0]);
expect(tuple[0]).to.be.at.most(4);
});

async function waitFor(fn, timeout = 5000, interval = 100) {
const start = Date.now();
let result;

while (Date.now() - start < timeout) {
result = await fn();
if (result !== undefined && result !== null) {
return result;
}
await new Promise(res => setTimeout(res, interval));
}

throw new Error("Timeout waiting for: " + fn.toString());
}

it("should click on all group by", async function () {
this.timeout(20000); // VS Code extension tests are slow
console.log("Test started: should click on all group by");
const commands = [CX_GROUP_LANGUAGE, CX_GROUP_STATUS, CX_GROUP_STATE, CX_GROUP_QUERY_NAME, CX_GROUP_FILE];

// Get scan node
console.log("Calling initialize()...");
const treeScans = await initialize();

console.log("initialize() returned:", treeScans);

console.log(`Searching for scan: '${SCAN_KEY_TREE_LABEL}'`);
let scan = await treeScans?.findItem(
SCAN_KEY_TREE_LABEL
);
console.log("scan found:", scan);

console.log("[GroupBy Test 2] Focusing Checkmarx Results view via command:", CX_LOOK_SCAN);
await bench.executeCommand(CX_LOOK_SCAN);
console.log("[GroupBy Test 2] initialize() returned treeScans:", !!treeScans);
let scan = await treeScans?.findItem(SCAN_KEY_TREE_LABEL);
{
const start = Date.now();
console.log("[GroupBy Test 2] Searching for scan node:", SCAN_KEY_TREE_LABEL);
while (scan === undefined && Date.now() - start < 15000) {
scan = await treeScans?.findItem(SCAN_KEY_TREE_LABEL);
}
console.log(JSON.stringify(scan));
console.log("[GroupBy Test 2] scan node found:", !!scan, "elapsed(ms):", Date.now() - start);
expect(scan).to.not.be.undefined;
}
// Expand and validate scan node to obtain engine nodes
console.log("Calling validateRootNode(scan)...");
const tuple = await validateRootNode(scan);
console.log("validateRootNode returned tuple:", tuple);
console.log("[GroupBy Test 2] Validating root node and expanding engines...");
let tuple = await validateRootNode(scan);
console.log("[GroupBy Test 2] Root validation tuple:", tuple);
//let level = 0;
// Get the sast results node, because it is the only one affected by all the group by commands
console.log(`Searching for SAST node: '${SAST_TYPE}'`);

let sastNode = await waitFor(() => scan?.findChildItem(SAST_TYPE));
console.log("SAST node found:", sastNode);

for (const command of commands) {
console.log(`Executing group-by command: ${command}`);
await bench.executeCommand(command);
console.log(`Command executed: ${command}`);
await sleep(10000);
console.log(`Finished waiting after command: ${command}`);
let sastNode = await scan?.findChildItem(SAST_TYPE);
{
const start = Date.now();
console.log("[GroupBy Test 2] Searching for SAST node:", SAST_TYPE);
while (sastNode === undefined && Date.now() - start < 15000) {
sastNode = await scan?.findChildItem(SAST_TYPE);
}
console.log("[GroupBy Test 2] SAST node found:", !!sastNode, "elapsed(ms):", Date.now() - start);
expect(sastNode).to.not.be.undefined;
}

// Validate for all commands the nested tree elements
for (var index in commands) {
// Execute the group by command for each command
console.log("[GroupBy Test 2] Executing group by:", commands[index]);
await bench.executeCommand(commands[index]);
};
// Size must not be bigger than 3 because there are at most 3 engines in the first node
console.log("[GroupBy Test 2] Engine count (tuple[0]):", tuple[0]);
expect(tuple[0]).to.be.at.most(4);
});


it("should click on all filter state", async function () {
await initialize();
const commands = [CX_FILTER_NOT_EXPLOITABLE, CX_FILTER_PROPOSED_NOT_EXPLOITABLE, CX_FILTER_CONFIRMED, CX_FILTER_TO_VERIFY, CX_FILTER_URGENT, CX_FILTER_NOT_IGNORED];
for (var index in commands) {
await bench.executeCommand(commands[index]);
expect(index).not.to.be.undefined;
}
});
});
});
3 changes: 1 addition & 2 deletions src/test/8.NoResult.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Workbench,
} from "vscode-extension-tester";
import { expect } from "chai";
import { getDetailsView, getResults, initialize, waitForNotificationWithTimeout, sleep } from "./utils/utils";
import { getDetailsView, getResults, initialize, waitForNotificationWithTimeout } from "./utils/utils";
import { CHANGES_CONTAINER, CHANGES_LABEL, CODEBASHING_HEADER, COMMENT_BOX, CX_LOOK_SCAN, GENERAL_LABEL, LEARN_MORE_LABEL, SAST_TYPE, SCAN_KEY_TREE_LABEL, UPDATE_BUTTON, WEBVIEW_TITLE } from "./utils/constants";
import { waitByClassName } from "./utils/waiters";
import { EMPTY_RESULTS_SCAN_ID, SCAN_ID } from "./utils/envs";
Expand All @@ -35,7 +35,6 @@ describe("Scan ID load results test", () => {
let input = await new InputBox();
await input.setText("e3b2505a-0634-4b41-8fa1-dfeb2edc26f7");
await input.confirm();
sleep(5000)
});

it("should check scan result is not undefined", async function () {
Expand Down
4 changes: 4 additions & 0 deletions src/test/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ export async function createTree(

export async function initialize(): Promise<CustomTreeSection | undefined> {
const control = await createControl();
console.log("Control:", control);
console.log("Control(Json):", JSON.stringify(control));
let view;
if (control) {
view = await createView(control);
console.log("View:", view);
console.log("View(Json):", JSON.stringify(view));
}
return await createTree(view);
}
Expand Down
20 changes: 20 additions & 0 deletions src/views/resultsView/astResultsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,39 @@ export class AstResultsProvider extends ResultsProvider {

async refreshData(): Promise<void> {
if (await validateConfigurationAndLicense(this.logs)) {
console.log("[AST] refreshData: starting generateTree");
this.showStatusBarItem(messages.commandRunning);
const treeItem = await this.generateTree();
console.log("[AST] refreshData: generateTree returned", !!treeItem, "children count:", treeItem?.children?.length ?? 0);
this.data = treeItem.children;
this._onDidChangeTreeData.fire(undefined);
console.log("[AST] refreshData: treeData fired, data length:", this.data?.length ?? 0);
this.hideStatusBarItem();
}
else {
console.log("[AST] refreshData: invalid configuration or license, clearing data");
this.data = [];
this._onDidChangeTreeData.fire(undefined);
}
}

async openRefreshData(): Promise<void> {
if (await validateConfigurationAndLicense(this.logs)) {
console.log("[AST] openRefreshData: starting with valid config");
this.showStatusBarItem(messages.commandRunning);
this.loadedResults = undefined;
const scanIDItem = getFromState(this.context, constants.scanIdKey);
let scanId = undefined;
if (scanIDItem && scanIDItem.name) {
scanId = getFromState(this.context, constants.scanIdKey).name;
}
console.log("[AST] openRefreshData: scanId from state:", scanId);
if (scanId) {
console.log("[AST] openRefreshData: invoking getResultsWithProgress for scanId");
await getResultsWithProgress(this.logs, scanId);
console.log("[AST] openRefreshData: results loaded, refreshing tree");
await vscode.commands.executeCommand(commands.refreshTree);
console.log("[AST] openRefreshData: refreshTree executed");
this.hideStatusBarItem();
}
}
Expand All @@ -105,29 +114,35 @@ export class AstResultsProvider extends ResultsProvider {
let treeItems = this.createRootItems();
// get scan from state
this.scan = getFromState(this.context, constants.scanIdKey);
console.log("[AST] generateTree: scan from state:", this.scan?.id, this.scan?.name);
const fromTriage = getFromState(this.context, constants.triageUpdate)?.id;
console.log("[AST] generateTree: fromTriage flag:", fromTriage);
// Case we come from triage we want to use the loaded results which were modified in triage
if (fromTriage === undefined || !fromTriage) {
// in case we scanId, it is needed to load them from the json file
if (this.scan?.id) {
console.log("[AST] generateTree: reading results from file:", resultJsonPath);
this.loadedResults = await readResultsFromFile(resultJsonPath, this.scan?.id)
.catch((error) => {
this.logs.error(`Error reading results: ${error.message}`);
return undefined;
});
console.log("[AST] generateTree: loadedResults length:", this.loadedResults?.length ?? -1);



}
// otherwise the results must be cleared
else {
console.log("[AST] generateTree: no scan id, clearing loadedResults and updating risk view");
this.loadedResults = undefined;
this.riskManagementView.updateContent();

}
}
// Case we come from triage we must update the state to load results from the correct place
else {
console.log("[AST] generateTree: clearing triageUpdate state");
updateState(this.context, constants.triageUpdate, {
id: false, name: constants.triageUpdate,
scanDatetime: "",
Expand All @@ -137,9 +152,11 @@ export class AstResultsProvider extends ResultsProvider {

// if there are results loaded, the tree needs to be recreated
if (this.loadedResults !== undefined) {
console.log("[AST] generateTree: recreating tree with results, count:", this.loadedResults.length);

// Update the risks management webview with project info
const project = getFromState(this.context, constants.projectIdKey);
console.log("[AST] generateTree: updating risk view with project:", project?.id, "scan:", this.scan?.id);
this.riskManagementView.updateContent({ project, scan: this.scan, cxResults: this.loadedResults });

const newItem = new TreeItem(`${this.scan.scanDatetime}`, constants.calendarItem);
Expand All @@ -149,6 +166,7 @@ export class AstResultsProvider extends ResultsProvider {
treeItems = treeItems.concat(this.createSummaryItem(this.loadedResults));
}

console.log("[AST] generateTree: grouping by:", this.groupByCommand.activeGroupBy, "active severities:", this.filterCommand.getAtiveSeverities(), "active states:", this.filterCommand.getActiveStates());
const treeItem = this.groupBy(
this.loadedResults,
this.groupByCommand.activeGroupBy,
Expand All @@ -165,7 +183,9 @@ export class AstResultsProvider extends ResultsProvider {

treeItem.collapsibleState = vscode.TreeItemCollapsibleState.Expanded;
treeItems = treeItems.concat(treeItem);
console.log("[AST] generateTree: treeItem children count:", treeItem.children.length);
}
console.log("[AST] generateTree: returning root with children count:", treeItems.length);
return new TreeItem("", undefined, undefined, treeItems);
}

Expand Down
Loading