Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinOehlerkingCap committed Jul 5, 2024
1 parent 8d149ee commit 15e0ecc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 55 deletions.
30 changes: 0 additions & 30 deletions apps/server/src/modules/system/domain/ldap-config.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -50,8 +23,6 @@ export class LdapConfig {

searchUserPassword?: string;

providerOptions?: ProviderOptions;

constructor(props: LdapConfig) {
this.active = props.active;
this.url = props.url;
Expand All @@ -64,6 +35,5 @@ export class LdapConfig {
this.rootPath = props.rootPath;
this.searchUser = props.searchUser;
this.searchUserPassword = props.searchUserPassword;
this.providerOptions = props.providerOptions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export class SystemEntityMapper {
rootPath: ldapConfig.rootPath,
searchUser: ldapConfig.searchUser,
searchUserPassword: ldapConfig.searchUserPassword,
providerOptions: ldapConfig.providerOptions,
});

return mapped;
Expand Down
48 changes: 25 additions & 23 deletions apps/server/src/modules/system/repo/mikro-orm/system.repo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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',
Expand All @@ -131,6 +121,7 @@ describe(SystemMikroOrmRepo.name, () => {
provisioningUrl: 'https://provisioningurl.de',
oauthConfig,
ldapConfig,
oidcConfig,
});

await em.persistAndFlush([system]);
Expand All @@ -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);

Expand Down Expand Up @@ -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,
},
});
});
});
Expand Down
7 changes: 6 additions & 1 deletion apps/server/src/shared/testing/factory/domainobject/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit 15e0ecc

Please sign in to comment.