diff --git a/apps/server/src/modules/server/server.config.ts b/apps/server/src/modules/server/server.config.ts index 09dd2210928..bec5dd2e4cc 100644 --- a/apps/server/src/modules/server/server.config.ts +++ b/apps/server/src/modules/server/server.config.ts @@ -5,6 +5,7 @@ import type { IAccountConfig } from '@modules/account'; import type { IFilesStorageClientConfig } from '@modules/files-storage-client'; import type { IUserConfig } from '@modules/user'; import type { ICommonCartridgeConfig } from '@modules/learnroom/common-cartridge'; +import { IMailConfig } from '@shared/infra/mail/interfaces/mail-config'; export enum NodeEnvType { TEST = 'test', @@ -19,7 +20,8 @@ export interface IServerConfig IFilesStorageClientConfig, IAccountConfig, IIdentityManagementConfig, - ICommonCartridgeConfig { + ICommonCartridgeConfig, + IMailConfig { NODE_ENV: string; SC_DOMAIN: string; } @@ -39,6 +41,9 @@ const config: IServerConfig = { FEATURE_IDENTITY_MANAGEMENT_ENABLED: Configuration.get('FEATURE_IDENTITY_MANAGEMENT_ENABLED') as boolean, FEATURE_IDENTITY_MANAGEMENT_STORE_ENABLED: Configuration.get('FEATURE_IDENTITY_MANAGEMENT_STORE_ENABLED') as boolean, FEATURE_IDENTITY_MANAGEMENT_LOGIN_ENABLED: Configuration.get('FEATURE_IDENTITY_MANAGEMENT_LOGIN_ENABLED') as boolean, + BLACKLISTED_DOMAINS: Configuration.has('ADDITIONAL_BLACKLISTED_EMAIL_DOMAINS') + ? (Configuration.get('ADDITIONAL_BLACKLISTED_EMAIL_DOMAINS') as string).split(',').map((domain) => domain.trim()) + : ([] as string[]), }; export const serverConfig = () => config; diff --git a/apps/server/src/shared/infra/mail/interfaces/mail-config.ts b/apps/server/src/shared/infra/mail/interfaces/mail-config.ts new file mode 100644 index 00000000000..fd2b0b75e56 --- /dev/null +++ b/apps/server/src/shared/infra/mail/interfaces/mail-config.ts @@ -0,0 +1,3 @@ +export interface IMailConfig { + BLACKLISTED_DOMAINS: string[]; +} diff --git a/apps/server/src/shared/infra/mail/mail.service.spec.ts b/apps/server/src/shared/infra/mail/mail.service.spec.ts index 6da86947a94..ebc77030252 100644 --- a/apps/server/src/shared/infra/mail/mail.service.spec.ts +++ b/apps/server/src/shared/infra/mail/mail.service.spec.ts @@ -1,8 +1,10 @@ import { AmqpConnection } from '@golevelup/nestjs-rabbitmq'; import { Test, TestingModule } from '@nestjs/testing'; -import { Configuration } from '@hpi-schul-cloud/commons/lib'; +import { createMock } from '@golevelup/ts-jest'; +import { ConfigService } from '@nestjs/config'; import { Mail } from './mail.interface'; import { MailService } from './mail.service'; +import { IMailConfig } from './interfaces/mail-config'; describe('MailService', () => { let module: TestingModule; @@ -15,12 +17,15 @@ describe('MailService', () => { }; beforeAll(async () => { - Configuration.set('ADDITIONAL_BLACKLISTED_EMAIL_DOMAINS', 'schul-cloud.org, example.com'); module = await Test.createTestingModule({ providers: [ MailService, { provide: AmqpConnection, useValue: { publish: () => {} } }, { provide: 'MAIL_SERVICE_OPTIONS', useValue: mailServiceOptions }, + { + provide: ConfigService, + useValue: createMock>({ get: () => ['schul-cloud.org', 'example.com'] }), + }, ], }).compile(); diff --git a/apps/server/src/shared/infra/mail/mail.service.ts b/apps/server/src/shared/infra/mail/mail.service.ts index 637cb4e227f..466390010b3 100644 --- a/apps/server/src/shared/infra/mail/mail.service.ts +++ b/apps/server/src/shared/infra/mail/mail.service.ts @@ -1,8 +1,8 @@ import { AmqpConnection } from '@golevelup/nestjs-rabbitmq'; import { Inject, Injectable } from '@nestjs/common'; -import { Configuration } from '@hpi-schul-cloud/commons/lib'; - +import { ConfigService } from '@nestjs/config'; import { Mail } from './mail.interface'; +import { IMailConfig } from './interfaces/mail-config'; interface MailServiceOptions { exchange: string; @@ -15,18 +15,10 @@ export class MailService { constructor( private readonly amqpConnection: AmqpConnection, - @Inject('MAIL_SERVICE_OPTIONS') private readonly options: MailServiceOptions + @Inject('MAIL_SERVICE_OPTIONS') private readonly options: MailServiceOptions, + private readonly configService: ConfigService ) { - this.domainBlacklist = this.getDomainBlacklist(); - } - - private getDomainBlacklist(): string[] { - if (Configuration.has('ADDITIONAL_BLACKLISTED_EMAIL_DOMAINS')) { - const domainBlackList = Configuration.get('ADDITIONAL_BLACKLISTED_EMAIL_DOMAINS') as string; - const domainBlackListArray = domainBlackList.split(',').map((domain) => domain.trim()); - return domainBlackListArray; - } - return [] as string[]; + this.domainBlacklist = this.configService.get('BLACKLISTED_DOMAINS'); } public async send(data: Mail): Promise {