mpx-scan 1.0.1 → 1.0.2

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/bin/cli.js CHANGED
@@ -36,6 +36,8 @@ program
36
36
  .option('--brief', 'Brief output (one-line summary)')
37
37
  .option('--fix <platform>', `Generate fix config for platform (${PLATFORMS.join(', ')})`)
38
38
  .option('--timeout <seconds>', 'Connection timeout', '10')
39
+ .option('--ci', 'CI/CD mode: exit 1 if score below threshold')
40
+ .option('--min-score <score>', 'Minimum score for CI mode (default: 70)', '70')
39
41
  .action(async (url, options) => {
40
42
  // Show help if no URL provided
41
43
  if (!url) {
@@ -103,11 +105,21 @@ program
103
105
  console.log(formatReport(results, options));
104
106
  }
105
107
 
106
- // Exit code based on grade (for CI/CD)
107
- const gradeToExitCode = {
108
- 'A+': 0, 'A': 0, 'B': 0, 'C': 0, 'D': 1, 'F': 1
109
- };
110
- process.exit(gradeToExitCode[results.grade] || 1);
108
+ // Exit code logic:
109
+ // - Exit 0: scan completed successfully (default)
110
+ // - Exit 1: only in --ci mode if score below threshold
111
+ if (options.ci) {
112
+ const minScore = parseInt(options.minScore);
113
+ const percentage = Math.round((results.score / results.maxScore) * 100);
114
+ if (percentage < minScore) {
115
+ if (!options.json && !options.brief) {
116
+ console.error(chalk.yellow(`\n⚠️ CI mode: Score ${percentage}/100 below minimum ${minScore}`));
117
+ }
118
+ process.exit(1);
119
+ }
120
+ }
121
+
122
+ process.exit(0);
111
123
 
112
124
  } catch (err) {
113
125
  if (options.json) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mpx-scan",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
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": {
@@ -42,5 +42,11 @@
42
42
  "chalk": "^4.1.2",
43
43
  "commander": "^12.0.0"
44
44
  },
45
- "files": "[\"src/\",\"bin/\",\"README.md\",\"LICENSE\",\"package.json\"]"
45
+ "files": [
46
+ "src/",
47
+ "bin/",
48
+ "README.md",
49
+ "LICENSE",
50
+ "package.json"
51
+ ]
46
52
  }
@@ -176,7 +176,7 @@ function fetchHeaders(parsedUrl, options = {}) {
176
176
  method: 'HEAD',
177
177
  timeout,
178
178
  headers: {
179
- 'User-Agent': 'SiteGuard/0.1 Security Scanner (https://github.com/persio10/siteguard)'
179
+ 'User-Agent': 'mpx-scan/1.0.1 Security Scanner (https://github.com/mesaplexdev/mpx-scan)'
180
180
  },
181
181
  rejectUnauthorized: false // We check SSL separately
182
182
  }, (res) => {
@@ -1,19 +0,0 @@
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
@@ -1,21 +0,0 @@
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 DELETED
@@ -1,6 +0,0 @@
1
- node_modules/
2
- .DS_Store
3
- *.log
4
- .env
5
- .mpx-scan/
6
- test-output-*.txt
package/.npmignore DELETED
@@ -1,7 +0,0 @@
1
- .github/
2
- test/
3
- .git/
4
- .gitignore
5
- node_modules/
6
- .env*
7
- *.test.js
package/test/run.js DELETED
@@ -1,156 +0,0 @@
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
- });