diff --git a/test/fixtures/env.js b/test/fixtures/env.js index 67f22edb..57adf7ad 100644 --- a/test/fixtures/env.js +++ b/test/fixtures/env.js @@ -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); +}; diff --git a/test/models/network.js b/test/models/network.js index 12d9b01e..5b2b7eef 100644 --- a/test/models/network.js +++ b/test/models/network.js @@ -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 () {