mirror of
https://github.com/thelounge/thelounge
synced 2024-11-28 23:10:23 +00:00
test/models/network.js: Add a simple test for STS policies
This commit is contained in:
parent
bcd4a060ec
commit
bd2a6cc5be
2 changed files with 37 additions and 0 deletions
9
test/fixtures/env.js
vendored
9
test/fixtures/env.js
vendored
|
@ -1,4 +1,13 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
const home = require("path").join(__dirname, ".thelounge");
|
const home = require("path").join(__dirname, ".thelounge");
|
||||||
require("../../src/helper").setHome(home);
|
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);
|
||||||
|
};
|
||||||
|
|
|
@ -6,6 +6,7 @@ const Msg = require("../../src/models/msg");
|
||||||
const User = require("../../src/models/user");
|
const User = require("../../src/models/user");
|
||||||
const Network = require("../../src/models/network");
|
const Network = require("../../src/models/network");
|
||||||
const Helper = require("../../src/helper");
|
const Helper = require("../../src/helper");
|
||||||
|
const STSPolicies = require("../../src/plugins/sts");
|
||||||
|
|
||||||
describe("Network", function () {
|
describe("Network", function () {
|
||||||
describe("Network(attr)", function () {
|
describe("Network(attr)", function () {
|
||||||
|
@ -173,6 +174,33 @@ describe("Network", function () {
|
||||||
|
|
||||||
Helper.config.lockNetwork = false;
|
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 () {
|
describe("#edit(client, args)", function () {
|
||||||
|
|
Loading…
Reference in a new issue