mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 00:13:12 +09:00
Use pre-generated certificate for HttpCloser test (#477)
Remove ugly hack to generate and use an insecure certificate on the fly in the HttpCloser's https tests and replace it with the already existing properly generated test certificate. Removes the dependency on node-forge.
This commit is contained in:
1 parent
4e9f3ee173
commit
87598b24ee
2 files changed
+4
-36
No files matched your search
@@ -34,7 +34,6 @@
|
|||||||
"jsonwebtoken": "^8.2.1",
|
"jsonwebtoken": "^8.2.1",
|
||||||
"jszip": "^3.2.2",
|
"jszip": "^3.2.2",
|
||||||
"mocha": "^9.2.2",
|
"mocha": "^9.2.2",
|
||||||
"node-forge": "^1.3.1",
|
|
||||||
"nyc": "^15.1.0",
|
"nyc": "^15.1.0",
|
||||||
"phin": "^3.5.1"
|
"phin": "^3.5.1"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
const assert = require("assert").strict;
|
const assert = require("assert").strict;
|
||||||
|
const fs = require("fs-extra");
|
||||||
const http = require("http");
|
const http = require("http");
|
||||||
const https = require("https");
|
const https = require("https");
|
||||||
const util = require("util");
|
const util = require("util");
|
||||||
const tls = require("tls");
|
|
||||||
|
|
||||||
const forge = require("node-forge");
|
|
||||||
const phin = require("phin");
|
const phin = require("phin");
|
||||||
|
|
||||||
const { wait } = require("@clusterio/lib/helpers");
|
const { wait } = require("@clusterio/lib/helpers");
|
||||||
@@ -14,21 +13,6 @@ const HttpCloser = require("@clusterio/master/src/HttpCloser");
|
|||||||
// Time to wait during async operations to ensure they happened in order.
|
// Time to wait during async operations to ensure they happened in order.
|
||||||
const tick = 20;
|
const tick = 20;
|
||||||
|
|
||||||
const origCreateSecureContext = tls.createSecureContext;
|
|
||||||
tls.createSecureContext = function(options) {
|
|
||||||
if (!options.cert || !options.key) {
|
|
||||||
return origCreateSecureContext(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
let lessOptions = { ...options };
|
|
||||||
delete lessOptions.key;
|
|
||||||
delete lessOptions.cert;
|
|
||||||
let ctx = origCreateSecureContext(lessOptions);
|
|
||||||
ctx.context.setCert(options.cert);
|
|
||||||
ctx.context.setKey(options.key, undefined);
|
|
||||||
return ctx;
|
|
||||||
};
|
|
||||||
|
|
||||||
function serverSuite(proto) {
|
function serverSuite(proto) {
|
||||||
let api = proto === "http" ? http : https;
|
let api = proto === "http" ? http : https;
|
||||||
let server;
|
let server;
|
||||||
@@ -49,24 +33,9 @@ function serverSuite(proto) {
|
|||||||
|
|
||||||
before(async function() {
|
before(async function() {
|
||||||
if (proto === "https") {
|
if (proto === "https") {
|
||||||
// Generate TLS certificate
|
serverOptions.key = await fs.readFile("test/file/tls/key.pem");
|
||||||
let keypair = forge.pki.rsa.generateKeyPair(512);
|
serverOptions.cert = await fs.readFile("test/file/tls/cert.pem");
|
||||||
let cert = forge.pki.createCertificate();
|
clientOptions.ca = serverOptions.cert;
|
||||||
cert.publicKey = keypair.publicKey;
|
|
||||||
cert.serialNumber = "01";
|
|
||||||
cert.validity.notBefore = new Date();
|
|
||||||
cert.validity.notAfter = new Date(cert.validity.notBefore);
|
|
||||||
cert.validity.notAfter.setFullYear(cert.validity.notAfter.getFullYear() + 1);
|
|
||||||
let attrs = [{ name: "commonName", value: "localhost" }];
|
|
||||||
cert.setSubject(attrs);
|
|
||||||
cert.setIssuer(attrs);
|
|
||||||
cert.sign(keypair.privateKey);
|
|
||||||
serverOptions.key = forge.pki.privateKeyToPem(keypair.privateKey);
|
|
||||||
let pem = forge.pki.certificateToPem(cert);
|
|
||||||
serverOptions.cert = pem;
|
|
||||||
serverOptions.ciphers = "DEFAULT@SECLEVEL=0";
|
|
||||||
clientOptions.ca = pem;
|
|
||||||
clientOptions.ciphers = "DEFAULT@SECLEVEL=0";
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
beforeEach(async function() {
|
beforeEach(async function() {
|
||||||
|
|||||||
Reference in new issue
Block a user