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
JavaScript
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 };