883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
35 lines
2.3 KiB
C++
35 lines
2.3 KiB
C++
// Pure endpoint parser/profile test. Never opens a socket or resolves a name.
|
|
#include "gateway/realms.hpp"
|
|
#include <iostream>
|
|
#include <type_traits>
|
|
using namespace gateway;
|
|
namespace {
|
|
void check(bool good){if(!good)throw Error("numeric endpoint contract failed");}
|
|
template<class F>void reject(F f){try{f();}catch(const Error&){return;}throw Error("unsafe numeric endpoint accepted");}
|
|
}
|
|
int main(){
|
|
static_assert(!std::is_copy_assignable_v<NumericIPv4Endpoint>);
|
|
for(const auto& host:{"127.0.0.1","127.0.0.2","10.0.0.1","172.16.0.1","192.168.0.1","192.0.2.1","223.255.255.254"}){
|
|
NumericIPv4Endpoint endpoint(host,65535);check(endpoint.host()==host && endpoint.port()==65535);
|
|
LegacyRealm realm{};realm.address=std::string(host)+":8090";
|
|
auto advertised=numeric_realm_endpoint(realm);check(advertised.host()==host && advertised.port()==8090);
|
|
}
|
|
for(const auto& host:{"","localhost","play.example.test","127.1","2130706433","0x7f000001","127.000.0.1",
|
|
" 127.0.0.1","127.0.0.1 ","+127.0.0.1","127.0.0.256","::1","[::1]",
|
|
"0.0.0.0","0.1.2.3","224.0.0.1","239.255.255.255","240.0.0.1","255.255.255.255"})
|
|
reject([&]{NumericIPv4Endpoint endpoint(host,3724);});
|
|
reject([]{NumericIPv4Endpoint endpoint(std::string("127.0.0.1\0suffix",16),3724);});
|
|
reject([]{NumericIPv4Endpoint endpoint("127.0.0.1",0);});
|
|
for(const auto& address:{"127.0.0.1","127.0.0.1:","127.0.0.1:0","127.0.0.1:65536","127.0.0.1:-1",
|
|
"127.0.0.1:+1","127.0.0.1:8090x","127.0.0.1:8090:1","play.example.test:8090",
|
|
"::1:8090","255.255.255.255:8090"}){
|
|
LegacyRealm realm{};realm.address=address;reject([&]{numeric_realm_endpoint(realm);});
|
|
}
|
|
LegacyRealm realm{};realm.address="127.0.0.1:8090";check(local_realm_endpoint(realm).port==8090);
|
|
realm.address="192.0.2.1:8090";reject([&]{local_realm_endpoint(realm);});
|
|
realm.address="127.0.0.2:8090";reject([&]{local_realm_endpoint(realm);});
|
|
realm.flags=2;reject([&]{numeric_realm_endpoint(realm);});
|
|
realm.address="127.0.0.1:8090";reject([&]{local_realm_endpoint(realm);});
|
|
std::cout<<"PASS explicit immutable numeric IPv4 profiles, malformed/unicast/port/hostname bounds and unchanged local realm guard; no networking\n";
|
|
}
|