add persist_user_denylist and persist_user_allowlist

Closes: #3511
This commit is contained in:
Luca Matei Pintilie
2025-11-28 21:54:38 +01:00
committed by mathieui
parent fdae7b03e0
commit fbb93dbd08
6 changed files with 170 additions and 3 deletions
+89
View File
@@ -0,0 +1,89 @@
#include "catch2/catch_test_macros.hpp"
#include "utils/is_requester_allowed_to_persist.hpp"
#include "xmpp/jid.hpp"
TEST_CASE("default")
{
Jid jid("foo@example.com");
Config::clear();
Config::set("persist_user_denylist", "");
Config::set("persist_user_allowlist", "");
bool result = utils::is_requester_allowed_to_persist(jid);
CHECK(result == true);
Config::clear();
}
TEST_CASE("denylist - jid")
{
Jid jid("foo@example.com");
Config::clear();
Config::set("persist_user_denylist", "foo@example.com");
bool result = utils::is_requester_allowed_to_persist(jid);
CHECK(result == false);
Config::clear();
}
TEST_CASE("denylist - domain")
{
Jid jid("foo@example.com");
Config::clear();
Config::set("persist_user_denylist", "example.com");
bool result = utils::is_requester_allowed_to_persist(jid);
CHECK(result == false);
Config::clear();
}
TEST_CASE("allowlist - jid")
{
Jid jid("foo@example.com");
Config::clear();
Config::set("persist_user_allowlist", "foo@example.com");
bool result = utils::is_requester_allowed_to_persist(jid);
CHECK(result == true);
Config::clear();
}
TEST_CASE("allowlist - domain")
{
Jid jid("foo@example.com");
Config::clear();
Config::set("persist_user_allowlist", "example.com");
bool result = utils::is_requester_allowed_to_persist(jid);
CHECK(result == true);
Config::clear();
}
TEST_CASE("denylist + allowlist - deny domain, allow jid")
{
Jid jid("foo@example.com");
Config::clear();
Config::set("persist_user_denylist", "example.com");
Config::set("persist_user_allowlist", "foo@example.com");
bool result = utils::is_requester_allowed_to_persist(jid);
CHECK(result == true);
Config::clear();
}
TEST_CASE("denylist + allowlist - deny jid, allow domain")
{
Jid jid("foo@example.com");
Config::clear();
Config::set("persist_user_denylist", "foo@example.com");
Config::set("persist_user_allowlist", "example.com");
bool result = utils::is_requester_allowed_to_persist(jid);
CHECK(result == false);
Config::clear();
}
TEST_CASE("denylist + allowlist - deny jid, allow jid")
{
Jid jid("foo@example.com");
Config::clear();
Config::set("persist_user_denylist", "foo@example.com");
Config::set("persist_user_allowlist", "foo@example.com");
bool result = utils::is_requester_allowed_to_persist(jid);
CHECK(result == false);
Config::clear();
}