Generate uuid per network

This commit is contained in:
Pavel Djundik 2017-11-28 19:25:15 +02:00
parent d1648823c3
commit 731b29c059
5 changed files with 21 additions and 0 deletions

View File

@ -59,6 +59,7 @@
"thelounge-ldapjs-non-maintained-fork": "1.0.2",
"ua-parser-js": "0.7.17",
"urijs": "1.19.1",
"uuid": "3.2.1",
"web-push": "3.3.0",
"yarn": "1.5.1"
},

View File

@ -174,6 +174,7 @@ Client.prototype.connect = function(args) {
args.hostname = args.hostname || (client.config && client.config.hostname) || client.hostname;
const network = new Network({
uuid: args.uuid,
name: args.name || (Helper.config.displayNetwork ? "" : Helper.config.defaults.name) || "",
host: args.host || "",
port: parseInt(args.port, 10) || (args.tls ? 6697 : 6667),

View File

@ -1,6 +1,7 @@
"use strict";
const _ = require("lodash");
const uuidv4 = require("uuid/v4");
const Chan = require("./chan");
module.exports = Network;
@ -42,6 +43,10 @@ function Network(attr) {
chanCache: [],
});
if (!this.uuid) {
this.uuid = uuidv4();
}
if (!this.name) {
this.name = this.host;
}
@ -125,6 +130,7 @@ Network.prototype.getNetworkStatus = function() {
Network.prototype.export = function() {
const network = _.pick(this, [
"uuid",
"awayMessage",
"nick",
"name",

View File

@ -306,6 +306,7 @@ function initializeClient(socket, client, token, lastMessage) {
// prevent people from overriding webirc settings
data.ip = null;
data.hostname = null;
data.uuid = null;
client.connect(data);
}

View File

@ -10,6 +10,7 @@ describe("Network", function() {
describe("#export()", function() {
it("should produce an valid object", function() {
const network = new Network({
uuid: "hello world",
awayMessage: "I am away",
name: "networkName",
channels: [
@ -24,6 +25,7 @@ describe("Network", function() {
network.setNick("chillin`");
expect(network.export()).to.deep.equal({
uuid: "hello world",
awayMessage: "I am away",
name: "networkName",
host: "",
@ -47,6 +49,15 @@ describe("Network", 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);
});
it("lobby should be at the top", function() {
const network = new Network({
name: "Super Nice Network",
@ -126,6 +137,7 @@ describe("Network", function() {
"status",
"tls",
"rejectUnauthorized",
"uuid",
"username"
);