nx_civic_fetch_test.nx source
↩ module page · 31 lines · 1774 B
1// nx_civic_fetch_test.nx -- rule-2 verify: does nx_https_fetch_follow_best (Chrome-JA3 ladder) reach a Socrata
2// civic host that rejected the default TLS-1.3 research fetch (status=0)? If yes, the F2 civic-ingest routes
3// through _best. Import ONLY nx_research_engine -> inherits sys_* + rf_init/TrustStore + nx_https_fetch_follow_best.
4// license_tier: ORIGINAL expect_exit:0
5import "nx_research_engine.nx"
6
7func ci_wn(v: i64) -> i64 {
8 var m: i64 = v; if m < 0 { let d: *u8 = sys_mmap(2); d[0] = 45 as u8; sys_write(1, d, 1); m = 0 - m }
9 let t: *u8 = sys_mmap(24); var k: i64 = 0; if m == 0 { t[0] = 48 as u8; k = 1 }
10 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
11 let o: *u8 = sys_mmap(24); var i: i64 = 0; while i < k { o[i] = t[k-1-i]; i = i + 1 } sys_write(1, o, k); return 0
12}
13
14func main() -> i64 {
15 let store: *TrustStore = rf_init()
16 if (store as i64) == 0 { rf_puts("civic-test: trust store load failed\n" as *u8); return 1 }
17 let cap: i64 = 1048576
18 let out: *u8 = sys_mmap(cap)
19 let status: *i64 = sys_mmap(16) as *i64
20 let url: *u8 = "https://data.cityofchicago.org/resource/ijzp-q8t2.json?$limit=2" as *u8
21 let n: i64 = nx_https_fetch_follow_best(url, store, out, cap, 6, status)
22 rf_puts("CIVIC-FETCH-TEST host=data.cityofchicago.org status=" as *u8); ci_wn(status[0])
23 rf_puts(" bytes=" as *u8); ci_wn(n)
24 let nl: *u8 = sys_mmap(2); nl[0] = 10 as u8; sys_write(1, nl, 1)
25 var hn: i64 = n; if hn > 240 { hn = 240 }
26 if hn > 0 { sys_write(1, out, hn) }
27 sys_write(1, nl, 1)
28 if n > 0 { if status[0] >= 200 { if status[0] < 300 { rf_puts("VERDICT=GREEN civic-fetch-via-best-works\n" as *u8); return 0 } } }
29 rf_puts("VERDICT=FAIL civic-fetch-blocked\n" as *u8)
30 return 0
31}