nx_https_get_test.nx source
↩ module page · 67 lines · 2865 B
1// nx_https_get_test.nx -- KAT for the top-level user-facing
2// nx_https_get primitive.
3//
4// Full happy-path against a real public HTTPS server is
5// exercised by Arc A's end-to-end demo (queued). This KAT
6// verifies the orchestrator's contract surface:
7// - bad URL (no scheme) -> BAD_URL
8// - http:// (wrong scheme) -> BAD_URL
9// - URL with non-routable IP-in-host -> CONNECT_FAIL or
10// HANDSHAKE_FAIL (platform-dep; DNS resolves "0.0.0.0" or
11// similar to a connect-failure)
12// - sealed verdict gate
13//
14// expect_exit: 0
15// license_tier: ORIGINAL
16
17import "nx_syscalls.nx"
18import "nx_x509_trust_store.nx"
19import "nx_https_get.nx"
20
21func main() -> i64 {
22 let client_random: *u8 = sys_mmap(32)
23 var i: i64 = 0
24 while i < 32 { client_random[i] = (0xC0 + i) as u8; i = i + 1 }
25 let priv: *u8 = sys_mmap(32)
26 i = 0
27 while i < 32 { priv[i] = (0x40 + i) as u8; i = i + 1 }
28
29 let store: *TrustStore = trust_store_alloc(4)
30 let out_buf: *u8 = sys_mmap(4096)
31
32 // ---- Test A: empty URL string -> BAD_URL ----
33 let empty_url: *u8 = sys_mmap(2)
34 empty_url[0] = 0
35 let v_a: i64 = nx_https_get(empty_url, client_random, priv, store,
36 1718452800, out_buf, 4096)
37 if v_a != (0 - NX_HTTPS_GET_BAD_URL) { return 1 }
38
39 // ---- Test B: http:// URL -> BAD_URL (wrong scheme) ----
40 let http_url: *u8 = sys_mmap(32)
41 http_url[0]=0x68; http_url[1]=0x74; http_url[2]=0x74; http_url[3]=0x70 // "http"
42 http_url[4]=0x3A; http_url[5]=0x2F; http_url[6]=0x2F
43 http_url[7]=0x65; http_url[8]=0x78; http_url[9]=0x61 // "exa"
44 http_url[10]=0x2F // "/"
45 http_url[11]=0
46 if nx_https_get(http_url, client_random, priv, store,
47 1718452800, out_buf, 4096) != (0 - NX_HTTPS_GET_BAD_URL) { return 2 }
48
49 // ---- Test C: malformed URL (no scheme) -> BAD_URL ----
50 let no_scheme: *u8 = sys_mmap(16)
51 no_scheme[0]=0x65; no_scheme[1]=0x78; no_scheme[2]=0x61
52 no_scheme[3]=0
53 if nx_https_get(no_scheme, client_random, priv, store,
54 1718452800, out_buf, 4096) != (0 - NX_HTTPS_GET_BAD_URL) { return 3 }
55
56 // ---- Test D: sealed verdict gate ----
57 if nx_https_get_verdict_is_valid(NX_HTTPS_GET_OK) != 1 { return 10 }
58 if nx_https_get_verdict_is_valid(NX_HTTPS_GET_BAD_URL) != 1 { return 11 }
59 if nx_https_get_verdict_is_valid(NX_HTTPS_GET_CONNECT_FAIL) != 1 { return 12 }
60 if nx_https_get_verdict_is_valid(NX_HTTPS_GET_HANDSHAKE_FAIL) != 1 { return 13 }
61 if nx_https_get_verdict_is_valid(NX_HTTPS_GET_FETCH_FAIL) != 1 { return 14 }
62 if nx_https_get_verdict_is_valid(NX_HTTPS_GET_VERDICT_N) != 0 { return 15 }
63 if nx_https_get_verdict_is_valid(0) != 0 { return 16 }
64 if nx_https_get_verdict_is_valid(0 - 1) != 0 { return 17 }
65
66 return 0
67}