code wiki / (root) / nx_https_fetch_test.nx

nx_https_fetch_test.nx source

↩ module page · 51 lines · 2108 B

1// nx_https_fetch_test.nx -- KAT for the structured-response top- 2// level fetch primitive. 3// 4// Live happy-path against a public HTTPS server is exercised by 5// Arc A's end-to-end demo (queued). This KAT verifies the 6// orchestrator's verdict surface + the sealed gate. 7// 8// expect_exit: 0 9// license_tier: ORIGINAL 10 11import "nx_syscalls.nx" 12import "nx_x509_trust_store.nx" 13import "nx_https_fetch.nx" 14 15func main() -> i64 { 16 let client_random: *u8 = sys_mmap(32) 17 var i: i64 = 0 18 while i < 32 { client_random[i] = (0xC0 + i) as u8; i = i + 1 } 19 let priv: *u8 = sys_mmap(32) 20 i = 0 21 while i < 32 { priv[i] = (0x40 + i) as u8; i = i + 1 } 22 let store: *TrustStore = trust_store_alloc(4) 23 let raw_buf: *u8 = sys_mmap(4096) 24 let parsed: *i64 = sys_mmap(128) as *i64 25 26 // ---- Test A: empty URL -> GET_FAIL (nx_https_get returns BAD_URL) ---- 27 let empty: *u8 = sys_mmap(2) 28 empty[0] = 0 29 let v_a: i64 = nx_https_fetch(empty, client_random, priv, store, 30 1718452800, raw_buf, 4096, parsed) 31 if v_a != (0 - NX_HTTPS_FETCH_GET_FAIL) { return 1 } 32 33 // ---- Test B: http:// URL -> GET_FAIL ---- 34 let http_url: *u8 = sys_mmap(32) 35 http_url[0]=0x68; http_url[1]=0x74; http_url[2]=0x74; http_url[3]=0x70 36 http_url[4]=0x3A; http_url[5]=0x2F; http_url[6]=0x2F 37 http_url[7]=0x65; http_url[8]=0x78; http_url[9]=0x61 38 http_url[10]=0x2F; http_url[11]=0 39 if nx_https_fetch(http_url, client_random, priv, store, 40 1718452800, raw_buf, 4096, parsed) != (0 - NX_HTTPS_FETCH_GET_FAIL) { return 2 } 41 42 // ---- Test C: sealed verdict gate ---- 43 if nx_https_fetch_verdict_is_valid(NX_HTTPS_FETCH_OK) != 1 { return 10 } 44 if nx_https_fetch_verdict_is_valid(NX_HTTPS_FETCH_GET_FAIL) != 1 { return 11 } 45 if nx_https_fetch_verdict_is_valid(NX_HTTPS_FETCH_PARSE_FAIL) != 1 { return 12 } 46 if nx_https_fetch_verdict_is_valid(NX_HTTPS_FETCH_VERDICT_N) != 0 { return 13 } 47 if nx_https_fetch_verdict_is_valid(0) != 0 { return 14 } 48 if nx_https_fetch_verdict_is_valid(0 - 1) != 0 { return 15 } 49 50 return 0 51}