load-tester
Advanced tools
| { | ||
| "baseUrls": [ | ||
| "http://74.125.237.114", | ||
| "http://74.125.237.115", | ||
| "http://74.125.237.116" | ||
| ], | ||
| "headers": { | ||
| "host": "www.google.com.au" | ||
| }, | ||
| "duration": 5000, | ||
| "connections": 1, | ||
| "sequence": [ | ||
| { "path": "/" } | ||
| ] | ||
| } |
+22
-13
@@ -5,2 +5,6 @@ | ||
| var _ = require('lodash'); | ||
| var pkg = require('../package.json'); | ||
| var DEFAULT_HEADERS = { | ||
| 'user-agent': pkg.name+'/'+pkg.version | ||
| }; | ||
@@ -32,8 +36,13 @@ //job class | ||
| if(typeof this.opts.baseUrl === 'string') { | ||
| if(!/^https?:\/\/[^\/]+$/.test(this.opts.baseUrl)) | ||
| return this.cb("'baseUrl' invalid origin, expected only protocol+host+port"); | ||
| } else | ||
| if(_.isArray(this.opts.baseUrls)) | ||
| this.baseUrls = this.opts.baseUrls; | ||
| else if(typeof this.opts.baseUrl === 'string') | ||
| this.baseUrls = [this.opts.baseUrl]; | ||
| else | ||
| return this.cb("requires a 'baseUrl'"); | ||
| for (var i = this.baseUrls.length - 1; i >= 0; i--) | ||
| if(!/^https?:\/\/[^\/]+$/.test(this.baseUrls[i])) | ||
| return this.cb("Invalid origin: '"+this.baseUrls[i]+"', must be http[s]://host:port"); | ||
| this.request = requestLib.defaults({ | ||
@@ -92,2 +101,5 @@ pool: {maxSockets: this.opts.maxSockets} | ||
| reqObj.headers = reqObj.headers || {}; | ||
| _.defaults(reqObj.headers, this.opts.headers, DEFAULT_HEADERS); | ||
| reqObj.method = reqObj.method || 'GET'; | ||
@@ -121,6 +133,8 @@ reqObj.path = reqObj.path || ''; | ||
| var url = this.opts.baseUrl + reqObj.path; | ||
| var path = reqObj.path; | ||
| var url = rand(this.baseUrls) + path; | ||
| var responseTime = Date.now(); | ||
| reqObj = _.pick(reqObj, 'method', 'form', 'followRedirect'); | ||
| //cleanse request object | ||
| reqObj = _.pick(reqObj, 'method', 'form', 'headers', 'followRedirect'); | ||
| reqObj.url = url; | ||
@@ -139,3 +153,3 @@ reqObj.jar = jar; | ||
| ' got: ' + res.statusCode + | ||
| ' (for ' + reqObj.method + ' ' + reqObj.url + ')'; | ||
| ' (for ' + reqObj.method + ' ' + path + ')'; | ||
| else if(expect._re && !expect._re.test(body)) | ||
@@ -146,8 +160,3 @@ err = 'expected body to match regex: ' + expect._re; | ||
| done(null, { | ||
| responseTime: Date.now() - responseTime, | ||
| err: err | ||
| // body: body | ||
| }); | ||
| done(null, { responseTime: Date.now() - responseTime, err: err }); | ||
| }); | ||
@@ -154,0 +163,0 @@ }; |
+1
-1
| { | ||
| "name": "load-tester", | ||
| "version": "0.3.1", | ||
| "version": "0.4.0", | ||
| "description": "A load testing server", | ||
@@ -5,0 +5,0 @@ "main": "server.js", |
+33
-3
@@ -5,3 +5,3 @@ # node-<name>load-tester</end> | ||
| <description>A load testing server</end> | ||
| <description>A load testing server</end> - v<version>0.4.0</end> | ||
@@ -14,2 +14,5 @@ ## Features | ||
| * Control number of runs with `runs` | ||
| * Set custom `headers` | ||
| * Create a set of `baseUrls`, randomly choosing a `baseUrl` to test against | ||
| * Create a set of `forms`, randomly choosing a `form` to POST with | ||
| * Create response expectations based on status code and body contents | ||
@@ -104,3 +107,3 @@ | ||
| Random form data | ||
| #### Random form data | ||
@@ -125,3 +128,3 @@ <showFile("example/random-forms.json")> | ||
| More response expectations | ||
| #### More response expectations | ||
@@ -145,2 +148,29 @@ <showFile("example/expectations.json")> | ||
| #### Simulate load balancer | ||
| <showFile("example/load-balancer.json")> | ||
| ``` json | ||
| { | ||
| "baseUrls": [ | ||
| "http://74.125.237.114", | ||
| "http://74.125.237.115", | ||
| "http://74.125.237.116" | ||
| ], | ||
| "headers": { | ||
| "host": "www.google.com.au" | ||
| }, | ||
| "duration": 5000, | ||
| "connections": 1, | ||
| "sequence": [ | ||
| { "path": "/" } | ||
| ] | ||
| } | ||
| ``` | ||
| </end> | ||
| *Every request will randomly choose one of the `baseUrls`* | ||
| *Requests may also specify a `header` object which will override the job's `header` object* | ||
| <license()> | ||
@@ -147,0 +177,0 @@ #### MIT License |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
17489
8.3%21
5%272
8.8%195
18.18%