From 3c4c3c061fd5fa4410bbe31a8a8c6d1c5e68dae8 Mon Sep 17 00:00:00 2001 From: DannyDainton <danny@getpostman.com> Date: Sun, 23 Aug 2020 10:05:15 +0100 Subject: [PATCH] Added a new `hideRequestBody` flag to allow you _hide_ a specific request body from the final report --- CHANGELOG.md | 12 +++++++ README.md | 14 ++++---- lib/dashboard-template.hbs | 26 ++++++++++++-- lib/index.js | 8 +++-- lib/only-failures-dashboard.hbs | 64 ++++++++++++++++++++++----------- package-lock.json | 39 ++++++++++---------- package.json | 4 +-- test/integration/cli.test.js | 2 +- 8 files changed, 115 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24e7b45..8637b46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ----------------------------------------------------------------------- +## [1.19.0] - 2020-08-23 + +### Added + +- Added a new `hideRequestBody` flag to allow you _hide_ a specific request body from the final report + +### Changed + +- Changed the `hideResponse` flag to `hideResponseBody` to make it more descriptive + +----------------------------------------------------------------------- + ## [1.18.0] - 2020-08-19 ### Fixed diff --git a/README.md b/README.md index d9cd8fb..44ccf44 100644 --- a/README.md +++ b/README.md @@ -50,10 +50,10 @@ To use `htmlextra` as a library, install the package as a dependency into a `nod npm install -S newman-reporter-htmlextra ``` -To install `nodejs`, `newman` and the `htmlextra` packages together, use this command (adding your own collection file) to run it using the `Docker` image: +To install `node`, `newman` and the `htmlextra` packages together, use this command to pull the `Docker` image: ```console -docker run -t -v $(pwd):/etc/newman dannydainton/htmlextra run collection.json -r htmlextra +docker pull dannydainton/htmlextra ``` --- @@ -80,7 +80,8 @@ newman run collection.json -r htmlextra | `--reporter-htmlextra-title` | This optional flag can be used to give your report a different main `Title` in the centre of the report. If this is not set, the report will show "Newman Run Dashboard". | `newman run collection.json -r htmlextra --reporter-htmlextra-title "My Newman Report"`| | `--reporter-htmlextra-titleSize` | An optional flag to reduce the size of the main report title. The sizes range from `1` to `6`, the higher the number, the smaller the title will be. The default size is `2`. | `newman run collection.json -r htmlextra --reporter-htmlextra-titleSize 4`| | `--reporter-htmlextra-logs` | This optional flag shows any console log statements in the collection, on the final report. This is `false` by default. | `newman run collection.json -r htmlextra --reporter-htmlextra-logs`| -| `--reporter-htmlextra-hideResponse` | An optional flag which allows you to exclude certain `Response Bodies` from the final report. Enter the name of the request that you wish to hide. | `newman run collection.json -r htmlextra --reporter-htmlextra-hideResponse "Auth Request"`| +| `--reporter-htmlextra-hideRequestBody` | An optional flag which allows you to exclude certain `Request Bodies` from the final report. Enter the name of the request that you wish to hide. | `newman run collection.json -r htmlextra --reporter-htmlextra-hideRequestBody "Login"`| +| `--reporter-htmlextra-hideResponseBody` | An optional flag which allows you to exclude certain `Response Bodies` from the final report. Enter the name of the request that you wish to hide. | `newman run collection.json -r htmlextra --reporter-htmlextra-hideResponse "Auth Request"`| | `--reporter-htmlextra-showEnvironmentData` | An optional flag which allows you to show all the `Environment` variables used during the run, in the final report | `newman run collection.json -r htmlextra --reporter-htmlextra-showEnvironmentData`| | `--reporter-htmlextra-skipEnvironmentVars` | An optional flag which allows you to exclude certain `Environment` variables from the final report | `newman run collection.json -r htmlextra --reporter-htmlextra-skipEnvironmentVars "API_KEY"`| | `--reporter-htmlextra-showGlobalData` | An optional flag which allows you to show all the `Global` variables used during the run, in the final report | `newman run collection.json -r htmlextra --reporter-htmlextra-showGlobalData`| @@ -93,8 +94,6 @@ newman run collection.json -r htmlextra | `--reporter-htmlextra-showFolderDescription` | An optional flag which allows you to show all the folder descriptions, in the final report | `newman run collection.json -r htmlextra --reporter-htmlextra-showFolderDescription`| | `--reporter-htmlextra-timezone` | An optional flag which allows you to set the timezone on the final report's timestamp | `newman run collection.json -r htmlextra --reporter-htmlextra-timezone "Australia/Sydney"`| -Custom templates can be passed to the `htmlextra` reporter via the `--reporter-htmlextra-template <path>` flag. The [default template](./lib/dashboard-template.hbs) is used in all other cases. - --- #### With Newman as a Library @@ -118,7 +117,7 @@ To enable the functionality of a given feature, uncomment any of the options wit const newman = require('newman'); newman.run({ - collection: './pathToFile/collection.json', + collection: './pathToFile/collection.json', // Collection URL from a public link or the Postman API can also be used reporters: ['htmlextra'], iterationCount: 1, reporter: { @@ -134,7 +133,8 @@ newman.run({ // titleSize: 4, // omitHeaders: true, // skipHeaders: "Authorization", - // hideResponse: ["Auth Request"], + // hideRequestBody: ["Login"], + // hideResponseBody: ["Auth Request"], // showEnvironmentData: true, // skipEnvironmentVars: ["API_KEY"], // showGlobalData: true, diff --git a/lib/dashboard-template.hbs b/lib/dashboard-template.hbs index b58850e..15aaf6b 100644 --- a/lib/dashboard-template.hbs +++ b/lib/dashboard-template.hbs @@ -925,7 +925,10 @@ table.dataTable td, table.dataTable tr { </div> {{/unless}} {{/unless}} + {{/with}} {{#unless @root.skipSensitiveData}} + {{#isNotIn item.name @root.hideRequestBody}} + {{#with request}} {{#if body.raw}} <div class="row"> <div class="col-sm-12 mb-3"> @@ -945,6 +948,12 @@ table.dataTable td, table.dataTable tr { </div> </div> {{/if}} + {{/with}} + {{/isNotIn}} + {{/unless}} + {{#unless @root.skipSensitiveData}} + {{#isNotIn item.name @root.hideRequestBody}} + {{#with request}} {{#if body.formdata.members}} <div class="row"> <div class="col-sm-12 mb-3"> @@ -964,6 +973,12 @@ table.dataTable td, table.dataTable tr { </div> </div> {{/if}} + {{/with}} + {{/isNotIn}} + {{/unless}} + {{#unless @root.skipSensitiveData}} + {{#isNotIn item.name @root.hideRequestBody}} + {{#with request}} {{#if body.urlencoded.members}} <div class="row"> <div class="col-sm-12 mb-3"> @@ -983,6 +998,12 @@ table.dataTable td, table.dataTable tr { </div> </div> {{/if}} + {{/with}} + {{/isNotIn}} + {{/unless}} + {{#unless @root.skipSensitiveData}} + {{#isNotIn item.name @root.hideRequestBody}} + {{#with request}} {{#if body.graphql}} <div class="row"> <div class="col-sm-12 mb-3"> @@ -1008,8 +1029,9 @@ table.dataTable td, table.dataTable tr { </div> </div> {{/if}} - {{/unless}} {{/with}} + {{/isNotIn}} + {{/unless}} {{#unless @root.omitHeaders}} {{#unless @root.skipSensitiveData}} <div class="row"> @@ -1043,7 +1065,7 @@ table.dataTable td, table.dataTable tr { {{/unless}} {{/unless}} {{#unless @root.skipSensitiveData}} - {{#isNotIn item.name @root.hideResponse}} + {{#isNotIn item.name @root.hideResponseBody}} <div class="row"> <div class="col-sm-12 mb-3"> <div class="card-deck"> diff --git a/lib/index.js b/lib/index.js index 1ba045b..e50a90a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -124,7 +124,10 @@ PostmanHTMLExtraReporter = function (newman, options, collectionRunOptions) { else if (list.length !== undefined) { list = list.toLowerCase() } - let convertedElem = elem.toLowerCase() + + if (elem !== undefined) { + var convertedElem = elem.toLowerCase() + } if (_.includes(list, convertedElem)) { return options.inverse(this); @@ -327,7 +330,8 @@ PostmanHTMLExtraReporter = function (newman, options, collectionRunOptions) { skipHeaders: options.skipHeaders || [], skipEnvironmentVars: options.skipEnvironmentVars || [], skipGlobalVars: options.skipGlobalVars || [], - hideResponse: options.hideResponse || [], + hideRequestBody: options.hideRequestBody || [], + hideResponseBody: options.hideResponseBody || [], showEnvironmentData: options.showEnvironmentData || false, showGlobalData: options.showGlobalData || false, skipSensitiveData: options.skipSensitiveData || false, diff --git a/lib/only-failures-dashboard.hbs b/lib/only-failures-dashboard.hbs index 770358d..3091f44 100644 --- a/lib/only-failures-dashboard.hbs +++ b/lib/only-failures-dashboard.hbs @@ -916,7 +916,35 @@ table.dataTable td, table.dataTable tr { </div> {{/unless}} {{/unless}} + {{/with}} + {{#unless @root.skipSensitiveData}} + {{#isNotIn item.name @root.hideRequestBody}} + {{#with request}} + {{#if body.raw}} + <div class="row"> + <div class="col-sm-12 mb-3"> + <div class="card-deck"> + <div class="card border-info" style="width: 50rem;"> + <div class="card-body"> + <h5 class="card-title text-uppercase text-white text-center bg-info">Request Body</h5> + <div class="dyn-height"> + <pre><code id="copyReqText-{{@key}}" class="prettyPrint">{{body.raw}}</code></pre> + </div> + <div class="card-footer"> + <button class="btn btn-outline-secondary btn-sm copyButton" type="button" data-clipboard-action="copy" data-clipboard-target="#copyReqText-{{@key}}">Copy to Clipboard</button> + </div> + </div> + </div> + </div> + </div> + </div> + {{/if}} + {{/with}} + {{/isNotIn}} + {{/unless}} {{#unless @root.skipSensitiveData}} + {{#isNotIn item.name @root.hideRequestBody}} + {{#with request}} {{#if body.formdata.members}} <div class="row"> <div class="col-sm-12 mb-3"> @@ -936,25 +964,12 @@ table.dataTable td, table.dataTable tr { </div> </div> {{/if}} - {{#if body.raw}} - <div class="row"> - <div class="col-sm-12 mb-3"> - <div class="card-deck"> - <div class="card border-info" style="width: 50rem;"> - <div class="card-body"> - <h5 class="card-title text-uppercase text-white text-center bg-info">Request Body</h5> - <div class="dyn-height"> - <pre><code class="prettyPrint">{{body.raw}}</code></pre> - </div> - <div id="copyReqText-{{@key}}" class="card-footer"> - <button class="btn btn-outline-secondary btn-sm copyButton" type="button" data-clipboard-action="copy" data-clipboard-target="#copyReqText-{{@key}}">Copy to Clipboard</button> - </div> - </div> - </div> - </div> - </div> - </div> - {{/if}} + {{/with}} + {{/isNotIn}} + {{/unless}} + {{#unless @root.skipSensitiveData}} + {{#isNotIn item.name @root.hideRequestBody}} + {{#with request}} {{#if body.urlencoded.members}} <div class="row"> <div class="col-sm-12 mb-3"> @@ -974,6 +989,12 @@ table.dataTable td, table.dataTable tr { </div> </div> {{/if}} + {{/with}} + {{/isNotIn}} + {{/unless}} + {{#unless @root.skipSensitiveData}} + {{#isNotIn item.name @root.hideRequestBody}} + {{#with request}} {{#if body.graphql}} <div class="row"> <div class="col-sm-12 mb-3"> @@ -999,8 +1020,9 @@ table.dataTable td, table.dataTable tr { </div> </div> {{/if}} - {{/unless}} {{/with}} + {{/isNotIn}} + {{/unless}} {{#unless @root.omitHeaders}} {{#unless @root.skipSensitiveData}} <div class="row"> @@ -1034,7 +1056,7 @@ table.dataTable td, table.dataTable tr { {{/unless}} {{/unless}} {{#unless @root.skipSensitiveData}} - {{#isNotIn item.name @root.hideResponse}} + {{#isNotIn item.name @root.hideResponseBody}} <div class="row"> <div class="col-sm-12 mb-3"> <div class="card-deck"> diff --git a/package-lock.json b/package-lock.json index 3418a3f..7d5058c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "newman-reporter-htmlextra", - "version": "1.18.0", + "version": "1.19.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -76,9 +76,9 @@ } }, "@sindresorhus/is": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-3.1.1.tgz", - "integrity": "sha512-tLnujxFtfH7F+i5ghUfgGlJsvyCKvUnSMFMlWybFdX9/DdX8svb4Zwx1gV0gkkVCHXtmPSetoAR3QlKfOld6Tw==" + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-2.1.1.tgz", + "integrity": "sha512-/aPsuoj/1Dw/kzhkgz+ES6TxG0zfTMGLwuK2ZG00k/iJzYHTLCE8mVU8EPqEOp/lmxPoq1C1C9RYToRKb2KEfg==" }, "@snyk/cli-interface": { "version": "2.8.1", @@ -3477,18 +3477,18 @@ } }, "got": { - "version": "11.5.2", - "resolved": "https://registry.npmjs.org/got/-/got-11.5.2.tgz", - "integrity": "sha512-yUhpEDLeuGiGJjRSzEq3kvt4zJtAcjKmhIiwNp/eUs75tRlXfWcHo5tcBaMQtnjHWC7nQYT5HkY/l0QOQTkVww==", + "version": "11.4.0", + "resolved": "https://registry.npmjs.org/got/-/got-11.4.0.tgz", + "integrity": "sha512-XysJZuZNVpaQ37Oo2LV90MIkPeYITehyy1A0QzO1JwOXm8EWuEf9eeGk2XuHePvLEGnm9AVOI37bHwD6KYyBtg==", "requires": { - "@sindresorhus/is": "^3.0.0", + "@sindresorhus/is": "^2.1.1", "@szmarczak/http-timer": "^4.0.5", "@types/cacheable-request": "^6.0.1", "@types/responselike": "^1.0.0", "cacheable-lookup": "^5.0.3", "cacheable-request": "^7.0.1", "decompress-response": "^6.0.0", - "http2-wrapper": "^1.0.0-beta.5.0", + "http2-wrapper": "^1.0.0-beta.4.5", "lowercase-keys": "^2.0.0", "p-cancelable": "^2.0.0", "responselike": "^2.0.0" @@ -5694,9 +5694,9 @@ } }, "open": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/open/-/open-7.1.0.tgz", - "integrity": "sha512-lLPI5KgOwEYCDKXf4np7y1PBEkj7HYIyP2DY8mVDRnx0VIIu6bNrRB0R66TuO7Mack6EnTNLm4uvcl1UoklTpA==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/open/-/open-7.2.0.tgz", + "integrity": "sha512-4HeyhxCvBTI5uBePsAdi55C5fmqnWZ2e2MlmvWi5KW5tdH5rxoiv/aMtbeVxKZc3eWkT1GymMnLG8XC4Rq4TDQ==", "requires": { "is-docker": "^2.0.0", "is-wsl": "^2.1.1" @@ -7017,9 +7017,9 @@ } }, "snyk": { - "version": "1.380.0", - "resolved": "https://registry.npmjs.org/snyk/-/snyk-1.380.0.tgz", - "integrity": "sha512-Vfj7+OdhJt87Da3qATGbi+anCONkw/7yUP+bvDMZ2lYg/LD2Igw0zO5lwUW8TbiwRkZWXvXZb+rtV9QsPYNDrA==", + "version": "1.381.2", + "resolved": "https://registry.npmjs.org/snyk/-/snyk-1.381.2.tgz", + "integrity": "sha512-END74c62u2Hg5SUxj8LKHkrbAWTU9HftAy1gOmN8AEgIS1jOihoXiV3qu7MvsIRYf9N9+go2d5bm5ZhwUJXmNg==", "requires": { "@snyk/cli-interface": "2.8.1", "@snyk/dep-graph": "1.19.3", @@ -7050,7 +7050,7 @@ "snyk-gradle-plugin": "3.5.1", "snyk-module": "3.1.0", "snyk-mvn-plugin": "2.19.1", - "snyk-nodejs-lockfile-parser": "1.26.3", + "snyk-nodejs-lockfile-parser": "1.27.0", "snyk-nuget-plugin": "1.18.1", "snyk-php-plugin": "1.9.0", "snyk-policy": "1.14.1", @@ -7502,14 +7502,15 @@ } }, "snyk-nodejs-lockfile-parser": { - "version": "1.26.3", - "resolved": "https://registry.npmjs.org/snyk-nodejs-lockfile-parser/-/snyk-nodejs-lockfile-parser-1.26.3.tgz", - "integrity": "sha512-mBQ6vhnXAeyMxlnl9amjJWpA+/3qqXwM8Sj/P+9uH2TByOFLxdGzMNQFcl3q/H2yUdcs/epVdXJp09A2dK2glA==", + "version": "1.27.0", + "resolved": "https://registry.npmjs.org/snyk-nodejs-lockfile-parser/-/snyk-nodejs-lockfile-parser-1.27.0.tgz", + "integrity": "sha512-s1yEqEC8uxELzEXqXmnWKpoOIn0rM8StMjuy0X5U+FmxGvO3jRtFDU5hcVw9cAULLfrQYBHRowrO/5FaR79fxA==", "requires": { "@snyk/graphlib": "2.1.9-patch", "@yarnpkg/core": "^2.0.0-rc.29", "@yarnpkg/lockfile": "^1.1.0", "event-loop-spinner": "^2.0.0", + "got": "11.4.0", "lodash.clonedeep": "^4.5.0", "lodash.flatmap": "^4.5.0", "lodash.isempty": "^4.4.0", diff --git a/package.json b/package.json index 3c45c75..cce182f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "newman-reporter-htmlextra", - "version": "1.18.0", + "version": "1.19.0", "description": "A newman reporter with added handlebars helpers and separated request iterations", "main": "index.js", "preferGlobal": true, @@ -33,7 +33,7 @@ "lodash": "^4.17.20", "moment-timezone": "^0.5.31", "pretty-ms": "^6.0.1", - "snyk": "^1.380.0" + "snyk": "^1.381.2" }, "author": "Danny Dainton", "license": "Apache-2.0", diff --git a/test/integration/cli.test.js b/test/integration/cli.test.js index 1671471..5932c71 100644 --- a/test/integration/cli.test.js +++ b/test/integration/cli.test.js @@ -222,7 +222,7 @@ describe('Newman and htmlextra run from the CLI', function () { }); it('should correctly generate the html report when a request name is not specified', function (done) { // eslint-disable-next-line max-len - exec(`${newman} run test/requests/simple-get-request.json -r htmlextra --reporter-htmlextra-export ${outFile} --reporter-htmlextra-hideResponse`, + exec(`${newman} run test/requests/simple-get-request.json -r htmlextra --reporter-htmlextra-export ${outFile} --reporter-htmlextra-hideResponseBody`, function (code) { expect(code, 'should have exit code of 0').to.equal(0); fs.stat(outFile, done);