Letzte Phase des RBAC-Umbaus: die transitionale Rollen-Infrastruktur, die seit Phase 1 parallel zum neuen Role/Permission-System mitlief, ist jetzt komplett weg. - Prisma-Migration: User.legacyRole-Spalte und LegacyRole-Enum gedroppt (nichts liest die Spalte mehr, seit Phase 2 jeder Controller auf @RequirePermission laeuft). - roles.guard.ts, roles.guard.spec.ts, roles.decorator.ts geloescht; RolesGuard aus den APP_GUARD-Providern entfernt. - AuthenticatedUser/JWT-Payload verlieren das role-Feld (permissions werden ohnehin frisch pro Request aus der DB aufgeloest, nicht aus dem Claim). - Users-API: CreateUserDto/UpdateUserDto akzeptieren jetzt roleId (eine echte Role.id) statt der alten role-Enum-Werte; UsersService validiert, dass die Rolle existiert und aktiv ist, bevor sie zugewiesen wird. - Alle 34 e2e-Fixtures und der Seed-Script folgen dem neuen Schema. Verifiziert: tsc, lint, build, unit (220/220), volle e2e-Suite 159/159 gruen - keine uebersprungenen Tests. Co-Authored-By: Claude Sonnet 5 <[email protected]>
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { INestApplication } from '@nestjs/common';
|
|
import * as bcrypt from 'bcryptjs';
|
|
import request from 'supertest';
|
|
import { App } from 'supertest/types';
|
|
import { PrismaService } from '../src/prisma/prisma.service';
|
|
import { createTestApp } from './utils/create-test-app';
|
|
|
|
const LOGIN_THROTTLE_LIMIT = 10;
|
|
|
|
describe('Auth login throttling (e2e)', () => {
|
|
let app: INestApplication<App>;
|
|
let prisma: PrismaService;
|
|
const email = `auth-throttle-e2e-${Date.now()}@example.com`;
|
|
const password = 'SuperSecret123!';
|
|
let userId: string;
|
|
|
|
beforeAll(async () => {
|
|
app = await createTestApp();
|
|
prisma = app.get(PrismaService);
|
|
|
|
const passwordHash = await bcrypt.hash(password, 12);
|
|
const user = await prisma.user.create({
|
|
data: {
|
|
email,
|
|
passwordHash,
|
|
name: 'Throttle E2E User',
|
|
role: { connect: { key: 'STAFF' } },
|
|
},
|
|
});
|
|
userId = user.id;
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await prisma.refreshToken.deleteMany({ where: { userId } });
|
|
await prisma.auditLog.deleteMany({ where: { userId } });
|
|
await prisma.user.delete({ where: { id: userId } });
|
|
await app.close();
|
|
});
|
|
|
|
it('rejects login attempts beyond the per-minute limit with 429', async () => {
|
|
for (let attempt = 0; attempt < LOGIN_THROTTLE_LIMIT; attempt += 1) {
|
|
await request(app.getHttpServer())
|
|
.post('/api/v1/auth/login')
|
|
.send({ email, password: 'wrong-password' })
|
|
.expect(401);
|
|
}
|
|
|
|
await request(app.getHttpServer())
|
|
.post('/api/v1/auth/login')
|
|
.send({ email, password: 'wrong-password' })
|
|
.expect(429);
|
|
});
|
|
});
|