Cypress test for LDAP

This commit is contained in:
Jamie Curnow 2024-11-04 08:16:55 +10:00
parent 4d60876394
commit c556b8acef
No known key found for this signature in database
GPG Key ID: FFBB624C43388E9E
6 changed files with 82 additions and 1 deletions

Binary file not shown.

View File

@ -1,6 +1,10 @@
# WARNING: This is a CI docker-compose file used for building and testing of the entire app, it should not be used for production.
services:
cypress:
environment:
CYPRESS_stack: 'mysql'
fullstack:
environment:
NPM_DB_DRIVER: 'mysql'

View File

@ -1,6 +1,10 @@
# WARNING: This is a CI docker-compose file used for building and testing of the entire app, it should not be used for production.
services:
cypress:
environment:
CYPRESS_stack: 'postgres'
fullstack:
environment:
NPM_DB_DRIVER: 'postgres'

View File

@ -83,6 +83,7 @@ services:
dockerfile: test/cypress/Dockerfile
environment:
CYPRESS_baseUrl: 'http://fullstack:81'
CYPRESS_stack: 'sqlite'
volumes:
- 'cypress_logs:/results'
- './dev/resolv.conf:/etc/resolv.conf:ro'

View File

@ -0,0 +1,71 @@
/// <reference types="cypress" />
const { curry } = require("lodash");
// WIP
describe('LDAP with Authentik', () => {
let token;
if (Cypress.env('stack') === 'postgres') {
before(() => {
cy.task('log', 'STACK IS: ' + Cypress.env('stack'));
cy.resetUsers();
cy.getToken().then((tok) => {
token = tok;
cy.task('backendApiPut', {
token: token,
path: '/api/settings/ldap-auth',
data: {
value: {
host: 'authentik-ldap:3389',
base_dn: 'ou=users,DC=ldap,DC=goauthentik,DC=io',
user_dn: 'cn={{USERNAME}},ou=users,DC=ldap,DC=goauthentik,DC=io',
email_property: 'mail',
name_property: 'sn',
self_filter: '(&(cn={{USERNAME}})(ak-active=TRUE))',
auto_create_user: true
}
}
}).then((data) => {
cy.validateSwaggerSchema('put', 200, '/settings/{name}', data);
expect(data.result).to.have.property('id');
expect(data.result.id).to.be.greaterThan(0);
});
cy.task('backendApiPut', {
token: token,
path: '/api/settings/auth-methods',
data: {
value: [
'local',
'ldap'
]
}
}).then((data) => {
cy.validateSwaggerSchema('put', 200, '/settings/{name}', data);
expect(data.result).to.have.property('id');
expect(data.result.id).to.be.greaterThan(0);
});
});
});
it('Should log in with LDAP', function() {
cy.task('backendApiPost', {
token: token,
path: '/api/auth',
data: {
// Authentik LDAP creds:
type: 'ldap',
identity: 'cypress',
secret: 'fqXBfUYqHvYqiwBHWW7f'
}
}).then((data) => {
cy.validateSwaggerSchema('post', 200, '/auth', data);
expect(data.result).to.have.property('token');
});
});
}
});

View File

@ -1,4 +1,5 @@
const {SwaggerValidation} = require('@jc21/cypress-swagger-validation');
const chalk = require('chalk');
module.exports = (on, config) => {
// Replace swaggerFile config var wildcard
@ -11,7 +12,7 @@ module.exports = (on, config) => {
on('task', require('./backendApi/task')(config));
on('task', {
log(message) {
console.log(message);
console.log(chalk.cyan.bold('[') + chalk.blue.bold('LOG') + chalk.cyan.bold(']') + ' ' + chalk.red.bold(message));
return null;
}
});