Files
WoW-Hybrid-gateway/tests/native_guild_name_bounds_test.cpp
2026-11-23 03:28:32 +02:00

55 lines
3.9 KiB
C++

#include "world_translation.hpp"
#include "gateway/chat.hpp"
#include <algorithm>
#include <iostream>
using namespace gateway;
namespace {
void require(bool v,const char* why){if(!v)throw Error(why);}
Bytes offer(const std::string& name){Bytes out;cstring(out,name);cstring(out,"FixtureGuild");return out;}
Bytes roster(const std::string& name){
Bytes out;le(out,1,4);cstring(out,"");cstring(out,"");le(out,1,4);le(out,0x41,4);
le(out,182,8);le(out,1,1);cstring(out,name);le(out,0,4);le(out,60,1);le(out,1,1);le(out,0,4);
cstring(out,"");cstring(out,"");return out;
}
template<class Hold,class F>void held(F call){bool caught=false;try{call();}catch(const Hold&){caught=true;}require(caught,"native storage hold missing");}
template<class F>void malformed(F call){
bool caught=false;try{call();}catch(const GuildRosterHold&){throw Error("malformed roster became hold");}
catch(const GuildInvitationHold&){throw Error("malformed invitation became hold");}
catch(const Error&){caught=true;}require(caught,"malformed Source accepted");
}
void empty(const Bytes& b){Reader r(b);require(r.le(4)==0,"unrepresentable name emitted");r.end();}
Bytes only(const Bytes& b,uint32_t op){Reader r(b);require(r.le(4)==1 && r.le(4)==op,"expected native event missing");auto body=r.take(r.le(4));Bytes out(body.begin(),body.end());r.end();return out;}
}
int main(){
try{
RosterRealm realm{};realm.realm_id=70;realm.virtual_address=0x46010046;
NativeWorldTranslation world{};world.selected.guid=182;world.realm=70;world.self_created=true;
for(size_t length:{49,63}){
const auto name=std::string(length,'n');auto invitation=turtle_guild_invitation(offer(name));
require(invitation.inviter==name,"Source inviter truncated");
held<GuildInvitationHold>([&]{forever_guild_invitation(invitation,realm.virtual_address);});
world.pending_guild_invitation=true;
empty(world.translate({0x83,offer(name)},realm.virtual_address,0,nullptr));
require(!world.pending_guild_invitation,"held offer retained response authority");
malformed([&]{world.gameplay(0x440029,Bytes{0,0});});
world.guild_id=22;auto parsed=turtle_guild_roster(roster(name));require(parsed.members[0].name==name,"Source roster name truncated");
held<GuildRosterHold>([&]{forever_guild_roster(parsed,realm);});
empty(world.translate({0x8a,roster(name)},realm.virtual_address,0,nullptr));world.guild_id=0;
}
// Byte capacity, not a Unicode character-count estimate:24 two-byte
// characters exactly fit48bytes. Preserve the encoded input verbatim.
std::string name;for(unsigned i=0;i<24;++i)name+="\xc3\xa9";
const auto packet=only(world.translate({0x83,offer(name)},realm.virtual_address,0,nullptr),0x530012);
require(world.pending_guild_invitation && packet.size()==44+name.size()+12,"48-byte invitation did not recover");
require(std::equal(name.begin(),name.end(),packet.begin()+44,[](char a,uint8_t b){return uint8_t(a)==b;}),"UTF8 bytes changed");
auto response=world.gameplay(0x440029,Bytes{0,0});require(response.opcode==0x84 && response.body.empty(),"presented offer not actionable");
world.guild_id=22;only(world.translate({0x8a,roster(name)},realm.virtual_address,0,nullptr),0x530003);world.guild_id=0;
auto truncated=offer(std::string(49,'n'));truncated.pop_back();
malformed([&]{world.translate({0x83,truncated},realm.virtual_address,0,nullptr);});
malformed([&]{world.translate({0x83,offer(std::string(64,'n'))},realm.virtual_address,0,nullptr);});
world.guild_id=22;
malformed([&]{world.translate({0x8a,roster(std::string(64,'n'))},realm.virtual_address,0,nullptr);});
std::cout<<"PASS shared guild name capacity, exact UTF8 bytes, invitation authority, recovery and malformed Source boundaries\n";
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}
}