mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-10 03:32:52 +00:00
refactor: update dependencies
This commit is contained in:
committed by
Rainer Killinger
parent
9512bca329
commit
053a6ce23f
@@ -1,207 +0,0 @@
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import {expect} from 'chai';
|
||||
import {ContainerInfo} from 'dockerode';
|
||||
import {slow, suite, test, timeout} from 'mocha-typescript';
|
||||
import * as sinon from 'sinon';
|
||||
import {containerMatchesRegex, generateUpstreamMap, getGatewayOfStAppsBackend} from '../src/main';
|
||||
|
||||
const logger = new Logger();
|
||||
|
||||
process.on('unhandledRejection', (err) => {
|
||||
logger.error('UNHANDLED REJECTION', err.stack);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
@suite(timeout(1000), slow(500))
|
||||
// @ts-ignore
|
||||
class ContainerInfoParsing {
|
||||
|
||||
static anyContainerWithExposedPorts: ContainerInfo;
|
||||
static backendContainerWithExposedPorts: ContainerInfo;
|
||||
|
||||
static before(done: () => void) {
|
||||
// tslint:disable:object-literal-sort-keys
|
||||
this.backendContainerWithExposedPorts = {
|
||||
Id: 'e3d3f4d18aceac2780bdb95523845d066ed25c04fc65168a5ddbd37a85671bb7',
|
||||
Names: [
|
||||
'/deployment_backend_1',
|
||||
],
|
||||
Image: 'gitlab-registry.tubit.tu-berlin.de/stapps/backend/b-tu-typescript-refactor-for-new-tslint-config',
|
||||
ImageID: 'sha256:ef9f0c8c4b6f99dd208948c7aae1d042590aa18e05ebeae4f586e4b4beebeac9',
|
||||
Command: 'node ./bin/www',
|
||||
Created: 1524669882,
|
||||
Ports: [
|
||||
{
|
||||
IP: '127.0.0.1',
|
||||
PrivatePort: 3000,
|
||||
PublicPort: 3000,
|
||||
Type: 'tcp',
|
||||
},
|
||||
],
|
||||
Labels: {
|
||||
'com.docker.compose.config-hash': '91c6e0cebad15951824162c93392b6880b69599692f07798ae8de659c1616a03',
|
||||
'com.docker.compose.container-number': '1',
|
||||
'com.docker.compose.oneoff': 'False',
|
||||
'com.docker.compose.project': 'deployment',
|
||||
'com.docker.compose.service': 'backend',
|
||||
'com.docker.compose.version': '1.21.0',
|
||||
'stapps.version': '1.0.0',
|
||||
},
|
||||
State: 'running',
|
||||
Status: 'Up 3 minutes',
|
||||
HostConfig: {
|
||||
NetworkMode: 'deployment_default',
|
||||
},
|
||||
NetworkSettings: {
|
||||
Networks: {
|
||||
deployment_default: {
|
||||
IPAMConfig: null,
|
||||
Links: null,
|
||||
Aliases: null,
|
||||
NetworkID: '947ea5247cc7429e1fdebd5404fa4d15f7c05e6765f2b93ddb3bdb6aaffd1193',
|
||||
EndpointID: 'da17549a086ff2c9f622e80de833e6f334afda52c8f07080428640c1716dcd14',
|
||||
Gateway: '172.18.0.1',
|
||||
IPAddress: '172.18.0.3',
|
||||
IPPrefixLen: 16,
|
||||
IPv6Gateway: '',
|
||||
GlobalIPv6Address: '',
|
||||
GlobalIPv6PrefixLen: 0,
|
||||
MacAddress: '03:41:ac:11:00:23',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// tslint:disable:object-literal-sort-keys
|
||||
this.anyContainerWithExposedPorts = {
|
||||
Id: 'e3d3f4d18aceac2780bdb95523845d066ed25c04fc65168a5ddbd37a85671bb7',
|
||||
Names: [
|
||||
'/container_name_1',
|
||||
],
|
||||
Image: 'ubuntu:4',
|
||||
ImageID: 'sha256:ef9f0c8c4b6f99dd208948c7aae1d042590aa18e05ebeae4f586e4b4beebeac9',
|
||||
Command: 'sh',
|
||||
Created: 1524669882,
|
||||
Ports: [
|
||||
{
|
||||
IP: '0.0.0.0',
|
||||
PrivatePort: 80,
|
||||
PublicPort: 80,
|
||||
Type: 'tcp',
|
||||
},
|
||||
],
|
||||
Labels: {},
|
||||
State: 'running',
|
||||
Status: 'Up 3 minutes',
|
||||
HostConfig: {
|
||||
NetworkMode: 'default',
|
||||
},
|
||||
NetworkSettings: {
|
||||
Networks: {
|
||||
bridge: {
|
||||
IPAMConfig: null,
|
||||
Links: null,
|
||||
Aliases: null,
|
||||
NetworkID: '947ea5247cc7429e1fdebd5404fa4d15f7c05e6765f2b93ddb3bdb6aaffd1193',
|
||||
EndpointID: 'da17549a086ff2c9f622e80de833e6f334afda52c8f07080428640c1716dcd14',
|
||||
Gateway: '172.18.0.1',
|
||||
IPAddress: '172.18.0.3',
|
||||
IPPrefixLen: 16,
|
||||
IPv6Gateway: '',
|
||||
GlobalIPv6Address: '',
|
||||
GlobalIPv6PrefixLen: 0,
|
||||
MacAddress: '03:41:ac:11:00:23',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
done();
|
||||
}
|
||||
|
||||
// tslint:disable:no-unused-expression
|
||||
@test
|
||||
checkIfContainerDoesNotMatchAnyContainer(done: () => void) {
|
||||
expect(containerMatchesRegex(
|
||||
'anyName',
|
||||
new RegExp('d+'),
|
||||
ContainerInfoParsing.anyContainerWithExposedPorts),
|
||||
).to.be.false;
|
||||
done();
|
||||
}
|
||||
|
||||
@test
|
||||
checkIfContainerDoesNotMatchIfVersionIsIncorrect(done: () => void) {
|
||||
expect(containerMatchesRegex(
|
||||
'backend',
|
||||
new RegExp('1\\.4\\.\\d+'),
|
||||
ContainerInfoParsing.backendContainerWithExposedPorts),
|
||||
).to.be.false;
|
||||
done();
|
||||
}
|
||||
|
||||
@test
|
||||
checkIfContainerMatches(done: () => void) {
|
||||
expect(containerMatchesRegex(
|
||||
'backend',
|
||||
new RegExp('1\\.0\\.\\d+'),
|
||||
ContainerInfoParsing.backendContainerWithExposedPorts),
|
||||
).to.be.true;
|
||||
done();
|
||||
}
|
||||
|
||||
@test
|
||||
getGatewayOfAnyContainerWithExposedPorts(done: () => void) {
|
||||
expect(getGatewayOfStAppsBackend(ContainerInfoParsing.anyContainerWithExposedPorts)).to.be.equal('0.0.0.0:80');
|
||||
done();
|
||||
}
|
||||
|
||||
@test
|
||||
getGatewayOfBackendContainer(done: () => void) {
|
||||
expect(getGatewayOfStAppsBackend(ContainerInfoParsing.backendContainerWithExposedPorts))
|
||||
.to
|
||||
.be
|
||||
.equal('127.0.0.1:3000');
|
||||
done();
|
||||
}
|
||||
|
||||
@test
|
||||
upstreamMapCallsLoggerErrorWhenNoMatchingContainerIsFound(done: () => void) {
|
||||
|
||||
const stub = sinon.stub(console, 'error');
|
||||
|
||||
expect(generateUpstreamMap(
|
||||
['0\\.8\\.\\d+'],
|
||||
['1\\.1\\.\\d+'],
|
||||
[ContainerInfoParsing.backendContainerWithExposedPorts],
|
||||
)).to.be.equal('map $http_x_stapps_version $proxyurl {\n' +
|
||||
' default unsupported;\n' +
|
||||
' "~0\\.8\\.\\d+" unavailable;\n' +
|
||||
' "~1\\.1\\.\\d+" outdated;\n' +
|
||||
'}\n');
|
||||
|
||||
stub.restore();
|
||||
expect(stub.args[0][0]).contains('[ERROR] No backend for version').and.contains('found');
|
||||
done();
|
||||
}
|
||||
|
||||
@test
|
||||
upstreamMapWithOneActiveVersionAndNoOutdatedOnes(done: () => void) {
|
||||
expect(
|
||||
generateUpstreamMap(
|
||||
['1\\.0\\.\\d+'],
|
||||
['0\\.8\\.\\d+'],
|
||||
[ContainerInfoParsing.backendContainerWithExposedPorts],
|
||||
),
|
||||
).to.be.equal(
|
||||
'map $http_x_stapps_version $proxyurl {\n' +
|
||||
' default unsupported;\n' +
|
||||
' "~1\\.0\\.\\d+" 1__0___d_;\n' +
|
||||
' "~0\\.8\\.\\d+" outdated;\n' +
|
||||
'}\n' +
|
||||
'upstream 1__0___d_ {\n' +
|
||||
' server 127.0.0.1:3000;\n' +
|
||||
'}\n',
|
||||
);
|
||||
done();
|
||||
}
|
||||
}
|
||||
54
test/common.spec.ts
Normal file
54
test/common.spec.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2019 StApps
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// tslint:disable:no-implicit-dependencies
|
||||
// tslint:disable:no-magic-numbers
|
||||
// tslint:disable:completed-docs
|
||||
// tslint:disable:prefer-function-over-method
|
||||
// tslint:disable:newline-per-chained-call
|
||||
import {suite, test} from '@testdeck/mocha';
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import {expect} from 'chai';
|
||||
import {mkdirSync, writeFileSync, unlinkSync, rmdirSync} from 'fs';
|
||||
import { resolve } from 'path';
|
||||
import { isFileType } from '../src/common';
|
||||
|
||||
process.on('unhandledRejection', async (error) => {
|
||||
await Logger.error(error);
|
||||
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
|
||||
@suite
|
||||
export class CommonSpec {
|
||||
|
||||
@test
|
||||
async testSSLCert() {
|
||||
const testCertDir = resolve(__dirname, 'certs');
|
||||
mkdirSync(testCertDir);
|
||||
const notAnExptectedFileTypeFilePath = resolve(testCertDir, 'notAnExptectedFileType.txt');
|
||||
const anExptectedFileTypeFilePath = resolve(testCertDir, 'notARealCert.crt');
|
||||
writeFileSync(notAnExptectedFileTypeFilePath,'Test');
|
||||
writeFileSync(anExptectedFileTypeFilePath,'Test');
|
||||
|
||||
expect(isFileType(notAnExptectedFileTypeFilePath,'crt')).to.equal(false)
|
||||
expect(isFileType(anExptectedFileTypeFilePath,'crt')).to.equal(true)
|
||||
|
||||
unlinkSync(notAnExptectedFileTypeFilePath);
|
||||
unlinkSync(anExptectedFileTypeFilePath);
|
||||
rmdirSync(testCertDir);
|
||||
}
|
||||
}
|
||||
322
test/main.spec.ts
Normal file
322
test/main.spec.ts
Normal file
@@ -0,0 +1,322 @@
|
||||
/*
|
||||
* Copyright (C) 2019 StApps
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// tslint:disable:no-implicit-dependencies
|
||||
// tslint:disable:no-magic-numbers
|
||||
// tslint:disable:completed-docs
|
||||
// tslint:disable:prefer-function-over-method
|
||||
// tslint:disable:newline-per-chained-call
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import chai from 'chai';
|
||||
import {expect} from 'chai';
|
||||
import chaiSpies from 'chai-spies';
|
||||
import {ContainerInfo} from 'dockerode';
|
||||
import {slow, suite, test, timeout} from '@testdeck/mocha';
|
||||
import {sslHardeningParameters, protocolHardeningParameters, SSLFilePaths } from './../src/common';
|
||||
import {containerMatchesRegex, generateUpstreamMap, getGatewayOfStAppsBackend, getTemplateView, generateListener, getContainers} from '../src/main';
|
||||
import { resolve } from 'path';
|
||||
import { mkdirSync, writeFileSync, unlinkSync, rmdirSync } from 'fs';
|
||||
|
||||
process.on('unhandledRejection', async (error) => {
|
||||
await Logger.error(error);
|
||||
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
chai.should();
|
||||
chai.use(chaiSpies);
|
||||
|
||||
@suite(timeout(1000), slow(500))
|
||||
export class MainSpec {
|
||||
static anyContainerWithExposedPorts: ContainerInfo = {
|
||||
Command: 'sh',
|
||||
Created: 1524669882,
|
||||
HostConfig: {
|
||||
NetworkMode: 'default',
|
||||
},
|
||||
Id: 'e3d3f4d18aceac2780bdb95523845d066ed25c04fc65168a5ddbd37a85671bb7',
|
||||
Image: 'ubuntu:4',
|
||||
ImageID: 'sha256:ef9f0c8c4b6f99dd208948c7aae1d042590aa18e05ebeae4f586e4b4beebeac9',
|
||||
Labels: {},
|
||||
Mounts: [],
|
||||
Names: [
|
||||
'/container_name_1',
|
||||
],
|
||||
NetworkSettings: {
|
||||
Networks: {
|
||||
bridge: {
|
||||
Aliases: null,
|
||||
EndpointID: 'da17549a086ff2c9f622e80de833e6f334afda52c8f07080428640c1716dcd14',
|
||||
Gateway: '172.18.0.1',
|
||||
GlobalIPv6Address: '',
|
||||
GlobalIPv6PrefixLen: 0,
|
||||
IPAMConfig: null,
|
||||
IPAddress: '172.18.0.3',
|
||||
IPPrefixLen: 16,
|
||||
IPv6Gateway: '',
|
||||
Links: null,
|
||||
MacAddress: '03:41:ac:11:00:23',
|
||||
NetworkID: '947ea5247cc7429e1fdebd5404fa4d15f7c05e6765f2b93ddb3bdb6aaffd1193',
|
||||
},
|
||||
},
|
||||
},
|
||||
Ports: [
|
||||
{
|
||||
IP: '0.0.0.0',
|
||||
PrivatePort: 80,
|
||||
PublicPort: 80,
|
||||
Type: 'tcp',
|
||||
},
|
||||
],
|
||||
State: 'running',
|
||||
Status: 'Up 3 minutes',
|
||||
};
|
||||
|
||||
static backendContainerWithExposedPorts: ContainerInfo = {
|
||||
Command: 'node ./bin/www',
|
||||
Created: 1524669882,
|
||||
HostConfig: {
|
||||
NetworkMode: 'deployment_default',
|
||||
},
|
||||
Id: 'e3d3f4d18aceac2780bdb95523845d066ed25c04fc65168a5ddbd37a85671bb7',
|
||||
Image: 'gitlab-registry.tubit.tu-berlin.de/stapps/backend/b-tu-typescript-refactor-for-new-tslint-config',
|
||||
ImageID: 'sha256:ef9f0c8c4b6f99dd208948c7aae1d042590aa18e05ebeae4f586e4b4beebeac9',
|
||||
Labels: {
|
||||
'com.docker.compose.config-hash': '91c6e0cebad15951824162c93392b6880b69599692f07798ae8de659c1616a03',
|
||||
'com.docker.compose.container-number': '1',
|
||||
'com.docker.compose.oneoff': 'False',
|
||||
'com.docker.compose.project': 'deployment',
|
||||
'com.docker.compose.service': 'backend',
|
||||
'com.docker.compose.version': '1.21.0',
|
||||
'stapps.version': '1.0.0',
|
||||
},
|
||||
Mounts: [],
|
||||
Names: [
|
||||
'/deployment_backend_1',
|
||||
],
|
||||
NetworkSettings: {
|
||||
Networks: {
|
||||
deployment_default: {
|
||||
Aliases: null,
|
||||
EndpointID: 'da17549a086ff2c9f622e80de833e6f334afda52c8f07080428640c1716dcd14',
|
||||
Gateway: '172.18.0.1',
|
||||
GlobalIPv6Address: '',
|
||||
GlobalIPv6PrefixLen: 0,
|
||||
IPAMConfig: null,
|
||||
IPAddress: '172.18.0.3',
|
||||
IPPrefixLen: 16,
|
||||
IPv6Gateway: '',
|
||||
Links: null,
|
||||
MacAddress: '03:41:ac:11:00:23',
|
||||
NetworkID: '947ea5247cc7429e1fdebd5404fa4d15f7c05e6765f2b93ddb3bdb6aaffd1193',
|
||||
},
|
||||
},
|
||||
},
|
||||
Ports: [
|
||||
{
|
||||
IP: '127.0.0.1',
|
||||
PrivatePort: 3000,
|
||||
PublicPort: 3000,
|
||||
Type: 'tcp',
|
||||
},
|
||||
],
|
||||
State: 'running',
|
||||
Status: 'Up 3 minutes',
|
||||
};
|
||||
|
||||
static sandbox = chai.spy.sandbox();
|
||||
|
||||
before() {
|
||||
MainSpec.sandbox.restore();
|
||||
}
|
||||
|
||||
@test
|
||||
checkIfContainerDoesNotMatchAnyContainer() {
|
||||
expect(containerMatchesRegex(
|
||||
'anyName',
|
||||
new RegExp('d+'),
|
||||
MainSpec.anyContainerWithExposedPorts),
|
||||
).to.be.equal(false);
|
||||
}
|
||||
|
||||
@test
|
||||
checkIfContainerDoesNotMatchIfVersionIsIncorrect() {
|
||||
expect(containerMatchesRegex(
|
||||
'backend',
|
||||
new RegExp('1\\.4\\.\\d+'),
|
||||
MainSpec.backendContainerWithExposedPorts),
|
||||
).to.be.equal(false);
|
||||
}
|
||||
|
||||
@test
|
||||
checkIfContainerMatches() {
|
||||
expect(containerMatchesRegex(
|
||||
'backend',
|
||||
new RegExp('1\\.0\\.\\d+'),
|
||||
MainSpec.backendContainerWithExposedPorts),
|
||||
).to.be.equal(true);
|
||||
}
|
||||
|
||||
@test
|
||||
async getGatewayOfAnyContainerWithExposedPorts() {
|
||||
expect(await getGatewayOfStAppsBackend(MainSpec.anyContainerWithExposedPorts)).to.be.equal('0.0.0.0:80');
|
||||
}
|
||||
|
||||
@test
|
||||
async 'get gateway of backend container'() {
|
||||
const spy = MainSpec.sandbox.on(console, 'error', () => {
|
||||
// noop
|
||||
});
|
||||
|
||||
const containerWithoutPorts: Partial<ContainerInfo> = {
|
||||
Id: 'Foo',
|
||||
Ports: [],
|
||||
};
|
||||
|
||||
expect(await getGatewayOfStAppsBackend(containerWithoutPorts as ContainerInfo)).to.be.equal('');
|
||||
expect(spy.__spy.calls[0][0]).to.contain('Container Foo does not advertise any port.');
|
||||
}
|
||||
|
||||
@test
|
||||
async 'get gateway of backend container without ports'() {
|
||||
expect(await getGatewayOfStAppsBackend(MainSpec.backendContainerWithExposedPorts)).to.be.equal('127.0.0.1:3000');
|
||||
}
|
||||
|
||||
@test
|
||||
async upstreamMapCallsLoggerErrorWhenNoMatchingContainerIsFound() {
|
||||
const spy = MainSpec.sandbox.on(console, 'error', () => {
|
||||
});
|
||||
|
||||
expect(await generateUpstreamMap(
|
||||
['0\\.8\\.\\d+'],
|
||||
['1\\.1\\.\\d+'],
|
||||
[MainSpec.backendContainerWithExposedPorts],
|
||||
)).to.be.equal(`map $http_x_stapps_version $proxyurl {
|
||||
default unsupported;
|
||||
"~0\\.8\\.\\d+" unavailable;
|
||||
"~1\\.1\\.\\d+" outdated;
|
||||
}
|
||||
`);
|
||||
|
||||
expect(spy.__spy.calls[0][0]).to.contain('No backend for version');
|
||||
}
|
||||
|
||||
@test
|
||||
async upstreamMapWithOneActiveVersionAndNoOutdatedOnes() {
|
||||
expect(await generateUpstreamMap(
|
||||
['1\\.0\\.\\d+'],
|
||||
['0\\.8\\.\\d+'],
|
||||
[MainSpec.backendContainerWithExposedPorts],
|
||||
)).to.be.equal(`map $http_x_stapps_version $proxyurl {
|
||||
default unsupported;
|
||||
"~1\\.0\\.\\d+" 1__0___d_;
|
||||
"~0\\.8\\.\\d+" outdated;
|
||||
}
|
||||
upstream 1__0___d_ {
|
||||
server 127.0.0.1:3000;
|
||||
}
|
||||
`);
|
||||
}
|
||||
|
||||
@test
|
||||
async testGetContainers() {
|
||||
try {
|
||||
await getContainers();
|
||||
return false;
|
||||
} catch (e) {
|
||||
if (e.message.startsWith('No')) {
|
||||
// Result, if docker is installed
|
||||
expect(e.message).to.equal(`No running docker containers found.
|
||||
|
||||
Please check if docker is running and Node.js can access the docker socket (/var/run/docker.sock)`);
|
||||
} else {
|
||||
// Result, if docker is not installed
|
||||
expect(e.message).to.equal(`connect ENOENT /var/run/docker.sock`);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@test
|
||||
async testGetTemplateView() {
|
||||
|
||||
try {
|
||||
let containersWithSameVersion = [MainSpec.backendContainerWithExposedPorts, MainSpec.backendContainerWithExposedPorts];
|
||||
await getTemplateView(containersWithSameVersion);
|
||||
return false;
|
||||
} catch (e) {
|
||||
expect(e.message).to.equal(
|
||||
`Multiple backends for one version found.`);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@test
|
||||
createListenerFaultyConfig() {
|
||||
|
||||
expect(generateListener({
|
||||
certificate: 'faultyTest',
|
||||
certificateChain: 'faultyTest',
|
||||
certificateKey: 'faultyTest',
|
||||
dhparam: 'faultyTest',
|
||||
})).to
|
||||
.equal(`listen 80 default_server;
|
||||
|
||||
${protocolHardeningParameters}
|
||||
`);
|
||||
|
||||
}
|
||||
|
||||
@test
|
||||
createListenerCorrectConfig() {
|
||||
const testCertDir = resolve(__dirname, 'certs');
|
||||
mkdirSync(testCertDir);
|
||||
|
||||
const certificateFile = resolve(testCertDir, 'ssl.crt');
|
||||
const certificateKeyFile = resolve(testCertDir, 'ssl.key');
|
||||
const certificateChainFile = resolve(testCertDir, 'chain.crt');
|
||||
const dhparamFile = resolve(testCertDir, 'dhparam.pem');
|
||||
|
||||
writeFileSync(certificateFile,'Test');
|
||||
writeFileSync(certificateKeyFile,'Test');
|
||||
writeFileSync(certificateChainFile,'Test');
|
||||
writeFileSync(dhparamFile,'Test');
|
||||
|
||||
const sslFilePaths: SSLFilePaths = {
|
||||
certificate: certificateFile,
|
||||
certificateKey: certificateKeyFile,
|
||||
certificateChain: certificateChainFile,
|
||||
dhparam: dhparamFile,
|
||||
};
|
||||
|
||||
expect(generateListener(sslFilePaths)).to.equal(`listen 443 ssl default_server;
|
||||
ssl_certificate ${sslFilePaths.certificate};
|
||||
ssl_certificate_key ${sslFilePaths.certificateKey};
|
||||
ssl_trusted_certificate ${sslFilePaths.certificateChain};
|
||||
ssl_dhparam ${sslFilePaths.dhparam};
|
||||
${sslHardeningParameters}
|
||||
|
||||
${protocolHardeningParameters}
|
||||
`);
|
||||
|
||||
unlinkSync(certificateFile);
|
||||
unlinkSync(certificateKeyFile);
|
||||
unlinkSync(certificateChainFile);
|
||||
unlinkSync(dhparamFile);
|
||||
rmdirSync(testCertDir);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
--ui mocha-typescript
|
||||
--require ts-node/register
|
||||
--require source-map-support/register
|
||||
test/*.ts
|
||||
Reference in New Issue
Block a user