ac-sanitizer 4.0.1 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,30 @@
1
+ # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
+
4
+ name: Node.js CI
5
+
6
+ on:
7
+ push:
8
+ branches: [ master ]
9
+ pull_request:
10
+ branches: [ master ]
11
+
12
+ jobs:
13
+ build:
14
+
15
+ runs-on: ubuntu-latest
16
+
17
+ strategy:
18
+ matrix:
19
+ node-version: [16.x, 18.x]
20
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21
+
22
+ steps:
23
+ - uses: actions/checkout@v3
24
+ - name: Use Node.js ${{ matrix.node-version }}
25
+ uses: actions/setup-node@v3
26
+ with:
27
+ node-version: ${{ matrix.node-version }}
28
+
29
+ - run: yarn install
30
+ - run: yarn run test
package/CHANGELOG.md CHANGED
@@ -1,3 +1,38 @@
1
+ <a name="4.0.3"></a>
2
+
3
+ ## [4.0.3](https://github.com/mmpro/ac-sanitizer/compare/v4.0.2..v4.0.3) (2023-07-21 19:16:42)
4
+
5
+
6
+ ### Bug Fix
7
+
8
+ * **App:** Package updated | MP | [32ba9d92894d54a4575a0765bafbe5f1be6f8edf](https://github.com/mmpro/ac-sanitizer/commit/32ba9d92894d54a4575a0765bafbe5f1be6f8edf)
9
+ Packages updated
10
+ Related issues: [/issues#undefined](https://github.com//issues/undefined)
11
+ ### Tests
12
+
13
+ * **App:** Fixed test | MP | [05e575d49d3254bc6191a1b3e950bb7f89e07fd0](https://github.com/mmpro/ac-sanitizer/commit/05e575d49d3254bc6191a1b3e950bb7f89e07fd0)
14
+ Fixed nested object test
15
+ Related issues: [/issues#undefined](https://github.com//issues/undefined)
16
+ <a name="4.0.2"></a>
17
+
18
+ ## [4.0.2](https://github.com/mmpro/ac-sanitizer/compare/v4.0.1..v4.0.2) (2023-06-18 11:35:24)
19
+
20
+
21
+ ### Bug Fix
22
+
23
+ * **App:** If base64 is an object, parse the converted string | MP | [cf9a49d9df121c7829932ae37192fd22f3d98438](https://github.com/mmpro/ac-sanitizer/commit/cf9a49d9df121c7829932ae37192fd22f3d98438)
24
+ Base64 might be a string or a stringified object. Try parsing the string to determine if it is an object
25
+ Related issues: [undefined/undefined#master](undefined/browse/master)
26
+ ### Chores
27
+
28
+ * **App:** Updated packages | MP | [49da6b224e9382aa7cc6a298b2a0af06648931b8](https://github.com/mmpro/ac-sanitizer/commit/49da6b224e9382aa7cc6a298b2a0af06648931b8)
29
+ Updated packages
30
+ Related issues: [undefined/undefined#master](undefined/browse/master)
31
+ ### Chores
32
+
33
+ * **App:** Add Github workflow | MP | [72668a139dda85330516077ef471af4aa4b68c3b](https://github.com/mmpro/ac-sanitizer/commit/72668a139dda85330516077ef471af4aa4b68c3b)
34
+ Add Github workflow
35
+ Related issues: [undefined/undefined#master](undefined/browse/master)
1
36
  <a name="4.0.1"></a>
2
37
 
3
38
  ## [4.0.1](https://github.com/mmpro/ac-sanitizer/compare/v4.0.0..v4.0.1) (2023-04-18 18:38:15)
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # AC Sanitizer
2
2
  Sanitizes payloads with given field definitions
3
3
 
4
+ [![Node.js CI](https://github.com/AdmiralCloud/ac-sanitizer/actions/workflows/node.js.yml/badge.svg)](https://github.com/AdmiralCloud/ac-sanitizer/actions/workflows/node.js.yml)
5
+
4
6
  ### Version 4 - Breaking changes
5
7
  Version 4 requires Node 16.
6
8
 
package/index.js CHANGED
@@ -330,6 +330,13 @@ const sanitizer = function() {
330
330
  if (!validator.isBase64(_.padEnd(value, (l+pad), '='))) error = { message: fieldName + '_notABase64String' }
331
331
  else if (field.convert) {
332
332
  _.set(paramsToCheck, fieldName, Buffer.from(value, 'base64').toString())
333
+ // the value might be a stringified object - try converting it
334
+ try {
335
+ _.set(paramsToCheck, fieldName, JSON.parse(_.get(paramsToCheck, fieldName)))
336
+ }
337
+ catch(e) {
338
+ // ignore
339
+ }
333
340
  }
334
341
  }
335
342
  }
package/package.json CHANGED
@@ -4,27 +4,27 @@
4
4
  "author": "Mark Poepping (https://www.admiralcloud.com)",
5
5
  "license": "MIT",
6
6
  "repository": "admiralcloud/ac-sanitizer",
7
- "version": "4.0.1",
7
+ "version": "4.0.3",
8
8
  "homepage": "https://www.admiralcloud.com",
9
9
  "dependencies": {
10
10
  "ac-countrylist": "^1.0.7",
11
11
  "ac-file-extensions": "^2.0.5",
12
12
  "ac-ip": "^3.0.1",
13
13
  "chai": "^4.3.7",
14
- "date-and-time": "^2.4.3",
15
- "hashids": "^2.2.11",
14
+ "date-and-time": "^3.0.2",
15
+ "hashids": "^2.3.0",
16
16
  "lodash": "^4.17.21",
17
17
  "validator": "^13.9.0"
18
18
  },
19
19
  "devDependencies": {
20
- "ac-semantic-release": "^0.4.0",
21
- "eslint": "^8.38.0",
22
- "mocha": "^10.2.0",
23
- "nyc": "^15.1.0"
20
+ "ac-semantic-release": "^0.4.2",
21
+ "c8": "^8.0.0",
22
+ "eslint": "^8.45.0",
23
+ "mocha": "^10.2.0"
24
24
  },
25
25
  "scripts": {
26
26
  "test": "mocha --reporter spec",
27
- "coverage": "nyc yarn run test"
27
+ "coverage": "./node_modules/c8/bin/c8.js yarn test"
28
28
  },
29
29
  "engines": {
30
30
  "node": ">=16.0.0"
@@ -13,6 +13,8 @@ module.exports = {
13
13
  { name: 'Invalid base64 with convert', type: 'base64', convert: true, value: 123, error: 'base64_mustBeString' },
14
14
  { name: 'Base64 app.admiralcloud.com - requires padding', type: 'base64', value: 'aHR0cHM6Ly9hcHAuYWRtaXJhbGNsb3VkLmNvbQ', convert: true, expected: 'https://app.admiralcloud.com' },
15
15
  { name: 'Base64 app.admiralcloud.com - with padding', type: 'base64', value: 'aHR0cHM6Ly9hcHAuYWRtaXJhbGNsb3VkLmNvbQ==', convert: true, expected: 'https://app.admiralcloud.com' },
16
+ { name: 'Base64 encoded object', type: 'base64', value: 'eyJ1c2VySWQiOjEyMywiY3VzdG9tZXJJZCI6MTQ2LCJyZWFzb24iOiJCZWNhdXNlIEkgY2FuIn0=', convert: true, expected: { userId: 123, customerId: 146, reason: 'Because I can' } },
17
+ { name: 'Base64 encoded object', type: 'base64', value: 'eyJ1c2VySWQiOjEyMywiY3VzdG9tZXJJZCI6MTQ2LCJyZWFzbOiJCZWNhdXNlIEkgY2FuIn0=', convert: true, error: 'base64_notABase64String' },
16
18
  ]
17
19
 
18
20
  _.forEach(baseTests, (test) => {
@@ -34,7 +36,7 @@ module.exports = {
34
36
  }
35
37
  }
36
38
  else {
37
- expect(_.get(r, 'params.base64')).to.equal(_.get(test, 'expected'))
39
+ expect(_.get(r, 'params.base64')).to.eql(_.get(test, 'expected'))
38
40
  }
39
41
  return done()
40
42
  })
@@ -199,6 +199,29 @@ module.exports = {
199
199
  }
200
200
  },
201
201
  },
202
+ {
203
+ name: "Object with complex nested properties",
204
+ type: "object",
205
+ properties: [
206
+ { field: "boo", type: "boolean" },
207
+ { field: "nested", type: "object", properties: [
208
+ { field: 'setId', type: 'boolean', required: false }
209
+ ] }
210
+ ],
211
+ value: {
212
+ boo: true,
213
+ enum: "blue",
214
+ nested: {
215
+ setId: false
216
+ }
217
+ },
218
+ expected: {
219
+ boo: true,
220
+ nested: {
221
+ setId: false
222
+ }
223
+ },
224
+ },
202
225
  ];
203
226
 
204
227
  _.forEach(baseTests, (test) => {