#!/usr/bin/env node /** * Test enhanced authentication features in Docker */ const { db } = require('../src/database/db'); const { checkAccountLockout, trackFailedAttempt, trackSuccessfulLogin } = require('../src/utils/authSecurity'); console.log('=== Testing Enhanced Auth Features ===\n'); async function testAuthFeatures() { try { // Test 1: Check if tables exist console.log('1. Checking database tables...'); const loginAttempts = await db('login_attempts').count().first(); console.log('✓ login_attempts table exists'); // Test 2: Test failed attempt tracking console.log('\n2. Testing failed attempt tracking...'); await trackFailedAttempt('test-user', '127.0.0.1', 'Test User Agent'); const attempts = await db('login_attempts') .where('identifier', 'test-user') .count() .first(); console.log(`✓ Failed attempt tracked (${attempts.count} total)`); // Test 3: Test lockout check console.log('\n3. Testing lockout detection...'); // Add 4 more failures to trigger lockout for (let i = 0; i < 4; i++) { await trackFailedAttempt('test-user', '127.0.0.1', 'Test User Agent'); } const lockoutStatus = await checkAccountLockout('test-user'); console.log(`✓ Lockout check works: ${lockoutStatus.isLocked ? 'LOCKED' : 'NOT LOCKED'}`); if (lockoutStatus.isLocked) { console.log(` Remaining lockout time: ${lockoutStatus.remainingTime} seconds`); } // Test 4: Test successful login tracking console.log('\n4. Testing successful login tracking...'); await trackSuccessfulLogin('test-user', '127.0.0.1', 'Test User Agent'); console.log('✓ Successful login tracked'); // Test 5: Check if auth routes load console.log('\n5. Testing enhanced auth routes...'); try { const authRoutes = require('../src/routes/auth-enhanced'); console.log('✓ Enhanced auth routes load successfully'); } catch (e) { console.log('✗ Error loading enhanced auth routes:', e.message); } // Clean up test data await db('login_attempts').where('identifier', 'test-user').delete(); console.log('\n✓ Test data cleaned up'); console.log('\n✅ Enhanced auth features are working correctly!'); console.log('\nNext step: Update server.js to use enhanced auth routes'); } catch (error) { console.error('\n❌ Test failed:', error); } finally { await db.destroy(); } } testAuthFeatures();