mobbdev 0.0.49 → 0.0.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -600,6 +600,11 @@ import { globby } from "globby";
600
600
  import { isBinary } from "istextorbinary";
601
601
  var debug4 = Debug4("mobbdev:pack");
602
602
  var MAX_FILE_SIZE = 1024 * 1024 * 5;
603
+ function endsWithAny(str, suffixes) {
604
+ return suffixes.some(function(suffix) {
605
+ return str.endsWith(suffix);
606
+ });
607
+ }
603
608
  async function pack(srcDirPath, vulnFiles) {
604
609
  debug4("pack folder %s", srcDirPath);
605
610
  const filepaths = await globby("**", {
@@ -613,7 +618,10 @@ async function pack(srcDirPath, vulnFiles) {
613
618
  debug4("compressing files");
614
619
  for (const filepath of filepaths) {
615
620
  const absFilepath = path3.join(srcDirPath, filepath.toString());
616
- if (!vulnFiles.includes(filepath.toString())) {
621
+ if (!endsWithAny(
622
+ absFilepath.toString().replaceAll(path3.win32.sep, path3.posix.sep),
623
+ vulnFiles
624
+ )) {
617
625
  debug4("ignoring %s because it is not a vulnerability file", filepath);
618
626
  continue;
619
627
  }
@@ -756,12 +764,15 @@ import chalk from "chalk";
756
764
  import Debug6 from "debug";
757
765
  import { existsSync } from "fs";
758
766
  import { createSpinner as createSpinner2 } from "nanospinner";
767
+ import { type } from "os";
759
768
  import path4 from "path";
760
769
  var debug5 = Debug6("mobbdev:checkmarx");
761
770
  var require2 = createRequire(import.meta.url);
762
771
  var getCheckmarxPath = () => {
772
+ const os3 = type();
773
+ const cxFileName = os3 === "Windows_NT" ? "cx.exe" : "cx";
763
774
  try {
764
- return require2.resolve(".bin/cx");
775
+ return require2.resolve(`.bin/${cxFileName}`);
765
776
  } catch (e) {
766
777
  throw new CliError(cxOperatingSystemSupportMessage);
767
778
  }
@@ -802,7 +813,7 @@ async function forkCheckmarx(args, { display }) {
802
813
  { display }
803
814
  );
804
815
  }
805
- async function getCheckmarxReport({ reportPath, repositoryRoot, branch }, { skipPrompts = false }) {
816
+ async function getCheckmarxReport({ reportPath, repositoryRoot, branch, projectName }, { skipPrompts = false }) {
806
817
  debug5("get checkmarx report start %s %s", reportPath, repositoryRoot);
807
818
  const { code: loginCode } = await forkCheckmarx(VALIDATE_COMMAND, {
808
819
  display: false
@@ -822,7 +833,7 @@ async function getCheckmarxReport({ reportPath, repositoryRoot, branch }, { skip
822
833
  branch,
823
834
  filePath,
824
835
  fileName,
825
- projectName: "mobb_dev"
836
+ projectName
826
837
  });
827
838
  console.log("\u280B \u{1F50D} Initiating Checkmarx Scan ");
828
839
  const { code: scanCode } = await forkCheckmarx(
@@ -852,7 +863,7 @@ async function validateCheckamxCredentials() {
852
863
  Here's a suggestion for checkmarx configuation:
853
864
  ${chalk.bold("AST Base URI:")} https://ast.checkmarx.net
854
865
  ${chalk.bold("AST Base Auth URI (IAM):")} https://iam.checkmarx.net
855
- `);
866
+ `);
856
867
  await forkCheckmarx(CONFIGURE_COMMAND, { display: true });
857
868
  const { code: loginCode } = await forkCheckmarx(VALIDATE_COMMAND, {
858
869
  display: false
@@ -2149,7 +2160,8 @@ async function _scan({
2149
2160
  srcPath,
2150
2161
  commitHash,
2151
2162
  ref,
2152
- scanner
2163
+ scanner,
2164
+ cxProjectName
2153
2165
  }, { skipPrompts = false } = {}) {
2154
2166
  debug8("start %s %s", dirname, repo);
2155
2167
  const { createSpinner: createSpinner4 } = Spinner2({ ci });
@@ -2257,8 +2269,16 @@ async function _scan({
2257
2269
  await getSnykReport(reportPath2, repositoryRoot, { skipPrompts });
2258
2270
  break;
2259
2271
  case "checkmarx":
2272
+ if (!cxProjectName) {
2273
+ throw new Error("cxProjectName is required for checkmarx scanner");
2274
+ }
2260
2275
  await getCheckmarxReport(
2261
- { reportPath: reportPath2, repositoryRoot, branch: reference },
2276
+ {
2277
+ reportPath: reportPath2,
2278
+ repositoryRoot,
2279
+ branch: reference,
2280
+ projectName: cxProjectName
2281
+ },
2262
2282
  { skipPrompts }
2263
2283
  );
2264
2284
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobbdev",
3
- "version": "0.0.49",
3
+ "version": "0.0.51",
4
4
  "description": "Automated secure code remediation tool",
5
5
  "repository": "https://github.com/mobb-dev/bugsy",
6
6
  "main": "dist/index.js",
@@ -1,30 +1,65 @@
1
1
  // this file is based from 'binary-install' https://www.npmjs.com/package/binary-install
2
+ import AdmZip from 'adm-zip'
2
3
  import axios from 'axios'
3
4
  import { existsSync, mkdirSync } from 'fs'
4
5
  import { arch as _arch, type as _type } from 'os'
5
6
  import { join } from 'path'
6
7
  import tar from 'tar'
7
8
 
8
- const __dirname = process.env['PWD']
9
+ /**
10
+ * Options for showing a installParams.
11
+ * @typedef {Object} InstallParams
12
+ * @property {string} installParams.binaryName
13
+ * @property {string} installParams.url
14
+ */
15
+
16
+ /**
17
+ * @param {string} url
18
+ * @returns {string}
19
+ */
20
+ function getArchiveType(url) {
21
+ if (url.endsWith('.zip')) {
22
+ return 'zip'
23
+ }
24
+ if (url.endsWith('.tar.gz')) {
25
+ return 'tar'
26
+ }
27
+ throw Error(`Unknown archive type for ${url}`)
28
+ }
9
29
 
10
30
  /**
11
- * @param {Object} installParams
12
- * @param {string} installParams.binaryName
13
- * @param {string} installParams.url
31
+ * @param {InstallParams} opts
14
32
  * @returns {Promise<void>}
15
33
  */
34
+
16
35
  export async function install({ binaryName, url }) {
17
- if (!__dirname) {
18
- throw Error('pwd is undefiled')
19
- }
20
- const installDirectory = join(__dirname, 'node_modules', '.bin')
36
+ const installDirectory = join(process.cwd(), 'node_modules', '.bin')
21
37
  const binaryPath = join(installDirectory, binaryName)
22
38
  if (existsSync(binaryPath)) {
23
39
  console.log(`${binaryName} is already installed, skipping installation.`)
24
40
  return
25
41
  }
42
+ const archiveType = getArchiveType(url)
26
43
  mkdirSync(installDirectory, { recursive: true })
27
44
  console.log(`Downloading release from ${url}`)
45
+ archiveType === 'zip'
46
+ ? installZip({ binaryName, url, installDirectory })
47
+ : installTar({ binaryName, url, installDirectory })
48
+
49
+ console.log(`${binaryName} has been installed!`)
50
+ }
51
+
52
+ /**
53
+ * @typedef {object} InstallDirectory
54
+ * @property {string} installDirectory
55
+ * @typedef {InstallParams & InstallDirectory} ArchiveInstallParams
56
+ **/
57
+
58
+ /**
59
+ * @param {ArchiveInstallParams} opts
60
+ * @returns {Promise<void>}
61
+ */
62
+ async function installTar({ binaryName, url, installDirectory }) {
28
63
  const binaryStream = await axios({ url, responseType: 'stream' })
29
64
  await new Promise((resolve, reject) => {
30
65
  const sink = binaryStream.data.pipe(
@@ -38,5 +73,17 @@ export async function install({ binaryName, url }) {
38
73
  sink.on('finish', () => resolve(null))
39
74
  sink.on('error', (/** @type {Error} */ err) => reject(err))
40
75
  })
41
- console.log(`${binaryName} has been installed!`)
76
+ }
77
+
78
+ /**
79
+ * @param {ArchiveInstallParams} opts
80
+ * @returns {Promise<void>}
81
+ */
82
+ async function installZip({ binaryName, url, installDirectory }) {
83
+ const body = await axios.get(url, {
84
+ responseType: 'arraybuffer',
85
+ })
86
+
87
+ var zip = new AdmZip(body.data)
88
+ zip.extractEntryTo(binaryName, installDirectory)
42
89
  }
@@ -43,7 +43,7 @@ function installBinary() {
43
43
  const { target } = supportedPlatform
44
44
 
45
45
  const url = `https://github.com/Checkmarx/ast-cli/releases/download/2.0.55/ast-cli_${target}`
46
- const binaryName = 'cx'
46
+ const binaryName = supportedPlatform.type === 'Windows_NT' ? 'cx.exe' : 'cx'
47
47
 
48
48
  install({ binaryName, url })
49
49
  }