diff --git a/README.md b/README.md index 68ed44de2..d730d8a70 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,7 @@ There are some major differences between this library and the [httpsnippet](http * Includes a full integration test suite for a handful of clients and targets. * Does not ship with a CLI component. +* Does not do any HAR schema validation. It's just assumed that the HAR you're supplying to the library is already valid. * The main `HTTPSnippet` export contains an `options` argument for an `harIsAlreadyEncoded` option for disabling [escaping](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) of cookies and query strings in URLs. * We added this because all HARs that we interact with already have this data escaped and this option prevents them from being double encoded, thus corrupting the data. * Node diff --git a/package-lock.json b/package-lock.json index 11deced3a..536a9fd08 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,10 +9,8 @@ "version": "4.1.1", "license": "MIT", "dependencies": { - "ajv": "^6.12.6", "event-stream": "4.0.1", "form-data": "^4.0.0", - "har-schema": "^2.0.0", "qs": "^6.10.1", "stringify-object": "^3.3.0" }, @@ -1795,6 +1793,7 @@ "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -3631,7 +3630,8 @@ "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", - "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true }, "node_modules/fast-diff": { "version": "1.2.0", @@ -3670,7 +3670,8 @@ "node_modules/fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", - "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==" + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", + "dev": true }, "node_modules/fast-levenshtein": { "version": "2.0.6", @@ -4032,14 +4033,6 @@ "integrity": "sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==", "dev": true }, - "node_modules/har-schema": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", - "integrity": "sha512-Oqluz6zhGX8cyRaTQlFMPw80bSJVG2x/cFb8ZPhUILGgHka9SsokCCOQgpveePerqidZOrT14ipqfJb7ILcW5Q==", - "engines": { - "node": ">=4" - } - }, "node_modules/has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -5589,7 +5582,8 @@ "node_modules/json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true }, "node_modules/json-stable-stringify-without-jsonify": { "version": "1.0.1", @@ -6427,6 +6421,7 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", + "dev": true, "engines": { "node": ">=6" } @@ -7488,6 +7483,7 @@ "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "dev": true, "dependencies": { "punycode": "^2.1.0" } @@ -9007,6 +9003,7 @@ "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, "requires": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -10326,7 +10323,8 @@ "fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", - "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true }, "fast-diff": { "version": "1.2.0", @@ -10361,7 +10359,8 @@ "fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", - "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==" + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", + "dev": true }, "fast-levenshtein": { "version": "2.0.6", @@ -10639,11 +10638,6 @@ "integrity": "sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==", "dev": true }, - "har-schema": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", - "integrity": "sha512-Oqluz6zhGX8cyRaTQlFMPw80bSJVG2x/cFb8ZPhUILGgHka9SsokCCOQgpveePerqidZOrT14ipqfJb7ILcW5Q==" - }, "has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -11785,7 +11779,8 @@ "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true }, "json-stable-stringify-without-jsonify": { "version": "1.0.1", @@ -12422,7 +12417,8 @@ "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", - "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", + "dev": true }, "qs": { "version": "6.11.0", @@ -13185,6 +13181,7 @@ "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "dev": true, "requires": { "punycode": "^2.1.0" } diff --git a/package.json b/package.json index 7d0fb8d52..b8744b84c 100644 --- a/package.json +++ b/package.json @@ -75,10 +75,8 @@ "typescript": "^4.9.4" }, "dependencies": { - "ajv": "^6.12.6", "event-stream": "4.0.1", "form-data": "^4.0.0", - "har-schema": "^2.0.0", "qs": "^6.10.1", "stringify-object": "^3.3.0" }, diff --git a/src/helpers/har-validator.ts b/src/helpers/har-validator.ts deleted file mode 100644 index 41d7a659c..000000000 --- a/src/helpers/har-validator.ts +++ /dev/null @@ -1,38 +0,0 @@ -import type { ErrorObject } from 'ajv'; -import type { Request } from 'har-format'; - -import Ajv from 'ajv'; -import * as schema from 'har-schema'; - -export class HARError extends Error { - name = 'HARError'; - - message = 'validation failed'; - - errors: ErrorObject[] = []; - - constructor(errors: ErrorObject[]) { - super(); - this.errors = errors; - Error.captureStackTrace(this, this.constructor); - } -} - -const ajv = new Ajv({ - allErrors: true, -}); -ajv.addSchema(schema); - -export const validateHarRequest = (request: any): request is Request => { - const validate = ajv.getSchema('request.json'); - if (!validate) { - throw new Error('failed to find HAR request schema'); - } - - const valid = validate(request); - if (!valid && validate.errors) { - throw new HARError(validate.errors); - } - - return true; -}; diff --git a/src/index.test.ts b/src/index.test.ts index 37c603590..fbcb5e8bc 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -16,15 +16,6 @@ describe('HTTPSnippet', () => { expect(result).toBe(false); }); - it('should fail validation for non-HAR inputs', () => { - expect.assertions(1); - - // @ts-expect-error intentionally incorrect - const attempt = () => new HTTPSnippet({ ziltoid: 'the omniscient' }); - - expect(attempt).toThrow('validation failed'); - }); - describe('repair malformed `postData`', () => { it('should repair a HAR with an empty `postData` object', () => { const snippet = new HTTPSnippet({ diff --git a/src/index.ts b/src/index.ts index a872cf543..45f03179e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,7 +11,6 @@ import FormData from 'form-data'; import { stringify as queryStringify } from 'qs'; import { formDataIterator, isBlob } from './helpers/form-data'; -import { validateHarRequest } from './helpers/har-validator'; import { getHeaderName } from './helpers/headers'; import { reducer } from './helpers/reducer'; import { targets } from './targets/targets'; @@ -126,9 +125,7 @@ export class HTTPSnippet { req.postData.mimeType = 'application/octet-stream'; } - if (validateHarRequest(req)) { - this.requests.push(this.prepare(req, options)); - } + this.requests.push(this.prepare(req as HarRequest, options)); }); } diff --git a/src/targets/har-schema.d.ts b/src/targets/har-schema.d.ts deleted file mode 100644 index 1df95659e..000000000 --- a/src/targets/har-schema.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare module 'har-schema' { - const schema: object; - export default schema; -}