From b3f771ef69330328874511506107240ba61fb3b0 Mon Sep 17 00:00:00 2001 From: miryamfoiferCX Date: Sun, 10 Nov 2024 15:24:12 +0200 Subject: [PATCH 01/15] delete zip file (AST-40077) --- cxAstScan/services/CleanUpRunner.ts | 118 ++++++++++++++++++---------- cxAstScan/test/_suite.ts | 16 ++-- package-lock.json | 18 +++-- package.json | 2 +- 4 files changed, 99 insertions(+), 55 deletions(-) diff --git a/cxAstScan/services/CleanUpRunner.ts b/cxAstScan/services/CleanUpRunner.ts index a6fa6ab..be28e50 100644 --- a/cxAstScan/services/CleanUpRunner.ts +++ b/cxAstScan/services/CleanUpRunner.ts @@ -7,62 +7,98 @@ export class CleanUpRunner { cxWrapperFactory= new CxWrapperFactory(); async run() { - console.log("Getting job status"); - const jobStatus = taskLib.getVariable('AGENT_JOBSTATUS'); - console.log("Job status: " + jobStatus); - if (jobStatus !== 'Canceled') { - console.log("Pipeline not cancelled, nothing to do."); - taskLib.setResult(taskLib.TaskResult.Succeeded, ""); - return; - } - - const cxScanConfig = getConfiguration(); - const wrapper = await this.cxWrapperFactory.createWrapper(cxScanConfig); - let data: string; - try { - data = await fs.readFile(getLogFilename(), 'utf8') - } catch (err: any) { - if (err.code === 'ENOENT') { - console.log("Log file not created. Task ended successfully") + console.log("Getting job status"); + const jobStatus = taskLib.getVariable('AGENT_JOBSTATUS'); + console.log("Job status: " + jobStatus); + if (jobStatus !== 'Canceled') { + console.log("Pipeline not cancelled, nothing to do."); taskLib.setResult(taskLib.TaskResult.Succeeded, ""); - } else if (err.code === 'EACCES') { - console.log('No permissions to read log file') - taskLib.setResult(taskLib.TaskResult.Failed, "") - } else { - throw err + return; } - return - } - //Regex to get the scanID ofthe logs - const regexScanId = new RegExp(/"(ID)":"((\\"|[^"])*)"/i); + const cxScanConfig = getConfiguration(); + const wrapper = await this.cxWrapperFactory.createWrapper(cxScanConfig); + let data: string; - const regexArray = regexScanId.exec(data!); + try { + data = await fs.readFile(getLogFilename(), 'utf8') + } catch (err: any) { + if (err.code === 'ENOENT') { + console.log("Log file not created. Task ended successfully") + taskLib.setResult(taskLib.TaskResult.Succeeded, ""); + } else if (err.code === 'EACCES') { + console.log('No permissions to read log file') + taskLib.setResult(taskLib.TaskResult.Failed, "") + } else { + throw err + } + return + } - try { - if (regexArray) { - //m[2] is the scanID - console.log("Canceling scan with ID: " + regexArray[2]) - await wrapper.scanCancel(regexArray[2]); - } else { - console.log("Scan not created. Terminating job.") + //Regex to get the scanID ofthe logs + const regexScanId = new RegExp(/"(ID)":"((\\"|[^"])*)"/i); + + const regexArray = regexScanId.exec(data!); + + try { + if (regexArray) { + //m[2] is the scanID + console.log("Canceling scan with ID: " + regexArray[2]) + await wrapper.scanCancel(regexArray[2]); + } else { + console.log("Scan not created. Terminating job.") + } + } catch (err) { + console.log("Error canceling scan: " + err + " " + Date.now().toString()) + taskLib.setResult(taskLib.TaskResult.Failed, ""); + return } + + taskLib.setResult(taskLib.TaskResult.Succeeded, ""); + } catch (err) { - console.log("Error canceling scan: " + err + " " + Date.now().toString()) - taskLib.setResult(taskLib.TaskResult.Failed, ""); return + } finally { + await this.deleteZipFile() + await this.deleteLogFile() } + } - taskLib.setResult(taskLib.TaskResult.Succeeded, ""); + async deleteZipFile(): Promise { + try { + const logFileName = getLogFilename(); + const data = await fs.readFile(logFileName, 'utf-8'); + const zipFilePath = this.extractZipFilePath(data); + if (zipFilePath) { + // Delete the zip file + await fs.unlink(zipFilePath); + console.log(`Deleted zip file: ${zipFilePath}`); + } else { + console.log('No zip file path found in the log file.'); + } + } catch (error: any) { + if(error.code === 'ENOENT') { + console.log('Zip file already deleted.'); + } + else { + console.error('Error deleting zip file', error); + } + } + } + async deleteLogFile(): Promise { try { - fs.unlink(getLogFilename()) - //file removed + await fs.unlink(getLogFilename()); + console.log('Log file deleted successfully.'); } catch (err) { - console.log("Unable to delete log file.", err) + console.log("Unable to delete log file.", err); } - } + extractZipFilePath(data: string): string | null { + const zipFilePattern = /Temporary zip file path:\s*(.+)$/; + const match = data.match(zipFilePattern); + return match ? match[1] : null; + } } diff --git a/cxAstScan/test/_suite.ts b/cxAstScan/test/_suite.ts index d76ad20..9c2e04c 100644 --- a/cxAstScan/test/_suite.ts +++ b/cxAstScan/test/_suite.ts @@ -73,9 +73,12 @@ describe('Task runner test', function () { console.log(tr.succeeded); assert.strictEqual(tr.succeeded, true, 'should have succeeded'); console.log(tr.stdout); - assert.strictEqual(tr.stdout.indexOf('Pipeline not cancelled, nothing to do.') >= 0, - true, + assert.strictEqual(tr.stdout.indexOf('Pipeline not cancelled, nothing to do.') >= 0, + true, "should display cleanup message: Pipeline not cancelled, nothing to do."); + assert.strictEqual(tr.stdout.indexOf('Deleted zip file') >= 0 || tr.stdout.indexOf('Zip file already deleted.') >= 0, + true, + "should display cleanup message: Deleted zip file or Zip file already deleted."); done(); }); @@ -92,9 +95,12 @@ describe('Task runner test', function () { const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); tr.run(nodeVersion); console.log(tr.stdout); - assert.strictEqual(tr.stdout.indexOf('Canceling scan with ID') >= 0, - true, + assert.strictEqual(tr.stdout.indexOf('Canceling scan with ID') >= 0, + true, "should display cleanup message: Canceling scan with ID"); + assert.strictEqual(tr.stdout.indexOf('Deleted zip file') >= 0 || tr.stdout.indexOf('Zip file already deleted.') >= 0, + true, + "should display cleanup message: Deleted zip file or Zip file already deleted."); done(); }); @@ -105,7 +111,7 @@ describe('Task runner test', function () { tr.run(nodeVersion); console.log(tr.stdout); assert.strictEqual(tr.stdout.indexOf('Log file not created. Task ended successfully') >= 0, - true, + true, "should display cleanup message: Log file not created. Task ended successfully."); done(); }); diff --git a/package-lock.json b/package-lock.json index ea3efe7..f677992 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "@typescript-eslint/parser": "^5.62.0", "eslint": "^8.57.0", "mocha": "10.7.0", - "typescript": "5.5.4" + "typescript": "^5.6.3" }, "engines": { "node": ">=16" @@ -2373,12 +2373,13 @@ } }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dev": true, + "license": "MIT", "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { @@ -3381,10 +3382,11 @@ } }, "node_modules/typescript": { - "version": "5.5.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", - "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "version": "5.6.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz", + "integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==", "dev": true, + "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index 5c2bdf2..08c3458 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "@typescript-eslint/parser": "^5.62.0", "eslint": "^8.57.0", "mocha": "10.7.0", - "typescript": "5.5.4" + "typescript": "^5.6.3" }, "publishConfig": { "registry": "https://npm.pkg.github.com" From 1e322c26fded3ac378a2ac7acbee1cf3b62a2b71 Mon Sep 17 00:00:00 2001 From: Andre Macedo <149069722+amacedoo@users.noreply.github.com> Date: Mon, 11 Nov 2024 11:47:20 +0000 Subject: [PATCH 02/15] Update AST Scan --- .github/workflows/ast-scan.yml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ast-scan.yml b/.github/workflows/ast-scan.yml index e6bd2f8..bc251d2 100644 --- a/.github/workflows/ast-scan.yml +++ b/.github/workflows/ast-scan.yml @@ -1,18 +1,25 @@ name: Checkmarx One Scan - -on: [ pull_request, workflow_dispatch ] +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + schedule: + - cron: '00 7 * * *' # Every day at 07:00 jobs: cx-scan: + name: Checkmarx One Scan runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Checkmarx One CLI Action - uses: checkmarx/ast-github-action@1fe318de2993222574e6249750ba9000a4e2a6cd #v2.0.33 - Check for the latest version and updated here if there is a new one + uses: checkmarx/ast-github-action@03a90e7253dadd7e2fff55f5dfbce647b39040a1 # v.2.0.37 with: base_uri: ${{ secrets.AST_RND_SCANS_BASE_URI }} cx_tenant: ${{ secrets.AST_RND_SCANS_TENANT }} cx_client_id: ${{ secrets.AST_RND_SCANS_CLIENT_ID }} cx_client_secret: ${{ secrets.AST_RND_SCANS_CLIENT_SECRET }} - additional_params: --tags phoenix --threshold "sast-critical=1;sast-high=1;sast-medium=1;sast-low=1;sca-critical=1;sca-high=1;sca-medium=2;sca-low=1;iac-security-critical=1;iac-security-high=1;iac-security-medium=1;iac-security-low=1" --debug + additional_params: --tags phoenix --threshold "sca-critical=1;sca-high=1;sca-medium=1;sca-low=1;sast-critical=1;sast-high=1;sast-medium=1;sast-low=1;iac-security-critical=1;iac-security-high=1;iac-security-medium=1;iac-security-low=1" \ No newline at end of file From 3d58b542a6dc4e06a3f3b2a8aacfaa2eef316c73 Mon Sep 17 00:00:00 2001 From: AlvoBen Date: Tue, 12 Nov 2024 10:38:00 +0200 Subject: [PATCH 03/15] update js runtime wrapper and node version --- .github/workflows/ci.yml | 4 ++-- cxAstScan/package-lock.json | 14 +++++++------- cxAstScan/package.json | 2 +- cxAstScan/test/_suite.ts | 2 +- package-lock.json | 20 +++++++++++--------- package.json | 4 ++-- 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ed5e9f4..944a93c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,12 +7,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Use Node.js 14 + - name: Use Node.js 22.11.0 uses: actions/setup-node@v4.0.3 env: INPUT_TOKEN: ${{ secrets.NPM_TOKEN }} with: - node-version: 14 + node-version: 22.11.0 - name: Authenticate with GitHub package registry run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc - name: npm install diff --git a/cxAstScan/package-lock.json b/cxAstScan/package-lock.json index 8089f42..fd59517 100644 --- a/cxAstScan/package-lock.json +++ b/cxAstScan/package-lock.json @@ -5,15 +5,15 @@ "packages": { "": { "dependencies": { - "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli": "1.0.2", + "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli": "1.0.3", "azure-pipelines-task-lib": "4.10.1" } }, "node_modules/@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli": { "name": "@CheckmarxDev/ast-cli-javascript-wrapper-runtime-cli", - "version": "1.0.2", - "resolved": "https://npm.pkg.github.com/download/@CheckmarxDev/ast-cli-javascript-wrapper-runtime-cli/1.0.2/80b533cf26754532f848fb0c1b7eb865d1272d88", - "integrity": "sha512-C+wZFeqTeoZoxeS786eZ4qMxGGiJneBuBmI9gPgYfIsm5BaEziyyYFMbAUlLwklsi3GHxQmxJ1ZElDJ9jwi7XA==", + "version": "1.0.3", + "resolved": "https://npm.pkg.github.com/download/@CheckmarxDev/ast-cli-javascript-wrapper-runtime-cli/1.0.3/aeb327e32c46d0f99ae8e6226fda645d54936fce", + "integrity": "sha512-8vD0yyZCU3s7H0gQB7AerP6NesOXJqMsoQPbyorVI6Sk5YY6EAlPkgU9h2KgQwTmBXsQV8+rvhthLBzVctcBww==", "license": "ISC", "dependencies": { "async-mutex": "^0.5.0", @@ -1342,9 +1342,9 @@ }, "dependencies": { "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli": { - "version": "npm:@CheckmarxDev/ast-cli-javascript-wrapper-runtime-cli@1.0.2", - "resolved": "https://npm.pkg.github.com/download/@CheckmarxDev/ast-cli-javascript-wrapper-runtime-cli/1.0.2/80b533cf26754532f848fb0c1b7eb865d1272d88", - "integrity": "sha512-C+wZFeqTeoZoxeS786eZ4qMxGGiJneBuBmI9gPgYfIsm5BaEziyyYFMbAUlLwklsi3GHxQmxJ1ZElDJ9jwi7XA==", + "version": "npm:@CheckmarxDev/ast-cli-javascript-wrapper-runtime-cli@1.0.3", + "resolved": "https://npm.pkg.github.com/download/@CheckmarxDev/ast-cli-javascript-wrapper-runtime-cli/1.0.3/aeb327e32c46d0f99ae8e6226fda645d54936fce", + "integrity": "sha512-8vD0yyZCU3s7H0gQB7AerP6NesOXJqMsoQPbyorVI6Sk5YY6EAlPkgU9h2KgQwTmBXsQV8+rvhthLBzVctcBww==", "requires": { "async-mutex": "^0.5.0", "axios": "^1.7.7", diff --git a/cxAstScan/package.json b/cxAstScan/package.json index 7436c5f..3e4aad0 100644 --- a/cxAstScan/package.json +++ b/cxAstScan/package.json @@ -1,6 +1,6 @@ { "dependencies": { "azure-pipelines-task-lib": "4.10.1", - "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli": "1.0.2" + "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli": "1.0.3" } } diff --git a/cxAstScan/test/_suite.ts b/cxAstScan/test/_suite.ts index d76ad20..16f4800 100644 --- a/cxAstScan/test/_suite.ts +++ b/cxAstScan/test/_suite.ts @@ -2,7 +2,7 @@ import * as path from 'path'; import * as ttm from 'azure-pipelines-task-lib/mock-test'; import * as assert from 'assert'; -const nodeVersion = 16; +const nodeVersion = 22; describe('Task runner test', function () { diff --git a/package-lock.json b/package-lock.json index ea3efe7..7e7715e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ }, "devDependencies": { "@types/mocha": "10.0.7", - "@types/node": "^22.0.0", + "@types/node": "^22.9.0", "@typescript-eslint/eslint-plugin": "^5.61.0", "@typescript-eslint/parser": "^5.62.0", "eslint": "^8.57.0", @@ -738,12 +738,13 @@ "integrity": "sha512-a2yhRIADupQfOFM75v7GfcQQLUxU705+i/xcZ3N/3PK3Xdo31SUfuCUByWPGOHB1e38m7MxTx/D8FPVsJXZKJw==" }, "node_modules/@types/node": { - "version": "22.0.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.0.0.tgz", - "integrity": "sha512-VT7KSYudcPOzP5Q0wfbowyNLaVR8QWUdw+088uFWwfvpY6uCWaXpqV6ieLAu9WBcnTa7H4Z5RLK8I5t2FuOcqw==", + "version": "22.9.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.9.0.tgz", + "integrity": "sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==", "dev": true, + "license": "MIT", "dependencies": { - "undici-types": "~6.11.1" + "undici-types": "~6.19.8" } }, "node_modules/@types/q": { @@ -3399,10 +3400,11 @@ "integrity": "sha512-mPKFGAgGJmeCqrzA6B64Lqoz6vLPtxa8yCd7sWAnfrz9opuNlxqW57VxjtEOL0OOoQeTdc/kBjGUh8sieBXa8A==" }, "node_modules/undici-types": { - "version": "6.11.1", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.11.1.tgz", - "integrity": "sha512-mIDEX2ek50x0OlRgxryxsenE5XaQD4on5U2inY7RApK3SOJpofyw7uW2AyfMKkhAxXIceo2DeWGVGwyvng1GNQ==", - "dev": true + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", + "dev": true, + "license": "MIT" }, "node_modules/update-browserslist-db": { "version": "1.0.16", diff --git a/package.json b/package.json index 5c2bdf2..405e7f5 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "repository": "https://github.com/checkmarx/ast-azure-plugin", "engines": { - "node": ">=16" + "node": ">=22" }, "scripts": { "build": "tsc -b cxAstScan/tsconfig.json && tsc -b ui/enhancer/tsconfig.json", @@ -23,7 +23,7 @@ }, "devDependencies": { "@types/mocha": "10.0.7", - "@types/node": "^22.0.0", + "@types/node": "^22.9.0", "@typescript-eslint/eslint-plugin": "^5.61.0", "@typescript-eslint/parser": "^5.62.0", "eslint": "^8.57.0", From 74b79b57c6553d3bce75c90e012a87cd4d805086 Mon Sep 17 00:00:00 2001 From: AlvoBen Date: Tue, 12 Nov 2024 10:47:09 +0200 Subject: [PATCH 04/15] update task node version --- cxAstScan/task.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cxAstScan/task.json b/cxAstScan/task.json index ea75e75..c7bb175 100644 --- a/cxAstScan/task.json +++ b/cxAstScan/task.json @@ -67,12 +67,12 @@ } ], "execution": { - "Node16": { + "Node22": { "target": "./dist/index.js" } }, "postjobexecution": { - "Node16": { + "Node22": { "target": "./dist/cleanup.js" } }, From 39bdcef9dac57339554401a35015883b53c6dc35 Mon Sep 17 00:00:00 2001 From: AlvoBen Date: Tue, 12 Nov 2024 10:57:15 +0200 Subject: [PATCH 05/15] check --- .github/workflows/ci.yml | 4 ++-- cxAstScan/task.json | 4 ++-- cxAstScan/test/_suite.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 944a93c..ed5e9f4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,12 +7,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Use Node.js 22.11.0 + - name: Use Node.js 14 uses: actions/setup-node@v4.0.3 env: INPUT_TOKEN: ${{ secrets.NPM_TOKEN }} with: - node-version: 22.11.0 + node-version: 14 - name: Authenticate with GitHub package registry run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc - name: npm install diff --git a/cxAstScan/task.json b/cxAstScan/task.json index c7bb175..ea75e75 100644 --- a/cxAstScan/task.json +++ b/cxAstScan/task.json @@ -67,12 +67,12 @@ } ], "execution": { - "Node22": { + "Node16": { "target": "./dist/index.js" } }, "postjobexecution": { - "Node22": { + "Node16": { "target": "./dist/cleanup.js" } }, diff --git a/cxAstScan/test/_suite.ts b/cxAstScan/test/_suite.ts index 16f4800..d76ad20 100644 --- a/cxAstScan/test/_suite.ts +++ b/cxAstScan/test/_suite.ts @@ -2,7 +2,7 @@ import * as path from 'path'; import * as ttm from 'azure-pipelines-task-lib/mock-test'; import * as assert from 'assert'; -const nodeVersion = 22; +const nodeVersion = 16; describe('Task runner test', function () { From 4555245d4f5f6b8076109965409fab92ad628b7b Mon Sep 17 00:00:00 2001 From: AlvoBen Date: Tue, 12 Nov 2024 10:59:00 +0200 Subject: [PATCH 06/15] revert --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 405e7f5..4484dcf 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "repository": "https://github.com/checkmarx/ast-azure-plugin", "engines": { - "node": ">=22" + "node": ">=16" }, "scripts": { "build": "tsc -b cxAstScan/tsconfig.json && tsc -b ui/enhancer/tsconfig.json", From f5dd73890851ac116528169087ba5da44bb2582c Mon Sep 17 00:00:00 2001 From: AlvoBen Date: Tue, 12 Nov 2024 12:14:15 +0200 Subject: [PATCH 07/15] upgrade node version --- cxAstScan/package-lock.json | 78 ++++--------------------------------- cxAstScan/package.json | 2 +- cxAstScan/task.json | 6 +-- 3 files changed, 11 insertions(+), 75 deletions(-) diff --git a/cxAstScan/package-lock.json b/cxAstScan/package-lock.json index fd59517..d13105d 100644 --- a/cxAstScan/package-lock.json +++ b/cxAstScan/package-lock.json @@ -6,7 +6,7 @@ "": { "dependencies": { "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli": "1.0.3", - "azure-pipelines-task-lib": "4.10.1" + "azure-pipelines-task-lib": "4.13.0" } }, "node_modules/@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli": { @@ -133,13 +133,12 @@ } }, "node_modules/azure-pipelines-task-lib": { - "version": "4.10.1", - "resolved": "https://registry.npmjs.org/azure-pipelines-task-lib/-/azure-pipelines-task-lib-4.10.1.tgz", - "integrity": "sha512-tehYJhA0FY48rQunic8FGYnUPNAkoCAkXUmbueW2k7fhIC+ujWJB8pwEodZ7w5r5jRgkYasr0mRFIT1cZZ20VQ==", + "version": "4.13.0", + "resolved": "https://registry.npmjs.org/azure-pipelines-task-lib/-/azure-pipelines-task-lib-4.13.0.tgz", + "integrity": "sha512-KVguui31If98vgokNepHUxE3/D8UFB4FHV1U6XxjGOkgxxwKxbupC3knVnEiZA/hNl7X+vmj9KrYOx79iwmezQ==", "license": "MIT", "dependencies": { "adm-zip": "^0.5.10", - "deasync": "^0.1.28", "minimatch": "3.0.5", "nodejs-file-downloader": "^4.11.1", "q": "^1.5.1", @@ -153,15 +152,6 @@ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, - "node_modules/bindings": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", - "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", - "license": "MIT", - "dependencies": { - "file-uri-to-path": "1.0.0" - } - }, "node_modules/bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", @@ -258,20 +248,6 @@ "node": ">=4.0" } }, - "node_modules/deasync": { - "version": "0.1.30", - "resolved": "https://registry.npmjs.org/deasync/-/deasync-0.1.30.tgz", - "integrity": "sha512-OaAjvEQuQ9tJsKG4oHO9nV1UHTwb2Qc2+fadB0VeVtD0Z9wiG1XPGLJ4W3aLhAoQSYTaLROFRbd5X20Dkzf7MQ==", - "hasInstallScript": true, - "license": "MIT", - "dependencies": { - "bindings": "^1.5.0", - "node-addon-api": "^1.7.1" - }, - "engines": { - "node": ">=0.11.0" - } - }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -341,12 +317,6 @@ "node": "^12.20 || >= 14.13" } }, - "node_modules/file-uri-to-path": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", - "license": "MIT" - }, "node_modules/flatted": { "version": "3.2.7", "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.7.tgz", @@ -664,12 +634,6 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, - "node_modules/node-addon-api": { - "version": "1.7.2", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.7.2.tgz", - "integrity": "sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg==", - "license": "MIT" - }, "node_modules/node-domexception": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", @@ -1428,12 +1392,11 @@ } }, "azure-pipelines-task-lib": { - "version": "4.10.1", - "resolved": "https://registry.npmjs.org/azure-pipelines-task-lib/-/azure-pipelines-task-lib-4.10.1.tgz", - "integrity": "sha512-tehYJhA0FY48rQunic8FGYnUPNAkoCAkXUmbueW2k7fhIC+ujWJB8pwEodZ7w5r5jRgkYasr0mRFIT1cZZ20VQ==", + "version": "4.13.0", + "resolved": "https://registry.npmjs.org/azure-pipelines-task-lib/-/azure-pipelines-task-lib-4.13.0.tgz", + "integrity": "sha512-KVguui31If98vgokNepHUxE3/D8UFB4FHV1U6XxjGOkgxxwKxbupC3knVnEiZA/hNl7X+vmj9KrYOx79iwmezQ==", "requires": { "adm-zip": "^0.5.10", - "deasync": "^0.1.28", "minimatch": "3.0.5", "nodejs-file-downloader": "^4.11.1", "q": "^1.5.1", @@ -1447,14 +1410,6 @@ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, - "bindings": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", - "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", - "requires": { - "file-uri-to-path": "1.0.0" - } - }, "bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", @@ -1525,15 +1480,6 @@ "resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz", "integrity": "sha512-39BOQLs9ZjKh0/patS9nrT8wc3ioX3/eA/zgbKNopnF2wCqJEoxywwwElATYvRsXdnOxA/OQeQoFZ3rFjVajhg==" }, - "deasync": { - "version": "0.1.30", - "resolved": "https://registry.npmjs.org/deasync/-/deasync-0.1.30.tgz", - "integrity": "sha512-OaAjvEQuQ9tJsKG4oHO9nV1UHTwb2Qc2+fadB0VeVtD0Z9wiG1XPGLJ4W3aLhAoQSYTaLROFRbd5X20Dkzf7MQ==", - "requires": { - "bindings": "^1.5.0", - "node-addon-api": "^1.7.1" - } - }, "debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -1574,11 +1520,6 @@ "web-streams-polyfill": "^3.0.3" } }, - "file-uri-to-path": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" - }, "flatted": { "version": "3.2.7", "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.7.tgz", @@ -1802,11 +1743,6 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, - "node-addon-api": { - "version": "1.7.2", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.7.2.tgz", - "integrity": "sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg==" - }, "node-domexception": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", diff --git a/cxAstScan/package.json b/cxAstScan/package.json index 3e4aad0..0824f70 100644 --- a/cxAstScan/package.json +++ b/cxAstScan/package.json @@ -1,6 +1,6 @@ { "dependencies": { - "azure-pipelines-task-lib": "4.10.1", + "azure-pipelines-task-lib": "4.13.0", "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli": "1.0.3" } } diff --git a/cxAstScan/task.json b/cxAstScan/task.json index ea75e75..6aa725c 100644 --- a/cxAstScan/task.json +++ b/cxAstScan/task.json @@ -15,7 +15,7 @@ "Patch": 0 }, "demands": [], - "minimumAgentVersion": "1.0.0", + "minimumAgentVersion": "3.232.1", "groups": [ { "name": "params", @@ -67,12 +67,12 @@ } ], "execution": { - "Node16": { + "Node20_1": { "target": "./dist/index.js" } }, "postjobexecution": { - "Node16": { + "Node20_1": { "target": "./dist/cleanup.js" } }, From 13a7f9a0e3db4f6233945757fd84cf47f2231688 Mon Sep 17 00:00:00 2001 From: AlvoBen Date: Tue, 12 Nov 2024 12:18:45 +0200 Subject: [PATCH 08/15] change tests --- cxAstScan/test/_suite.ts | 124 +++++++-------------------------------- 1 file changed, 22 insertions(+), 102 deletions(-) diff --git a/cxAstScan/test/_suite.ts b/cxAstScan/test/_suite.ts index d76ad20..1e26f6b 100644 --- a/cxAstScan/test/_suite.ts +++ b/cxAstScan/test/_suite.ts @@ -2,111 +2,31 @@ import * as path from 'path'; import * as ttm from 'azure-pipelines-task-lib/mock-test'; import * as assert from 'assert'; -const nodeVersion = 16; -describe('Task runner test', function () { - - - it('should be success with api key', function (done) { - this.timeout(3000000); - const tp = path.join(__dirname, 'success_api_key.js'); - const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); - tr.run(nodeVersion); - - console.log(tr.stdout) - console.log(tr.stderr) - assert.ok(tr.succeeded); - done(); - }); - - it('should be success wait mode', function (done) { - this.timeout(3000000); - const tp = path.join(__dirname, 'success_waitmode.js'); - const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); - tr.run(nodeVersion); +const nodeVersion = 20; - console.log(tr.stdout) - console.log(tr.stderr) - assert.ok(tr.succeeded); - done(); - }); - - it('should be success no wait mode', function (done) { - this.timeout(3000000); - const tp = path.join(__dirname, 'success_nowait.js'); - const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); - tr.run(nodeVersion); - - console.log(tr.stdout) - console.log(tr.stderr) - assert.ok(tr.succeeded); - done(); - }); - - it('should be failure additional params', function (done) { - this.timeout(3000000); - const tp = path.join(__dirname, 'failure_additional_params.js'); - const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); - tr.run(nodeVersion); - console.log(tr.stdout) - console.log(tr.stderr) - assert.ok(tr.failed); - done(); - }); - - it('should be failure preset', function (done) { - this.timeout(3000000); - const tp = path.join(__dirname, 'failure_wrong_preset.js'); - const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); - tr.run(nodeVersion); - - console.log(tr.stdout) - console.log(tr.stderr) - assert.ok(tr.failed); - done(); - }); - - it('should be success no cancel scan', function (done) { - this.timeout(3000000); - const tp = path.join(__dirname, 'success_no_cancel.js'); - const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); - tr.run(nodeVersion); - console.log(tr.succeeded); - assert.strictEqual(tr.succeeded, true, 'should have succeeded'); - console.log(tr.stdout); - assert.strictEqual(tr.stdout.indexOf('Pipeline not cancelled, nothing to do.') >= 0, - true, - "should display cleanup message: Pipeline not cancelled, nothing to do."); - done(); - }); +describe('Task runner test', function () { + this.timeout(3000000); - it('should be success cancel scan', function (done) { - this.timeout(3000000); - const scan = path.join(__dirname, 'success_nowait.js'); - const scanTestRunner: ttm.MockTestRunner = new ttm.MockTestRunner(scan); - scanTestRunner.run(nodeVersion); - console.log(scanTestRunner.stdout) - console.log(scanTestRunner.stderr) - assert.ok(scanTestRunner.succeeded); - - const tp = path.join(__dirname, 'success_cancel.js'); + const runTest = async (testFile: string, expectedSuccess: boolean, checkMessage?: string) => { + const tp = path.join(__dirname, testFile); const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); - tr.run(nodeVersion); - console.log(tr.stdout); - assert.strictEqual(tr.stdout.indexOf('Canceling scan with ID') >= 0, - true, - "should display cleanup message: Canceling scan with ID"); - done(); - }); + await tr.runAsync(nodeVersion); - it('should be success cancel before scan start', function (done) { - this.timeout(3000000); - const tp = path.join(__dirname, 'success_cancel.js'); - const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); - tr.run(nodeVersion); console.log(tr.stdout); - assert.strictEqual(tr.stdout.indexOf('Log file not created. Task ended successfully') >= 0, - true, - "should display cleanup message: Log file not created. Task ended successfully."); - done(); - }); + console.log(tr.stderr); + assert.strictEqual(tr.succeeded, expectedSuccess, `Test ${testFile} ${expectedSuccess ? 'should succeed' : 'should fail'}`); + + if (checkMessage) { + assert.strictEqual(tr.stdout.indexOf(checkMessage) >= 0, true, `Expected message: "${checkMessage}"`); + } + }; + + it('should be success with api key', async () => await runTest('success_api_key.js', true)); + it('should be success wait mode', async () => await runTest('success_waitmode.js', true)); + it('should be success no wait mode', async () => await runTest('success_nowait.js', true)); + it('should be failure additional params', async () => await runTest('failure_additional_params.js', false)); + it('should be failure preset', async () => await runTest('failure_wrong_preset.js', false)); + it('should be success no cancel scan', async () => await runTest('success_no_cancel.js', true, 'Pipeline not cancelled, nothing to do.')); + it('should be success cancel scan', async () => await runTest('success_cancel.js', true, 'Canceling scan with ID')); + it('should be success cancel before scan start', async () => await runTest('success_cancel.js', true, 'Log file not created. Task ended successfully.')); }); From 49fd0c039281ff8ad69d47e75ea47cb49ba8fe14 Mon Sep 17 00:00:00 2001 From: AlvoBen Date: Tue, 12 Nov 2024 12:21:37 +0200 Subject: [PATCH 09/15] chnage node version in ci --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ed5e9f4..2892120 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,12 +7,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Use Node.js 14 + - name: Use Node.js 20 uses: actions/setup-node@v4.0.3 env: INPUT_TOKEN: ${{ secrets.NPM_TOKEN }} with: - node-version: 14 + node-version: 20 - name: Authenticate with GitHub package registry run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc - name: npm install From 9e554526bb3d305ccfd87d5531baa99635f56308 Mon Sep 17 00:00:00 2001 From: AlvoBen Date: Tue, 12 Nov 2024 12:33:01 +0200 Subject: [PATCH 10/15] revert test refactoring --- cxAstScan/test/_suite.ts | 120 ++++++++++++++++++++++++++++++++------- 1 file changed, 100 insertions(+), 20 deletions(-) diff --git a/cxAstScan/test/_suite.ts b/cxAstScan/test/_suite.ts index 1e26f6b..fe2132f 100644 --- a/cxAstScan/test/_suite.ts +++ b/cxAstScan/test/_suite.ts @@ -3,30 +3,110 @@ import * as ttm from 'azure-pipelines-task-lib/mock-test'; import * as assert from 'assert'; const nodeVersion = 20; - describe('Task runner test', function () { - this.timeout(3000000); - const runTest = async (testFile: string, expectedSuccess: boolean, checkMessage?: string) => { - const tp = path.join(__dirname, testFile); + + it('should be success with api key', async function (done) { + this.timeout(3000000); + const tp = path.join(__dirname, 'success_api_key.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + await tr.runAsync(nodeVersion); + + console.log(tr.stdout) + console.log(tr.stderr) + assert.ok(tr.succeeded); + done(); + }); + + it('should be success wait mode', async function (done) { + this.timeout(3000000); + const tp = path.join(__dirname, 'success_waitmode.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + await tr.runAsync(nodeVersion); + + console.log(tr.stdout) + console.log(tr.stderr) + assert.ok(tr.succeeded); + done(); + }); + + it('should be success no wait mode', async function (done) { + this.timeout(3000000); + const tp = path.join(__dirname, 'success_nowait.js'); const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); await tr.runAsync(nodeVersion); + console.log(tr.stdout) + console.log(tr.stderr) + assert.ok(tr.succeeded); + done(); + }); + + it('should be failure additional params', async function (done) { + this.timeout(3000000); + const tp = path.join(__dirname, 'failure_additional_params.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + await tr.runAsync(nodeVersion); + console.log(tr.stdout) + console.log(tr.stderr) + assert.ok(tr.failed); + done(); + }); + + it('should be failure preset', async function (done) { + this.timeout(3000000); + const tp = path.join(__dirname, 'failure_wrong_preset.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + await tr.runAsync(nodeVersion); + + console.log(tr.stdout) + console.log(tr.stderr) + assert.ok(tr.failed); + done(); + }); + + it('should be success no cancel scan', async function (done) { + this.timeout(3000000); + const tp = path.join(__dirname, 'success_no_cancel.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + await tr.runAsync(nodeVersion); + console.log(tr.succeeded); + assert.strictEqual(tr.succeeded, true, 'should have succeeded'); + console.log(tr.stdout); + assert.strictEqual(tr.stdout.indexOf('Pipeline not cancelled, nothing to do.') >= 0, + true, + "should display cleanup message: Pipeline not cancelled, nothing to do."); + done(); + }); + + it('should be success cancel scan', async function (done) { + this.timeout(3000000); + const scan = path.join(__dirname, 'success_nowait.js'); + const scanTestRunner: ttm.MockTestRunner = new ttm.MockTestRunner(scan); + await scanTestRunner.runAsync(nodeVersion); + console.log(scanTestRunner.stdout) + console.log(scanTestRunner.stderr) + assert.ok(scanTestRunner.succeeded); + + const tp = path.join(__dirname, 'success_cancel.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + await tr.runAsync(nodeVersion); + console.log(tr.stdout); + assert.strictEqual(tr.stdout.indexOf('Canceling scan with ID') >= 0, + true, + "should display cleanup message: Canceling scan with ID"); + done(); + }); + + it('should be success cancel before scan start', async function (done) { + this.timeout(3000000); + const tp = path.join(__dirname, 'success_cancel.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + await tr.runAsync(nodeVersion); console.log(tr.stdout); - console.log(tr.stderr); - assert.strictEqual(tr.succeeded, expectedSuccess, `Test ${testFile} ${expectedSuccess ? 'should succeed' : 'should fail'}`); - - if (checkMessage) { - assert.strictEqual(tr.stdout.indexOf(checkMessage) >= 0, true, `Expected message: "${checkMessage}"`); - } - }; - - it('should be success with api key', async () => await runTest('success_api_key.js', true)); - it('should be success wait mode', async () => await runTest('success_waitmode.js', true)); - it('should be success no wait mode', async () => await runTest('success_nowait.js', true)); - it('should be failure additional params', async () => await runTest('failure_additional_params.js', false)); - it('should be failure preset', async () => await runTest('failure_wrong_preset.js', false)); - it('should be success no cancel scan', async () => await runTest('success_no_cancel.js', true, 'Pipeline not cancelled, nothing to do.')); - it('should be success cancel scan', async () => await runTest('success_cancel.js', true, 'Canceling scan with ID')); - it('should be success cancel before scan start', async () => await runTest('success_cancel.js', true, 'Log file not created. Task ended successfully.')); + assert.strictEqual(tr.stdout.indexOf('Log file not created. Task ended successfully') >= 0, + true, + "should display cleanup message: Log file not created. Task ended successfully."); + done(); + }); }); From 186df44b8447cc5d0a3c8d6fe737e4b48e7d58c0 Mon Sep 17 00:00:00 2001 From: AlvoBen Date: Tue, 12 Nov 2024 12:39:29 +0200 Subject: [PATCH 11/15] fix tests --- cxAstScan/test/_suite.ts | 120 +++++++-------------------------------- 1 file changed, 20 insertions(+), 100 deletions(-) diff --git a/cxAstScan/test/_suite.ts b/cxAstScan/test/_suite.ts index fe2132f..1e26f6b 100644 --- a/cxAstScan/test/_suite.ts +++ b/cxAstScan/test/_suite.ts @@ -3,110 +3,30 @@ import * as ttm from 'azure-pipelines-task-lib/mock-test'; import * as assert from 'assert'; const nodeVersion = 20; -describe('Task runner test', function () { - - - it('should be success with api key', async function (done) { - this.timeout(3000000); - const tp = path.join(__dirname, 'success_api_key.js'); - const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); - await tr.runAsync(nodeVersion); - - console.log(tr.stdout) - console.log(tr.stderr) - assert.ok(tr.succeeded); - done(); - }); - - it('should be success wait mode', async function (done) { - this.timeout(3000000); - const tp = path.join(__dirname, 'success_waitmode.js'); - const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); - await tr.runAsync(nodeVersion); - console.log(tr.stdout) - console.log(tr.stderr) - assert.ok(tr.succeeded); - done(); - }); - - it('should be success no wait mode', async function (done) { - this.timeout(3000000); - const tp = path.join(__dirname, 'success_nowait.js'); - const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); - await tr.runAsync(nodeVersion); - - console.log(tr.stdout) - console.log(tr.stderr) - assert.ok(tr.succeeded); - done(); - }); - - it('should be failure additional params', async function (done) { - this.timeout(3000000); - const tp = path.join(__dirname, 'failure_additional_params.js'); - const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); - await tr.runAsync(nodeVersion); - console.log(tr.stdout) - console.log(tr.stderr) - assert.ok(tr.failed); - done(); - }); - - it('should be failure preset', async function (done) { - this.timeout(3000000); - const tp = path.join(__dirname, 'failure_wrong_preset.js'); - const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); - await tr.runAsync(nodeVersion); - - console.log(tr.stdout) - console.log(tr.stderr) - assert.ok(tr.failed); - done(); - }); - - it('should be success no cancel scan', async function (done) { - this.timeout(3000000); - const tp = path.join(__dirname, 'success_no_cancel.js'); - const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); - await tr.runAsync(nodeVersion); - console.log(tr.succeeded); - assert.strictEqual(tr.succeeded, true, 'should have succeeded'); - console.log(tr.stdout); - assert.strictEqual(tr.stdout.indexOf('Pipeline not cancelled, nothing to do.') >= 0, - true, - "should display cleanup message: Pipeline not cancelled, nothing to do."); - done(); - }); - - it('should be success cancel scan', async function (done) { - this.timeout(3000000); - const scan = path.join(__dirname, 'success_nowait.js'); - const scanTestRunner: ttm.MockTestRunner = new ttm.MockTestRunner(scan); - await scanTestRunner.runAsync(nodeVersion); - console.log(scanTestRunner.stdout) - console.log(scanTestRunner.stderr) - assert.ok(scanTestRunner.succeeded); +describe('Task runner test', function () { + this.timeout(3000000); - const tp = path.join(__dirname, 'success_cancel.js'); + const runTest = async (testFile: string, expectedSuccess: boolean, checkMessage?: string) => { + const tp = path.join(__dirname, testFile); const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); await tr.runAsync(nodeVersion); - console.log(tr.stdout); - assert.strictEqual(tr.stdout.indexOf('Canceling scan with ID') >= 0, - true, - "should display cleanup message: Canceling scan with ID"); - done(); - }); - it('should be success cancel before scan start', async function (done) { - this.timeout(3000000); - const tp = path.join(__dirname, 'success_cancel.js'); - const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); - await tr.runAsync(nodeVersion); console.log(tr.stdout); - assert.strictEqual(tr.stdout.indexOf('Log file not created. Task ended successfully') >= 0, - true, - "should display cleanup message: Log file not created. Task ended successfully."); - done(); - }); + console.log(tr.stderr); + assert.strictEqual(tr.succeeded, expectedSuccess, `Test ${testFile} ${expectedSuccess ? 'should succeed' : 'should fail'}`); + + if (checkMessage) { + assert.strictEqual(tr.stdout.indexOf(checkMessage) >= 0, true, `Expected message: "${checkMessage}"`); + } + }; + + it('should be success with api key', async () => await runTest('success_api_key.js', true)); + it('should be success wait mode', async () => await runTest('success_waitmode.js', true)); + it('should be success no wait mode', async () => await runTest('success_nowait.js', true)); + it('should be failure additional params', async () => await runTest('failure_additional_params.js', false)); + it('should be failure preset', async () => await runTest('failure_wrong_preset.js', false)); + it('should be success no cancel scan', async () => await runTest('success_no_cancel.js', true, 'Pipeline not cancelled, nothing to do.')); + it('should be success cancel scan', async () => await runTest('success_cancel.js', true, 'Canceling scan with ID')); + it('should be success cancel before scan start', async () => await runTest('success_cancel.js', true, 'Log file not created. Task ended successfully.')); }); From d52c26196236baed76c2461184a414f9d679608b Mon Sep 17 00:00:00 2001 From: AlvoBen Date: Tue, 12 Nov 2024 12:48:26 +0200 Subject: [PATCH 12/15] test checking iun delay because of async execution of tests --- cxAstScan/test/_suite.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cxAstScan/test/_suite.ts b/cxAstScan/test/_suite.ts index 1e26f6b..b662fdd 100644 --- a/cxAstScan/test/_suite.ts +++ b/cxAstScan/test/_suite.ts @@ -12,6 +12,8 @@ describe('Task runner test', function () { const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); await tr.runAsync(nodeVersion); + await new Promise((resolve) => setTimeout(resolve, 100)); + console.log(tr.stdout); console.log(tr.stderr); assert.strictEqual(tr.succeeded, expectedSuccess, `Test ${testFile} ${expectedSuccess ? 'should succeed' : 'should fail'}`); From 93ff1beee405c5e2316fb0903085fbc06391dccc Mon Sep 17 00:00:00 2001 From: AlvoBen Date: Tue, 12 Nov 2024 12:58:51 +0200 Subject: [PATCH 13/15] fix tests --- cxAstScan/test/_suite.ts | 116 ++++++++++++++++++++++++++++++++------- 1 file changed, 95 insertions(+), 21 deletions(-) diff --git a/cxAstScan/test/_suite.ts b/cxAstScan/test/_suite.ts index b662fdd..47d9253 100644 --- a/cxAstScan/test/_suite.ts +++ b/cxAstScan/test/_suite.ts @@ -3,32 +3,106 @@ import * as ttm from 'azure-pipelines-task-lib/mock-test'; import * as assert from 'assert'; const nodeVersion = 20; - describe('Task runner test', function () { - this.timeout(3000000); - const runTest = async (testFile: string, expectedSuccess: boolean, checkMessage?: string) => { - const tp = path.join(__dirname, testFile); + it('should be success with api key', async function () { + this.timeout(3000000); + const tp = path.join(__dirname, 'success_api_key.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + await tr.runAsync(nodeVersion); + + console.log(tr.stdout); + console.log(tr.stderr); + assert.ok(tr.succeeded); + }); + + it('should be success wait mode', async function () { + this.timeout(3000000); + const tp = path.join(__dirname, 'success_waitmode.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + await tr.runAsync(nodeVersion); + + console.log(tr.stdout); + console.log(tr.stderr); + assert.ok(tr.succeeded); + }); + + it('should be success no wait mode', async function () { + this.timeout(3000000); + const tp = path.join(__dirname, 'success_nowait.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + await tr.runAsync(nodeVersion); + + console.log(tr.stdout); + console.log(tr.stderr); + assert.ok(tr.succeeded); + }); + + it('should be failure additional params', async function () { + this.timeout(3000000); + const tp = path.join(__dirname, 'failure_additional_params.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + await tr.runAsync(nodeVersion); + + console.log(tr.stdout); + console.log(tr.stderr); + assert.ok(tr.failed); + }); + + it('should be failure preset', async function () { + this.timeout(3000000); + const tp = path.join(__dirname, 'failure_wrong_preset.js'); const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); await tr.runAsync(nodeVersion); - await new Promise((resolve) => setTimeout(resolve, 100)); - console.log(tr.stdout); console.log(tr.stderr); - assert.strictEqual(tr.succeeded, expectedSuccess, `Test ${testFile} ${expectedSuccess ? 'should succeed' : 'should fail'}`); - - if (checkMessage) { - assert.strictEqual(tr.stdout.indexOf(checkMessage) >= 0, true, `Expected message: "${checkMessage}"`); - } - }; - - it('should be success with api key', async () => await runTest('success_api_key.js', true)); - it('should be success wait mode', async () => await runTest('success_waitmode.js', true)); - it('should be success no wait mode', async () => await runTest('success_nowait.js', true)); - it('should be failure additional params', async () => await runTest('failure_additional_params.js', false)); - it('should be failure preset', async () => await runTest('failure_wrong_preset.js', false)); - it('should be success no cancel scan', async () => await runTest('success_no_cancel.js', true, 'Pipeline not cancelled, nothing to do.')); - it('should be success cancel scan', async () => await runTest('success_cancel.js', true, 'Canceling scan with ID')); - it('should be success cancel before scan start', async () => await runTest('success_cancel.js', true, 'Log file not created. Task ended successfully.')); + assert.ok(tr.failed); + }); + + it('should be success no cancel scan', async function () { + this.timeout(3000000); + const tp = path.join(__dirname, 'success_no_cancel.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + await tr.runAsync(nodeVersion); + + console.log(tr.succeeded); + assert.strictEqual(tr.succeeded, true, 'should have succeeded'); + console.log(tr.stdout); + assert.strictEqual(tr.stdout.indexOf('Pipeline not cancelled, nothing to do.') >= 0, + true, + "should display cleanup message: Pipeline not cancelled, nothing to do."); + }); + + it('should be success cancel scan', async function () { + this.timeout(3000000); + const scan = path.join(__dirname, 'success_nowait.js'); + const scanTestRunner: ttm.MockTestRunner = new ttm.MockTestRunner(scan); + await scanTestRunner.runAsync(nodeVersion); + + console.log(scanTestRunner.stdout); + console.log(scanTestRunner.stderr); + assert.ok(scanTestRunner.succeeded); + + const tp = path.join(__dirname, 'success_cancel.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + await tr.runAsync(nodeVersion); + + console.log(tr.stdout); + assert.strictEqual(tr.stdout.indexOf('Canceling scan with ID') >= 0, + true, + "should display cleanup message: Canceling scan with ID"); + }); + + it('should be success cancel before scan start', async function () { + this.timeout(3000000); + const tp = path.join(__dirname, 'success_cancel.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + await tr.runAsync(nodeVersion); + + console.log(tr.stdout); + assert.strictEqual(tr.stdout.indexOf('Log file not created. Task ended successfully') >= 0, + true, + "should display cleanup message: Log file not created. Task ended successfully."); + }); }); From 0a2d4f1d83e577d4df23cc73da1d0d7cb3683a9d Mon Sep 17 00:00:00 2001 From: AlvoBen Date: Thu, 14 Nov 2024 11:51:54 +0200 Subject: [PATCH 14/15] upgrafe js wrapper version --- cxAstScan/package-lock.json | 14 +++++++------- cxAstScan/package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cxAstScan/package-lock.json b/cxAstScan/package-lock.json index d13105d..df749b8 100644 --- a/cxAstScan/package-lock.json +++ b/cxAstScan/package-lock.json @@ -5,15 +5,15 @@ "packages": { "": { "dependencies": { - "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli": "1.0.3", + "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli": "1.0.4", "azure-pipelines-task-lib": "4.13.0" } }, "node_modules/@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli": { "name": "@CheckmarxDev/ast-cli-javascript-wrapper-runtime-cli", - "version": "1.0.3", - "resolved": "https://npm.pkg.github.com/download/@CheckmarxDev/ast-cli-javascript-wrapper-runtime-cli/1.0.3/aeb327e32c46d0f99ae8e6226fda645d54936fce", - "integrity": "sha512-8vD0yyZCU3s7H0gQB7AerP6NesOXJqMsoQPbyorVI6Sk5YY6EAlPkgU9h2KgQwTmBXsQV8+rvhthLBzVctcBww==", + "version": "1.0.4", + "resolved": "https://npm.pkg.github.com/download/@CheckmarxDev/ast-cli-javascript-wrapper-runtime-cli/1.0.4/a4780ae9f14b817b68fc2ea84e2edde8f31e4e0d", + "integrity": "sha512-/ecpVKDByGrv6e+Z9T16fr9eixo2ym319Fhcsd6pL37DJWGxlv1uUno3/MSDfwSdHxmGLApvEsqPkD8JTgJO9w==", "license": "ISC", "dependencies": { "async-mutex": "^0.5.0", @@ -1306,9 +1306,9 @@ }, "dependencies": { "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli": { - "version": "npm:@CheckmarxDev/ast-cli-javascript-wrapper-runtime-cli@1.0.3", - "resolved": "https://npm.pkg.github.com/download/@CheckmarxDev/ast-cli-javascript-wrapper-runtime-cli/1.0.3/aeb327e32c46d0f99ae8e6226fda645d54936fce", - "integrity": "sha512-8vD0yyZCU3s7H0gQB7AerP6NesOXJqMsoQPbyorVI6Sk5YY6EAlPkgU9h2KgQwTmBXsQV8+rvhthLBzVctcBww==", + "version": "npm:@CheckmarxDev/ast-cli-javascript-wrapper-runtime-cli@1.0.4", + "resolved": "https://npm.pkg.github.com/download/@CheckmarxDev/ast-cli-javascript-wrapper-runtime-cli/1.0.4/a4780ae9f14b817b68fc2ea84e2edde8f31e4e0d", + "integrity": "sha512-/ecpVKDByGrv6e+Z9T16fr9eixo2ym319Fhcsd6pL37DJWGxlv1uUno3/MSDfwSdHxmGLApvEsqPkD8JTgJO9w==", "requires": { "async-mutex": "^0.5.0", "axios": "^1.7.7", diff --git a/cxAstScan/package.json b/cxAstScan/package.json index 0824f70..045fdfd 100644 --- a/cxAstScan/package.json +++ b/cxAstScan/package.json @@ -1,6 +1,6 @@ { "dependencies": { "azure-pipelines-task-lib": "4.13.0", - "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli": "1.0.3" + "@checkmarxdev/ast-cli-javascript-wrapper-runtime-cli": "1.0.4" } } From 90c92d476a42525cda6fb1497999eb320f9a9cd4 Mon Sep 17 00:00:00 2001 From: miryamfoiferCX Date: Mon, 18 Nov 2024 14:53:49 +0200 Subject: [PATCH 15/15] delete zip file (AST-40077) --- cxAstScan/services/CleanUpRunner.ts | 4 ++-- cxAstScan/test/_suite.ts | 6 ++++++ package-lock.json | 7 ++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cxAstScan/services/CleanUpRunner.ts b/cxAstScan/services/CleanUpRunner.ts index be28e50..096acc9 100644 --- a/cxAstScan/services/CleanUpRunner.ts +++ b/cxAstScan/services/CleanUpRunner.ts @@ -97,8 +97,8 @@ export class CleanUpRunner { } extractZipFilePath(data: string): string | null { - const zipFilePattern = /Temporary zip file path:\s*(.+)$/; + const zipFilePattern = /Temporary zip file path:\s*(.*)$/m; const match = data.match(zipFilePattern); - return match ? match[1] : null; + return match ? match[1].trim() : null; } } diff --git a/cxAstScan/test/_suite.ts b/cxAstScan/test/_suite.ts index 47d9253..d1844b4 100644 --- a/cxAstScan/test/_suite.ts +++ b/cxAstScan/test/_suite.ts @@ -72,6 +72,9 @@ describe('Task runner test', function () { assert.strictEqual(tr.stdout.indexOf('Pipeline not cancelled, nothing to do.') >= 0, true, "should display cleanup message: Pipeline not cancelled, nothing to do."); + assert.strictEqual(tr.stdout.indexOf('Deleted zip file') >= 0 || tr.stdout.indexOf('Zip file already deleted.') >= 0, + true, + "should display cleanup message: Deleted zip file or Zip file already deleted."); }); it('should be success cancel scan', async function () { @@ -92,6 +95,9 @@ describe('Task runner test', function () { assert.strictEqual(tr.stdout.indexOf('Canceling scan with ID') >= 0, true, "should display cleanup message: Canceling scan with ID"); + assert.strictEqual(tr.stdout.indexOf('Deleted zip file') >= 0 || tr.stdout.indexOf('Zip file already deleted.') >= 0, + true, + "should display cleanup message: Deleted zip file or Zip file already deleted."); }); it('should be success cancel before scan start', async function () { diff --git a/package-lock.json b/package-lock.json index 8965db1..67a9957 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1345,9 +1345,10 @@ "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==" }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.5", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.5.tgz", + "integrity": "sha512-ZVJrKKYunU38/76t0RMOulHOnUcbU9GbpWKAOZ0mhjr7CX6FVrH+4FrAapSOekrgFQ3f/8gwMEuIft0aKq6Hug==", + "license": "MIT", "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0",