Files
WoW-Hybrid-gateway/tests/private_gameplay_capture_test.cpp

73 lines
7.1 KiB
C++

#include "../native/private_gameplay_capture.hpp"
#include <fstream>
#include <iterator>
#include <stdexcept>
#include <iostream>
static void check(bool v,const char* label){if(!v)throw std::runtime_error(label);}
int main(){try{
char directory[]="/tmp/gw-private-capture-test-XXXXXX";check(mkdtemp(directory),"private testdirectory");std::string path=std::string(directory)+"/capture.jsonl";setenv("GW_PRIVATE_GAMEPLAY_CAPTURE",path.c_str(),1);
const std::vector<uint8_t> secret={0xfa,0xce,0xbe,0xef},body={1,2,3};
{PrivateGameplayCapture capture;
capture.source_in(false,123,0xdd,secret);capture.source_in(true,123,0x1ec,secret);capture.source_in(true,123,0x20c,secret);
check(!std::filesystem::exists(path),"outofscope/auth/account input must notopenfile");
capture.stage_source_out(true,123,0x12e,body);check(!std::filesystem::exists(path),"encoded unsentframe mustnotlog");capture.send_complete(false);check(!std::filesystem::exists(path),"failedsend mustnotlog");
capture.stage_source_out(true,123,0x1ed,secret);capture.send_complete(true);check(!std::filesystem::exists(path),"outboundauth excluded entirely");
capture.stage_source_out(true,123,0x12e,body);capture.send_complete(true);
capture.stage_source_out(true,123,0x95,secret);capture.send_complete(true);
capture.stage_source_out(true,123,0x97,secret);capture.send_complete(true);
capture.stage_source_out(true,123,0x9c,secret);capture.send_complete(true);
capture.native_out(true,123,0x440001,99);capture.native_out(true,123,0x2d0000,77);
capture.source_in(true,123,0xdd,body);check(capture.error()==0&&capture.count()==6,"expected realframed receive/successfulsend/metadata records");
struct stat st{};check(!stat(path.c_str(),&st)&&(st.st_mode&0777)==0600,"capture permissions600");
std::ifstream file(path);std::string text((std::istreambuf_iterator<char>(file)),{});
check(text.find("facebeef")==std::string::npos,"secretbytes mustnotleak");check(text.find("010203")!=std::string::npos,"gameplay body mustbelogged");
check(text.find("\"direction\":\"source_in\"")!=std::string::npos&&text.find("\"direction\":\"source_out\"")!=std::string::npos,"both realframe directions");
check(text.find("2949120")!=std::string::npos,"unknownnativeJoin opcode observablewithoutbody");}
std::string rankpath=std::string(directory)+"/rank.jsonl";setenv("GW_PRIVATE_GAMEPLAY_CAPTURE",rankpath.c_str(),1);
{PrivateGameplayCapture capture;
capture.guild_rank_rejected(false,123,0x2f0008,secret,"outside world");
capture.guild_rank_rejected(true,0,0x2f0008,secret,"no owner");
capture.guild_rank_rejected(true,123,0x440001,secret,"auth opcode");
const std::vector<uint8_t> oversized(129,0xff);capture.guild_rank_rejected(true,123,0x2f0008,oversized,"oversize");
check(!std::filesystem::exists(rankpath),"rank diagnostic scope/opcode/owner/size filters");
for(int i=0;i<9;++i)capture.guild_rank_rejected(true,123,0x2f0008,body,"stale or unsupported guild rank permissions");
check(capture.count()==8,"rank rejection bound");
std::ifstream file(rankpath);std::string text((std::istreambuf_iterator<char>(file)),{});
check(text.find("stale or unsupported guild rank permissions")!=std::string::npos&&text.find("010203")!=std::string::npos,"exact reason and admitted rank body");
check(text.find("facebeef")==std::string::npos,"rank scope rejects private excluded bytes");}
std::string clubpath=std::string(directory)+"/club.jsonl";setenv("GW_PRIVATE_GAMEPLAY_CAPTURE",clubpath.c_str(),1);
{PrivateGameplayCapture capture;std::vector<uint8_t> rpc(24,0);const uint64_t type=(uint64_t(0xe273de0e)<<32)|0x80000096u;
for(unsigned i=0;i<8;++i)rpc[i]=uint8_t(type>>(8*i));
capture.club_chat_request(false,123,rpc);capture.club_chat_request(true,0,rpc);
auto foreign=rpc;foreign[7]^=1;capture.club_chat_request(true,123,foreign);
check(!std::filesystem::exists(clubpath),"only authenticated owned exact Club150 bodies");
for(int i=0;i<9;++i)capture.club_chat_request(true,123,rpc);
check(capture.count()==8,"Club150 private specimen bound");}
std::string hotfixpath=std::string(directory)+"/hotfix.jsonl";setenv("GW_PRIVATE_GAMEPLAY_CAPTURE",hotfixpath.c_str(),1);
{PrivateGameplayCapture capture;std::vector<uint8_t> payload(8,0);
gw_wire_call input{};input.operation=GW_WIRE_PRIVATE_GAMEPLAY_CAPTURE;input.index=4;input.opcode=0x4b0003;input.build=payload.size();
check(!gw_wire_private_gameplay_body_input(&input,0,0,payload.data(),payload.size()),"hotfix producer requires authentication");
check(gw_wire_private_gameplay_body_input(&input,1,0,payload.data(),payload.size()),"login hotfix producer before self creation");
input.opcode=0x4b0001;check(!gw_wire_private_gameplay_body_input(&input,1,1,payload.data(),payload.size()),"other reply bodies excluded");
check(capture.notice(4,false,0,0x4b0003,payload.size(),payload),"unauthenticated hotfix diagnostic ignored");
check(!std::filesystem::exists(hotfixpath),"unauthenticated hotfix opens no file");
check(!capture.notice(4,true,0,0x4b0001,payload.size(),payload),"wrong server opcode rejected");
check(!capture.notice(4,true,0,0x4b0003,9,payload),"submitted size must match body");
std::vector<uint8_t> oversized(GW_WIRE_PRIVATE_HOTFIX_BODY_MAX+1,0);
check(!capture.notice(4,true,0,0x4b0003,oversized.size(),oversized),"bounded submitted hotfix");
check(capture.notice(4,true,0,0x4b0003,payload.size(),payload),"actual login submit captured");
check(capture.count()==1,"only valid hotfix submit recorded");
input.opcode=0x4b0000;input.build=payload.size();
check(!gw_wire_private_gameplay_body_input(&input,1,0,payload.data(),payload.size()),"truncated DBReply producer rejected");
check(!capture.notice(4,true,0,0x4b0000,payload.size(),payload),"truncated DBReply recorder rejected");
payload.resize(17);input.build=payload.size();
check(!gw_wire_private_gameplay_body_input(&input,0,0,payload.data(),payload.size()),"DBReply authentication required");
check(gw_wire_private_gameplay_body_input(&input,1,0,payload.data(),payload.size()),"DBReply pre-self producer accepted");
check(capture.notice(4,true,0,0x4b0000,payload.size(),payload),"DBReply submit captured");
check(capture.count()==2,"both admitted submit opcodes recorded");
std::ifstream file(hotfixpath);std::string text((std::istreambuf_iterator<char>(file)),{});
check(text.find("pe-after-engine-submit")!=std::string::npos && text.find("authenticated-world-transport")!=std::string::npos && text.find("0000000000000000")!=std::string::npos,"submitted hotfix bytes and truthful pre-self scope");}
std::string link=std::string(directory)+"/linked.jsonl";check(!symlink(path.c_str(),link.c_str()),"create symlink fixture");setenv("GW_PRIVATE_GAMEPLAY_CAPTURE",link.c_str(),1);{PrivateGameplayCapture rejected;rejected.source_in(true,123,0xdd,body);check(rejected.error()!=0,"unsafe output mustfail visibly nonfatally");}
std::filesystem::remove_all(directory);std::cout<<"PASS private scope/body filters/successfulsend acknowledgement/permissions/failure isolation\n";return 0;
}catch(const std::exception& e){std::cerr<<e.what()<<"\n";return 1;}}