90 lines
2.3 KiB
C++
90 lines
2.3 KiB
C++
#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();
|
|
}
|
|
|