2022-06-19 00:25:21 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
|
|
import {expect} from "chai";
|
|
|
|
import sinon from "ts-sinon";
|
|
|
|
import Chan, {ChanType} from "../../server/models/chan";
|
|
|
|
import Msg from "../../server/models/msg";
|
|
|
|
import User from "../../server/models/user";
|
|
|
|
import Network from "../../server/models/network";
|
|
|
|
import Config from "../../server/config";
|
|
|
|
import STSPolicies from "../../server/plugins/sts";
|
|
|
|
import ClientCertificate from "../../server/plugins/clientCertificate";
|
2016-03-16 05:41:19 +00:00
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
describe("Network", function () {
|
2022-06-19 00:25:21 +00:00
|
|
|
let stsPoliciesRefreshStub: sinon.SinonStub<unknown[], void>;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
stsPoliciesRefreshStub = sinon.stub(STSPolicies, "refresh");
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
stsPoliciesRefreshStub.restore();
|
|
|
|
});
|
|
|
|
|
2022-02-13 12:24:38 +00:00
|
|
|
describe("Network(attr)", function () {
|
|
|
|
it("should generate uuid (v4) for each network", function () {
|
|
|
|
const network1 = new Network();
|
|
|
|
const network2 = new Network();
|
|
|
|
|
|
|
|
expect(network1.uuid).to.have.lengthOf(36);
|
|
|
|
expect(network2.uuid).to.have.lengthOf(36);
|
|
|
|
expect(network1.uuid).to.not.equal(network2.uuid);
|
|
|
|
});
|
|
|
|
|
2023-03-14 20:24:19 +00:00
|
|
|
it("should keep the lobby at the top", function () {
|
2022-02-13 12:24:38 +00:00
|
|
|
const network = new Network({
|
|
|
|
name: "Super Nice Network",
|
|
|
|
channels: [
|
2022-06-19 00:25:21 +00:00
|
|
|
new Chan({name: "AAAA!", type: ChanType.QUERY}),
|
2022-02-13 12:24:38 +00:00
|
|
|
new Chan({name: "#thelounge"}),
|
|
|
|
new Chan({name: "&foobar"}),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
network.channels.push(new Chan({name: "#swag"}));
|
|
|
|
|
|
|
|
expect(network.channels[0].name).to.equal("Super Nice Network");
|
2022-06-19 00:25:21 +00:00
|
|
|
expect(network.channels[0].type).to.equal(ChanType.LOBBY);
|
2022-02-13 12:24:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should maintain channel reference", function () {
|
|
|
|
const chan = new Chan({
|
|
|
|
name: "#506-bug-fix",
|
|
|
|
messages: [
|
|
|
|
new Msg({
|
|
|
|
text: "message in constructor",
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
const network = new Network({
|
|
|
|
name: "networkName",
|
|
|
|
channels: [chan],
|
|
|
|
});
|
|
|
|
|
|
|
|
chan.messages.push(
|
|
|
|
new Msg({
|
|
|
|
text: "message in original instance",
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
network.channels[1].messages.push(
|
|
|
|
new Msg({
|
|
|
|
text: "message after network creation",
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(network.channels[1].messages).to.have.lengthOf(3);
|
|
|
|
expect(network.channels[1].messages[0].text).to.equal("message in constructor");
|
|
|
|
expect(network.channels[1].messages[1].text).to.equal("message in original instance");
|
|
|
|
expect(network.channels[1].messages[2].text).to.equal("message after network creation");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
describe("#export()", function () {
|
|
|
|
it("should produce an valid object", function () {
|
2018-01-11 11:33:36 +00:00
|
|
|
const network = new Network({
|
2017-11-28 17:25:15 +00:00
|
|
|
uuid: "hello world",
|
2016-12-18 09:24:50 +00:00
|
|
|
awayMessage: "I am away",
|
2016-10-02 07:37:37 +00:00
|
|
|
name: "networkName",
|
2020-03-31 08:02:18 +00:00
|
|
|
sasl: "plain",
|
|
|
|
saslAccount: "testaccount",
|
|
|
|
saslPassword: "testpassword",
|
2016-10-02 07:37:37 +00:00
|
|
|
channels: [
|
2022-02-11 01:56:17 +00:00
|
|
|
new Chan({name: "#thelounge", key: "", muted: false}),
|
|
|
|
new Chan({name: "&foobar", key: "", muted: false}),
|
|
|
|
new Chan({name: "#secret", key: "foo", muted: false}),
|
|
|
|
new Chan({name: "&secure", key: "bar", muted: true}),
|
2022-06-19 00:25:21 +00:00
|
|
|
new Chan({name: "Channel List", type: ChanType.SPECIAL}),
|
|
|
|
new Chan({name: "PrivateChat", type: ChanType.QUERY, muted: true}),
|
2017-11-15 06:35:15 +00:00
|
|
|
],
|
2016-10-02 07:37:37 +00:00
|
|
|
});
|
2016-05-12 11:30:23 +00:00
|
|
|
network.setNick("chillin`");
|
2016-03-16 05:41:19 +00:00
|
|
|
|
|
|
|
expect(network.export()).to.deep.equal({
|
2017-11-28 17:25:15 +00:00
|
|
|
uuid: "hello world",
|
2016-12-18 09:24:50 +00:00
|
|
|
awayMessage: "I am away",
|
2016-03-16 05:41:19 +00:00
|
|
|
name: "networkName",
|
|
|
|
host: "",
|
|
|
|
port: 6667,
|
|
|
|
tls: false,
|
2018-08-25 09:11:59 +00:00
|
|
|
userDisconnected: false,
|
2018-02-17 08:22:28 +00:00
|
|
|
rejectUnauthorized: false,
|
2016-03-16 05:41:19 +00:00
|
|
|
password: "",
|
|
|
|
username: "",
|
|
|
|
realname: "",
|
2020-11-25 23:37:46 +00:00
|
|
|
leaveMessage: "",
|
2020-03-31 08:02:18 +00:00
|
|
|
sasl: "plain",
|
|
|
|
saslAccount: "testaccount",
|
|
|
|
saslPassword: "testpassword",
|
2016-03-16 05:41:19 +00:00
|
|
|
commands: [],
|
2016-05-12 11:30:23 +00:00
|
|
|
nick: "chillin`",
|
2021-05-06 00:37:54 +00:00
|
|
|
proxyEnabled: false,
|
|
|
|
proxyHost: "",
|
|
|
|
proxyPort: 1080,
|
2021-10-23 00:16:04 +00:00
|
|
|
proxyPassword: "",
|
2021-05-06 00:37:54 +00:00
|
|
|
proxyUsername: "",
|
2016-06-19 17:12:42 +00:00
|
|
|
channels: [
|
2022-02-11 01:56:17 +00:00
|
|
|
{name: "#thelounge", key: "", muted: false},
|
|
|
|
{name: "&foobar", key: "", muted: false},
|
|
|
|
{name: "#secret", key: "foo", muted: false},
|
|
|
|
{name: "&secure", key: "bar", muted: true},
|
|
|
|
{name: "PrivateChat", type: "query", muted: true},
|
2017-11-15 06:35:15 +00:00
|
|
|
],
|
2018-03-11 18:17:57 +00:00
|
|
|
ignoreList: [],
|
2016-03-16 05:41:19 +00:00
|
|
|
});
|
|
|
|
});
|
2022-02-13 12:24:06 +00:00
|
|
|
});
|
2016-10-02 07:37:37 +00:00
|
|
|
|
2022-02-13 12:24:06 +00:00
|
|
|
describe("#validate()", function () {
|
|
|
|
it("should set correct defaults", function () {
|
2022-05-01 19:12:39 +00:00
|
|
|
Config.values.defaults.nick = "";
|
2018-04-03 14:49:22 +00:00
|
|
|
|
2018-03-19 08:26:24 +00:00
|
|
|
const network = new Network({
|
|
|
|
host: "localhost",
|
|
|
|
});
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
expect(network.validate({} as any)).to.be.true;
|
2018-03-19 08:26:24 +00:00
|
|
|
expect(network.nick).to.equal("thelounge");
|
|
|
|
expect(network.username).to.equal("thelounge");
|
2022-08-28 09:17:14 +00:00
|
|
|
expect(network.realname).to.equal("thelounge");
|
2018-03-19 08:26:24 +00:00
|
|
|
expect(network.port).to.equal(6667);
|
|
|
|
|
|
|
|
const network2 = new Network({
|
|
|
|
host: "localhost",
|
|
|
|
nick: "@Invalid Nick?",
|
|
|
|
});
|
2022-06-19 00:25:21 +00:00
|
|
|
expect(network2.validate({} as any)).to.be.true;
|
2018-03-19 08:26:24 +00:00
|
|
|
expect(network2.username).to.equal("InvalidNick");
|
|
|
|
});
|
|
|
|
|
2022-02-13 12:24:06 +00:00
|
|
|
it("should enforce lockNetwork", function () {
|
2022-05-01 19:12:39 +00:00
|
|
|
Config.values.lockNetwork = true;
|
2019-10-31 09:01:44 +00:00
|
|
|
|
|
|
|
// Make sure we lock in private mode
|
2022-05-01 19:12:39 +00:00
|
|
|
Config.values.public = false;
|
2018-03-19 08:26:24 +00:00
|
|
|
|
|
|
|
const network = new Network({
|
|
|
|
host: "",
|
|
|
|
port: 1337,
|
|
|
|
tls: false,
|
|
|
|
rejectUnauthorized: false,
|
|
|
|
});
|
2022-06-19 00:25:21 +00:00
|
|
|
expect(network.validate({} as any)).to.be.true;
|
2021-05-26 11:43:06 +00:00
|
|
|
expect(network.host).to.equal("irc.example.com");
|
2018-03-19 08:26:24 +00:00
|
|
|
expect(network.port).to.equal(6697);
|
|
|
|
expect(network.tls).to.be.true;
|
|
|
|
expect(network.rejectUnauthorized).to.be.true;
|
|
|
|
|
2019-10-31 09:01:44 +00:00
|
|
|
// Make sure we lock in public mode (also resets public=true for other tests)
|
2022-05-01 19:12:39 +00:00
|
|
|
Config.values.public = true;
|
2018-03-19 08:26:24 +00:00
|
|
|
|
|
|
|
const network2 = new Network({
|
|
|
|
host: "some.fake.tld",
|
|
|
|
});
|
2022-06-19 00:25:21 +00:00
|
|
|
expect(network2.validate({} as any)).to.be.true;
|
2021-05-26 11:43:06 +00:00
|
|
|
expect(network2.host).to.equal("irc.example.com");
|
2018-03-19 08:26:24 +00:00
|
|
|
|
2022-05-01 19:12:39 +00:00
|
|
|
Config.values.lockNetwork = false;
|
2018-03-19 08:26:24 +00:00
|
|
|
});
|
2022-02-13 13:21:40 +00:00
|
|
|
|
2022-08-28 09:17:14 +00:00
|
|
|
it("realname should be set to nick only if realname is empty", function () {
|
|
|
|
const network = new Network({
|
|
|
|
host: "localhost",
|
|
|
|
nick: "dummy",
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(network.validate({} as any)).to.be.true;
|
|
|
|
expect(network.nick).to.equal("dummy");
|
|
|
|
expect(network.realname).to.equal("dummy");
|
|
|
|
|
|
|
|
const network2 = new Network({
|
|
|
|
host: "localhost",
|
|
|
|
nick: "dummy",
|
|
|
|
realname: "notdummy",
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(network2.validate({} as any)).to.be.true;
|
|
|
|
expect(network2.nick).to.equal("dummy");
|
|
|
|
expect(network2.realname).to.equal("notdummy");
|
|
|
|
});
|
|
|
|
|
2022-02-13 13:21:40 +00:00
|
|
|
it("should apply STS policies iff they match", function () {
|
2022-06-19 00:25:21 +00:00
|
|
|
const client = {idMsg: 1, emit() {}} as any;
|
2022-02-13 13:21:40 +00:00
|
|
|
STSPolicies.update("irc.example.com", 7000, 3600);
|
2022-06-19 00:25:21 +00:00
|
|
|
expect(STSPolicies.get("irc.example.com")).to.not.be.null;
|
2022-02-13 13:21:40 +00:00
|
|
|
|
|
|
|
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
|
2022-06-19 00:25:21 +00:00
|
|
|
expect(STSPolicies.get("irc.example.com")).to.be.null;
|
2022-02-13 13:21:40 +00:00
|
|
|
});
|
2022-02-13 13:21:59 +00:00
|
|
|
|
2022-03-05 10:20:57 +00:00
|
|
|
it("should not remove client certs if TLS is disabled", function () {
|
2022-05-01 19:12:39 +00:00
|
|
|
Config.values.public = false;
|
2022-02-13 13:21:59 +00:00
|
|
|
|
|
|
|
const client = {idMsg: 1, emit() {}, messageStorage: []};
|
|
|
|
|
|
|
|
const network = new Network({host: "irc.example.com", sasl: "external"});
|
2022-06-19 00:25:21 +00:00
|
|
|
(network as any).createIrcFramework(client);
|
2022-02-13 13:21:59 +00:00
|
|
|
expect(network.irc).to.not.be.null;
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const client_cert = network.irc?.options?.client_certificate;
|
2022-02-13 13:21:59 +00:00
|
|
|
expect(client_cert).to.not.be.null;
|
|
|
|
expect(ClientCertificate.get(network.uuid)).to.deep.equal(client_cert);
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
expect(network.validate(client as any)).to.be.true;
|
2022-02-13 13:21:59 +00:00
|
|
|
|
2022-03-05 10:20:57 +00:00
|
|
|
expect(ClientCertificate.get(network.uuid)).to.deep.equal(client_cert); // Should be unchanged
|
2022-02-13 13:21:59 +00:00
|
|
|
|
|
|
|
ClientCertificate.remove(network.uuid);
|
2022-05-01 19:12:39 +00:00
|
|
|
Config.values.public = true;
|
2022-02-13 13:21:59 +00:00
|
|
|
});
|
2022-02-13 13:26:45 +00:00
|
|
|
|
2022-03-05 10:20:57 +00:00
|
|
|
it("should not remove client certs if there is a STS policy", function () {
|
2022-05-01 19:12:39 +00:00
|
|
|
Config.values.public = false;
|
2022-02-13 13:26:45 +00:00
|
|
|
|
|
|
|
const client = {idMsg: 1, emit() {}, messageStorage: []};
|
|
|
|
STSPolicies.update("irc.example.com", 7000, 3600);
|
2022-06-19 00:25:21 +00:00
|
|
|
expect(STSPolicies.get("irc.example.com")).to.not.be.null;
|
2022-02-13 13:26:45 +00:00
|
|
|
|
|
|
|
const network = new Network({host: "irc.example.com", sasl: "external"});
|
2022-06-19 00:25:21 +00:00
|
|
|
(network as any).createIrcFramework(client);
|
2022-02-13 13:26:45 +00:00
|
|
|
expect(network.irc).to.not.be.null;
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const client_cert = network.irc?.options?.client_certificate;
|
2022-02-13 13:26:45 +00:00
|
|
|
expect(client_cert).to.not.be.null;
|
|
|
|
expect(ClientCertificate.get(network.uuid)).to.deep.equal(client_cert);
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
expect(network.validate(client as any)).to.be.true;
|
2022-02-13 13:26:45 +00:00
|
|
|
|
|
|
|
expect(ClientCertificate.get(network.uuid)).to.deep.equal(client_cert); // Should be unchanged
|
|
|
|
|
|
|
|
ClientCertificate.remove(network.uuid);
|
2022-05-01 19:12:39 +00:00
|
|
|
Config.values.public = true;
|
2022-06-19 00:25:21 +00:00
|
|
|
|
|
|
|
STSPolicies.update("irc.example.com", 7000, 0); // Cleanup
|
|
|
|
expect(STSPolicies.get("irc.example.com")).to.be.null;
|
2022-02-13 13:26:45 +00:00
|
|
|
});
|
2022-02-13 13:21:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("#createIrcFramework(client)", function () {
|
|
|
|
it("should generate and use a client certificate when using SASL external", function () {
|
2022-05-01 19:12:39 +00:00
|
|
|
Config.values.public = false;
|
2022-02-13 13:21:59 +00:00
|
|
|
|
|
|
|
const client = {idMsg: 1, emit() {}};
|
|
|
|
STSPolicies.update("irc.example.com", 7000, 3600);
|
2022-06-19 00:25:21 +00:00
|
|
|
expect(STSPolicies.get("irc.example.com")).to.not.be.null;
|
2022-02-13 13:21:59 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
let network: any = new Network({host: "irc.example.com"});
|
2022-02-13 13:21:59 +00:00
|
|
|
network.createIrcFramework(client);
|
|
|
|
expect(network.irc).to.not.be.null;
|
|
|
|
expect(network.irc.options.client_certificate).to.be.null;
|
|
|
|
|
|
|
|
network = new Network({host: "irc.example.com", sasl: "external"});
|
|
|
|
network.createIrcFramework(client);
|
|
|
|
expect(network.irc).to.not.be.null;
|
|
|
|
expect(network.irc.options.client_certificate).to.not.be.null;
|
|
|
|
|
|
|
|
ClientCertificate.remove(network.uuid);
|
2022-05-01 19:12:39 +00:00
|
|
|
Config.values.public = true;
|
2022-06-19 00:25:21 +00:00
|
|
|
|
|
|
|
STSPolicies.update("irc.example.com", 7000, 0); // Cleanup
|
|
|
|
expect(STSPolicies.get("irc.example.com")).to.be.null;
|
2022-02-13 13:21:59 +00:00
|
|
|
});
|
2022-02-13 12:24:06 +00:00
|
|
|
});
|
2018-03-19 08:26:24 +00:00
|
|
|
|
2022-02-13 12:24:06 +00:00
|
|
|
describe("#edit(client, args)", function () {
|
|
|
|
it("should enforce correct types", function () {
|
2018-03-19 08:26:24 +00:00
|
|
|
let saveCalled = false;
|
2019-10-28 16:11:45 +00:00
|
|
|
let nameEmitCalled = false;
|
2018-03-19 08:26:24 +00:00
|
|
|
|
|
|
|
const network = new Network();
|
2022-06-19 00:25:21 +00:00
|
|
|
(network as any).edit(
|
2019-07-17 09:33:59 +00:00
|
|
|
{
|
2019-10-28 16:11:45 +00:00
|
|
|
emit(name, data) {
|
|
|
|
if (name === "network:name") {
|
|
|
|
nameEmitCalled = true;
|
|
|
|
expect(data.uuid).to.equal(network.uuid);
|
|
|
|
expect(data.name).to.equal("Lounge Test Network");
|
|
|
|
}
|
|
|
|
},
|
2019-07-17 09:33:59 +00:00
|
|
|
save() {
|
|
|
|
saveCalled = true;
|
|
|
|
},
|
2018-03-19 08:26:24 +00:00
|
|
|
},
|
2019-07-17 09:33:59 +00:00
|
|
|
{
|
|
|
|
nick: "newNick",
|
|
|
|
host: "new.tld",
|
|
|
|
name: "Lounge Test Network",
|
|
|
|
port: "1337",
|
|
|
|
tls: undefined,
|
|
|
|
rejectUnauthorized: undefined,
|
|
|
|
username: 1234,
|
|
|
|
password: 4567,
|
|
|
|
realname: 8901,
|
2020-03-31 08:02:18 +00:00
|
|
|
sasl: "something",
|
|
|
|
saslAccount: 1337,
|
|
|
|
saslPassword: 1337,
|
2019-07-17 09:33:59 +00:00
|
|
|
commands: "/command 1 2 3\r\n/ping HELLO\r\r\r\r/whois test\r\n\r\n",
|
|
|
|
ip: "newIp",
|
|
|
|
hostname: "newHostname",
|
2019-10-28 16:11:45 +00:00
|
|
|
uuid: "newuuid",
|
2019-07-17 09:33:59 +00:00
|
|
|
}
|
|
|
|
);
|
2018-03-19 08:26:24 +00:00
|
|
|
|
|
|
|
expect(saveCalled).to.be.true;
|
2019-10-28 16:11:45 +00:00
|
|
|
expect(nameEmitCalled).to.be.true;
|
|
|
|
expect(network.uuid).to.not.equal("newuuid");
|
2022-06-19 00:25:21 +00:00
|
|
|
|
|
|
|
// @ts-expect-error Property 'ip' does not exist on type 'Network'.
|
2019-07-16 09:51:22 +00:00
|
|
|
expect(network.ip).to.be.undefined;
|
2022-06-19 00:25:21 +00:00
|
|
|
// @ts-expect-error Property 'hostname' does not exist on type 'Network'.
|
2019-07-16 09:51:22 +00:00
|
|
|
expect(network.hostname).to.be.undefined;
|
2018-03-19 08:26:24 +00:00
|
|
|
|
|
|
|
expect(network.name).to.equal("Lounge Test Network");
|
|
|
|
expect(network.channels[0].name).to.equal("Lounge Test Network");
|
|
|
|
|
|
|
|
expect(network.nick).to.equal("newNick");
|
|
|
|
expect(network.host).to.equal("new.tld");
|
|
|
|
expect(network.port).to.equal(1337);
|
|
|
|
expect(network.tls).to.be.false;
|
|
|
|
expect(network.rejectUnauthorized).to.be.false;
|
|
|
|
expect(network.username).to.equal("1234");
|
|
|
|
expect(network.password).to.equal("4567");
|
|
|
|
expect(network.realname).to.equal("8901");
|
2020-03-31 08:02:18 +00:00
|
|
|
expect(network.sasl).to.equal("");
|
|
|
|
expect(network.saslAccount).to.equal("1337");
|
|
|
|
expect(network.saslPassword).to.equal("1337");
|
2018-03-19 08:26:24 +00:00
|
|
|
expect(network.commands).to.deep.equal([
|
|
|
|
"/command 1 2 3",
|
|
|
|
"/ping HELLO",
|
|
|
|
"/whois test",
|
|
|
|
]);
|
|
|
|
});
|
2022-02-13 12:24:06 +00:00
|
|
|
});
|
2018-03-19 08:26:24 +00:00
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
describe("#getFilteredClone(lastActiveChannel, lastMessage)", function () {
|
|
|
|
it("should filter channels", function () {
|
2017-11-30 21:46:55 +00:00
|
|
|
const chan = new Chan();
|
|
|
|
chan.setUser(new User({nick: "test"}));
|
|
|
|
|
|
|
|
const network = new Network({
|
2019-07-17 09:33:59 +00:00
|
|
|
channels: [chan],
|
2017-11-30 21:46:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(network.channels[0].users).to.be.empty;
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should keep necessary properties", function () {
|
2017-11-30 21:46:55 +00:00
|
|
|
const network = new Network();
|
2018-02-19 11:12:01 +00:00
|
|
|
const clone = network.getFilteredClone();
|
2017-11-30 21:46:55 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
expect(clone)
|
|
|
|
.to.be.an("object")
|
2019-11-02 18:45:00 +00:00
|
|
|
.that.has.all.keys("channels", "status", "nick", "name", "serverOptions", "uuid");
|
2019-07-17 09:33:59 +00:00
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
expect(clone.status).to.be.an("object").that.has.all.keys("connected", "secure");
|
2017-11-30 21:46:55 +00:00
|
|
|
});
|
|
|
|
});
|
2018-03-12 12:42:59 +00:00
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
describe("#addChannel(newChan)", function () {
|
|
|
|
it("should add channel", function () {
|
2018-03-12 12:42:59 +00:00
|
|
|
const chan = new Chan({name: "#thelounge"});
|
|
|
|
|
|
|
|
const network = new Network({
|
2019-07-17 09:33:59 +00:00
|
|
|
channels: [chan],
|
2018-03-12 12:42:59 +00:00
|
|
|
});
|
|
|
|
// Lobby and initial channel
|
|
|
|
expect(network.channels.length).to.equal(2);
|
|
|
|
|
2021-05-26 11:43:06 +00:00
|
|
|
const newChan = new Chan({name: "#foo"});
|
2018-03-12 12:42:59 +00:00
|
|
|
network.addChannel(newChan);
|
|
|
|
|
|
|
|
expect(network.channels.length).to.equal(3);
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should add channel alphabetically", function () {
|
2018-03-12 12:42:59 +00:00
|
|
|
const chan1 = new Chan({name: "#abc"});
|
|
|
|
const chan2 = new Chan({name: "#thelounge"});
|
|
|
|
const chan3 = new Chan({name: "#zero"});
|
|
|
|
|
|
|
|
const network = new Network({
|
2019-07-17 09:33:59 +00:00
|
|
|
channels: [chan1, chan2, chan3],
|
2021-05-26 11:43:06 +00:00
|
|
|
name: "foo",
|
2018-03-12 12:42:59 +00:00
|
|
|
});
|
|
|
|
|
2021-05-26 11:43:06 +00:00
|
|
|
const newChan = new Chan({name: "#foo"});
|
2018-03-12 12:42:59 +00:00
|
|
|
network.addChannel(newChan);
|
|
|
|
|
2021-05-26 11:43:06 +00:00
|
|
|
expect(network.channels[0].name).to.equal("foo");
|
2018-03-12 12:42:59 +00:00
|
|
|
expect(network.channels[1]).to.equal(chan1);
|
|
|
|
expect(network.channels[2]).to.equal(newChan);
|
|
|
|
expect(network.channels[3]).to.equal(chan2);
|
|
|
|
expect(network.channels[4]).to.equal(chan3);
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should sort case-insensitively", function () {
|
2018-03-12 12:42:59 +00:00
|
|
|
const chan1 = new Chan({name: "#abc"});
|
|
|
|
const chan2 = new Chan({name: "#THELOUNGE"});
|
|
|
|
|
|
|
|
const network = new Network({
|
2019-07-17 09:33:59 +00:00
|
|
|
channels: [chan1, chan2],
|
2018-03-12 12:42:59 +00:00
|
|
|
});
|
|
|
|
|
2021-05-26 11:43:06 +00:00
|
|
|
const newChan = new Chan({name: "#foo"});
|
2018-03-12 12:42:59 +00:00
|
|
|
network.addChannel(newChan);
|
|
|
|
|
|
|
|
expect(network.channels[1]).to.equal(chan1);
|
|
|
|
expect(network.channels[2]).to.equal(newChan);
|
|
|
|
expect(network.channels[3]).to.equal(chan2);
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should sort users separately from channels", function () {
|
2018-03-12 12:42:59 +00:00
|
|
|
const chan1 = new Chan({name: "#abc"});
|
|
|
|
const chan2 = new Chan({name: "#THELOUNGE"});
|
|
|
|
|
|
|
|
const network = new Network({
|
2019-07-17 09:33:59 +00:00
|
|
|
channels: [chan1, chan2],
|
2018-03-12 12:42:59 +00:00
|
|
|
});
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const newUser = new Chan({name: "mcinkay", type: ChanType.QUERY});
|
2018-03-12 12:42:59 +00:00
|
|
|
network.addChannel(newUser);
|
|
|
|
|
|
|
|
expect(network.channels[1]).to.equal(chan1);
|
|
|
|
expect(network.channels[2]).to.equal(chan2);
|
|
|
|
expect(network.channels[3]).to.equal(newUser);
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should sort users alphabetically", function () {
|
2018-03-12 12:42:59 +00:00
|
|
|
const chan1 = new Chan({name: "#abc"});
|
|
|
|
const chan2 = new Chan({name: "#THELOUNGE"});
|
2022-06-19 00:25:21 +00:00
|
|
|
const user1 = new Chan({name: "astorije", type: ChanType.QUERY});
|
|
|
|
const user2 = new Chan({name: "xpaw", type: ChanType.QUERY});
|
2018-03-12 12:42:59 +00:00
|
|
|
|
|
|
|
const network = new Network({
|
2019-07-17 09:33:59 +00:00
|
|
|
channels: [chan1, chan2, user1, user2],
|
2018-03-12 12:42:59 +00:00
|
|
|
});
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const newUser = new Chan({name: "mcinkay", type: ChanType.QUERY});
|
2018-03-12 12:42:59 +00:00
|
|
|
network.addChannel(newUser);
|
|
|
|
|
|
|
|
expect(network.channels[1]).to.equal(chan1);
|
|
|
|
expect(network.channels[2]).to.equal(chan2);
|
|
|
|
expect(network.channels[3]).to.equal(user1);
|
|
|
|
expect(network.channels[4]).to.equal(newUser);
|
|
|
|
expect(network.channels[5]).to.equal(user2);
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should not sort special channels", function () {
|
2018-03-12 12:42:59 +00:00
|
|
|
const chan1 = new Chan({name: "#abc"});
|
|
|
|
const chan2 = new Chan({name: "#THELOUNGE"});
|
2022-06-19 00:25:21 +00:00
|
|
|
const user1 = new Chan({name: "astorije", type: ChanType.QUERY});
|
|
|
|
const user2 = new Chan({name: "xpaw", type: ChanType.QUERY});
|
2018-03-12 12:42:59 +00:00
|
|
|
|
|
|
|
const network = new Network({
|
2019-07-17 09:33:59 +00:00
|
|
|
channels: [chan1, chan2, user1, user2],
|
2018-03-12 12:42:59 +00:00
|
|
|
});
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const newBanlist = new Chan({name: "Banlist for #THELOUNGE", type: ChanType.SPECIAL});
|
2018-03-12 12:42:59 +00:00
|
|
|
network.addChannel(newBanlist);
|
|
|
|
|
|
|
|
expect(network.channels[1]).to.equal(chan1);
|
|
|
|
expect(network.channels[2]).to.equal(chan2);
|
|
|
|
expect(network.channels[3]).to.equal(user1);
|
|
|
|
expect(network.channels[4]).to.equal(user2);
|
|
|
|
expect(network.channels[5]).to.equal(newBanlist);
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should not compare against special channels", function () {
|
2018-03-12 12:42:59 +00:00
|
|
|
const chan1 = new Chan({name: "#abc"});
|
|
|
|
const chan2 = new Chan({name: "#THELOUNGE"});
|
2022-06-19 00:25:21 +00:00
|
|
|
const user1 = new Chan({name: "astorije", type: ChanType.QUERY});
|
2018-03-12 12:42:59 +00:00
|
|
|
|
|
|
|
const network = new Network({
|
2019-07-17 09:33:59 +00:00
|
|
|
channels: [chan1, chan2, user1],
|
2018-03-12 12:42:59 +00:00
|
|
|
});
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const newBanlist = new Chan({name: "Banlist for #THELOUNGE", type: ChanType.SPECIAL});
|
2018-03-12 12:42:59 +00:00
|
|
|
network.addChannel(newBanlist);
|
2022-06-19 00:25:21 +00:00
|
|
|
const newUser = new Chan({name: "mcinkay", type: ChanType.QUERY});
|
2018-03-12 12:42:59 +00:00
|
|
|
network.addChannel(newUser);
|
|
|
|
|
|
|
|
expect(network.channels[1]).to.equal(chan1);
|
|
|
|
expect(network.channels[2]).to.equal(chan2);
|
|
|
|
expect(network.channels[3]).to.equal(user1);
|
|
|
|
expect(network.channels[4]).to.equal(newUser);
|
|
|
|
expect(network.channels[5]).to.equal(newBanlist);
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should insert before first special channel", function () {
|
2022-06-19 00:25:21 +00:00
|
|
|
const banlist = new Chan({name: "Banlist for #THELOUNGE", type: ChanType.SPECIAL});
|
2018-03-12 12:42:59 +00:00
|
|
|
const chan1 = new Chan({name: "#thelounge"});
|
2022-06-19 00:25:21 +00:00
|
|
|
const user1 = new Chan({name: "astorije", type: ChanType.QUERY});
|
2018-03-12 12:42:59 +00:00
|
|
|
|
|
|
|
const network = new Network({
|
2019-07-17 09:33:59 +00:00
|
|
|
channels: [banlist, chan1, user1],
|
2018-03-12 12:42:59 +00:00
|
|
|
});
|
|
|
|
|
2021-05-26 11:43:06 +00:00
|
|
|
const newChan = new Chan({name: "#foo"});
|
2018-03-12 12:42:59 +00:00
|
|
|
network.addChannel(newChan);
|
|
|
|
|
|
|
|
expect(network.channels[1]).to.equal(newChan);
|
|
|
|
expect(network.channels[2]).to.equal(banlist);
|
|
|
|
expect(network.channels[3]).to.equal(chan1);
|
|
|
|
expect(network.channels[4]).to.equal(user1);
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should never add something in front of the lobby", function () {
|
2018-03-12 12:42:59 +00:00
|
|
|
const network = new Network({
|
2021-05-26 11:43:06 +00:00
|
|
|
name: "foo",
|
2018-03-12 12:42:59 +00:00
|
|
|
channels: [],
|
|
|
|
});
|
|
|
|
|
|
|
|
const newUser = new Chan({name: "astorije"});
|
|
|
|
network.addChannel(newUser);
|
|
|
|
|
|
|
|
expect(network.channels[1]).to.equal(newUser);
|
|
|
|
});
|
|
|
|
});
|
2016-03-16 05:41:19 +00:00
|
|
|
});
|