spec/core_configmanager_spec.lua
author Jonas Schäfer <jonas@wielicki.name>
Mon, 10 Jan 2022 18:23:54 +0100
branch0.11
changeset 12185 783056b4e448
parent 9171 29de7ad20250
child 10499 8ea685ec0979
permissions -rw-r--r--
util.xml: Do not allow doctypes, comments or processing instructions Yes. This is as bad as it sounds. CVE pending. In Prosody itself, this only affects mod_websocket, which uses util.xml to parse the <open/> frame, thus allowing unauthenticated remote DoS using Billion Laughs. However, third-party modules using util.xml may also be affected by this. This commit installs handlers which disallow the use of doctype declarations and processing instructions without any escape hatch. It, by default, also introduces such a handler for comments, however, there is a way to enable comments nontheless. This is because util.xml is used to parse human-facing data, where comments are generally a desirable feature, and also because comments are generally harmless.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8239
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
     1
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
     2
local configmanager = require "core.configmanager";
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
     3
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
     4
describe("core.configmanager", function()
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
     5
	describe("#get()", function()
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
     6
		it("should work", function()
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
     7
			configmanager.set("example.com", "testkey", 123);
9171
29de7ad20250 spec: Correct order of arguments to asserts in configmanager tests
Kim Alvefur <zash@zash.se>
parents: 8239
diff changeset
     8
			assert.are.equal(123, configmanager.get("example.com", "testkey"), "Retrieving a set key");
8239
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
     9
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    10
			configmanager.set("*", "testkey1", 321);
9171
29de7ad20250 spec: Correct order of arguments to asserts in configmanager tests
Kim Alvefur <zash@zash.se>
parents: 8239
diff changeset
    11
			assert.are.equal(321, configmanager.get("*", "testkey1"), "Retrieving a set global key");
29de7ad20250 spec: Correct order of arguments to asserts in configmanager tests
Kim Alvefur <zash@zash.se>
parents: 8239
diff changeset
    12
			assert.are.equal(321, configmanager.get("example.com", "testkey1"), "Retrieving a set key of undefined host, of which only a globally set one exists");
8239
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    13
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    14
			configmanager.set("example.com", ""); -- Creates example.com host in config
9171
29de7ad20250 spec: Correct order of arguments to asserts in configmanager tests
Kim Alvefur <zash@zash.se>
parents: 8239
diff changeset
    15
			assert.are.equal(321, configmanager.get("example.com", "testkey1"), "Retrieving a set key, of which only a globally set one exists");
8239
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    16
9171
29de7ad20250 spec: Correct order of arguments to asserts in configmanager tests
Kim Alvefur <zash@zash.se>
parents: 8239
diff changeset
    17
			assert.are.equal(nil, configmanager.get(), "No parameters to get()");
29de7ad20250 spec: Correct order of arguments to asserts in configmanager tests
Kim Alvefur <zash@zash.se>
parents: 8239
diff changeset
    18
			assert.are.equal(nil, configmanager.get("undefined host"), "Getting for undefined host");
29de7ad20250 spec: Correct order of arguments to asserts in configmanager tests
Kim Alvefur <zash@zash.se>
parents: 8239
diff changeset
    19
			assert.are.equal(nil, configmanager.get("undefined host", "undefined key"), "Getting for undefined host & key");
8239
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    20
		end);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    21
	end);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    22
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    23
	describe("#set()", function()
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    24
		it("should work", function()
9171
29de7ad20250 spec: Correct order of arguments to asserts in configmanager tests
Kim Alvefur <zash@zash.se>
parents: 8239
diff changeset
    25
			assert.are.equal(false, configmanager.set("*"), "Set with no key");
8239
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    26
9171
29de7ad20250 spec: Correct order of arguments to asserts in configmanager tests
Kim Alvefur <zash@zash.se>
parents: 8239
diff changeset
    27
			assert.are.equal(true, configmanager.set("*", "set_test", "testkey"), "Setting a nil global value");
29de7ad20250 spec: Correct order of arguments to asserts in configmanager tests
Kim Alvefur <zash@zash.se>
parents: 8239
diff changeset
    28
			assert.are.equal(true, configmanager.set("*", "set_test", "testkey", 123), "Setting a global value");
8239
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    29
		end);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    30
	end);
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    31
end);