hive-view
aien-dev/hive-view
Brought by drakestapleton
| 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 "</body></html>" |
| 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 "<script>" |
| 93 | text tcpu1 "hive-view ticks " |
| 94 | text tcpu2 " tmux-server ticks " |
| 95 | text tcpu3 " over " |
| 96 | text tcpu4 " s (USER_HZ 100)\n" |
| 97 | text tstat "/stat" |
| 98 | text tproc "/proc/" |
| 99 | text tchild "/task/" |
| 100 | text tchild2 "/children" |
| 101 | note ---- the cases typed literally: each must arrive byte for byte, followed by Enter (LF) |
| 102 | text c01 "semi;" |
| 103 | text c02 ";" |
| 104 | text c03 ";;" |
| 105 | text c04 "-n" |
| 106 | text c05 "--" |
| 107 | text c06 "$(id) `id` 'q' \"dq\" & | > <" |
| 108 | text c07 "é ü 漢字 🐝" |
| 109 | text c08 "<script>alert(1)</script>" |
| 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=<token>. |
| 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 "<c>=" 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 "<script> on a session screen is shown escaped, never as markup" |
| 819 | text thc39 "test session hv-test deleted" |
| 820 | text thc40 "typing into the deleted session is refused (m=5)" |
| 821 | text thc41 "hv-test no longer exists" |
| 822 | text thc44 "4096-byte text of 3-byte UTF-8 characters, one split by the 2048-byte chunk edge" |
| 823 | text thc45 "Enter with text in the box presses only Enter (the text is not typed)" |
| 824 | text thc46 "QUESTIONS panel answers 200 with the whole page (no \"## \" entries or no file)" |
| 825 | text thc47 "DECISIONS panel answers 200 with the whole page (no \"## \" entries or no file)" |
| 826 | text thc42 "with the send log unwritable the send is refused (m=8), nothing typed" |
| 827 | fn gareq2 t view uchar * to long |
| 828 | gatgt t |
| 829 | ret gareq false 0 |
| 830 | end |
| 831 | note gafbad: forged names (shell metacharacters, a tmux target, path, empty, too long) get m=2 |
| 832 | text nb1 "hv-test;ls" |
| 833 | text nb2 "=omp-queen:" |
| 834 | text nb3 "../hv-test" |
| 835 | text nb4 "hv test" |
| 836 | text nb5 "omp-queen:0.1" |
| 837 | fn gafbn n view uchar * to bool |
| 838 | s0 = gasize |
| 839 | gasett c01 |
| 840 | gaform n tline 0 |
| 841 | st = gapost 3 |
| 842 | if or ne st 302 ne galq 109 2 |
| 843 | ret false |
| 844 | end |
| 845 | ret eq gasize s0 |
| 846 | end |
| 847 | fn gafbad to bool |
| 848 | e = new uchar 1 0 |
| 849 | l = new uchar 64 97 |
| 850 | ok = gafbn nb1 |
| 851 | ok = and ok gafbn nb2 |
| 852 | ok = and ok gafbn nb3 |
| 853 | ok = and ok gafbn nb4 |
| 854 | ok = and ok gafbn nb5 |
| 855 | ok = and ok gafbn view part e 0 0 |
| 856 | ok = and ok gafbn l |
| 857 | ret ok |
| 858 | end |
| 859 | note gafdup: a repeated field, an unknown field, a field without '=', a bad percent escape |
| 860 | text db1 "&s=hv-test" |
| 861 | text db2 "&x=1" |
| 862 | text db3 "&t" |
| 863 | text db4 "&t=%zz" |
| 864 | fn gafdb t view uchar * to bool |
| 865 | s0 = gasize |
| 866 | gasett c01 |
| 867 | gaform tsessn tline 0 |
| 868 | gabt t |
| 869 | st = gapost 3 |
| 870 | if or ne st 302 ne galq 109 1 |
| 871 | ret false |
| 872 | end |
| 873 | ret eq gasize s0 |
| 874 | end |
| 875 | fn gafdup to bool |
| 876 | ok = gafdb db1 |
| 877 | ok = and ok gafdb db2 |
| 878 | ok = and ok gafdb db3 |
| 879 | ok = and ok gafdb db4 |
| 880 | ret ok |
| 881 | end |
| 882 | fn gafbig to bool |
| 883 | s0 = gasize |
| 884 | gasett c01 |
| 885 | gaform tsessn tline 0 |
| 886 | for i ulong 16400 |
| 887 | gabc 120 |
| 888 | end |
| 889 | st = gapost 3 |
| 890 | x = sleepns 300000000 |
| 891 | ret and eq st 413 eq gasize s0 |
| 892 | end |
| 893 | note gaents: an entries panel answers 200 with the whole page. With a HOME that has no QUESTIONS or |
| 894 | note DECISIONS file (a scratch server, CI) this drives the fallback that shows the last 4000 bytes. |
| 895 | fn gaents t view uchar * to bool |
| 896 | st = gaget t 1 |
| 897 | if ne st 200 |
| 898 | ret false |
| 899 | end |
| 900 | ret gahas tendh |
| 901 | end |
| 902 | note gapane: type gatx (a <script> line) again so it is on the visible screen, wait for the poller |
| 903 | note to capture it, then read the pane panel: the markup must arrive escaped |
| 904 | fn gapane to bool |
| 905 | if not gatype tline 10 |
| 906 | ret false |
| 907 | end |
| 908 | for it ulong 20 |
| 909 | x = sleepns 500000000 |
| 910 | st = gaget tpane 1 |
| 911 | if eq st 200 |
| 912 | if gahas tescs |
| 913 | ret not gahas tscr |
| 914 | end |
| 915 | end |
| 916 | end |
| 917 | ret false |
| 918 | end |
| 919 | note ---- the run mode |
| 920 | fn garun to int |
| 921 | gaxbuf |
| 922 | if not gatok |
| 923 | ret 3 |
| 924 | end |
| 925 | gachk eq gaget tphealth 0 200 thc01 |
| 926 | gachk eq gaget troot 0 403 thc02 |
| 927 | gachk eq gaget tpane 0 403 thc03 |
| 928 | gachk eq gaget troot 16 403 thc04 |
| 929 | z = new uchar 68 48 |
| 930 | for i ulong 4 |
| 931 | put z i get tqt i |
| 932 | end |
| 933 | gachk eq gareq2 z 403 thc05 |
| 934 | for i ulong 64 |
| 935 | put z add 4 i get gtok i |
| 936 | end |
| 937 | st = gareq2 z |
| 938 | gachk and eq st 302 eq get gack 0 1 thc06 |
| 939 | gachk eq gaget troot 9 400 thc07 |
| 940 | gachk eq gaget tpsend 1 405 thc08 |
| 941 | gachk gamkses thc09 |
| 942 | gachk gagetk thc10 |
| 943 | gasett c01 |
| 944 | gaform tsessn tline 0 |
| 945 | gachk eq gapost 0 403 thc11 |
| 946 | gachk eq gapost 1 403 thc12 |
| 947 | gachk eq gapost 5 403 thc13 |
| 948 | gaform tsessn tline 1 |
| 949 | gachk eq gapost 3 403 thc14 |
| 950 | gachk eq gasize 0 thc15 |
| 951 | gasett c01 |
| 952 | gachk gatype tline 10 c01 |
| 953 | gasett c02 |
| 954 | gachk gatype tline 10 c02 |
| 955 | gasett c03 |
| 956 | gachk gatype tline 10 c03 |
| 957 | gasett c04 |
| 958 | gachk gatype tline 10 c04 |
| 959 | gasett c05 |
| 960 | gachk gatype tline 10 c05 |
| 961 | gasett c06 |
| 962 | gachk gatype tline 10 c06 |
| 963 | gasett c07 |
| 964 | gachk gatype tline 10 c07 |
| 965 | gasett c08 |
| 966 | gachk gatype tline 10 c08 |
| 967 | gasett c09 |
| 968 | gachk gatype tline 10 c09 |
| 969 | gasett c10 |
| 970 | gachk gatype tline 10 c10 |
| 971 | gasett c11 |
| 972 | gachk gatype tline 10 c11 |
| 973 | gasett n01 |
| 974 | put gatx 4 92 |
| 975 | gachk gatype tline 10 thc16 |
| 976 | put gatx 0 92 |
| 977 | put gatx 1 59 |
| 978 | put gatxl 0 2 |
| 979 | gachk gatype tline 10 thc17 |
| 980 | put gatx 0 98 |
| 981 | put gatx 1 115 |
| 982 | put gatx 2 92 |
| 983 | put gatx 3 59 |
| 984 | put gatxl 0 4 |
| 985 | gachk gatype tline 10 thc18 |
| 986 | for i ulong 4096 |
| 987 | put gatx i uchar add 97 rem i 26 |
| 988 | end |
| 989 | put gatx 2047 59 |
| 990 | put gatx 4095 59 |
| 991 | put gatxl 0 4096 |
| 992 | gachk gatype tline 10 thc19 |
| 993 | put gatx 0 97 |
| 994 | for i ulong 1365 |
| 995 | put gatx add 1 mul i 3 226 |
| 996 | put gatx add 2 mul i 3 130 |
| 997 | put gatx add 3 mul i 3 172 |
| 998 | end |
| 999 | put gatxl 0 4096 |
| 1000 | gachk gatype tline 10 thc44 |
| 1001 | put gatxl 0 0 |
| 1002 | gachk gatype tenter 10 thc20 |
| 1003 | gachk gatype tescape 27 thc21 |
| 1004 | gasett tmark |
| 1005 | gachk gatype tline 10 thc22 |
| 1006 | gachk galogok thc23 |
| 1007 | gachk galogno thc24 |
| 1008 | for i ulong 4097 |
| 1009 | put gatx i 120 |
| 1010 | end |
| 1011 | put gatxl 0 4097 |
| 1012 | gachk garef tline 7 thc25 |
| 1013 | gasett c01 |
| 1014 | put gatx 2 1 |
| 1015 | gachk garef tline 4 thc26 |
| 1016 | put gatx 2 10 |
| 1017 | gachk garef tline 4 thc27 |
| 1018 | put gatx 2 127 |
| 1019 | gachk garef tline 4 thc28 |
| 1020 | put gatx 2 255 |
| 1021 | gachk garef tline 4 thc29 |
| 1022 | put gatx 1 192 |
| 1023 | put gatx 2 175 |
| 1024 | gachk garef tline 4 thc30 |
| 1025 | put gatx 2 13 |
| 1026 | gachk garef tline 4 thc31 |
| 1027 | put gatx 2 9 |
| 1028 | gachk garef tline 4 thc32 |
| 1029 | put gatx 2 27 |
| 1030 | gachk garef tline 4 thc33 |
| 1031 | gasett c01 |
| 1032 | gachk garef tbadact 3 thc34 |
| 1033 | gachk gatype tenter 10 thc45 |
| 1034 | gachk gafbad thc35 |
| 1035 | gachk gafdup thc36 |
| 1036 | gachk gafbig thc37 |
| 1037 | gasett c08 |
| 1038 | gachk gapane thc38 |
| 1039 | gachk gaents tpenq thc46 |
| 1040 | gachk gaents tpend thc47 |
| 1041 | gachk gakilss thc39 |
| 1042 | gasett c01 |
| 1043 | gachk garef tline 5 thc40 |
| 1044 | gachk not gakilss thc41 |
| 1045 | gaend |
| 1046 | ret garc |
| 1047 | end |
| 1048 | note gaend / garc: delete the sink file, print the summary; exit 0 only when nothing failed |
| 1049 | fn gaend to void |
| 1050 | gasinkp |
| 1051 | u = unlink gpth 0 get gpl 0 |
| 1052 | vwsbt tsum |
| 1053 | vwsbd get gapass 0 |
| 1054 | vwsbt tsum2 |
| 1055 | vwsbd get gafail 0 |
| 1056 | vwsbt tsum3 |
| 1057 | gaout |
| 1058 | end |
| 1059 | fn garc to int |
| 1060 | if eq get gafail 0 0 |
| 1061 | ret 0 |
| 1062 | end |
| 1063 | ret 1 |
| 1064 | end |
| 1065 | note ganolog: against a server whose HOME has no writable ~/.local/state/hive-view, a send is |
| 1066 | note refused with code 8 before anything is typed (the gate runs with that same HOME) |
| 1067 | fn ganolog to int |
| 1068 | gaxbuf |
| 1069 | if not gatok |
| 1070 | ret 3 |
| 1071 | end |
| 1072 | z = new uchar 68 48 |
| 1073 | for i ulong 4 |
| 1074 | put z i get tqt i |
| 1075 | end |
| 1076 | for i ulong 64 |
| 1077 | put z add 4 i get gtok i |
| 1078 | end |
| 1079 | st = gareq2 z |
| 1080 | gachk and eq st 302 eq get gack 0 1 thc06 |
| 1081 | gachk gamkses thc09 |
| 1082 | gachk gagetk thc10 |
| 1083 | gasett c01 |
| 1084 | gachk garef tline 8 thc42 |
| 1085 | gachk gakilss thc39 |
| 1086 | gaend |
| 1087 | ret garc |
| 1088 | end |
| 1089 | note ---- the cpu mode: utime + stime + cutime + cstime (fields 14..17 of /proc/PID/stat) |
| 1090 | fn gastat pid ulong to ulong |
| 1091 | vwpb |
| 1092 | vwpt tproc |
| 1093 | vwpd pid |
| 1094 | vwpt tstat |
| 1095 | r = vwrdall 4096 |
| 1096 | if lt r 0 |
| 1097 | ret 0 |
| 1098 | end |
| 1099 | n = get gol 0 |
| 1100 | p = ulong 0 |
| 1101 | for i ulong n |
| 1102 | if eq get gob i 41 |
| 1103 | p = i |
| 1104 | end |
| 1105 | end |
| 1106 | f = ulong 2 |
| 1107 | v = ulong 0 |
| 1108 | s = ulong 0 |
| 1109 | for i ulong sub n p |
| 1110 | c = get gob add p i |
| 1111 | if eq c 32 |
| 1112 | if and ge f 14 le f 17 |
| 1113 | s = add s v |
| 1114 | end |
| 1115 | f = add f 1 |
| 1116 | v = 0 |
| 1117 | else |
| 1118 | if vwdig c |
| 1119 | v = add mul v 10 ulong sub c 48 |
| 1120 | end |
| 1121 | end |
| 1122 | end |
| 1123 | ret s |
| 1124 | end |
| 1125 | note gatree: ticks of pid plus its direct children (the poller and the connection handlers) |
| 1126 | fn gatree pid ulong to ulong |
| 1127 | t = gastat pid |
| 1128 | vwpb |
| 1129 | vwpt tproc |
| 1130 | vwpd pid |
| 1131 | vwpt tchild |
| 1132 | vwpd pid |
| 1133 | vwpt tchild2 |
| 1134 | r = vwrdall 4096 |
| 1135 | if lt r 0 |
| 1136 | ret t |
| 1137 | end |
| 1138 | n = get gol 0 |
| 1139 | kids = new ulong 256 0 |
| 1140 | k = ulong 0 |
| 1141 | v = ulong 0 |
| 1142 | for i ulong add n 1 |
| 1143 | c = uchar 32 |
| 1144 | if lt i n |
| 1145 | c = get gob i |
| 1146 | end |
| 1147 | if vwdig c |
| 1148 | v = add mul v 10 ulong sub c 48 |
| 1149 | else |
| 1150 | if and gt v 0 lt k 256 |
| 1151 | put kids k v |
| 1152 | k = add k 1 |
| 1153 | end |
| 1154 | v = 0 |
| 1155 | end |
| 1156 | end |
| 1157 | for i ulong k |
| 1158 | t = add t gastat get kids i |
| 1159 | end |
| 1160 | ret t |
| 1161 | end |
| 1162 | fn gatmxp to ulong |
| 1163 | gatmux |
| 1164 | vwka tdisp |
| 1165 | vwka tdp |
| 1166 | vwka tpid |
| 1167 | r = vwrun 5000000000 |
| 1168 | if ne r 0 |
| 1169 | ret 0 |
| 1170 | end |
| 1171 | v = ulong 0 |
| 1172 | for i ulong get gol 0 |
| 1173 | c = get gob i |
| 1174 | if not vwdig c |
| 1175 | break |
| 1176 | end |
| 1177 | v = add mul v 10 ulong sub c 48 |
| 1178 | end |
| 1179 | ret v |
| 1180 | end |
| 1181 | fn gacpu pid ulong secs ulong to int |
| 1182 | tp = gatmxp |
| 1183 | a0 = gatree pid |
| 1184 | b0 = gastat tp |
| 1185 | x = sleepns long mul secs 1000000000 |
| 1186 | a1 = gatree pid |
| 1187 | b1 = gastat tp |
| 1188 | da = ulong 0 |
| 1189 | if gt a1 a0 |
| 1190 | da = sub a1 a0 |
| 1191 | end |
| 1192 | db = ulong 0 |
| 1193 | if gt b1 b0 |
| 1194 | db = sub b1 b0 |
| 1195 | end |
| 1196 | vwsbt tcpu1 |
| 1197 | vwsbd da |
| 1198 | vwsbt tcpu2 |
| 1199 | vwsbd db |
| 1200 | vwsbt tcpu3 |
| 1201 | vwsbd secs |
| 1202 | vwsbt tcpu4 |
| 1203 | gaout |
| 1204 | ret 0 |
| 1205 | end |
| 1206 | text trun "run" |
| 1207 | text tcpu "cpu" |
| 1208 | text tnolog "nolog" |
| 1209 | fn main to int |
| 1210 | if not gahome |
| 1211 | ret 6 |
| 1212 | end |
| 1213 | ab = new uchar 512 0 |
| 1214 | n = argread 1 ab 0 512 |
| 1215 | if lt argcnt 3 |
| 1216 | ret 2 |
| 1217 | end |
| 1218 | if heq view part ab 0 ulong hmin ulong n 512 trun |
| 1219 | m = argread 2 ab 0 512 |
| 1220 | put gaport 0 gadec view part ab 0 ulong m |
| 1221 | ret garun |
| 1222 | end |
| 1223 | if heq view part ab 0 ulong hmin ulong n 512 tcpu |
| 1224 | if lt argcnt 4 |
| 1225 | ret 2 |
| 1226 | end |
| 1227 | m = argread 2 ab 0 512 |
| 1228 | pid = gadec view part ab 0 ulong m |
| 1229 | m = argread 3 ab 0 512 |
| 1230 | secs = gadec view part ab 0 ulong m |
| 1231 | ret gacpu pid secs |
| 1232 | end |
| 1233 | if heq view part ab 0 ulong hmin ulong n 512 tnolog |
| 1234 | m = argread 2 ab 0 512 |
| 1235 | put gaport 0 gadec view part ab 0 ulong m |
| 1236 | ret ganolog |
| 1237 | end |
| 1238 | ret 2 |
| 1239 | end |