light-my-request
Advanced tools
@@ -40,4 +40,11 @@ 'use strict' | ||
| query: { | ||
| type: 'object', | ||
| additionalProperties: true | ||
| anyOf: [ | ||
| { | ||
| type: 'object', | ||
| additionalProperties: true | ||
| }, | ||
| { | ||
| type: 'string' | ||
| } | ||
| ] | ||
| }, | ||
@@ -44,0 +51,0 @@ simulate: { |
+1
-1
@@ -96,3 +96,3 @@ import * as http from 'http' | ||
| payload: (payload: InjectPayload) => Chain | ||
| query: (query: object) => Chain | ||
| query: (query: string | { [k: string]: string | string[] } ) => Chain | ||
| cookies: (query: object) => Chain | ||
@@ -99,0 +99,0 @@ end(): Promise<Response> |
+159
-92
@@ -1,2 +0,2 @@ | ||
| // This file is autogenerated by build/build-validation.js, do not edit | ||
| // This file is autogenerated by build\build-validation.js, do not edit | ||
| /* istanbul ignore file */ | ||
@@ -7,3 +7,3 @@ /* eslint-disable */ | ||
| module.exports.default = validate10; | ||
| const schema11 = {"type":"object","properties":{"url":{"oneOf":[{"type":"string"},{"type":"object","properties":{"protocol":{"type":"string"},"hostname":{"type":"string"},"pathname":{"type":"string"}},"additionalProperties":true,"required":["pathname"]}]},"path":{"oneOf":[{"type":"string"},{"type":"object","properties":{"protocol":{"type":"string"},"hostname":{"type":"string"},"pathname":{"type":"string"}},"additionalProperties":true,"required":["pathname"]}]},"cookies":{"type":"object","additionalProperties":true},"headers":{"type":"object","additionalProperties":true},"query":{"type":"object","additionalProperties":true},"simulate":{"type":"object","properties":{"end":{"type":"boolean"},"split":{"type":"boolean"},"error":{"type":"boolean"},"close":{"type":"boolean"}}},"authority":{"type":"string"},"remoteAddress":{"type":"string"},"method":{"type":"string","enum":["ACL","BIND","CHECKOUT","CONNECT","COPY","DELETE","GET","HEAD","LINK","LOCK","M-SEARCH","MERGE","MKACTIVITY","MKCALENDAR","MKCOL","MOVE","NOTIFY","OPTIONS","PATCH","POST","PROPFIND","PROPPATCH","PURGE","PUT","REBIND","REPORT","SEARCH","SOURCE","SUBSCRIBE","TRACE","UNBIND","UNLINK","UNLOCK","UNSUBSCRIBE","acl","bind","checkout","connect","copy","delete","get","head","link","lock","m-search","merge","mkactivity","mkcalendar","mkcol","move","notify","options","patch","post","propfind","proppatch","purge","put","rebind","report","search","source","subscribe","trace","unbind","unlink","unlock","unsubscribe"]},"validate":{"type":"boolean"}},"additionalProperties":true,"oneOf":[{"required":["url"]},{"required":["path"]}]}; | ||
| const schema11 = {"type":"object","properties":{"url":{"oneOf":[{"type":"string"},{"type":"object","properties":{"protocol":{"type":"string"},"hostname":{"type":"string"},"pathname":{"type":"string"}},"additionalProperties":true,"required":["pathname"]}]},"path":{"oneOf":[{"type":"string"},{"type":"object","properties":{"protocol":{"type":"string"},"hostname":{"type":"string"},"pathname":{"type":"string"}},"additionalProperties":true,"required":["pathname"]}]},"cookies":{"type":"object","additionalProperties":true},"headers":{"type":"object","additionalProperties":true},"query":{"anyOf":[{"type":"object","additionalProperties":true},{"type":"string"}]},"simulate":{"type":"object","properties":{"end":{"type":"boolean"},"split":{"type":"boolean"},"error":{"type":"boolean"},"close":{"type":"boolean"}}},"authority":{"type":"string"},"remoteAddress":{"type":"string"},"method":{"type":"string","enum":["ACL","BIND","CHECKOUT","CONNECT","COPY","DELETE","GET","HEAD","LINK","LOCK","M-SEARCH","MERGE","MKACTIVITY","MKCALENDAR","MKCOL","MOVE","NOTIFY","OPTIONS","PATCH","POST","PROPFIND","PROPPATCH","PURGE","PUT","REBIND","REPORT","SEARCH","SOURCE","SUBSCRIBE","TRACE","UNBIND","UNLINK","UNLOCK","UNSUBSCRIBE","acl","bind","checkout","connect","copy","delete","get","head","link","lock","m-search","merge","mkactivity","mkcalendar","mkcol","move","notify","options","patch","post","propfind","proppatch","purge","put","rebind","report","search","source","subscribe","trace","unbind","unlink","unlock","unsubscribe"]},"validate":{"type":"boolean"}},"additionalProperties":true,"oneOf":[{"required":["url"]},{"required":["path"]}]}; | ||
@@ -558,8 +558,75 @@ function validate10(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){ | ||
| const _errs37 = errors; | ||
| if(errors === _errs37){ | ||
| const _errs38 = errors; | ||
| let valid6 = false; | ||
| const _errs39 = errors; | ||
| if(errors === _errs39){ | ||
| if(!(data10 && typeof data10 == "object" && !Array.isArray(data10))){ | ||
| validate10.errors = [{instancePath:instancePath+"/query",schemaPath:"#/properties/query/type",keyword:"type",params:{type: "object"},message:"must be object"}]; | ||
| const err17 = {instancePath:instancePath+"/query",schemaPath:"#/properties/query/anyOf/0/type",keyword:"type",params:{type: "object"},message:"must be object"}; | ||
| if(vErrors === null){ | ||
| vErrors = [err17]; | ||
| } | ||
| else { | ||
| vErrors.push(err17); | ||
| } | ||
| errors++; | ||
| } | ||
| } | ||
| var _valid3 = _errs39 === errors; | ||
| valid6 = valid6 || _valid3; | ||
| if(!valid6){ | ||
| const _errs42 = errors; | ||
| if(typeof data10 !== "string"){ | ||
| let dataType8 = typeof data10; | ||
| let coerced8 = undefined; | ||
| if(!(coerced8 !== undefined)){ | ||
| if(dataType8 == "number" || dataType8 == "boolean"){ | ||
| coerced8 = "" + data10; | ||
| } | ||
| else if(data10 === null){ | ||
| coerced8 = ""; | ||
| } | ||
| else { | ||
| const err18 = {instancePath:instancePath+"/query",schemaPath:"#/properties/query/anyOf/1/type",keyword:"type",params:{type: "string"},message:"must be string"}; | ||
| if(vErrors === null){ | ||
| vErrors = [err18]; | ||
| } | ||
| else { | ||
| vErrors.push(err18); | ||
| } | ||
| errors++; | ||
| } | ||
| } | ||
| if(coerced8 !== undefined){ | ||
| data10 = coerced8; | ||
| if(data !== undefined){ | ||
| data["query"] = coerced8; | ||
| } | ||
| } | ||
| } | ||
| var _valid3 = _errs42 === errors; | ||
| valid6 = valid6 || _valid3; | ||
| } | ||
| if(!valid6){ | ||
| const err19 = {instancePath:instancePath+"/query",schemaPath:"#/properties/query/anyOf",keyword:"anyOf",params:{},message:"must match a schema in anyOf"}; | ||
| if(vErrors === null){ | ||
| vErrors = [err19]; | ||
| } | ||
| else { | ||
| vErrors.push(err19); | ||
| } | ||
| errors++; | ||
| validate10.errors = vErrors; | ||
| return false; | ||
| } | ||
| else { | ||
| errors = _errs38; | ||
| if(vErrors !== null){ | ||
| if(_errs38){ | ||
| vErrors.length = _errs38; | ||
| } | ||
| else { | ||
| vErrors = null; | ||
| } | ||
| } | ||
| } | ||
| var valid1 = _errs37 === errors; | ||
@@ -573,16 +640,16 @@ } | ||
| let data11 = data.simulate; | ||
| const _errs40 = errors; | ||
| if(errors === _errs40){ | ||
| const _errs44 = errors; | ||
| if(errors === _errs44){ | ||
| if(data11 && typeof data11 == "object" && !Array.isArray(data11)){ | ||
| if(data11.end !== undefined){ | ||
| let data12 = data11.end; | ||
| const _errs42 = errors; | ||
| const _errs46 = errors; | ||
| if(typeof data12 !== "boolean"){ | ||
| let coerced8 = undefined; | ||
| if(!(coerced8 !== undefined)){ | ||
| let coerced9 = undefined; | ||
| if(!(coerced9 !== undefined)){ | ||
| if(data12 === "false" || data12 === 0 || data12 === null){ | ||
| coerced8 = false; | ||
| coerced9 = false; | ||
| } | ||
| else if(data12 === "true" || data12 === 1){ | ||
| coerced8 = true; | ||
| coerced9 = true; | ||
| } | ||
@@ -594,26 +661,26 @@ else { | ||
| } | ||
| if(coerced8 !== undefined){ | ||
| data12 = coerced8; | ||
| if(coerced9 !== undefined){ | ||
| data12 = coerced9; | ||
| if(data11 !== undefined){ | ||
| data11["end"] = coerced8; | ||
| data11["end"] = coerced9; | ||
| } | ||
| } | ||
| } | ||
| var valid6 = _errs42 === errors; | ||
| var valid7 = _errs46 === errors; | ||
| } | ||
| else { | ||
| var valid6 = true; | ||
| var valid7 = true; | ||
| } | ||
| if(valid6){ | ||
| if(valid7){ | ||
| if(data11.split !== undefined){ | ||
| let data13 = data11.split; | ||
| const _errs44 = errors; | ||
| const _errs48 = errors; | ||
| if(typeof data13 !== "boolean"){ | ||
| let coerced9 = undefined; | ||
| if(!(coerced9 !== undefined)){ | ||
| let coerced10 = undefined; | ||
| if(!(coerced10 !== undefined)){ | ||
| if(data13 === "false" || data13 === 0 || data13 === null){ | ||
| coerced9 = false; | ||
| coerced10 = false; | ||
| } | ||
| else if(data13 === "true" || data13 === 1){ | ||
| coerced9 = true; | ||
| coerced10 = true; | ||
| } | ||
@@ -625,26 +692,26 @@ else { | ||
| } | ||
| if(coerced9 !== undefined){ | ||
| data13 = coerced9; | ||
| if(coerced10 !== undefined){ | ||
| data13 = coerced10; | ||
| if(data11 !== undefined){ | ||
| data11["split"] = coerced9; | ||
| data11["split"] = coerced10; | ||
| } | ||
| } | ||
| } | ||
| var valid6 = _errs44 === errors; | ||
| var valid7 = _errs48 === errors; | ||
| } | ||
| else { | ||
| var valid6 = true; | ||
| var valid7 = true; | ||
| } | ||
| if(valid6){ | ||
| if(valid7){ | ||
| if(data11.error !== undefined){ | ||
| let data14 = data11.error; | ||
| const _errs46 = errors; | ||
| const _errs50 = errors; | ||
| if(typeof data14 !== "boolean"){ | ||
| let coerced10 = undefined; | ||
| if(!(coerced10 !== undefined)){ | ||
| let coerced11 = undefined; | ||
| if(!(coerced11 !== undefined)){ | ||
| if(data14 === "false" || data14 === 0 || data14 === null){ | ||
| coerced10 = false; | ||
| coerced11 = false; | ||
| } | ||
| else if(data14 === "true" || data14 === 1){ | ||
| coerced10 = true; | ||
| coerced11 = true; | ||
| } | ||
@@ -656,26 +723,26 @@ else { | ||
| } | ||
| if(coerced10 !== undefined){ | ||
| data14 = coerced10; | ||
| if(coerced11 !== undefined){ | ||
| data14 = coerced11; | ||
| if(data11 !== undefined){ | ||
| data11["error"] = coerced10; | ||
| data11["error"] = coerced11; | ||
| } | ||
| } | ||
| } | ||
| var valid6 = _errs46 === errors; | ||
| var valid7 = _errs50 === errors; | ||
| } | ||
| else { | ||
| var valid6 = true; | ||
| var valid7 = true; | ||
| } | ||
| if(valid6){ | ||
| if(valid7){ | ||
| if(data11.close !== undefined){ | ||
| let data15 = data11.close; | ||
| const _errs48 = errors; | ||
| const _errs52 = errors; | ||
| if(typeof data15 !== "boolean"){ | ||
| let coerced11 = undefined; | ||
| if(!(coerced11 !== undefined)){ | ||
| let coerced12 = undefined; | ||
| if(!(coerced12 !== undefined)){ | ||
| if(data15 === "false" || data15 === 0 || data15 === null){ | ||
| coerced11 = false; | ||
| coerced12 = false; | ||
| } | ||
| else if(data15 === "true" || data15 === 1){ | ||
| coerced11 = true; | ||
| coerced12 = true; | ||
| } | ||
@@ -687,13 +754,13 @@ else { | ||
| } | ||
| if(coerced11 !== undefined){ | ||
| data15 = coerced11; | ||
| if(coerced12 !== undefined){ | ||
| data15 = coerced12; | ||
| if(data11 !== undefined){ | ||
| data11["close"] = coerced11; | ||
| data11["close"] = coerced12; | ||
| } | ||
| } | ||
| } | ||
| var valid6 = _errs48 === errors; | ||
| var valid7 = _errs52 === errors; | ||
| } | ||
| else { | ||
| var valid6 = true; | ||
| var valid7 = true; | ||
| } | ||
@@ -709,3 +776,3 @@ } | ||
| } | ||
| var valid1 = _errs40 === errors; | ||
| var valid1 = _errs44 === errors; | ||
| } | ||
@@ -718,12 +785,12 @@ else { | ||
| let data16 = data.authority; | ||
| const _errs50 = errors; | ||
| const _errs54 = errors; | ||
| if(typeof data16 !== "string"){ | ||
| let dataType12 = typeof data16; | ||
| let coerced12 = undefined; | ||
| if(!(coerced12 !== undefined)){ | ||
| if(dataType12 == "number" || dataType12 == "boolean"){ | ||
| coerced12 = "" + data16; | ||
| let dataType13 = typeof data16; | ||
| let coerced13 = undefined; | ||
| if(!(coerced13 !== undefined)){ | ||
| if(dataType13 == "number" || dataType13 == "boolean"){ | ||
| coerced13 = "" + data16; | ||
| } | ||
| else if(data16 === null){ | ||
| coerced12 = ""; | ||
| coerced13 = ""; | ||
| } | ||
@@ -735,10 +802,10 @@ else { | ||
| } | ||
| if(coerced12 !== undefined){ | ||
| data16 = coerced12; | ||
| if(coerced13 !== undefined){ | ||
| data16 = coerced13; | ||
| if(data !== undefined){ | ||
| data["authority"] = coerced12; | ||
| data["authority"] = coerced13; | ||
| } | ||
| } | ||
| } | ||
| var valid1 = _errs50 === errors; | ||
| var valid1 = _errs54 === errors; | ||
| } | ||
@@ -751,12 +818,12 @@ else { | ||
| let data17 = data.remoteAddress; | ||
| const _errs52 = errors; | ||
| const _errs56 = errors; | ||
| if(typeof data17 !== "string"){ | ||
| let dataType13 = typeof data17; | ||
| let coerced13 = undefined; | ||
| if(!(coerced13 !== undefined)){ | ||
| if(dataType13 == "number" || dataType13 == "boolean"){ | ||
| coerced13 = "" + data17; | ||
| let dataType14 = typeof data17; | ||
| let coerced14 = undefined; | ||
| if(!(coerced14 !== undefined)){ | ||
| if(dataType14 == "number" || dataType14 == "boolean"){ | ||
| coerced14 = "" + data17; | ||
| } | ||
| else if(data17 === null){ | ||
| coerced13 = ""; | ||
| coerced14 = ""; | ||
| } | ||
@@ -768,10 +835,10 @@ else { | ||
| } | ||
| if(coerced13 !== undefined){ | ||
| data17 = coerced13; | ||
| if(coerced14 !== undefined){ | ||
| data17 = coerced14; | ||
| if(data !== undefined){ | ||
| data["remoteAddress"] = coerced13; | ||
| data["remoteAddress"] = coerced14; | ||
| } | ||
| } | ||
| } | ||
| var valid1 = _errs52 === errors; | ||
| var valid1 = _errs56 === errors; | ||
| } | ||
@@ -784,12 +851,12 @@ else { | ||
| let data18 = data.method; | ||
| const _errs54 = errors; | ||
| const _errs58 = errors; | ||
| if(typeof data18 !== "string"){ | ||
| let dataType14 = typeof data18; | ||
| let coerced14 = undefined; | ||
| if(!(coerced14 !== undefined)){ | ||
| if(dataType14 == "number" || dataType14 == "boolean"){ | ||
| coerced14 = "" + data18; | ||
| let dataType15 = typeof data18; | ||
| let coerced15 = undefined; | ||
| if(!(coerced15 !== undefined)){ | ||
| if(dataType15 == "number" || dataType15 == "boolean"){ | ||
| coerced15 = "" + data18; | ||
| } | ||
| else if(data18 === null){ | ||
| coerced14 = ""; | ||
| coerced15 = ""; | ||
| } | ||
@@ -801,6 +868,6 @@ else { | ||
| } | ||
| if(coerced14 !== undefined){ | ||
| data18 = coerced14; | ||
| if(coerced15 !== undefined){ | ||
| data18 = coerced15; | ||
| if(data !== undefined){ | ||
| data["method"] = coerced14; | ||
| data["method"] = coerced15; | ||
| } | ||
@@ -813,3 +880,3 @@ } | ||
| } | ||
| var valid1 = _errs54 === errors; | ||
| var valid1 = _errs58 === errors; | ||
| } | ||
@@ -822,11 +889,11 @@ else { | ||
| let data19 = data.validate; | ||
| const _errs56 = errors; | ||
| const _errs60 = errors; | ||
| if(typeof data19 !== "boolean"){ | ||
| let coerced15 = undefined; | ||
| if(!(coerced15 !== undefined)){ | ||
| let coerced16 = undefined; | ||
| if(!(coerced16 !== undefined)){ | ||
| if(data19 === "false" || data19 === 0 || data19 === null){ | ||
| coerced15 = false; | ||
| coerced16 = false; | ||
| } | ||
| else if(data19 === "true" || data19 === 1){ | ||
| coerced15 = true; | ||
| coerced16 = true; | ||
| } | ||
@@ -838,10 +905,10 @@ else { | ||
| } | ||
| if(coerced15 !== undefined){ | ||
| data19 = coerced15; | ||
| if(coerced16 !== undefined){ | ||
| data19 = coerced16; | ||
| if(data !== undefined){ | ||
| data["validate"] = coerced15; | ||
| data["validate"] = coerced16; | ||
| } | ||
| } | ||
| } | ||
| var valid1 = _errs56 === errors; | ||
| var valid1 = _errs60 === errors; | ||
| } | ||
@@ -848,0 +915,0 @@ else { |
+19
-9
@@ -22,14 +22,24 @@ 'use strict' | ||
| const merged = Object.assign({}, url.query, query) | ||
| for (const key in merged) { | ||
| const value = merged[key] | ||
| if (Array.isArray(value)) { | ||
| if (typeof query === 'string') { | ||
| query = new URLSearchParams(query) | ||
| for (const key of query.keys()) { | ||
| result.searchParams.delete(key) | ||
| for (const param of value) { | ||
| result.searchParams.append(key, param) | ||
| for (const value of query.getAll(key)) { | ||
| result.searchParams.append(key, value) | ||
| } | ||
| } else { | ||
| result.searchParams.set(key, value) | ||
| } | ||
| } else { | ||
| const merged = Object.assign({}, url.query, query) | ||
| for (const key in merged) { | ||
| const value = merged[key] | ||
| if (Array.isArray(value)) { | ||
| result.searchParams.delete(key) | ||
| for (const param of value) { | ||
| result.searchParams.append(key, param) | ||
| } | ||
| } else { | ||
| result.searchParams.set(key, value) | ||
| } | ||
| } | ||
| } | ||
@@ -36,0 +46,0 @@ |
+1
-1
| { | ||
| "name": "light-my-request", | ||
| "version": "5.2.0", | ||
| "version": "5.3.0", | ||
| "description": "Fake HTTP injection library", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+1
-1
@@ -157,3 +157,3 @@ # Light my Request | ||
| - `payload` - an optional request payload. Can be a string, Buffer, Stream or object. If the payload is string, Buffer or Stream is used as is as the request payload. Oherwise it is serialized with `JSON.stringify` forcing the request to have the `Content-type` equal to `application/json` | ||
| - `query` - an optional object containing query parameters. | ||
| - `query` - an optional object or string containing query parameters. | ||
| - `body` - alias for payload. | ||
@@ -160,0 +160,0 @@ - `simulate` - an object containing flags to simulate various conditions: |
@@ -61,2 +61,7 @@ import * as http from 'http' | ||
| inject(dispatch, { method: 'get', url: '/', query: 'name1=value1' }, (err, res) => { | ||
| expectType<Error>(err) | ||
| expectResponse(res) | ||
| }) | ||
| expectType<void>( | ||
@@ -63,0 +68,0 @@ inject(dispatch) |
+37
-0
@@ -242,2 +242,39 @@ 'use strict' | ||
| test('passes query as a string', (t) => { | ||
| t.plan(2) | ||
| const query = 'message=OK&xs=foo&xs=bar' | ||
| const dispatch = function (req, res) { | ||
| res.writeHead(200, { 'Content-Type': 'text/plain' }) | ||
| res.end(req.url) | ||
| } | ||
| inject(dispatch, { method: 'GET', url: 'http://example.com:8080/hello', query }, (err, res) => { | ||
| t.error(err) | ||
| t.same(parseQuery(res.payload), { | ||
| message: 'OK', | ||
| xs: ['foo', 'bar'] | ||
| }) | ||
| }) | ||
| }) | ||
| test('query as a string will be merged into that in url', (t) => { | ||
| t.plan(2) | ||
| const query = 'xs=foo&xs=bar' | ||
| const dispatch = function (req, res) { | ||
| res.writeHead(200, { 'Content-Type': 'text/plain' }) | ||
| res.end(req.url) | ||
| } | ||
| inject(dispatch, { method: 'GET', url: 'http://example.com:8080/hello?message=OK', query }, (err, res) => { | ||
| t.error(err) | ||
| t.same(parseQuery(res.payload), Object.assign({ message: 'OK' }, { | ||
| xs: ['foo', 'bar'] | ||
| })) | ||
| }) | ||
| }) | ||
| test('passes localhost as default remote address', (t) => { | ||
@@ -244,0 +281,0 @@ t.plan(2) |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
113591
2.57%3440
3.52%