Skip to content

Commit 0f0230f

Browse files
committed
Cypress test for LDAP
1 parent 4d60876 commit 0f0230f

File tree

5 files changed

+81
-1
lines changed

5 files changed

+81
-1
lines changed

docker/docker-compose.ci.mysql.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# WARNING: This is a CI docker-compose file used for building and testing of the entire app, it should not be used for production.
22
services:
33

4+
cypress:
5+
environment:
6+
CYPRESS_stack: 'mysql'
7+
48
fullstack:
59
environment:
610
NPM_DB_DRIVER: 'mysql'

docker/docker-compose.ci.postgres.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# WARNING: This is a CI docker-compose file used for building and testing of the entire app, it should not be used for production.
22
services:
33

4+
cypress:
5+
environment:
6+
CYPRESS_stack: 'postgres'
7+
48
fullstack:
59
environment:
610
NPM_DB_DRIVER: 'postgres'

docker/docker-compose.ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ services:
8383
dockerfile: test/cypress/Dockerfile
8484
environment:
8585
CYPRESS_baseUrl: 'http://fullstack:81'
86+
CYPRESS_stack: 'sqlite'
8687
volumes:
8788
- 'cypress_logs:/results'
8889
- './dev/resolv.conf:/etc/resolv.conf:ro'

test/cypress/e2e/api/Ldap.cy.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/// <reference types="cypress" />
2+
3+
const { curry } = require("lodash");
4+
5+
// WIP
6+
7+
describe('LDAP with Authentik', () => {
8+
let token;
9+
if (Cypress.env('stack') === 'postgres') {
10+
11+
before(() => {
12+
cy.task('log', 'STACK IS: ' + Cypress.env('stack'));
13+
14+
cy.resetUsers();
15+
cy.getToken().then((tok) => {
16+
token = tok;
17+
18+
cy.task('backendApiPut', {
19+
token: token,
20+
path: '/api/settings/ldap-auth',
21+
data: {
22+
value: {
23+
host: 'authentik-ldap:3389',
24+
base_dn: 'ou=users,DC=ldap,DC=goauthentik,DC=io',
25+
user_dn: 'cn={{USERNAME}},ou=users,DC=ldap,DC=goauthentik,DC=io',
26+
email_property: 'mail',
27+
name_property: 'sn',
28+
self_filter: '(&(cn={{USERNAME}})(ak-active=TRUE))',
29+
auto_create_user: true
30+
}
31+
}
32+
}).then((data) => {
33+
cy.validateSwaggerSchema('put', 200, '/settings/{settingID}', data);
34+
expect(data.result).to.have.property('id');
35+
expect(data.result.id).to.be.greaterThan(0);
36+
});
37+
38+
cy.task('backendApiPut', {
39+
token: token,
40+
path: '/api/settings/auth-methods',
41+
data: {
42+
value: [
43+
'local',
44+
'ldap'
45+
]
46+
}
47+
}).then((data) => {
48+
cy.validateSwaggerSchema('put', 200, '/settings/{settingID}', data);
49+
expect(data.result).to.have.property('id');
50+
expect(data.result.id).to.be.greaterThan(0);
51+
});
52+
});
53+
});
54+
55+
it('Should log in with LDAP', function() {
56+
cy.task('backendApiPost', {
57+
token: token,
58+
path: '/api/auth',
59+
data: {
60+
type: 'ldap',
61+
identity: 'admin',
62+
secret: 'admin'
63+
}
64+
}).then((data) => {
65+
cy.validateSwaggerSchema('post', 200, '/auth', data);
66+
expect(data.result).to.have.property('token');
67+
});
68+
});
69+
}
70+
});

test/cypress/plugins/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const {SwaggerValidation} = require('@jc21/cypress-swagger-validation');
2+
const chalk = require('chalk');
23

34
module.exports = (on, config) => {
45
// Replace swaggerFile config var wildcard
@@ -11,7 +12,7 @@ module.exports = (on, config) => {
1112
on('task', require('./backendApi/task')(config));
1213
on('task', {
1314
log(message) {
14-
console.log(message);
15+
console.log(chalk.cyan.bold('[') + chalk.blue.bold('LOG') + chalk.cyan.bold(']') + ' ' + chalk.red.bold(message));
1516
return null;
1617
}
1718
});

0 commit comments

Comments
 (0)