code wiki / (root) / nx_https_url_connect_test.nx

nx_https_url_connect_test.nx source

↩ module page · 71 lines · 2767 B

1// nx_https_url_connect_test.nx -- KAT for the URL+DNS+TCP step 2 2// primitive. 3// 4// We don't exercise the live DNS+connect path here (that requires 5// a real network). This KAT exercises: 6// - sockaddr-byte-layout for known IPv4 + port 7// - sealed verdict gate 8// - constants (AF_INET, SOCK_STREAM) match POSIX expectations 9// 10// Live DNS+connect path is exercised by Arc A demo (queued). 11// 12// expect_exit: 0 13// license_tier: ORIGINAL 14 15import "nx_syscalls.nx" 16import "nx_https_url_connect.nx" 17 18func main() -> i64 { 19 // ---- Test A: sockaddr layout for 1.2.3.4 port 443 ---- 20 let sa: *u8 = sys_mmap(16) 21 nx_https_build_sockaddr(sa, 0x01020304, 443) 22 // [0..1] sin_family = AF_INET = 2 (LE short) -> 02 00 23 if (sa[0] & 0xff) != 0x02 { return 1 } 24 if (sa[1] & 0xff) != 0x00 { return 2 } 25 // [2..3] port = 443 = 0x01BB (BE) -> 01 BB 26 if (sa[2] & 0xff) != 0x01 { return 3 } 27 if (sa[3] & 0xff) != 0xBB { return 4 } 28 // [4..7] ipv4 = 01 02 03 04 29 if (sa[4] & 0xff) != 0x01 { return 5 } 30 if (sa[5] & 0xff) != 0x02 { return 6 } 31 if (sa[6] & 0xff) != 0x03 { return 7 } 32 if (sa[7] & 0xff) != 0x04 { return 8 } 33 // [8..15] padding zero 34 var i: i64 = 8 35 while i < 16 { 36 if (sa[i] & 0xff) != 0x00 { return 10 + i } 37 i = i + 1 38 } 39 40 // ---- Test B: sockaddr layout for 8.8.8.8 port 80 ---- 41 let sa2: *u8 = sys_mmap(16) 42 nx_https_build_sockaddr(sa2, 0x08080808, 80) 43 if (sa2[0] & 0xff) != 0x02 { return 30 } 44 if (sa2[2] & 0xff) != 0x00 { return 31 } 45 if (sa2[3] & 0xff) != 0x50 { return 32 } // 80 = 0x50 46 if (sa2[4] & 0xff) != 0x08 { return 33 } 47 if (sa2[7] & 0xff) != 0x08 { return 34 } 48 49 // ---- Test C: highest-port + 255.255.255.255 ---- 50 let sa3: *u8 = sys_mmap(16) 51 nx_https_build_sockaddr(sa3, 0xFFFFFFFF, 65535) 52 if (sa3[2] & 0xff) != 0xFF { return 40 } 53 if (sa3[3] & 0xff) != 0xFF { return 41 } 54 if (sa3[4] & 0xff) != 0xFF { return 42 } 55 if (sa3[7] & 0xff) != 0xFF { return 43 } 56 57 // ---- Test D: AF/SOCK constants match POSIX ---- 58 if NX_HTTPS_AF_INET != 2 { return 50 } 59 if NX_HTTPS_SOCK_STREAM != 1 { return 51 } 60 61 // ---- Test E: verdict gate ---- 62 if nx_https_connect_verdict_is_valid(NX_HTTPS_CONNECT_OK) != 1 { return 60 } 63 if nx_https_connect_verdict_is_valid(NX_HTTPS_CONNECT_DNS_FAIL) != 1 { return 61 } 64 if nx_https_connect_verdict_is_valid(NX_HTTPS_CONNECT_SOCKET_FAIL) != 1 { return 62 } 65 if nx_https_connect_verdict_is_valid(NX_HTTPS_CONNECT_CONNECT_FAIL) != 1 { return 63 } 66 if nx_https_connect_verdict_is_valid(NX_HTTPS_CONNECT_VERDICT_N) != 0 { return 64 } 67 if nx_https_connect_verdict_is_valid(0) != 0 { return 65 } 68 if nx_https_connect_verdict_is_valid(0 - 1) != 0 { return 66 } 69 70 return 0 71}