interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / si / packages / homebrew / test.om

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