mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2026-02-04 18:02:54 +00:00
Compare commits
1 Commits
bd8f3530bd
...
bb4139ffdb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb4139ffdb |
@@ -109,7 +109,7 @@ services:
|
||||
- "cypress_logs:/test/results"
|
||||
- "./dev/resolv.conf:/etc/resolv.conf:ro"
|
||||
- "/etc/localtime:/etc/localtime:ro"
|
||||
command: cypress run --browser chrome --config-file=cypress/config/ci.mjs
|
||||
command: cypress run --browser chrome --config-file=cypress/config/ci.js
|
||||
networks:
|
||||
- fulltest
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ services:
|
||||
- "../test/results:/results"
|
||||
- "./dev/resolv.conf:/etc/resolv.conf:ro"
|
||||
- "/etc/localtime:/etc/localtime:ro"
|
||||
command: cypress run --browser chrome --config-file=cypress/config/ci.mjs
|
||||
command: cypress run --browser chrome --config-file=cypress/config/ci.js
|
||||
networks:
|
||||
- nginx_proxy_manager
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM cypress/included:15.9.0
|
||||
FROM cypress/included:14.0.1
|
||||
|
||||
# Disable Cypress CLI colors
|
||||
ENV FORCE_COLOR=0
|
||||
|
||||
@@ -24,10 +24,10 @@ 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);
|
||||
expect(result.code).to.eq(0);
|
||||
// Install CA
|
||||
cy.exec('mkcert -install').then((result) => {
|
||||
expect(result.exitCode).to.eq(0);
|
||||
expect(result.code).to.eq(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -56,7 +56,7 @@ describe('Streams', () => {
|
||||
expect(data).to.have.property('udp_forwarding', false);
|
||||
|
||||
cy.exec('curl --noproxy -- http://website1.example.com:1500').then((result) => {
|
||||
expect(result.exitCode).to.eq(0);
|
||||
expect(result.code).to.eq(0);
|
||||
expect(result.stdout).to.contain('yay it works');
|
||||
});
|
||||
});
|
||||
@@ -107,7 +107,7 @@ describe('Streams', () => {
|
||||
expect(data).to.have.property('udp_forwarding', true);
|
||||
|
||||
cy.exec('curl --noproxy -- http://website1.example.com:1502').then((result) => {
|
||||
expect(result.exitCode).to.eq(0);
|
||||
expect(result.code).to.eq(0);
|
||||
expect(result.stdout).to.contain('yay it works');
|
||||
});
|
||||
});
|
||||
@@ -176,7 +176,6 @@ describe('Streams', () => {
|
||||
'cert_chain_of_trust',
|
||||
'cert_extlifeSpan',
|
||||
'cert_revocation',
|
||||
'engine_problem',
|
||||
'overall_grade',
|
||||
];
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import axios from "axios";
|
||||
import logger from "./logger.mjs";
|
||||
const logger = require('./logger');
|
||||
const axios = require('axios').default;
|
||||
|
||||
const BackendApi = function (config, token) {
|
||||
const BackendApi = function(config, token) {
|
||||
this.config = config;
|
||||
this.token = token;
|
||||
this.token = token;
|
||||
|
||||
this.axios = axios.create({
|
||||
baseURL: config.baseUrl,
|
||||
@@ -14,24 +14,26 @@ const BackendApi = function (config, token) {
|
||||
/**
|
||||
* @param {string} token
|
||||
*/
|
||||
BackendApi.prototype.setToken = function (token) {
|
||||
BackendApi.prototype.setToken = function(token) {
|
||||
this.token = token;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {bool} returnOnError
|
||||
*/
|
||||
BackendApi.prototype._prepareOptions = function (returnOnError) {
|
||||
const options = {
|
||||
BackendApi.prototype._prepareOptions = function(returnOnError) {
|
||||
let options = {
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
},
|
||||
};
|
||||
Accept: 'application/json'
|
||||
}
|
||||
}
|
||||
if (this.token) {
|
||||
options.headers.Authorization = `Bearer ${this.token}`;
|
||||
options.headers.Authorization = 'Bearer ' + this.token;
|
||||
}
|
||||
if (returnOnError) {
|
||||
options.validateStatus = () => true;
|
||||
options.validateStatus = function () {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return options;
|
||||
};
|
||||
@@ -42,30 +44,13 @@ BackendApi.prototype._prepareOptions = function (returnOnError) {
|
||||
* @param {function} reject
|
||||
* @param {bool} returnOnError
|
||||
*/
|
||||
BackendApi.prototype._handleResponse = (
|
||||
response,
|
||||
resolve,
|
||||
reject,
|
||||
returnOnError,
|
||||
) => {
|
||||
logger("Response data:", response.data);
|
||||
if (
|
||||
!returnOnError &&
|
||||
typeof response.data === "object" &&
|
||||
typeof response.data.error === "object"
|
||||
) {
|
||||
if (
|
||||
typeof response.data === "object" &&
|
||||
typeof response.data.error === "object" &&
|
||||
typeof response.data.error.message !== "undefined"
|
||||
) {
|
||||
reject(
|
||||
new Error(
|
||||
`${response.data.error.code}: ${response.data.error.message}`,
|
||||
),
|
||||
);
|
||||
BackendApi.prototype._handleResponse = function(response, resolve, reject, returnOnError) {
|
||||
logger('Response data:', response.data);
|
||||
if (!returnOnError && typeof response.data === 'object' && typeof response.data.error === 'object') {
|
||||
if (typeof response.data === 'object' && typeof response.data.error === 'object' && typeof response.data.error.message !== 'undefined') {
|
||||
reject(new Error(response.data.error.code + ': ' + response.data.error.message));
|
||||
} else {
|
||||
reject(new Error(`Error ${response.status}`));
|
||||
reject(new Error('Error ' + response.status));
|
||||
}
|
||||
} else {
|
||||
resolve(response.data);
|
||||
@@ -78,10 +63,10 @@ BackendApi.prototype._handleResponse = (
|
||||
* @param {function} reject
|
||||
* @param {bool} returnOnError
|
||||
*/
|
||||
BackendApi.prototype._handleError = (err, resolve, reject, returnOnError) => {
|
||||
logger("Axios Error:", err);
|
||||
BackendApi.prototype._handleError = function(err, resolve, reject, returnOnError) {
|
||||
logger('Axios Error:', err);
|
||||
if (returnOnError) {
|
||||
resolve(typeof err.response.data !== "undefined" ? err.response.data : err);
|
||||
resolve(typeof err.response.data !== 'undefined' ? err.response.data : err);
|
||||
} else {
|
||||
reject(err);
|
||||
}
|
||||
@@ -99,11 +84,11 @@ BackendApi.prototype.request = function (method, path, returnOnError, data) {
|
||||
const options = this._prepareOptions(returnOnError);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const opts = {
|
||||
let opts = {
|
||||
method: method,
|
||||
url: path,
|
||||
...options,
|
||||
};
|
||||
...options
|
||||
}
|
||||
if (data !== undefined && data !== null) {
|
||||
opts.data = data;
|
||||
}
|
||||
@@ -125,17 +110,16 @@ BackendApi.prototype.request = function (method, path, returnOnError, data) {
|
||||
* @returns {Promise<object>}
|
||||
*/
|
||||
BackendApi.prototype.postForm = function (path, form, returnOnError) {
|
||||
logger("POST", this.config.baseUrl + path);
|
||||
logger('POST', this.config.baseUrl + path);
|
||||
const options = this._prepareOptions(returnOnError);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const opts = {
|
||||
...options,
|
||||
...form.getHeaders(),
|
||||
};
|
||||
}
|
||||
|
||||
this.axios
|
||||
.post(path, form, opts)
|
||||
this.axios.post(path, form, opts)
|
||||
.then((response) => {
|
||||
this._handleResponse(response, resolve, reject, returnOnError);
|
||||
})
|
||||
@@ -145,4 +129,4 @@ BackendApi.prototype.postForm = function (path, form, returnOnError) {
|
||||
});
|
||||
};
|
||||
|
||||
export default BackendApi;
|
||||
module.exports = BackendApi;
|
||||
7
test/cypress/plugins/backendApi/logger.js
Normal file
7
test/cypress/plugins/backendApi/logger.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const _ = require("lodash");
|
||||
|
||||
module.exports = function() {
|
||||
let arr = _.values(arguments);
|
||||
arr.unshift('[Backend API]');
|
||||
console.log.apply(null, arr);
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
const log = (...args) => {
|
||||
const arr = args;
|
||||
arr.unshift("[Backend API]");
|
||||
console.log(...arr);
|
||||
};
|
||||
|
||||
export default log;
|
||||
@@ -1,12 +1,13 @@
|
||||
import fs from "node:fs";
|
||||
import FormData from "form-data";
|
||||
import Client from "./client.mjs";
|
||||
import logger from "./logger.mjs";
|
||||
const fs = require('fs');
|
||||
const FormData = require('form-data');
|
||||
const logger = require('./logger');
|
||||
const Client = require('./client');
|
||||
|
||||
export default (config) => {
|
||||
logger("Client Ready using", config.baseUrl);
|
||||
module.exports = function (config) {
|
||||
logger('Client Ready using', config.baseUrl);
|
||||
|
||||
return {
|
||||
|
||||
/**
|
||||
* @param {object} options
|
||||
* @param {string} options.path API path
|
||||
@@ -17,7 +18,7 @@ export default (config) => {
|
||||
backendApiGet: (options) => {
|
||||
const api = new Client(config);
|
||||
api.setToken(options.token);
|
||||
return api.request("get", options.path, options.returnOnError || false);
|
||||
return api.request('get', options.path, options.returnOnError || false);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -31,12 +32,7 @@ export default (config) => {
|
||||
backendApiPost: (options) => {
|
||||
const api = new Client(config);
|
||||
api.setToken(options.token);
|
||||
return api.request(
|
||||
"post",
|
||||
options.path,
|
||||
options.returnOnError || false,
|
||||
options.data,
|
||||
);
|
||||
return api.request('post', options.path, options.returnOnError || false, options.data);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -52,11 +48,8 @@ export default (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}`),
|
||||
);
|
||||
for (let [key, value] of Object.entries(options.files)) {
|
||||
form.append(key, fs.createReadStream(config.fixturesFolder + '/' + value));
|
||||
}
|
||||
return api.postForm(options.path, form, options.returnOnError || false);
|
||||
},
|
||||
@@ -72,12 +65,7 @@ export default (config) => {
|
||||
backendApiPut: (options) => {
|
||||
const api = new Client(config);
|
||||
api.setToken(options.token);
|
||||
return api.request(
|
||||
"put",
|
||||
options.path,
|
||||
options.returnOnError || false,
|
||||
options.data,
|
||||
);
|
||||
return api.request('put', options.path, options.returnOnError || false, options.data);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -90,11 +78,7 @@ export default (config) => {
|
||||
backendApiDelete: (options) => {
|
||||
const api = new Client(config);
|
||||
api.setToken(options.token);
|
||||
return api.request(
|
||||
"delete",
|
||||
options.path,
|
||||
options.returnOnError || false,
|
||||
);
|
||||
},
|
||||
return api.request('delete', options.path, options.returnOnError || false);
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -1,26 +1,20 @@
|
||||
import { SwaggerValidation } from "@jc21/cypress-swagger-validation";
|
||||
import chalk from "chalk";
|
||||
import backendTask from "./backendApi/task.mjs";
|
||||
import { SwaggerValidation } from '@jc21/cypress-swagger-validation';
|
||||
import chalk from 'chalk';
|
||||
|
||||
export default (on, config) => {
|
||||
// Replace swaggerBase config var wildcard
|
||||
if (typeof config.env.swaggerBase !== "undefined") {
|
||||
config.env.swaggerBase = config.env.swaggerBase.replace(
|
||||
"{{baseUrl}}",
|
||||
config.baseUrl,
|
||||
);
|
||||
if (typeof config.env.swaggerBase !== 'undefined') {
|
||||
config.env.swaggerBase = config.env.swaggerBase.replace('{{baseUrl}}', config.baseUrl);
|
||||
}
|
||||
|
||||
// Plugin Events
|
||||
on("task", SwaggerValidation(config));
|
||||
on("task", backendTask(config));
|
||||
on("task", {
|
||||
on('task', SwaggerValidation(config));
|
||||
on('task', require('./backendApi/task')(config));
|
||||
on('task', {
|
||||
log(message) {
|
||||
console.log(
|
||||
`${chalk.cyan.bold("[")}${chalk.blue.bold("LOG")}${chalk.cyan.bold("]")} ${chalk.red.bold(message)}`,
|
||||
);
|
||||
console.log(`${chalk.cyan.bold('[')}${chalk.blue.bold('LOG')}${chalk.cyan.bold(']')} ${chalk.red.bold(message)}`);
|
||||
return null;
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
return config;
|
||||
|
||||
@@ -35,7 +35,7 @@ Cypress.Commands.add("validateSwaggerFile", (url, savePath) => {
|
||||
.then((response) => cy.writeFile(savePath, response.body, { log: false }))
|
||||
.then(() => cy.exec(`yarn swagger-lint '${savePath}'`, { failOnNonZeroExit: false }))
|
||||
.then((result) => cy.task('log', `Swagger Vacuum Results:\n${result.stdout || ''}`)
|
||||
.then(() => expect(result.exitCode).to.eq(0)));
|
||||
.then(() => expect(result.code).to.eq(0)));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import './commands.mjs';
|
||||
import './commands';
|
||||
|
||||
Cypress.on('uncaught:exception', (/*err, runnable*/) => {
|
||||
// returning false here prevents Cypress from
|
||||
|
||||
@@ -4,10 +4,6 @@
|
||||
"cypress/**/*.js",
|
||||
"cypress/config/dev.mjs",
|
||||
"cypress/config/ci.mjs",
|
||||
"cypress/plugins/index.mjs",
|
||||
"cypress/plugins/backendApi/task.mjs",
|
||||
"cypress/plugins/backendApi/logger.mjs",
|
||||
"cypress/plugins/backendApi/client.mjs",
|
||||
"cypress/support/commands.mjs"
|
||||
"cypress/plugins/index.mjs"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user