2022-06-19 00:25:21 +00:00
|
|
|
import fs from "fs";
|
|
|
|
import path from "path";
|
|
|
|
import {expect} from "chai";
|
|
|
|
import ClientCertificate, {ClientCertificateType} from "../../server/plugins/clientCertificate";
|
|
|
|
import Config from "../../server/config";
|
2020-03-30 20:15:32 +00:00
|
|
|
|
|
|
|
describe("ClientCertificate", function () {
|
|
|
|
it("should not generate a client certificate in public mode", function () {
|
2022-05-01 19:12:39 +00:00
|
|
|
Config.values.public = true;
|
2020-03-30 20:15:32 +00:00
|
|
|
|
|
|
|
const certificate = ClientCertificate.get("this-is-test-uuid");
|
|
|
|
expect(certificate).to.be.null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should generate a client certificate", function () {
|
2022-05-01 19:12:39 +00:00
|
|
|
Config.values.public = false;
|
2022-06-19 00:25:21 +00:00
|
|
|
const certificate = ClientCertificate.get("this-is-test-uuid") as ClientCertificateType;
|
2020-03-30 20:15:32 +00:00
|
|
|
|
|
|
|
expect(certificate.certificate).to.match(/^-----BEGIN CERTIFICATE-----/);
|
|
|
|
expect(certificate.private_key).to.match(/^-----BEGIN RSA PRIVATE KEY-----/);
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const certificate2 = ClientCertificate.get("this-is-test-uuid") as ClientCertificateType;
|
2020-03-30 20:15:32 +00:00
|
|
|
expect(certificate2.certificate).to.equal(certificate.certificate);
|
|
|
|
expect(certificate2.private_key).to.equal(certificate.private_key);
|
|
|
|
|
2022-05-01 19:12:39 +00:00
|
|
|
Config.values.public = true;
|
2020-03-30 20:15:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should remove the client certificate files", function () {
|
2022-05-01 19:12:39 +00:00
|
|
|
Config.values.public = false;
|
2020-03-30 20:15:32 +00:00
|
|
|
|
|
|
|
const privateKeyPath = path.join(
|
2022-05-01 19:12:39 +00:00
|
|
|
Config.getClientCertificatesPath(),
|
2020-03-30 20:15:32 +00:00
|
|
|
`this-is-test-uuid.pem`
|
|
|
|
);
|
|
|
|
const certificatePath = path.join(
|
2022-05-01 19:12:39 +00:00
|
|
|
Config.getClientCertificatesPath(),
|
2020-03-30 20:15:32 +00:00
|
|
|
`this-is-test-uuid.crt`
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(fs.existsSync(privateKeyPath)).to.be.true;
|
|
|
|
expect(fs.existsSync(certificatePath)).to.be.true;
|
|
|
|
|
|
|
|
ClientCertificate.remove("this-is-test-uuid");
|
|
|
|
|
|
|
|
expect(fs.existsSync(privateKeyPath)).to.be.false;
|
|
|
|
expect(fs.existsSync(certificatePath)).to.be.false;
|
|
|
|
|
2022-05-01 19:12:39 +00:00
|
|
|
Config.values.public = true;
|
2020-03-30 20:15:32 +00:00
|
|
|
});
|
|
|
|
});
|