-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SPSH-1291: LdapPersonEntries have objectClass posixAccount (#740)
* LdapPersonEntries have objectClass posixAccount and required attributes * add error-logging if LDAP-createLehrer fails * add logging when modifying LDAPEntry (email-address) fails --------- Co-authored-by: Kristoff Kiefer <[email protected]>
- Loading branch information
1 parent
c6a73b7
commit 6bb3a76
Showing
5 changed files
with
142 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ import { ClassLogger } from '../../logging/class-logger.js'; | |
import { EventService } from '../../eventbus/services/event.service.js'; | ||
import { LdapEmailDomainError } from '../error/ldap-email-domain.error.js'; | ||
import { LdapEmailAddressError } from '../error/ldap-email-address.error.js'; | ||
import { LdapCreateLehrerError } from '../error/ldap-create-lehrer.error.js'; | ||
import { LdapModifyEmailError } from '../error/ldap-modify-email.error.js'; | ||
|
||
describe('LDAP Client Service', () => { | ||
let app: INestApplication; | ||
|
@@ -236,6 +238,30 @@ describe('LDAP Client Service', () => { | |
expect(loggerMock.info).toHaveBeenLastCalledWith(`LDAP: Successfully created lehrer ${lehrerUid}`); | ||
}); | ||
|
||
it('when adding fails should log error', async () => { | ||
ldapClientMock.getClient.mockImplementation(() => { | ||
clientMock.bind.mockResolvedValue(); | ||
clientMock.search.mockResolvedValueOnce(createMock<SearchResult>({ searchEntries: [] })); //mock: lehrer not present | ||
clientMock.add.mockRejectedValueOnce(new Error('LDAP-Error')); | ||
|
||
return clientMock; | ||
}); | ||
const testLehrer: PersonData = { | ||
id: faker.string.uuid(), | ||
vorname: faker.person.firstName(), | ||
familienname: faker.person.lastName(), | ||
referrer: faker.lorem.word(), | ||
}; | ||
const lehrerUid: string = 'uid=' + testLehrer.referrer + ',ou=oeffentlicheSchulen,dc=schule-sh,dc=de'; | ||
const result: Result<PersonData> = await ldapClientService.createLehrer(testLehrer, fakeEmailDomain); | ||
|
||
if (result.ok) throw Error(); | ||
expect(loggerMock.error).toHaveBeenLastCalledWith( | ||
`LDAP: Creating lehrer FAILED, uid:${lehrerUid}, errMsg:{}`, | ||
); | ||
expect(result.error).toEqual(new LdapCreateLehrerError()); | ||
}); | ||
|
||
it('when called with explicit domain "ersatzschule-sh.de" should return truthy result', async () => { | ||
ldapClientMock.getClient.mockImplementation(() => { | ||
clientMock.bind.mockResolvedValue(); | ||
|
@@ -290,9 +316,6 @@ describe('LDAP Client Service', () => { | |
ldapClientMock.getClient.mockImplementation(() => { | ||
clientMock.bind.mockResolvedValue(); | ||
clientMock.add.mockResolvedValueOnce(); | ||
clientMock.search.mockResolvedValueOnce( | ||
createMock<SearchResult>({ searchEntries: [createMock<Entry>()] }), | ||
); //mock existsSchule: schule present | ||
clientMock.search.mockResolvedValueOnce(createMock<SearchResult>({ searchEntries: [] })); //mock: lehrer not present | ||
|
||
return clientMock; | ||
|
@@ -498,6 +521,44 @@ describe('LDAP Client Service', () => { | |
}); | ||
}); | ||
|
||
describe('when person can be found but modification fails', () => { | ||
const fakePersonID: string = faker.string.uuid(); | ||
const fakeDN: string = faker.string.alpha(); | ||
const newEmailAddress: string = '[email protected]'; | ||
const currentEmailAddress: string = '[email protected]'; | ||
|
||
it('should set mailAlternativeAddress as current mailPrimaryAddress and throw LdapPersonEntryChangedEvent', async () => { | ||
ldapClientMock.getClient.mockImplementation(() => { | ||
clientMock.bind.mockResolvedValueOnce(); | ||
clientMock.search.mockResolvedValueOnce( | ||
createMock<SearchResult>({ | ||
searchEntries: [ | ||
createMock<Entry>({ | ||
dn: fakeDN, | ||
mailPrimaryAddress: currentEmailAddress, | ||
}), | ||
], | ||
}), | ||
); | ||
clientMock.modify.mockRejectedValueOnce(new Error()); | ||
|
||
return clientMock; | ||
}); | ||
|
||
const result: Result<PersonID> = await ldapClientService.changeEmailAddressByPersonId( | ||
fakePersonID, | ||
newEmailAddress, | ||
); | ||
|
||
if (result.ok) throw Error(); | ||
expect(result.error).toStrictEqual(new LdapModifyEmailError()); | ||
expect(loggerMock.error).toHaveBeenLastCalledWith( | ||
`LDAP: Modifying mailPrimaryAddress and mailAlternativeAddress FAILED, errMsg:{}`, | ||
); | ||
expect(eventServiceMock.publish).toHaveBeenCalledTimes(0); | ||
}); | ||
}); | ||
|
||
describe('when person can be found and modified', () => { | ||
let fakePersonID: string; | ||
let fakeDN: string; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { DomainError } from '../../../shared/error/index.js'; | ||
|
||
export class LdapCreateLehrerError extends DomainError { | ||
public constructor(details?: unknown[] | Record<string, unknown>) { | ||
super(`LDAP error: Creating lehrer FAILED`, 'LDAP_LEHRER_CREATION_FAILED', details); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { DomainError } from '../../../shared/error/index.js'; | ||
|
||
export class LdapModifyEmailError extends DomainError { | ||
public constructor(details?: unknown[] | Record<string, unknown>) { | ||
super( | ||
`LDAP error: Modifying mailPrimaryAddress and mailAlternativeAddress FAILED`, | ||
'LDAP_EMAIL_MODIFICATION_FAILED', | ||
details, | ||
); | ||
} | ||
} |