fix(session): limit subqueries for mariadb

MariaDB does not support `connect-typeorm`s subqueries,
so they need to be disabled if this dialect is used.

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2022-03-05 19:22:21 +01:00
parent 9c6d3d9dab
commit f9448bb801
3 changed files with 11 additions and 2 deletions

View file

@ -11,6 +11,7 @@ import { NestExpressApplication } from '@nestjs/platform-express';
import { AppModule } from './app.module';
import { AppConfig } from './config/app.config';
import { AuthConfig } from './config/auth.config';
import { DatabaseConfig } from './config/database.config';
import { MediaConfig } from './config/media.config';
import { ErrorExceptionMapping } from './errors/error-mapping';
import { ConsoleLoggerService } from './logger/console-logger.service';
@ -31,10 +32,11 @@ async function bootstrap(): Promise<void> {
app.useLogger(logger);
const configService = app.get(ConfigService);
const appConfig = configService.get<AppConfig>('appConfig');
const databaseConfig = configService.get<DatabaseConfig>('databaseConfig');
const authConfig = configService.get<AuthConfig>('authConfig');
const mediaConfig = configService.get<MediaConfig>('mediaConfig');
if (!appConfig || !authConfig || !mediaConfig) {
if (!appConfig || !databaseConfig || !authConfig || !mediaConfig) {
logger.error('Could not initialize config, aborting.', 'AppBootstrap');
process.exit(1);
}
@ -55,7 +57,7 @@ async function bootstrap(): Promise<void> {
await setupSpecialGroups(app);
setupSessionMiddleware(app, authConfig);
setupSessionMiddleware(app, authConfig, databaseConfig);
app.enableCors({
origin: appConfig.rendererOrigin,

View file

@ -10,16 +10,20 @@ import session from 'express-session';
import { Repository } from 'typeorm';
import { AuthConfig } from '../config/auth.config';
import { DatabaseDialect } from '../config/database-dialect.enum';
import { DatabaseConfig } from '../config/database.config';
import { Session } from '../users/session.entity';
/**
* Setup the session middleware via the given authConfig.
* @param {INestApplication} app - the nest application to configure the middleware for.
* @param {AuthConfig} authConfig - the authConfig to configure the middleware with.
* @param {DatabaseConfig} dbConfig - the DatabaseConfig to configure the middleware with.
*/
export function setupSessionMiddleware(
app: INestApplication,
authConfig: AuthConfig,
dbConfig: DatabaseConfig,
): void {
app.use(
session({
@ -32,6 +36,7 @@ export function setupSessionMiddleware(
saveUninitialized: false,
store: new TypeormStore({
cleanupLimit: 2,
limitSubquery: dbConfig.dialect !== DatabaseDialect.MARIADB,
}).connect(app.get<Repository<Session>>(getRepositoryToken(Session))),
}),
);

View file

@ -19,6 +19,7 @@ import { MockAuthGuard } from '../src/auth/mock-auth.guard';
import { TokenAuthGuard } from '../src/auth/token.strategy';
import { AuthorsModule } from '../src/authors/authors.module';
import { AuthConfig } from '../src/config/auth.config';
import { DatabaseConfig } from '../src/config/database.config';
import appConfigMock from '../src/config/mock/app.config.mock';
import authConfigMock from '../src/config/mock/auth.config.mock';
import customizationConfigMock from '../src/config/mock/customization.config.mock';
@ -267,6 +268,7 @@ export class TestSetupBuilder {
setupSessionMiddleware(
this.testSetup.app,
this.testSetup.configService.get<AuthConfig>('authConfig'),
this.testSetup.configService.get<DatabaseConfig>('databaseConfig'),
);
this.testSetup.app.useGlobalPipes(
setupValidationPipe(