-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-cheating.js
More file actions
79 lines (67 loc) · 2.64 KB
/
test-cheating.js
File metadata and controls
79 lines (67 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const { createClient } = require('@libsql/client')
require('dotenv').config({ path: '.env.local' })
async function testBlockIP() {
console.log('🧪 Testing Block IP Functionality...\n')
const client = createClient({
url: process.env.TURSO_DATABASE_URL,
authToken: process.env.TURSO_AUTH_TOKEN,
})
const testIP = '192.168.1.100'
try {
// Test 1: Block an IP
console.log('1. Blocking test IP:', testIP)
const blockResponse = await fetch('http://localhost:3000/api/admin/security/block-ip', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ip: testIP, reason: 'Test block' })
})
if (blockResponse.ok) {
console.log('✅ IP blocked successfully')
} else {
console.log('❌ Failed to block IP:', await blockResponse.text())
}
// Test 2: Check if IP is in blocked_ips table
console.log('\n2. Verifying IP is blocked in database...')
const blockedCheck = await client.execute('SELECT * FROM blocked_ips WHERE ip = ?', [testIP])
if (blockedCheck.rows.length > 0) {
console.log('✅ IP found in blocked_ips table')
console.log(' Details:', blockedCheck.rows[0])
} else {
console.log('❌ IP not found in blocked_ips table')
}
// Test 3: Check security logs
console.log('\n3. Checking security logs...')
const logsCheck = await client.execute('SELECT * FROM security_logs WHERE type = ? ORDER BY timestamp DESC LIMIT 1', ['ip_block'])
if (logsCheck.rows.length > 0) {
console.log('✅ Block action logged in security_logs')
console.log(' Log:', logsCheck.rows[0])
} else {
console.log('❌ Block action not found in security logs')
}
// Test 4: Unblock the IP
console.log('\n4. Unblocking test IP...')
const unblockResponse = await fetch('http://localhost:3000/api/admin/security/unblock-ip', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ip: testIP })
})
if (unblockResponse.ok) {
console.log('✅ IP unblocked successfully')
} else {
console.log('❌ Failed to unblock IP:', await unblockResponse.text())
}
console.log('\n🎯 Block IP Test Complete!')
} catch (error) {
console.error('❌ Block IP test failed:', error.message)
}
}
// Only run if server is available
fetch('http://localhost:3000/api/admin/security')
.then(() => {
console.log('✅ Server is running, testing block IP functionality...\n')
testBlockIP()
})
.catch(() => {
console.log('❌ Server not running, skipping API tests')
console.log('Run "npm run dev" first, then run this test')
})