makiwara 2.1.3 → 2.1.5
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.
- package/README.md +6 -6
- package/bin/cli.js +2 -2
- package/package.json +17 -15
- package/src/color-logs.js +4 -4
- package/src/display.js +22 -19
- package/src/local-fetch.js +10 -10
- package/src/make-requests.js +13 -14
- package/src/object-util.js +2 -6
package/README.md
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/makiwara)
|
|
4
4
|
[](https://badge.fury.io/js/makiwara)
|
|
5
5
|
[](https://www.npmjs.com/package/makiwara)
|
|
6
|
-
[](https://
|
|
7
|
-
[](https://piecioshka.mit-license.org)
|
|
7
|
+
[](https://github.com/piecioshka/makiwara/actions/workflows/testing.yml)
|
|
8
8
|
|
|
9
9
|
:hammer: Benchmark URL to gain HTTP requests limits
|
|
10
10
|
|
|
@@ -19,7 +19,7 @@ npm install -g makiwara
|
|
|
19
19
|
```javascript
|
|
20
20
|
const { attack } = require('makiwara');
|
|
21
21
|
|
|
22
|
-
attack('
|
|
22
|
+
attack('https://example.org', [1, 5, 10], 'sequence')
|
|
23
23
|
.then((result) => {
|
|
24
24
|
console.log(result);
|
|
25
25
|
})
|
|
@@ -36,11 +36,11 @@ makiwara --help
|
|
|
36
36
|
Usage: cli [options]
|
|
37
37
|
|
|
38
38
|
Example:
|
|
39
|
-
makiwara -u
|
|
39
|
+
makiwara -u https://localhost:3000 -t 10 -s sequence
|
|
40
40
|
|
|
41
41
|
Options:
|
|
42
42
|
-V, --version output the version number
|
|
43
|
-
-u, --url <url> Define URL to attack. Ex.
|
|
43
|
+
-u, --url <url> Define URL to attack. Ex. https://example.org/
|
|
44
44
|
-t, --timelimit [numbers] Define list of time thresholds (in seconds). Ex. 10,100,1000
|
|
45
45
|
-s, --strategy <concurrent|sequence> Define strategy for making requests
|
|
46
46
|
-h, --help output usage information
|
|
@@ -101,4 +101,4 @@ npm run coverage
|
|
|
101
101
|
|
|
102
102
|
## License
|
|
103
103
|
|
|
104
|
-
[The MIT License](
|
|
104
|
+
[The MIT License](https://piecioshka.mit-license.org) @ 2017-2019
|
package/bin/cli.js
CHANGED
|
@@ -26,10 +26,10 @@ const STRATEGY_REGEXP = /^(concurrent|sequence)$/;
|
|
|
26
26
|
|
|
27
27
|
program
|
|
28
28
|
.version(pkg.version)
|
|
29
|
-
.option('-u, --url <url>', 'Define URL to attack. Ex.
|
|
29
|
+
.option('-u, --url <url>', 'Define URL to attack. Ex. https://example.org/')
|
|
30
30
|
.option('-t, --timelimit [numbers]', 'Define list of time thresholds (in seconds). Ex. 10,100,1000')
|
|
31
31
|
.option('-s, --strategy <concurrent|sequence>', 'Define strategy for making requests')
|
|
32
|
-
.description('Example:\n\tmakiwara -u
|
|
32
|
+
.description('Example:\n\tmakiwara -u https://localhost:3000 -t 10 -s sequence')
|
|
33
33
|
.parse(process.argv);
|
|
34
34
|
|
|
35
35
|
if (typeof program.url !== 'string') {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "makiwara",
|
|
3
3
|
"description": "Benchmark URL to gain HTTP requests limits",
|
|
4
|
-
"version": "2.1.
|
|
4
|
+
"version": "2.1.5",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Piotr Kowalski",
|
|
@@ -18,32 +18,32 @@
|
|
|
18
18
|
"prepare": "npm run snyk-protect"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@types/node": "^
|
|
21
|
+
"@types/node": "^22.7.5",
|
|
22
22
|
"ansi-bold": "^0.1.1",
|
|
23
23
|
"ansi-cyan": "^0.1.1",
|
|
24
24
|
"ansi-gray": "^0.1.1",
|
|
25
25
|
"ansi-red": "^0.1.1",
|
|
26
26
|
"ansi-yellow": "^0.1.1",
|
|
27
|
-
"axios": "^
|
|
28
|
-
"commander": "^
|
|
29
|
-
"http-status-codes": "^2.
|
|
27
|
+
"axios": "^1.7.7",
|
|
28
|
+
"commander": "^12.1.0",
|
|
29
|
+
"http-status-codes": "^2.3.0",
|
|
30
30
|
"is-url": "^1.2.4",
|
|
31
|
-
"node-fetch": "^3.
|
|
32
|
-
"ora": "^
|
|
33
|
-
"snyk": "^1.
|
|
34
|
-
"table": "^6.8.
|
|
31
|
+
"node-fetch": "^3.3.2",
|
|
32
|
+
"ora": "^8.1.0",
|
|
33
|
+
"snyk": "^1.1293.1",
|
|
34
|
+
"table": "^6.8.2"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@types/jasmine": "^
|
|
37
|
+
"@types/jasmine": "^5.1.4",
|
|
38
38
|
"eslint": "^8.6.0",
|
|
39
|
-
"eslint-config-piecioshka": "^2.
|
|
40
|
-
"jasmine": "^4.0
|
|
41
|
-
"nock": "^13.
|
|
39
|
+
"eslint-config-piecioshka": "^2.3.1",
|
|
40
|
+
"jasmine": "^5.4.0",
|
|
41
|
+
"nock": "^13.5.5",
|
|
42
42
|
"nyc": "^15.1.0"
|
|
43
43
|
},
|
|
44
44
|
"repository": {
|
|
45
45
|
"type": "git",
|
|
46
|
-
"url": "https://github.com/piecioshka/makiwara.git"
|
|
46
|
+
"url": "git+https://github.com/piecioshka/makiwara.git"
|
|
47
47
|
},
|
|
48
48
|
"bugs": {
|
|
49
49
|
"url": "https://github.com/piecioshka/makiwara/issues"
|
|
@@ -71,6 +71,8 @@
|
|
|
71
71
|
"commonjs"
|
|
72
72
|
],
|
|
73
73
|
"main": "./index.js",
|
|
74
|
-
"bin":
|
|
74
|
+
"bin": {
|
|
75
|
+
"makiwara": "bin/cli.js"
|
|
76
|
+
},
|
|
75
77
|
"snyk": true
|
|
76
78
|
}
|
package/src/color-logs.js
CHANGED
|
@@ -3,10 +3,10 @@ function setupColorLogFunction(name) {
|
|
|
3
3
|
console[name] = (...args) => console.log(...args.map(fn));
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
setupColorLogFunction(
|
|
7
|
-
setupColorLogFunction(
|
|
8
|
-
setupColorLogFunction(
|
|
9
|
-
setupColorLogFunction(
|
|
6
|
+
setupColorLogFunction("red");
|
|
7
|
+
setupColorLogFunction("yellow");
|
|
8
|
+
setupColorLogFunction("gray");
|
|
9
|
+
setupColorLogFunction("cyan");
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @type console
|
package/src/display.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
const { table } = require(
|
|
2
|
-
const HTTPStatusCodes = require(
|
|
3
|
-
const bold = require(
|
|
1
|
+
const { table } = require("table");
|
|
2
|
+
const HTTPStatusCodes = require("http-status-codes");
|
|
3
|
+
const bold = require("ansi-bold");
|
|
4
4
|
|
|
5
|
-
const { collapseArray } = require(
|
|
5
|
+
const { collapseArray } = require("./object-util");
|
|
6
6
|
|
|
7
7
|
const SECOND_IN_MILLISECONDS = 1000;
|
|
8
8
|
|
|
9
9
|
const tableOptions = {
|
|
10
10
|
columns: {
|
|
11
11
|
0: { width: 22 },
|
|
12
|
-
1: { width: 30 }
|
|
13
|
-
}
|
|
12
|
+
1: { width: 30 },
|
|
13
|
+
},
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
function appendHttpStatusCodeLabel(statusCodeEntries) {
|
|
17
|
-
statusCodeEntries.forEach(entry => {
|
|
17
|
+
statusCodeEntries.forEach((entry) => {
|
|
18
18
|
let label = null;
|
|
19
19
|
try {
|
|
20
20
|
label = HTTPStatusCodes.getStatusText(entry[0]);
|
|
21
21
|
} catch (err) {
|
|
22
22
|
console.red(err);
|
|
23
23
|
}
|
|
24
|
-
if (typeof label ===
|
|
24
|
+
if (typeof label === "string") {
|
|
25
25
|
entry[0] = `${entry[0]} ${label}`;
|
|
26
26
|
}
|
|
27
27
|
});
|
|
@@ -29,28 +29,31 @@ function appendHttpStatusCodeLabel(statusCodeEntries) {
|
|
|
29
29
|
|
|
30
30
|
function displayRequestsSummary(attackResults) {
|
|
31
31
|
const statusCodes = collapseArray(
|
|
32
|
-
attackResults.requests.map(r => r.status)
|
|
32
|
+
attackResults.requests.map((r) => r.status)
|
|
33
33
|
);
|
|
34
|
-
const isEmptyResults =
|
|
34
|
+
const isEmptyResults = statusCodes.length === 0;
|
|
35
35
|
|
|
36
36
|
if (isEmptyResults) {
|
|
37
|
-
statusCodes[
|
|
37
|
+
statusCodes["-"] = -1;
|
|
38
38
|
} else {
|
|
39
39
|
appendHttpStatusCodeLabel(statusCodes);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
const data = [[
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
const data = [["HTTP Status Code", "Requests quantity"].map(bold)].concat(
|
|
43
|
+
statusCodes
|
|
44
|
+
);
|
|
45
45
|
console.log(table(data, tableOptions));
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
function displayAttackSummary(results) {
|
|
49
49
|
const meta = [];
|
|
50
|
-
meta.push([
|
|
51
|
-
const durationInSeconds =
|
|
52
|
-
meta.push([
|
|
53
|
-
|
|
50
|
+
meta.push(["Type", results.type]);
|
|
51
|
+
const durationInSeconds = results.duration / SECOND_IN_MILLISECONDS;
|
|
52
|
+
meta.push([
|
|
53
|
+
"Effective Duration",
|
|
54
|
+
`${durationInSeconds.toLocaleString()} seconds`,
|
|
55
|
+
]);
|
|
56
|
+
meta.push(["Times", `${results.times}`]);
|
|
54
57
|
console.log(table(meta, tableOptions));
|
|
55
58
|
}
|
|
56
59
|
|
|
@@ -65,5 +68,5 @@ function displayError(err) {
|
|
|
65
68
|
|
|
66
69
|
module.exports = {
|
|
67
70
|
displaySummary,
|
|
68
|
-
displayError
|
|
71
|
+
displayError,
|
|
69
72
|
};
|
package/src/local-fetch.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const http = require(
|
|
2
|
-
const https = require(
|
|
1
|
+
const http = require("http");
|
|
2
|
+
const https = require("https");
|
|
3
3
|
|
|
4
|
-
const IS_HTTP =
|
|
4
|
+
const IS_HTTP = /^https/;
|
|
5
5
|
|
|
6
6
|
function getProtocol(url) {
|
|
7
7
|
if (IS_HTTP.test(url)) {
|
|
@@ -12,20 +12,20 @@ function getProtocol(url) {
|
|
|
12
12
|
|
|
13
13
|
async function makeRequest(url, options = {}) {
|
|
14
14
|
const response = {
|
|
15
|
-
status:
|
|
16
|
-
text:
|
|
15
|
+
status: 0,
|
|
16
|
+
text: "",
|
|
17
17
|
};
|
|
18
18
|
const protocol = getProtocol(url);
|
|
19
19
|
return new Promise((resolve, reject) => {
|
|
20
|
-
protocol.get(url, options, res => {
|
|
21
|
-
res.addListener(
|
|
20
|
+
protocol.get(url, options, (res) => {
|
|
21
|
+
res.addListener("data", (data) => {
|
|
22
22
|
response.text += data.toString();
|
|
23
23
|
});
|
|
24
|
-
res.addListener(
|
|
24
|
+
res.addListener("error", (err) => {
|
|
25
25
|
reject(err);
|
|
26
26
|
});
|
|
27
|
-
res.addListener(
|
|
28
|
-
response.status = res.statusCode;
|
|
27
|
+
res.addListener("end", () => {
|
|
28
|
+
response.status = Number(res.statusCode);
|
|
29
29
|
resolve(response);
|
|
30
30
|
});
|
|
31
31
|
});
|
package/src/make-requests.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
const http = require(
|
|
1
|
+
const http = require("http");
|
|
2
2
|
|
|
3
3
|
// const makeRequest = require('node-fetch');
|
|
4
|
-
const makeRequest = require(
|
|
4
|
+
const makeRequest = require("./local-fetch");
|
|
5
5
|
|
|
6
6
|
const SECOND_IN_MILLISECONDS = 1000;
|
|
7
7
|
|
|
8
8
|
function pause(timeoutInSeconds) {
|
|
9
|
-
return new Promise(resolve => {
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
10
|
setTimeout(resolve, timeoutInSeconds * SECOND_IN_MILLISECONDS);
|
|
11
11
|
});
|
|
12
12
|
}
|
|
@@ -20,7 +20,7 @@ function status(i) {
|
|
|
20
20
|
|
|
21
21
|
async function makeRequestsInConcurrentMode(url, durationInSeconds) {
|
|
22
22
|
if (isNaN(durationInSeconds)) {
|
|
23
|
-
throw new TypeError(
|
|
23
|
+
throw new TypeError("duration should be a number (ex. 1,3,5)");
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
const requests = [];
|
|
@@ -44,10 +44,9 @@ async function makeRequestsInConcurrentMode(url, durationInSeconds) {
|
|
|
44
44
|
|
|
45
45
|
status(i);
|
|
46
46
|
|
|
47
|
-
await makeRequest(url, { agent: false })
|
|
48
|
-
.
|
|
49
|
-
|
|
50
|
-
});
|
|
47
|
+
await makeRequest(url, { agent: false }).then((response) => {
|
|
48
|
+
requests.push(response);
|
|
49
|
+
});
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
const endTime = Date.now();
|
|
@@ -56,18 +55,18 @@ async function makeRequestsInConcurrentMode(url, durationInSeconds) {
|
|
|
56
55
|
await pause(durationInSeconds);
|
|
57
56
|
|
|
58
57
|
return {
|
|
59
|
-
type:
|
|
58
|
+
type: "Concurrent",
|
|
60
59
|
startTime,
|
|
61
60
|
endTime,
|
|
62
61
|
duration: wholeProcessDuration,
|
|
63
62
|
times: i,
|
|
64
|
-
requests
|
|
63
|
+
requests,
|
|
65
64
|
};
|
|
66
65
|
}
|
|
67
66
|
|
|
68
67
|
async function makeRequestsInSequenceMode(url, durationInSeconds) {
|
|
69
68
|
if (isNaN(durationInSeconds)) {
|
|
70
|
-
throw new TypeError(
|
|
69
|
+
throw new TypeError("duration should be a number (ex. 1,3,5)");
|
|
71
70
|
}
|
|
72
71
|
|
|
73
72
|
const requests = [];
|
|
@@ -95,17 +94,17 @@ async function makeRequestsInSequenceMode(url, durationInSeconds) {
|
|
|
95
94
|
const wholeProcessDuration = endTime - startTime;
|
|
96
95
|
|
|
97
96
|
return {
|
|
98
|
-
type:
|
|
97
|
+
type: "Sequence",
|
|
99
98
|
startTime,
|
|
100
99
|
endTime,
|
|
101
100
|
duration: wholeProcessDuration,
|
|
102
101
|
times: i,
|
|
103
|
-
requests
|
|
102
|
+
requests,
|
|
104
103
|
};
|
|
105
104
|
}
|
|
106
105
|
|
|
107
106
|
module.exports = {
|
|
108
107
|
makeRequest,
|
|
109
108
|
makeRequestsInSequenceMode,
|
|
110
|
-
makeRequestsInConcurrentMode
|
|
109
|
+
makeRequestsInConcurrentMode,
|
|
111
110
|
};
|
package/src/object-util.js
CHANGED
|
@@ -9,13 +9,9 @@ function collapseArray(array) {
|
|
|
9
9
|
|
|
10
10
|
const entries = Object.entries(hashMap);
|
|
11
11
|
|
|
12
|
-
entries.
|
|
13
|
-
entry[0] = Number(entry[0]);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
return entries;
|
|
12
|
+
return entries.map((entry) => Number(entry[0]));
|
|
17
13
|
}
|
|
18
14
|
|
|
19
15
|
module.exports = {
|
|
20
|
-
collapseArray
|
|
16
|
+
collapseArray,
|
|
21
17
|
};
|