feat(Core/RBAC): Role Based Access Controls (#24641)
Co-authored-by: blinkysc <blinkysc@users.noreply.github.com> Co-authored-by: Spp <spp@jorge.gr> Co-authored-by: Spp <spp@tc.plus> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Andrew <47818697+Nyeriah@users.noreply.github.com>
This commit is contained in:
@@ -85,6 +85,7 @@ public:
|
||||
MOCK_METHOD(std::string const&, GetRealmName, (), (const));
|
||||
MOCK_METHOD(void, SetRealmName, (std::string name), ());
|
||||
MOCK_METHOD(void, RemoveOldCorpses, ());
|
||||
MOCK_METHOD(void, ReloadRBAC, ());
|
||||
};
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -29,11 +29,6 @@
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#ifndef TEST_F
|
||||
#define TEST_F(fixture, name) void fixture##_##name()
|
||||
#endif
|
||||
|
||||
using namespace testing;
|
||||
|
||||
@@ -111,6 +106,7 @@ protected:
|
||||
|
||||
session = new WorldSession(1, "gm", 0, nullptr, SEC_GAMEMASTER, EXPANSION_WRATH_OF_THE_LICH_KING,
|
||||
0, LOCALE_enUS, 0, false, false, 0);
|
||||
session->InitRBACDataForTest();
|
||||
|
||||
player = new TestPlayer(session);
|
||||
player->ForceInitValues();
|
||||
@@ -133,20 +129,14 @@ protected:
|
||||
player = nullptr;
|
||||
}
|
||||
|
||||
void ExecuteCommand(std::string_view text)
|
||||
void SimulateGmVisibleOff()
|
||||
{
|
||||
if (text == ".gm visible off")
|
||||
{
|
||||
ApplyGmVisibleState(false);
|
||||
}
|
||||
else if (text == ".gm visible on")
|
||||
{
|
||||
ApplyGmVisibleState(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
FAIL() << "Unsupported test command: " << text;
|
||||
}
|
||||
player->SetServerSideVisibility(SERVERSIDE_VISIBILITY_GM, session->GetSecurity());
|
||||
}
|
||||
|
||||
void SimulateGmVisibleOn()
|
||||
{
|
||||
player->SetServerSideVisibility(SERVERSIDE_VISIBILITY_GM, SEC_PLAYER);
|
||||
}
|
||||
|
||||
static void EnsureScriptRegistriesInitialized()
|
||||
@@ -167,52 +157,31 @@ protected:
|
||||
NiceMock<WorldMock>* worldMock = nullptr;
|
||||
WorldSession* session = nullptr;
|
||||
TestPlayer* player = nullptr;
|
||||
|
||||
private:
|
||||
void ApplyGmVisibleState(bool makeVisible)
|
||||
{
|
||||
constexpr uint32 VISUAL_AURA = 37800;
|
||||
|
||||
if (makeVisible)
|
||||
{
|
||||
player->RemoveAurasDueToSpell(VISUAL_AURA);
|
||||
player->SetGMVisible(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
player->AddAura(VISUAL_AURA, player);
|
||||
player->SetGMVisible(false);
|
||||
}
|
||||
|
||||
player->UpdateObjectVisibility();
|
||||
}
|
||||
};
|
||||
|
||||
// cppcheck-suppress syntaxError
|
||||
TEST_F(GmVisibleCommandTest, SetsPlayerInvisibleAndInvokesHook)
|
||||
{
|
||||
ExecuteCommand(".gm visible off");
|
||||
SimulateGmVisibleOff();
|
||||
|
||||
EXPECT_EQ(TestVisibilityScript::CallCount, 1u);
|
||||
EXPECT_EQ(TestVisibilityScript::LastPlayer, player);
|
||||
EXPECT_EQ(TestVisibilityScript::LastType, SERVERSIDE_VISIBILITY_GM);
|
||||
EXPECT_EQ(TestVisibilityScript::LastSecurity, session->GetSecurity());
|
||||
EXPECT_EQ(player->m_serverSideVisibility.GetValue(SERVERSIDE_VISIBILITY_GM), uint32(session->GetSecurity()));
|
||||
EXPECT_FALSE(player->isGMVisible());
|
||||
}
|
||||
|
||||
TEST_F(GmVisibleCommandTest, SetsPlayerVisibleAndInvokesHook)
|
||||
{
|
||||
// Ensure the player starts from invisible state to test the opposite transition as well.
|
||||
ExecuteCommand(".gm visible off");
|
||||
SimulateGmVisibleOff();
|
||||
TestVisibilityScript::Reset();
|
||||
|
||||
ExecuteCommand(".gm visible on");
|
||||
SimulateGmVisibleOn();
|
||||
|
||||
EXPECT_EQ(TestVisibilityScript::CallCount, 1u);
|
||||
EXPECT_EQ(TestVisibilityScript::LastPlayer, player);
|
||||
EXPECT_EQ(TestVisibilityScript::LastType, SERVERSIDE_VISIBILITY_GM);
|
||||
EXPECT_EQ(TestVisibilityScript::LastSecurity, SEC_PLAYER);
|
||||
EXPECT_EQ(player->m_serverSideVisibility.GetValue(SERVERSIDE_VISIBILITY_GM), uint32(SEC_PLAYER));
|
||||
EXPECT_TRUE(player->isGMVisible());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user