Skip to content

Commit ad1cbb2

Browse files
committed
add e2e ldap tests
1 parent 681b9a8 commit ad1cbb2

File tree

7 files changed

+58
-4
lines changed

7 files changed

+58
-4
lines changed

.github/workflows/workflow.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ jobs:
4040
if: always()
4141
run: docker compose down
4242

43+
- name: Run ldap containers
44+
run: docker compose -f docker-compose.yml -f docker-compose.ldap.yml up -d
45+
46+
- name: Run ldap test
47+
run: npm run test:ldap
48+
49+
- name: Stop ldap containers
50+
if: always()
51+
run: docker compose -f docker-compose.yml -f docker-compose.ldap.yml down
52+
4353
- name: SonarCloud Scan
4454
uses: SonarSource/sonarcloud-github-action@master
4555
env:

docker-compose.ldap.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: "3.7"
21
services:
32
api:
43
environment:

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"test:cov": "jest --projects src --coverage",
2121
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --projects src --runInBand",
2222
"test:e2e": "jest --projects test",
23-
"test:acceptance": "jest --projects test_acceptance"
23+
"test:acceptance": "jest --projects test_acceptance",
24+
"test:ldap": "jest --projects test_ldap"
2425
},
2526
"engines": {
2627
"node": ">=18.12.0"

src/users/ldap/ldapusers.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class LdapUsersService implements Users {
4141
attributeMail: this.configService.getOrThrow<string>('LDAP_ATTRIBUTE_MAIL'),
4242
attributeFirstName: this.configService.getOrThrow<string>('LDAP_ATTRIBUTE_FIRST_NAME'),
4343
attributeLastName: this.configService.getOrThrow<string>('LDAP_ATTRIBUTE_LAST_NAME'),
44-
tlsNoVerify: this.configService.get<boolean>('LDAP_TLS_NO_VERIFY', false),
44+
tlsNoVerify: this.configService.get<string>('LDAP_TLS_NO_VERIFY', 'false').toLowerCase() === 'true',
4545
};
4646
this.ldapClient = new LdapClient({
4747
url: this.ldapConfig.url,

src/users/users.factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class UsersFactoryService {
1717
) {}
1818

1919
getUsersService(): Users {
20-
const serviceType = this.configService.get<boolean>('LDAP_ENABLED', false);
20+
const serviceType = this.configService.get<string>('LDAP_ENABLED', 'false')?.toLowerCase() === 'true';
2121
switch (serviceType) {
2222
case true:
2323
this.logger.debug('users service type: LDAP');

test_ldap/jest.config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** @returns {Promise<import('jest').Config>} */
2+
module.exports = async () => {
3+
return {
4+
displayName: 'Ldap',
5+
roots: ['./'],
6+
testTimeout: 30000,
7+
testRegex: '.spec.ts$',
8+
moduleFileExtensions: ['js', 'json', 'ts'],
9+
transform: {
10+
'^.+\\.(t|j)s$': 'ts-jest',
11+
},
12+
testEnvironment: 'node',
13+
};
14+
};

test_ldap/ldap.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import axios from 'axios';
2+
import { UserLoginRequestDto } from 'src/users/dto/user-login-request.dto';
3+
import { UserLoginResponseDto } from 'src/users/dto/user-login-response.dto';
4+
5+
axios.defaults.baseURL = 'http://localhost:4200';
6+
7+
const loginData: UserLoginRequestDto = {
8+
9+
password: 'password',
10+
};
11+
const wrongLoginData: UserLoginRequestDto = {
12+
email: loginData.email,
13+
password: 'wrongpassword',
14+
};
15+
16+
describe('Ldap', () => {
17+
test('Sucessful login', async () => {
18+
const response = await axios.post<UserLoginResponseDto>('/users/login', loginData);
19+
20+
expect(response.status).toBe(201);
21+
expect(response.data.token).toBeDefined();
22+
});
23+
24+
test('Unsucessful login', async () => {
25+
await axios.post<UserLoginResponseDto>('/users/login', wrongLoginData).catch((error) => {
26+
expect(error.response.status).toBe(400);
27+
expect(error.response.data.message).toContain('Invalid email or password.');
28+
});
29+
});
30+
});

0 commit comments

Comments
 (0)