From 15e0eccd840a2e2e59e1cf600dc5ed80b7993df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20=C3=96hlerking?= Date: Fri, 5 Jul 2024 16:07:29 +0200 Subject: [PATCH] fix test --- .../src/modules/system/domain/ldap-config.ts | 30 ------------ .../mikro-orm/mapper/system-entity.mapper.ts | 1 - .../system/repo/mikro-orm/system.repo.spec.ts | 48 ++++++++++--------- .../testing/factory/domainobject/index.ts | 7 ++- 4 files changed, 31 insertions(+), 55 deletions(-) diff --git a/apps/server/src/modules/system/domain/ldap-config.ts b/apps/server/src/modules/system/domain/ldap-config.ts index 6e3e345e54f..785b41ce35e 100644 --- a/apps/server/src/modules/system/domain/ldap-config.ts +++ b/apps/server/src/modules/system/domain/ldap-config.ts @@ -1,32 +1,5 @@ import { EntityId } from '@shared/domain/types'; -type ProviderOptions = { - schoolName?: string; - userPathAdditions?: string; - classPathAdditions?: string; - roleType?: string; - userAttributeNameMapping?: { - givenName?: string; - sn?: string; - dn?: string; - uuid?: string; - uid?: string; - mail?: string; - role?: string; - }; - roleAttributeNameMapping?: { - roleStudent?: string; - roleTeacher?: string; - roleAdmin?: string; - roleNoSc?: string; - }; - classAttributeNameMapping?: { - description?: string; - dn?: string; - uniqueMember?: string; - }; -}; - export class LdapConfig { active: boolean; @@ -50,8 +23,6 @@ export class LdapConfig { searchUserPassword?: string; - providerOptions?: ProviderOptions; - constructor(props: LdapConfig) { this.active = props.active; this.url = props.url; @@ -64,6 +35,5 @@ export class LdapConfig { this.rootPath = props.rootPath; this.searchUser = props.searchUser; this.searchUserPassword = props.searchUserPassword; - this.providerOptions = props.providerOptions; } } diff --git a/apps/server/src/modules/system/repo/mikro-orm/mapper/system-entity.mapper.ts b/apps/server/src/modules/system/repo/mikro-orm/mapper/system-entity.mapper.ts index 0a3a1c75c6c..a8da1afa1b2 100644 --- a/apps/server/src/modules/system/repo/mikro-orm/mapper/system-entity.mapper.ts +++ b/apps/server/src/modules/system/repo/mikro-orm/mapper/system-entity.mapper.ts @@ -52,7 +52,6 @@ export class SystemEntityMapper { rootPath: ldapConfig.rootPath, searchUser: ldapConfig.searchUser, searchUserPassword: ldapConfig.searchUserPassword, - providerOptions: ldapConfig.providerOptions, }); return mapped; diff --git a/apps/server/src/modules/system/repo/mikro-orm/system.repo.spec.ts b/apps/server/src/modules/system/repo/mikro-orm/system.repo.spec.ts index cb7c8258a8c..ba3ae03afe3 100644 --- a/apps/server/src/modules/system/repo/mikro-orm/system.repo.spec.ts +++ b/apps/server/src/modules/system/repo/mikro-orm/system.repo.spec.ts @@ -4,9 +4,15 @@ import { NotImplementedException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { SystemProvisioningStrategy } from '@shared/domain/interface/system-provisioning.strategy'; import { SystemTypeEnum } from '@shared/domain/types'; -import { cleanupCollections, systemEntityFactory } from '@shared/testing'; +import { + cleanupCollections, + systemEntityFactory, + systemLdapConfigFactory, + systemOauthConfigFactory, + systemOidcConfigFactory, +} from '@shared/testing'; import { System, SYSTEM_REPO, SystemProps, SystemRepo, SystemType } from '../../domain'; -import { LdapConfigEntity, OauthConfigEntity, SystemEntity } from '../../entity'; +import { SystemEntity } from '../../entity'; import { SystemEntityMapper } from './mapper'; import { SystemMikroOrmRepo } from './system.repo'; @@ -102,26 +108,10 @@ describe(SystemMikroOrmRepo.name, () => { describe('getSystemById', () => { describe('when the system exists', () => { const setup = async () => { - const oauthConfig = new OauthConfigEntity({ - clientId: '12345', - clientSecret: 'mocksecret', - idpHint: 'mock-oauth-idpHint', - tokenEndpoint: 'http://mock.de/mock/auth/public/mockToken', - grantType: 'authorization_code', - redirectUri: 'http://mockhost:3030/api/v3/sso/oauth/', - scope: 'openid uuid', - responseType: 'code', - authEndpoint: 'http://mock.de/auth', - provider: 'mock_type', - logoutEndpoint: 'http://mock.de/logout', - issuer: 'mock_issuer', - jwksEndpoint: 'http://mock.de/jwks', - }); - const ldapConfig = new LdapConfigEntity({ - url: 'ldaps:mock.de:389', - active: true, - provider: 'mock_provider', - }); + const oauthConfig = systemOauthConfigFactory.build(); + const ldapConfig = systemLdapConfigFactory.build(); + const oidcConfig = systemOidcConfigFactory.build(); + const system: SystemEntity = systemEntityFactory.buildWithId({ type: 'oauth', url: 'https://mock.de', @@ -131,6 +121,7 @@ describe(SystemMikroOrmRepo.name, () => { provisioningUrl: 'https://provisioningurl.de', oauthConfig, ldapConfig, + oidcConfig, }); await em.persistAndFlush([system]); @@ -140,11 +131,12 @@ describe(SystemMikroOrmRepo.name, () => { system, oauthConfig, ldapConfig, + oidcConfig, }; }; it('should return the system', async () => { - const { system, oauthConfig, ldapConfig } = await setup(); + const { system, oauthConfig, ldapConfig, oidcConfig } = await setup(); const result = await repo.getSystemById(system.id); @@ -176,6 +168,16 @@ describe(SystemMikroOrmRepo.name, () => { provider: ldapConfig.provider, active: !!ldapConfig.active, }, + oidcConfig: { + clientId: oidcConfig.clientId, + clientSecret: oidcConfig.clientSecret, + idpHint: oidcConfig.idpHint, + authorizationUrl: oidcConfig.authorizationUrl, + tokenUrl: oidcConfig.tokenUrl, + logoutUrl: oidcConfig.logoutUrl, + userinfoUrl: oidcConfig.userinfoUrl, + defaultScopes: oidcConfig.defaultScopes, + }, }); }); }); diff --git a/apps/server/src/shared/testing/factory/domainobject/index.ts b/apps/server/src/shared/testing/factory/domainobject/index.ts index d829f10bbfb..806f417ce84 100644 --- a/apps/server/src/shared/testing/factory/domainobject/index.ts +++ b/apps/server/src/shared/testing/factory/domainobject/index.ts @@ -5,5 +5,10 @@ export * from './domain-object.factory'; export * from './user-login-migration-do.factory'; export * from './lti-tool.factory'; export * from './pseudonym.factory'; -export { systemFactory, systemOauthConfigFactory, systemLdapConfigFactory } from './system/system.factory'; +export { + systemFactory, + systemOauthConfigFactory, + systemLdapConfigFactory, + systemOidcConfigFactory, +} from './system/system.factory'; export { schoolSystemOptionsFactory } from './school-system-options/school-system-options.factory';