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/hive-view/blob/main/tests/gate.om # hive-view aien-dev/hive-view Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `hive-view / tests / gate.om` 1239 lines · 23748 bytes Raw Blame History 1 note hive-view tests/gate.om: the acceptance gate, in pure Omega. Built like the server, with 2 note src/util.om and src/run.om (no shell, exact argument lists) and this file as the entry: 3 note gate run PORT drive a running server on 127.0.0.1:PORT through every check below; 4 note prints one PASS/FAIL line per check, exit 0 only when all pass 5 note gate cpu PID SECS CPU ticks (USER_HZ) used by server PID with its children and by the 6 note tmux server over SECS seconds 7 note The run mode creates its own tmux session hv-test whose only program is 8 note `/usr/bin/tee -a /tmp/hv-gate-sink` on a raw (-icanon -echo) terminal, so every byte the 9 note dashboard types is recorded exactly; it is deleted at the end (which is itself a check). 10 global gaport ulong 1 11 global gax uchar 64 12 global gaxl ulong 1 13 global gatg uchar 1024 14 global gatgl ulong 1 15 global gabd uchar 40000 16 global gabdl ulong 1 17 global garb uchar 262144 18 global garbl ulong 1 19 global galoc uchar 1024 20 global galocl ulong 1 21 global gack ulong 1 22 global gakey uchar 64 23 global gatx uchar 8192 24 global gatxl ulong 1 25 global gapass ulong 1 26 global gafail ulong 1 27 global gatk ulong 4 28 text tget "GET" 29 text tpost "POST" 30 text tenvh "HOME=" 31 text ttokf "/.config/hive-view/token" 32 text tlogf "/.local/state/hive-view/sends.log" 33 text tsink "/tmp/hv-gate-sink" 34 text ttmux "/usr/bin/tmux" 35 text tstty "/usr/bin/stty" 36 text ttee "/usr/bin/tee" 37 text tnew "new-session" 38 text tdd "-d" 39 text tds "-s" 40 text tdx "-x" 41 text tdy "-y" 42 text t120 "120" 43 text t30 "30" 44 text tdash "-a" 45 text tkill "kill-session" 46 text tdt "-t" 47 text tdisp "display-message" 48 text tdp "-p" 49 text tptty "#{pane_tty}" 50 text tpid "#{pid}" 51 text tsessn "hv-test" 52 text tsesst "=hv-test:" 53 text tsesk "=hv-test" 54 text tdf "-F" 55 text ticanon "-icanon" 56 text techo "-echo" 57 text thost "Host" 58 text tcook "Cookie" 59 text torig "Origin" 60 text tctype "Content-Type" 61 text tform "application/x-www-form-urlencoded" 62 text tckpre "hv=" 63 text thttp "http://" 64 text tevil "http://evil.example" 65 text tevilh "evil.example" 66 text tlocn "location" 67 text tsetck "set-cookie" 68 text tphealth "/health" 69 text troot "/" 70 text tqt "/?t=" 71 text tpsend "/send" 72 text tpses "/s/hv-test" 73 text tpane "/p/pane?n=hv-test" 74 text tpenq "/p/entries?f=questions" 75 text tpend "/p/entries?f=decisions" 76 text tendh "" 77 text tkpat "name=\"k\" value=\"" 78 text tline "line" 79 text tenter "enter" 80 text tescape "escape" 81 text tps "s" 82 text tpq "q" 83 text tpass "PASS " 84 text tfail "FAIL " 85 text tsum "gate: " 86 text tsum2 " passed, " 87 text tsum3 " failed\n" 88 text tsha "sha256=" 89 text tbyt "bytes=" 90 text tmark "gate-secret-marker-5c1e" 91 text tescs "<script>alert(1)</script>" 92 text tscr "" 110 text c09 " leading and trailing spaces " 111 text c10 "%41+%20&a=escape" 112 text c11 "send-keys -t =omp-queen: Enter" 113 text n01 "send ;semi" 114 note ---- output 115 fn gaout to void 116 n = get gsl 0 117 p = ulong 0 118 for it ulong 1000 119 if ge p n 120 break 121 end 122 w = write 1 gsb p sub n p 123 if le w 0 124 break 125 end 126 p = add p ulong w 127 end 128 put gsl 0 0 129 end 130 fn gachk ok bool name view uchar * to void 131 if ok 132 vwsbt tpass 133 put gapass 0 add get gapass 0 1 134 else 135 vwsbt tfail 136 put gafail 0 add get gafail 0 1 137 end 138 vwsbt name 139 vwsbc 10 140 gaout 141 end 142 note ---- environment 143 fn gahome to bool 144 eb = new uchar 600 0 145 for i ulong ulong envcnt 146 n = envread i eb 0 600 147 if gt n 5 148 if heq view part eb 0 5 tenvh 149 k = hmin sub ulong n 5 511 150 for j ulong k 151 put ghome j get eb add 5 j 152 end 153 put ghomel 0 k 154 ret gt k 0 155 end 156 end 157 end 158 ret false 159 end 160 fn gatok to bool 161 vwpb 162 vwph 163 vwpt ttokf 164 r = vwrdall 128 165 if lt r 64 166 ret false 167 end 168 for i ulong 64 169 put gtok i get gob i 170 end 171 ret true 172 end 173 fn gadec a view uchar * to ulong 174 v = ulong 0 175 for i ulong len a 176 c = get a i 177 if not vwdig c 178 ret v 179 end 180 v = add mul v 10 ulong sub c 48 181 end 182 ret v 183 end 184 note ---- HTTP client: one connection per request. fl: 1 cookie, 2 good Origin, 4 foreign Origin, 185 note 8 foreign Host, 16 bad cookie. The response body lands in garb, Location in galoc, and gack 186 note is 1 when Set-Cookie carried hv=. 187 fn gaxbuf to void 188 put gaxl 0 0 189 s = new uchar 24 0 190 p = ulong 0 191 put s 0 49 192 put s 1 50 193 put s 2 55 194 put s 3 46 195 put s 4 48 196 put s 5 46 197 put s 6 48 198 put s 7 46 199 put s 8 49 200 put s 9 58 201 p = 10 202 for i ulong 10 203 put gax i get s i 204 end 205 d = new uchar 20 0 206 k = ulong 0 207 x = get gaport 0 208 for it ulong 20 209 put d k uchar add rem x 10 48 210 k = add k 1 211 x = div x 10 212 if eq x 0 213 break 214 end 215 end 216 for i ulong k 217 put gax add p i get d sub sub k 1 i 218 end 219 put gaxl 0 add p k 220 end 221 fn gahdrs cs edit ulong 320 io edit uchar 131072 fl ulong to long 222 hb = new uchar 64 0 223 ck = new uchar 67 0 224 o = new uchar 96 0 225 n = get gaxl 0 226 for i ulong n 227 put hb i get gax i 228 end 229 r = hhname cs io thost 230 if ne and fl 8 0 231 r = hfe r hhval cs io tevilh 232 else 233 r = hfe r hhval cs io view part hb 0 n 234 end 235 if ne and fl 17 0 236 for i ulong 3 237 put ck i get tckpre i 238 end 239 for i ulong 64 240 put ck add 3 i get gtok i 241 end 242 if ne and fl 16 0 243 put ck 3 48 244 if eq get gtok 0 48 245 put ck 3 49 246 end 247 end 248 r = hfe r hhname cs io tcook 249 r = hfe r hhval cs io ck 250 end 251 if ne and fl 2 0 252 for i ulong 96 253 put o i 0 254 end 255 for i ulong 7 256 put o i get thttp i 257 end 258 n = get gaxl 0 259 for i ulong n 260 put o add 7 i get gax i 261 end 262 r = hfe r hhname cs io torig 263 r = hfe r hhval cs io view part o 0 add 7 n 264 end 265 if ne and fl 4 0 266 r = hfe r hhname cs io torig 267 r = hfe r hhval cs io tevil 268 end 269 ret r 270 end 271 fn gawreq cs edit ulong 320 io edit uchar 131072 post bool fl ulong to long 272 tg = new uchar 1024 0 273 bd = new uchar 40000 0 274 r = long 0 275 if post 276 r = hreqst cs io tpost 277 else 278 r = hreqst cs io tget 279 end 280 tn = get gatgl 0 281 for i ulong tn 282 put tg i get gatg i 283 end 284 r = hfe r hreqtg cs io view part tg 0 tn 285 r = hfe r gahdrs cs io fl 286 bl = ulong 0 287 if post 288 r = hfe r hhname cs io tctype 289 r = hfe r hhval cs io tform 290 bl = get gabdl 0 291 end 292 r = hfe r hhend cs io 0 bl 293 if post 294 for i ulong bl 295 put bd i get gabd i 296 end 297 r = hfe r hput cs io view part bd 0 bl 298 end 299 ret hfe r hwfin cs io 300 end 301 fn garbody cs edit ulong 320 io edit uchar 131072 to void 302 rb = new uchar 262144 0 303 put cs HBCAP 262144 304 n = hbodyall cs io rb 305 m = ulong 0 306 if gt n 0 307 m = ulong n 308 end 309 for i ulong m 310 put garb i get rb i 311 end 312 put garbl 0 m 313 end 314 fn gareq post bool fl ulong to long 315 a = new uchar 16 0 316 cs = new ulong 320 0 317 io = new uchar 131072 0 318 put garbl 0 0 319 put galocl 0 0 320 put gack 0 0 321 r = haddr4 a uint `2130706433` get gaport 0 322 fd = hdial a `3000000000` 323 if lt fd 0 324 ret fd 325 end 326 r = hinit cs io int fd 0 327 hsettmo cs `10000000000` `10000000000` 328 hsetbdl cs `10000000000` 329 r = hfe r gawreq cs io post fl 330 if lt r 0 331 x = hclose cs 332 ret r 333 end 334 s = hrsprd cs io 335 if lt s 0 336 x = hclose cs 337 ret s 338 end 339 garesp cs io 340 garbody cs io 341 x = hclose cs 342 ret s 343 end 344 fn garesp cs edit ulong 320 io edit uchar 131072 to void 345 i = hhfind cs io tlocn 346 if ge i 0 347 vo = hhvoff cs ulong i 348 vl = hmin hhvlen cs ulong i 1024 349 for k ulong vl 350 put galoc k get io add vo k 351 end 352 put galocl 0 vl 353 end 354 j = hhfind cs io tsetck 355 if ge j 0 356 vo = hhvoff cs ulong j 357 vl = hhvlen cs ulong j 358 if ge vl 67 359 ok = heq view part io vo 3 tckpre 360 for k ulong 64 361 if ne get io add add vo 3 k get gtok k 362 ok = false 363 end 364 end 365 if ok 366 put gack 0 1 367 end 368 end 369 end 370 end 371 fn gatgt t view uchar * to void 372 for i ulong len t 373 put gatg i get t i 374 end 375 put gatgl 0 len t 376 end 377 fn gaget t view uchar * fl ulong to long 378 gatgt t 379 ret gareq false fl 380 end 381 fn hmax2 a long b long to long 382 if gt a b 383 ret a 384 end 385 ret b 386 end 387 fn garbat a ulong t view uchar * to bool 388 if gt add a len t get garbl 0 389 ret false 390 end 391 for i ulong len t 392 if ne get garb add a i get t i 393 ret false 394 end 395 end 396 ret true 397 end 398 fn gaobat a ulong t view uchar * to bool 399 if gt add a len t get gol 0 400 ret false 401 end 402 for i ulong len t 403 if ne get gob add a i get t i 404 ret false 405 end 406 end 407 ret true 408 end 409 note gahas: garb contains t 410 fn gahas t view uchar * to bool 411 n = get garbl 0 412 m = len t 413 if gt m n 414 ret false 415 end 416 for i ulong add sub n m 1 417 if garbat i t 418 ret true 419 end 420 end 421 ret false 422 end 423 note ---- form bodies 424 fn gabc c uchar to void 425 n = get gabdl 0 426 if lt n len gabd 427 put gabd n c 428 put gabdl 0 add n 1 429 end 430 end 431 fn gabt t view uchar * to void 432 for i ulong len t 433 gabc get t i 434 end 435 end 436 note gabe: percent-encode every byte except ASCII letters and digits 437 fn gabe a view uchar * to void 438 for i ulong len a 439 c = get a i 440 if or vwdig c or and ge c 65 le c 90 and ge c 97 le c 122 441 gabc c 442 else 443 gabc 37 444 gabc get thexd ulong shr ulong c 4 445 gabc get thexd and ulong c 15 446 end 447 end 448 end 449 fn gafld k uchar v view uchar * to void 450 if gt get gabdl 0 0 451 gabc 38 452 end 453 gabc k 454 gabc 61 455 gabe v 456 end 457 note gaform: s, k, r, a and t (the text is gatx[0, gatxl)); badk 1 sends a wrong key 458 fn gaform sn view uchar * act view uchar * badk ulong to void 459 z = new uchar 64 48 460 kk = new uchar 64 0 461 tx = new uchar 8192 0 462 put gabdl 0 0 463 gafld 115 sn 464 if eq badk 1 465 gafld 107 z 466 else 467 for i ulong 64 468 put kk i get gakey i 469 end 470 gafld 107 kk 471 end 472 gafld 114 tps 473 gafld 97 act 474 n = get gatxl 0 475 for i ulong n 476 put tx i get gatx i 477 end 478 gafld 116 view part tx 0 n 479 end 480 fn gapost fl ulong to long 481 gatgt tpsend 482 ret gareq true fl 483 end 484 note galq: the number after "=" in the Location query, or 999999 485 fn galq c uchar to ulong 486 n = get galocl 0 487 for i ulong n 488 if and eq get galoc i c lt add i 1 n 489 if eq get galoc add i 1 61 490 p = add i 2 491 if or eq i 0 or eq get galoc sub i 1 63 eq get galoc sub i 1 38 492 v = ulong 0 493 ok = false 494 for k ulong 20 495 if ge add p k n 496 break 497 end 498 d = get galoc add p k 499 if not vwdig d 500 break 501 end 502 v = add mul v 10 ulong sub d 48 503 ok = true 504 end 505 if ok 506 ret v 507 end 508 end 509 end 510 end 511 end 512 ret 999999 513 end 514 note ---- the sink file written by tee inside hv-test 515 fn gasinkp to void 516 vwpb 517 vwpt tsink 518 end 519 fn gasize to ulong 520 gasinkp 521 fd = vwfopen 522 if lt fd 0 523 ret 0 524 end 525 r = fstat int fd gstb 0 128 526 x = fclose int fd 527 if lt r 0 528 ret 0 529 end 530 ret vwst64 48 531 end 532 fn gawait want ulong to bool 533 for it ulong 60 534 if ge gasize want 535 ret true 536 end 537 x = sleepns `50000000` 538 end 539 ret ge gasize want 540 end 541 note gasink: the sink from offset off holds exactly gatx[0, gatxl) followed by the byte tail 542 fn gasink off ulong tail long to bool 543 gasinkp 544 r = vwrdall 262144 545 if lt r 0 546 ret false 547 end 548 n = get gatxl 0 549 want = n 550 if ge tail 0 551 want = add n 1 552 end 553 if ne get gol 0 add off want 554 ret false 555 end 556 for i ulong n 557 if ne get gob add off i get gatx i 558 ret false 559 end 560 end 561 if ge tail 0 562 ret eq get gob add off n uchar tail 563 end 564 ret true 565 end 566 fn gasett t view uchar * to void 567 for i ulong len t 568 put gatx i get t i 569 end 570 put gatxl 0 len t 571 end 572 note gatype: type gatx with action act; true when the redirect reports m=0, the byte count, and the 573 note sink received exactly the text plus tail (LF for a line, ESC for Escape, LF for Enter) 574 fn gatype act view uchar * tail long to bool 575 s0 = gasize 576 gaform tsessn act 0 577 st = gapass2 578 if ne st 302 579 ret false 580 end 581 nb = ulong 0 582 if heq act tline 583 nb = get gatxl 0 584 end 585 if ne galq 109 0 586 ret false 587 end 588 if ne galq 98 nb 589 ret false 590 end 591 want = add s0 add nb 1 592 if not gawait want 593 ret false 594 end 595 if heq act tline 596 ret gasink s0 tail 597 end 598 gasinkp 599 r = vwrdall 262144 600 if ne get gol 0 want 601 ret false 602 end 603 ret eq get gob s0 uchar tail 604 end 605 fn gapass2 to long 606 ret gapost 3 607 end 608 note garef: the send is refused with code m and nothing reaches the sink 609 fn garef act view uchar * m ulong to bool 610 s0 = gasize 611 gaform tsessn act 0 612 st = gapost 3 613 if ne st 302 614 ret false 615 end 616 if ne galq 109 m 617 ret false 618 end 619 x = sleepns `300000000` 620 ret eq gasize s0 621 end 622 note ---- tmux and the sink session 623 fn gatmux to void 624 vwkb 625 vwka ttmux 626 end 627 fn gamkses to bool 628 gatmux 629 vwka tkill 630 vwka tdt 631 vwka tsesk 632 r = vwrun `5000000000` 633 gasinkp 634 u = unlink gpth 0 get gpl 0 635 gatmux 636 vwka tnew 637 vwka tdd 638 vwka tds 639 vwka tsessn 640 vwka tdx 641 vwka t120 642 vwka tdy 643 vwka t30 644 vwka ttee 645 vwka tdash 646 vwka tsink 647 r = vwrun `5000000000` 648 if ne r 0 649 ret false 650 end 651 gatmux 652 vwka tdisp 653 vwka tdp 654 vwka tdt 655 vwka tsesst 656 vwka tptty 657 r = vwrun `5000000000` 658 if ne r 0 659 ret false 660 end 661 n = get gol 0 662 if and gt n 0 eq get gob sub n 1 10 663 n = sub n 1 664 end 665 if or eq n 0 gt n 200 666 ret false 667 end 668 vwkb 669 vwka tstty 670 vwka tdf 671 vwkopen 672 for i ulong n 673 vwkc get gob i 674 end 675 vwka ticanon 676 vwka techo 677 r = vwrun `5000000000` 678 x = sleepns `300000000` 679 ret eq r 0 680 end 681 fn gakilss to bool 682 gatmux 683 vwka tkill 684 vwka tdt 685 vwka tsesk 686 r = vwrun `5000000000` 687 ret eq r 0 688 end 689 note gakey: the form key from the hv-test page 690 fn gagetk to bool 691 st = gaget tpses 1 692 if ne st 200 693 ret false 694 end 695 n = get garbl 0 696 m = len tkpat 697 if lt n add m 64 698 ret false 699 end 700 for i ulong sub sub n m 63 701 if garbat i tkpat 702 for k ulong 64 703 put gakey k get garb add add i m k 704 end 705 ret true 706 end 707 end 708 ret false 709 end 710 note ---- send log: the newest line names the bytes and the sha256 of the text; the file never 711 note contains the marker text 712 fn galogok to bool 713 dg = new uchar 32 0 714 tx = new uchar 8192 0 715 tn = get gatxl 0 716 for i ulong tn 717 put tx i get gatx i 718 end 719 k = sha2_digest 256 view part tx 0 tn dg 720 hx = new uchar 71 0 721 for i ulong 7 722 put hx i get tsha i 723 end 724 for i ulong 32 725 put hx add 7 mul i 2 get thexd ulong shr ulong get dg i 4 726 put hx add 8 mul i 2 get thexd and ulong get dg i 15 727 end 728 vwpb 729 vwph 730 vwpt tlogf 731 r = vwrdtail 4096 732 if lt r 0 733 ret false 734 end 735 e = get gol 0 736 if eq e 0 737 ret false 738 end 739 if eq get gob sub e 1 10 740 e = sub e 1 741 end 742 b = e 743 for it ulong 4096 744 if eq b 0 745 break 746 end 747 if eq get gob sub b 1 10 748 break 749 end 750 b = sub b 1 751 end 752 ok = false 753 for i ulong sub e b 754 if gt add add b i 71 e 755 break 756 end 757 if gaobat add b i hx 758 ok = true 759 end 760 end 761 ret ok 762 end 763 fn galogno to bool 764 vwpb 765 vwph 766 vwpt tlogf 767 r = vwrdall 262144 768 n = get gol 0 769 m = len tmark 770 if lt n m 771 ret true 772 end 773 for i ulong add sub n m 1 774 if gaobat i tmark 775 ret false 776 end 777 end 778 ret true 779 end 780 text tbadact "type" 781 text thc01 "health answers 200 without auth" 782 text thc02 "GET / without the cookie is refused (403)" 783 text thc03 "a panel without the cookie is refused (403)" 784 text thc04 "a wrong cookie is refused (403)" 785 text thc05 "a wrong one-time link is refused (403)" 786 text thc06 "the one-time link answers 302 and sets the token cookie" 787 text thc07 "a foreign Host header is refused (400)" 788 text thc08 "GET /send is refused (405)" 789 text thc09 "test session hv-test created (tee into the sink, raw terminal)" 790 text thc10 "the form key is on the session page" 791 text thc11 "POST /send without the cookie is refused (403)" 792 text thc12 "POST /send without an Origin header is refused (403)" 793 text thc13 "POST /send from a foreign Origin is refused (403)" 794 text thc14 "POST /send with a wrong form key is refused (403)" 795 text thc15 "nothing reached the session from the refused posts" 796 text thc16 "literal backslash-semicolon inside the text" 797 text thc17 "literal backslash-semicolon alone" 798 text thc18 "text ending in backslash-semicolon" 799 text thc19 "4096-byte text (the limit) with semicolons at the chunk edges" 800 text thc20 "Enter button sends one Enter" 801 text thc21 "Escape button sends one Escape" 802 text thc22 "marker text typed" 803 text thc23 "send log names the byte count and sha256 of the text" 804 text thc24 "send log never contains the text" 805 text thc25 "4097-byte text refused (m=7), nothing typed" 806 text thc26 "control byte 0x01 refused (m=4), nothing typed" 807 text thc27 "newline inside the text refused (m=4), nothing typed" 808 text thc28 "DEL refused (m=4), nothing typed" 809 text thc29 "invalid UTF-8 byte 0xff refused (m=4), nothing typed" 810 text thc30 "overlong UTF-8 refused (m=4), nothing typed" 811 text thc31 "carriage return refused (m=4), nothing typed" 812 text thc32 "tab refused (m=4), nothing typed" 813 text thc33 "escape byte inside the text refused (m=4), nothing typed" 814 text thc34 "unknown action refused (m=3), nothing typed" 815 text thc35 "malformed and forged session names refused (m=2), nothing typed" 816 text thc36 "duplicate or unknown form fields refused (m=1), nothing typed" 817 text thc37 "a body over 16 KiB is refused (413), nothing typed" 818 text thc38 "