Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPSH-1570-main: Enhanced Logging In Email-Event-Handler #857

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/core/ldap/domain/ldap-client.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Person } from '../../../modules/person/domain/person.js';
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { LdapClient } from './ldap-client.js';
import { Attribute, Change, Client, Entry, SearchResult } from 'ldapts';
import { PersonID } from '../../../shared/types/aggregate-ids.types.js';
import { PersonID, PersonReferrer } from '../../../shared/types/aggregate-ids.types.js';
import { LdapSearchError } from '../error/ldap-search.error.js';
import { LdapEntityType } from './ldap.types.js';
import { ClassLogger } from '../../logging/class-logger.js';
Expand Down Expand Up @@ -140,8 +140,8 @@ describe('LDAP Client Service', () => {
expect(em).toBeDefined();
});
describe('updateMemberDnInGroups', () => {
const fakeOldReferrer: string = 'old-user';
const fakeNewReferrer: string = 'new-user';
const fakeOldReferrer: PersonReferrer = 'old-user';
const fakeNewReferrer: PersonReferrer = 'new-user';
const fakeOldReferrerUid: string = `uid=${fakeOldReferrer},ou=users,${mockLdapInstanceConfig.BASE_DN}`;
const fakeNewReferrerUid: string = `uid=${fakeNewReferrer},ou=users,${mockLdapInstanceConfig.BASE_DN}`;
const fakeGroupDn: string = 'cn=lehrer-group,' + mockLdapInstanceConfig.BASE_DN;
Expand Down Expand Up @@ -478,7 +478,7 @@ describe('LDAP Client Service', () => {
});

describe('addPersonToGroup', () => {
const fakeReferrer: string = 'test-user';
const fakeReferrer: PersonReferrer = 'test-user';
const fakeSchoolReferrer: string = '123';
const fakeLehrerUid: string = `uid=${fakeReferrer},ou=oeffentlicheSchulen,${mockLdapInstanceConfig.BASE_DN}`;
const fakeGroupId: string = `lehrer-${fakeSchoolReferrer}`;
Expand Down Expand Up @@ -904,7 +904,7 @@ describe('LDAP Client Service', () => {
});

it('should log an error and return the failed result if addPersonToGroup fails', async () => {
const referrer: string = 'test-user';
const referrer: PersonReferrer = 'test-user';
const schulId: string = '123';
const expectedGroupId: string = `lehrer-${schulId}`;
const errorMessage: string = `LDAP: Failed to add lehrer ${referrer} to group ${expectedGroupId}`;
Expand Down Expand Up @@ -1159,7 +1159,7 @@ describe('LDAP Client Service', () => {
});
describe('when modifying', () => {
it('Should Update LDAP When called with Attributes', async () => {
const oldReferrer: string = faker.internet.userName();
const oldReferrer: PersonReferrer = faker.internet.userName();
const newGivenName: string = faker.person.firstName();
const newSn: string = faker.person.lastName();
const newUid: string = faker.string.alphanumeric(6);
Expand Down Expand Up @@ -1211,7 +1211,7 @@ describe('LDAP Client Service', () => {
});

it('should return error if updateMemberDnInGroups fails', async () => {
const oldReferrer: string = faker.internet.userName();
const oldReferrer: PersonReferrer = faker.internet.userName();
const newUid: string = faker.string.alphanumeric(6);

jest.spyOn(ldapClientService, 'updateMemberDnInGroups').mockResolvedValueOnce({
Expand Down Expand Up @@ -1897,7 +1897,7 @@ describe('LDAP Client Service', () => {
describe('createNewLehrerUidFromOldUid', () => {
it('should replace the old uid with the new referrer and join the DN parts with commas', () => {
const oldUid: string = 'uid=oldUser,ou=users,dc=example,dc=com';
const newReferrer: string = 'newUser';
const newReferrer: PersonReferrer = 'newUser';

const result: string = ldapClientService.createNewLehrerUidFromOldUid(oldUid, newReferrer);

Expand All @@ -1906,7 +1906,7 @@ describe('LDAP Client Service', () => {

it('should handle a DN with only a uid component', () => {
const oldUid: string = 'uid=oldUser';
const newReferrer: string = 'newUser';
const newReferrer: PersonReferrer = 'newUser';

const result: string = ldapClientService.createNewLehrerUidFromOldUid(oldUid, newReferrer);

Expand All @@ -1915,7 +1915,7 @@ describe('LDAP Client Service', () => {

it('should handle an empty DN string', () => {
const oldUid: string = '';
const newReferrer: string = 'newUser';
const newReferrer: PersonReferrer = 'newUser';

const result: string = ldapClientService.createNewLehrerUidFromOldUid(oldUid, newReferrer);

Expand Down
22 changes: 10 additions & 12 deletions src/core/ldap/domain/ldap-client.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class LdapClientService {
};
}

public getLehrerUid(referrer: string, rootName: string): string {
public getLehrerUid(referrer: PersonReferrer, rootName: string): string {
return `uid=${referrer},ou=${rootName},${this.ldapInstanceConfig.BASE_DN}`;
}

Expand All @@ -126,7 +126,7 @@ export class LdapClientService {
schulId: string,
mail?: string, //Wird hier erstmal seperat mit reingegeben bis die Umstellung auf primary/alternative erfolgt
): Promise<Result<PersonData>> {
const referrer: string | undefined = person.referrer;
const referrer: PersonReferrer | undefined = person.referrer;
if (!referrer) {
return {
ok: false,
Expand Down Expand Up @@ -194,7 +194,7 @@ export class LdapClientService {
});
}

public async isLehrerExisting(referrer: string, domain: string): Promise<Result<boolean>> {
public async isLehrerExisting(referrer: PersonReferrer, domain: string): Promise<Result<boolean>> {
const rootName: Result<string> = this.getRootNameOrError(domain);
if (!rootName.ok) return rootName;

Expand All @@ -218,10 +218,10 @@ export class LdapClientService {
}

public async modifyPersonAttributes(
oldReferrer: string,
oldReferrer: PersonReferrer,
newGivenName?: string,
newSn?: string,
newReferrer?: string,
newReferrer?: PersonReferrer,
): Promise<Result<string>> {
return this.mutex.runExclusive(async () => {
this.logger.info('LDAP: modifyPersonAttributes');
Expand Down Expand Up @@ -309,15 +309,15 @@ export class LdapClientService {
});
}

public createNewLehrerUidFromOldUid(oldUid: string, newReferrer: string): string {
public createNewLehrerUidFromOldUid(oldUid: string, newReferrer: PersonReferrer): string {
const splitted: string[] = oldUid.split(',');
splitted[0] = `uid=${newReferrer}`;
return splitted.join(',');
}

public async updateMemberDnInGroups(
oldReferrer: string,
newReferrer: string,
oldReferrer: PersonReferrer,
newReferrer: PersonReferrer,
oldUid: string,
client: Client,
): Promise<Result<string>> {
Expand Down Expand Up @@ -391,7 +391,7 @@ export class LdapClientService {
return { ok: true, value: `Updated member data for ${groupEntries.length} groups.` };
}

public async deleteLehrerByReferrer(referrer: string): Promise<Result<string>> {
public async deleteLehrerByReferrer(referrer: PersonReferrer): Promise<Result<string>> {
return this.mutex.runExclusive(async () => {
this.logger.info('LDAP: deleteLehrer by referrer');
const client: Client = this.ldapClient.getClient();
Expand Down Expand Up @@ -464,7 +464,6 @@ export class LdapClientService {
newEmailAddress: string,
): Promise<Result<PersonID>> {
// Converted to avoid PersonRepository-ref, UEM-password-generation
//const referrer: string | undefined = await this.getPersonReferrerOrUndefined(personId);
return this.mutex.runExclusive(async () => {
this.logger.info('LDAP: changeEmailAddress');
const splitted: string[] = newEmailAddress.split('@');
Expand Down Expand Up @@ -632,7 +631,7 @@ export class LdapClientService {
}

public async removePersonFromGroup(
referrer: string,
referrer: PersonReferrer,
schoolReferrer: string,
lehrerUid: string,
): Promise<Result<boolean>> {
Expand Down Expand Up @@ -709,7 +708,6 @@ export class LdapClientService {

public async changeUserPasswordByPersonId(personId: PersonID, referrer: PersonReferrer): Promise<Result<PersonID>> {
// Converted to avoid PersonRepository-ref, UEM-password-generation
//const referrer: string | undefined = await this.getPersonReferrerOrUndefined(personId);
const userPassword: string = generatePassword();

return this.mutex.runExclusive(async () => {
Expand Down
Loading
Loading