Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/protocol/interplane/core/test.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / protocol / interplane / core / test.om` 346 lines ยท 11052 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note protocol/interplane/core/test.om: comprehensive positive & negative control tests 3 note for Interplane core envelope parser, trust-boundary policy evaluator, conformance 4 note lifecycle state machine, and hash-chained provenance ledger. 5 note Compose with: 6 note si/directives/om2.om om/tls/sha2.om protocol/interplane/core/envelope.om 7 note protocol/interplane/core/policy.om protocol/interplane/core/test.om 8 9 text t_pass "PASS " 10 text t_fail "FAIL " 11 text t_nl "\n" 12 13 text t_c1 "version_and_identifier_positive_and_negative" 14 text t_c2 "untrusted_envelope_parser_valid_and_digest_determinism" 15 text t_c3 "untrusted_envelope_parser_rejects_dup_unknown_missing_badchar" 16 text t_c4 "inv1_parsing_never_executes_and_lifecycle_machine" 17 text t_c5 "inv2_transport_never_grants_mtls_and_loopback_denied" 18 text t_c6 "inv3_valid_envelope_is_not_authorization" 19 text t_c7 "inv4_signature_proves_origin_not_authority_and_revoked" 20 text t_c8 "inv5_runtime_policy_decides_no_request_upgrade" 21 text t_c9 "provenance_ledger_chain_and_tamper_detection" 22 text t_done "PASS interplane-core all 9 test suites passed\n" 23 24 text t_v_ok1 "1.0" 25 text t_v_ok2 "1.12" 26 text t_v_bad_maj "2.0" 27 text t_v_bad_lz "1.01" 28 text t_v_bad_fmt "1.0.0" 29 30 text t_id_ok "agent.spark-01_a" 31 text t_id_trav "foo..bar" 32 text t_id_lead ".hidden" 33 text t_id_upper "BadUpper" 34 text t_id_space "bad id" 35 36 text t_env_ok "version=1.0\nenvelope_id=env-001\norigin_id=node.spark\naction=read.state\npayload_sha256=`e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855`\ntransport=mtls\nclaimed_policy=1\n" 37 text t_env_ok_alt "version=1.0\nenvelope_id=env-002\norigin_id=node.spark\naction=read.state\npayload_sha256=`e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855`\ntransport=mtls\nclaimed_policy=1\n" 38 text t_env_dup "version=1.0\nversion=1.0\nenvelope_id=env-001\norigin_id=node.spark\naction=read.state\npayload_sha256=`e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855`\n" 39 text t_env_unk "version=1.0\nenvelope_id=env-001\norigin_id=node.spark\naction=read.state\npayload_sha256=`e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855`\nevil_key=1\n" 40 text t_env_miss "version=1.0\nenvelope_id=env-001\norigin_id=node.spark\naction=read.state\n" 41 text t_env_badhex "version=1.0\nenvelope_id=env-001\norigin_id=node.spark\naction=read.state\npayload_sha256=ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ\n" 42 text t_env_badtr "version=1.0\nenvelope_id=env-001\norigin_id=node.spark\naction=read.state\npayload_sha256=`e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855`\ntransport=godmode\n" 43 text t_env_escal "version=1.0\nenvelope_id=env-003\norigin_id=node.spark\naction=policy.set\npayload_sha256=`e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855`\ntransport=loopback\nclaimed_policy=3\n" 44 45 fn report_case name view uchar * ok bool to int 46 if ok 47 w1 = ip_write_all int 1 t_pass 48 w2 = ip_write_all int 1 name 49 w3 = ip_write_all int 1 t_nl 50 if and w1 and w2 w3 51 ret int 0 52 end 53 ret int 1 54 end 55 w4 = ip_write_all int 1 t_fail 56 w5 = ip_write_all int 1 name 57 w6 = ip_write_all int 1 t_nl 58 if and w4 and w5 w6 59 ret int 1 60 end 61 ret int 1 62 end 63 64 fn test_ver_ident to bool 65 if ne ip_validate_version t_v_ok1 IP_OK 66 ret false 67 end 68 if ne ip_validate_version t_v_ok2 IP_OK 69 ret false 70 end 71 if ne ip_validate_version t_v_bad_maj IP_ERR_BAD_VERSION 72 ret false 73 end 74 if ne ip_validate_version t_v_bad_lz IP_ERR_BAD_VERSION 75 ret false 76 end 77 if ne ip_validate_version t_v_bad_fmt IP_ERR_BAD_VERSION 78 ret false 79 end 80 if ne ip_valid_ident t_id_ok IP_OK 81 ret false 82 end 83 if ne ip_valid_ident t_id_trav IP_ERR_BAD_IDENT 84 ret false 85 end 86 if ne ip_valid_ident t_id_lead IP_ERR_BAD_IDENT 87 ret false 88 end 89 if ne ip_valid_ident t_id_upper IP_ERR_BAD_IDENT 90 ret false 91 end 92 if ne ip_valid_ident t_id_space IP_ERR_BAD_IDENT 93 ret false 94 end 95 ret true 96 end 97 98 fn test_parse_valid to bool 99 m1 = new ulong 4 0 100 m2 = new ulong 4 0 101 d1 = new uchar 32 0 102 d2 = new uchar 32 0 103 if ne ip_parse_envelope t_env_ok m1 d1 IP_OK 104 ret false 105 end 106 if ne get m1 1 TRANS_MTLS 107 ret false 108 end 109 if ne get m1 2 POL_READ_ONLY 110 ret false 111 end 112 if ne get m1 3 LC_PARSED 113 ret false 114 end 115 note Determinism check 116 if ne ip_parse_envelope t_env_ok m2 d2 IP_OK 117 ret false 118 end 119 if not ip_digest_eq d1 d2 120 ret false 121 end 122 note Different envelope_id produces different digest 123 if ne ip_parse_envelope t_env_ok_alt m2 d2 IP_OK 124 ret false 125 end 126 if ip_digest_eq d1 d2 127 ret false 128 end 129 ret true 130 end 131 132 fn test_parse_negative to bool 133 m = new ulong 4 0 134 d = new uchar 32 0 135 if ne ip_parse_envelope part t_env_ok 0 0 m d IP_ERR_BAD_LEN 136 ret false 137 end 138 if ne ip_parse_envelope t_env_dup m d IP_ERR_DUP_KEY 139 ret false 140 end 141 if ne ip_parse_envelope t_env_unk m d IP_ERR_UNKNOWN_KEY 142 ret false 143 end 144 if ne ip_parse_envelope t_env_miss m d IP_ERR_MISSING_FIELD 145 ret false 146 end 147 if ne ip_parse_envelope t_env_badhex m d IP_ERR_BAD_HEX 148 ret false 149 end 150 if ne ip_parse_envelope t_env_badtr m d IP_ERR_BAD_TRANSPORT 151 ret false 152 end 153 note Control byte injection (tab 0x09) must be rejected 154 bad = new uchar 16 0 155 put bad 0 uchar 118 156 put bad 1 uchar 61 157 put bad 2 uchar 9 158 if ne ip_parse_envelope part bad 0 3 m d IP_ERR_BAD_CHAR 159 ret false 160 end 161 ret true 162 end 163 164 fn test_inv1_parse_never_exec to bool 165 m = new ulong 4 0 166 d = new uchar 32 0 167 if ne ip_parse_envelope t_env_ok m d IP_OK 168 ret false 169 end 170 lc = get m 3 171 if ne lc LC_PARSED 172 ret false 173 end 174 if ip_can_execute lc 175 ret false 176 end 177 note Jumping directly from PARSED -> EXECUTED or PARSED -> POLICY_AUTHORIZED must fail 178 if ne ip_lc_transition LC_PARSED LC_EXECUTED POL_ERR_UNAUTH_TRANSITION 179 ret false 180 end 181 if ne ip_lc_transition LC_PARSED LC_POLICY_AUTHORIZED POL_ERR_UNAUTH_TRANSITION 182 ret false 183 end 184 note Valid full sequence: RECEIVED -> PARSED -> ORIGIN_CHECKED -> POLICY_AUTHORIZED -> EXECUTED 185 if ne ip_lc_transition LC_RECEIVED LC_PARSED POL_OK 186 ret false 187 end 188 if ne ip_lc_transition LC_PARSED LC_ORIGIN_CHECKED POL_OK 189 ret false 190 end 191 if ne ip_lc_transition LC_ORIGIN_CHECKED LC_POLICY_AUTHORIZED POL_OK 192 ret false 193 end 194 if not ip_can_execute LC_POLICY_AUTHORIZED 195 ret false 196 end 197 if ne ip_lc_transition LC_POLICY_AUTHORIZED LC_EXECUTED POL_OK 198 ret false 199 end 200 note Terminal states cannot transition 201 if ne ip_lc_transition LC_EXECUTED LC_PARSED POL_ERR_UNAUTH_TRANSITION 202 ret false 203 end 204 if ne ip_lc_transition LC_DENIED LC_POLICY_AUTHORIZED POL_ERR_UNAUTH_TRANSITION 205 ret false 206 end 207 ret true 208 end 209 210 fn test_inv2_transport_never_grants to bool 211 note Even LOOPBACK and MTLS with valid signature MUST be denied under POL_DENY_ALL 212 if ne ip_eval_policy POL_DENY_ALL OP_READ ORIG_SIG_VALID TRANS_LOOPBACK OP_READ POL_DENY_ALL POL_ERR_POLICY_DENIED 213 ret false 214 end 215 if ne ip_eval_policy POL_DENY_ALL OP_READ ORIG_SIG_VALID TRANS_MTLS OP_READ POL_DENY_ALL POL_ERR_POLICY_DENIED 216 ret false 217 end 218 note Even LOOPBACK cannot grant OP_EXEC when runtime only allows OP_READ 219 if ne ip_eval_policy POL_STANDARD OP_READ ORIG_SIG_VALID TRANS_LOOPBACK OP_EXEC POL_READ_ONLY POL_ERR_OP_NOT_ALLOWED 220 ret false 221 end 222 note Conversely, UNTRUSTED transport succeeds when runtime policy + origin + op allow it 223 if ne ip_eval_policy POL_READ_ONLY OP_READ ORIG_SIG_VALID TRANS_UNTRUSTED OP_READ POL_READ_ONLY POL_OK 224 ret false 225 end 226 ret true 227 end 228 229 fn test_inv3_valid_env_not_auth to bool 230 m = new ulong 4 0 231 d = new uchar 32 0 232 if ne ip_parse_envelope t_env_ok m d IP_OK 233 ret false 234 end 235 note Valid envelope is in LC_PARSED, not authorized; calling authorize_step before origin check fails 236 if ne ip_authorize_step get m 3 POL_READ_ONLY OP_READ ORIG_SIG_VALID OP_READ POL_READ_ONLY POL_ERR_UNAUTH_TRANSITION 237 ret false 238 end 239 if ip_can_execute LC_ORIGIN_CHECKED 240 ret false 241 end 242 note Only after origin check AND policy eval passes is authorization granted 243 if ne ip_authorize_step LC_ORIGIN_CHECKED POL_READ_ONLY OP_READ ORIG_SIG_VALID OP_READ POL_READ_ONLY POL_OK 244 ret false 245 end 246 ret true 247 end 248 249 fn test_inv4_sig_not_authority to bool 250 note Valid signature on ORIG_SIG_VALID does NOT grant OP_ADMIN when runtime is POL_STANDARD 251 if ne ip_eval_policy POL_STANDARD OP_ALL_MASK ORIG_SIG_VALID TRANS_MTLS OP_ADMIN POL_STANDARD POL_ERR_POLICY_DENIED 252 ret false 253 end 254 note Valid signature does NOT grant OP_WRITE when allowed_ops only has OP_READ 255 if ne ip_eval_policy POL_ELEVATED OP_READ ORIG_SIG_VALID TRANS_MTLS OP_WRITE POL_READ_ONLY POL_ERR_OP_NOT_ALLOWED 256 ret false 257 end 258 note Unverified origin and revoked origin are both refused 259 if ne ip_eval_policy POL_ELEVATED OP_ALL_MASK ORIG_UNVERIFIED TRANS_LOOPBACK OP_READ POL_READ_ONLY POL_ERR_ORIGIN_UNVERIFIED 260 ret false 261 end 262 if ne ip_eval_policy POL_ELEVATED OP_ALL_MASK ORIG_REVOKED TRANS_LOOPBACK OP_READ POL_READ_ONLY POL_ERR_ORIGIN_REVOKED 263 ret false 264 end 265 ret true 266 end 267 268 fn test_inv5_no_policy_upgrade to bool 269 m = new ulong 4 0 270 d = new uchar 32 0 271 if ne ip_parse_envelope t_env_escal m d IP_OK 272 ret false 273 end 274 note Envelope claims policy=3 (POL_ELEVATED) over loopback, but runtime policy is POL_STANDARD (2) 275 if ne ip_eval_policy POL_STANDARD OP_ALL_MASK ORIG_SIG_VALID get m 1 OP_READ get m 2 POL_ERR_ESCALATION 276 ret false 277 end 278 note Requesting OP_POLICY_MUTATE under POL_STANDARD must be refused 279 if ne ip_eval_policy POL_STANDARD OP_ALL_MASK ORIG_SIG_VALID TRANS_LOOPBACK OP_POLICY_MUTATE POL_STANDARD POL_ERR_POLICY_DENIED 280 ret false 281 end 282 note Requesting OP_POLICY_MUTATE under POL_ELEVATED succeeds only if OP_POLICY_MUTATE is in allowed_ops 283 if ne ip_eval_policy POL_ELEVATED OP_READ ORIG_SIG_VALID TRANS_LOOPBACK OP_POLICY_MUTATE POL_ELEVATED POL_ERR_OP_NOT_ALLOWED 284 ret false 285 end 286 if ne ip_eval_policy POL_ELEVATED OP_POLICY_MUTATE ORIG_SIG_VALID TRANS_MTLS OP_POLICY_MUTATE POL_ELEVATED POL_OK 287 ret false 288 end 289 ret true 290 end 291 292 fn test_ledger_chain to bool 293 gen = new uchar 32 0 294 e1 = new uchar 32 0 295 e2 = new uchar 32 0 296 l1 = new uchar 32 0 297 l2 = new uchar 32 0 298 m = new ulong 4 0 299 if ne ip_parse_envelope t_env_ok m e1 IP_OK 300 ret false 301 end 302 if ne ip_parse_envelope t_env_ok_alt m e2 IP_OK 303 ret false 304 end 305 ip_ledger_step gen ulong 1 e1 POL_OK l1 306 ip_ledger_step l1 ulong 2 e2 POL_ERR_ESCALATION l2 307 if ne ip_ledger_verify gen ulong 1 e1 POL_OK l1 POL_OK 308 ret false 309 end 310 if ne ip_ledger_verify l1 ulong 2 e2 POL_ERR_ESCALATION l2 POL_OK 311 ret false 312 end 313 note Negative controls: wrong verdict, wrong seq, or flipped digest byte detected as tamper 314 if ne ip_ledger_verify l1 ulong 2 e2 POL_OK l2 POL_ERR_LEDGER_TAMPER 315 ret false 316 end 317 if ne ip_ledger_verify l1 ulong 3 e2 POL_ERR_ESCALATION l2 POL_ERR_LEDGER_TAMPER 318 ret false 319 end 320 put l2 0 xor get l2 0 uchar 1 321 if ne ip_ledger_verify l1 ulong 2 e2 POL_ERR_ESCALATION l2 POL_ERR_LEDGER_TAMPER 322 ret false 323 end 324 ret true 325 end 326 327 fn main to int 328 fail = int 0 329 fail = add fail report_case t_c1 test_ver_ident 330 fail = add fail report_case t_c2 test_parse_valid 331 fail = add fail report_case t_c3 test_parse_negative 332 fail = add fail report_case t_c4 test_inv1_parse_never_exec 333 fail = add fail report_case t_c5 test_inv2_transport_never_grants 334 fail = add fail report_case t_c6 test_inv3_valid_env_not_auth 335 fail = add fail report_case t_c7 test_inv4_sig_not_authority 336 fail = add fail report_case t_c8 test_inv5_no_policy_upgrade 337 fail = add fail report_case t_c9 test_ledger_chain 338 if ne fail int 0 339 ret int 1 340 end 341 ok = ip_write_all int 1 t_done 342 if not ok 343 ret int 1 344 end 345 ret int 0 346 end