test/models/network.js: Add a simple test for STS policies

This commit is contained in:
Val Lorentz 2022-02-13 14:21:40 +01:00
parent bcd4a060ec
commit bd2a6cc5be
2 changed files with 37 additions and 0 deletions

View File

@ -1,4 +1,13 @@
"use strict";
const fs = require("fs");
const home = require("path").join(__dirname, ".thelounge");
require("../../src/helper").setHome(home);
const STSPolicies = require("../../src/plugins/sts"); // Must be imported *after* setHome
exports.mochaGlobalTeardown = async function () {
STSPolicies.refresh.cancel(); // Cancel debounced function, so it does not write later
fs.unlinkSync(STSPolicies.stsFile);
};

View File

@ -6,6 +6,7 @@ const Msg = require("../../src/models/msg");
const User = require("../../src/models/user");
const Network = require("../../src/models/network");
const Helper = require("../../src/helper");
const STSPolicies = require("../../src/plugins/sts");
describe("Network", function () {
describe("Network(attr)", function () {
@ -173,6 +174,33 @@ describe("Network", function () {
Helper.config.lockNetwork = false;
});
it("should apply STS policies iff they match", function () {
const client = {idMsg: 1, emit() {}};
STSPolicies.update("irc.example.com", 7000, 3600);
let network = new Network({
host: "irc.example.com",
port: 1337,
tls: false,
});
expect(network.validate(client)).to.be.true;
expect(network.port).to.equal(7000);
expect(network.tls).to.be.true;
network = new Network({
host: "irc2.example.com",
port: 1337,
tls: false,
});
expect(network.validate(client)).to.be.true;
expect(network.port).to.equal(1337);
expect(network.tls).to.be.false;
STSPolicies.update("irc.example.com", 7000, 0); // Cleanup
});
});
describe("#edit(client, args)", function () {