Comparing version 3.4.1 to 3.5.0
{ | ||
"name": "pactum", | ||
"version": "3.4.1", | ||
"version": "3.5.0", | ||
"description": "REST API Testing Tool for all levels in a Test Pyramid", | ||
@@ -55,10 +55,10 @@ "main": "./src/index.js", | ||
"dependencies": { | ||
"@exodus/schemasafe": "^1.0.0-rc.9", | ||
"@exodus/schemasafe": "^1.2.3", | ||
"deep-override": "^1.0.2", | ||
"form-data-lite": "^1.0.3", | ||
"json-query": "^2.2.2", | ||
"klona": "^2.0.5", | ||
"klona": "^2.0.6", | ||
"lightcookie": "^1.0.25", | ||
"openapi-fuzzer-core": "^1.0.6", | ||
"pactum-matchers": "^1.1.5", | ||
"pactum-matchers": "^1.1.6", | ||
"parse-graphql": "^1.0.0", | ||
@@ -69,6 +69,6 @@ "phin": "^3.7.0", | ||
"devDependencies": { | ||
"chai": "^4.3.6", | ||
"mocha": "^10.1.0", | ||
"chai": "^4.3.7", | ||
"mocha": "^10.2.0", | ||
"nyc": "^15.1.0", | ||
"sinon": "^14.0.1" | ||
"sinon": "^15.2.0" | ||
}, | ||
@@ -75,0 +75,0 @@ "engines": { |
@@ -5,3 +5,8 @@ const config = { | ||
host: process.env.PACTUM_MOCK_HOST || '0.0.0.0', | ||
remote: '' | ||
remote: '', | ||
isHttps: false, | ||
httpsOpts: { | ||
key: '', | ||
cert: '' | ||
} | ||
}, | ||
@@ -8,0 +13,0 @@ request: { |
@@ -13,2 +13,3 @@ export type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'TRACE'; | ||
headers?: object; | ||
cookies?: object; | ||
queryParams?: object; | ||
@@ -23,2 +24,3 @@ graphQL?: GraphQLRequest; | ||
headers?: object; | ||
cookies?: object; | ||
body?: any; | ||
@@ -28,3 +30,3 @@ file?: string; | ||
randomDelay?: RandomDelay; | ||
onCall?: OnCall | ||
onCall?: OnCall; | ||
} | ||
@@ -87,2 +89,13 @@ | ||
export interface HttpsOpts { | ||
key?: string; | ||
cert?: string; | ||
} | ||
export interface MockServerOptions { | ||
port?: number; | ||
host?: string; | ||
httpOpts?: HttpsOpts; | ||
} | ||
/** | ||
@@ -103,2 +116,9 @@ * starts the mock server | ||
/** | ||
* sets default configuration for mock server | ||
* @see https://pactumjs.github.io/guides/mock-server.html | ||
* @see https://pactumjs.github.io/api/mock/setDefaults.html | ||
*/ | ||
export function setDefaults(options: MockServerOptions): Promise<void>; | ||
/** | ||
* adds a interaction | ||
@@ -105,0 +125,0 @@ * @see https://pactumjs.github.io/guides/mock-server.html |
@@ -6,2 +6,4 @@ const Interaction = require('../models/Interaction.model'); | ||
const remote = require('../helpers/remoteServer'); | ||
const helper = require('../helpers/helper'); | ||
const fs = require('fs'); | ||
@@ -15,3 +17,3 @@ const config = require('../config'); | ||
start(port, host) { | ||
this.setDefaults(port, host) | ||
this.setDefaults({port, host}) | ||
return this._server.start(); | ||
@@ -24,3 +26,4 @@ }, | ||
setDefaults(port, host) { | ||
setDefaults(options) { | ||
const {port, host, httpsOpts} = options; | ||
if (port && typeof port !== 'number') { | ||
@@ -38,2 +41,15 @@ throw new PactumConfigurationError(`Invalid port number provided - ${port}`); | ||
} | ||
if (httpsOpts && helper.isValidObject(httpsOpts)) { | ||
if (httpsOpts.key && !fs.existsSync(httpsOpts.key)) { | ||
throw new PactumConfigurationError(`Invalid key provided or key doesn't exist - ${httpsOpts.key}`); | ||
} | ||
if (httpsOpts.cert && !fs.existsSync(httpsOpts.cert)) { | ||
throw new PactumConfigurationError(`Invalid cert provided or cert doesn't exist - ${httpsOpts.cert}`); | ||
} | ||
if (httpsOpts.cert && httpsOpts.key) { | ||
config.mock.isHttps = true; | ||
config.mock.httpsOpts.key = fs.readFileSync(httpsOpts.key); | ||
config.mock.httpsOpts.cert = fs.readFileSync(httpsOpts.cert); | ||
} | ||
} | ||
}, | ||
@@ -40,0 +56,0 @@ |
@@ -0,1 +1,2 @@ | ||
const lc = require('lightcookie'); | ||
const jqy = require('json-query'); | ||
@@ -26,2 +27,9 @@ | ||
data = request.headers; | ||
} else if (path.startsWith('req.cookies')) { | ||
path = path.replace('req.cookies', ''); | ||
if (!request.headers) { | ||
request.headers = {}; | ||
} | ||
const cookies = lc.parse(request.headers['cookie']); | ||
data = cookies; | ||
} else if (path.startsWith('req.body')) { | ||
@@ -33,2 +41,9 @@ path = path.replace('req.body', ''); | ||
data = response.headers; | ||
} else if (path.startsWith('res.cookies')) { | ||
path = path.replace('res.cookies', ''); | ||
if (!response.headers) { | ||
response.headers = {}; | ||
} | ||
const cookies = lc.parse(response.headers['set-cookie']); | ||
data = cookies; | ||
} else { | ||
@@ -35,0 +50,0 @@ path = path.replace('res.body', ''); |
@@ -0,1 +1,2 @@ | ||
const lc = require('lightcookie'); | ||
const { setMatchingRules, getValue } = require('pactum-matchers').utils; | ||
@@ -122,2 +123,9 @@ const processor = require('../helpers/dataProcessor'); | ||
} | ||
if (request.cookies && typeof request.cookies === 'object') { | ||
const cookie = lc.serialize(request.cookies); | ||
if(!this.headers) { | ||
this.headers = {}; | ||
} | ||
this.headers['cookie'] = cookie; | ||
} | ||
if (request.queryParams && typeof request.queryParams === 'object') { | ||
@@ -165,2 +173,9 @@ setMatchingRules(this.matchingRules, request.queryParams, '$.query'); | ||
this.body = getValue(response.body); | ||
if(response.cookies) { | ||
const cookie = lc.serialize(response.cookies); | ||
if(!this.headers) { | ||
this.headers = {}; | ||
} | ||
this.headers['set-cookie'] = cookie; | ||
} | ||
if (response.fixedDelay) { | ||
@@ -167,0 +182,0 @@ this.delay = new InteractionResponseDelay('FIXED', response.fixedDelay); |
const polka = require('polka'); | ||
const http = require('http'); | ||
const https = require('https'); | ||
const fs = require('fs'); | ||
@@ -22,2 +24,3 @@ const mime = require('mime-lite') | ||
this.interactions = new Map(); | ||
this.server = null; | ||
} | ||
@@ -27,3 +30,3 @@ | ||
return new Promise((resolve) => { | ||
if (!this.app) { | ||
if (!this.app || !this.server) { | ||
this.app = polka(); | ||
@@ -33,4 +36,10 @@ this.app.use(bodyParser); | ||
registerAllRoutes(this, this.app); | ||
this.app.listen(config.mock.port, () => { | ||
log.info(`Mock server is listening on http://localhost:${config.mock.port}`); | ||
if(config.mock.isHttps) { | ||
const {key, cert} = config.mock.httpsOpts; | ||
this.server = https.createServer({key: key, cert: cert}, this.app.handler); | ||
} else { | ||
this.server = http.createServer(this.app.handler); | ||
} | ||
this.server.listen(config.mock.port, () => { | ||
log.info(`Mock server is listening on ${config.mock.isHttps ? " https" : "http"}://${config.mock.host}:${config.mock.port}`); | ||
this._registerEvents(); | ||
@@ -48,5 +57,6 @@ resolve(); | ||
return new Promise((resolve) => { | ||
if (this.app) { | ||
this.app.server.close(() => { | ||
if (this.server) { | ||
this.server.close(() => { | ||
this.app = null; | ||
this.server = null; | ||
log.info(`Mock server stopped on port ${config.mock.port}`); | ||
@@ -53,0 +63,0 @@ resolve(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
168526
5050
9
3
Updated@exodus/schemasafe@^1.2.3
Updatedklona@^2.0.6
Updatedpactum-matchers@^1.1.6