nx_https_get_complete_test.nx source
↩ module page · 69 lines · 3049 B
1// nx_https_get_complete_test.nx -- KAT for the HTTP GET
2// round-trip primitive.
3//
4// Full happy-path against a real TLS 1.3 server is exercised by
5// Arc A's end-to-end demo (queued). This KAT verifies the
6// orchestrator's CONTRACT SURFACE:
7// - state guard (must be at CONNECTED)
8// - fd error propagation (bad fd -> WRITE_FAIL or READ_FAIL)
9// - sealed verdict gate
10//
11// expect_exit: 0
12// license_tier: ORIGINAL
13
14import "nx_syscalls.nx"
15import "nx_tls13_client_session.nx"
16import "nx_https_get_complete.nx"
17
18func main() -> i64 {
19 let client_random: *u8 = sys_mmap(32)
20 var i: i64 = 0
21 while i < 32 { client_random[i] = (0xC0 + i) as u8; i = i + 1 }
22 let priv: *u8 = sys_mmap(32)
23 i = 0
24 while i < 32 { priv[i] = (0x40 + i) as u8; i = i + 1 }
25
26 let path: *u8 = sys_mmap(8)
27 path[0] = 0x2F // "/"
28 let host: *u8 = sys_mmap(16)
29 host[0]=0x65; host[1]=0x78; host[2]=0x61
30 host[3]=0x6D; host[4]=0x70; host[5]=0x6C; host[6]=0x65 // "example"
31
32 let out_buf: *u8 = sys_mmap(1024)
33
34 // ---- Test A: session not at CONNECTED -> BAD_STATE ----
35 let s1: *Tls13ClientSession = nx_tls13_client_session_new(client_random, priv)
36 let v_a: i64 = nx_https_get_complete(s1, 1, path, 1, host, 7, out_buf, 1024)
37 if v_a != (0 - NX_HTTPS_GC_BAD_STATE) { return 1 }
38
39 // ---- Test B: session at WAIT_APP_KEYS -> BAD_STATE ----
40 s1.state = NX_TLS13_CSESSION_STATE_WAIT_APP_KEYS
41 if nx_https_get_complete(s1, 1, path, 1, host, 7, out_buf, 1024) != (0 - NX_HTTPS_GC_BAD_STATE) { return 2 }
42
43 // ---- Test C: session at CONNECTED with bad fd -> WRITE_FAIL or READ_FAIL ----
44 // We need a session in CONNECTED state. Force it for test
45 // purposes (real handshake gets there via the 6 sub-steps).
46 s1.state = NX_TLS13_CSESSION_STATE_CONNECTED
47 let v_c: i64 = nx_https_get_complete(s1, 0 - 1, path, 1, host, 7, out_buf, 1024)
48 // Either WRITE_FAIL (sys_write rejects -1) or READ_FAIL.
49 let nv: i64 = 0 - v_c
50 if v_c >= 0 { return 10 } // must be negative
51 if nv != NX_HTTPS_GC_WRITE_FAIL {
52 if nv != NX_HTTPS_GC_READ_FAIL { return 11 }
53 }
54
55 // ---- Test D: verdict gate ----
56 if nx_https_gc_verdict_is_valid(NX_HTTPS_GC_OK) != 1 { return 20 }
57 if nx_https_gc_verdict_is_valid(NX_HTTPS_GC_BAD_STATE) != 1 { return 21 }
58 if nx_https_gc_verdict_is_valid(NX_HTTPS_GC_BUILD_FAIL) != 1 { return 22 }
59 if nx_https_gc_verdict_is_valid(NX_HTTPS_GC_ENCRYPT_FAIL) != 1 { return 23 }
60 if nx_https_gc_verdict_is_valid(NX_HTTPS_GC_WRITE_FAIL) != 1 { return 24 }
61 if nx_https_gc_verdict_is_valid(NX_HTTPS_GC_READ_FAIL) != 1 { return 25 }
62 if nx_https_gc_verdict_is_valid(NX_HTTPS_GC_DECRYPT_FAIL) != 1 { return 26 }
63 if nx_https_gc_verdict_is_valid(NX_HTTPS_GC_BUF_OVERFLOW) != 1 { return 27 }
64 if nx_https_gc_verdict_is_valid(NX_HTTPS_GC_VERDICT_N) != 0 { return 28 }
65 if nx_https_gc_verdict_is_valid(0) != 0 { return 29 }
66 if nx_https_gc_verdict_is_valid(0 - 1) != 0 { return 30 }
67
68 return 0
69}