spec/muc_util_spec.lua
author Kim Alvefur <zash@zash.se>
Thu, 20 Jan 2022 10:51:46 +0100
branch0.11
changeset 12206 ebeb4d959fb3
parent 9216 172f93f752b8
child 10719 ad86b93093a3
permissions -rw-r--r--
util.xml: Deduplicate handlers for restricted XML Makes the code more like util.xmppstream, allowing easier comparisons if we ever need to apply fixes in the future.

local muc_util;

local st = require "util.stanza";

do
	local old_pp = package.path;
	package.path = "./?.lib.lua;"..package.path;
	muc_util = require "plugins.muc.util";
	package.path = old_pp;
end

describe("muc/util", function ()
	describe("filter_muc_x()", function ()
		it("correctly filters muc#user", function ()
			local stanza = st.message({ to = "to", from = "from", id = "foo" })
				:tag("x", { xmlns = "http://jabber.org/protocol/muc#user" })
					:tag("invite", { to = "user@example.com" });

			assert.equal(1, #stanza.tags);
			assert.equal(stanza, muc_util.filter_muc_x(stanza));
			assert.equal(0, #stanza.tags);
		end);

		it("correctly filters muc#user on a cloned stanza", function ()
			local stanza = st.message({ to = "to", from = "from", id = "foo" })
				:tag("x", { xmlns = "http://jabber.org/protocol/muc#user" })
					:tag("invite", { to = "user@example.com" });

			assert.equal(1, #stanza.tags);
			local filtered = muc_util.filter_muc_x(st.clone(stanza));
			assert.equal(1, #stanza.tags);
			assert.equal(0, #filtered.tags);
		end);
	end);
end);