mpx-scan 1.0.0 → 1.0.1
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/.github/workflows/ci.yml +19 -0
- package/.github/workflows/publish.yml +21 -0
- package/.gitignore +6 -0
- package/.npmignore +7 -0
- package/package.json +5 -4
- package/test/run.js +156 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [master]
|
|
5
|
+
pull_request:
|
|
6
|
+
branches: [master]
|
|
7
|
+
jobs:
|
|
8
|
+
test:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
strategy:
|
|
11
|
+
matrix:
|
|
12
|
+
node-version: [18, 20, 22]
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-node@v4
|
|
16
|
+
with:
|
|
17
|
+
node-version: ${{ matrix.node-version }}
|
|
18
|
+
- run: npm ci
|
|
19
|
+
- run: npm test
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: Publish to npm
|
|
2
|
+
on:
|
|
3
|
+
release:
|
|
4
|
+
types: [published]
|
|
5
|
+
jobs:
|
|
6
|
+
publish:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
id-token: write
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- uses: actions/setup-node@v4
|
|
14
|
+
with:
|
|
15
|
+
node-version: 22
|
|
16
|
+
registry-url: https://registry.npmjs.org
|
|
17
|
+
- run: npm ci
|
|
18
|
+
- run: npm test
|
|
19
|
+
- run: npm publish --access public --provenance
|
|
20
|
+
env:
|
|
21
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/.gitignore
ADDED
package/.npmignore
ADDED
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mpx-scan",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Professional website security scanner CLI. Check headers, SSL, cookies, DNS, and get actionable fix suggestions. Part of the Mesaplex developer toolchain.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"mpx-scan": "
|
|
7
|
+
"mpx-scan": "bin/cli.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"test": "node test/run.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"license": "SEE LICENSE IN LICENSE",
|
|
32
32
|
"repository": {
|
|
33
33
|
"type": "git",
|
|
34
|
-
"url": "https://github.com/mesaplexdev/mpx-scan"
|
|
34
|
+
"url": "git+https://github.com/mesaplexdev/mpx-scan.git"
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/mesaplexdev/mpx-scan#readme",
|
|
37
37
|
"bugs": "https://github.com/mesaplexdev/mpx-scan/issues",
|
|
@@ -41,5 +41,6 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"chalk": "^4.1.2",
|
|
43
43
|
"commander": "^12.0.0"
|
|
44
|
-
}
|
|
44
|
+
},
|
|
45
|
+
"files": "[\"src/\",\"bin/\",\"README.md\",\"LICENSE\",\"package.json\"]"
|
|
45
46
|
}
|
package/test/run.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Test Suite for mpx-scan
|
|
5
|
+
*
|
|
6
|
+
* Zero-dependency test runner. Tests core scanning logic.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const { scan, calculateGrade, scoreToPercentage } = require('../src/index');
|
|
10
|
+
const { getLicense, activateLicense, deactivateLicense } = require('../src/license');
|
|
11
|
+
|
|
12
|
+
let passed = 0;
|
|
13
|
+
let failed = 0;
|
|
14
|
+
|
|
15
|
+
function test(name, fn) {
|
|
16
|
+
process.stdout.write(` ${name} ... `);
|
|
17
|
+
try {
|
|
18
|
+
fn();
|
|
19
|
+
console.log('✓');
|
|
20
|
+
passed++;
|
|
21
|
+
} catch (err) {
|
|
22
|
+
console.log('✗');
|
|
23
|
+
console.error(` ${err.message}`);
|
|
24
|
+
failed++;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function asyncTest(name, fn) {
|
|
29
|
+
process.stdout.write(` ${name} ... `);
|
|
30
|
+
try {
|
|
31
|
+
await fn();
|
|
32
|
+
console.log('✓');
|
|
33
|
+
passed++;
|
|
34
|
+
} catch (err) {
|
|
35
|
+
console.log('✗');
|
|
36
|
+
console.error(` ${err.message}`);
|
|
37
|
+
failed++;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function assert(condition, message) {
|
|
42
|
+
if (!condition) {
|
|
43
|
+
throw new Error(message || 'Assertion failed');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function assertEqual(actual, expected, message) {
|
|
48
|
+
if (actual !== expected) {
|
|
49
|
+
throw new Error(`${message || 'Assertion failed'}: expected ${expected}, got ${actual}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function runTests() {
|
|
54
|
+
console.log('\n🧪 Running mpx-scan tests...\n');
|
|
55
|
+
|
|
56
|
+
// Grade calculation tests
|
|
57
|
+
console.log('Grade Calculation:');
|
|
58
|
+
test('calculateGrade(1.0) returns A+', () => {
|
|
59
|
+
assertEqual(calculateGrade(1.0), 'A+');
|
|
60
|
+
});
|
|
61
|
+
test('calculateGrade(0.95) returns A+', () => {
|
|
62
|
+
assertEqual(calculateGrade(0.95), 'A+');
|
|
63
|
+
});
|
|
64
|
+
test('calculateGrade(0.85) returns A', () => {
|
|
65
|
+
assertEqual(calculateGrade(0.85), 'A');
|
|
66
|
+
});
|
|
67
|
+
test('calculateGrade(0.70) returns B', () => {
|
|
68
|
+
assertEqual(calculateGrade(0.70), 'B');
|
|
69
|
+
});
|
|
70
|
+
test('calculateGrade(0.55) returns C', () => {
|
|
71
|
+
assertEqual(calculateGrade(0.55), 'C');
|
|
72
|
+
});
|
|
73
|
+
test('calculateGrade(0.40) returns D', () => {
|
|
74
|
+
assertEqual(calculateGrade(0.40), 'D');
|
|
75
|
+
});
|
|
76
|
+
test('calculateGrade(0.30) returns F', () => {
|
|
77
|
+
assertEqual(calculateGrade(0.30), 'F');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Score percentage tests
|
|
81
|
+
console.log('\nScore Calculation:');
|
|
82
|
+
test('scoreToPercentage(50, 100) returns 50', () => {
|
|
83
|
+
assertEqual(scoreToPercentage(50, 100), 50);
|
|
84
|
+
});
|
|
85
|
+
test('scoreToPercentage(0, 100) returns 0', () => {
|
|
86
|
+
assertEqual(scoreToPercentage(0, 100), 0);
|
|
87
|
+
});
|
|
88
|
+
test('scoreToPercentage(100, 100) returns 100', () => {
|
|
89
|
+
assertEqual(scoreToPercentage(100, 100), 100);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// License tests
|
|
93
|
+
console.log('\nLicense Management:');
|
|
94
|
+
test('getLicense() returns free tier by default', () => {
|
|
95
|
+
const license = getLicense();
|
|
96
|
+
assertEqual(license.tier, 'free');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('activateLicense() requires MPX-PRO prefix', () => {
|
|
100
|
+
let error = null;
|
|
101
|
+
try {
|
|
102
|
+
activateLicense('INVALID-KEY');
|
|
103
|
+
} catch (err) {
|
|
104
|
+
error = err;
|
|
105
|
+
}
|
|
106
|
+
assert(error !== null, 'Should throw error for invalid key');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Scan tests (basic validation)
|
|
110
|
+
console.log('\nScanning (basic validation):');
|
|
111
|
+
await asyncTest('scan() returns valid result structure', async () => {
|
|
112
|
+
const result = await scan('https://example.com', { timeout: 5000, tier: 'free' });
|
|
113
|
+
assert(result.url, 'Should have url');
|
|
114
|
+
assert(result.hostname, 'Should have hostname');
|
|
115
|
+
assert(result.grade, 'Should have grade');
|
|
116
|
+
assert(typeof result.score === 'number', 'Should have numeric score');
|
|
117
|
+
assert(result.sections, 'Should have sections');
|
|
118
|
+
assert(result.summary, 'Should have summary');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
await asyncTest('scan() handles timeout gracefully', async () => {
|
|
122
|
+
// Test with very short timeout to simulate network error
|
|
123
|
+
let error = null;
|
|
124
|
+
try {
|
|
125
|
+
await scan('https://example.com', { timeout: 1, tier: 'free' });
|
|
126
|
+
} catch (err) {
|
|
127
|
+
error = err;
|
|
128
|
+
}
|
|
129
|
+
// Either succeeds very fast or times out - both are acceptable
|
|
130
|
+
assert(true, 'Timeout handling works');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
await asyncTest('scan() respects tier limits', async () => {
|
|
134
|
+
const freeResult = await scan('https://example.com', { timeout: 5000, tier: 'free' });
|
|
135
|
+
const freeSections = Object.keys(freeResult.sections);
|
|
136
|
+
|
|
137
|
+
// Free tier should only have: headers, ssl, server
|
|
138
|
+
assert(freeSections.includes('headers'), 'Free should include headers');
|
|
139
|
+
assert(freeSections.includes('ssl'), 'Free should include ssl');
|
|
140
|
+
assert(!freeSections.includes('dns'), 'Free should NOT include dns');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Summary
|
|
144
|
+
console.log('\n' + '─'.repeat(50));
|
|
145
|
+
console.log(`Tests: ${passed + failed} total, ${passed} passed, ${failed} failed`);
|
|
146
|
+
console.log('─'.repeat(50) + '\n');
|
|
147
|
+
|
|
148
|
+
if (failed > 0) {
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
runTests().catch(err => {
|
|
154
|
+
console.error('\n❌ Test suite error:', err);
|
|
155
|
+
process.exit(1);
|
|
156
|
+
});
|