feat: prepare six-lesson trial backend with reliable rewards and operations
Backend CI / type-check, build, tests (push) Successful in 1m0s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-12 14:35:42 +03:30
co-authored by Cursor
parent 5e5a14030a
commit dfb20ca92c
46 changed files with 2589 additions and 123 deletions
+36
View File
@@ -0,0 +1,36 @@
import assert from 'node:assert/strict'
import type { FastifyRequest } from 'fastify'
import { getClientIp } from '../src/common/http/client-ip'
import {
assertAuthRateLimit,
resetAuthRateLimitForTests,
} from '../src/common/rate-limit/auth-rate-limit'
resetAuthRateLimitForTests()
process.env.TRUST_PROXY = 'true'
const attackerPeer = '203.0.113.99'
const req = {
socket: { remoteAddress: attackerPeer },
headers: { 'x-forwarded-for': 'fresh-spoofed-ip-1' },
} as FastifyRequest
const ip = getClientIp(req)
assert.equal(ip, attackerPeer, 'forged XFF must not become rate-limit key')
for (let i = 0; i < 30; i++) {
assertAuthRateLimit(ip)
}
let blocked = false
try {
assertAuthRateLimit(ip)
blocked = true
} catch (error) {
assert.equal((error as { status?: number }).status, 429)
}
assert.equal(blocked, false, 'rate limit must apply to real peer IP')
resetAuthRateLimitForTests()
delete process.env.TRUST_PROXY
console.log('auth-rate-limit-xff tests passed')