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/benalvo/vorpal warning file with no extension #916

Open
wants to merge 67 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
5782c02
first working code
tamarleviCm Jun 25, 2024
d9364c3
Merge branch 'main' into vorpal-engine-extention
tamarleviCm Jun 25, 2024
b95f57d
WIP: 10ba35b docs(changelog): update release notes
tamarleviCm Jul 2, 2024
327b428
Merge branch 'main' into vorpal-engine-extention
tamarleviCm Jul 2, 2024
6b5c59e
Merge branch 'main' into vorpal-engine-extention
tamarleviCm Jul 3, 2024
a943024
settings
tamarleviCm Jul 7, 2024
c78e292
Merge branch 'main' into vorpal-engine-extention
tamarleviCm Jul 7, 2024
2bedd80
tests
tamarleviCm Jul 8, 2024
fb43579
Merge branch 'vorpal-engine-extention' of https://github.com/Checkmar…
tamarleviCm Jul 8, 2024
e3b9b5f
Merge branch 'vorpal-engine-extention' of https://github.com/Checkmar…
tamarleviCm Jul 8, 2024
6c5fd71
delete problems when disabled vorpal
tamarleviCm Jul 9, 2024
f50e3cc
test
tamarleviCm Jul 9, 2024
582ee75
tests
tamarleviCm Jul 9, 2024
46b76b2
tests
tamarleviCm Jul 11, 2024
5035c0a
test
tamarleviCm Jul 11, 2024
9e979f3
test
tamarleviCm Jul 11, 2024
6ad8327
ignore log files
tamarleviCm Jul 11, 2024
f91fe08
ignore settings.json windows
tamarleviCm Jul 14, 2024
8968f07
tests
tamarleviCm Jul 14, 2024
91ff402
fix tests
tamarleviCm Jul 14, 2024
04458d0
tests
tamarleviCm Jul 14, 2024
fe442ea
onDidChangeActiveTextEditor
tamarleviCm Jul 15, 2024
7ea02cd
tests
tamarleviCm Jul 15, 2024
aa53763
log settings
tamarleviCm Jul 15, 2024
9026fc5
fix tests
tamarleviCm Jul 15, 2024
b7f86ab
tests
tamarleviCm Jul 15, 2024
c185315
fixes
tamarleviCm Jul 15, 2024
7de1ce3
fix
tamarleviCm Jul 15, 2024
73e4e44
Update launch.json
tamarleviCm Jul 17, 2024
ed7d8d0
Update package.json
tamarleviCm Jul 17, 2024
34db373
ignore system files
tamarleviCm Jul 17, 2024
5d75bc4
Merge branch 'main' into vorpal-engine-extention
tamarleviCm Jul 21, 2024
27ea8a8
tests
tamarleviCm Jul 21, 2024
4e32ecb
Merge branch 'main' into vorpal-engine-extention
tamarleviCm Jul 21, 2024
f10050c
test name
tamarleviCm Jul 21, 2024
09f6073
try
tamarleviCm Jul 21, 2024
cd9238f
revert
tamarleviCm Jul 21, 2024
c218872
Update launch.json
tamarleviCm Jul 21, 2024
4acd883
Merge branch 'vorpal-engine-extention' of https://github.com/Checkmar…
tamarleviCm Jul 21, 2024
fc2c1df
try
tamarleviCm Jul 21, 2024
6017e3b
fix
tamarleviCm Jul 21, 2024
06f4cbf
remove test
tamarleviCm Jul 22, 2024
7b984ef
order
tamarleviCm Jul 22, 2024
5910ec5
fix mock
tamarleviCm Jul 22, 2024
961e2e2
vorpal tests
tamarleviCm Jul 22, 2024
2c51710
try import again
tamarleviCm Jul 22, 2024
6c1386c
clear tests
tamarleviCm Jul 25, 2024
6f0a29a
fix test mock
tamarleviCm Jul 25, 2024
2f71cbe
setting name without space
tamarleviCm Jul 25, 2024
d9dd8f6
timeout
tamarleviCm Jul 25, 2024
4d5d615
fix the test
tamarleviCm Jul 25, 2024
21e63e2
beezrat hashem
tamarleviCm Jul 25, 2024
b50a81c
vorpal test
tamarleviCm Jul 25, 2024
e3c3c5d
settings test
tamarleviCm Jul 25, 2024
1d71985
add test
tamarleviCm Jul 25, 2024
8096c4e
test
tamarleviCm Jul 25, 2024
13c1f3a
test cases
tamarleviCm Jul 25, 2024
b0ffc42
code review
tamarleviCm Jul 25, 2024
6a85076
await
tamarleviCm Jul 29, 2024
584d16b
latest wrapper and settings descreption
tamarleviCm Jul 31, 2024
caceb93
formmater
tamarleviCm Jul 31, 2024
e1fd1ad
Merge branch 'main' into vorpal-engine-extention
tamarleviCm Jul 31, 2024
4ccd40a
pull vorpal branch
BenAlvo1 Aug 1, 2024
e5d0543
change log.err to log.warn in scan vorpal
AlvoBen Aug 1, 2024
676938d
Merge remote-tracking branch 'origin/vorpal-engine-extention' into fi…
BenAlvo1 Aug 1, 2024
94abdfb
support Critical severities
BenAlvo1 Aug 4, 2024
5ca4aaa
Merge branch 'main' into fix/benalvo/vorpal-warning-file-with-no-exte…
pedrompflopes Aug 8, 2024
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
27 changes: 15 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 17 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@
{
"title": "Checkmarx One",
"id": "ast-results",
"order": 3,
"order": 4,
"properties": {
"checkmarxOne.apiKey": {
"type": "string",
Expand Down Expand Up @@ -825,7 +825,7 @@
{
"title": "Checkmarx AI Security Champion",
"id": "ask-kics",
"order": 2,
"order": 3,
"properties": {
"CheckmarxSecurityChampion.key": {
"type": "string",
Expand All @@ -849,6 +849,19 @@
]
}
}
},
{
"title": "Activate Vorpal Auto Scanning",
"id": "vorpal",
"order": 2,
"properties": {
"CheckmarxVorpal.ActivateVorpalAutoScanning": {
"type": "boolean",
"order": 3,
"default": false,
"markdownDescription": "Scans your file as you code"
}
}
}
]
},
Expand All @@ -861,7 +874,7 @@
"copytestproject": "copyfiles -u 2 \"src/resources/**/*\" out/test/ -E",
"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.71.0 -i -r .",
"test": "export TEST=true && npm run compile && extest setup-and-run './out/test/**/*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 ."
},
"devDependencies": {
Expand All @@ -883,7 +896,7 @@
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@checkmarxdev/ast-cli-javascript-wrapper": "0.0.108",
"@checkmarxdev/ast-cli-javascript-wrapper": "0.0.110",
"copyfiles": "2.4.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-node": "^11.1.0",
Expand Down
76 changes: 76 additions & 0 deletions src/commands/vorpalCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import * as vscode from 'vscode';
import { Logs } from "../models/logs";
import { clearVorpalProblems, installVorpal, scanVorpal } from "../vorpal/scanVorpal";
import { constants } from '../utils/common/constants';

let timeout = null;
export class VorpalCommand {
context: vscode.ExtensionContext;
logs: Logs;
onDidChangeTextDocument: vscode.Disposable;
constructor(context: vscode.ExtensionContext, logs: Logs) {
this.context = context;
this.logs = logs;
}
public async registerVorpal() {
try {
const vorpalActive = vscode.workspace
.getConfiguration("CheckmarxVorpal")
.get("ActivateVorpalAutoScanning") as boolean;
if (vorpalActive) {
await this.installVorpal();
await this.registerVorpalScanOnChangeText();
this.logs.info(constants.vorpalStart);
} else {
await this.disposeVorpalScanOnChangeText();
await clearVorpalProblems();
this.logs.info(constants.vorpalDisabled);
}
} catch(error) {
console.error(error);
}
}
public installVorpal() {
installVorpal(this.logs);
this.onDidChangeTextDocument = vscode.workspace.onDidChangeTextDocument(
// Must be no less than 2000ms. Otherwise, the temporary file can be deleted before the vorpal scan is finished.
this.debounce(this.onTextChange, 2000)
);
}

public onTextChange(event) {
try {
scanVorpal(event.document, this.logs);
} catch (error) {
console.error(error);
this.logs.warn("fail to scan vorpal");
}
}
// Debounce function
public debounce(func, wait) {
const context = this;
console.log("onDidChangeTextDocument");
return function (...args) {
try {
const later = () => {
clearTimeout(timeout);
func.apply(context, args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
} catch (error) {
console.error(error);
}
};
}

public registerVorpalScanOnChangeText() {
this.context.subscriptions.push(this.onDidChangeTextDocument);
}
public disposeVorpalScanOnChangeText() {
if (this.onDidChangeTextDocument) {
this.onDidChangeTextDocument.dispose();
this.context.subscriptions.push(this.onDidChangeTextDocument);
}
}
}
42 changes: 38 additions & 4 deletions src/cx/cx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import CxScan from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/scan/CxSc
import CxProject from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/project/CxProject";
import CxCodeBashing from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/codebashing/CxCodeBashing";
import { CxConfig } from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/wrapper/CxConfig";
import {
constants
} from "../utils/common/constants";
import { constants } from "../utils/common/constants";
import { getFilePath, getResultsFilePath } from "../utils/utils";
import { SastNode } from "../models/sastNode";
import AstError from "../exceptions/AstError";
Expand All @@ -17,6 +15,7 @@ import { CxPlatform } from "./cxPlatform";
import { CxCommandOutput } from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/wrapper/CxCommandOutput";
import { ChildProcessWithoutNullStreams } from "child_process";
import CxLearnMoreDescriptions from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/learnmore/CxLearnMoreDescriptions";
import CxVorpal from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/vorpal/CxVorpal";
import { messages } from "../utils/common/messages";
export class Cx implements CxPlatform {
async scaScanCreate(sourcePath: string): Promise<CxScaRealtime | undefined> {
Expand Down Expand Up @@ -425,4 +424,39 @@ export class Cx implements CxPlatform {
statusBarItem.text = text;
show ? statusBarItem.show() : statusBarItem.hide();
}
}
async installVorpal(): Promise<CxVorpal> {
let config = this.getAstConfiguration();
if (!config) {
config = new CxConfig();
}
const cx = new CxWrapper(config);
const scans = await cx.scanVorpal(null, true, constants.vsCodeAgent);
if (scans.payload && scans.exitCode === 0) {
return scans.payload[0];
} else {
return this.getVorpalError(scans.status, "Failed to run vorpal engine");
}
}

private getVorpalError(scanStatus: string, errorMessage: string) {
console.error(errorMessage);
const errorRes = new CxVorpal();
errorRes.error = scanStatus;
return errorRes;
}

async scanVorpal(sourcePath: string): Promise<CxVorpal> {
let config = this.getAstConfiguration();
if (!config) {
config = new CxConfig();
}
const cx = new CxWrapper(config);
const scans = await cx.scanVorpal(sourcePath, false, constants.vsCodeAgent);
if (scans.payload && scans.exitCode === 0) {
return scans.payload[0];
} else {
return this.getVorpalError(scans.status, "Fail to call vorpal scan");
}
}
}

13 changes: 12 additions & 1 deletion src/cx/cxMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import { CxConfig } from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/wra
import { getFilePath } from "../utils/utils";
import { writeFileSync } from "fs";
import { CxPlatform } from "./cxPlatform";
import CxVorpal from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/vorpal/CxVorpal";
import { EMPTY_RESULTS_SCAN_ID } from "../test/utils/envs";

export class CxMock implements CxPlatform {


// eslint-disable-next-line @typescript-eslint/no-explicit-any
async scaScanCreate(): Promise<CxScaRealtime[] | any> {
return [
Expand Down Expand Up @@ -552,7 +555,7 @@ export class CxMock implements CxPlatform {
await this.sleep(1000);
return [{ conversationId: '0', response: ["Mock message response from gpt"] }];
}

sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
Expand All @@ -561,5 +564,13 @@ export class CxMock implements CxPlatform {
statusBarItem.text = text;
show ? statusBarItem.show() : statusBarItem.hide();
}

installVorpal(): Promise<CxVorpal> {
return null;
}

async scanVorpal(sourcePath: string): Promise<CxVorpal> {
return new CxVorpal();
}
}

12 changes: 12 additions & 0 deletions src/cx/cxPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Logs } from "../models/logs";
import { ChildProcessWithoutNullStreams } from "child_process";
import { CxCommandOutput } from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/wrapper/CxCommandOutput";
import CxLearnMoreDescriptions from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/learnmore/CxLearnMoreDescriptions";
import CxVorpal from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/vorpal/CxVorpal";

export interface CxPlatform {
/**
Expand Down Expand Up @@ -176,5 +177,16 @@ export interface CxPlatform {
* @param statusBarItem The {@link vscode.StatusBarItem} associated with the results.
*/
updateStatusBarItem(text: string, show: boolean, statusBarItem: vscode.StatusBarItem);

/**
* install the Vorpal engine
*/
installVorpal(): Promise<CxVorpal>;

/**
* Scan the edited file in the vorpal engine and show the results in the problem section
* @param sourcePath the edited file sent to the vorpal engine
*/
scanVorpal(sourcePath: string): Promise<CxVorpal>;
}

6 changes: 5 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ import { WorkspaceListener } from "./utils/listener/workspaceListener";
import { DocAndFeedbackView } from "./views/docsAndFeedbackView/docAndFeedbackView";
import { messages } from "./utils/common/messages";
import { commands } from "./utils/common/commands";
import { VorpalCommand } from "./commands/vorpalCommand";

export async function activate(context: vscode.ExtensionContext) {
// Create logs channel and make it visible
const output = vscode.window.createOutputChannel(constants.extensionFullName);
const logs = new Logs(output);
logs.show();
logs.info(messages.pluginRunning);

// Status bars creation
Expand Down Expand Up @@ -175,6 +177,8 @@ export async function activate(context: vscode.ExtensionContext) {
}
}
});
const vorpalCommand = new VorpalCommand(context, logs);
vorpalCommand.registerVorpal();
// Register Settings
const commonCommand = new CommonCommand(context, logs);
commonCommand.registerSettings();
Expand All @@ -186,7 +190,7 @@ export async function activate(context: vscode.ExtensionContext) {
// SCA auto scanning enablement
await commonCommand.executeCheckScaScanEnabled();
// execute command to listen to settings change
await executeCheckSettingsChange(kicsStatusBarItem, logs);
await executeCheckSettingsChange(kicsStatusBarItem, logs, vorpalCommand);

const treeCommand = new TreeCommand(
context,
Expand Down
2 changes: 1 addition & 1 deletion src/test/0.welcome.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("Welcome view test", () => {
let bench: Workbench;

before(async function () {
this.timeout(8000);
this.timeout(100000);
bench = new Workbench();
});

Expand Down
21 changes: 21 additions & 0 deletions src/test/1.settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,25 @@ describe("Extension settings tests", () => {
const enablement = await setting.getValue();
expect(enablement).to.equal(true);
});

it("verify vorpal checkbox exists in the settings", async function () {
settingsEditor = await bench.openSettings();
const vorpalCheckbox = await settingsEditor.findSetting(
"ActivateVorpalAutoScanning",
"Checkmarx Vorpal"
);
let vorpalCheckboxValue = await vorpalCheckbox.getValue();
expect(vorpalCheckboxValue).to.not.be.undefined;
});

it("vorpal starts when the Vorpal checkbox is True in settings", async function () {
settingsEditor = await bench.openSettings();
const vorpalCheckbox = await settingsEditor.findSetting(
"ActivateVorpalAutoScanning",
"Checkmarx Vorpal"
);
await vorpalCheckbox.setValue(true);
let vorpalCheckboxValue = await vorpalCheckbox.getValue();
expect(vorpalCheckboxValue).to.be.true;
});
});
Loading
Loading