Cypress improvements, move mkcert back to command line

This commit is contained in:
Jamie Curnow committed 2026-05-19 08:51:52 +10:00
1 parent f53bf88f4d
commit 11955e5dff
10 files changed
+133 -210

No files matched your search

+1
View File
@@ -2,6 +2,7 @@ import { defineConfig } from 'cypress';
import pluginSetup from '../plugins/index.mjs';
export default defineConfig({
allowCypressEnv: false,
requestTimeout: 30000,
defaultCommandTimeout: 20000,
reporter: "cypress-multi-reporters",
+1
View File
@@ -2,6 +2,7 @@ import { defineConfig } from 'cypress';
import pluginSetup from '../plugins/index.mjs';
export default defineConfig({
allowCypressEnv: false,
requestTimeout: 30000,
defaultCommandTimeout: 20000,
reporter: "cypress-multi-reporters",
-65
View File
@@ -1,65 +0,0 @@
/// <reference types="cypress" />
describe('LDAP with Authentik', () => {
let _token;
if (cy.env('skipStackCheck') === 'true' || cy.env('stack') === 'postgres') {
before(() => {
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.skip('Should log in with LDAP', () => {
// 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');
// });
});
}
});
-97
View File
@@ -1,97 +0,0 @@
/// <reference types="cypress" />
describe('OAuth with Authentik', () => {
let _token;
if (cy.env('skipStackCheck') === 'true' || cy.env('stack') === 'postgres') {
before(() => {
cy.getToken().then((tok) => {
_token = tok;
// cy.task('backendApiPut', {
// token: token,
// path: '/api/settings/oauth-auth',
// data: {
// value: {
// client_id: '7iO2AvuUp9JxiSVkCcjiIbQn4mHmUMBj7yU8EjqU',
// client_secret: 'VUMZzaGTrmXJ8PLksyqzyZ6lrtz04VvejFhPMBP9hGZNCMrn2LLBanySs4ta7XGrDr05xexPyZT1XThaf4ubg00WqvHRVvlu4Naa1aMootNmSRx3VAk6RSslUJmGyHzq',
// authorization_url: 'http://authentik:9000/application/o/authorize/',
// resource_url: 'http://authentik:9000/application/o/userinfo/',
// token_url: 'http://authentik:9000/application/o/token/',
// logout_url: 'http://authentik:9000/application/o/npm/end-session/',
// identifier: 'preferred_username',
// scopes: [],
// 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',
// 'oauth'
// ]
// }
// }).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.skip('Should log in with OAuth', () => {
// cy.task('backendApiGet', {
// path: '/oauth/login?redirect_base=' + encodeURI(Cypress.config('baseUrl')),
// }).then((data) => {
// expect(data).to.have.property('result');
// cy.origin('http://authentik:9000', {args: data.result}, (url) => {
// cy.visit(url);
// cy.get('ak-flow-executor')
// .shadow()
// .find('ak-stage-identification')
// .shadow()
// .find('input[name="uidField"]', { visible: true })
// .type('cypress');
// cy.get('ak-flow-executor')
// .shadow()
// .find('ak-stage-identification')
// .shadow()
// .find('button[type="submit"]', { visible: true })
// .click();
// cy.get('ak-flow-executor')
// .shadow()
// .find('ak-stage-password')
// .shadow()
// .find('input[name="password"]', { visible: true })
// .type('fqXBfUYqHvYqiwBHWW7f');
// cy.get('ak-flow-executor')
// .shadow()
// .find('ak-stage-password')
// .shadow()
// .find('button[type="submit"]', { visible: true })
// .click();
// })
// // we should be logged in
// cy.get('#root p.chakra-text')
// .first()
// .should('have.text', 'Nginx Proxy Manager');
// // logout:
// cy.clearLocalStorage();
// });
});
}
});
+6 -4
View File
@@ -23,11 +23,13 @@ describe('Streams', () => {
});
// Create a custom cert pair
cy.exec('mkcert -cert-file=/test/cypress/fixtures/website1.pem -key-file=/test/cypress/fixtures/website1.key.pem website1.example.com').then((result) => {
expect(result.exitCode).to.eq(0);
// Install CA
cy.exec('mkcert -install').then((result) => {
cy.task('getFixturesFolder').then((fixturesFolder) => {
cy.exec(`mkcert -cert-file=${fixturesFolder}/website1.pem -key-file=${fixturesFolder}/website1.key.pem website1.example.com`).then((result) => {
expect(result.exitCode).to.eq(0);
// Install CA
cy.exec('mkcert -install').then((result) => {
expect(result.exitCode).to.eq(0);
});
});
});
+5
View File
@@ -22,6 +22,11 @@ export default (on, config) => {
return null;
},
});
on('task', {
getFixturesFolder() {
return config.fixturesFolder
},
});
return config;
};
+20 -25
View File
@@ -10,7 +10,6 @@
//
import 'cypress-wait-until';
import { createCA, createCert } from 'mkcert';
Cypress.Commands.add('randomString', (length) => {
let result = '';
@@ -49,14 +48,16 @@ Cypress.Commands.add("validateSwaggerFile", (url, savePath) => {
* @param {*} data The API response data to check against the swagger schema
*/
Cypress.Commands.add('validateSwaggerSchema', (method, code, path, data) => {
cy.task('validateSwaggerSchema', {
file: cy.env('swaggerBase'),
endpoint: path,
method: method,
statusCode: code,
responseSchema: data,
verbose: true
}).should('equal', null);
cy.env(['swaggerBase']).then(({ swaggerBase }) => {
cy.task('validateSwaggerSchema', {
file: swaggerBase,
endpoint: path,
method: method,
statusCode: code,
responseSchema: data,
verbose: true
}).should('equal', null);
});
});
Cypress.Commands.add('createInitialUser', (defaultUser) => {
@@ -156,21 +157,15 @@ Cypress.Commands.add('waitForCertificateStatus', (token, certID, expected, timeo
// Creates CA files for testing, if they already exist they will be deleted
// and recreated with the same content. This is to ensure that the files exist
// for testing and are in a known state.
Cypress.Commands.add('createCustomCerts', async () => {
const ca = await createCA({
organization: "NPM CA",
countryCode: "AU",
state: "QLD",
locality: "Brisbane",
validity: 365
Cypress.Commands.add('createCustomCerts', () => {
cy.task('getFixturesFolder').then((fixturesFolder) => {
cy.exec(`mkcert -cert-file=${fixturesFolder}/test.example.com.pem -key-file=${fixturesFolder}/test.example.com-key.pem test.example.com`)
.then((result) => {
expect(result.exitCode).to.eq(0);
// Install CA
cy.exec('mkcert -install').then((result) => {
expect(result.exitCode).to.eq(0);
});
});
});
const cert = await createCert({
ca: { key: ca.key, cert: ca.cert },
domains: ["test.example.com"],
validity: 365
});
cy.writeFile(`${config.fixturesFolder}/test.example.com.pem`, cert.cert);
cy.writeFile(`${config.fixturesFolder}/test.example.com-key.pem`, cert.key);
});
+100
View File
@@ -0,0 +1,100 @@
import fs from "node:fs";
import FormData from "form-data";
import Client from "./client.mjs";
import logger from "./logger.mjs";
export default (config) => {
logger("Client Ready using", config.baseUrl);
return {
/**
* @param {object} options
* @param {string} options.path API path
* @param {string} [options.token] JWT
* @param {bool} [options.returnOnError] If true, will return instead of throwing errors
* @returns {string}
*/
backendApiGet: (options) => {
const api = new Client(config);
api.setToken(options.token);
return api.request("get", options.path, options.returnOnError || false);
},
/**
* @param {object} options
* @param {string} options.token JWT
* @param {string} options.path API path
* @param {object} options.data
* @param {bool} [options.returnOnError] If true, will return instead of throwing errors
* @returns {string}
*/
backendApiPost: (options) => {
const api = new Client(config);
api.setToken(options.token);
return api.request(
"post",
options.path,
options.returnOnError || false,
options.data,
);
},
/**
* @param {object} options
* @param {string} options.token JWT
* @param {string} options.path API path
* @param {object} options.files
* @param {bool} [options.returnOnError] If true, will return instead of throwing errors
* @returns {string}
*/
backendApiPostFiles: (options) => {
const api = new Client(config);
api.setToken(options.token);
const form = new FormData();
for (const [key, value] of Object.entries(options.files)) {
form.append(
key,
fs.createReadStream(`${config.fixturesFolder}/${value}`),
);
}
return api.postForm(options.path, form, options.returnOnError || false);
},
/**
* @param {object} options
* @param {string} options.token JWT
* @param {string} options.path API path
* @param {object} options.data
* @param {bool} [options.returnOnError] If true, will return instead of throwing errors
* @returns {string}
*/
backendApiPut: (options) => {
const api = new Client(config);
api.setToken(options.token);
return api.request(
"put",
options.path,
options.returnOnError || false,
options.data,
);
},
/**
* @param {object} options
* @param {string} options.token JWT
* @param {string} options.path API path
* @param {bool} [options.returnOnError] If true, will return instead of throwing errors
* @returns {string}
*/
backendApiDelete: (options) => {
const api = new Client(config);
api.setToken(options.token);
return api.request(
"delete",
options.path,
options.returnOnError || false,
);
},
};
};