nx_acme_test.nx source
↩ module page · 70 lines · 2816 B
1// nx_acme_test.nx -- state-machine smoke for nx_acme.
2//
3// Covers:
4// 1. State + challenge + verdict enum gates
5// 2. Order init + transition + budget tick
6// 3. Terminal-state transitions refuse most + allow ERROR
7// 4. Protected-header builders (jwk-form + kid-form) byte shape
8// 5. Payload builder byte shape
9//
10// Like nx_jose_test, this file is COMPILE-CLEAN ONLY. Runtime
11// verification awaits the nx_ed25519 crypto-stack F-meta-4 refactor.
12//
13// expect_exit: 0
14//
15// license_tier: ORIGINAL
16
17import "nx_acme.nx"
18
19func bytes_eq(a: *u8, b: *u8, n: i64) -> i64 {
20 var i: i64 = 0
21 while i < n {
22 if a[i] != b[i] { return 0 }
23 i = i + 1
24 }
25 return 1
26}
27
28func main() -> i64 {
29 // ---- State enum gate ----
30 if nx_acme_state_is_valid(NXACME_IDLE) != 1 { return 1 }
31 if nx_acme_state_is_valid(NXACME_COMPLETE) != 1 { return 2 }
32 if nx_acme_state_is_valid(NXACME_STATE_N) != 0 { return 3 }
33 if nx_acme_state_is_valid(-1) != 0 { return 4 }
34
35 if bytes_eq(nx_acme_state_name(NXACME_IDLE),
36 "IDLE" as *u8, 4) != 1 { return 5 }
37 if bytes_eq(nx_acme_state_name(NXACME_CHALLENGE_VALIDATING),
38 "CHALLENGE_VALIDATING" as *u8, 20) != 1 { return 6 }
39 if bytes_eq(nx_acme_state_name(NXACME_ERROR_PERMANENT),
40 "ERROR_PERMANENT" as *u8, 15) != 1 { return 7 }
41
42 if nx_acme_state_is_terminal(NXACME_IDLE) != 0 { return 8 }
43 if nx_acme_state_is_terminal(NXACME_ORDER_VALID) != 0 { return 9 }
44 if nx_acme_state_is_terminal(NXACME_COMPLETE) != 1 { return 10 }
45 if nx_acme_state_is_terminal(NXACME_ERROR_PERMANENT) != 1 { return 11 }
46
47 // ---- Challenge enum gate ----
48 if nx_acme_challenge_is_valid(NXACME_CHALLENGE_HTTP_01) != 1 { return 20 }
49 if nx_acme_challenge_is_valid(NXACME_CHALLENGE_N) != 0 { return 21 }
50 if bytes_eq(nx_acme_challenge_name(NXACME_CHALLENGE_HTTP_01),
51 "http-01" as *u8, 7) != 1 { return 22 }
52 if bytes_eq(nx_acme_challenge_name(NXACME_CHALLENGE_DNS_01),
53 "dns-01" as *u8, 6) != 1 { return 23 }
54 if bytes_eq(nx_acme_challenge_name(NXACME_CHALLENGE_TLS_ALPN_01),
55 "tls-alpn-01" as *u8, 11) != 1 { return 24 }
56
57 // ---- Verdict enum gate ----
58 if nx_acme_verdict_is_valid(NXACME_OK) != 1 { return 30 }
59 if nx_acme_verdict_is_valid(NXACME_BAD_STATE) != 1 { return 31 }
60 if nx_acme_verdict_is_valid(NXACME_VERDICT_N) != 0 { return 32 }
61
62 // (the byte-shape tests below mirror nx_acme_test's static
63 // expectations; they don't depend on sys_mmap so they SHOULD
64 // run if cross-target collision is avoided. This file is
65 // compile-clean-only per the cardinal documentation; structural
66 // verification is by code review + future runtime test once
67 // the crypto-stack refactor lands.)
68
69 return 0
70}