Files
WoW-Hybrid-gateway/tests/source_public_worker_handoff_fixture.c
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

116 lines
7.5 KiB
C

/* Public profile-2 mailbox -> deferred account worker -> synchronous backend.
* Synthetic inputs/dispatcher only: no socket, game process or account data. */
#include <windows.h>
#include "wine_wire_abi.h"
static NTSTATUS WINAPI fixture_hash_dispatch(struct gw_wire_call*);
#define GW_SOURCE_ONLY_PROFILE 2
#define GW_ACCOUNT_HASH_DISPATCH fixture_hash_dispatch
#define fixture_start existing_account_fixture_start
#include "native_account_memory_fixture.c"
#undef fixture_start
static unsigned int expected_user,expected_password,hash_calls,identity_calls;
static unsigned int resolver_failure,expected_generation;
static unsigned char expected_hash[20];
struct gw_session_retirement_control gw_wire_session_retirement_data={.abi=1,.size=sizeof(struct gw_session_retirement_control),.next_credentials_generation=1};
LONG WINAPI gw_source_profile_kind(void){return 2;}
LONG WINAPI gw_source_profile_read(struct gw_source_profile* profile){
if(!profile || profile->abi!=1 || profile->size!=sizeof(*profile))return -1;
profile->kind=2;profile->auth_port=3724;return 2;
}
int gw_private_worker_resolve(unsigned int profile,char out[16]){
check(profile==2,201);if(resolver_failure)return -1;
__builtin_memcpy(out,"192.0.2.7",10);return 0;
}
int gw_private_source_realm_endpoint_eligible(unsigned int kind,const unsigned char address[4],uint16_t port){
(void)kind;(void)address;(void)port;return 0;
}
int gw_source_preflight_consume_session(uint32_t generation,const char address[16],uint32_t port){
(void)generation;(void)address;(void)port;check(0,202);return -1;
}
void gw_wire_account_identity_note(uint32_t generation,uint32_t actual,uint32_t expected,uint32_t code){
(void)expected;(void)code;check(generation==expected_generation && actual==expected_user,203);++identity_calls;
}
void gw_wire_realm_note_entered_original(void){check(0,204);}
static void verify_spans(const struct gw_native_auth_memory_ipv4_hash_config* config){
unsigned int i;
check(config->abi==GW_NATIVE_IPV4_HASH_ABI && config->size==sizeof(*config) &&
config->auth_port==3724 && config->password_bytes==expected_password &&
config->version_hash_bytes==20,210);
check(config->username!=gw_wire_auth_credentials_data.username &&
config->password!=gw_wire_auth_credentials_data.password &&
config->version_hash!=gw_wire_public_hash_data.bytes,211);
for(i=0;i<expected_user;++i)check(config->username[i]=='A',212);
check(!config->username[expected_user],213);
for(i=0;i<expected_password;++i)check(config->password[i]=='X',214);
check(!__builtin_memcmp(config->version_hash,expected_hash,20) &&
!__builtin_memcmp(config->auth_ipv4,"192.0.2.7",10),215);
}
static NTSTATUS WINAPI fixture_hash_dispatch(struct gw_wire_call* call){
struct gw_native_auth_memory_ipv4_hash_config config;
++hash_calls;check(call->input && call->input_bytes==sizeof(config),220);
__builtin_memcpy(&config,call->input,sizeof(config));
check(all_zero(&call->auth,sizeof(call->auth)) && call->reserved==GW_AUTH_DETAIL_REQUEST_V1,221);
wiped(3,222);check(gw_wire_auth_credentials_data.consumed_generation==expected_generation,223);
verify_spans(&config);
/* Reentrant coordinator attempts at the exact synchronous-borrow boundary
* cannot retire/reset or claim a second worker. */
check(gw_wire_account_active() && gw_wire_account_retirement_ready(expected_generation)==-2 &&
gw_wire_account_retire_generation(expected_generation)==-2 && gw_wire_account_start()==-1,224);
/* Prove that the borrowed input is independent of the consumed mailbox.
* These are fixture-owned bytes, deliberately poisoned after consumption. */
__builtin_memset(gw_wire_auth_credentials_data.username,'Z',sizeof(gw_wire_auth_credentials_data.username));
__builtin_memset(gw_wire_auth_credentials_data.password,'Y',sizeof(gw_wire_auth_credentials_data.password));
verify_spans(&config);credentials_wipe(3);
borrowed_password=config.password;
call->result=-2;call->value=GW_AUTH_DETAIL_RESPONSE_V1|0x204u;return 0;
}
static void begin(unsigned int generation,unsigned int user_size,unsigned int password_size){
expected_generation=generation;expected_user=user_size;expected_password=password_size;
configure();publish(generation,user_size,password_size);gw_wire_endpoint_profile_data.kind=1;
for(unsigned int i=0;i<20;++i)expected_hash[i]=(unsigned char)(generation+i);
check(gw_wire_public_hash_publish(&gw_wire_public_hash_data,generation,expected_hash),230);
}
static void finish(unsigned int generation){
check(!gw_wire_account_active() && gw_wire_auth_data.state==3 && !gw_wire_auth_data.server_proof_verified,240);
check(!gw_wire_account_retirement_ready(generation) && !gw_wire_account_retire_generation(generation),241);
check(!gw_wire_auth_data.state && !gw_wire_auth_credentials_data.generation &&
!gw_wire_public_hash_data.state && gw_wire_account_generation()==generation,242);
}
void fixture_start(void){
static const unsigned int lengths[][2]={{1,1},{14,18},{15,16},{16,15},{32,64}};
message("GW_PUBLIC_HANDOFF entry\n");
for(unsigned int i=0;i<sizeof(lengths)/sizeof(*lengths);++i){
unsigned int generation=i+1;
begin(generation,lengths[i][0],lengths[i][1]);
check(!gw_wire_account_start_owned((void*)0x1234) && pending && pending_argument==(void*)1,250);
check(gw_wire_auth_credentials_data.state==2 && gw_wire_auth_data.state==1 && gw_wire_account_active(),251);
check(gw_wire_account_start()==-1 && gw_wire_account_retire_generation(generation)==-2,252);
check(gw_wire_auth_credentials_data.state==2 && gw_wire_auth_credentials_data.username_bytes==expected_user &&
gw_wire_auth_credentials_data.password_bytes==expected_password,253);
run_worker();wiped(3,254);
check(hash_calls==generation && identity_calls==generation && wipe_calls>=1 &&
gw_wire_auth_data.auth_result==-2 && gw_wire_auth_data.error==1 &&
gw_source_auth_detail_v1(generation)==(GW_AUTH_DETAIL_RESPONSE_V1|0x204u),255);
finish(generation);
}
begin(6,14,18);resolver_failure=1;check(!gw_wire_account_start(),263);run_worker();resolver_failure=0;
wiped(3,264);check(hash_calls==5 && gw_wire_auth_data.auth_result==-9 && gw_wire_auth_data.error==1,265);finish(6);
/* A stale generation is rejected before scheduling or backend access. */
begin(6,14,18);check(gw_wire_account_start()==-1 && !pending && hash_calls==5,266);wiped(-1,267);
/* Fixture-owned cleanup of the deliberately invalid published input. */
public_rows_retire_generation();credentials_wipe(0);
gw_wire_auth_credentials_data=(struct gw_wire_auth_credentials){.abi=1,.size=sizeof(gw_wire_auth_credentials_data)};
begin(7,32,64);thread_failure=1;check(gw_wire_account_start()==-2 && !pending,260);thread_failure=0;
wiped(-1,261);check(hash_calls==5 && gw_wire_auth_data.error==6,262);
check(gw_wire_session_lease_data.released==1 && !gw_wire_session_lease_data.attached &&
(gw_login_result_seen&(UINT64_C(1)<<6)) && !gw_source_auth_detail_v1(7),268);finish(7);
/* A real next generation can now start after the no-worker failure. */
begin(8,32,64);check(!gw_wire_account_start(),269);run_worker();wiped(3,270);
check(hash_calls==6 && identity_calls==6 && gw_wire_auth_data.auth_result==-2,271);finish(8);
message("GW_PUBLIC_HANDOFF complete: 6 exact-span generations; deferred/borrow guards; thread/DNS/stale failures\n");
ExitProcess(0);
}
int main(void){fixture_start();return 0;}