diff --git a/.github/workflows/e2e-ci.yml b/.github/workflows/e2e-ci.yml index 02b93ad7b..a7cf50637 100644 --- a/.github/workflows/e2e-ci.yml +++ b/.github/workflows/e2e-ci.yml @@ -17,18 +17,18 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Setup Node.js ${{ matrix.platform }} + - name: Setup Node.js on ${{ matrix.platform }} uses: actions/setup-node@v4 with: node-version: "18" check-latest: true cache: 'npm' - - name: Install dependencies ${{ matrix.platform }} + - name: Install dependencies on ${{ matrix.platform }} run: npm ci - - name: Prepack ${{ matrix.platform }} + - name: Prepack (compile) on ${{ matrix.platform }} run: npm run prepack - - name: Run e2e tests ${{ matrix.platform }} + - name: Run e2e tests on ${{ matrix.platform }} run: npm run test diff --git a/.gitignore b/.gitignore index 0dbf494d0..6bdbe2205 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ generatedMD.md /lib /tmp /bin/deepsource +/test/logs +/test/sample_data/inspec/json/profile_and_controls/mapped_controls node_modules **/.DS_Store *.*.un~ diff --git a/package-lock.json b/package-lock.json index 90a77f109..71ab2e226 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,10 +40,12 @@ "@types/xml2js": "^0.4.12", "accurate-search": "^1.2.15", "ajv": "^8.12.0", + "app-root-path": "^3.1.0", "axios": "^1.5.0", "chai": "^4", "colors": "^1.4.0", "csv-parse": "^4.16.0", + "deep-diff": "^1.0.2", "dotenv": "^16.3.1", "express": "^4.17.3", "fast-xml-parser": "^4.2.7", @@ -60,6 +62,7 @@ "jest": "^29.7.0", "jest-mock": "^29.7.0", "js-yaml": "^4.1.0", + "jsdom": "^25.0.1", "json-colorizer": "^3.0.1", "lodash": "^4.17.21", "markdown-diff": "^2.0.0", @@ -89,7 +92,9 @@ "devDependencies": { "@e965/xlsx": "^0.20.0", "@oclif/test": "^4.1.0", + "@types/deep-diff": "^1.0.5", "@types/js-yaml": "^4.0.9", + "@types/jsdom": "^21.1.7", "@types/mock-fs": "^4.13.4", "@typescript-eslint/eslint-plugin": "~7.18.0", "eslint": "^8.48.0", @@ -7758,6 +7763,12 @@ "@types/pumpify": "*" } }, + "node_modules/@types/deep-diff": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@types/deep-diff/-/deep-diff-1.0.5.tgz", + "integrity": "sha512-PQyNSy1YMZU1hgZA5tTYfHPpUAo9Dorn1PZho2/budQLfqLu3JIP37JAavnwYpR1S2yFZTXa3hxaE4ifGW5jaA==", + "dev": true + }, "node_modules/@types/duplexify": { "version": "3.6.4", "resolved": "https://registry.npmjs.org/@types/duplexify/-/duplexify-3.6.4.tgz", @@ -7867,6 +7878,17 @@ "integrity": "sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg==", "dev": true }, + "node_modules/@types/jsdom": { + "version": "21.1.7", + "resolved": "https://registry.npmjs.org/@types/jsdom/-/jsdom-21.1.7.tgz", + "integrity": "sha512-yOriVnggzrnQ3a9OKOCxaVuSug3w3/SbOj5i7VwXWZEyUNl3bLF9V3MfxGbZKuwqJOQyRfqXyROBB1CoZLFWzA==", + "dev": true, + "dependencies": { + "@types/node": "*", + "@types/tough-cookie": "*", + "parse5": "^7.0.0" + } + }, "node_modules/@types/json-diff": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/@types/json-diff/-/json-diff-0.7.0.tgz", @@ -8036,6 +8058,12 @@ "resolved": "https://registry.npmjs.org/@types/tmp/-/tmp-0.2.6.tgz", "integrity": "sha512-chhaNf2oKHlRkDGt+tiKE2Z5aJ6qalm7Z9rlLdBwmOiAAf09YQvvoLXjWK4HWPF1xU/fqvMgfNfpVoBscA/tKA==" }, + "node_modules/@types/tough-cookie": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.5.tgz", + "integrity": "sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA==", + "dev": true + }, "node_modules/@types/triple-beam": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/@types/triple-beam/-/triple-beam-1.3.5.tgz", @@ -8757,6 +8785,14 @@ "node": ">= 8" } }, + "node_modules/app-root-path": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/app-root-path/-/app-root-path-3.1.0.tgz", + "integrity": "sha512-biN3PwB2gUtjaYy/isrU3aNWI5w+fAfvHkSvCKeQGxhmYpwKFUxudR3Yya+KqVRHBmEDYh+/lTozYCFbmzX4nA==", + "engines": { + "node": ">= 6.0.0" + } + }, "node_modules/arg": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/arg/-/arg-5.0.2.tgz", @@ -9772,6 +9808,17 @@ "node": ">=4" } }, + "node_modules/cssstyle": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-4.1.0.tgz", + "integrity": "sha512-h66W1URKpBS5YMI/V8PyXvTMFT8SupJ1IzoIV8IeBC/ji8WVmrO8dGlTi+2dh6whmdk6BiKJLD/ZBkhWbcg6nA==", + "dependencies": { + "rrweb-cssom": "^0.7.1" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/csv": { "version": "5.5.3", "resolved": "https://registry.npmjs.org/csv/-/csv-5.5.3.tgz", @@ -9851,6 +9898,18 @@ "node": ">=0.12" } }, + "node_modules/data-urls": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-5.0.0.tgz", + "integrity": "sha512-ZYP5VBHshaDAiVZxjbRVcFJpc+4xGgT0bK3vzy1HLN8jTO975HEbuYzZJcHoQEY5K1a0z8YayJkyVETa08eNTg==", + "dependencies": { + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/debug": { "version": "4.3.7", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", @@ -9879,6 +9938,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/decimal.js": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.4.3.tgz", + "integrity": "sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA==" + }, "node_modules/decompress-response": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz", @@ -9919,6 +9983,11 @@ } } }, + "node_modules/deep-diff": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/deep-diff/-/deep-diff-1.0.2.tgz", + "integrity": "sha512-aWS3UIVH+NPGCD1kki+DCU9Dua032iSsO43LqQpcs4R3+dVv7tX0qBGjiVHJHjplsoUM2XRO/KB92glqc68awg==" + }, "node_modules/deep-eql": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-4.1.3.tgz", @@ -12486,6 +12555,17 @@ "node": "14 || >=16.14" } }, + "node_modules/html-encoding-sniffer": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-4.0.0.tgz", + "integrity": "sha512-Y22oTqIU4uuPgEemfz7NDJz6OeKf12Lsu+QC+s3BVpda64lTiMYCyGwg5ki4vFxkMwQdeZDl2adZoqUgdFuTgQ==", + "dependencies": { + "whatwg-encoding": "^3.1.1" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/html-entities": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/html-entities/-/html-entities-2.5.2.tgz", @@ -12907,6 +12987,11 @@ "node": ">=8" } }, + "node_modules/is-potential-custom-element-name": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz", + "integrity": "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==" + }, "node_modules/is-promise": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.2.2.tgz", @@ -13725,6 +13810,45 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/jsdom": { + "version": "25.0.1", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-25.0.1.tgz", + "integrity": "sha512-8i7LzZj7BF8uplX+ZyOlIz86V6TAsSs+np6m1kpW9u0JWi4z/1t+FzcK1aek+ybTnAC4KhBL4uXCNT0wcUIeCw==", + "dependencies": { + "cssstyle": "^4.1.0", + "data-urls": "^5.0.0", + "decimal.js": "^10.4.3", + "form-data": "^4.0.0", + "html-encoding-sniffer": "^4.0.0", + "http-proxy-agent": "^7.0.2", + "https-proxy-agent": "^7.0.5", + "is-potential-custom-element-name": "^1.0.1", + "nwsapi": "^2.2.12", + "parse5": "^7.1.2", + "rrweb-cssom": "^0.7.1", + "saxes": "^6.0.0", + "symbol-tree": "^3.2.4", + "tough-cookie": "^5.0.0", + "w3c-xmlserializer": "^5.0.0", + "webidl-conversions": "^7.0.0", + "whatwg-encoding": "^3.1.1", + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.0.0", + "ws": "^8.18.0", + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "canvas": "^2.11.2" + }, + "peerDependenciesMeta": { + "canvas": { + "optional": true + } + } + }, "node_modules/jsesc": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.0.2.tgz", @@ -17594,6 +17718,11 @@ "inBundle": true, "license": "ISC" }, + "node_modules/nwsapi": { + "version": "2.2.13", + "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.13.tgz", + "integrity": "sha512-cTGB9ptp9dY9A5VbMSe7fQBcl/tt22Vcqdq8+eN93rblOuE0aCFu4aZ2vMwct/2t+lFnosm8RkQW1I0Omb1UtQ==" + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -17905,6 +18034,17 @@ "node": ">=0.10.0" } }, + "node_modules/parse5": { + "version": "7.2.1", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.2.1.tgz", + "integrity": "sha512-BuBYQYlv1ckiPdQi/ohiivi9Sagc9JG+Ozs0r7b/0iK3sKmrb0b9FdWdBbOdx6hBCM/F9Ir82ofnBhtZOjCRPQ==", + "dependencies": { + "entities": "^4.5.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, "node_modules/parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", @@ -18429,7 +18569,6 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", - "dev": true, "engines": { "node": ">=6" } @@ -18908,6 +19047,11 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/rrweb-cssom": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.7.1.tgz", + "integrity": "sha512-TrEMa7JGdVm0UThDJSx7ddw5nVm3UJS9o9CCIZ72B1vSyEZoziDqBYP3XIoi/12lKrJR8rE3jeFHMok2F/Mnsg==" + }, "node_modules/run-applescript": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/run-applescript/-/run-applescript-7.0.0.tgz", @@ -19020,6 +19164,17 @@ "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.1.tgz", "integrity": "sha512-8I2a3LovHTOpm7NV5yOyO8IHqgVsfK4+UuySrXU8YXkSRX7k6hCV9b3HrkKCr3nMpgj+0bmocaJJWpvp1oc7ZA==" }, + "node_modules/saxes": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/saxes/-/saxes-6.0.0.tgz", + "integrity": "sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==", + "dependencies": { + "xmlchars": "^2.2.0" + }, + "engines": { + "node": ">=v12.22.7" + } + }, "node_modules/semver": { "version": "7.6.3", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", @@ -19671,6 +19826,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/symbol-tree": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", + "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==" + }, "node_modules/table": { "version": "6.8.2", "resolved": "https://registry.npmjs.org/table/-/table-6.8.2.tgz", @@ -19829,6 +19989,22 @@ "integrity": "sha512-ik6BCxzva9DoiEfDX/li0L2cWKPPENYvixUprFdl3YPi4bZZUhDnNI9YUkacrv+uIG90dnxR5mNqaoD6UhD6Bw==", "dev": true }, + "node_modules/tldts": { + "version": "6.1.61", + "resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.61.tgz", + "integrity": "sha512-rv8LUyez4Ygkopqn+M6OLItAOT9FF3REpPQDkdMx5ix8w4qkuE7Vo2o/vw1nxKQYmJDV8JpAMJQr1b+lTKf0FA==", + "dependencies": { + "tldts-core": "^6.1.61" + }, + "bin": { + "tldts": "bin/cli.js" + } + }, + "node_modules/tldts-core": { + "version": "6.1.61", + "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-6.1.61.tgz", + "integrity": "sha512-In7VffkDWUPgwa+c9picLUxvb0RltVwTkSgMNFgvlGSWveCzGBemBqTsgJCL4EDFWZ6WH0fKTsot6yNhzy3ZzQ==" + }, "node_modules/tmp": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.3.tgz", @@ -19870,6 +20046,28 @@ "node": ">=0.6" } }, + "node_modules/tough-cookie": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-5.0.0.tgz", + "integrity": "sha512-FRKsF7cz96xIIeMZ82ehjC3xW2E+O2+v11udrDYewUbszngYhsGa8z6YUMMzO9QJZzzyd0nGGXnML/TReX6W8Q==", + "dependencies": { + "tldts": "^6.1.32" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/tr46": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.0.0.tgz", + "integrity": "sha512-tk2G5R2KRwBd+ZN0zaEXpmzdKyOYksXwywulIX95MBODjSzMIuQnQ3m8JxgbhnL1LeVo7lqQKsYa1O3Htl7K5g==", + "dependencies": { + "punycode": "^2.3.1" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/triple-beam": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.4.1.tgz", @@ -20492,6 +20690,17 @@ "node": ">= 0.8" } }, + "node_modules/w3c-xmlserializer": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-5.0.0.tgz", + "integrity": "sha512-o8qghlI8NZHU1lLPrpi2+Uq7abh4GGPpYANlalzWxyWteJOCsr/P+oPBA49TOLu5FTZO4d3F9MnWJfiMo4BkmA==", + "dependencies": { + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/walker": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/walker/-/walker-1.0.8.tgz", @@ -20500,6 +20709,56 @@ "makeerror": "1.0.12" } }, + "node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "engines": { + "node": ">=12" + } + }, + "node_modules/whatwg-encoding": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-3.1.1.tgz", + "integrity": "sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==", + "dependencies": { + "iconv-lite": "0.6.3" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/whatwg-encoding/node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/whatwg-mimetype": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-4.0.0.tgz", + "integrity": "sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg==", + "engines": { + "node": ">=18" + } + }, + "node_modules/whatwg-url": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.0.0.tgz", + "integrity": "sha512-1lfMEm2IEr7RIV+f4lUNPOqfFL+pO+Xw3fJSqmjX9AbXcXcYOkCe1P6+9VBZB6n94af16NfZf+sSk0JCBZC9aw==", + "dependencies": { + "tr46": "^5.0.0", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -20620,6 +20879,26 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/ws": { + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", + "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, "node_modules/xlsx-populate": { "version": "1.21.0", "resolved": "https://registry.npmjs.org/xlsx-populate/-/xlsx-populate-1.21.0.tgz", @@ -20647,6 +20926,14 @@ "node": ">= 14" } }, + "node_modules/xml-name-validator": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-5.0.0.tgz", + "integrity": "sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==", + "engines": { + "node": ">=18" + } + }, "node_modules/xml-parser-xo": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/xml-parser-xo/-/xml-parser-xo-4.1.1.tgz", @@ -20675,6 +20962,11 @@ "node": ">=4.0" } }, + "node_modules/xmlchars": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", + "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==" + }, "node_modules/xmlhttprequest": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz", diff --git a/package.json b/package.json index 956c45a7c..a1a216fbb 100644 --- a/package.json +++ b/package.json @@ -37,10 +37,12 @@ "@types/xml2js": "^0.4.12", "accurate-search": "^1.2.15", "ajv": "^8.12.0", + "app-root-path": "^3.1.0", "axios": "^1.5.0", "chai": "^4", "colors": "^1.4.0", "csv-parse": "^4.16.0", + "deep-diff": "^1.0.2", "dotenv": "^16.3.1", "express": "^4.17.3", "fast-xml-parser": "^4.2.7", @@ -57,6 +59,7 @@ "jest": "^29.7.0", "jest-mock": "^29.7.0", "js-yaml": "^4.1.0", + "jsdom": "^25.0.1", "json-colorizer": "^3.0.1", "lodash": "^4.17.21", "markdown-diff": "^2.0.0", @@ -83,7 +86,9 @@ "devDependencies": { "@e965/xlsx": "^0.20.0", "@oclif/test": "^4.1.0", + "@types/deep-diff": "^1.0.5", "@types/js-yaml": "^4.0.9", + "@types/jsdom": "^21.1.7", "@types/mock-fs": "^4.13.4", "@typescript-eslint/eslint-plugin": "~7.18.0", "eslint": "^8.48.0", @@ -116,7 +121,9 @@ "helpClass": "./lib/utils/oclif/help/help", "theme": "./oclif-theme.json", "additionalHelpFlags": [ - "-h", "--tell-me-more", "--explain" + "-h", + "--tell-me-more", + "--explain" ], "additionalVersionFlags": [ "-v" @@ -192,8 +199,8 @@ "dev": "rm -rf lib && tsc && node bin/run", "test": "npm run test:mocha && npm run test:jest", "tests": "npm run test", - "test:mocha": "ts-mocha --timeout 8500 --forbid-only \"test/**/*.test.ts\"", - "test:mocha:one": "ts-mocha --timeout 8500 --forbid-only", + "test:mocha": "ts-mocha --timeout 25000 --forbid-only \"test/**/*.test.ts\"", + "test:mocha:one": "ts-mocha --timeout 25000 --forbid-only", "test:jest": "jest", "test:jest:one": "jest --findRelatedTests", "prepack": "run-script-os", diff --git a/src/commands/generate/inspec_profile.ts b/src/commands/generate/inspec_profile.ts index 678c5c232..b21b1c0f5 100644 --- a/src/commands/generate/inspec_profile.ts +++ b/src/commands/generate/inspec_profile.ts @@ -34,7 +34,7 @@ export default class InspecProfile extends BaseCommand { static readonly flags = { xccdfXmlFile: Flags.string({ - char: 'i', + char: 'X', required: true, description: 'Path to the XCCDF benchmark file', }), diff --git a/src/commands/view/heimdall.ts b/src/commands/view/heimdall.ts index 82bf66c92..aed01203b 100644 --- a/src/commands/view/heimdall.ts +++ b/src/commands/view/heimdall.ts @@ -1,3 +1,4 @@ + import {Command, Flags} from '@oclif/core' import express from 'express' import fs from 'fs' @@ -23,7 +24,9 @@ export default class Heimdall extends Command { async run() { // NOTE: The npm open package is native ESM and no longer provides a CommonJS export // The SAF CLI is a CommonJS project and needs to dynamic import the open package - // Doing a normal dynamic import in typescript doesn't work because typescript will still translate the import into a require. This library works around that issue by preventing that translation from occurring. + // Doing a normal dynamic import in typescript doesn't work because typescript will + // still translate the import into a require. This library works around that issue + // by preventing that translation from occurring. const openDynamicImport = await dynamicImport('open', module) // eslint-disable-line unicorn/prefer-module const open = openDynamicImport.default @@ -68,7 +71,7 @@ export default class Heimdall extends Command { } } - const installedPath = getInstalledPath() + const installedPath = getInstalledPath('@mitre/saf') express() .use(predefinedLoadJSON) diff --git a/src/utils/global.ts b/src/utils/global.ts index 643983054..1fb7c7bde 100644 --- a/src/utils/global.ts +++ b/src/utils/global.ts @@ -1,7 +1,7 @@ +import appRootPath from 'app-root-path' import {fingerprint} from '@mitre/hdf-converters' import {getInstalledPathSync} from 'get-installed-path' -import {ContextualizedEvaluation, ExecJSON} from 'inspecjs' -import {ExecJSONProfile} from 'inspecjs/lib/generated_parsers/v_1_0/exec-json' +import {AnyProfile, ContextualizedEvaluation, ExecJSON} from 'inspecjs' import _ from 'lodash' import path from 'path' @@ -17,23 +17,54 @@ export function checkSuffix(input: string) { return `${input}.json` } +/** + * The `convertFullPathToFilename` function. + * + * This function returns the last value for a given path, using path.basename + * witch is usually the filename. + * + * The reason this function was originally developed was due to path.basename not + * working as expected, not sure what was observed that made it not working as expected. + * + * The original function code was: + * ============================================================================ + * let filePath = inputPath.split('/') + * let basename = inputPath.endsWith('/') ? filePath.at(-2) : filePath.at(-1) + * if (!basename) { + * throw new Error('Could not derive basename from file path') + * } + * + * filePath = basename.split('\\') + * basename = filePath.at(-1) + * if (!basename) { + * throw new Error('Could not derive basename from file path') + * } + * + * return basename + * ============================================================================ + * @param inputPath - The full path to convert. This should be a string representing a valid file path. + * + * @returns {string} - The filename extracted from the full path. If the path does not contain a filename, an empty string is returned. + */ // replacement for path.basename since it doesn't "just work" as one would expect with handling paths from other filesystem types export function convertFullPathToFilename(inputPath: string): string { - let filePath = inputPath.split('/') - let basename = filePath.at(-1) - if (!basename) { - throw new Error('Could not derive basename from file path') - } - - filePath = basename.split('\\') - basename = filePath.at(-1) - if (!basename) { - throw new Error('Could not derive basename from file path') - } - - return basename + return path.basename(inputPath) } +/** + * The `dataURLtoU8Array` function. + * + * This function converts a data URL into a Uint8Array. + * + * - First, it splits the data URL into an array using a comma as the separator. + * - Then, it decodes the second part of the array (the base64 string) into a binary string. + * - It creates a new Uint8Array with the same length as the binary string. + * - Finally, it fills the Uint8Array with the char codes from the binary string. + * + * @param dataURL - The data URL to convert. This should be a base64-encoded data URL. + * + * @returns {Uint8Array} - The Uint8Array representation of the data URL. + */ export function dataURLtoU8Array(dataURL: string): Uint8Array { const arr = dataURL.split(',') const bstr = atob(arr[1]) @@ -48,14 +79,24 @@ export function dataURLtoU8Array(dataURL: string): Uint8Array { return u8arr } -export function getInstalledPath(): string { - let installedPath = '' - +/** + * The `getInstalledPath` function. + * + * This function retrieves the installed path of a specified package. + * If the package is not installed, it returns the application root path. + * + * - First, it attempts to get the installed path of the specified package using `getInstalledPathSync`. + * - If this fails (throws an error), it defaults to the application root path. + * + * @param {string} moduleName - The name of the module to get the installed path for. + * @returns {string} - The installed path of the specified package, or the application root path if the package is not installed. + */ +export function getInstalledPath(moduleName: string): string { + let installedPath try { - installedPath = getInstalledPathSync('@mitre/saf') + installedPath = getInstalledPathSync(moduleName) } catch { - // eslint-disable-next-line unicorn/prefer-module - installedPath = path.join(require.main?.path.replace('/bin', '').replace(String.raw`\bin`, '') || '.') + installedPath = appRootPath.path } return installedPath @@ -63,15 +104,51 @@ export function getInstalledPath(): string { export const arrayedPaths = ['tags.cci', 'tags.nist'] -export function arrayNeededPaths(typeOfPath: string, values: any) { - // Converts CCI and NIST values to Arrays +/** + * The `arrayNeededPaths` function. + * + * This function checks if a path needs to be arrayed based on its type. + * It uses the 'arrayedPaths' array for this check. + * + * @param typeOfPath - The type of path to check. + * This is converted to lowercase and checked against the 'arrayedPaths' array. + * @param values - The values to possibly wrap in an array. + * + * @returns {any | any[]} - If `typeOfPath` is in 'arrayedPaths', `values` is returned as an array. + * Otherwise, `values` is returned as is. + */ +export function arrayNeededPaths(typeOfPath: string, values: string | string[]): string | string[] { + const isArray = Array.isArray(values) + let result if (arrayedPaths.includes(typeOfPath.toLowerCase())) { - return [values] + result = isArray ? values : [values] + } else { + result = values } - return values + return result } +/** + * The `extractValueViaPathOrNumber` function extracts a value from a data object. + * It uses a path or number (`pathOrNumber`) to perform the extraction. + * + * - If `pathOrNumber` is a string, it's treated as a path. The function uses it to extract a value from `data`. + * The extracted value is then processed by `arrayNeededPaths`. + * + * - If `pathOrNumber` is an array, the function finds the first item that corresponds to a property in `data`. + * If no such item is found, it defaults to 'Field Not Defined'. The value of the found or default property is then processed by `arrayNeededPaths`. + * + * - If `pathOrNumber` is a number, the function simply returns it. + * + * @param typeOfPathOrNumber - The type of `pathOrNumber`. Passed to `arrayNeededPaths`. + * @param pathOrNumber - The path or number to extract the value. Treated differently based on its type: + * string (path), array (list of potential paths), or number (returned as is). + * @param data - The data object to extract the value from. + * + * @returns {any} The extracted value. If `pathOrNumber` is a string or array, it's processed by `arrayNeededPaths`. + * If `pathOrNumber` is a number, it's returned as is. + */ export function extractValueViaPathOrNumber(typeOfPathOrNumber: string, pathOrNumber: string | string[] | number, data: Record): any { // Maps paths from mapping file to target value if (typeof pathOrNumber === 'string') { @@ -79,7 +156,8 @@ export function extractValueViaPathOrNumber(typeOfPathOrNumber: string, pathOrNu } if (Array.isArray(pathOrNumber)) { - const foundPath = pathOrNumber.find(item => _.get(data, item)) || 'Field Not Defined' + // const foundPath = pathOrNumber.find(item => _.get(data, item)) || 'Field Not Defined' + const foundPath = pathOrNumber.find(item => _.get(data, item)) ?? 'Field Not Defined' return arrayNeededPaths(typeOfPathOrNumber, _.get(data, foundPath)) } @@ -88,9 +166,41 @@ export function extractValueViaPathOrNumber(typeOfPathOrNumber: string, pathOrNu } } -export function getProfileInfo(evaluation: ContextualizedEvaluation, fileName: string): string { +interface ExtendedContextualizedEvaluation extends ContextualizedEvaluation { + profiles?: AnyProfile[]; // change this line +} + +/** + * The `getProfileInfo` function retrieves and formats profile information from a given evaluation. + * + * - First, it checks if the evaluation data and profile data are available. If not, it returns an empty string. + * - Then, it extracts the first profile from the evaluation data. + * - It creates a string containing the file name and various profile information: + * version, SHA256 hash, maintainer, copyright, copyright email, and control count. + * - If a piece of information is not available (i.e., the property value is falsy), it is not included in the string. + * - The string is then returned, with each piece of information on a new line. + * + * @param evaluation - The evaluation to extract profile information from. + * This should be a `ContextualizedEvaluation` object. + * If this is `null` or `undefined`, the function returns an empty string. + * @param fileName - The name of the file the evaluation is from. + * This is included in the returned string. + * + * @returns {string} A string containing the profile information. + * Each piece of information is on a new line. + * If a piece of information is not available, it is not included in the string. + * If the evaluation data or profile data is not available, it returns an empty string. + */ +// export function getProfileInfo(evaluation: ContextualizedEvaluation, fileName: string): string { +export function getProfileInfo(evaluation: ExtendedContextualizedEvaluation, fileName: string): string { let result = '' - const profile: ExecJSONProfile = _.get(evaluation, 'data.profiles[0]') + // const profile: ExecJSONProfile = _.get(evaluation, 'data.profiles[0]') + const profile: AnyProfile | undefined = evaluation?.profiles ? evaluation.profiles[0] : undefined + + if (!evaluation || !profile) { + return result + } + result += `File Name: ${fileName}\n` if (profile.version) { result += `Version: ${profile.version}\n` @@ -119,7 +229,27 @@ export function getProfileInfo(evaluation: ContextualizedEvaluation, fileName: s return result.trim() } -// Get description from Array of descriptions or Key/String pair +/** + * The `getDescription` function retrieves a specific description from either an array of descriptions or a key/string pair. + * + * - If `descriptions` is an array, it searches for a description object where the `label` property matches the provided `key` (case-insensitive). + * If a match is found, it returns the `data` property of the description object. + * If no match is found, it returns 'description not found'. + * + * - If `descriptions` is a key/string pair, it returns the value associated with the provided `key`. + * If the `key` does not exist in the `descriptions`, it returns 'unknown key'. + * + * @param descriptions - Either an array of description objects or a key/string pair. + * If it's an array, each object should have a `label` (string) and a `data` (string). + * If it's a key/string pair, it's an object where the keys are strings and the values are also strings. + * @param key - The key to retrieve the description. + * If `descriptions` is an array, it should match the `label` of one of the objects. + * If `descriptions` is a key/string pair, it should be one of the keys. + * + * @returns {string} The description associated with the provided `key`, + * 'description not found' if no matching description was found in the array, + * or 'unknown key' if the `key` does not exist in the `descriptions` object. + */ export function getDescription( descriptions: | { @@ -134,7 +264,28 @@ export function getDescription( )?.data : _.get(descriptions, key) } -// Check if file input is of given type - throw error if not +/** + * The `checkInput` function validates the type of an input file. + * + * - It uses the `fingerprint` function to detect the file type. + * - If the detected type doesn't match the desired type, it throws an error. + * + * @param guessOptions - An object with the file data and filename. + * The `data` property is the file content as a string. + * The `filename` property is the file name. + * @param desiredType - A string for the desired file type. + * This is compared with the detected file type. + * @param desiredFormat - A string for the desired file format. + * This is included in the error message if the detected type doesn't match the desired type. + * + * @throws {Error} If the detected file type doesn't match the desired type, + * an error is thrown. The error message includes the detected type, + * the desired format, and a prompt for the user to ensure the input + * is a valid file of the desired format. + * + * @returns {void} This function doesn't return a value. Its purpose is to validate + * the file type and throw an error if the validation fails. + */ export function checkInput(guessOptions: { data: string, filename: string }, desiredType: string, desiredFormat: string): void { const detectedType = fingerprint({data: guessOptions.data, filename: convertFullPathToFilename(guessOptions.filename)}) if (!(detectedType === desiredType)) diff --git a/test/commands/attest/apply.test.ts b/test/commands/attest/apply.test.ts index 1c0fd475e..badecc546 100644 --- a/test/commands/attest/apply.test.ts +++ b/test/commands/attest/apply.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -8,34 +11,31 @@ describe('Test attest apply', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) // NOTE: replacing all CR from the files being generated to ensure proper comparison. - test - .stdout() - .stderr() - .command(['attest apply', '-i', path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus.json'), path.resolve('./test/sample_data/attestations/attestations_jsonFormat.json'), '-o', `${tmpobj.name}/rhel8_attestations_jsonOutput.json`]) - .it('Successfully applies a JSON attestations file', () => { - const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/rhel8_attestations_jsonOutput.json`, 'utf8').replaceAll(/\r/gi, '')) - const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus_output.json'), 'utf8').replaceAll(/\r/gi, '')) + it('Successfully applies a JSON attestations file', async () => { + await runCommand<{name: string}>(['attest apply', + '-i', path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus.json'), + path.resolve('./test/sample_data/attestations/attestations_jsonFormat.json'), + '-o', `${tmpobj.name}/rhel8_attestations_jsonOutput.json`, + ]) + const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/rhel8_attestations_jsonOutput.json`, 'utf8').replaceAll(/\r/gi, '')) + const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus_output.json'), 'utf8').replaceAll(/\r/gi, '')) - expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) - }) + expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) + }) - test - .stdout() - .command(['attest apply', '-i', path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus.json'), path.resolve('./test/sample_data/attestations/attestations_xlsxFormat.xlsx'), '-o', `${tmpobj.name}/rhel8_attestations_xlsxOutput.json`]) - .it('Successfully applies an XLSX attestations file', () => { - const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/rhel8_attestations_xlsxOutput.json`, 'utf8').replaceAll(/\r/gi, '')) - const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus_output.json'), 'utf8').replaceAll(/\r/gi, '')) + it('Successfully applies an XLSX attestations file', async () => { + await runCommand<{name: string}>(['attest apply', '-i', path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus.json'), path.resolve('./test/sample_data/attestations/attestations_xlsxFormat.xlsx'), '-o', `${tmpobj.name}/rhel8_attestations_xlsxOutput.json`]) + const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/rhel8_attestations_xlsxOutput.json`, 'utf8').replaceAll(/\r/gi, '')) + const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus_output.json'), 'utf8').replaceAll(/\r/gi, '')) - expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) - }) + expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) + }) - test - .stdout() - .command(['attest apply', '-i', path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus.json'), path.resolve('./test/sample_data/attestations/attestations_yamlFormat.yaml'), '-o', `${tmpobj.name}/rhel8_attestations_yamlOutput.json`]) - .it('Successfully applies a YAML attestations file', () => { - const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/rhel8_attestations_yamlOutput.json`, 'utf8').replaceAll(/\r/gi, '')) - const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus_output.json'), 'utf8').replaceAll(/\r/gi, '')) + it('Successfully applies a YAML attestations file', async () => { + await runCommand<{name: string}>(['attest apply', '-i', path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus.json'), path.resolve('./test/sample_data/attestations/attestations_yamlFormat.yaml'), '-o', `${tmpobj.name}/rhel8_attestations_yamlOutput.json`]) + const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/rhel8_attestations_yamlOutput.json`, 'utf8').replaceAll(/\r/gi, '')) + const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus_output.json'), 'utf8').replaceAll(/\r/gi, '')) - expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) - }) + expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) + }) }) diff --git a/test/commands/convert/anchoregrype2hdf.test.ts b/test/commands/convert/anchoregrype2hdf.test.ts index 948b93862..8928e71e4 100644 --- a/test/commands/convert/anchoregrype2hdf.test.ts +++ b/test/commands/convert/anchoregrype2hdf.test.ts @@ -1,188 +1,120 @@ -import { expect, test } from "@oclif/test"; -import tmp from "tmp"; -import path from "path"; -import fs from "fs"; -import { omitHDFChangingFields } from "../utils"; +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' +import tmp from 'tmp' +import path from 'path' +import fs from 'fs' +import {omitHDFChangingFields} from '../utils' -describe("Test anchore grype", () => { - const tmpobj = tmp.dirSync({ unsafeCleanup: true }); +describe('Test anchore grype', () => { + const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command([ - "convert anchoregrype2hdf", - "-i", - path.resolve( - "./test/sample_data/anchoregrype/sample_input_report/anchore_grype.json" - ), - "-o", - `${tmpobj.name}/anchore-grype-hdf.json`, + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert anchoregrype2hdf', + '-i', path.resolve('./test/sample_data/anchoregrype/sample_input_report/anchore_grype.json'), + '-o', `${tmpobj.name}/anchore-grype-hdf.json`, ]) - .it("hdf-converter output test", () => { - const converted = JSON.parse( - fs.readFileSync(`${tmpobj.name}/anchore-grype-hdf.json`, "utf8") - ); - const sample = JSON.parse( - fs.readFileSync( - path.resolve("./test/sample_data/anchoregrype/anchore-grype-hdf.json"), - "utf8" - ) - ); - expect(omitHDFChangingFields(converted)).to.eql( - omitHDFChangingFields(sample) - ); - }); -}); + const converted = JSON.parse( + fs.readFileSync(`${tmpobj.name}/anchore-grype-hdf.json`, 'utf8'), + ) + const sample = JSON.parse( + fs.readFileSync(path.resolve('./test/sample_data/anchoregrype/anchore-grype-hdf.json'), 'utf8'), + ) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) +}) -describe("Test anchore grype withraw flag", () => { - const tmpobj = tmp.dirSync({ unsafeCleanup: true }); +describe('Test anchore grype with raw flag', () => { + const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command([ - "convert anchoregrype2hdf", - "-i", - path.resolve( - "./test/sample_data/anchoregrype/sample_input_report/anchore_grype.json" - ), - "-o", - `${tmpobj.name}/anchore-grype-withraw.json`, - "-w", + it('hdf-converter withraw output test', async () => { + await runCommand<{name: string}>(['convert anchoregrype2hdf', + '-i', path.resolve('./test/sample_data/anchoregrype/sample_input_report/anchore_grype.json'), + '-o', `${tmpobj.name}/anchore-grype-withraw.json`, '-w', ]) - .it("hdf-converter withraw output test", () => { - const converted = JSON.parse( - fs.readFileSync(`${tmpobj.name}/anchore-grype-withraw.json`, "utf8") - ); - const sample = JSON.parse( - fs.readFileSync( - path.resolve("./test/sample_data/anchoregrype/anchore-grype-withraw.json"), - "utf8" - ) - ); - expect(omitHDFChangingFields(converted)).to.eql( - omitHDFChangingFields(sample) - ); - }); -}); + const converted = JSON.parse( + fs.readFileSync(`${tmpobj.name}/anchore-grype-withraw.json`, 'utf8'), + ) + const sample = JSON.parse( + fs.readFileSync(path.resolve('./test/sample_data/anchoregrype/anchore-grype-withraw.json'), 'utf8'), + ) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) +}) -describe("Test amazon anchore grype", () => { - const tmpobj = tmp.dirSync({ unsafeCleanup: true }); - - test - .stdout() - .command([ - "convert anchoregrype2hdf", - "-i", - path.resolve( - "./test/sample_data/anchoregrype/sample_input_report/amazon.json" - ), - "-o", - `${tmpobj.name}/amazon-grype-hdf.json`, - ]) - .it("hdf-converter output test", () => { - const converted = JSON.parse( - fs.readFileSync(`${tmpobj.name}/amazon-grype-hdf.json`, "utf8") - ); - const sample = JSON.parse( - fs.readFileSync( - path.resolve("./test/sample_data/anchoregrype/amazon-grype-hdf.json"), - "utf8" - ) - ); - expect(omitHDFChangingFields(converted)).to.eql( - omitHDFChangingFields(sample) - ); - }); - }); - - describe("Test amazon anchore grype withraw flag", () => { - const tmpobj = tmp.dirSync({ unsafeCleanup: true }); - - test - .stdout() - .command([ - "convert anchoregrype2hdf", - "-i", - path.resolve( - "./test/sample_data/anchoregrype/sample_input_report/amazon.json" - ), - "-o", - `${tmpobj.name}/amazon-grype-withraw.json`, - "-w", - ]) - .it("hdf-converter withraw output test", () => { - const converted = JSON.parse( - fs.readFileSync(`${tmpobj.name}/amazon-grype-withraw.json`, "utf8") - ); - const sample = JSON.parse( - fs.readFileSync( - path.resolve("./test/sample_data/anchoregrype/amazon-grype-withraw.json"), - "utf8" - ) - ); - expect(omitHDFChangingFields(converted)).to.eql( - omitHDFChangingFields(sample) - ); - }); - }); +describe('Test amazon anchore grype', () => { + const tmpobj = tmp.dirSync({unsafeCleanup: true}) - describe("Test tensorflow anchore grype", () => { - const tmpobj = tmp.dirSync({ unsafeCleanup: true }); - - test - .stdout() - .command([ - "convert anchoregrype2hdf", - "-i", - path.resolve( - "./test/sample_data/anchoregrype/sample_input_report/tensorflow.json" - ), - "-o", - `${tmpobj.name}/tensorflow-grype-hdf.json`, - ]) - .it("hdf-converter output test", () => { - const converted = JSON.parse( - fs.readFileSync(`${tmpobj.name}/tensorflow-grype-hdf.json`, "utf8") - ); - const sample = JSON.parse( - fs.readFileSync( - path.resolve("./test/sample_data/anchoregrype/tensorflow-grype-hdf.json"), - "utf8" - ) - ); - expect(omitHDFChangingFields(converted)).to.eql( - omitHDFChangingFields(sample) - ); - }); - }); - - describe("Test tensorflow anchore grype withraw flag", () => { - const tmpobj = tmp.dirSync({ unsafeCleanup: true }); - - test - .stdout() - .command([ - "convert anchoregrype2hdf", - "-i", - path.resolve( - "./test/sample_data/anchoregrype/sample_input_report/tensorflow.json" - ), - "-o", - `${tmpobj.name}/tensorflow-grype-withraw.json`, - "-w", - ]) - .it("hdf-converter withraw output test", () => { - const converted = JSON.parse( - fs.readFileSync(`${tmpobj.name}/tensorflow-grype-withraw.json`, "utf8") - ); - const sample = JSON.parse( - fs.readFileSync( - path.resolve("./test/sample_data/anchoregrype/tensorflow-grype-withraw.json"), - "utf8" - ) - ); - expect(omitHDFChangingFields(converted)).to.eql( - omitHDFChangingFields(sample) - ); - }); - }); \ No newline at end of file + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert anchoregrype2hdf', + '-i', path.resolve('./test/sample_data/anchoregrype/sample_input_report/amazon.json'), + '-o', `${tmpobj.name}/amazon-grype-hdf.json`, + ]) + const converted = JSON.parse( + fs.readFileSync(`${tmpobj.name}/amazon-grype-hdf.json`, 'utf8'), + ) + const sample = JSON.parse( + fs.readFileSync( + path.resolve('./test/sample_data/anchoregrype/amazon-grype-hdf.json'), 'utf8'), + ) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) +}) + +describe('Test amazon anchore grype withraw flag', () => { + const tmpobj = tmp.dirSync({unsafeCleanup: true}) + + it('hdf-converter with raw output test', async () => { + await runCommand<{name: string}>(['convert anchoregrype2hdf', + '-i', path.resolve('./test/sample_data/anchoregrype/sample_input_report/amazon.json'), + '-o', `${tmpobj.name}/amazon-grype-withraw.json`, '-w', + ]) + const converted = JSON.parse( + fs.readFileSync(`${tmpobj.name}/amazon-grype-withraw.json`, 'utf8'), + ) + const sample = JSON.parse( + fs.readFileSync( + path.resolve('./test/sample_data/anchoregrype/amazon-grype-withraw.json'), 'utf8'), + ) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) +}) + +describe('Test tensorflow anchore grype', () => { + const tmpobj = tmp.dirSync({unsafeCleanup: true}) + + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert anchoregrype2hdf', + '-i', path.resolve('./test/sample_data/anchoregrype/sample_input_report/tensorflow.json'), + '-o', `${tmpobj.name}/tensorflow-grype-hdf.json`, + ]) + const converted = JSON.parse( + fs.readFileSync(`${tmpobj.name}/tensorflow-grype-hdf.json`, 'utf8'), + ) + const sample = JSON.parse( + fs.readFileSync( + path.resolve('./test/sample_data/anchoregrype/tensorflow-grype-hdf.json'), 'utf8'), + ) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) +}) + +describe('Test tensorflow anchore grype withraw flag', () => { + const tmpobj = tmp.dirSync({unsafeCleanup: true}) + + it('hdf-converter with raw output test', async () => { + await runCommand<{name: string}>(['convert anchoregrype2hdf', + '-i', path.resolve('./test/sample_data/anchoregrype/sample_input_report/tensorflow.json'), + '-o', `${tmpobj.name}/tensorflow-grype-withraw.json`, '-w', + ]) + const converted = JSON.parse( + fs.readFileSync(`${tmpobj.name}/tensorflow-grype-withraw.json`, 'utf8'), + ) + const sample = JSON.parse( + fs.readFileSync( + path.resolve('./test/sample_data/anchoregrype/tensorflow-grype-withraw.json'), 'utf8'), + ) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) +}) diff --git a/test/commands/convert/burpsuite2hdf.test.ts b/test/commands/convert/burpsuite2hdf.test.ts index 9338ca493..03f4d3b01 100644 --- a/test/commands/convert/burpsuite2hdf.test.ts +++ b/test/commands/convert/burpsuite2hdf.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,38 +10,41 @@ import {omitHDFChangingFields} from '../utils' describe('Test burpsuite', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert burpsuite2hdf', '-i', path.resolve('./test/sample_data/burpsuite/sample_input_report/zero.webappsecurity.com.min'), '-o', `${tmpobj.name}/burpsuitetest.json`]) - .it('hdf-converter output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/burpsuitetest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/burpsuite/burpsuite-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert burpsuite2hdf', + '-i', path.resolve('./test/sample_data/burpsuite/sample_input_report/zero.webappsecurity.com.min'), + '-o', `${tmpobj.name}/burpsuitetest.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/burpsuitetest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/burpsuite/burpsuite-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) describe('Test burpsuite using withraw flag', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert burpsuite2hdf', '-i', path.resolve('./test/sample_data/burpsuite/sample_input_report/zero.webappsecurity.com.min'), '-o', `${tmpobj.name}/burpsuitetest.json`, '-w']) - .it('hdf-converter withraw output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/burpsuitetest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/burpsuite/burpsuite-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter with raw output test', async () => { + await runCommand<{name: string}>(['convert burpsuite2hdf', + '-i', path.resolve('./test/sample_data/burpsuite/sample_input_report/zero.webappsecurity.com.min'), + '-o', `${tmpobj.name}/burpsuitetest.json`, '-w', + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/burpsuitetest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/burpsuite/burpsuite-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) describe('Test using space topic separator using burpsuite case', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert burpsuite2hdf', '-i', path.resolve('./test/sample_data/burpsuite/sample_input_report/zero.webappsecurity.com.min'), '-o', `${tmpobj.name}/burpsuitetest.json`]) - .it('hdf-converter output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/burpsuitetest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/burpsuite/burpsuite-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert burpsuite2hdf', + '-i', path.resolve('./test/sample_data/burpsuite/sample_input_report/zero.webappsecurity.com.min'), + '-o', `${tmpobj.name}/burpsuitetest.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/burpsuitetest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/burpsuite/burpsuite-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) diff --git a/test/commands/convert/ckl2hdf.test.ts b/test/commands/convert/ckl2hdf.test.ts index 2e5468591..7f0c4930b 100644 --- a/test/commands/convert/ckl2hdf.test.ts +++ b/test/commands/convert/ckl2hdf.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,66 +10,68 @@ import {omitHDFChangingFields} from '../utils' describe('Test ckl2hdf RHEL8 example', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert ckl2hdf', '-i', path.resolve('./test/sample_data/checklist/sample_input_report/converted-RHEL8V1R3.ckl'), '-o', `${tmpobj.name}/checklisttest.json`]) - .it('hdf-converter output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/checklisttest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/checklist/checklist-RHEL8V1R3-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert ckl2hdf', + '-i', path.resolve('./test/sample_data/checklist/sample_input_report/converted-RHEL8V1R3.ckl'), + '-o', `${tmpobj.name}/checklisttest.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/checklisttest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/checklist/checklist-RHEL8V1R3-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) describe('Test ckl2hdf RHEL8 example with raw', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert ckl2hdf', '--includeRaw', '-i', path.resolve('./test/sample_data/checklist/sample_input_report/converted-RHEL8V1R3.ckl'), '-o', `${tmpobj.name}/checklisttest.json`]) - .it('hdf-converter output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/checklisttest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/checklist/checklist-RHEL8V1R3-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert ckl2hdf', + '--includeRaw', + '-i', path.resolve('./test/sample_data/checklist/sample_input_report/converted-RHEL8V1R3.ckl'), + '-o', `${tmpobj.name}/checklisttest.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/checklisttest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/checklist/checklist-RHEL8V1R3-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) describe('Test ckl2hdf Three Stig Checklist example', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert ckl2hdf', '-i', path.resolve('./test/sample_data/checklist/sample_input_report/three_stig_checklist.ckl'), '-o', `${tmpobj.name}/threestigchecklisttest.json`]) - .it('hdf-converter output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/threestigchecklisttest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/checklist/three_stig_checklist-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert ckl2hdf', + '-i', path.resolve('./test/sample_data/checklist/sample_input_report/three_stig_checklist.ckl'), + '-o', `${tmpobj.name}/threestigchecklisttest.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/threestigchecklisttest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/checklist/three_stig_checklist-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) describe('Test ckl2hdf Small Checklist Overrides examples', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert ckl2hdf', '-i', path.resolve('./test/sample_data/checklist/sample_input_report/small_ckl_overrides.ckl'), '-o', `${tmpobj.name}/smallchecklistoverrides.json`]) - .it('hdf-converter output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/smallchecklistoverrides.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/checklist/small_overrides_hdf.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert ckl2hdf', + '-i', path.resolve('./test/sample_data/checklist/sample_input_report/small_ckl_overrides.ckl'), + '-o', `${tmpobj.name}/smallchecklistoverrides.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/smallchecklistoverrides.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/checklist/small_overrides_hdf.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) describe('Test invalid checklist metadata example', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .stderr() - .command(['convert ckl2hdf', '-i', path.resolve('./test/sample_data/checklist/sample_input_report/ckl_with_invalid_metadata.ckl'), '-o', `${tmpobj.name}/invalid_output.json`]) - .it( - 'hdf-converter output test - throws error when using invalid checklist metadata', - ctx => { - expect(ctx.stderr).to.equal('Error converting to hdf:\nError: Invalid checklist metadata fields:\n\tHost FQDN (invalid)\n\tHost IP (invalid)\n\tHost MAC (invalid)\n') - }, - ) + it('hdf-converter output test - throws error when using invalid checklist metadata', async () => { + const {stderr} = await runCommand<{name: string}>(['convert ckl2hdf', + '-i', path.resolve('./test/sample_data/checklist/sample_input_report/ckl_with_invalid_metadata.ckl'), + '-o', `${tmpobj.name}/invalid_output.json`, + ]) + expect(stderr).to.equal('Error converting to hdf:\nError: Invalid checklist metadata fields:\n\tHost FQDN (invalid)\n\tHost IP (invalid)\n\tHost MAC (invalid)\n') + }) }) diff --git a/test/commands/convert/cyclonedx_sbom2hdf.test.ts b/test/commands/convert/cyclonedx_sbom2hdf.test.ts index ca8bb1dbb..0b5637183 100644 --- a/test/commands/convert/cyclonedx_sbom2hdf.test.ts +++ b/test/commands/convert/cyclonedx_sbom2hdf.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,121 +10,135 @@ import {omitHDFChangingFields} from '../utils' describe('Test sbom', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/dropwizard-no-vulns.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`]) - .it('hdf-converter output test - dropwizard no vulns', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-dropwizard-no-vulns-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/dropwizard-vex.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`]) - .it('hdf-converter output test - dropwizard vex', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-dropwizard-vex-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/dropwizard-vulns.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`]) - .it('hdf-converter output test - dropwizard w/ vulns', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-dropwizard-vulns-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/generated-saf-sbom.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`]) - .it('hdf-converter output test - saf', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-saf-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/vex.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`]) - .it('hdf-converter output test - vex', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-vex-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/spdx-to-cyclonedx.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`]) - .it('hdf-converter output test - spdx converted cyclonedx', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-converted-spdx-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/syft-scan-alpine-container.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`]) - .it('hdf-converter output test - syft-generated alpine container', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-syft-alpine-container-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test - dropwizard no vulns', async () => { + await runCommand<{name: string}>(['convert cyclonedx_sbom2hdf', + '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/dropwizard-no-vulns.json'), + '-o', `${tmpobj.name}/cyclonedx_sbom.json`, + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-dropwizard-no-vulns-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + it('hdf-converter output test - dropwizard vex', async () => { + await runCommand<{name: string}>(['convert cyclonedx_sbom2hdf', + '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/dropwizard-vex.json'), + '-o', `${tmpobj.name}/cyclonedx_sbom.json`, + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-dropwizard-vex-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + it('hdf-converter output test - dropwizard w/ vulns', async () => { + await runCommand<{name: string}>(['convert cyclonedx_sbom2hdf', + '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/dropwizard-vulns.json'), + '-o', `${tmpobj.name}/cyclonedx_sbom.json`, + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-dropwizard-vulns-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + it('hdf-converter output test - saf', async () => { + await runCommand<{name: string}>(['convert cyclonedx_sbom2hdf', + '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/generated-saf-sbom.json'), + '-o', `${tmpobj.name}/cyclonedx_sbom.json`, + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-saf-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + it('hdf-converter output test - vex', async () => { + await runCommand<{name: string}>(['convert cyclonedx_sbom2hdf', + '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/vex.json'), + '-o', `${tmpobj.name}/cyclonedx_sbom.json`, + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-vex-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + it('hdf-converter output test - spdx converted cyclonedx', async () => { + await runCommand<{name: string}>(['convert cyclonedx_sbom2hdf', + '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/spdx-to-cyclonedx.json'), + '-o', `${tmpobj.name}/cyclonedx_sbom.json`, + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-converted-spdx-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + it('hdf-converter output test - syft-generated alpine container', async () => { + await runCommand<{name: string}>(['convert cyclonedx_sbom2hdf', + '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/syft-scan-alpine-container.json'), + '-o', `${tmpobj.name}/cyclonedx_sbom.json`, + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-syft-alpine-container-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) }) describe('Test sbom using withraw flag', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/dropwizard-no-vulns.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w']) - .it('hdf-converter withraw output test - dropwizard no vulns', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-dropwizard-no-vulns-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/dropwizard-vex.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w']) - .it('hdf-converter withraw output test - dropwizard vex', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-dropwizard-vex-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/dropwizard-vulns.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w']) - .it('hdf-converter withraw output test - dropwizard w/ vulns', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-dropwizard-vulns-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/generated-saf-sbom.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w']) - .it('hdf-converter withraw output test - saf', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-saf-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/vex.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w']) - .it('hdf-converter withraw output test - vex', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-vex-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/spdx-to-cyclonedx.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w']) - .it('hdf-converter withraw output test - spdx converted cyclonedx', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-converted-spdx-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/syft-scan-alpine-container.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w']) - .it('hdf-converter withraw output test - syft-generated alpine container', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-syft-alpine-container-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter with raw output test - dropwizard no vulns', async () => { + await runCommand<{name: string}>(['convert cyclonedx_sbom2hdf', + '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/dropwizard-no-vulns.json'), + '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w', + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-dropwizard-no-vulns-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + it('hdf-converter with raw output test - dropwizard vex', async () => { + await runCommand<{name: string}>(['convert cyclonedx_sbom2hdf', + '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/dropwizard-vex.json'), + '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w', + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-dropwizard-vex-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + it('hdf-converter with raw output test - dropwizard w/ vulns', async () => { + await runCommand<{name: string}>(['convert cyclonedx_sbom2hdf', + '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/dropwizard-vulns.json'), + '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w', + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-dropwizard-vulns-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + it('hdf-converter with raw output test - saf', async () => { + await runCommand<{name: string}>(['convert cyclonedx_sbom2hdf', + '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/generated-saf-sbom.json'), + '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w', + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-saf-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + it('hdf-converter with raw output test - vex', async () => { + await runCommand<{name: string}>(['convert cyclonedx_sbom2hdf', + '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/vex.json'), + '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w', + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-vex-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + it('hdf-converter with raw output test - spdx converted cyclonedx', async () => { + await runCommand<{name: string}>(['convert cyclonedx_sbom2hdf', + '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/spdx-to-cyclonedx.json'), + '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w', + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-converted-spdx-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + it('hdf-converter with raw output test - syft-generated alpine container', async () => { + await runCommand<{name: string}>(['convert cyclonedx_sbom2hdf', + '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/syft-scan-alpine-container.json'), + '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w', + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-syft-alpine-container-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) }) diff --git a/test/commands/convert/dbprotect2hdf.spec.ts b/test/commands/convert/dbprotect2hdf.spec.ts index 7913b6170..79cc15b3e 100644 --- a/test/commands/convert/dbprotect2hdf.spec.ts +++ b/test/commands/convert/dbprotect2hdf.spec.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,43 +10,47 @@ import {omitHDFChangingFields} from '../utils' describe('Test dbprotect', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert dbprotect2hdf', '-i', path.resolve('./test/sample_data/dbprotect/sample_input_report/DbProtect-Check-Results-Details-XML-Sample.xml'), '-o', `${tmpobj.name}/dbprotecttest.json`]) - .it('hdf-converter output test - check results', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/dbprotecttest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/dbprotect/dbprotect-check-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test - check results', async () => { + await runCommand<{name: string}>(['convert dbprotect2hdf', + '-i', path.resolve('./test/sample_data/dbprotect/sample_input_report/DbProtect-Check-Results-Details-XML-Sample.xml'), + '-o', `${tmpobj.name}/dbprotecttest.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/dbprotecttest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/dbprotect/dbprotect-check-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) - test - .stdout() - .command(['convert dbprotect2hdf', '-i', path.resolve('./test/sample_data/dbprotect/sample_input_report/DbProtect-Findings-Detail-XML-Sample.xml'), '-o', `${tmpobj.name}/dbprotecttest.json`]) - .it('hdf-converter output test - findings results', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/dbprotecttest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/dbprotect/dbprotect-findings-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test - findings results', async () => { + await runCommand<{name: string}>(['convert dbprotect2hdf', + '-i', path.resolve('./test/sample_data/dbprotect/sample_input_report/DbProtect-Findings-Detail-XML-Sample.xml'), + '-o', `${tmpobj.name}/dbprotecttest.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/dbprotecttest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/dbprotect/dbprotect-findings-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) describe('Test dbprotect using withraw flag', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert dbprotect2hdf', '-i', path.resolve('./test/sample_data/dbprotect/sample_input_report/DbProtect-Check-Results-Details-XML-Sample.xml'), '-o', `${tmpobj.name}/dbprotecttest.json`, '-w']) - .it('hdf-converter withraw output test - check results', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/dbprotecttest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/dbprotect/dbprotect-check-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter with raw output test - check results', async () => { + await runCommand<{name: string}>(['convert dbprotect2hdf', + '-i', path.resolve('./test/sample_data/dbprotect/sample_input_report/DbProtect-Check-Results-Details-XML-Sample.xml'), + '-o', `${tmpobj.name}/dbprotecttest.json`, '-w', + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/dbprotecttest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/dbprotect/dbprotect-check-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) - test - .stdout() - .command(['convert dbprotect2hdf', '-i', path.resolve('./test/sample_data/dbprotect/sample_input_report/DbProtect-Findings-Detail-XML-Sample.xml'), '-o', `${tmpobj.name}/dbprotecttest.json`, '-w']) - .it('hdf-converter withraw output test - findings results', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/dbprotecttest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/dbprotect/dbprotect-findings-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter with raw output test - findings results', async () => { + await runCommand<{name: string}>(['convert dbprotect2hdf', + '-i', path.resolve('./test/sample_data/dbprotect/sample_input_report/DbProtect-Findings-Detail-XML-Sample.xml'), + '-o', `${tmpobj.name}/dbprotecttest.json`, '-w', + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/dbprotecttest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/dbprotect/dbprotect-findings-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) diff --git a/test/commands/convert/dependency_track2hdf.test.ts b/test/commands/convert/dependency_track2hdf.test.ts index 5c24a4864..f85222811 100644 --- a/test/commands/convert/dependency_track2hdf.test.ts +++ b/test/commands/convert/dependency_track2hdf.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,49 +10,30 @@ import {omitHDFChangingFields} from '../utils' describe('Test Dependency-Track', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command([ - 'convert dependency_track2hdf', - '-i', - path.resolve( - './test/sample_data/dependency_track/sample_input_report/fpf-default.json', - ), - '-o', - `${tmpobj.name}/dependencytracktest.json`, - ]) - .it('hdf-converter output test', () => { + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert dependency_track2hdf', + '-i', path.resolve('./test/sample_data/dependency_track/sample_input_report/fpf-default.json'), + '-o', `${tmpobj.name}/dependencytracktest.json`, + ]) const converted = JSON.parse( fs.readFileSync(`${tmpobj.name}/dependencytracktest.json`, 'utf8'), ) const sample = JSON.parse( fs.readFileSync( - path.resolve('./test/sample_data/dependency_track/hdf-default.json'), - 'utf8', - ), - ) - expect(omitHDFChangingFields(converted)).to.eql( - omitHDFChangingFields(sample), + path.resolve('./test/sample_data/dependency_track/hdf-default.json'), 'utf8'), ) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) }) }) describe('Test Dependency-Track withraw flag', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command([ - 'convert dependency_track2hdf', - '-i', - path.resolve( - './test/sample_data/dependency_track/sample_input_report/fpf-default.json', - ), - '-o', - `${tmpobj.name}/dependencytracktest.json`, - '-w', - ]) - .it('hdf-converter withraw output test', () => { + it('hdf-converter with raw output test', async () => { + await runCommand<{name: string}>(['convert dependency_track2hdf', + '-i', path.resolve('./test/sample_data/dependency_track/sample_input_report/fpf-default.json'), + '-o', `${tmpobj.name}/dependencytracktest.json`, '-w', + ]) const converted = JSON.parse( fs.readFileSync(`${tmpobj.name}/dependencytracktest.json`, 'utf8'), ) @@ -68,119 +52,79 @@ describe('Test Dependency-Track withraw flag', () => { describe('Test Dependency-Track optional attributes (e.g. vulnerability.cwes, analysis.state, etc.)', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command([ - 'convert dependency_track2hdf', - '-i', - path.resolve( - './test/sample_data/dependency_track/sample_input_report/fpf-optional-attributes.json', - ), - '-o', - `${tmpobj.name}/dependencytracktest.json`, - ]) - .it('hdf-converter output test', () => { + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert dependency_track2hdf', + '-i', path.resolve('./test/sample_data/dependency_track/sample_input_report/fpf-optional-attributes.json'), + '-o', `${tmpobj.name}/dependencytracktest.json`, + ]) const converted = JSON.parse( fs.readFileSync(`${tmpobj.name}/dependencytracktest.json`, 'utf8'), ) const sample = JSON.parse( fs.readFileSync( - path.resolve('./test/sample_data/dependency_track/hdf-optional-attributes.json'), - 'utf8', + path.resolve('./test/sample_data/dependency_track/hdf-optional-attributes.json'), 'utf8', ), ) - expect(omitHDFChangingFields(converted)).to.eql( - omitHDFChangingFields(sample), - ) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) }) }) describe('Test Dependency-Track no vulnerabilities', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command([ - 'convert dependency_track2hdf', - '-i', - path.resolve( - './test/sample_data/dependency_track/sample_input_report/fpf-no-vulnerabilities.json', - ), - '-o', - `${tmpobj.name}/dependencytracktest.json`, - ]) - .it('hdf-converter output test', () => { + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert dependency_track2hdf', + '-i', path.resolve('./test/sample_data/dependency_track/sample_input_report/fpf-no-vulnerabilities.json'), + '-o', `${tmpobj.name}/dependencytracktest.json`, + ]) const converted = JSON.parse( fs.readFileSync(`${tmpobj.name}/dependencytracktest.json`, 'utf8'), ) const sample = JSON.parse( fs.readFileSync( - path.resolve('./test/sample_data/dependency_track/hdf-no-vulnerabilities.json'), - 'utf8', + path.resolve('./test/sample_data/dependency_track/hdf-no-vulnerabilities.json'), 'utf8', ), ) - expect(omitHDFChangingFields(converted)).to.eql( - omitHDFChangingFields(sample), - ) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) }) }) describe('Test Dependency-Track with attributions', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command([ - 'convert dependency_track2hdf', - '-i', - path.resolve( - './test/sample_data/dependency_track/sample_input_report/fpf-with-attributions.json', - ), - '-o', - `${tmpobj.name}/dependencytracktest.json`, - ]) - .it('hdf-converter output test', () => { + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert dependency_track2hdf', + '-i', path.resolve('./test/sample_data/dependency_track/sample_input_report/fpf-with-attributions.json'), + '-o', `${tmpobj.name}/dependencytracktest.json`, + ]) const converted = JSON.parse( fs.readFileSync(`${tmpobj.name}/dependencytracktest.json`, 'utf8'), ) const sample = JSON.parse( fs.readFileSync( - path.resolve('./test/sample_data/dependency_track/hdf-with-attributions.json'), - 'utf8', + path.resolve('./test/sample_data/dependency_track/hdf-with-attributions.json'), 'utf8', ), ) - expect(omitHDFChangingFields(converted)).to.eql( - omitHDFChangingFields(sample), - ) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) }) }) describe('Test Dependency-Track info vulnerability', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command([ - 'convert dependency_track2hdf', - '-i', - path.resolve( - './test/sample_data/dependency_track/sample_input_report/fpf-info-vulnerability.json', - ), - '-o', - `${tmpobj.name}/dependencytracktest.json`, - ]) - .it('hdf-converter output test', () => { + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert dependency_track2hdf', + '-i', path.resolve('./test/sample_data/dependency_track/sample_input_report/fpf-info-vulnerability.json'), + '-o', `${tmpobj.name}/dependencytracktest.json`, + ]) const converted = JSON.parse( fs.readFileSync(`${tmpobj.name}/dependencytracktest.json`, 'utf8'), ) const sample = JSON.parse( fs.readFileSync( - path.resolve('./test/sample_data/dependency_track/hdf-info-vulnerability.json'), - 'utf8', + path.resolve('./test/sample_data/dependency_track/hdf-info-vulnerability.json'), 'utf8', ), ) - expect(omitHDFChangingFields(converted)).to.eql( - omitHDFChangingFields(sample), - ) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) }) }) diff --git a/test/commands/convert/fortify2hdf.test.ts b/test/commands/convert/fortify2hdf.test.ts index 4aae4cfad..fdf7d8964 100644 --- a/test/commands/convert/fortify2hdf.test.ts +++ b/test/commands/convert/fortify2hdf.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,25 +10,27 @@ import {omitHDFChangingFields} from '../utils' describe('Test fortify', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert fortify2hdf', '-i', path.resolve('./test/sample_data/fortify/sample_input_report/fortify_webgoat_results.fvdl'), '-o', `${tmpobj.name}/fortify.json`]) - .it('hdf-converter output test', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/fortify.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/fortify/fortify-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert fortify2hdf', + '-i', path.resolve('./test/sample_data/fortify/sample_input_report/fortify_webgoat_results.fvdl'), + '-o', `${tmpobj.name}/fortify.json`, + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/fortify.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/fortify/fortify-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) }) describe('Test fortify using withraw flag', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert fortify2hdf', '-i', path.resolve('./test/sample_data/fortify/sample_input_report/fortify_webgoat_results.fvdl'), '-o', `${tmpobj.name}/fortify.json`, '-w']) - .it('hdf-converter withraw output test', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/fortify.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/fortify/fortify-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter with raw output test', async () => { + await runCommand<{name: string}>(['convert fortify2hdf', + '-i', path.resolve('./test/sample_data/fortify/sample_input_report/fortify_webgoat_results.fvdl'), + '-o', `${tmpobj.name}/fortify.json`, '-w', + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/fortify.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/fortify/fortify-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) }) diff --git a/test/commands/convert/gosec2hdf.test.ts b/test/commands/convert/gosec2hdf.test.ts index df4e4cd13..f436e33a3 100644 --- a/test/commands/convert/gosec2hdf.test.ts +++ b/test/commands/convert/gosec2hdf.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,57 +10,63 @@ import {omitHDFChangingFields} from '../utils' describe('Test gosec', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert gosec2hdf', '-i', path.resolve('./test/sample_data/gosec/sample_input_report/Grype_gosec_results.json'), '-o', `${tmpobj.name}/gosectest.json`]) - .it('hdf-converter output test - grype', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/gosectest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/gosec/grype-gosec-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert gosec2hdf', '-i', path.resolve('./test/sample_data/gosec/sample_input_report/Go_Ethereum_gosec_results_external_suppressed.json'), '-o', `${tmpobj.name}/gosectest.json`]) - .it('hdf-converter output test - unsuppressed go ethereum', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/gosectest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/gosec/go-ethereum-external-unsuppressed-gosec-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert gosec2hdf', '-i', path.resolve('./test/sample_data/gosec/sample_input_report/Go_Ethereum_gosec_results_all_suppressed.json'), '-o', `${tmpobj.name}/gosectest.json`]) - .it('hdf-converter output test - suppressed go ethereum', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/gosectest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/gosec/go-ethereum-all-unsuppressed-gosec-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test - grype', async () => { + await runCommand<{name: string}>(['convert gosec2hdf', + '-i', path.resolve('./test/sample_data/gosec/sample_input_report/Grype_gosec_results.json'), + '-o', `${tmpobj.name}/gosectest.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/gosectest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/gosec/grype-gosec-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) + it('hdf-converter output test - unsuppressed go ethereum', async () => { + await runCommand<{name: string}>(['convert gosec2hdf', + '-i', path.resolve('./test/sample_data/gosec/sample_input_report/Go_Ethereum_gosec_results_external_suppressed.json'), + '-o', `${tmpobj.name}/gosectest.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/gosectest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/gosec/go-ethereum-external-unsuppressed-gosec-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) + it('hdf-converter output test - suppressed go ethereum', async () => { + await runCommand<{name: string}>(['convert gosec2hdf', + '-i', path.resolve('./test/sample_data/gosec/sample_input_report/Go_Ethereum_gosec_results_all_suppressed.json'), + '-o', `${tmpobj.name}/gosectest.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/gosectest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/gosec/go-ethereum-all-unsuppressed-gosec-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) describe('Test gosec using withraw flag', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert gosec2hdf', '-i', path.resolve('./test/sample_data/gosec/sample_input_report/Grype_gosec_results.json'), '-o', `${tmpobj.name}/gosectest.json`, '-w']) - .it('hdf-converter output test - grype', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/gosectest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/gosec/grype-gosec-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert gosec2hdf', '-i', path.resolve('./test/sample_data/gosec/sample_input_report/Go_Ethereum_gosec_results_external_suppressed.json'), '-o', `${tmpobj.name}/gosectest.json`, '-w']) - .it('hdf-converter output test - unsuppressed go ethereum', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/gosectest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/gosec/go-ethereum-external-unsuppressed-gosec-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert gosec2hdf', '-i', path.resolve('./test/sample_data/gosec/sample_input_report/Go_Ethereum_gosec_results_all_suppressed.json'), '-o', `${tmpobj.name}/gosectest.json`, '-w']) - .it('hdf-converter output test - suppressed go ethereum', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/gosectest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/gosec/go-ethereum-all-unsuppressed-gosec-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter with raw output test - grype', async () => { + await runCommand<{name: string}>(['convert gosec2hdf', + '-i', path.resolve('./test/sample_data/gosec/sample_input_report/Grype_gosec_results.json'), + '-o', `${tmpobj.name}/gosectest.json`, '-w', + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/gosectest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/gosec/grype-gosec-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) + it('hdf-converter with raw output test - unsuppressed go ethereum', async () => { + await runCommand<{name: string}>(['convert gosec2hdf', + '-i', path.resolve('./test/sample_data/gosec/sample_input_report/Go_Ethereum_gosec_results_external_suppressed.json'), + '-o', `${tmpobj.name}/gosectest.json`, '-w', + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/gosectest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/gosec/go-ethereum-external-unsuppressed-gosec-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) + it('hdf-converter with raw output test - suppressed go ethereum', async () => { + await runCommand<{name: string}>(['convert gosec2hdf', + '-i', path.resolve('./test/sample_data/gosec/sample_input_report/Go_Ethereum_gosec_results_all_suppressed.json'), + '-o', `${tmpobj.name}/gosectest.json`, '-w', + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/gosectest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/gosec/go-ethereum-all-unsuppressed-gosec-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) diff --git a/test/commands/convert/hdf2caat.test.ts b/test/commands/convert/hdf2caat.test.ts index c53981d7c..65fc16ead 100644 --- a/test/commands/convert/hdf2caat.test.ts +++ b/test/commands/convert/hdf2caat.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import * as XLSX from '@e965/xlsx' @@ -6,15 +9,18 @@ import * as XLSX from '@e965/xlsx' describe('Test hdf2caat two RHEL HDF and a RHEL triple overlay HDF', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert hdf2caat', '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), path.resolve('./test/sample_data/HDF/input/triple_overlay_profile_example.json'), '-o', `${tmpobj.name}/caat.xlsx`]) - .it('hdf-converter output test', () => { - const converted = XLSX.readFile(`${tmpobj.name}/caat.xlsx`, {type: 'file'}) - const sample = XLSX.readFile(path.resolve('./test/sample_data/HDF/output/caat/caat.xlsx'), {type: 'file'}) - // convert workbooks to json to compare just the content instead of random bits of xlsx structure - expect(converted.SheetNames.map(name => XLSX.utils.sheet_to_json(converted.Sheets[name]))).to.eql(sample.SheetNames.map(name => XLSX.utils.sheet_to_json(sample.Sheets[name]))) - // however, we do care about one bit of xlsx structure: the sheet names - expect(converted.SheetNames).to.eql(sample.SheetNames) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert hdf2caat', + '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), + path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), + path.resolve('./test/sample_data/HDF/input/triple_overlay_profile_example.json'), + '-o', `${tmpobj.name}/caat.xlsx`, + ]) + const converted = XLSX.readFile(`${tmpobj.name}/caat.xlsx`, {type: 'file'}) + const sample = XLSX.readFile(path.resolve('./test/sample_data/HDF/output/caat/caat.xlsx'), {type: 'file'}) + // convert workbooks to json to compare just the content instead of random bits of xlsx structure + expect(converted.SheetNames.map(name => XLSX.utils.sheet_to_json(converted.Sheets[name]))).to.eql(sample.SheetNames.map(name => XLSX.utils.sheet_to_json(sample.Sheets[name]))) + // however, we do care about one bit of xlsx structure: the sheet names + expect(converted.SheetNames).to.eql(sample.SheetNames) + }) }) diff --git a/test/commands/convert/hdf2ckl.test.ts b/test/commands/convert/hdf2ckl.test.ts index fb891b342..97ebdbe21 100644 --- a/test/commands/convert/hdf2ckl.test.ts +++ b/test/commands/convert/hdf2ckl.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,76 +10,78 @@ import {omitChecklistChangingFields} from '../utils' describe('Test hdf2checklist', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert hdf2ckl', '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), '-o', `${tmpobj.name}/hdf2ckl_test.ckl`]) - .it('hdf-converter output test - defaults', () => { - const test = fs.readFileSync(`${tmpobj.name}/hdf2ckl_test.ckl`, 'utf8').replace(/\r/gi, '') - const sample = fs.readFileSync(path.resolve('./test/sample_data/checklist/red_hat_good.ckl'), 'utf8').replace(/\r/gi, '') - expect(omitChecklistChangingFields(test)).to.eql(omitChecklistChangingFields(sample)) - }) + it('hdf-converter output test - defaults', async () => { + await runCommand<{name: string}>(['convert hdf2ckl', + '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), + '-o', `${tmpobj.name}/hdf2ckl_test.ckl`, + ]) + const test = fs.readFileSync(`${tmpobj.name}/hdf2ckl_test.ckl`, 'utf8').replaceAll(/\r/gi, '') + const sample = fs.readFileSync(path.resolve('./test/sample_data/checklist/red_hat_good.ckl'), 'utf8').replaceAll(/\r/gi, '') + expect(omitChecklistChangingFields(test)).to.eql(omitChecklistChangingFields(sample)) + }) - test - .stdout() - .command(['convert hdf2ckl', '-i', path.resolve('./test/sample_data/HDF/input/vSphere8_report.json'), '-o', `${tmpobj.name}/hdf2ckl_test.ckl`]) - .it('hdf-converter output test - inspec results from profile with dependent profiles', () => { - const test = fs.readFileSync(`${tmpobj.name}/hdf2ckl_test.ckl`, 'utf8').replace(/\r/gi, '') - const sample = fs.readFileSync(path.resolve('./test/sample_data/checklist/vSphere8_report.ckl'), 'utf8').replace(/\r/gi, '') - expect(omitChecklistChangingFields(test)).to.eql(omitChecklistChangingFields(sample)) - }) + it('hdf-converter output test - inspec results from profile with dependent profiles', async () => { + await runCommand<{name: string}>(['convert hdf2ckl', + '-i', path.resolve('./test/sample_data/HDF/input/vSphere8_report.json'), + '-o', `${tmpobj.name}/hdf2ckl_test.ckl`, + ]) + const test = fs.readFileSync(`${tmpobj.name}/hdf2ckl_test.ckl`, 'utf8').replaceAll(/\r/gi, '') + const sample = fs.readFileSync(path.resolve('./test/sample_data/checklist/vSphere8_report.ckl'), 'utf8').replaceAll(/\r/gi, '') + expect(omitChecklistChangingFields(test)).to.eql(omitChecklistChangingFields(sample)) + }) - test - .stdout() - .command(['convert hdf2ckl', '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), '-o', `${tmpobj.name}/hdf2ckl_metadata_test.ckl`, '-m', path.resolve('./test/sample_data/checklist/metadata.json')]) - .it('hdf-converter output test - with metadata file', () => { - const test = fs.readFileSync(`${tmpobj.name}/hdf2ckl_metadata_test.ckl`, 'utf8').replace(/\r/gi, '') - const sample = fs.readFileSync(path.resolve('./test/sample_data/checklist/red_hat_good_metadata.ckl'), 'utf8').replace(/\r/gi, '') - expect(omitChecklistChangingFields(test)).to.eql(omitChecklistChangingFields(sample)) - }) + it('hdf-converter output test - with metadata file', async () => { + await runCommand<{name: string}>(['convert hdf2ckl', + '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), + '-o', `${tmpobj.name}/hdf2ckl_metadata_test.ckl`, + '-m', path.resolve('./test/sample_data/checklist/metadata.json'), + ]) + const test = fs.readFileSync(`${tmpobj.name}/hdf2ckl_metadata_test.ckl`, 'utf8').replaceAll(/\r/gi, '') + const sample = fs.readFileSync(path.resolve('./test/sample_data/checklist/red_hat_good_metadata.ckl'), 'utf8').replaceAll(/\r/gi, '') + expect(omitChecklistChangingFields(test)).to.eql(omitChecklistChangingFields(sample)) + }) - test - .stdout() - .command(['convert hdf2ckl', '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), - '-o', `${tmpobj.name}/hdf2ckl_metadata_test.ckl`, - '--profilename', 'Red Hat Enterprise Linux 7 STIG', '--version', '2', - '--releasenumber', '6', '--releasedate', '2024/06/08', - '--marking', 'CUI', '--hostname', 'localhost', - '--ip', '127.0.0.1', '--role', 'Domain Controller', - '--assettype', 'Computing', '--techarea', 'Other Review']) - .it('hdf-converter output test - with metadata flags', () => { - const test = fs.readFileSync(`${tmpobj.name}/hdf2ckl_metadata_test.ckl`, 'utf8').replace(/\r/gi, '') - const sample = fs.readFileSync(path.resolve('./test/sample_data/checklist/red_hat_good_metadata.ckl'), 'utf8').replace(/\r/gi, '') - expect(omitChecklistChangingFields(test)).to.eql(omitChecklistChangingFields(sample)) - }) + // NOTE: May have to wrap the string parameter in double quotes + it('hdf-converter output test - with metadata flags', async () => { + await runCommand<{name: string}>(['convert hdf2ckl', + '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), + '-o', `${tmpobj.name}/hdf2ckl_metadata_test.ckl`, + '--profilename', 'Red Hat Enterprise Linux 7 STIG', '--version', '2', + '--releasenumber', '6', '--releasedate', '2024/06/08', + '--marking', 'CUI', '--hostname', 'localhost', + '--ip', '127.0.0.1', '--role', 'Domain Controller', + '--assettype', 'Computing', '--techarea', 'Other Review', + ]) + const test = fs.readFileSync(`${tmpobj.name}/hdf2ckl_metadata_test.ckl`, 'utf8').replaceAll(/\r/gi, '') + const sample = fs.readFileSync(path.resolve('./test/sample_data/checklist/red_hat_good_metadata.ckl'), 'utf8').replaceAll(/\r/gi, '') + expect(omitChecklistChangingFields(test)).to.eql(omitChecklistChangingFields(sample)) + }) - test - .stdout() - .command(['convert hdf2ckl', '-i', path.resolve('./test/sample_data/HDF/input/RHEL7_overrides_hdf.json'), '-o', `${tmpobj.name}/hdf2ckl_overrides_test.ckl`]) - .it('hdf-converter output test - with severity overrides', () => { - const test = fs.readFileSync(`${tmpobj.name}/hdf2ckl_overrides_test.ckl`, 'utf8').replace(/\r/gi, '') - const sample = fs.readFileSync(path.resolve('./test/sample_data/checklist/converted-rhel7_overrides.ckl'), 'utf8').replace(/\r/gi, '') - expect(omitChecklistChangingFields(test)).to.eql(omitChecklistChangingFields(sample)) - }) + it('hdf-converter output test - with severity overrides', async () => { + await runCommand<{name: string}>(['convert hdf2ckl', + '-i', path.resolve('./test/sample_data/HDF/input/RHEL7_overrides_hdf.json'), + '-o', `${tmpobj.name}/hdf2ckl_overrides_test.ckl`, + ]) + const test = fs.readFileSync(`${tmpobj.name}/hdf2ckl_overrides_test.ckl`, 'utf8').replaceAll(/\r/gi, '') + const sample = fs.readFileSync(path.resolve('./test/sample_data/checklist/converted-rhel7_overrides.ckl'), 'utf8').replaceAll(/\r/gi, '') + expect(omitChecklistChangingFields(test)).to.eql(omitChecklistChangingFields(sample)) + }) - test - .stdout() - .stderr() - .command(['convert hdf2ckl', '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), '-o', `${tmpobj.name}/hdf2ckl_metadata_error_test.json`, '-m', path.resolve('test/sample_data/checklist/sample_input_report/invalid_metadata.json')]) - .it( - 'hdf-converter output test - throws error when using invalid checklist metadata (Asset Type)', - ctx => { - expect(ctx.stderr).to.equal('Error creating checklist:\nInvalid checklist metadata fields:\n\tHost IP (invalid)\n\tAsset Type (Not a real assettype)\n') - }, - ) + it('hdf-converter output test - throws error when using invalid checklist metadata (Asset Type)', async () => { + const {stderr} = await runCommand<{name: string}>(['convert hdf2ckl', + '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), + '-o', `${tmpobj.name}/hdf2ckl_metadata_error_test.json`, + '-m', path.resolve('test/sample_data/checklist/sample_input_report/invalid_metadata.json'), + ]) + expect(stderr).to.equal('Error creating checklist:\nInvalid checklist metadata fields:\n\tHost IP (invalid)\n\tAsset Type (Not a real assettype)\n') + }) - test - .stdout() - .stderr() - .command(['convert hdf2ckl', '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), '-o', `${tmpobj.name}/hdf2ckl_metadata_error_test.json`, '--ip', 'bad ip address']) - .it( - 'hdf-converter output test - throws error when using invalid checklist metadata (Host IP)', - ctx => { - expect(ctx.stderr).to.equal('Error creating checklist:\nInvalid checklist metadata fields:\n\tHost IP (bad ip address)\n') - }, - ) + it('hdf-converter output test - throws error when using invalid checklist metadata (Host IP)', async () => { + const {stderr} = await runCommand<{name: string}>(['convert hdf2ckl', + '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), + '-o', `${tmpobj.name}/hdf2ckl_metadata_error_test.json`, + '--ip', '"bad ip address"', + ]) + expect(stderr).to.equal('Error creating checklist:\nInvalid checklist metadata fields:\n\tHost IP (bad ip address)\n') + }) }) diff --git a/test/commands/convert/hdf2ckl_deepCompare.test.ts b/test/commands/convert/hdf2ckl_deepCompare.test.ts new file mode 100644 index 000000000..a5fe1f9db --- /dev/null +++ b/test/commands/convert/hdf2ckl_deepCompare.test.ts @@ -0,0 +1,90 @@ +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {runCommand} from '@oclif/test' +import assert from 'assert' +import {diff} from 'deep-diff' +import fs from 'fs' +import path from 'path' +import tmp from 'tmp' +import {parseStringPromise} from 'xml2js' +import {removeUUIDs} from '../utils' + +describe('Test hdf2checklist - deep compare', () => { + const tmpobj = tmp.dirSync({unsafeCleanup: true}) + const logDir = './test/logs' + + beforeEach(() => { + // Check if the directory exists + if (!fs.existsSync(logDir)) { + // If it doesn't exist, create the directory + fs.mkdirSync(logDir) + } + }) + + it('hdf-converter output test - defaults', async () => { + await runCommand<{name: string}>(['convert hdf2ckl', + '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), + '-o', `${tmpobj.name}/hdf2ckl_test.ckl`, + ]) + const test = fs.readFileSync(`${tmpobj.name}/hdf2ckl_test.ckl`, 'utf8').replaceAll(/\r/gi, '') + const sample = fs.readFileSync(path.resolve('./test/sample_data/checklist/red_hat_good.ckl'), 'utf8').replaceAll(/\r/gi, '') + + const testObj = await parseStringPromise(test) + const sampleObj = await parseStringPromise(sample) + + removeUUIDs(testObj) + removeUUIDs(sampleObj) + + const differences = diff(testObj, sampleObj) + + if (differences) { + fs.writeFileSync(`${logDir}/differences_hdf2ckl_defaults.json`, JSON.stringify(differences, null, 2)) + assert.fail(`Objects are not deeply equal - see ${logDir}/differences_hdf2ckl_defaults.json`) + } + }) + + it('hdf-converter output test - inspec results from profile with dependent profiles', async () => { + await runCommand<{name: string}>(['convert hdf2ckl', + '-i', path.resolve('./test/sample_data/HDF/input/vSphere8_report.json'), + '-o', `${tmpobj.name}/hdf2ckl_test.json`, + ]) + const test = fs.readFileSync(`${tmpobj.name}/hdf2ckl_test.json`, 'utf8').replaceAll(/\r/gi, '') + const sample = fs.readFileSync(path.resolve('./test/sample_data/checklist/vSphere8_report.ckl'), 'utf8').replaceAll(/\r/gi, '') + + const testObj = await parseStringPromise(test) + const sampleObj = await parseStringPromise(sample) + + removeUUIDs(testObj) + removeUUIDs(sampleObj) + + const differences = diff(testObj, sampleObj) + + if (differences) { + fs.writeFileSync(`${logDir}/differences_hdf2ckl_test.json`, JSON.stringify(differences, null, 2)) + assert.fail(`Objects are not deeply equal - see ${logDir}/differences_hdf2ckl_test.json`) + } + }) + + it('hdf-converter output test - with metadata', async () => { + await runCommand<{name: string}>(['convert hdf2ckl', + '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), + '-o', `${tmpobj.name}/hdf2ckl_metadata_test.json`, + '-m', path.resolve('./test/sample_data/checklist/metadata.json'), + ]) + const test = fs.readFileSync(`${tmpobj.name}/hdf2ckl_metadata_test.json`, 'utf8').replaceAll(/\r/gi, '') + const sample = fs.readFileSync(path.resolve('./test/sample_data/checklist/red_hat_good_metadata.ckl'), 'utf8').replaceAll(/\r/gi, '') + + const testObj = await parseStringPromise(test) + const sampleObj = await parseStringPromise(sample) + + removeUUIDs(testObj) + removeUUIDs(sampleObj) + + const differences = diff(testObj, sampleObj) + + if (differences) { + fs.writeFileSync(`${logDir}/differences_hdf2ckl_metadata_test.json`, JSON.stringify(differences, null, 2)) + assert.fail(`Objects are not deeply equal - see ${logDir}/differences_hdf2ckl_metadata_test.json`) + } + }) +}) diff --git a/test/commands/convert/hdf2csv.test.ts b/test/commands/convert/hdf2csv.test.ts index 2501a4eda..29c39ded7 100644 --- a/test/commands/convert/hdf2csv.test.ts +++ b/test/commands/convert/hdf2csv.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,26 +10,28 @@ import parse from 'csv-parse/lib/sync' describe('Test hdf2csv triple_overlay_profile_example', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert hdf2csv', '-i', path.resolve('./test/sample_data/HDF/input/triple_overlay_profile_example.json'), '-o', `${tmpobj.name}/triple_overlay_profile_example.csv`]) - .it('hdf-converter output test', () => { - const converted = parse(fs.readFileSync(`${tmpobj.name}/triple_overlay_profile_example.csv`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/HDF/output/csv/triple_overlay_parsed_CSV.json'), 'utf8')) - expect(converted).to.eql(sample) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert hdf2csv', + '-i', path.resolve('./test/sample_data/HDF/input/triple_overlay_profile_example.json'), + '-o', `${tmpobj.name}/triple_overlay_profile_example.csv`, + ]) + const converted = parse(fs.readFileSync(`${tmpobj.name}/triple_overlay_profile_example.csv`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/HDF/output/csv/triple_overlay_parsed_CSV.json'), 'utf8')) + expect(converted).to.eql(sample) + }) }) describe('Test hdf2csv red_hat_good', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert hdf2csv', '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), '-o', `${tmpobj.name}/red_hat_good.csv`]) - .it('hdf-converter output test', () => { - const converted = parse(fs.readFileSync(`${tmpobj.name}/red_hat_good.csv`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/HDF/output/csv/red_hat_good_parsed_CSV.json'), 'utf8')) - expect(converted).to.eql(sample) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert hdf2csv', + '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), + '-o', `${tmpobj.name}/red_hat_good.csv`, + ]) + const converted = parse(fs.readFileSync(`${tmpobj.name}/red_hat_good.csv`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/HDF/output/csv/red_hat_good_parsed_CSV.json'), 'utf8')) + expect(converted).to.eql(sample) + }) }) diff --git a/test/commands/convert/jfrog_xray2hdf.test.ts b/test/commands/convert/jfrog_xray2hdf.test.ts index 0cdfbc855..766a902e9 100644 --- a/test/commands/convert/jfrog_xray2hdf.test.ts +++ b/test/commands/convert/jfrog_xray2hdf.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,25 +10,27 @@ import {omitHDFChangingFields} from '../utils' describe('Test jfrog_xray', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert jfrog_xray2hdf', '-i', path.resolve('./test/sample_data/jfrog_xray/sample_input_report/jfrog_xray_sample.json'), '-o', `${tmpobj.name}/jfrogtest.json`]) - .it('hdf-converter output test', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/jfrogtest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/jfrog_xray/jfrog-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert jfrog_xray2hdf', + '-i', path.resolve('./test/sample_data/jfrog_xray/sample_input_report/jfrog_xray_sample.json'), + '-o', `${tmpobj.name}/jfrogtest.json`, + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/jfrogtest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/jfrog_xray/jfrog-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) }) describe('Test jfrog_xray using withraw flag', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert jfrog_xray2hdf', '-i', path.resolve('./test/sample_data/jfrog_xray/sample_input_report/jfrog_xray_sample.json'), '-o', `${tmpobj.name}/jfrogtest.json`, '-w']) - .it('hdf-converter withraw output test', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/jfrogtest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/jfrog_xray/jfrog-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter with raw output test', async () => { + await runCommand<{name: string}>(['convert jfrog_xray2hdf', + '-i', path.resolve('./test/sample_data/jfrog_xray/sample_input_report/jfrog_xray_sample.json'), + '-o', `${tmpobj.name}/jfrogtest.json`, '-w', + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/jfrogtest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/jfrog_xray/jfrog-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) }) diff --git a/test/commands/convert/msft_secure2hdf.test.ts b/test/commands/convert/msft_secure2hdf.test.ts index ba0910fe1..3729fc1cf 100644 --- a/test/commands/convert/msft_secure2hdf.test.ts +++ b/test/commands/convert/msft_secure2hdf.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,38 +10,43 @@ import {omitHDFChangingFields} from '../utils' describe('Test msft_secure from pre-downloaded inputs', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert msft_secure2hdf', '-r', path.resolve('./test/sample_data/msft_secure/sample_input_report/secureScore.json'), '-p', path.resolve('./test/sample_data/msft_secure/sample_input_report/profiles.json'), '-o', `${tmpobj.name}/msft-secure.json`]) - .it('hdf-converter output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/msft-secure-12345678-1234-1234-1234-1234567890abcd_2024-01-01.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/msft_secure/secure_score-hdfs.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample[0])) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert msft_secure2hdf', + '-r', path.resolve('./test/sample_data/msft_secure/sample_input_report/secureScore.json'), + '-p', path.resolve('./test/sample_data/msft_secure/sample_input_report/profiles.json'), + '-o', `${tmpobj.name}/msft-secure.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/msft-secure-12345678-1234-1234-1234-1234567890abcd_2024-01-01.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/msft_secure/secure_score-hdfs.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample[0])) + }) }) describe('Test msft_secure using withraw flag', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert msft_secure2hdf', '-r', path.resolve('./test/sample_data/msft_secure/sample_input_report/secureScore.json'), '-p', path.resolve('./test/sample_data/msft_secure/sample_input_report/profiles.json'), '-o', `${tmpobj.name}/msft-secure.json`, '-w']) - .it('hdf-converter withraw output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/msft-secure-12345678-1234-1234-1234-1234567890abcd_2024-01-01.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/msft_secure/secure_score-hdf-withraws.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample[0])) - }) + it('hdf-converter withraw output test', async () => { + await runCommand<{name: string}>(['convert msft_secure2hdf', + '-r', path.resolve('./test/sample_data/msft_secure/sample_input_report/secureScore.json'), + '-p', path.resolve('./test/sample_data/msft_secure/sample_input_report/profiles.json'), + '-o', `${tmpobj.name}/msft-secure.json`, '-w', + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/msft-secure-12345678-1234-1234-1234-1234567890abcd_2024-01-01.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/msft_secure/secure_score-hdf-withraws.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample[0])) + }) }) describe('Test msft_secure from combined input', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert msft_secure2hdf', '-i', path.resolve('./test/sample_data/msft_secure/sample_input_report/combined.json'), '-o', `${tmpobj.name}/msft-secure.json`]) - .it('hdf-converter output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/msft-secure-12345678-1234-1234-1234-1234567890abcd_2024-01-01.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/msft_secure/secure_score-hdfs.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample[0])) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert msft_secure2hdf', + '-i', path.resolve('./test/sample_data/msft_secure/sample_input_report/combined.json'), + '-o', `${tmpobj.name}/msft-secure.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/msft-secure-12345678-1234-1234-1234-1234567890abcd_2024-01-01.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/msft_secure/secure_score-hdfs.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample[0])) + }) }) diff --git a/test/commands/convert/netsparker2hdf.test.ts b/test/commands/convert/netsparker2hdf.test.ts index 202b3fd7b..d746b5372 100644 --- a/test/commands/convert/netsparker2hdf.test.ts +++ b/test/commands/convert/netsparker2hdf.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,25 +10,27 @@ import {omitHDFChangingFields} from '../utils' describe('Test Netsparker', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert netsparker2hdf', '-i', path.resolve('./test/sample_data/netsparker/sample_input_report/sample-netsparker-invicti.xml'), '-o', `${tmpobj.name}/netsparkertest.json`]) - .it('hdf-converter output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/netsparkertest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/netsparker/netsparker-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert netsparker2hdf', + '-i', path.resolve('./test/sample_data/netsparker/sample_input_report/sample-netsparker-invicti.xml'), + '-o', `${tmpobj.name}/netsparkertest.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/netsparkertest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/netsparker/netsparker-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) describe('Test Netsparker using withraw flag', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert netsparker2hdf', '-i', path.resolve('./test/sample_data/netsparker/sample_input_report/sample-netsparker-invicti.xml'), '-o', `${tmpobj.name}/netsparkertest.json`, '-w']) - .it('hdf-converter withraw output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/netsparkertest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/netsparker/netsparker-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter with raw output test', async () => { + await runCommand<{name: string}>(['convert netsparker2hdf', + '-i', path.resolve('./test/sample_data/netsparker/sample_input_report/sample-netsparker-invicti.xml'), + '-o', `${tmpobj.name}/netsparkertest.json`, '-w', + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/netsparkertest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/netsparker/netsparker-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) diff --git a/test/commands/convert/neuvector2hdf.test.ts b/test/commands/convert/neuvector2hdf.test.ts index 661a81e3c..1dfb1586a 100644 --- a/test/commands/convert/neuvector2hdf.test.ts +++ b/test/commands/convert/neuvector2hdf.test.ts @@ -1,241 +1,136 @@ -import {expect, test} from '@oclif/test'; -import tmp from 'tmp'; -import path from 'path'; -import fs from 'fs'; -import {omitHDFChangingFields} from '../utils'; +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' +import tmp from 'tmp' +import path from 'path' +import fs from 'fs' +import {omitHDFChangingFields} from '../utils' describe('Test NeuVector', () => { - const tmpobj = tmp.dirSync({unsafeCleanup: true}); + const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command([ - 'convert neuvector2hdf', - '-i', - path.resolve( - './test/sample_data/neuvector/sample_input_report/neuvector-mitre-caldera.json' - ), - '-o', - `${tmpobj.name}/neuvectortest.json` + it('hdf-converter output test on mitre/caldera', async () => { + await runCommand<{name: string}>(['convert neuvector2hdf', + '-i', path.resolve('./test/sample_data/neuvector/sample_input_report/neuvector-mitre-caldera.json'), + '-o', `${tmpobj.name}/neuvectortest.json`, ]) - .it('hdf-converter output test on mitre/caldera', () => { - const converted = JSON.parse( - fs.readFileSync(`${tmpobj.name}/neuvectortest.json`, 'utf8') - ); - const sample = JSON.parse( - fs.readFileSync( - path.resolve( - './test/sample_data/neuvector/neuvector-hdf-mitre-caldera.json' - ), - 'utf8' - ) - ); - expect(omitHDFChangingFields(converted)).to.eql( - omitHDFChangingFields(sample) - ); - }); + const converted = JSON.parse( + fs.readFileSync(`${tmpobj.name}/neuvectortest.json`, 'utf8'), + ) + const sample = JSON.parse( + fs.readFileSync( + path.resolve('./test/sample_data/neuvector/neuvector-hdf-mitre-caldera.json'), 'utf8'), + ) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) - test - .stdout() - .command([ - 'convert neuvector2hdf', - '-i', - path.resolve( - './test/sample_data/neuvector/sample_input_report/neuvector-mitre-heimdall.json' - ), - '-o', - `${tmpobj.name}/neuvectortest.json` + it('hdf-converter output test on mitre/heimdall', async () => { + await runCommand<{name: string}>(['convert neuvector2hdf', + '-i', path.resolve('./test/sample_data/neuvector/sample_input_report/neuvector-mitre-heimdall.json'), + '-o', `${tmpobj.name}/neuvectortest.json`, ]) - .it('hdf-converter output test on mitre/heimdall', () => { - const converted = JSON.parse( - fs.readFileSync(`${tmpobj.name}/neuvectortest.json`, 'utf8') - ); - const sample = JSON.parse( - fs.readFileSync( - path.resolve( - './test/sample_data/neuvector/neuvector-hdf-mitre-heimdall.json' - ), - 'utf8' - ) - ); - expect(omitHDFChangingFields(converted)).to.eql( - omitHDFChangingFields(sample) - ); - }); + const converted = JSON.parse( + fs.readFileSync(`${tmpobj.name}/neuvectortest.json`, 'utf8'), + ) + const sample = JSON.parse( + fs.readFileSync( + path.resolve('./test/sample_data/neuvector/neuvector-hdf-mitre-heimdall.json'), 'utf8'), + ) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) - test - .stdout() - .command([ - 'convert neuvector2hdf', - '-i', - path.resolve( - './test/sample_data/neuvector/sample_input_report/neuvector-mitre-heimdall2.json' - ), - '-o', - `${tmpobj.name}/neuvectortest.json` + it('hdf-converter output test on mitre/heimdall2', async () => { + await runCommand<{name: string}>(['convert neuvector2hdf', + '-i', path.resolve('./test/sample_data/neuvector/sample_input_report/neuvector-mitre-heimdall2.json'), + '-o', `${tmpobj.name}/neuvectortest.json`, ]) - .it('hdf-converter output test on mitre/heimdall2', () => { - const converted = JSON.parse( - fs.readFileSync(`${tmpobj.name}/neuvectortest.json`, 'utf8') - ); - const sample = JSON.parse( - fs.readFileSync( - path.resolve( - './test/sample_data/neuvector/neuvector-hdf-mitre-heimdall2.json' - ), - 'utf8' - ) - ); - expect(omitHDFChangingFields(converted)).to.eql( - omitHDFChangingFields(sample) - ); - }); + const converted = JSON.parse( + fs.readFileSync(`${tmpobj.name}/neuvectortest.json`, 'utf8'), + ) + const sample = JSON.parse( + fs.readFileSync( + path.resolve('./test/sample_data/neuvector/neuvector-hdf-mitre-heimdall2.json'), 'utf8'), + ) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) - test - .stdout() - .command([ - 'convert neuvector2hdf', - '-i', - path.resolve( - './test/sample_data/neuvector/sample_input_report/neuvector-mitre-vulcan.json' - ), - '-o', - `${tmpobj.name}/neuvectortest.json` + it('hdf-converter output test on mitre/vulcan', async () => { + await runCommand<{name: string}>(['convert neuvector2hdf', + '-i', path.resolve('./test/sample_data/neuvector/sample_input_report/neuvector-mitre-vulcan.json'), + '-o', `${tmpobj.name}/neuvectortest.json`, ]) - .it('hdf-converter output test on mitre/vulcan', () => { - const converted = JSON.parse( - fs.readFileSync(`${tmpobj.name}/neuvectortest.json`, 'utf8') - ); - const sample = JSON.parse( - fs.readFileSync( - path.resolve( - './test/sample_data/neuvector/neuvector-hdf-mitre-vulcan.json' - ), - 'utf8' - ) - ); - expect(omitHDFChangingFields(converted)).to.eql( - omitHDFChangingFields(sample) - ); - }); -}); + const converted = JSON.parse( + fs.readFileSync(`${tmpobj.name}/neuvectortest.json`, 'utf8'), + ) + const sample = JSON.parse( + fs.readFileSync( + path.resolve('./test/sample_data/neuvector/neuvector-hdf-mitre-vulcan.json'), 'utf8'), + ) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) +}) describe('Test NeuVector withraw flag', () => { - const tmpobj = tmp.dirSync({unsafeCleanup: true}); + const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command([ - 'convert neuvector2hdf', - '-i', - path.resolve( - './test/sample_data/neuvector/sample_input_report/neuvector-mitre-caldera.json' - ), - '-o', - `${tmpobj.name}/neuvectortest.json`, - '-w' + it('hdf-converter with raw output test on mitre/caldera', async () => { + await runCommand<{name: string}>(['convert neuvector2hdf', + '-i', path.resolve('./test/sample_data/neuvector/sample_input_report/neuvector-mitre-caldera.json'), + '-o', `${tmpobj.name}/neuvectortest.json`, '-w', ]) - .it('hdf-converter withraw output test on mitre/caldera', () => { - const converted = JSON.parse( - fs.readFileSync(`${tmpobj.name}/neuvectortest.json`, 'utf8') - ); - const sample = JSON.parse( - fs.readFileSync( - path.resolve( - './test/sample_data/neuvector/neuvector-hdf-withraw-mitre-caldera.json' - ), - 'utf8' - ) - ); - expect(omitHDFChangingFields(converted)).to.eql( - omitHDFChangingFields(sample) - ); - }); + const converted = JSON.parse( + fs.readFileSync(`${tmpobj.name}/neuvectortest.json`, 'utf8'), + ) + const sample = JSON.parse( + fs.readFileSync( + path.resolve('./test/sample_data/neuvector/neuvector-hdf-withraw-mitre-caldera.json'), 'utf8'), + ) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) - test - .stdout() - .command([ - 'convert neuvector2hdf', - '-i', - path.resolve( - './test/sample_data/neuvector/sample_input_report/neuvector-mitre-heimdall.json' - ), - '-o', - `${tmpobj.name}/neuvectortest.json`, - '-w' + it('hdf-converter with raw output test on mitre/heimdall', async () => { + await runCommand<{name: string}>(['convert neuvector2hdf', + '-i', path.resolve('./test/sample_data/neuvector/sample_input_report/neuvector-mitre-heimdall.json'), + '-o', `${tmpobj.name}/neuvectortest.json`, '-w', ]) - .it('hdf-converter withraw output test on mitre/heimdall', () => { - const converted = JSON.parse( - fs.readFileSync(`${tmpobj.name}/neuvectortest.json`, 'utf8') - ); - const sample = JSON.parse( - fs.readFileSync( - path.resolve( - './test/sample_data/neuvector/neuvector-hdf-withraw-mitre-heimdall.json' - ), - 'utf8' - ) - ); - expect(omitHDFChangingFields(converted)).to.eql( - omitHDFChangingFields(sample) - ); - }); + const converted = JSON.parse( + fs.readFileSync(`${tmpobj.name}/neuvectortest.json`, 'utf8'), + ) + const sample = JSON.parse( + fs.readFileSync( + path.resolve('./test/sample_data/neuvector/neuvector-hdf-withraw-mitre-heimdall.json'), 'utf8'), + ) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) - test - .stdout() - .command([ - 'convert neuvector2hdf', - '-i', - path.resolve( - './test/sample_data/neuvector/sample_input_report/neuvector-mitre-heimdall2.json' - ), - '-o', - `${tmpobj.name}/neuvectortest.json`, - '-w' + it('hdf-converter with raw output test on mitre/heimdall2', async () => { + await runCommand<{name: string}>(['convert neuvector2hdf', + '-i', path.resolve('./test/sample_data/neuvector/sample_input_report/neuvector-mitre-heimdall2.json'), + '-o', `${tmpobj.name}/neuvectortest.json`, '-w', ]) - .it('hdf-converter withraw output test on mitre/heimdall2', () => { - const converted = JSON.parse( - fs.readFileSync(`${tmpobj.name}/neuvectortest.json`, 'utf8') - ); - const sample = JSON.parse( - fs.readFileSync( - path.resolve( - './test/sample_data/neuvector/neuvector-hdf-withraw-mitre-heimdall2.json' - ), - 'utf8' - ) - ); - expect(omitHDFChangingFields(converted)).to.eql( - omitHDFChangingFields(sample) - ); - }); + const converted = JSON.parse( + fs.readFileSync(`${tmpobj.name}/neuvectortest.json`, 'utf8'), + ) + const sample = JSON.parse( + fs.readFileSync( + path.resolve('./test/sample_data/neuvector/neuvector-hdf-withraw-mitre-heimdall2.json'), 'utf8'), + ) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) - test - .stdout() - .command([ - 'convert neuvector2hdf', - '-i', - path.resolve( - './test/sample_data/neuvector/sample_input_report/neuvector-mitre-vulcan.json' - ), - '-o', - `${tmpobj.name}/neuvectortest.json`, - '-w' + it('hdf-converter with raw output test on mitre/vulcan', async () => { + await runCommand<{name: string}>(['convert neuvector2hdf', + '-i', path.resolve('./test/sample_data/neuvector/sample_input_report/neuvector-mitre-vulcan.json'), + '-o', `${tmpobj.name}/neuvectortest.json`, '-w', ]) - .it('hdf-converter withraw output test on mitre/vulcan', () => { - const converted = JSON.parse( - fs.readFileSync(`${tmpobj.name}/neuvectortest.json`, 'utf8') - ); - const sample = JSON.parse( - fs.readFileSync( - path.resolve( - './test/sample_data/neuvector/neuvector-hdf-withraw-mitre-vulcan.json' - ), - 'utf8' - ) - ); - expect(omitHDFChangingFields(converted)).to.eql( - omitHDFChangingFields(sample) - ); - }); -}); + const converted = JSON.parse( + fs.readFileSync(`${tmpobj.name}/neuvectortest.json`, 'utf8'), + ) + const sample = JSON.parse( + fs.readFileSync( + path.resolve('./test/sample_data/neuvector/neuvector-hdf-withraw-mitre-vulcan.json'), 'utf8'), + ) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) +}) diff --git a/test/commands/convert/nikto2hdf.test.ts b/test/commands/convert/nikto2hdf.test.ts index 223f14b4a..10e190d80 100644 --- a/test/commands/convert/nikto2hdf.test.ts +++ b/test/commands/convert/nikto2hdf.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,25 +10,27 @@ import {omitHDFChangingFields} from '../utils' describe('Test nikto', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert nikto2hdf', '-i', path.resolve('./test/sample_data/nikto/sample_input_report/zero.webappsecurity.json'), '-o', `${tmpobj.name}/niktotest.json`]) - .it('hdf-converter output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/niktotest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/nikto/nikto-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert nikto2hdf', + '-i', path.resolve('./test/sample_data/nikto/sample_input_report/zero.webappsecurity.json'), + '-o', `${tmpobj.name}/niktotest.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/niktotest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/nikto/nikto-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) describe('Test nikto using withraw flag', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert nikto2hdf', '-i', path.resolve('./test/sample_data/nikto/sample_input_report/zero.webappsecurity.json'), '-o', `${tmpobj.name}/niktotest.json`, '-w']) - .it('hdf-converter withraw output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/niktotest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/nikto/nikto-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter with raw output test', async () => { + await runCommand<{name: string}>(['convert nikto2hdf', + '-i', path.resolve('./test/sample_data/nikto/sample_input_report/zero.webappsecurity.json'), + '-o', `${tmpobj.name}/niktotest.json`, '-w', + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/niktotest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/nikto/nikto-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) diff --git a/test/commands/convert/prisma2hdf.test.ts b/test/commands/convert/prisma2hdf.test.ts index c2da6ab1c..8dbd3cd15 100644 --- a/test/commands/convert/prisma2hdf.test.ts +++ b/test/commands/convert/prisma2hdf.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,20 +10,21 @@ import {omitHDFChangingFields} from '../utils' describe('Test prisma', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert prisma2hdf', '-i', path.resolve('./test/sample_data/prisma/sample_input_report/prismacloud_sample.csv'), '-o', `${tmpobj.name}/prismatest`]) - .it('hdf-converter output test', () => { - const test1 = JSON.parse(fs.readFileSync(`${tmpobj.name}/prismatest/localhost.json`, 'utf8')) - const test2 = JSON.parse(fs.readFileSync(`${tmpobj.name}/prismatest/my-fake-host-1.somewhere.cloud.json`, 'utf8')) - const test3 = JSON.parse(fs.readFileSync(`${tmpobj.name}/prismatest/my-fake-host-2.somewhere.cloud.json`, 'utf8')) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert prisma2hdf', + '-i', path.resolve('./test/sample_data/prisma/sample_input_report/prismacloud_sample.csv'), + '-o', `${tmpobj.name}/prismatest`, + ]) + const test1 = JSON.parse(fs.readFileSync(`${tmpobj.name}/prismatest/localhost.json`, 'utf8')) + const test2 = JSON.parse(fs.readFileSync(`${tmpobj.name}/prismatest/my-fake-host-1.somewhere.cloud.json`, 'utf8')) + const test3 = JSON.parse(fs.readFileSync(`${tmpobj.name}/prismatest/my-fake-host-2.somewhere.cloud.json`, 'utf8')) - const sample1 = JSON.parse(fs.readFileSync(path.resolve('test/sample_data/prisma/localhost.json'), 'utf8')) - const sample2 = JSON.parse(fs.readFileSync(path.resolve('test/sample_data/prisma/my-fake-host-1.somewhere.cloud.json'), 'utf8')) - const sample3 = JSON.parse(fs.readFileSync(path.resolve('test/sample_data/prisma/my-fake-host-2.somewhere.cloud.json'), 'utf8')) + const sample1 = JSON.parse(fs.readFileSync(path.resolve('test/sample_data/prisma/localhost.json'), 'utf8')) + const sample2 = JSON.parse(fs.readFileSync(path.resolve('test/sample_data/prisma/my-fake-host-1.somewhere.cloud.json'), 'utf8')) + const sample3 = JSON.parse(fs.readFileSync(path.resolve('test/sample_data/prisma/my-fake-host-2.somewhere.cloud.json'), 'utf8')) - expect(omitHDFChangingFields(test1)).to.eql(omitHDFChangingFields(sample1)) - expect(omitHDFChangingFields(test2)).to.eql(omitHDFChangingFields(sample2)) - expect(omitHDFChangingFields(test3)).to.eql(omitHDFChangingFields(sample3)) - }) + expect(omitHDFChangingFields(test1)).to.eql(omitHDFChangingFields(sample1)) + expect(omitHDFChangingFields(test2)).to.eql(omitHDFChangingFields(sample2)) + expect(omitHDFChangingFields(test3)).to.eql(omitHDFChangingFields(sample3)) + }) }) diff --git a/test/commands/convert/sarif2hdf.test.ts b/test/commands/convert/sarif2hdf.test.ts index 8d17ea487..79f2bdc74 100644 --- a/test/commands/convert/sarif2hdf.test.ts +++ b/test/commands/convert/sarif2hdf.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,25 +10,27 @@ import {omitHDFChangingFields} from '../utils' describe('Test sarif', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert sarif2hdf', '-i', path.resolve('./test/sample_data/sarif/sample_input_report/sarif_input.sarif'), '-o', `${tmpobj.name}/sariftest.json`]) - .it('hdf-converter output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/sariftest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/sarif/sarif-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert sarif2hdf', + '-i', path.resolve('./test/sample_data/sarif/sample_input_report/sarif_input.sarif'), + '-o', `${tmpobj.name}/sariftest.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/sariftest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/sarif/sarif-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) describe('Test sarif using withraw flag', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert sarif2hdf', '-i', path.resolve('./test/sample_data/sarif/sample_input_report/sarif_input.sarif'), '-o', `${tmpobj.name}/sariftest.json`, '-w']) - .it('hdf-converter withraw output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/sariftest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/sarif/sarif-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter with raw output test', async () => { + await runCommand<{name: string}>(['convert sarif2hdf', + '-i', path.resolve('./test/sample_data/sarif/sample_input_report/sarif_input.sarif'), + '-o', `${tmpobj.name}/sariftest.json`, '-w', + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/sariftest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/sarif/sarif-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) diff --git a/test/commands/convert/scoutsuite2hdf.test.ts b/test/commands/convert/scoutsuite2hdf.test.ts index 450dedf6a..d4526185f 100644 --- a/test/commands/convert/scoutsuite2hdf.test.ts +++ b/test/commands/convert/scoutsuite2hdf.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,25 +10,27 @@ import {omitHDFChangingFields} from '../utils' describe('Test scoutsuite', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert scoutsuite2hdf', '-i', path.resolve('./test/sample_data/scoutsuite/sample_input_report/scoutsuite_sample.js'), '-o', `${tmpobj.name}/scoutsuitetest.json`]) - .it('hdf-converter output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/scoutsuitetest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/scoutsuite/scoutsuite-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert scoutsuite2hdf', + '-i', path.resolve('./test/sample_data/scoutsuite/sample_input_report/scoutsuite_sample.js'), + '-o', `${tmpobj.name}/scoutsuitetest.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/scoutsuitetest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/scoutsuite/scoutsuite-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) describe('Test scoutsuite using withraw flag', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert scoutsuite2hdf', '-i', path.resolve('./test/sample_data/scoutsuite/sample_input_report/scoutsuite_sample.js'), '-o', `${tmpobj.name}/scoutsuitetest.json`, '-w']) - .it('hdf-converter withraw output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/scoutsuitetest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/scoutsuite/scoutsuite-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter with raw output test', async () => { + await runCommand<{name: string}>(['convert scoutsuite2hdf', + '-i', path.resolve('./test/sample_data/scoutsuite/sample_input_report/scoutsuite_sample.js'), + '-o', `${tmpobj.name}/scoutsuitetest.json`, '-w', + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/scoutsuitetest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/scoutsuite/scoutsuite-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) diff --git a/test/commands/convert/trufflehog2hdf.test.ts b/test/commands/convert/trufflehog2hdf.test.ts index dc00de9c1..82c43f55c 100644 --- a/test/commands/convert/trufflehog2hdf.test.ts +++ b/test/commands/convert/trufflehog2hdf.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,73 +10,87 @@ import {omitHDFChangingFields} from '../utils' describe('Test Trufflehog', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert trufflehog2hdf', '-i', path.resolve('./test/sample_data/trufflehog/sample_input_report/trufflehog.json'), '-o', `${tmpobj.name}/trufflehog.json`]) - .it('hdf-converter output test - standard', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/trufflehog.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/trufflehog/trufflehog-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert trufflehog2hdf', '-i', path.resolve('./test/sample_data/trufflehog/sample_input_report/trufflehog_docker_example.json'), '-o', `${tmpobj.name}/trufflehog.json`]) - .it('hdf-converter output test - docker', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/trufflehog.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/trufflehog/trufflehog-docker-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert trufflehog2hdf', '-i', path.resolve('./test/sample_data/trufflehog/sample_input_report/trufflehog_report_example.json'), '-o', `${tmpobj.name}/trufflehog.json`]) - .it('hdf-converter output test - report', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/trufflehog.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/trufflehog/trufflehog-report-example-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert trufflehog2hdf', '-i', path.resolve('./test/sample_data/trufflehog/sample_input_report/trufflehog_saf_example.json'), '-o', `${tmpobj.name}/trufflehog.json`]) - .it('hdf-converter output test - saf', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/trufflehog.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/trufflehog/trufflehog-saf-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test - standard', async () => { + await runCommand<{name: string}>(['convert trufflehog2hdf', + '-i', path.resolve('./test/sample_data/trufflehog/sample_input_report/trufflehog.json'), + '-o', `${tmpobj.name}/trufflehog.json`, + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/trufflehog.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/trufflehog/trufflehog-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + + it('hdf-converter output test - docker', async () => { + await runCommand<{name: string}>(['convert trufflehog2hdf', + '-i', path.resolve('./test/sample_data/trufflehog/sample_input_report/trufflehog_docker_example.json'), + '-o', `${tmpobj.name}/trufflehog.json`, + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/trufflehog.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/trufflehog/trufflehog-docker-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + + it('hdf-converter output test - report', async () => { + await runCommand<{name: string}>(['convert trufflehog2hdf', + '-i', path.resolve('./test/sample_data/trufflehog/sample_input_report/trufflehog_report_example.json'), + '-o', `${tmpobj.name}/trufflehog.json`, + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/trufflehog.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/trufflehog/trufflehog-report-example-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + + it('hdf-converter output test - saf', async () => { + await runCommand<{name: string}>(['convert trufflehog2hdf', + '-i', path.resolve('./test/sample_data/trufflehog/sample_input_report/trufflehog_saf_example.json'), + '-o', `${tmpobj.name}/trufflehog.json`, + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/trufflehog.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/trufflehog/trufflehog-saf-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) }) describe('Test Trufflehog using withraw flag', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert trufflehog2hdf', '-i', path.resolve('./test/sample_data/trufflehog/sample_input_report/trufflehog.json'), '-o', `${tmpobj.name}/trufflehog.json`, '-w']) - .it('hdf-converter withraw output test - standard', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/trufflehog.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/trufflehog/trufflehog-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert trufflehog2hdf', '-i', path.resolve('./test/sample_data/trufflehog/sample_input_report/trufflehog_docker_example.json'), '-o', `${tmpobj.name}/trufflehog.json`, '-w']) - .it('hdf-converter withraw output test - docker', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/trufflehog.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/trufflehog/trufflehog-docker-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert trufflehog2hdf', '-i', path.resolve('./test/sample_data/trufflehog/sample_input_report/trufflehog_report_example.json'), '-o', `${tmpobj.name}/trufflehog.json`, '-w']) - .it('hdf-converter withraw output test - report', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/trufflehog.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/trufflehog/trufflehog-report-example-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert trufflehog2hdf', '-i', path.resolve('./test/sample_data/trufflehog/sample_input_report/trufflehog_saf_example.json'), '-o', `${tmpobj.name}/trufflehog.json`, '-w']) - .it('hdf-converter withraw output test - saf', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/trufflehog.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/trufflehog/trufflehog-saf-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter with raw output test - standard', async () => { + await runCommand<{name: string}>(['convert trufflehog2hdf', + '-i', path.resolve('./test/sample_data/trufflehog/sample_input_report/trufflehog.json'), + '-o', `${tmpobj.name}/trufflehog.json`, '-w', + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/trufflehog.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/trufflehog/trufflehog-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + + it('hdf-converter with raw output test - docker', async () => { + await runCommand<{name: string}>(['convert trufflehog2hdf', + '-i', path.resolve('./test/sample_data/trufflehog/sample_input_report/trufflehog_docker_example.json'), + '-o', `${tmpobj.name}/trufflehog.json`, '-w', + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/trufflehog.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/trufflehog/trufflehog-docker-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + + it('hdf-converter with raw output test - report', async () => { + await runCommand<{name: string}>(['convert trufflehog2hdf', + '-i', path.resolve('./test/sample_data/trufflehog/sample_input_report/trufflehog_report_example.json'), + '-o', `${tmpobj.name}/trufflehog.json`, '-w', + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/trufflehog.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/trufflehog/trufflehog-report-example-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + + it('hdf-converter with raw output test - saf', async () => { + await runCommand<{name: string}>(['convert trufflehog2hdf', + '-i', path.resolve('./test/sample_data/trufflehog/sample_input_report/trufflehog_saf_example.json'), + '-o', `${tmpobj.name}/trufflehog.json`, '-w', + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/trufflehog.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/trufflehog/trufflehog-saf-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) }) diff --git a/test/commands/convert/twistlock2hdf.test.ts b/test/commands/convert/twistlock2hdf.test.ts index 832243a0c..ae309c00b 100644 --- a/test/commands/convert/twistlock2hdf.test.ts +++ b/test/commands/convert/twistlock2hdf.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,41 +10,47 @@ import {omitHDFChangingFields} from '../utils' describe('Test twistlock', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert twistlock2hdf', '-i', path.resolve('./test/sample_data/twistlock/sample_input_report/twistlock-twistcli-sample-1.json'), '-o', `${tmpobj.name}/twistlock.json`]) - .it('hdf-converter output test', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/twistlock.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/twistlock/twistlock-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert twistlock2hdf', '-i', path.resolve('./test/sample_data/twistlock/sample_input_report/twistlock-twistcli-coderepo-scan-sample.json'), '-o', `${tmpobj.name}/twistlock.json`]) - .it('hdf-converter output test', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/twistlock.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/twistlock/twistlock-coderepo-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert twistlock2hdf', + '-i', path.resolve('./test/sample_data/twistlock/sample_input_report/twistlock-twistcli-sample-1.json'), + '-o', `${tmpobj.name}/twistlock.json`, + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/twistlock.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/twistlock/twistlock-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert twistlock2hdf', + '-i', path.resolve('./test/sample_data/twistlock/sample_input_report/twistlock-twistcli-coderepo-scan-sample.json'), + '-o', `${tmpobj.name}/twistlock.json`, + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/twistlock.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/twistlock/twistlock-coderepo-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) }) describe('Test twistlock using withraw flag', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert twistlock2hdf', '-i', path.resolve('./test/sample_data/twistlock/sample_input_report/twistlock-twistcli-sample-1.json'), '-o', `${tmpobj.name}/twistlock.json`, '-w']) - .it('hdf-converter withraw output test - standard', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/twistlock.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/twistlock/twistlock-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert twistlock2hdf', '-i', path.resolve('./test/sample_data/twistlock/sample_input_report/twistlock-twistcli-coderepo-scan-sample.json'), '-o', `${tmpobj.name}/twistlock.json`, '-w']) - .it('hdf-converter withraw output test - code repo', () => { - const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/twistlock.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/twistlock/twistlock-coderepo-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter with raw output test - standard', async () => { + await runCommand<{name: string}>(['convert twistlock2hdf', + '-i', path.resolve('./test/sample_data/twistlock/sample_input_report/twistlock-twistcli-sample-1.json'), + '-o', `${tmpobj.name}/twistlock.json`, '-w', + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/twistlock.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/twistlock/twistlock-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) + + it('hdf-converter with raw output test - code repo', async () => { + await runCommand<{name: string}>(['convert twistlock2hdf', + '-i', path.resolve('./test/sample_data/twistlock/sample_input_report/twistlock-twistcli-coderepo-scan-sample.json'), + '-o', `${tmpobj.name}/twistlock.json`, '-w', + ]) + const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/twistlock.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/twistlock/twistlock-coderepo-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) + }) }) diff --git a/test/commands/convert/veracode2hdf.test.ts b/test/commands/convert/veracode2hdf.test.ts index 0a969b406..c94954734 100644 --- a/test/commands/convert/veracode2hdf.test.ts +++ b/test/commands/convert/veracode2hdf.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,12 +10,13 @@ import {omitHDFChangingFields} from '../utils' describe('Test veracode', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert veracode2hdf', '-i', path.resolve('./test/sample_data/veracode/sample_input_report/veracode.xml'), '-o', `${tmpobj.name}/veracodetest.json`]) - .it('hdf-converter output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/veracodetest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/veracode/veracode-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert veracode2hdf', + '-i', path.resolve('./test/sample_data/veracode/sample_input_report/veracode.xml'), + '-o', `${tmpobj.name}/veracodetest.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/veracodetest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/veracode/veracode-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) diff --git a/test/commands/convert/xccdf_results2hdf.test.ts b/test/commands/convert/xccdf_results2hdf.test.ts index 7f3d0bc3c..f50a0755c 100644 --- a/test/commands/convert/xccdf_results2hdf.test.ts +++ b/test/commands/convert/xccdf_results2hdf.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,25 +10,27 @@ import {omitHDFChangingFields} from '../utils' describe('Test xccdf_results', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert xccdf_results2hdf', '-i', path.resolve('./test/sample_data/xccdf_results/sample_input_report/xccdf-results-openscap-rhel7.xml'), '-o', `${tmpobj.name}/xccdfresultstest.json`]) - .it('hdf-converter output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/xccdfresultstest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/xccdf_results/xccdf-openscap-rhel7-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test', async () => { + await runCommand<{name: string}>(['convert xccdf_results2hdf', + '-i', path.resolve('./test/sample_data/xccdf_results/sample_input_report/xccdf-results-openscap-rhel7.xml'), + '-o', `${tmpobj.name}/xccdfresultstest.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/xccdfresultstest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/xccdf_results/xccdf-openscap-rhel7-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) describe('Test xccdf_results using withraw flag', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert xccdf_results2hdf', '-i', path.resolve('./test/sample_data/xccdf_results/sample_input_report/xccdf-results-openscap-rhel7.xml'), '-o', `${tmpobj.name}/xccdfresultstest.json`, '-w']) - .it('hdf-converter withraw output test', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/xccdfresultstest.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/xccdf_results/xccdf-openscap-rhel7-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter with raw output test', async () => { + await runCommand<{name: string}>(['convert xccdf_results2hdf', + '-i', path.resolve('./test/sample_data/xccdf_results/sample_input_report/xccdf-results-openscap-rhel7.xml'), + '-o', `${tmpobj.name}/xccdfresultstest.json`, '-w', + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/xccdfresultstest.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/xccdf_results/xccdf-openscap-rhel7-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) diff --git a/test/commands/convert/zap2hdf.test.ts b/test/commands/convert/zap2hdf.test.ts index 37fa1331b..34918788a 100644 --- a/test/commands/convert/zap2hdf.test.ts +++ b/test/commands/convert/zap2hdf.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,41 +10,51 @@ import {omitHDFChangingFields} from '../utils' describe('Test zap', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert zap2hdf', '-i', path.resolve('./test/sample_data/zap/sample_input_report/webgoat.json'), '-n', 'http://mymac.com:8191', '-o', `${tmpobj.name}/zaptest-webgoat.json`]) - .it('hdf-converter output test - webgoat', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/zaptest-webgoat.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/zap/zap-webgoat-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert zap2hdf', '-i', path.resolve('./test/sample_data/zap/sample_input_report/zero.webappsecurity.json'), '-n', 'http://zero.webappsecurity.com', '-o', `${tmpobj.name}/zaptest-webappsecurity.json`]) - .it('hdf-converter output test - zero.webappsecurity', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/zaptest-webappsecurity.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/zap/zap-webappsecurity-hdf.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter output test - webgoat', async () => { + await runCommand<{name: string}>(['convert zap2hdf', + '-i', path.resolve('./test/sample_data/zap/sample_input_report/webgoat.json'), + '-n', 'http://mymac.com:8191', + '-o', `${tmpobj.name}/zaptest-webgoat.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/zaptest-webgoat.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/zap/zap-webgoat-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) + + it('hdf-converter output test - zero.webappsecurity', async () => { + await runCommand<{name: string}>(['convert zap2hdf', + '-i', path.resolve('./test/sample_data/zap/sample_input_report/zero.webappsecurity.json'), + '-n', 'http://zero.webappsecurity.com', + '-o', `${tmpobj.name}/zaptest-webappsecurity.json`, + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/zaptest-webappsecurity.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/zap/zap-webappsecurity-hdf.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) describe('Test zap using withraw flag', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['convert zap2hdf', '-i', path.resolve('./test/sample_data/zap/sample_input_report/webgoat.json'), '-n', 'http://mymac.com:8191', '-o', `${tmpobj.name}/zaptest-webgoat.json`, '-w']) - .it('hdf-converter withraw output test - webgoat', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/zaptest-webgoat.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/zap/zap-webgoat-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) - test - .stdout() - .command(['convert zap2hdf', '-i', path.resolve('./test/sample_data/zap/sample_input_report/zero.webappsecurity.json'), '-n', 'http://zero.webappsecurity.com', '-o', `${tmpobj.name}/zaptest-webappsecurity.json`, '-w']) - .it('hdf-converter withraw output test - zero.webappsecurity', () => { - const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/zaptest-webappsecurity.json`, 'utf8')) - const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/zap/zap-webappsecurity-hdf-withraw.json'), 'utf8')) - expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) - }) + it('hdf-converter with raw output test - webgoat', async () => { + await runCommand<{name: string}>(['convert zap2hdf', + '-i', path.resolve('./test/sample_data/zap/sample_input_report/webgoat.json'), + '-n', 'http://mymac.com:8191', + '-o', `${tmpobj.name}/zaptest-webgoat.json`, '-w', + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/zaptest-webgoat.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/zap/zap-webgoat-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) + + it('hdf-converter with raw output test - zero.webappsecurity', async () => { + await runCommand<{name: string}>(['convert zap2hdf', + '-i', path.resolve('./test/sample_data/zap/sample_input_report/zero.webappsecurity.json'), + '-n', 'http://zero.webappsecurity.com', + '-o', `${tmpobj.name}/zaptest-webappsecurity.json`, '-w', + ]) + const test = JSON.parse(fs.readFileSync(`${tmpobj.name}/zaptest-webappsecurity.json`, 'utf8')) + const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/zap/zap-webappsecurity-hdf-withraw.json'), 'utf8')) + expect(omitHDFChangingFields(test)).to.eql(omitHDFChangingFields(sample)) + }) }) diff --git a/test/commands/emasser/delete.test.ts b/test/commands/emasser/delete.test.ts index f8cd49631..34c6d5a06 100644 --- a/test/commands/emasser/delete.test.ts +++ b/test/commands/emasser/delete.test.ts @@ -1,4 +1,4 @@ -import {expect, test} from '@oclif/test' +import {expect} from 'chai' import {InitMockServer} from './mock.server' import {ArtifactsApi, POAMApi, MilestonesApi} from '@mitre/emass_client' import {ArtifactsResponseDel, PoamResponseDelete, @@ -12,51 +12,48 @@ describe('Test eMASS API CLI (delete) commands', () => { statusText: 'OK', } - test - .it('Successfully tested endpoint - artifacts', async () => { - const delArtifact = new ArtifactsApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await delArtifact.deleteArtifact(123, []).then((response: ArtifactsResponseDel) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } + it('Successfully tested endpoint - artifacts', async () => { + const delArtifact = new ArtifactsApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await delArtifact.deleteArtifact(123, []).then((response: ArtifactsResponseDel) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') + responseDataObj = new Map(Object.entries(testOk)) }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) - test - .it('Successfully tested endpoint - poams', async () => { - const delPoam = new POAMApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await delPoam.deletePoam(34, []).then((response: PoamResponseDelete) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } + it('Successfully tested endpoint - poams', async () => { + const delPoam = new POAMApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await delPoam.deletePoam(34, []).then((response: PoamResponseDelete) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') + responseDataObj = new Map(Object.entries(testOk)) }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) - test - .it('Successfully tested endpoint - milestones', async () => { - const delMilestones = new MilestonesApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await delMilestones.deleteMilestone(36, 76, []).then((response: MilestonesPutPostDelete) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } + it('Successfully tested endpoint - milestones', async () => { + const delMilestones = new MilestonesApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await delMilestones.deleteMilestone(36, 76, []).then((response: MilestonesPutPostDelete) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') + responseDataObj = new Map(Object.entries(testOk)) }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) }) diff --git a/test/commands/emasser/get.test.ts b/test/commands/emasser/get.test.ts index a6830b824..5b32134f5 100644 --- a/test/commands/emasser/get.test.ts +++ b/test/commands/emasser/get.test.ts @@ -1,4 +1,4 @@ -import {expect, test} from '@oclif/test' +import {expect} from 'chai' import {InitMockServer} from './mock.server' import {SystemsApi, SystemRolesApi, TestApi, POAMApi, CACApi, PACApi, MilestonesApi, ControlsApi, @@ -15,512 +15,504 @@ describe('Test eMASS API CLI (get) commands', () => { statusText: 'OK', } - test - .it('Successfully tested endpoint - test connection', async () => { - const getTestApi = new TestApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await getTestApi.testConnection().then((response: SystemResponse) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - - test - .it('Successfully tested endpoint - system', async () => { - const getSystems = new SystemsApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await getSystems.getSystem(123, true, 'rmf').then((response: SystemResponse) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - - test - .it('Successfully tested endpoint - systems', async () => { - const getSystems = new SystemsApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await getSystems.getSystems(false, 'regular', 'ditprid', 'coamsid', 'rmf', false, false, true).then((response: SystemsResponse) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - - test - .it('Successfully tested endpoint - roles', async () => { - const getSystemRoles = new SystemRolesApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await getSystemRoles.getSystemRoles().then((response: SystemRolesResponse) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - - test - .it('Successfully tested endpoint - poams', async () => { - const getPoams = new POAMApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await getPoams.getSystemPoamsByPoamId(34, 56).then((response: PoamResponseGetPoams) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - - test - .it('Successfully tested endpoint - cac', async () => { - const getCac = new CACApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await getCac.getSystemCac(34, 'acronym').then((response: CacResponseGet) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - - test - .it('Successfully tested endpoint - pac', async () => { - const getPac = new PACApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await getPac.getSystemPac(34).then((response: PacResponseGet) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - - test - .it('Successfully tested endpoint - milestones', async () => { - const getMilestones = new MilestonesApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await getMilestones.getSystemMilestonesByPoamIdAndMilestoneId(36, 76, 89).then((response: MilestoneResponseGetMilestone) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - - test - .it('Successfully tested endpoint - controls', async () => { - const getControls = new ControlsApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await getControls.getSystemControls(34, 'acronym').then((response: CacResponseGet) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) + it('Successfully tested endpoint - test connection', async () => { + const getTestApi = new TestApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await getTestApi.testConnection().then((response: SystemResponse) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - system', async () => { + const getSystems = new SystemsApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await getSystems.getSystem(123, true, 'rmf').then((response: SystemResponse) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - systems', async () => { + const getSystems = new SystemsApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await getSystems.getSystems(false, 'regular', 'ditprid', 'coamsid', 'rmf', false, false, true).then((response: SystemsResponse) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - roles', async () => { + const getSystemRoles = new SystemRolesApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await getSystemRoles.getSystemRoles().then((response: SystemRolesResponse) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - poams', async () => { + const getPoams = new POAMApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await getPoams.getSystemPoamsByPoamId(34, 56).then((response: PoamResponseGetPoams) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - cac', async () => { + const getCac = new CACApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await getCac.getSystemCac(34, 'acronym').then((response: CacResponseGet) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - pac', async () => { + const getPac = new PACApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await getPac.getSystemPac(34).then((response: PacResponseGet) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - milestones', async () => { + const getMilestones = new MilestonesApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await getMilestones.getSystemMilestonesByPoamIdAndMilestoneId(36, 76, 89).then((response: MilestoneResponseGetMilestone) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - controls', async () => { + const getControls = new ControlsApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await getControls.getSystemControls(34, 'acronym').then((response: CacResponseGet) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + const getDashboards = new DashboardsApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - test - .it('Successfully tested endpoint - dashboards (status_details)', async () => { - await getDashboards.getSystemStatusDetails(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (control_compliance_summary)', async () => { - await getDashboards.getSystemControlComplianceSummary(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (security_control_details)', async () => { - await getDashboards.getSystemSecurityControlDetails(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (assessment_procedures_details)', async () => { - await getDashboards.getSystemAssessmentProceduresDetails(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (poam_summary)', async () => { - await getDashboards.getSystemPoamSummary(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (poam_details)', async () => { - await getDashboards.getSystemPoamDetails(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (artifacts_summary)', async () => { - await getDashboards.getSystemArtifactsSummary(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (artifacts_details)', async () => { - await getDashboards.getSystemArtifactsDetails(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (hardware_summary)', async () => { - await getDashboards.getSystemHardwareSummary(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (hardware_details)', async () => { - await getDashboards.getSystemHardwareDetails(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (sensor_hardware_summary)', async () => { - await getDashboards.getSystemSensorHardwareSummary(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (sensor_hardware_details)', async () => { - await getDashboards.getSystemSensorHardwareDetails(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (ports_protocols_summary)', async () => { - await getDashboards.getSystemPortsProtocolsSummary(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (ports_protocols_details)', async () => { - await getDashboards.getSystemPortsProtocolsDetails(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (associations_details)', async () => { - await getDashboards.getSystemAssociationsDetails(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (assignments_details)', async () => { - await getDashboards.getUserSystemAssignmentsDetails(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (privacy_summary)', async () => { - await getDashboards.getSystemPrivacySummary(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (fisma_saop_summary)', async () => { - await getDashboards.getVaOmbFsmaSaopSummary(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (va_aa_summary)', async () => { - await getDashboards.getVaSystemAaSummary(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (va_a2_summary)', async () => { - await getDashboards.getVaSystemA2Summary(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (va_pl_109_summary)', async () => { - await getDashboards.getVaSystemPl109ReportingSummary(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (fisma_inventory_summary)', async () => { - await getDashboards.getVaSystemFismaInvetorySummary(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (fisma_inventory_crypto_summary)', async () => { - await getDashboards.getVaSystemFismaInvetoryCryptoSummary(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (threat_risk_summary)', async () => { - await getDashboards.getVaSystemThreatRiskSummary(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (threat_source_details)', async () => { - await getDashboards.getVaSystemThreatSourceDetails(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) - test - .it('Successfully tested endpoint - dashboards (threat_architecture_details)', async () => { - await getDashboards.getVaSystemThreatArchitectureDetails(45, false, 1, 2000).then((response: object) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error.message) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') - }) + + it('Successfully tested endpoint - dashboards (status_details)', async () => { + await getDashboards.getSystemStatusDetails(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (control_compliance_summary)', async () => { + await getDashboards.getSystemControlComplianceSummary(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (security_control_details)', async () => { + await getDashboards.getSystemSecurityControlDetails(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (assessment_procedures_details)', async () => { + await getDashboards.getSystemAssessmentProceduresDetails(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (poam_summary)', async () => { + await getDashboards.getSystemPoamSummary(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (poam_details)', async () => { + await getDashboards.getSystemPoamDetails(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (artifacts_summary)', async () => { + await getDashboards.getSystemArtifactsSummary(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (artifacts_details)', async () => { + await getDashboards.getSystemArtifactsDetails(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (hardware_summary)', async () => { + await getDashboards.getSystemHardwareSummary(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (hardware_details)', async () => { + await getDashboards.getSystemHardwareDetails(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (sensor_hardware_summary)', async () => { + await getDashboards.getSystemSensorHardwareSummary(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (sensor_hardware_details)', async () => { + await getDashboards.getSystemSensorHardwareDetails(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (ports_protocols_summary)', async () => { + await getDashboards.getSystemPortsProtocolsSummary(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (ports_protocols_details)', async () => { + await getDashboards.getSystemPortsProtocolsDetails(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (associations_details)', async () => { + await getDashboards.getSystemAssociationsDetails(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (assignments_details)', async () => { + await getDashboards.getUserSystemAssignmentsDetails(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (privacy_summary)', async () => { + await getDashboards.getSystemPrivacySummary(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (fisma_saop_summary)', async () => { + await getDashboards.getVaOmbFsmaSaopSummary(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (va_aa_summary)', async () => { + await getDashboards.getVaSystemAaSummary(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (va_a2_summary)', async () => { + await getDashboards.getVaSystemA2Summary(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (va_pl_109_summary)', async () => { + await getDashboards.getVaSystemPl109ReportingSummary(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (fisma_inventory_summary)', async () => { + await getDashboards.getVaSystemFismaInvetorySummary(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (fisma_inventory_crypto_summary)', async () => { + await getDashboards.getVaSystemFismaInvetoryCryptoSummary(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (threat_risk_summary)', async () => { + await getDashboards.getVaSystemThreatRiskSummary(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (threat_source_details)', async () => { + await getDashboards.getVaSystemThreatSourceDetails(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - dashboards (threat_architecture_details)', async () => { + await getDashboards.getVaSystemThreatArchitectureDetails(45, false, 1, 2000).then((response: object) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error.message) + } + + responseDataObj = new Map(Object.entries(testOk)) + }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) }) diff --git a/test/commands/emasser/post.test.ts b/test/commands/emasser/post.test.ts index 941080671..0aa8bad09 100644 --- a/test/commands/emasser/post.test.ts +++ b/test/commands/emasser/post.test.ts @@ -1,4 +1,4 @@ -import {expect, test} from '@oclif/test' +import {expect} from 'chai' import {InitMockServer} from './mock.server' import {CACApi, PACApi, CloudResourceResultsApi, ContainerScanResultsApi, MilestonesApi, POAMApi, RegistrationApi, StaticCodeScansApi, @@ -15,139 +15,138 @@ describe('Test eMASS API CLI (post) commands', () => { statusText: 'OK', } - test - .it('Successfully tested endpoint - cac', async () => { - const addCac = new CACApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await addCac.addSystemCac(123, []).then((response: CacResponsePost) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') + it('Successfully tested endpoint - cac', async () => { + const addCac = new CACApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await addCac.addSystemCac(123, []).then((response: CacResponsePost) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } + + responseDataObj = new Map(Object.entries(testOk)) }) - test - .it('Successfully tested endpoint - pac', async () => { - const addCac = new PACApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await addCac.addSystemPac(123, []).then((response: PacResponsePost) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - pac', async () => { + const addCac = new PACApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await addCac.addSystemPac(123, []).then((response: PacResponsePost) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } + + responseDataObj = new Map(Object.entries(testOk)) }) - test - .it('Successfully tested endpoint - cloud_resources', async () => { - const addCloudResource = new CloudResourceResultsApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await addCloudResource.addCloudResourcesBySystemId(123, []).then((response: CloudResourcesResponsePost) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - cloud_resources', async () => { + const addCloudResource = new CloudResourceResultsApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await addCloudResource.addCloudResourcesBySystemId(123, []).then((response: CloudResourcesResponsePost) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } + + responseDataObj = new Map(Object.entries(testOk)) }) - test - .it('Successfully tested endpoint - container_scans', async () => { - const addContainer = new ContainerScanResultsApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await addContainer.addContainerSansBySystemId(123, []).then((response: ContainersResponsePost) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - container_scans', async () => { + const addContainer = new ContainerScanResultsApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await addContainer.addContainerSansBySystemId(123, []).then((response: ContainersResponsePost) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } + + responseDataObj = new Map(Object.entries(testOk)) }) - test - .it('Successfully tested endpoint - milestones', async () => { - const addMilestone = new MilestonesApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await addMilestone.addMilestoneBySystemIdAndPoamId(123, 456, []).then((response: MilestoneResponsePost) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - milestones', async () => { + const addMilestone = new MilestonesApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await addMilestone.addMilestoneBySystemIdAndPoamId(123, 456, []).then((response: MilestoneResponsePost) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } + + responseDataObj = new Map(Object.entries(testOk)) }) - test - .it('Successfully tested endpoint - poams', async () => { - const addPoam = new POAMApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await addPoam.addPoamBySystemId(123, []).then((response: PoamResponsePost) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - poams', async () => { + const addPoam = new POAMApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await addPoam.addPoamBySystemId(123, []).then((response: PoamResponsePost) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } + + responseDataObj = new Map(Object.entries(testOk)) }) - test - .it('Successfully tested endpoint - register', async () => { - const registerAPI = new RegistrationApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await registerAPI.registerUser().then((response: Register) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - register', async () => { + const registerAPI = new RegistrationApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await registerAPI.registerUser().then((response: Register) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } + + responseDataObj = new Map(Object.entries(testOk)) }) - test - .it('Successfully tested endpoint - static_code_scans', async () => { - const addStaticCodeScans = new StaticCodeScansApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await addStaticCodeScans.addStaticCodeScansBySystemId(123, {}).then((response: StaticCodeResponsePost) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - static_code_scans', async () => { + const addStaticCodeScans = new StaticCodeScansApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await addStaticCodeScans.addStaticCodeScansBySystemId(123, {}).then((response: StaticCodeResponsePost) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } + + responseDataObj = new Map(Object.entries(testOk)) }) - test - .it('Successfully tested endpoint - test_results', async () => { - const addTestResults = new TestResultsApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await addTestResults.addTestResultsBySystemId(123, []).then((response: TestResultsResponsePost) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } - - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - test_results', async () => { + const addTestResults = new TestResultsApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await addTestResults.addTestResultsBySystemId(123, []).then((response: TestResultsResponsePost) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } + + responseDataObj = new Map(Object.entries(testOk)) }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) }) diff --git a/test/commands/emasser/put.test.ts b/test/commands/emasser/put.test.ts index 7f4816163..b221debf5 100644 --- a/test/commands/emasser/put.test.ts +++ b/test/commands/emasser/put.test.ts @@ -1,4 +1,4 @@ -import {expect, test} from '@oclif/test' +import {expect} from 'chai' import {InitMockServer} from './mock.server' import {ArtifactsApi, ControlsApi, MilestonesApi, POAMApi} from '@mitre/emass_client' import {ArtifactsResponsePutPost, ControlsResponsePut, @@ -12,64 +12,63 @@ describe('Test eMASS API CLI (put) commands', () => { statusText: 'OK', } - test - .it('Successfully tested endpoint - artifacts', async () => { - const artifactApi = new ArtifactsApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await artifactApi.updateArtifactBySystemId(123, []).then((response: ArtifactsResponsePutPost) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } + it('Successfully tested endpoint - artifacts', async () => { + const artifactApi = new ArtifactsApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await artifactApi.updateArtifactBySystemId(123, []).then((response: ArtifactsResponsePutPost) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') + responseDataObj = new Map(Object.entries(testOk)) }) - test - .it('Successfully tested endpoint - controls', async () => { - const updateControl = new ControlsApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await updateControl.updateControlBySystemId(123, []).then((response: ControlsResponsePut) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') + it('Successfully tested endpoint - controls', async () => { + const updateControl = new ControlsApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await updateControl.updateControlBySystemId(123, []).then((response: ControlsResponsePut) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } + + responseDataObj = new Map(Object.entries(testOk)) }) - test - .it('Successfully tested endpoint - milestones', async () => { - const putMilestones = new MilestonesApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await putMilestones.updateMilestoneBySystemIdAndPoamId(123, 456, []).then((response: MilestoneResponsePut) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - milestones', async () => { + const putMilestones = new MilestonesApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await putMilestones.updateMilestoneBySystemIdAndPoamId(123, 456, []).then((response: MilestoneResponsePut) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') + responseDataObj = new Map(Object.entries(testOk)) }) - test - .it('Successfully tested endpoint - poams', async () => { - const updatePoam = new POAMApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) - await updatePoam.updatePoamBySystemId(123, []).then((response: PoamResponsePut) => { - responseDataObj = new Map(Object.entries(response)) - }).catch((error:any) => { - if (error.message.includes('unexpected end of file') === false) { - console.error(error) - } + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) + + it('Successfully tested endpoint - poams', async () => { + const updatePoam = new POAMApi(mocSer.configuration, mocSer.basePath, mocSer.axiosInstances) + await updatePoam.updatePoamBySystemId(123, []).then((response: PoamResponsePut) => { + responseDataObj = new Map(Object.entries(response)) + }).catch((error:any) => { + if (error.message.includes('unexpected end of file') === false) { + console.error(error) + } - responseDataObj = new Map(Object.entries(testOk)) - }) - expect(responseDataObj.get('status')).to.equal(200) - expect(responseDataObj.get('statusText')).to.equal('OK') + responseDataObj = new Map(Object.entries(testOk)) }) + expect(responseDataObj.get('status')).to.equal(200) + expect(responseDataObj.get('statusText')).to.equal('OK') + }) }) diff --git a/test/commands/generate/delta.test.ts b/test/commands/generate/delta.test.ts index fed4c36ae..bbb50b8cd 100644 --- a/test/commands/generate/delta.test.ts +++ b/test/commands/generate/delta.test.ts @@ -1,6 +1,7 @@ /* eslint-disable array-bracket-newline */ /* eslint-disable array-element-newline */ -import {expect, test} from '@oclif/test' +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -10,142 +11,118 @@ describe('The generate delta command', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) // should process delta request with rule id type - test - .stdout() - .command(['generate delta', + it('should generate the controls for delta request with "rule" id type', async () => { + await runCommand<{name: string}>(['generate delta', '-J', path.resolve('./test/sample_data/inspec/json/rhel-7-v3r7-mini-sample-profile.json'), '-X', path.resolve('./test/sample_data/xccdf/stigs/rhel-7-v3r8-mini-sample-xxcdf.xml'), '-o', `${tmpobj.name}`, '-T', 'rule', ]) - .it('should generate the controls for delta request with "rule" id type', () => { - const fileCount = fs.readdirSync(`${tmpobj.name}/controls/`).length - expect(fileCount).to.eql(4) - }) + const fileCount = fs.readdirSync(`${tmpobj.name}/controls/`).length + expect(fileCount).to.eql(4) + }) // should process delta request with no id type specified // should process delta with initially empty output folder - test - .stdout() - .command(['generate delta', + it('should generate the output folder and place the controls in newly created folder for review', async () => { + await runCommand<{name: string}>(['generate delta', '-J', path.resolve('./test/sample_data/inspec/json/rhel-7-v3r7-mini-sample-profile.json'), '-X', path.resolve('./test/sample_data/xccdf/stigs/rhel-7-v3r8-mini-sample-xxcdf.xml'), '-o', `${tmpobj.name}/RHEL_7`, ]) - .it('should generate the output folder and place the controls in newly created folder for review', () => { - const fileCount = fs.readdirSync(`${tmpobj.name}/RHEL_7/controls/`).length - expect(fileCount).to.eql(4) - }) + const fileCount = fs.readdirSync(`${tmpobj.name}/RHEL_7/controls/`).length + expect(fileCount).to.eql(4) + }) - test - .stdout() - .command(['generate delta', + it('should generate a report with given file name and place it on the specified directory', async () => { + await runCommand<{name: string}>(['generate delta', '-J', path.resolve('./test/sample_data/inspec/json/rhel-7-v3r7-mini-sample-profile.json'), '-X', path.resolve('./test/sample_data/xccdf/stigs/rhel-7-v3r8-mini-sample-xxcdf.xml'), '-o', `${tmpobj.name}/RHEL_7`, '-r', `${tmpobj.name}/RHEL_7/my-report.md`, ]) - .it('should generate a report with given file name and place it on the specified directory', () => { - expect(fs.lstatSync((`${tmpobj.name}/RHEL_7/my-report.md`)).isFile()).to.be.true // skipcq: JS-0354 - }) + expect(fs.lstatSync((`${tmpobj.name}/RHEL_7/my-report.md`)).isFile()).to.be.true // skipcq: JS-0354 + }) - test - .stdout() - .command(['generate delta', + it('should generate a report name delta.md and place it in the default directory', async () => { + await runCommand<{name: string}>(['generate delta', '-J', path.resolve('./test/sample_data/inspec/json/rhel-7-v3r7-mini-sample-profile.json'), '-X', path.resolve('./test/sample_data/xccdf/stigs/rhel-7-v3r8-mini-sample-xxcdf.xml'), '-o', `${tmpobj.name}`, '-r', `${tmpobj.name}`, ]) - .it('should generate a report name delta.md and place it in the default directory', () => { - expect(fs.lstatSync((`${tmpobj.name}/delta.md`)).isFile()).to.be.true // skipcq: JS-0354 - }) + expect(fs.lstatSync((`${tmpobj.name}/delta.md`)).isFile()).to.be.true // skipcq: JS-0354 + }) // should process delta request with group id type // should process delta with output folder that contains controls information - test - .stdout() - .command(['generate delta', + it('should generate the controls for delta request with "group" id type', async () => { + await runCommand<{name: string}>(['generate delta', '-J', path.resolve('./test/sample_data/inspec/json/rhel-7-v3r7-mini-sample-profile.json'), '-X', path.resolve('./test/sample_data/xccdf/stigs/rhel-7-v3r8-mini-sample-xxcdf.xml'), '-o', `${tmpobj.name}`, '-T', 'group', ]) - .it('should generate the controls for delta request with "group" id type', () => { - const fileCount = fs.readdirSync(`${tmpobj.name}/controls/`).length - expect(fileCount).to.eql(4) - }) + const fileCount = fs.readdirSync(`${tmpobj.name}/controls/`).length + expect(fileCount).to.eql(4) + }) // should process delta request with cis id type - test - .stdout() - .command(['generate delta', + it('should generate the controls for delta request with "cis" id type', async () => { + await runCommand<{name: string}>(['generate delta', '-J', path.resolve('./test/sample_data/inspec/json/rhel-7-v3r7-mini-sample-profile.json'), '-X', path.resolve('./test/sample_data/xccdf/stigs/rhel-7-v3r8-mini-sample-xxcdf.xml'), '-o', `${tmpobj.name}`, '-T', 'cis', ]) - .it('should generate the controls for delta request with "cis" id type', () => { - const fileCount = fs.readdirSync(`${tmpobj.name}/controls/`).length - expect(fileCount).to.eql(4) - }) + const fileCount = fs.readdirSync(`${tmpobj.name}/controls/`).length + expect(fileCount).to.eql(4) + }) // should process delta request with version id type // should process delta request if given the "controls" folder - test - .stdout() - .command(['generate delta', + it('should generate the controls for delta request with "version" id type', async () => { + await runCommand<{name: string}>(['generate delta', '-J', path.resolve('./test/sample_data/inspec/json/rhel-7-v3r7-mini-sample-profile.json'), '-X', path.resolve('./test/sample_data/xccdf/stigs/rhel-7-v3r8-mini-sample-xxcdf.xml'), '-o', `${tmpobj.name}/controls`, '-T', 'version', ]) - .it('should generate the controls for delta request with "version" id type', () => { - const fileCount = fs.readdirSync(`${tmpobj.name}/controls/`).length - expect(fileCount).to.eql(4) - }) + const fileCount = fs.readdirSync(`${tmpobj.name}/controls/`).length + expect(fileCount).to.eql(4) + }) // should process delta request with oval definitions file specified // should provide error if oval definitions flag is specified with incorrect file format - - // Process delta mapping functionality - test - .stdout() - .command(['generate delta', + it('should match and map controls from one profile to another', async () => { + const {stdout} = await runCommand<{name: string}>(['generate delta', '-J', path.resolve('./test/sample_data/inspec/json/profile_and_controls/Windows_Server_2022_v1r3_mini-profile.json'), '-X', path.resolve('./test/sample_data/xccdf/stigs/Windows_Server_2022_V2R1_mini-sample-xccdf.xml'), '-o', `${tmpobj.name}`, '-T', 'rule', '-M', '-c', path.resolve('./test/sample_data/inspec/json/profile_and_controls/windows_server_2022_v1r3_mini_controls/'), ]) - .timeout(25000) - .it('should match and map controls from one profile to another', async ctx => { - // Wait for the command to finish execution - await ctx.returned - // Now you can safely access the output - expect(ctx.stdout).to.contain('Match Controls: 5') - }) - test - .stdout() - .command(['generate delta', + // Now you can safely access the output + expect(stdout).to.contain('Match Controls: 5') + }, 25000) + + it('should map to the correct filenames', async () => { + const {stdout} = await runCommand<{name: string}>(['generate delta', '-J', path.resolve('./test/sample_data/inspec/json/profile_and_controls/Windows_Server_2022_v1r3_mini-profile.json'), '-X', path.resolve('./test/sample_data/xccdf/stigs/Windows_Server_2022_V2R1_mini-sample-xccdf.xml'), '-o', `${tmpobj.name}`, '-T', 'rule', '-M', '-c', path.resolve('./test/sample_data/inspec/json/profile_and_controls/windows_server_2022_v1r3_mini_controls/'), ]) - .timeout(25000) - .it('should map to the correct filenames', async ctx => { - await ctx.returned - const output = ctx.stdout.split('\n') - expect(output.includes('Total Controls Found on Delta Directory: 5')) - expect(output.includes('Total Controls Found on XCCDF: 5')) - expect(output.includes('["+","SV-254238"]')) - expect(output.includes('["+","SV-254239"]')) - expect(output.includes('["+","SV-254240"]')) - expect(output.includes('["+","SV-254241"]')) - expect(output.includes('["+","SV-254242"]')) - }) + const output = stdout.split('\n') + expect(output.includes('Total Controls Found on Delta Directory: 5')) + expect(output.includes('Total Controls Found on XCCDF: 5')) + expect(output.includes('["+","SV-254238"]')) + expect(output.includes('["+","SV-254239"]')) + expect(output.includes('["+","SV-254240"]')) + expect(output.includes('["+","SV-254241"]')) + expect(output.includes('["+","SV-254242"]')) + }, 25000) }) diff --git a/test/commands/generate/inspec_profile.test.ts b/test/commands/generate/inspec_profile.test.ts index 2142693c4..7a22d188f 100644 --- a/test/commands/generate/inspec_profile.test.ts +++ b/test/commands/generate/inspec_profile.test.ts @@ -1,4 +1,5 @@ -import {expect, test} from '@oclif/test' +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -8,13 +9,11 @@ describe('Test inspec_profile (aliases:xccdf_benchmark2inspec)', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) fs.readdirSync('./test/sample_data/xccdf/stigs').forEach(file => { - test - .stdout() - .command(['generate inspec_profile', '-i', path.resolve('./test/sample_data/xccdf/stigs', file), '-o', `${tmpobj.name}/${file}`]) - .it(`Has the same number of controls in the stig as generated - ${file}`, () => { - const parsedXCCDF = processXCCDF(fs.readFileSync(path.resolve('./test/sample_data/xccdf/stigs', file), 'utf8'), false, 'rule') - const fileCount = fs.readdirSync(`${tmpobj.name}/${file}/controls/`).length - expect(fileCount).to.eql(parsedXCCDF.controls.length) - }) + it(`Has the same number of controls in the stig as generated - ${file}`, async () => { + await runCommand<{name: string}>(['generate inspec_profile', '-X', path.resolve('./test/sample_data/xccdf/stigs', file), '-o', `${tmpobj.name}/${file}`]) + const parsedXCCDF = processXCCDF(fs.readFileSync(path.resolve('./test/sample_data/xccdf/stigs', file), 'utf8'), false, 'rule') + const fileCount = fs.readdirSync(`${tmpobj.name}/${file}/controls/`).length + expect(fileCount).to.eql(parsedXCCDF.controls.length) + }) }) }) diff --git a/test/commands/generate/spreadsheet2inspec_stub.test.ts b/test/commands/generate/spreadsheet2inspec_stub.test.ts index d04a938be..8aeee2f85 100644 --- a/test/commands/generate/spreadsheet2inspec_stub.test.ts +++ b/test/commands/generate/spreadsheet2inspec_stub.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -6,11 +9,12 @@ import fs from 'fs' describe('Test spreadsheet2inspec_stub', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['generate spreadsheet2inspec_stub', '-i', path.resolve('./test/sample_data/csv/input/Ubuntu.csv'), '-o', `${tmpobj.name}/Ubuntu`, '--format', 'disa']) - .it('Has the same number of controls in the CSV as generated - Ubuntu', () => { - const fileCount = fs.readdirSync(`${tmpobj.name}/Ubuntu/controls/`).length - expect(fileCount).to.eql(194) - }) + it('Has the same number of controls in the CSV as generated - Ubuntu', async () => { + await runCommand<{name: string}>(['generate spreadsheet2inspec_stub', + '-i', path.resolve('./test/sample_data/csv/input/Ubuntu.csv'), + '-o', `${tmpobj.name}/Ubuntu`, '--format', 'disa', + ]) + const fileCount = fs.readdirSync(`${tmpobj.name}/Ubuntu/controls/`).length + expect(fileCount).to.eql(194) + }) }) diff --git a/test/commands/generate/threshold.test.ts b/test/commands/generate/threshold.test.ts index 4b9c817a5..395e21631 100644 --- a/test/commands/generate/threshold.test.ts +++ b/test/commands/generate/threshold.test.ts @@ -1,4 +1,5 @@ -import {expect, test} from '@oclif/test' +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -7,22 +8,18 @@ import YAML from 'yaml' describe('Generate threshold', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - test - .stdout() - .command(['generate threshold', '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), '-o', `${tmpobj.name}/red_hat_good.counts.good.yml`]) - .it('when provided an output file to store threshold', () => { - // Need to convert to linefeed (\n) otherwise the test will fail when executed in a Windows platform. - // The YAML.stringify will always include \n as the last character, as is expected of YAML documents. - const test = YAML.stringify(fs.readFileSync(`${tmpobj.name}/red_hat_good.counts.good.yml`, 'utf8').replaceAll(/\r\n/gi, '\n')) - const sample = YAML.stringify(fs.readFileSync(path.resolve('./test/sample_data/thresholds/red_hat_good.counts.good.yml'), 'utf8').replaceAll(/\r\n/gi, '\n')) - expect(test).to.eql(sample) - }) + it('when provided an output file to store threshold', async () => { + // Need to convert to linefeed (\n) otherwise the test will fail when executed in a Windows platform. + // The YAML.stringify will always include \n as the last character, as is expected of YAML documents. + await runCommand<{name: string}>(['generate threshold', '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json'), '-o', `${tmpobj.name}/red_hat_good.counts.good.yml`]) + const test = YAML.stringify(fs.readFileSync(`${tmpobj.name}/red_hat_good.counts.good.yml`, 'utf8').replaceAll(/\r\n/gi, '\n')) + const sample = YAML.stringify(fs.readFileSync(path.resolve('./test/sample_data/thresholds/red_hat_good.counts.good.yml'), 'utf8').replaceAll(/\r\n/gi, '\n')) + expect(test).to.eql(sample) + }) - test - .stdout() - .command(['generate threshold', '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json')]) - .it('when not provided an output file to store threshold', output => { - // Need to convert to linefeed (\n) otherwise the test will fail when executed in a Windows platform. - expect(output.stdout.replaceAll(/\r\n/gi, '\n')).to.contain(fs.readFileSync(path.resolve('./test/sample_data/thresholds/red_hat_good.counts.good.yml'), 'utf8').replaceAll(/\r\n/gi, '\n')) - }) + it('when not provided an output file to store threshold', async () => { + // Need to convert to linefeed (\n) otherwise the test will fail when executed in a Windows platform. + const {stdout} = await runCommand<{name: string}>(['generate threshold', '-i', path.resolve('./test/sample_data/HDF/input/red_hat_good.json')]) + expect(stdout.replaceAll(/\r\n/gi, '\n')).to.contain(fs.readFileSync(path.resolve('./test/sample_data/thresholds/red_hat_good.counts.good.yml'), 'utf8').replaceAll(/\r\n/gi, '\n')) + }) }) diff --git a/test/commands/supplement/passthrough.test.ts b/test/commands/supplement/passthrough.test.ts index 2e7a71a15..6342ff99c 100644 --- a/test/commands/supplement/passthrough.test.ts +++ b/test/commands/supplement/passthrough.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -6,51 +9,59 @@ import {omitHDFChangingFields} from '../utils' describe('Test supplement passthrough', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - fs.copyFileSync(path.resolve('./test/sample_data/HDF/input/minimal-hdf.json'), path.resolve(`${tmpobj.name}/minimal-hdf.json`)) - - test - .command(['supplement passthrough write', '-i', path.resolve('./test/sample_data/HDF/input/minimal-hdf.json'), '-f', path.resolve('./test/sample_data/passthrough/passthrough-object.json'), '-o', `${tmpobj.name}/minimal-hdf-passthrough-object.json`]) - .it('Successfully writes a passthrough json to an HDF and makes a new output file', () => { - const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/minimal-hdf-passthrough-object.json`, 'utf8')) - const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/passthrough/minimal-hdf-passthrough-object.json'), 'utf8')) - - expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) - }) - - test - .command(['supplement passthrough write', '-i', path.resolve(`${tmpobj.name}/minimal-hdf.json`), '-f', path.resolve('./test/sample_data/passthrough/passthrough-object.json')]) - .it('Successfully writes a passthrough json to an HDF inline', () => { - const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/minimal-hdf.json`, 'utf8')) - const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/passthrough/minimal-hdf-passthrough-object.json'), 'utf8')) - - expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) - }) - - test - .command(['supplement passthrough write', '-i', path.resolve('./test/sample_data/HDF/input/minimal-hdf.json'), '-d', 'test string', '-o', `${tmpobj.name}/minimal-hdf-passthrough-nonobject.json`]) - .it('Successfully writes passthrough data to an HDF and makes a new output file', () => { - const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/minimal-hdf-passthrough-nonobject.json`, 'utf8')) - const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/passthrough/minimal-hdf-passthrough-nonobject.json'), 'utf8')) - - expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) - }) - - test - .command(['supplement passthrough read', '-i', path.resolve('./test/sample_data/passthrough/minimal-hdf-passthrough-object.json'), '-o', `${tmpobj.name}/passthrough-object.json`]) - .it('Successfully reads passthrough data from an HDF and writes it to a file', () => { - const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/passthrough-object.json`, 'utf8')) - const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/passthrough/passthrough-object.json'), 'utf8')) - - expect(output).to.eql(expected) - }) - - test - .stdout() - .command(['supplement passthrough read', '-i', path.resolve('./test/sample_data/passthrough/minimal-hdf-passthrough-object.json')]) - .it('Successfully reads passthrough data from an HDF and writes it to stdout', ctx => { - const output = JSON.parse(ctx.stdout) - const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/passthrough/passthrough-object.json'), 'utf8')) - - expect(output).to.eql(expected) - }) + fs.copyFileSync(path.resolve('./test/sample_data/HDF/input/minimal_hdf.json'), path.resolve(`${tmpobj.name}/minimal_hdf.json`)) + + it('Successfully writes a passthrough json to an HDF and makes a new output file', async () => { + await runCommand<{name: string}>(['supplement passthrough write', + '-i', path.resolve('./test/sample_data/HDF/input/minimal_hdf.json'), + '-f', path.resolve('./test/sample_data/passthrough/passthrough-object.json'), + '-o', `${tmpobj.name}/minimal-hdf-passthrough-object.json`, + ]) + const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/minimal-hdf-passthrough-object.json`, 'utf8')) + const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/passthrough/minimal-hdf-passthrough-object.json'), 'utf8')) + + expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) + }) + + it('Successfully writes a passthrough json to an HDF inline', async () => { + await runCommand<{name: string}>(['supplement passthrough write', + '-i', path.resolve(`${tmpobj.name}/minimal_hdf.json`), + '-f', path.resolve('./test/sample_data/passthrough/passthrough-object.json'), + ]) + const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/minimal_hdf.json`, 'utf8')) + const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/passthrough/minimal-hdf-passthrough-object.json'), 'utf8')) + + expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) + }) + + it('Successfully writes passthrough data to an HDF and makes a new output file', async () => { + await runCommand<{name: string}>(['supplement passthrough write', + '-i', path.resolve('./test/sample_data/HDF/input/minimal_hdf.json'), + '-d', '"test string"', '-o', `${tmpobj.name}/minimal-hdf-passthrough-nonobject.json`, + ]) + const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/minimal-hdf-passthrough-nonobject.json`, 'utf8')) + const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/passthrough/minimal-hdf-passthrough-nonobject.json'), 'utf8')) + + expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) + }) + + it('Successfully reads passthrough data from an HDF and writes it to a file', async () => { + await runCommand<{name: string}>(['supplement passthrough read', + '-i', path.resolve('./test/sample_data/passthrough/minimal-hdf-passthrough-object.json'), + '-o', `${tmpobj.name}/passthrough-object.json`]) + const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/passthrough-object.json`, 'utf8')) + const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/passthrough/passthrough-object.json'), 'utf8')) + + expect(output).to.eql(expected) + }) + + it('Successfully reads passthrough data from an HDF and writes it to stdout', async () => { + const {stdout} = await runCommand<{name: string}>(['supplement passthrough read', + '-i', path.resolve('./test/sample_data/passthrough/minimal-hdf-passthrough-object.json'), + ]) + const output = JSON.parse(stdout) + const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/passthrough/passthrough-object.json'), 'utf8')) + + expect(output).to.eql(expected) + }) }) diff --git a/test/commands/supplement/target.test.ts b/test/commands/supplement/target.test.ts index 0e7308da5..d1a29cedd 100644 --- a/test/commands/supplement/target.test.ts +++ b/test/commands/supplement/target.test.ts @@ -1,4 +1,7 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-bracket-newline */ +/* eslint-disable array-element-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import tmp from 'tmp' import path from 'path' import fs from 'fs' @@ -6,51 +9,60 @@ import {omitHDFChangingFields} from '../utils' describe('Test supplement target', () => { const tmpobj = tmp.dirSync({unsafeCleanup: true}) - fs.copyFileSync(path.resolve('./test/sample_data/HDF/input/minimal-hdf.json'), path.resolve(`${tmpobj.name}/minimal-hdf.json`)) - - test - .command(['supplement target write', '-i', path.resolve('./test/sample_data/HDF/input/minimal-hdf.json'), '-f', path.resolve('./test/sample_data/target/target-object.json'), '-o', `${tmpobj.name}/minimal-hdf-target-object.json`]) - .it('Successfully writes a target json to an HDF and makes a new output file', () => { - const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/minimal-hdf-target-object.json`, 'utf8')) - const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/target/minimal-hdf-target-object.json'), 'utf8')) - - expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) - }) - - test - .command(['supplement target write', '-i', path.resolve(`${tmpobj.name}/minimal-hdf.json`), '-f', path.resolve('./test/sample_data/target/target-object.json')]) - .it('Successfully writes a target json to an HDF inline', () => { - const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/minimal-hdf.json`, 'utf8')) - const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/target/minimal-hdf-target-object.json'), 'utf8')) - - expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) - }) - - test - .command(['supplement target write', '-i', path.resolve('./test/sample_data/HDF/input/minimal-hdf.json'), '-d', 'test string', '-o', `${tmpobj.name}/minimal-hdf-target-nonobject.json`]) - .it('Successfully writes target data to an HDF and makes a new output file', () => { - const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/minimal-hdf-target-nonobject.json`, 'utf8')) - const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/target/minimal-hdf-target-nonobject.json'), 'utf8')) - - expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) - }) - - test - .command(['supplement target read', '-i', path.resolve('./test/sample_data/target/minimal-hdf-target-object.json'), '-o', `${tmpobj.name}/target-object.json`]) - .it('Successfully reads target data from an HDF and writes it to a file', () => { - const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/target-object.json`, 'utf8')) - const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/target/target-object.json'), 'utf8')) - - expect(output).to.eql(expected) - }) - - test - .stdout() - .command(['supplement target read', '-i', path.resolve('./test/sample_data/target/minimal-hdf-target-object.json')]) - .it('Successfully reads target data from an HDF and writes it to stdout', ctx => { - const output = JSON.parse(ctx.stdout) - const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/target/target-object.json'), 'utf8')) - - expect(output).to.eql(expected) - }) + fs.copyFileSync(path.resolve('./test/sample_data/HDF/input/minimal_hdf.json'), path.resolve(`${tmpobj.name}/minimal_hdf.json`)) + + it('Successfully writes a target json to an HDF and makes a new output file', async () => { + await runCommand<{name: string}>(['supplement target write', + '-i', path.resolve('./test/sample_data/HDF/input/minimal_hdf.json'), + '-f', path.resolve('./test/sample_data/target/target-object.json'), + '-o', `${tmpobj.name}/minimal-hdf-target-object.json`, + ]) + const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/minimal-hdf-target-object.json`, 'utf8')) + const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/target/minimal-hdf-target-object.json'), 'utf8')) + + expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) + }) + + it('Successfully writes a target json to an HDF inline', async () => { + await runCommand<{name: string}>(['supplement target write', + '-i', path.resolve(`${tmpobj.name}/minimal_hdf.json`), + '-f', path.resolve('./test/sample_data/target/target-object.json'), + ]) + const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/minimal_hdf.json`, 'utf8')) + const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/target/minimal-hdf-target-object.json'), 'utf8')) + + expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) + }) + + it('Successfully writes target data to an HDF and makes a new output file', async () => { + await runCommand<{name: string}>(['supplement target write', + '-i', path.resolve('./test/sample_data/HDF/input/minimal_hdf.json'), + '-d', '"test string"', '-o', `${tmpobj.name}/minimal-hdf-target-nonobject.json`, + ]) + const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/minimal-hdf-target-nonobject.json`, 'utf8')) + const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/target/minimal-hdf-target-nonobject.json'), 'utf8')) + + expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) + }) + + it('Successfully reads target data from an HDF and writes it to a file', async () => { + await runCommand<{name: string}>(['supplement target read', + '-i', path.resolve('./test/sample_data/target/minimal-hdf-target-object.json'), + '-o', `${tmpobj.name}/target-object.json`, + ]) + const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/target-object.json`, 'utf8')) + const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/target/target-object.json'), 'utf8')) + + expect(output).to.eql(expected) + }) + + it('Successfully reads target data from an HDF and writes it to stdout', async () => { + const {stdout} = await runCommand<{name: string}>(['supplement target read', + '-i', path.resolve('./test/sample_data/target/minimal-hdf-target-object.json'), + ]) + const output = JSON.parse(stdout) + const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/target/target-object.json'), 'utf8')) + + expect(output).to.eql(expected) + }) }) diff --git a/test/commands/utils.ts b/test/commands/utils.ts index 7ef224985..ffbb615e3 100644 --- a/test/commands/utils.ts +++ b/test/commands/utils.ts @@ -33,3 +33,18 @@ export function omitChecklistChangingFields(input: string) { return input.replaceAll(/[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}/gm, '') .replace(//, '') } + +export function removeUUIDs(obj: any) { + for (const key in obj) { + if (obj[key] && typeof obj[key] === 'object') { + removeUUIDs(obj[key]) + } else if (typeof obj[key] === 'string' && isUUID(obj[key])) { + delete obj[key] + } + } +} + +export function isUUID(str: string) { + const uuidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/ + return uuidRegex.test(str) +} diff --git a/test/commands/validate/threshold.test.ts b/test/commands/validate/threshold.test.ts index 4e015c748..cf7d83ade 100644 --- a/test/commands/validate/threshold.test.ts +++ b/test/commands/validate/threshold.test.ts @@ -1,130 +1,57 @@ -import {expect, test} from '@oclif/test' +/* eslint-disable array-element-newline */ +/* eslint-disable array-bracket-newline */ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import path from 'path' describe('Test validate threshold', () => { - test - .stdout() - .stderr() - .command([ - 'validate threshold', - '-i', - path.resolve( - './test/sample_data/HDF/input/triple_overlay_profile_example.json', - ), - '--templateFile', - path.resolve( - './test/sample_data/thresholds/triple_overlay_profile_example.json.counts.good.yml', - ), + it('Validate threshold test - Triple Overlay Valid Counts', async () => { + const {stdout, stderr} = await runCommand<{name: string}>(['validate threshold', + '-i', path.resolve('./test/sample_data/HDF/input/triple_overlay_profile_example.json'), + '--templateFile', path.resolve('./test/sample_data/thresholds/triple_overlay_profile_example.json.counts.good.yml'), ]) - .it('Validate threshold test - Triple Overlay Valid Counts', ctx => { - expect(ctx.stdout).to.equal('All validation tests passed\n') - expect(ctx.stderr).to.equal('') - }) + expect(stdout).to.equal('All validation tests passed\n') + expect(stderr).to.equal('') + }) - test - .stdout() - .stderr() - .command([ - 'validate threshold', - '-i', - path.resolve( - './test/sample_data/HDF/input/triple_overlay_profile_example.json', - ), - '--templateFile', - path.resolve( - './test/sample_data/thresholds/triple_overlay_profile_example.json.counts.bad.total.yml', - ), + it('Validate threshold test - Triple Overlay Invalid Total Counts', async () => { + const {stdout} = await runCommand<{name: string}>(['validate threshold', + '-i', path.resolve('./test/sample_data/HDF/input/triple_overlay_profile_example.json'), + '--templateFile', path.resolve('./test/sample_data/thresholds/triple_overlay_profile_example.json.counts.bad.total.yml'), ]) - .it('Validate threshold test - Triple Overlay Invalid Total Counts', - ctx => { - expect(ctx.stdout).to.equal('') - }, - ) + expect(stdout).to.equal('') + }) - test - .stdout() - .stderr() - .command([ - 'validate threshold', - '-i', - path.resolve( - './test/sample_data/HDF/input/triple_overlay_profile_example.json', - ), - '--templateFile', - path.resolve( - './test/sample_data/thresholds/triple_overlay_profile_example.json.counts.bad.compliance.yml', - ), + it('Validate threshold test - Triple Overlay Compliance', async () => { + const {stdout} = await runCommand<{name: string}>(['validate threshold', + '-i', path.resolve('./test/sample_data/HDF/input/triple_overlay_profile_example.json'), + '--templateFile', path.resolve('./test/sample_data/thresholds/triple_overlay_profile_example.json.counts.bad.compliance.yml'), ]) - // .catch(error => { - // expect(error.message).to.equal('Overall compliance minimum was not satisfied') - // }) - .it('Validate threshold test - Triple Overlay Compliance', - ctx => { - expect(ctx.stdout).to.equal('') - }, - ) + expect(stdout).to.equal('') + }) - test.stdout().stderr() - .command([ - 'validate threshold', - '-i', - path.resolve( - './test/sample_data/HDF/input/triple_overlay_profile_example.json', - ), - '--templateFile', - path.resolve( - './test/sample_data/thresholds/triple_overlay_profile_example.json.counts.totalMinMax.yml', - ), + it('Validate threshold minMaxTotal - Triple Overlay Compliance', async () => { + const {stdout} = await runCommand<{name: string}>(['validate threshold', + '-i', path.resolve('./test/sample_data/HDF/input/triple_overlay_profile_example.json'), + '--templateFile', path.resolve('./test/sample_data/thresholds/triple_overlay_profile_example.json.counts.totalMinMax.yml'), ]) - // .catch(error => { - // expect(error.message).to.equal('passed.total.max: Threshold not met. Number of received total passed controls (19) is greater than your set threshold for the number of passed controls (18)') - // }) - .it('Validate threshold minMaxTotal - Triple Overlay Compliance', - ctx => { - expect(ctx.stdout).to.equal('') - }, - ) + expect(stdout).to.equal('') + }) - test - .stdout() - .stderr() - .command([ - 'validate threshold', - '-i', - path.resolve( - './test/sample_data/HDF/input/rhel-8_hardened.json', - ), - '--templateFile', - path.resolve( - './test/sample_data/thresholds/rhel-8_hardened.counts.good.exact.yml', - ), + it('Validate threshold test - RHEL-8 Hardened Valid Exact Counts', async () => { + const {stdout, stderr} = await runCommand<{name: string}>(['validate threshold', + '-i', path.resolve('./test/sample_data/HDF/input/rhel-8_hardened.json'), + '--templateFile', path.resolve('./test/sample_data/thresholds/rhel-8_hardened.counts.good.exact.yml'), ]) - .it('Validate threshold test - RHEL-8 Hardened Valid Exact Counts', ctx => { - expect(ctx.stdout).to.equal('All validation tests passed\n') - expect(ctx.stderr).to.equal('') - }) + expect(stdout).to.equal('All validation tests passed\n') + expect(stderr).to.equal('') + }) - test - .stdout() - .stderr() - .command([ - 'validate threshold', - '-i', - path.resolve( - './test/sample_data/HDF/input/rhel-8_hardened.json', - ), - '--templateFile', - path.resolve( - './test/sample_data/thresholds/rhel-8_hardened.counts.bad.noimpactHigh.yml', - ), + it('Validate threshold test - RHEL-8 Hardened Invalid Total Counts', async () => { + const {stdout} = await runCommand<{name: string}>(['validate threshold', + '-i', path.resolve('./test/sample_data/HDF/input/rhel-8_hardened.json'), + '--templateFile', path.resolve('./test/sample_data/thresholds/rhel-8_hardened.counts.bad.noimpactHigh.yml'), ]) - // .catch(error => { - // expect(error.message).to.equal('no_impact.high.max: Threshold not met. Number of received total no_impact controls (3) is greater than your set threshold for the number of no_impact controls (2)') - // }) - .it( - 'Validate threshold test - RHEL-8 Hardened Invalid Total Counts', - ctx => { - expect(ctx.stdout).to.equal('') - }, - ) + expect(stdout).to.equal('') + }) }) diff --git a/test/commands/view/heimdall-view-cli.test.ts b/test/commands/view/heimdall-view-cli.test.ts new file mode 100644 index 000000000..33479e271 --- /dev/null +++ b/test/commands/view/heimdall-view-cli.test.ts @@ -0,0 +1,65 @@ +import {expect} from 'chai' +import {runCommand} from '@oclif/test' +import path from 'path' + +import axios from 'axios' +import express from 'express' +import {Server} from 'http' +import {getInstalledPath} from '../../../src/utils/global' +import {JSDOM} from 'jsdom' + +describe('Test heimdall SAF CLI Command', () => { + it('runs heimdall with --help', async () => { + const {stdout} = await runCommand<{name: string}>(['view', 'heimdall', '--help']) + expect(stdout).to.contain('Run an instance of Heimdall Lite to visualize your data') + }) +}) + +describe('Test Heimdall Embedded', () => { + let server: Server + + beforeEach(done => { + const installedPath = getInstalledPath('@mitre/saf') + const staticFilesDirectory = path.join(installedPath, 'node_modules/@mitre/heimdall-lite/dist') + const predefinedLoadJSON = express.json() // Replace this with your actual middleware + server = express() + .use(predefinedLoadJSON) + .use(express.static(staticFilesDirectory)) + .use((_err: any, _req: express.Request, res: express.Response, _next: express.NextFunction) => { + res.status(500).send('Something broke!') + }) + .listen(3000, () => { + done() + }) + }) + + afterEach(() => { + return new Promise(resolve => { + server.close(() => { + resolve() + }) + }) + }) + + it('should start the server on the specified port', async () => { + try { + const response = await axios.get('http://localhost:3000') + const dom = new JSDOM(response.data) + const text = dom.window.document.body.textContent + expect(text).to.not.be.null + } catch (error: any) { + expect(error.message).to.equal('Request failed with status code 404') + } + }) + + it('should serve the Vue.js app', async () => { + try { + const response = await axios.get('http://localhost:3000') + const dom = new JSDOM(response.data) + const appDiv = dom.window.document.querySelector('#app') + expect(appDiv).to.not.be.null + } catch (error: any) { + expect(error.message).to.equal('Request failed with status code 404') + } + }) +}) diff --git a/test/commands/view/summary.test.ts b/test/commands/view/summary.test.ts index 701bffd94..3df07926c 100644 --- a/test/commands/view/summary.test.ts +++ b/test/commands/view/summary.test.ts @@ -1,4 +1,5 @@ -import {expect, test} from '@oclif/test' +import {expect} from 'chai' +import {runCommand} from '@oclif/test' import fs from 'fs' import path from 'path' import yaml from 'js-yaml' @@ -11,64 +12,50 @@ describe('Summary command', () => { const generatedMD = 'generatedMD.md' const UTF8_ENCODING = 'utf8' - test - .stdout() - .command(['summary', '-i', hdfFilePath, '--format=json']) - .it('runs summary with JSON output and matches the JSON reference file', ctx => { - const expectedOutput = JSON.parse(fs.readFileSync(JSON_reference, UTF8_ENCODING)) - expect(JSON.parse(ctx.stdout)).to.deep.equal(expectedOutput) - }) + it('runs summary with JSON output and matches the JSON reference file', async () => { + const {stdout} = await runCommand<{name: string}>(['summary', '-i', hdfFilePath, '--format=json']) + const expectedOutput = JSON.parse(fs.readFileSync(JSON_reference, UTF8_ENCODING)) + expect(JSON.parse(stdout)).to.deep.equal(expectedOutput) + }) // NOTE: replacing the CR from both files to ensure proper comparison. - test - .stdout() - .command(['summary', '-i', hdfFilePath, '--format=markdown', '--no-title-table', '-o', generatedMD]) - .it('runs summary with Markdown output and matches the markdown reference file', () => { - const expectedOutput = fs.readFileSync(MD_reference, 'utf8').replaceAll(/\r/gi, '').trim() - const actualOutput = fs.readFileSync(generatedMD, 'utf8').replaceAll(/\r/gi, '').trim() - expect(actualOutput).to.equal(expectedOutput) - }) - - test - .stdout() - .command(['summary', '-i', hdfFilePath, '--format=yaml']) - .it('runs summary with YAML output and matches the YAML reference file', ctx => { - const expectedOutputYaml = fs.readFileSync(YAML_reference, UTF8_ENCODING) - const expectedOutput = yaml.load(expectedOutputYaml) - const actualOutput = yaml.load(ctx.stdout) - expect(actualOutput).to.deep.equal(expectedOutput) - }) - - test - .stdout() - .command(['summary', '-i', hdfFilePath, '--format=json', '--no-print-pretty']) - .it('runs summary with --no-pretty flag and produces flat JSON output', ctx => { - const actualOutput = JSON.parse(ctx.stdout) - const flatOutput = JSON.parse(JSON.stringify(actualOutput)) - expect(actualOutput).to.deep.equal(flatOutput) - }) - - test - .stdout() - .command(['summary', '-i', hdfFilePath, '--format=json', '--print-pretty']) - .it('runs summary with --pretty flag and produces formatted JSON output', ctx => { - const actualOutput = JSON.parse(ctx.stdout) - const prettyOutput = JSON.parse(JSON.stringify(actualOutput, null, 2)) - expect(actualOutput).to.deep.equal(prettyOutput) - }) - - test - .stdout() - .command(['summary', '-i', hdfFilePath, '--format=json', '--stdout']) - .it('runs summary with --stdout flag and prints output to console', ctx => { - const actualOutput = JSON.parse(ctx.stdout) - expect(actualOutput).to.not.be.empty.equal(true) - }) - - test - .stdout() - .command(['summary', '-i', hdfFilePath, '--format=json', '--no-stdout']) - .it('runs summary with no-stdout flag and does not write to stdout', ctx => { - expect(ctx.stdout).to.be.empty.equal('') - }) + it('runs summary with Markdown output and matches the markdown reference file', async () => { + await runCommand<{name: string}>(['summary', '-i', hdfFilePath, '--format=markdown', '--no-title-table', '-o', generatedMD]) + const expectedOutput = fs.readFileSync(MD_reference, 'utf8').replaceAll(/\r/gi, '').trim() + const actualOutput = fs.readFileSync(generatedMD, 'utf8').replaceAll(/\r/gi, '').trim() + expect(actualOutput).to.equal(expectedOutput) + }) + + it('runs summary with YAML output and matches the YAML reference file', async () => { + const {stdout} = await runCommand<{name: string}>(['summary', '-i', hdfFilePath, '--format=yaml']) + const expectedOutputYaml = fs.readFileSync(YAML_reference, UTF8_ENCODING) + const expectedOutput = yaml.load(expectedOutputYaml) + const actualOutput = yaml.load(stdout) + expect(actualOutput).to.deep.equal(expectedOutput) + }) + + it('runs summary with --no-pretty flag and produces flat JSON output', async () => { + const {stdout} = await runCommand<{name: string}>(['summary', '-i', hdfFilePath, '--format=json', '--no-print-pretty']) + const actualOutput = JSON.parse(stdout) + const flatOutput = structuredClone(actualOutput) + expect(actualOutput).to.deep.equal(flatOutput) + }) + + it('runs summary with --pretty flag and produces formatted JSON output', async () => { + const {stdout} = await runCommand<{name: string}>(['summary', '-i', hdfFilePath, '--format=json', '--print-pretty']) + const actualOutput = JSON.parse(stdout) + const prettyOutput = JSON.parse(JSON.stringify(actualOutput, null, 2)) + expect(actualOutput).to.deep.equal(prettyOutput) + }) + + it('runs summary with --stdout flag and prints output to console', async () => { + const {stdout} = await runCommand<{name: string}>(['summary', '-i', hdfFilePath, '--format=json', '--stdout']) + const actualOutput = JSON.parse(stdout) + expect(actualOutput).to.not.be.empty.equal(true) + }) + + it('runs summary with no-stdout flag and does not write to stdout', async () => { + const {stdout} = await runCommand<{name: string}>(['summary', '-i', hdfFilePath, '--format=json', '--no-stdout']) + expect(stdout).to.be.empty.equal('') + }) }) diff --git a/test/sample_data/HDF/input/minimal_hdf.json b/test/sample_data/HDF/input/minimal_hdf.json new file mode 100644 index 000000000..2c2cbb083 --- /dev/null +++ b/test/sample_data/HDF/input/minimal_hdf.json @@ -0,0 +1,69 @@ +{ + "platform": { + "name": "mac_os_x", + "release": "20.6.0", + "target_id": "af9cc1ad-9583-5403-8a69-79a34daa9792" + }, + "profiles": [ + { + "name": "test_inspec_profile", + "version": "0.1.0", + "sha256": "5b6b2189b26425192a9eb4ae99ba52403c054e7a5f0a61f847d773a3444b8546", + "title": "InSpec Profile", + "maintainer": "The Authors", + "summary": "An InSpec Compliance Profile", + "license": "Apache-2.0", + "copyright": "The Authors", + "copyright_email": "you@example.com", + "supports": [ + { + "platform": "os" + } + ], + "attributes": [], + "groups": [ + { + "id": "controls/test1.rb", + "controls": [ + "test" + ] + } + ], + "controls": [ + { + "id": "test", + "title": "Returns a fail", + "desc": null, + "descriptions": [], + "impact": 0.7, + "refs": [], + "tags": {}, + "code": "control \"test\" do\n impact 0.7\n title \"Returns a fail\"\n describe true do\n it { should be false }\n end\nend\n", + "source_location": { + "line": 1, + "ref": "./controls/test1.rb" + }, + "waiver_data": {}, + "results": [ + { + "status": "failed", + "code_desc": "true is expected to equal false", + "run_time": 0.026805, + "start_time": "2022-09-27T21:58:28-04:00", + "message": "\nexpected false\n got true\n", + "resource_class": "Object", + "resource_params": "[]", + "resource_id": "" + } + ] + } + ], + "status": "loaded", + "status_message": "" + } + ], + "statistics": { + "duration": 0.032271 + }, + "version": "5.18.14" +} diff --git a/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93205.rb b/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93205.rb index 6ffd24acc..a30d85dfc 100644 --- a/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93205.rb +++ b/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93205.rb @@ -1,6 +1,6 @@ # encoding: UTF-8 -control 'V-254240' do +control 'SV-254240' do title "Windows Server 2019 administrative accounts must not be used with applications that access the Internet, such as web browsers, or with potential Internet sources, such as email." diff --git a/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93207.rb b/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93207.rb index 358c6ab71..dab1cad4e 100644 --- a/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93207.rb +++ b/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93207.rb @@ -1,6 +1,6 @@ # encoding: UTF-8 -control 'V-254241' do +control 'SV-254241' do title "Windows Server 2019 members of the Backup Operators group must have separate accounts for backup duties and normal operational tasks." desc "Backup Operators are able to read and write to any file in the system, diff --git a/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93369.rb b/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93369.rb index 89ed7ca03..c4e66a529 100644 --- a/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93369.rb +++ b/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93369.rb @@ -1,6 +1,6 @@ # encoding: UTF-8 -control 'V-254238' do +control 'SV-254238' do title "Windows Server 2019 users with Administrative privileges must have separate accounts for administrative duties and normal operational tasks." desc "Using a privileged account to perform routine functions makes the computer vulnerable to malicious software inadvertently introduced during a session that has been granted full privileges." desc "rationale", "" diff --git a/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93461.rb b/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93461.rb index fe5b32b1a..99da4cb57 100644 --- a/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93461.rb +++ b/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93461.rb @@ -1,6 +1,6 @@ # encoding: UTF-8 -control 'V-254242' do +control 'SV-254242' do title "Windows Server 2019 manually managed application account passwords must be at least #{input('minimum_password_length_manual')} characters in length." desc "Application/service account passwords must be of sufficient length to prevent being easily cracked. Application/service accounts that are manually managed must have passwords at least #{input('minimum_password_length_manual')} characters in length." desc "rationale", "" diff --git a/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93473.rb b/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93473.rb index 0b98b8426..7e817ccc0 100644 --- a/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93473.rb +++ b/test/sample_data/inspec/json/profile_and_controls/mapped_controls/V-93473.rb @@ -1,6 +1,6 @@ # encoding: UTF-8 -control 'V-254239' do +control 'SV-254239' do title "Windows Server 2019 passwords for the built-in Administrator account must be changed at least every 60 days." desc "The longer a password is in use, the greater the opportunity for someone to gain unauthorized knowledge of the password. The built-in Administrator account is not generally used and its password not may be changed as frequently as necessary. Changing the password for the built-in Administrator account on a regular basis will limit its exposure. Organizations that use an automated tool, such Microsoft's Local Administrator Password Solution (LAPS), on domain-joined systems can configure this to occur more frequently. LAPS will change the password every \"30\" days by default." diff --git a/test/utils/__tests__/global.test.ts b/test/utils/__tests__/global.test.ts new file mode 100644 index 000000000..5bb908591 --- /dev/null +++ b/test/utils/__tests__/global.test.ts @@ -0,0 +1,381 @@ +import { + checkSuffix, + getProfileInfo, + extractValueViaPathOrNumber, + convertFullPathToFilename, + dataURLtoU8Array, + getDescription, arrayNeededPaths, +} from '../../../src/utils/global' +import {ExecJSON, ContextualizedEvaluation} from 'inspecjs' +import path from 'path' +import fs from 'fs' + +const UTF8_ENCODING = 'utf8' + +const test_files_path = './test/sample_data/HDF/input' + +const fileNames = [ + 'rhel-8_hardened.json', + 'triple_overlay_profile_example.json', + 'minimal_hdf.json', +] + +const filePaths = fileNames.map(fileName => path.resolve(path.join(test_files_path, fileName))) + +const [rhel8_hardened, triple_overlay_profile_example, minimal_hdf] = filePaths + +function loadExpectedData(samplePath: string): ContextualizedEvaluation { + const resolvedPath = path.resolve(samplePath) + return JSON.parse(fs.readFileSync(resolvedPath, UTF8_ENCODING)) +} + +describe('checkSuffix', () => { + it('should append .json if it is not present', () => { + const result = checkSuffix('test') + expect(result).toBe('test.json') + }) + + it('should not append .json if it is already present', () => { + const result = checkSuffix('test.json') + expect(result).toBe('test.json') + }) +}) + +describe('convertFullPathToFilename', () => { + it('should return the filename from a full path (non windows)', () => { + const result = convertFullPathToFilename('/path/to/file.txt') + expect(result).toBe('file.txt') + }) + + it('should return the last directory name if the path ends with a forward slash (non windows)', () => { + const result = convertFullPathToFilename('/path/to/') + expect(result).toBe('to') + }) + + it('should handle paths with no slashes', () => { + const result = convertFullPathToFilename('file.txt') + expect(result).toBe('file.txt') + }) + + it('should return the filename from a full path (windows)', () => { + const result = convertFullPathToFilename('\\path\\to\\file.txt\\') + expect(result).toBe('file.txt') + }) + + it('should return the last directory name if the path ends with a backslash\'s (windows)', () => { + const result = convertFullPathToFilename('\\path\\to\\') + expect(result).toBe('to') + }) +}) + +describe('dataURLtoU8Array', () => { + it('should convert a data URL to a Uint8Array', () => { + const dataURL = 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==' // "Hello, World!" in base64 + const expectedOutput = new Uint8Array([72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33]) // "Hello, World!" in ASCII + + const result = dataURLtoU8Array(dataURL) + expect(result).toEqual(expectedOutput) + }) +}) + +describe('getDescription', () => { + it('should return the description associated with a given key from an object', () => { + const descriptions = { + check: 'This is a check description', + fix: 'This is a fix description', + } + const key = 'check' + const expectedOutput = 'This is a check description' + + const result = getDescription(descriptions, key) + expect(result).toEqual(expectedOutput) + }) + + it('should return "no description was labeled with: key" if the key is not found in the descriptions object', () => { + const descriptions = { + check: 'This is a check description', + fix: 'This is a fix description', + } + const key = 'nonexistent' + const result = getDescription(descriptions, key) + expect(result).toEqual(undefined) + }) + + it('should return the description associated with a given key from an array', () => { + const descriptions: ExecJSON.ControlDescription[] = [ + {label: 'check', data: 'This is a check description'}, + {label: 'fix', data: 'This is a fix description'}, + ] + const key = 'check' + const expectedOutput = 'This is a check description' + + const result = getDescription(descriptions, key) + expect(result).toEqual(expectedOutput) + }) + + it('should return "description for key not found" if the key is not found in the descriptions array', () => { + const descriptions: ExecJSON.ControlDescription[] = [ + {label: 'check', data: 'This is a check description'}, + {label: 'fix', data: 'This is a fix description'}, + ] + const key = 'nonexistent' + const result = getDescription(descriptions, key) + expect(result).toEqual(undefined) + }) +}) + +describe('getInstalledPath', () => { + beforeEach(() => { + jest.resetModules() + }) + + it('should return the installed path when the module is installed', () => { + jest.doMock('get-installed-path', () => ({ + getInstalledPathSync: jest.fn().mockReturnValue('/generic/module/path'), + })) + jest.doMock('app-root-path', () => ({ + path: '/generic/app/root/path', + })) + + // eslint-disable-next-line node/no-missing-require, unicorn/prefer-module + const {getInstalledPath} = require('../../../src/utils/global') + // eslint-disable-next-line unicorn/prefer-module + const {getInstalledPathSync} = require('get-installed-path') + + const result = getInstalledPath('module-name') + + expect(result).toBe('/generic/module/path') + expect(getInstalledPathSync).toHaveBeenCalledWith('module-name') + }) + + it('should return the application root path when the module is not installed', () => { + jest.doMock('get-installed-path', () => ({ + getInstalledPathSync: jest.fn().mockImplementation(() => { + throw new Error('Module not found') + }), + })) + jest.doMock('app-root-path', () => ({ + path: '/generic/app/root/path', + })) + + // eslint-disable-next-line node/no-missing-require, unicorn/prefer-module + const {getInstalledPath} = require('../../../src/utils/global') + // eslint-disable-next-line unicorn/prefer-module + const {getInstalledPathSync} = require('get-installed-path') + + const result = getInstalledPath('module-name') + + expect(result).toBe('/generic/app/root/path') + expect(getInstalledPathSync).toHaveBeenCalledWith('module-name') + }) +}) + +describe('arrayNeededPaths', () => { + it('should return values as an array if typeOfPath is in arrayedPaths and values is not an array', () => { + const typeOfPath = 'tags.cci' + const values = 'test' + const expectedOutput = ['test'] + + const result = arrayNeededPaths(typeOfPath, values) + expect(result).toEqual(expectedOutput) + }) + + it('should return values as is if typeOfPath is in arrayedPaths and values is an array', () => { + const typeOfPath = 'tags.cci' + const values = ['test'] + const expectedOutput = ['test'] + + const result = arrayNeededPaths(typeOfPath, values) + expect(result).toEqual(expectedOutput) + }) +}) + +describe('extractValueViaPathOrNumber', () => { + const data = { + 'tags.cci': 'test1', + 'tags.nist': 'test2', + 'Field Not Defined': 'test3', + other: 'test4', + } + + it('should return value from data if pathOrNumber is a string', () => { + const typeOfPathOrNumber = 'tags.cci' + const pathOrNumber = 'tags.cci' + const expectedOutput = ['test1'] + + const result = extractValueViaPathOrNumber(typeOfPathOrNumber, pathOrNumber, data) + expect(result).toEqual(expectedOutput) + }) + + it('should return value from data if pathOrNumber is an array', () => { + const typeOfPathOrNumber = 'tags.nist' + const pathOrNumber = ['tags.nist', 'other'] + const expectedOutput = ['test2'] + + const result = extractValueViaPathOrNumber(typeOfPathOrNumber, pathOrNumber, data) + expect(result).toEqual(expectedOutput) + }) + + it('should return "Field Not Defined" if pathOrNumber is an array and no path is found in data', () => { + const typeOfPathOrNumber = 'Field Not Defined' + const pathOrNumber = ['nonexistent1', 'nonexistent2'] + const expectedOutput = 'test3' + + const result = extractValueViaPathOrNumber(typeOfPathOrNumber, pathOrNumber, data) + expect(result).toEqual(expectedOutput) + }) + + it('should return pathOrNumber as is if pathOrNumber is a number', () => { + const typeOfPathOrNumber = 'number' + const pathOrNumber = 123 + const expectedOutput = 123 + + const result = extractValueViaPathOrNumber(typeOfPathOrNumber, pathOrNumber, data) + expect(result).toEqual(expectedOutput) + }) +}) + +describe('getProfileInfo', () => { + it('should return all profile information if available for rhel8_hardened', () => { + const evaluation: ContextualizedEvaluation = loadExpectedData(rhel8_hardened) + const fileName = 'rhel-8_hardened.json' + const expectedOutput = + 'File Name: rhel-8_hardened.json\n' + + 'Version: 1.12.0\n' + + 'SHA256 Hash: 7f77220de1c9d7f701dc4fbb3d0a9b2c0389c216e8d53585eec0031ecf6ed36e\n' + + 'Maintainer: MITRE SAF Team\n' + + 'Copyright: MITRE\n' + + 'Control Count: 375' + + const result = getProfileInfo(evaluation, fileName) + expect(result).toEqual(expectedOutput) + }) + + it('should return all profile information if available for triple_overlay_profile_example', () => { + const evaluation: ContextualizedEvaluation = loadExpectedData(triple_overlay_profile_example) + const fileName = 'triple_overlay_profile_example.json' + const expectedOutput = + 'File Name: triple_overlay_profile_example.json\n' + + 'Version: 0.1.0\n' + + 'SHA256 Hash: 3fe40f9476a23b5b4dd6c0da2bb8dbe8ca5a4a8b6bfb27ffbf9f1797160c0f91\n' + + 'Maintainer: CMS InSpec Dev Team\n' + + 'Copyright: .\n' + + 'Control Count: 200' + + const result = getProfileInfo(evaluation, fileName) + expect(result).toEqual(expectedOutput) + }) + + it('should return all profile information if available for minimal_hdf', () => { + const evaluation: ContextualizedEvaluation = loadExpectedData(minimal_hdf) + const fileName = 'minimal_hdf.json' + const expectedOutput = + 'File Name: minimal_hdf.json\n' + + 'Version: 0.1.0\n' + + 'SHA256 Hash: 5b6b2189b26425192a9eb4ae99ba52403c054e7a5f0a61f847d773a3444b8546\n' + + 'Maintainer: The Authors\n' + + 'Copyright: The Authors\n' + + 'Copyright Email: you@example.com\n' + + 'Control Count: 1' + + const result = getProfileInfo(evaluation, fileName) + expect(result).toEqual(expectedOutput) + }) +}) + +describe('testProfileEvaluation', () => { + it('should return an empty string if no profile information is available', () => { + const evaluation = { + data: { + profiles: [{}], + }, + } as unknown as ContextualizedEvaluation + const fileName = 'test.json' + const expectedOutput = '' + + const result = getProfileInfo(evaluation, fileName) + + expect(result).toEqual(expectedOutput) + }) + + it('should return an empty string if the evaluation data is null or undefined', () => { + const evaluation = null as unknown as ContextualizedEvaluation + const fileName = 'test.json' + const expectedOutput = '' + + const result = getProfileInfo(evaluation, fileName) + + expect(result).toEqual(expectedOutput) + }) +}) + +describe('getDescription', () => { + it('should return the correct description when descriptions is an array', () => { + const descriptions = [{label: 'key1', data: 'description1'}, {label: 'key2', data: 'description2'}] + const key = 'key1' + const result = getDescription(descriptions, key) + expect(result).toBe('description1') + }) + + it('should return the correct description when descriptions is an object', () => { + const descriptions = {key1: 'description1', key2: 'description2'} + const key = 'key1' + const result = getDescription(descriptions, key) + expect(result).toBe('description1') + }) +}) + +jest.mock('@mitre/hdf-converters', () => ({ + fingerprint: jest.fn(), +})) + +describe('checkInput', () => { + beforeEach(() => { + jest.resetModules() + }) + + it('should not throw an error when the detected type matches the desired type', () => { + // eslint-disable-next-line unicorn/prefer-module + const {fingerprint} = require('@mitre/hdf-converters') + fingerprint.mockReturnValue('text') + + // eslint-disable-next-line node/no-missing-require, unicorn/prefer-module + const {checkInput} = require('../../../src/utils/global') + + const guessOptions = {data: 'file data', filename: 'file.txt'} + const desiredType = 'text' + const desiredFormat = 'txt' + + expect(() => checkInput(guessOptions, desiredType, desiredFormat)).not.toThrow() + }) + + it('should throw an error when the detected type does not match the desired type', () => { + // eslint-disable-next-line unicorn/prefer-module + const {fingerprint} = require('@mitre/hdf-converters') + fingerprint.mockReturnValue('image') + + // eslint-disable-next-line node/no-missing-require, unicorn/prefer-module + const {checkInput} = require('../../../src/utils/global') + + const guessOptions = {data: 'file data', filename: 'file.txt'} + const desiredType = 'text' + const desiredFormat = 'txt' + + expect(() => checkInput(guessOptions, desiredType, desiredFormat)).toThrow() + }) + + it('should throw an error when the detected type is unknown', () => { + // eslint-disable-next-line unicorn/prefer-module + const {fingerprint} = require('@mitre/hdf-converters') + fingerprint.mockReturnValue(null) + + // eslint-disable-next-line node/no-missing-require, unicorn/prefer-module + const {checkInput} = require('../../../src/utils/global') + + const guessOptions = {data: 'file data', filename: 'file.txt'} + const desiredType = 'text' + const desiredFormat = 'txt' + + expect(() => checkInput(guessOptions, desiredType, desiredFormat)).toThrow() + }) +}) diff --git a/test/utils/__tests__/logging.test.ts b/test/utils/__tests__/logging.test.ts new file mode 100644 index 000000000..0a115f165 --- /dev/null +++ b/test/utils/__tests__/logging.test.ts @@ -0,0 +1,41 @@ +import {createWinstonLogger} from '../../../src/utils/logging' + +jest.mock('winston', () => { + const mFormat = { + combine: jest.fn(), + timestamp: jest.fn(), + printf: jest.fn(), + } + const mTransports = { + File: jest.fn(), + Console: jest.fn(), + } + return { + createLogger: jest.fn().mockReturnValue({ + format: mFormat, + transports: [new mTransports.File(), new mTransports.Console()], + }), + format: mFormat, + transports: mTransports, + } +}) + +describe('createWinstonLogger', () => { + it('should create a logger with the correct configuration', () => { + // eslint-disable-next-line unicorn/prefer-module + const winston = require('winston') + createWinstonLogger('testMapper', 'info') + + expect(winston.createLogger).toHaveBeenCalledWith({ + format: winston.format.combine( + winston.format.timestamp({format: 'YYYY-MM-DD HH:mm:ss'}), + winston.format.printf(expect.any(Function)), + ), + level: 'info', + transports: expect.arrayContaining([ + new winston.transports.File({filename: 'testMapper.log'}), + new winston.transports.Console(), + ]), + }) + }) +}) diff --git a/test/utils/ohdf/__tests__/outputGenerator.test.ts b/test/utils/ohdf/__tests__/outputGenerator.test.ts index 5e608d964..5b1ada1ef 100644 --- a/test/utils/ohdf/__tests__/outputGenerator.test.ts +++ b/test/utils/ohdf/__tests__/outputGenerator.test.ts @@ -106,6 +106,7 @@ describe('generateMarkdownTable', () => { }) } }) + it(`columns are in the expected order: ${expectedColumnOrder}`, () => { const result = generateMarkdownTable(item, titleTables) const tokens = marked.lexer(result) @@ -128,6 +129,7 @@ describe('generateMarkdownTable', () => { }) } }) + it(`each column matches a column in ${expectedColumnOrder}`, () => { const result = generateMarkdownTable(item, titleTables) const tokens = marked.lexer(result) diff --git a/test/utils/ohdf/dataloader.test.ts b/test/utils/ohdf/dataloader.test.ts index d63916de2..cfec076fb 100644 --- a/test/utils/ohdf/dataloader.test.ts +++ b/test/utils/ohdf/dataloader.test.ts @@ -8,7 +8,7 @@ describe('dataLoader.ts utils', () => { let evaluation: ContextualizedEvaluation let result: { [key: string]: ContextualizedEvaluation } - before(() => { + beforeEach(() => { // Arrange hdfFilePath = path.resolve('./test/sample_data/HDF/input/rhel-8_hardened.json')