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
omega-mv / si / packages / homebrew / test.om
| 1 | om2 |
| 2 | note si/packages/homebrew/test.om: Standalone OM-2 behavioral test suite for homebrew-omega formula generator & validator. |
| 3 | note Tests positive formula generation/validation (semver, date version, interplane/github URLs) |
| 4 | note and negative/refusal controls (bad version, disallowed URL prefix, path traversal, bad SHA-256, |
| 5 | note Ruby/shell injection chars, and tampered emitted formula). |
| 6 | |
| 7 | global outbuf uchar 8192 |
| 8 | global decbuf uchar 32 |
| 9 | global f_ver uchar 128 |
| 10 | global f_url uchar 384 |
| 11 | global f_sha uchar 128 |
| 12 | global f_omc uchar 128 |
| 13 | global f_home uchar 384 |
| 14 | global f_lic uchar 128 |
| 15 | global meta ulong 16 |
| 16 | |
| 17 | const k_outlen ulong 1 |
| 18 | const k_vlen ulong 2 |
| 19 | const k_ulen ulong 3 |
| 20 | const k_slen ulong 4 |
| 21 | const k_olen ulong 5 |
| 22 | const k_hlen ulong 6 |
| 23 | const k_llen ulong 7 |
| 24 | |
| 25 | text allow_p1 "https://interplane.io/" |
| 26 | text allow_p2 "https://github.com/aien-dev/" |
| 27 | text allow_p3 "https://github.com/drakestapleton/" |
| 28 | text sfx_tgz ".tar.gz" |
| 29 | text sfx_txz ".tar.xz" |
| 30 | |
| 31 | text rb_hdr "# omc, the Omega compiler, born from the 408-byte hand-written seed of aien-dev/omega-mv.\nclass Omc < Formula\n desc \"Omega compiler, born from a 408-byte hand-written seed\"\n homepage \"" |
| 32 | text rb_url "\"\n url \"" |
| 33 | text rb_ver "\"\n version \"" |
| 34 | text rb_sha "\"\n sha256 \"" |
| 35 | text rb_lic "\"\n license \"" |
| 36 | text rb_dep "\"\n\n depends_on arch: :arm64\n depends_on :linux\n\n OMC_SHA256 = \"" |
| 37 | text rb_inst "\".freeze\n\n def install\n system \"sh\", \"seed/omega-from-seed.sh\"\n got = Digest::SHA256.file(\"seed/out/omc\").hexdigest\n odie \"omc sha256 #{got} is not the pinned #{OMC_SHA256}\" if got != OMC_SHA256\n bin.install \"seed/out/omc\"\n end\nend\n" |
| 38 | |
| 39 | text chk_cls "class Omc < Formula" |
| 40 | text chk_arm "depends_on arch: :arm64" |
| 41 | text chk_lin "depends_on :linux" |
| 42 | text chk_odi "odie \"omc sha256 " |
| 43 | |
| 44 | text v_ok_git "0.0.0+git.e5b32567" |
| 45 | text v_ok_sem "1.2.3-rc.1" |
| 46 | text v_ok_date "20261119" |
| 47 | text v_bad_2part "1.2" |
| 48 | text v_bad_dots "1.2..3" |
| 49 | text v_bad_pfx "v1.0.0" |
| 50 | text v_bad_date "20261301" |
| 51 | text v_bad_trail "1.0.0+" |
| 52 | text v_inj_interp "1.0.0#{id}" |
| 53 | text v_inj_quote "1.0.0\"+" |
| 54 | text v_inj_semi "1.0.0;id" |
| 55 | |
| 56 | text u_ok_gh "https://github.com/aien-dev/omega-mv/archive/e5b32567a7aff3ce594e3254a622a846a6cd190b.tar.gz" |
| 57 | text u_ok_ip "https://interplane.io/drakestapleton/omega-mv/archive/v1.0.0.tar.xz" |
| 58 | text u_bad_http "http://github.com/aien-dev/omega-mv/archive/e5b32567.tar.gz" |
| 59 | text u_bad_host "https://evil.example/aien-dev/omega-mv/archive/x.tar.gz" |
| 60 | text u_bad_ext "https://interplane.io/drakestapleton/omega-mv/install.sh" |
| 61 | text u_bad_trav "https://interplane.io/drakestapleton/../etc/passwd.tar.gz" |
| 62 | text u_bad_inj "https://interplane.io/drakestapleton/x\"#{id}.tar.gz" |
| 63 | |
| 64 | text h_ok_gh "https://github.com/aien-dev/omega-mv" |
| 65 | text h_ok_ip "https://interplane.io/drakestapleton/omega-mv" |
| 66 | text h_bad_inj "https://interplane.io/drakestapleton/omega-mv\"#{" |
| 67 | |
| 68 | text l_ok "Apache-2.0" |
| 69 | text l_bad_inj "Apache-2.0\";system('id')" |
| 70 | |
| 71 | text s_ok_src "c621b6cefe728d67a1a253a9d8991495406460d365dd91ea356451eb2254a95c" |
| 72 | text s_ok_omc "2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f" |
| 73 | text s_bad_short "c621b6cefe728d67a1a253a9d8991495406460d365dd91ea356451eb2254a95" |
| 74 | text s_bad_upper "C621b6cefe728d67a1a253a9d8991495406460d365dd91ea356451eb2254a95c" |
| 75 | text s_bad_char "z621b6cefe728d67a1a253a9d8991495406460d365dd91ea356451eb2254a95c" |
| 76 | |
| 77 | text bad_rb "class Omc < Formula\n depends_on arch: :arm64\nend\n" |
| 78 | |
| 79 | text p_1 "PASS valid_upstream_formula_emitted_and_validated\n" |
| 80 | text p_2 "PASS valid_interplane_semver_and_date_versions\n" |
| 81 | text p_3 "PASS neg_bad_versions_refused\n" |
| 82 | text p_4 "PASS neg_bad_urls_and_traversal_refused\n" |
| 83 | text p_5 "PASS neg_bad_sha256_digests_refused\n" |
| 84 | text p_6 "PASS neg_ruby_shell_injection_refused\n" |
| 85 | text p_7 "PASS neg_tampered_formula_refused\n" |
| 86 | text p_all "HOMEBREW-OMEGA TEST SUITE PASS (7/7)\n" |
| 87 | text f_msg "FAIL test case " |
| 88 | text t_nl "\n" |
| 89 | |
| 90 | fn write_all fd int src view uchar * off ulong n ulong to void |
| 91 | p = ulong 0 |
| 92 | while lt p n bound 4096 |
| 93 | k = write fd src add off p sub n p |
| 94 | if le k 0 |
| 95 | exit 2 |
| 96 | end |
| 97 | p = add p ulong k |
| 98 | end |
| 99 | end |
| 100 | |
| 101 | fn wstr fd int s view uchar * to void |
| 102 | write_all fd s 0 len s |
| 103 | end |
| 104 | |
| 105 | fn wdec fd int v ulong to void |
| 106 | i = ulong 32 |
| 107 | n = v |
| 108 | while true bound 24 |
| 109 | i = sub i 1 |
| 110 | put decbuf i uchar add rem n 10 48 |
| 111 | n = div n 10 |
| 112 | if eq n 0 |
| 113 | break |
| 114 | end |
| 115 | end |
| 116 | p = i |
| 117 | while lt p 32 bound 32 |
| 118 | k = write fd decbuf p sub 32 p |
| 119 | if le k 0 |
| 120 | exit 2 |
| 121 | end |
| 122 | p = add p ulong k |
| 123 | end |
| 124 | end |
| 125 | |
| 126 | fn fail_case id ulong to void |
| 127 | wstr 2 f_msg |
| 128 | wdec 2 id |
| 129 | wstr 2 t_nl |
| 130 | exit 1 |
| 131 | end |
| 132 | |
| 133 | fn set_field which ulong s view uchar * to void |
| 134 | n = len s |
| 135 | i = ulong 0 |
| 136 | while lt i n bound 384 |
| 137 | c = get s i |
| 138 | if eq which 0 |
| 139 | put f_home i c |
| 140 | else |
| 141 | if eq which 1 |
| 142 | put f_url i c |
| 143 | else |
| 144 | if eq which 2 |
| 145 | put f_ver i c |
| 146 | else |
| 147 | if eq which 3 |
| 148 | put f_sha i c |
| 149 | else |
| 150 | if eq which 4 |
| 151 | put f_lic i c |
| 152 | else |
| 153 | put f_omc i c |
| 154 | end |
| 155 | end |
| 156 | end |
| 157 | end |
| 158 | end |
| 159 | i = add i 1 |
| 160 | end |
| 161 | if eq which 0 |
| 162 | put meta k_hlen n |
| 163 | else |
| 164 | if eq which 1 |
| 165 | put meta k_ulen n |
| 166 | else |
| 167 | if eq which 2 |
| 168 | put meta k_vlen n |
| 169 | else |
| 170 | if eq which 3 |
| 171 | put meta k_slen n |
| 172 | else |
| 173 | if eq which 4 |
| 174 | put meta k_llen n |
| 175 | else |
| 176 | put meta k_olen n |
| 177 | end |
| 178 | end |
| 179 | end |
| 180 | end |
| 181 | end |
| 182 | end |
| 183 | |
| 184 | fn is_dig c uchar to bool |
| 185 | ret and ge c 48 le c 57 |
| 186 | end |
| 187 | |
| 188 | fn is_hex_low c uchar to bool |
| 189 | if is_dig c |
| 190 | ret true |
| 191 | end |
| 192 | ret and ge c 97 le c 102 |
| 193 | end |
| 194 | |
| 195 | fn is_alnum c uchar to bool |
| 196 | if is_dig c |
| 197 | ret true |
| 198 | end |
| 199 | if and ge c 65 le c 90 |
| 200 | ret true |
| 201 | end |
| 202 | ret and ge c 97 le c 122 |
| 203 | end |
| 204 | |
| 205 | fn is_injection_ch c uchar to bool |
| 206 | if or lt c 32 gt c 126 |
| 207 | ret true |
| 208 | end |
| 209 | if or eq c 34 eq c 39 |
| 210 | ret true |
| 211 | end |
| 212 | if or eq c 96 eq c 92 |
| 213 | ret true |
| 214 | end |
| 215 | if or eq c 36 eq c 35 |
| 216 | ret true |
| 217 | end |
| 218 | if or eq c 59 eq c 124 |
| 219 | ret true |
| 220 | end |
| 221 | if or eq c 38 eq c 40 |
| 222 | ret true |
| 223 | end |
| 224 | if or eq c 41 eq c 123 |
| 225 | ret true |
| 226 | end |
| 227 | if or eq c 125 or eq c 60 eq c 62 |
| 228 | ret true |
| 229 | end |
| 230 | ret false |
| 231 | end |
| 232 | |
| 233 | fn is_url_ch c uchar to bool |
| 234 | if is_alnum c |
| 235 | ret true |
| 236 | end |
| 237 | if or eq c 45 eq c 46 |
| 238 | ret true |
| 239 | end |
| 240 | if or eq c 95 eq c 126 |
| 241 | ret true |
| 242 | end |
| 243 | if or eq c 58 eq c 47 |
| 244 | ret true |
| 245 | end |
| 246 | ret eq c 37 |
| 247 | end |
| 248 | |
| 249 | fn valid_sha_field which ulong to bool |
| 250 | n = ulong 0 |
| 251 | if eq which 0 |
| 252 | n = get meta k_slen |
| 253 | else |
| 254 | n = get meta k_olen |
| 255 | end |
| 256 | if ne n 64 |
| 257 | ret false |
| 258 | end |
| 259 | i = ulong 0 |
| 260 | while lt i 64 bound 64 |
| 261 | c = uchar 0 |
| 262 | if eq which 0 |
| 263 | c = get f_sha i |
| 264 | else |
| 265 | c = get f_omc i |
| 266 | end |
| 267 | if not is_hex_low c |
| 268 | ret false |
| 269 | end |
| 270 | i = add i 1 |
| 271 | end |
| 272 | ret true |
| 273 | end |
| 274 | |
| 275 | fn valid_ver_ext pos ulong vlen ulong to bool |
| 276 | if ge pos vlen |
| 277 | ret false |
| 278 | end |
| 279 | seg = ulong 0 |
| 280 | i = pos |
| 281 | while lt i vlen bound 128 |
| 282 | c = get f_ver i |
| 283 | if is_injection_ch c |
| 284 | ret false |
| 285 | end |
| 286 | if eq c 46 |
| 287 | if eq seg 0 |
| 288 | ret false |
| 289 | end |
| 290 | seg = ulong 0 |
| 291 | else |
| 292 | if or is_alnum c eq c 45 |
| 293 | seg = add seg 1 |
| 294 | else |
| 295 | ret false |
| 296 | end |
| 297 | end |
| 298 | i = add i 1 |
| 299 | end |
| 300 | ret gt seg 0 |
| 301 | end |
| 302 | |
| 303 | fn valid_date_ver to bool |
| 304 | j = ulong 0 |
| 305 | while lt j 8 bound 8 |
| 306 | if not is_dig get f_ver j |
| 307 | ret false |
| 308 | end |
| 309 | j = add j 1 |
| 310 | end |
| 311 | yr = mul ulong sub get f_ver 0 48 1000 |
| 312 | yr = add yr mul ulong sub get f_ver 1 48 100 |
| 313 | yr = add yr mul ulong sub get f_ver 2 48 10 |
| 314 | yr = add yr ulong sub get f_ver 3 48 |
| 315 | mo = mul ulong sub get f_ver 4 48 10 |
| 316 | mo = add mo ulong sub get f_ver 5 48 |
| 317 | dy = mul ulong sub get f_ver 6 48 10 |
| 318 | dy = add dy ulong sub get f_ver 7 48 |
| 319 | if lt yr 2020 |
| 320 | ret false |
| 321 | end |
| 322 | if or lt mo 1 gt mo 12 |
| 323 | ret false |
| 324 | end |
| 325 | ret and ge dy 1 le dy 31 |
| 326 | end |
| 327 | |
| 328 | fn valid_version to bool |
| 329 | n = get meta k_vlen |
| 330 | if or eq n 0 gt n 64 |
| 331 | ret false |
| 332 | end |
| 333 | i = ulong 0 |
| 334 | while lt i n bound 128 |
| 335 | if is_injection_ch get f_ver i |
| 336 | ret false |
| 337 | end |
| 338 | i = add i 1 |
| 339 | end |
| 340 | if eq n 8 |
| 341 | if valid_date_ver |
| 342 | ret true |
| 343 | end |
| 344 | end |
| 345 | dots = ulong 0 |
| 346 | seg = ulong 0 |
| 347 | p = ulong 0 |
| 348 | while lt p n bound 128 |
| 349 | c = get f_ver p |
| 350 | if is_dig c |
| 351 | seg = add seg 1 |
| 352 | else |
| 353 | if eq c 46 |
| 354 | if or eq seg 0 ge dots 2 |
| 355 | ret false |
| 356 | end |
| 357 | dots = add dots 1 |
| 358 | seg = ulong 0 |
| 359 | else |
| 360 | if or eq c 45 eq c 43 |
| 361 | if or ne dots 2 eq seg 0 |
| 362 | ret false |
| 363 | end |
| 364 | ret valid_ver_ext add p 1 n |
| 365 | else |
| 366 | ret false |
| 367 | end |
| 368 | end |
| 369 | end |
| 370 | p = add p 1 |
| 371 | end |
| 372 | ret and eq dots 2 gt seg 0 |
| 373 | end |
| 374 | |
| 375 | fn url_starts_with pfx view uchar * is_home bool to bool |
| 376 | pl = len pfx |
| 377 | ul = ulong 0 |
| 378 | if is_home |
| 379 | ul = get meta k_hlen |
| 380 | else |
| 381 | ul = get meta k_ulen |
| 382 | end |
| 383 | if lt ul pl |
| 384 | ret false |
| 385 | end |
| 386 | i = ulong 0 |
| 387 | while lt i pl bound 64 |
| 388 | c = uchar 0 |
| 389 | if is_home |
| 390 | c = get f_home i |
| 391 | else |
| 392 | c = get f_url i |
| 393 | end |
| 394 | if ne c get pfx i |
| 395 | ret false |
| 396 | end |
| 397 | i = add i 1 |
| 398 | end |
| 399 | ret true |
| 400 | end |
| 401 | |
| 402 | fn url_ends_with sfx view uchar * to bool |
| 403 | sl = len sfx |
| 404 | ul = get meta k_ulen |
| 405 | if lt ul sl |
| 406 | ret false |
| 407 | end |
| 408 | off = sub ul sl |
| 409 | i = ulong 0 |
| 410 | while lt i sl bound 32 |
| 411 | if ne get f_url add off i get sfx i |
| 412 | ret false |
| 413 | end |
| 414 | i = add i 1 |
| 415 | end |
| 416 | ret true |
| 417 | end |
| 418 | |
| 419 | fn url_has_dotdot is_home bool to bool |
| 420 | ul = ulong 0 |
| 421 | if is_home |
| 422 | ul = get meta k_hlen |
| 423 | else |
| 424 | ul = get meta k_ulen |
| 425 | end |
| 426 | if lt ul 2 |
| 427 | ret false |
| 428 | end |
| 429 | i = ulong 0 |
| 430 | lim = sub ul 1 |
| 431 | while lt i lim bound 384 |
| 432 | a = uchar 0 |
| 433 | b = uchar 0 |
| 434 | if is_home |
| 435 | a = get f_home i |
| 436 | b = get f_home add i 1 |
| 437 | else |
| 438 | a = get f_url i |
| 439 | b = get f_url add i 1 |
| 440 | end |
| 441 | if and eq a 46 eq b 46 |
| 442 | ret true |
| 443 | end |
| 444 | i = add i 1 |
| 445 | end |
| 446 | ret false |
| 447 | end |
| 448 | |
| 449 | fn valid_url to bool |
| 450 | ul = get meta k_ulen |
| 451 | if or lt ul 16 gt ul 320 |
| 452 | ret false |
| 453 | end |
| 454 | ok_pfx = false |
| 455 | if url_starts_with allow_p1 false |
| 456 | ok_pfx = true |
| 457 | end |
| 458 | if url_starts_with allow_p2 false |
| 459 | ok_pfx = true |
| 460 | end |
| 461 | if url_starts_with allow_p3 false |
| 462 | ok_pfx = true |
| 463 | end |
| 464 | if not ok_pfx |
| 465 | ret false |
| 466 | end |
| 467 | ok_sfx = false |
| 468 | if url_ends_with sfx_tgz |
| 469 | ok_sfx = true |
| 470 | end |
| 471 | if url_ends_with sfx_txz |
| 472 | ok_sfx = true |
| 473 | end |
| 474 | if not ok_sfx |
| 475 | ret false |
| 476 | end |
| 477 | if url_has_dotdot false |
| 478 | ret false |
| 479 | end |
| 480 | i = ulong 0 |
| 481 | while lt i ul bound 384 |
| 482 | c = get f_url i |
| 483 | if or is_injection_ch c not is_url_ch c |
| 484 | ret false |
| 485 | end |
| 486 | i = add i 1 |
| 487 | end |
| 488 | ret true |
| 489 | end |
| 490 | |
| 491 | fn valid_homepage to bool |
| 492 | hl = get meta k_hlen |
| 493 | if or lt hl 16 gt hl 320 |
| 494 | ret false |
| 495 | end |
| 496 | ok_pfx = false |
| 497 | if url_starts_with allow_p1 true |
| 498 | ok_pfx = true |
| 499 | end |
| 500 | if url_starts_with allow_p2 true |
| 501 | ok_pfx = true |
| 502 | end |
| 503 | if url_starts_with allow_p3 true |
| 504 | ok_pfx = true |
| 505 | end |
| 506 | if not ok_pfx |
| 507 | ret false |
| 508 | end |
| 509 | if url_has_dotdot true |
| 510 | ret false |
| 511 | end |
| 512 | i = ulong 0 |
| 513 | while lt i hl bound 384 |
| 514 | c = get f_home i |
| 515 | if or is_injection_ch c not is_url_ch c |
| 516 | ret false |
| 517 | end |
| 518 | i = add i 1 |
| 519 | end |
| 520 | ret true |
| 521 | end |
| 522 | |
| 523 | fn valid_license to bool |
| 524 | ll = get meta k_llen |
| 525 | if or eq ll 0 gt ll 64 |
| 526 | ret false |
| 527 | end |
| 528 | i = ulong 0 |
| 529 | while lt i ll bound 64 |
| 530 | c = get f_lic i |
| 531 | if is_injection_ch c |
| 532 | ret false |
| 533 | end |
| 534 | ok = false |
| 535 | if is_alnum c |
| 536 | ok = true |
| 537 | end |
| 538 | if or eq c 45 or eq c 46 or eq c 43 eq c 32 |
| 539 | ok = true |
| 540 | end |
| 541 | if not ok |
| 542 | ret false |
| 543 | end |
| 544 | i = add i 1 |
| 545 | end |
| 546 | ret true |
| 547 | end |
| 548 | |
| 549 | fn out_clear to void |
| 550 | put meta k_outlen 0 |
| 551 | end |
| 552 | |
| 553 | fn out_push_lit s view uchar * to void |
| 554 | sl = len s |
| 555 | p = get meta k_outlen |
| 556 | i = ulong 0 |
| 557 | while lt i sl bound 4096 |
| 558 | if lt p 8192 |
| 559 | put outbuf p get s i |
| 560 | p = add p 1 |
| 561 | end |
| 562 | i = add i 1 |
| 563 | end |
| 564 | put meta k_outlen p |
| 565 | end |
| 566 | |
| 567 | fn out_push_field which ulong to void |
| 568 | p = get meta k_outlen |
| 569 | n = ulong 0 |
| 570 | if eq which 0 |
| 571 | n = get meta k_hlen |
| 572 | else |
| 573 | if eq which 1 |
| 574 | n = get meta k_ulen |
| 575 | else |
| 576 | if eq which 2 |
| 577 | n = get meta k_vlen |
| 578 | else |
| 579 | if eq which 3 |
| 580 | n = get meta k_slen |
| 581 | else |
| 582 | if eq which 4 |
| 583 | n = get meta k_llen |
| 584 | else |
| 585 | n = get meta k_olen |
| 586 | end |
| 587 | end |
| 588 | end |
| 589 | end |
| 590 | end |
| 591 | i = ulong 0 |
| 592 | while lt i n bound 384 |
| 593 | c = uchar 0 |
| 594 | if eq which 0 |
| 595 | c = get f_home i |
| 596 | else |
| 597 | if eq which 1 |
| 598 | c = get f_url i |
| 599 | else |
| 600 | if eq which 2 |
| 601 | c = get f_ver i |
| 602 | else |
| 603 | if eq which 3 |
| 604 | c = get f_sha i |
| 605 | else |
| 606 | if eq which 4 |
| 607 | c = get f_lic i |
| 608 | else |
| 609 | c = get f_omc i |
| 610 | end |
| 611 | end |
| 612 | end |
| 613 | end |
| 614 | end |
| 615 | if lt p 8192 |
| 616 | put outbuf p c |
| 617 | p = add p 1 |
| 618 | end |
| 619 | i = add i 1 |
| 620 | end |
| 621 | put meta k_outlen p |
| 622 | end |
| 623 | |
| 624 | fn emit_formula to void |
| 625 | out_clear |
| 626 | out_push_lit rb_hdr |
| 627 | out_push_field 0 |
| 628 | out_push_lit rb_url |
| 629 | out_push_field 1 |
| 630 | out_push_lit rb_ver |
| 631 | out_push_field 2 |
| 632 | out_push_lit rb_sha |
| 633 | out_push_field 3 |
| 634 | out_push_lit rb_lic |
| 635 | out_push_field 4 |
| 636 | out_push_lit rb_dep |
| 637 | out_push_field 5 |
| 638 | out_push_lit rb_inst |
| 639 | end |
| 640 | |
| 641 | fn out_starts_at pos ulong needle view uchar * to bool |
| 642 | nl = len needle |
| 643 | tot = get meta k_outlen |
| 644 | if gt add pos nl tot |
| 645 | ret false |
| 646 | end |
| 647 | i = ulong 0 |
| 648 | while lt i nl bound 128 |
| 649 | if ne get outbuf add pos i get needle i |
| 650 | ret false |
| 651 | end |
| 652 | i = add i 1 |
| 653 | end |
| 654 | ret true |
| 655 | end |
| 656 | |
| 657 | fn out_contains needle view uchar * to bool |
| 658 | nl = len needle |
| 659 | tot = get meta k_outlen |
| 660 | if gt nl tot |
| 661 | ret false |
| 662 | end |
| 663 | lim = add sub tot nl 1 |
| 664 | i = ulong 0 |
| 665 | while lt i lim bound 8192 |
| 666 | if out_starts_at i needle |
| 667 | ret true |
| 668 | end |
| 669 | i = add i 1 |
| 670 | end |
| 671 | ret false |
| 672 | end |
| 673 | |
| 674 | fn validate_emitted_formula to bool |
| 675 | if not out_contains chk_cls |
| 676 | ret false |
| 677 | end |
| 678 | if not out_contains chk_arm |
| 679 | ret false |
| 680 | end |
| 681 | if not out_contains chk_lin |
| 682 | ret false |
| 683 | end |
| 684 | if not out_contains chk_odi |
| 685 | ret false |
| 686 | end |
| 687 | ret true |
| 688 | end |
| 689 | |
| 690 | fn main to int |
| 691 | note Test 1: valid upstream formula parameters |
| 692 | set_field 0 h_ok_gh |
| 693 | set_field 1 u_ok_gh |
| 694 | set_field 2 v_ok_git |
| 695 | set_field 3 s_ok_src |
| 696 | set_field 4 l_ok |
| 697 | set_field 5 s_ok_omc |
| 698 | if not and valid_version and valid_url and valid_sha_field 0 and valid_sha_field 1 and valid_homepage valid_license |
| 699 | fail_case 1 |
| 700 | end |
| 701 | emit_formula |
| 702 | if not validate_emitted_formula |
| 703 | fail_case 1 |
| 704 | end |
| 705 | wstr 1 p_1 |
| 706 | |
| 707 | note Test 2: valid Interplane URL, semver-prerelease, and date version |
| 708 | set_field 0 h_ok_ip |
| 709 | set_field 1 u_ok_ip |
| 710 | set_field 2 v_ok_sem |
| 711 | if not and valid_homepage and valid_url valid_version |
| 712 | fail_case 2 |
| 713 | end |
| 714 | set_field 2 v_ok_date |
| 715 | if not valid_version |
| 716 | fail_case 2 |
| 717 | end |
| 718 | wstr 1 p_2 |
| 719 | |
| 720 | note Test 3: negative control - invalid versions |
| 721 | set_field 2 v_bad_2part |
| 722 | if valid_version |
| 723 | fail_case 3 |
| 724 | end |
| 725 | set_field 2 v_bad_dots |
| 726 | if valid_version |
| 727 | fail_case 3 |
| 728 | end |
| 729 | set_field 2 v_bad_pfx |
| 730 | if valid_version |
| 731 | fail_case 3 |
| 732 | end |
| 733 | set_field 2 v_bad_date |
| 734 | if valid_version |
| 735 | fail_case 3 |
| 736 | end |
| 737 | set_field 2 v_bad_trail |
| 738 | if valid_version |
| 739 | fail_case 3 |
| 740 | end |
| 741 | wstr 1 p_3 |
| 742 | |
| 743 | note Test 4: negative control - disallowed URLs & path traversal |
| 744 | set_field 1 u_bad_http |
| 745 | if valid_url |
| 746 | fail_case 4 |
| 747 | end |
| 748 | set_field 1 u_bad_host |
| 749 | if valid_url |
| 750 | fail_case 4 |
| 751 | end |
| 752 | set_field 1 u_bad_ext |
| 753 | if valid_url |
| 754 | fail_case 4 |
| 755 | end |
| 756 | set_field 1 u_bad_trav |
| 757 | if valid_url |
| 758 | fail_case 4 |
| 759 | end |
| 760 | wstr 1 p_4 |
| 761 | |
| 762 | note Test 5: negative control - malformed SHA-256 digests |
| 763 | set_field 3 s_bad_short |
| 764 | if valid_sha_field 0 |
| 765 | fail_case 5 |
| 766 | end |
| 767 | set_field 3 s_bad_upper |
| 768 | if valid_sha_field 0 |
| 769 | fail_case 5 |
| 770 | end |
| 771 | set_field 5 s_bad_char |
| 772 | if valid_sha_field 1 |
| 773 | fail_case 5 |
| 774 | end |
| 775 | wstr 1 p_5 |
| 776 | |
| 777 | note Test 6: negative control - Ruby/shell injection characters |
| 778 | set_field 2 v_inj_interp |
| 779 | if valid_version |
| 780 | fail_case 6 |
| 781 | end |
| 782 | set_field 2 v_inj_quote |
| 783 | if valid_version |
| 784 | fail_case 6 |
| 785 | end |
| 786 | set_field 2 v_inj_semi |
| 787 | if valid_version |
| 788 | fail_case 6 |
| 789 | end |
| 790 | set_field 1 u_bad_inj |
| 791 | if valid_url |
| 792 | fail_case 6 |
| 793 | end |
| 794 | set_field 0 h_bad_inj |
| 795 | if valid_homepage |
| 796 | fail_case 6 |
| 797 | end |
| 798 | set_field 4 l_bad_inj |
| 799 | if valid_license |
| 800 | fail_case 6 |
| 801 | end |
| 802 | wstr 1 p_6 |
| 803 | |
| 804 | note Test 7: negative control - tampered formula missing linux/odie checks |
| 805 | out_clear |
| 806 | out_push_lit bad_rb |
| 807 | if validate_emitted_formula |
| 808 | fail_case 7 |
| 809 | end |
| 810 | wstr 1 p_7 |
| 811 | |
| 812 | wstr 1 p_all |
| 813 | ret 0 |
| 814 | end |