UNPKG

bigbasealpha

Version:

Professional Grade Custom Database System - A sophisticated, dependency-free database with encryption, caching, indexing, and web dashboard

129 lines (98 loc) โ€ข 3.92 kB
import BigBaseAlpha from '../src/alpha.js'; /** * Test file for Security & Privacy Suite v1.4.0 */ console.log('๐Ÿงช Testing BigBaseAlpha Security & Privacy Suite v1.4.0\n'); async function testSecuritySuite() { console.log('๐Ÿ”’ Testing Security & Privacy Suite...'.cyan); const alpha = new BigBaseAlpha({ path: './test_security_data', encryption: false, security: { paranoidLogging: true } }); try { await alpha.init(); await alpha.createCollection('security_test'); console.log('โœ… Database initialized'); // Test One-Time Keys console.log('๐Ÿ”‘ Testing One-Time Keys...'); await alpha.setOneTime('test_secret', 'secret_value'); const secret = await alpha.getOneTime('test_secret'); if (secret === 'secret_value') { console.log('โœ… One-Time Keys: PASSED'); } else { throw new Error('One-time key test failed'); } // Test Execution Triggers console.log('๐Ÿงช Testing Execution Triggers...'); let triggerExecuted = false; await alpha.setTrigger('test_trigger', 'trigger_value', { onRead: () => { triggerExecuted = true; } }); await alpha.executeTrigger('test_trigger', 'read'); if (triggerExecuted) { console.log('โœ… Execution Triggers: PASSED'); } else { throw new Error('Execution trigger test failed'); } // Test Paranoia Mode console.log('๐Ÿ‘๏ธ Testing Paranoia Mode...'); const paranoia = alpha.enableParanoia(); await alpha.insert('security_test', { test: 'paranoid_data' }); await alpha.find('security_test'); const logs = paranoia.getLogs(); if (logs.length > 0) { console.log('โœ… Paranoia Mode: PASSED'); } else { throw new Error('Paranoia mode test failed'); } paranoia.disable(); // Test Decoy Mode console.log('๐ŸŽญ Testing Decoy Mode...'); const decoy = alpha.enableDecoy({ password: 'test123', decoyData: { security_test: [{ fake: 'data' }] } }); const wrongAuth = decoy.authenticate('wrong'); const correctAuth = decoy.authenticate('test123'); if (!wrongAuth && correctAuth) { console.log('โœ… Decoy Mode: PASSED'); } else { throw new Error('Decoy mode test failed'); } decoy.disable(); // Test Security Status console.log('๐Ÿ“Š Testing Security Status...'); const status = alpha.getSecurityStatus(); if (typeof status === 'object' && status.hasOwnProperty('paranoia')) { console.log('โœ… Security Status: PASSED'); } else { throw new Error('Security status test failed'); } await alpha.close(); return true; } catch (error) { console.error('โŒ Security Suite test failed:', error.message); return false; } } async function runTests() { try { const result = await testSecuritySuite(); if (result) { console.log('\n๐ŸŽ‰ All Security & Privacy Suite tests passed!'.rainbow); process.exit(0); } else { console.log('\nโŒ Security Suite tests failed!'.red); process.exit(1); } } catch (error) { console.error('๐Ÿ’ฅ Test suite error:', error); process.exit(1); } } // Run tests if this file is executed directly if (import.meta.url === `file://${process.argv[1]}`) { runTests(); } export { testSecuritySuite };