feat: secure admin user management

This commit is contained in:
Bastian Wagner
2026-07-31 23:37:54 +02:00
parent 4105460400
commit e6acfdcac7
22 changed files with 1598 additions and 148 deletions

View File

@@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddPlayerLookupIndexes1785517200000 implements MigrationInterface {
name = 'AddPlayerLookupIndexes1785517200000';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
'CREATE INDEX "IDX_player_team_id" ON "player" ("teamId")',
);
await queryRunner.query(
'CREATE INDEX "IDX_player_user_id" ON "player" ("userId")',
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query('DROP INDEX "IDX_player_user_id"');
await queryRunner.query('DROP INDEX "IDX_player_team_id"');
}
}

View File

@@ -0,0 +1,33 @@
import { getMetadataArgsStorage } from 'typeorm';
import { Player } from '../../players/entities/player.entity';
import { AddPlayerLookupIndexes1785517200000 } from './1785517200000-AddPlayerLookupIndexes';
describe('AddPlayerLookupIndexes1785517200000', () => {
it('adds reversible indexes for team and user foreign-key lookups', async () => {
const queryRunner = { query: jest.fn() } as any;
const migration = new AddPlayerLookupIndexes1785517200000();
await migration.up(queryRunner);
expect(queryRunner.query.mock.calls.map(([sql]) => sql)).toEqual([
'CREATE INDEX "IDX_player_team_id" ON "player" ("teamId")',
'CREATE INDEX "IDX_player_user_id" ON "player" ("userId")',
]);
queryRunner.query.mockClear();
await migration.down(queryRunner);
expect(queryRunner.query.mock.calls.map(([sql]) => sql)).toEqual([
'DROP INDEX "IDX_player_user_id"',
'DROP INDEX "IDX_player_team_id"',
]);
});
it('keeps entity index metadata aligned with the migration', () => {
const playerIndexes = getMetadataArgsStorage()
.indices.filter((index) => index.target === Player)
.map((index) => index.name);
expect(playerIndexes).toEqual(
expect.arrayContaining(['IDX_player_team_id', 'IDX_player_user_id']),
);
});
});