883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
106 lines
5.5 KiB
Python
106 lines
5.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Exercise the actual world-entry function with isolated transport boundaries.
|
|
|
|
No sockets, credentials, client memory, or live world are used. Authentication
|
|
and packet I/O are doubles; the session's identity/address/state guards are the
|
|
production function extracted verbatim, including its failure paths.
|
|
"""
|
|
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
START = 'extern "C" int gw_native_transport_begin_world('
|
|
END = 'extern "C" uint32_t gw_native_transport_world_call_state('
|
|
PRELUDE = r'''
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
#include <cstring>
|
|
#include <memory>
|
|
#include <span>
|
|
#include <string>
|
|
#include <vector>
|
|
#include "gateway/source_account_key.h"
|
|
namespace gateway {
|
|
using Bytes=std::vector<uint8_t>;
|
|
struct Character {uint64_t guid=4509;uint8_t race=1,cls=1;};
|
|
using Roster=std::vector<Character>;
|
|
Roster forever_preview_roster(const Roster& r){return r;}
|
|
uint64_t selected_turtle_guid(std::span<const uint8_t> b,uint16_t,const Roster&){return b[0]?4509:9999;}
|
|
bool turtle_native_presentation_pair(uint8_t r,uint8_t c){return r==1&&c==1;}
|
|
void le(Bytes& b,uint64_t v,unsigned n){while(n--){b.push_back(v&255);v>>=8;}}
|
|
}
|
|
struct Stream {unsigned calls=0;gateway::Bytes encode(unsigned,const gateway::Bytes&){++calls;return gateway::Bytes(14);}};
|
|
struct Authentication {
|
|
bool accepted=true;uint32_t key=gw_source_account_key("fixture_a",9);Stream io;
|
|
uint32_t internal_source_account()const{return accepted?key:0;}
|
|
Stream& stream(){return io;}
|
|
};
|
|
struct Contacts {unsigned retired=0;unsigned retired_queries()const{return retired;}void hold_retired(unsigned x){retired=x;}};
|
|
struct NativeWorldTranslation {
|
|
gateway::Character selected;uint16_t realm=0;uint32_t internal_source_account=0;
|
|
bool local_gameobject_authority=false,logout_complete=false;Contacts contact_names;
|
|
struct {unsigned serial=0;}loot;
|
|
};
|
|
struct gw_native_transport {
|
|
Authentication* authentication;bool roster_seen=true;gateway::Roster roster{{}};
|
|
struct {std::string address;}realm;
|
|
std::unique_ptr<NativeWorldTranslation>world;
|
|
};
|
|
bool gw_native_transport_authenticated(gw_native_transport* t){return t&&t->authentication&&t->authentication->accepted;}
|
|
'''
|
|
MAIN = r'''
|
|
#include <stdexcept>
|
|
#include <iostream>
|
|
void require(bool ok,const char* why){if(!ok)throw std::runtime_error(why);}
|
|
int main(){try {
|
|
for(const auto& endpoint:{"127.0.0.1:8090","192.168.122.1:8090","example.invalid:8090",
|
|
"192.168.122.2:8090","192.168.122.1:8085","127.0.0.2:8090",
|
|
"10.0.0.1:8090","[::1]:8090","localhost:8090"}) {
|
|
Authentication a;gw_native_transport t{&a};t.realm.address=endpoint;
|
|
uint8_t input=1,out[14]{};uint32_t required=0;
|
|
require(gw_native_transport_begin_world(&t,70,&input,1,out,14,&required)==0,"verified world entry");
|
|
require(t.world&&t.world->internal_source_account==a.key,"membership key must match verified Wire key at every admitted endpoint");
|
|
require(t.world->local_gameobject_authority==(t.realm.address=="127.0.0.1:8090" || t.realm.address=="192.168.122.1:8090"),"local snapshot authority must remain scoped to the two proved owned aliases");
|
|
require(a.io.calls==1&&required==14,"one authenticated world packet");
|
|
}
|
|
for(unsigned failure=0;failure<5;++failure) {
|
|
Authentication a;gw_native_transport t{&a};t.realm.address="192.168.122.1:8090";
|
|
uint8_t input=1,out[14]{};uint32_t required=99,capacity=14;
|
|
if(failure==0)a.accepted=false;
|
|
if(failure==1)a.key=0;
|
|
if(failure==2)input=0;
|
|
if(failure==3)t.roster_seen=false;
|
|
if(failure==4)capacity=13;
|
|
require(gw_native_transport_begin_world(&t,70,&input,1,out,capacity,&required)<0,"invalid admission must fail closed");
|
|
require(!t.world&&a.io.calls==0,"failure cannot mutate world or consume cipher");
|
|
}
|
|
std::cout<<"PASS verified endpoint-independent identity, preserved local authority, and fail-closed admission\n";
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}
|
|
'''
|
|
|
|
def run(source: str, directory: Path, name: str):
|
|
function = source[source.index(START):source.index(END)]
|
|
cpp = directory / (name + '.cpp')
|
|
exe = directory / name
|
|
cpp.write_text(PRELUDE + function + MAIN)
|
|
subprocess.run(['c++', '-std=c++20', '-I', str(ROOT / 'include'), str(cpp), '-o', str(exe)], check=True)
|
|
return subprocess.run([str(exe)], capture_output=True, text=True)
|
|
|
|
if __name__ == '__main__':
|
|
source = (ROOT / 'native/session.cpp').read_text()
|
|
with tempfile.TemporaryDirectory(prefix='world-identity-') as tmp:
|
|
directory = Path(tmp)
|
|
fixed = run(source, directory, 'fixed')
|
|
assert fixed.returncode == 0, fixed.stderr
|
|
old = source.replace('world->internal_source_account=source_account;', 'if(t->realm.address=="127.0.0.1:8090")world->internal_source_account=source_account;')
|
|
assert old != source
|
|
regression = run(old, directory, 'old-endpoint-guard')
|
|
assert regression.returncode != 0 and 'membership key must match' in regression.stderr
|
|
old_go = source.replace('world->local_gameobject_authority=t->realm.address=="127.0.0.1:8090" ||\n t->realm.address=="192.168.122.1:8090";', 'world->local_gameobject_authority=t->realm.address=="127.0.0.1:8090";')
|
|
assert old_go != source
|
|
go_regression = run(old_go, directory, 'old-go-endpoint-guard')
|
|
assert go_regression.returncode != 0 and 'local snapshot authority' in go_regression.stderr
|
|
print(fixed.stdout.strip())
|
|
print('PASS regression witness rejects the previous endpoint-specific assignment')
|