UNPKG

aimless-sdk

Version:

Enhanced Runtime Application Self-Protection (RASP) and API Fuzzing Engine with advanced threat detection, behavioral analysis, and intelligent response scoring for Node.js applications

142 lines (125 loc) • 4.21 kB
#!/usr/bin/env node /** * Quick validation script for pre-publish checks * Runs all critical tests before publishing to NPM */ const { execSync } = require('child_process'); console.log('šŸ” Running Pre-Publish Validation...\n'); let exitCode = 0; function run(command, description) { console.log(`\nšŸ“‹ ${description}...`); try { const output = execSync(command, { encoding: 'utf8', stdio: 'inherit' }); console.log(`āœ… ${description} - PASSED`); return true; } catch (error) { console.error(`āŒ ${description} - FAILED`); exitCode = 1; return false; } } // 1. Build check run('npm run build', 'TypeScript Compilation'); // 2. Test suite run('npm test', 'Serverless Compatibility Tests'); // 3. Import verification run('npm run verify', 'Package Import Verification'); // 4. Smoke test - SQL injection detection console.log('\nšŸ“‹ Smoke Test - SQL Injection Detection...'); try { const { Aimless } = require('./dist/index.js'); const aimless = new Aimless(); const safe = aimless.isSafe("' OR 1=1--"); if (safe) { throw new Error('Failed to detect SQL injection'); } console.log('āœ… Smoke Test - SQL Injection Detection - PASSED'); } catch (error) { console.error('āŒ Smoke Test - SQL Injection Detection - FAILED'); console.error(' Error:', error.message); exitCode = 1; } // 5. Smoke test - XSS detection console.log('\nšŸ“‹ Smoke Test - XSS Detection...'); try { const { Aimless } = require('./dist/index.js'); const aimless = new Aimless(); const safe = aimless.isSafe("<script>alert('xss')</script>"); if (safe) { throw new Error('Failed to detect XSS'); } console.log('āœ… Smoke Test - XSS Detection - PASSED'); } catch (error) { console.error('āŒ Smoke Test - XSS Detection - FAILED'); console.error(' Error:', error.message); exitCode = 1; } // 6. Smoke test - Safe input console.log('\nšŸ“‹ Smoke Test - Safe Input Recognition...'); try { const { Aimless } = require('./dist/index.js'); const aimless = new Aimless(); const safe = aimless.isSafe("Hello, World!"); if (!safe) { throw new Error('Safe input marked as unsafe'); } console.log('āœ… Smoke Test - Safe Input Recognition - PASSED'); } catch (error) { console.error('āŒ Smoke Test - Safe Input Recognition - FAILED'); console.error(' Error:', error.message); exitCode = 1; } // 7. File structure check console.log('\nšŸ“‹ File Structure Check...'); const fs = require('fs'); const requiredFiles = [ 'dist/index.js', 'dist/index.d.ts', 'dist/rasp/index.js', 'dist/middleware/express.js', 'README.md', 'LICENSE', 'package.json' ]; let structureOk = true; for (const file of requiredFiles) { if (!fs.existsSync(file)) { console.error(` āŒ Missing: ${file}`); structureOk = false; exitCode = 1; } } if (structureOk) { console.log('āœ… File Structure Check - PASSED'); } // 8. Version consistency check console.log('\nšŸ“‹ Version Consistency Check...'); try { const packageJson = require('./package.json'); const version = packageJson.version; const readmeContent = fs.readFileSync('README.md', 'utf8'); const changelogContent = fs.readFileSync('CHANGELOG.md', 'utf8'); if (!readmeContent.includes(version)) { console.warn(` āš ļø Version ${version} not mentioned in README.md`); } if (!changelogContent.includes(version)) { console.warn(` āš ļø Version ${version} not in CHANGELOG.md`); } console.log(`āœ… Version Consistency Check - PASSED (v${version})`); } catch (error) { console.error('āŒ Version Consistency Check - FAILED'); console.error(' Error:', error.message); exitCode = 1; } // Final summary console.log('\n' + '='.repeat(60)); if (exitCode === 0) { console.log('šŸŽ‰ ALL VALIDATION CHECKS PASSED!'); console.log('āœ… Package is ready for publishing'); console.log('\nTo publish, run: npm publish'); } else { console.log('āŒ VALIDATION FAILED!'); console.log('āš ļø Fix the issues above before publishing'); } console.log('='.repeat(60) + '\n'); process.exit(exitCode);