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 / apps / core / test.om

223 lines · 5468 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note apps/core/test.om: positive & negative control test suite for
3note aienos.com site/CSP/consent verifier and interplane-forge/hop core validators.
4note Compose with:
5note si/directives/om2.om om/tls/sha2.om apps/core/site_forge.om apps/core/test.om
6
7text t_pass "PASS "
8text t_fail "FAIL "
9text t_nl "\n"
10
11text t_c1 "aienos_csp_header_validation_and_unsafe_controls"
12text t_c2 "aienos_route_sanitization_and_traversal_controls"
13text t_c3 "aienos_consent_and_dnt_fail_closed_controls"
14text t_c4 "forge_git_ref_validation_and_flag_injection_controls"
15text t_c5 "forge_archive_extension_allowlist_controls"
16text t_c6 "hop_frame_kind_cap_and_sequence_controls"
17text t_c7 "app_manifest_digest_determinism_and_sensitivity"
18text t_done "PASS apps-site-forge-hop all 7 test suites passed\n"
19
20text t_csp_ok "default-src 'self'; script-src 'self'; style-src 'self'; object-src 'none'"
21text t_csp_nodef "script-src 'self'; object-src 'none'"
22text t_csp_ui "default-src 'self'; script-src 'unsafe-inline'"
23text t_csp_ue "default-src 'self'; script-src 'unsafe-eval'"
24text t_csp_star "default-src 'self'; img-src *"
25text t_csp_http "default-src 'self'; img-src http://example.com"
26
27text t_rt_ok "/docs/omega/index.html"
28text t_rt_ok2 "/evidence"
29text t_rt_trav "/docs/../etc/passwd"
30text t_rt_dbl "/docs//index.html"
31text t_rt_hid "/.env"
32text t_rt_pct "/docs/%2e%2e/secret"
33text t_rt_rel "docs/index.html"
34
35text t_ref_ok "main"
36text t_ref_ok2 "releases/v1.0-alpha"
37text t_ref_dash "--upload-pack=evil"
38text t_ref_trav "refs/heads/a..b"
39text t_ref_lock "refs/heads/main.lock"
40text t_ref_space "bad ref"
41text t_ref_tilde "HEAD~1"
42
43text t_ext_tgz ".tar.gz"
44text t_ext_zip ".zip"
45text t_ext_rar ".rar"
46text t_ext_sh ".sh"
47
48fn report_case name view uchar * ok bool to int
49if ok
50w1 = app_write_all int 1 t_pass
51w2 = app_write_all int 1 name
52w3 = app_write_all int 1 t_nl
53if and w1 and w2 w3
54ret int 0
55end
56ret int 1
57end
58w4 = app_write_all int 1 t_fail
59w5 = app_write_all int 1 name
60w6 = app_write_all int 1 t_nl
61if and w4 and w5 w6
62ret int 1
63end
64ret int 1
65end
66
67fn test_csp to bool
68if ne app_validate_csp t_csp_ok APP_OK
69ret false
70end
71if ne app_validate_csp t_csp_nodef APP_ERR_CSP_MISSING_DEFAULT
72ret false
73end
74if ne app_validate_csp t_csp_ui APP_ERR_CSP_UNSAFE
75ret false
76end
77if ne app_validate_csp t_csp_ue APP_ERR_CSP_UNSAFE
78ret false
79end
80if ne app_validate_csp t_csp_star APP_ERR_CSP_UNSAFE
81ret false
82end
83if ne app_validate_csp t_csp_http APP_ERR_CSP_UNSAFE
84ret false
85end
86ret true
87end
88
89fn test_routes to bool
90if ne app_validate_route t_rt_ok APP_OK
91ret false
92end
93if ne app_validate_route t_rt_ok2 APP_OK
94ret false
95end
96if ne app_validate_route t_rt_trav APP_ERR_BAD_ROUTE
97ret false
98end
99if ne app_validate_route t_rt_dbl APP_ERR_BAD_ROUTE
100ret false
101end
102if ne app_validate_route t_rt_hid APP_ERR_BAD_ROUTE
103ret false
104end
105if ne app_validate_route t_rt_pct APP_ERR_BAD_ROUTE
106ret false
107end
108if ne app_validate_route t_rt_rel APP_ERR_BAD_ROUTE
109ret false
110end
111ret true
112end
113
114fn test_consent to bool
115if ne app_check_consent false false true APP_OK
116ret false
117end
118if ne app_check_consent true true false APP_OK
119ret false
120end
121note Negative controls: analytics without consent, or analytics with DNT=1
122if ne app_check_consent true false false APP_ERR_CONSENT_VIOLATION
123ret false
124end
125if ne app_check_consent true true true APP_ERR_CONSENT_VIOLATION
126ret false
127end
128ret true
129end
130
131fn test_forge_refs to bool
132if ne forge_validate_ref t_ref_ok APP_OK
133ret false
134end
135if ne forge_validate_ref t_ref_ok2 APP_OK
136ret false
137end
138if ne forge_validate_ref t_ref_dash APP_ERR_BAD_REF
139ret false
140end
141if ne forge_validate_ref t_ref_trav APP_ERR_BAD_REF
142ret false
143end
144if ne forge_validate_ref t_ref_lock APP_ERR_BAD_REF
145ret false
146end
147if ne forge_validate_ref t_ref_space APP_ERR_BAD_REF
148ret false
149end
150if ne forge_validate_ref t_ref_tilde APP_ERR_BAD_REF
151ret false
152end
153ret true
154end
155
156fn test_forge_exts to bool
157if ne forge_validate_ext t_ext_tgz APP_OK
158ret false
159end
160if ne forge_validate_ext t_ext_zip APP_OK
161ret false
162end
163if ne forge_validate_ext t_ext_rar APP_ERR_BAD_EXT
164ret false
165end
166if ne forge_validate_ext t_ext_sh APP_ERR_BAD_EXT
167ret false
168end
169ret true
170end
171
172fn test_hop_frames to bool
173if ne hop_validate_frame HOP_KIND_DATA ulong 1024 ulong 4096 ulong 1 ulong 2 APP_OK
174ret false
175end
176if ne hop_validate_frame ulong 0 ulong 10 ulong 4096 ulong 1 ulong 2 APP_ERR_FRAME_KIND
177ret false
178end
179if ne hop_validate_frame HOP_KIND_DATA ulong 4097 ulong 4096 ulong 1 ulong 2 APP_ERR_FRAME_CAP
180ret false
181end
182if ne hop_validate_frame HOP_KIND_DATA ulong 10 ulong 4096 ulong 5 ulong 5 APP_ERR_FRAME_SEQ
183ret false
184end
185if ne hop_validate_frame HOP_KIND_DATA ulong 10 ulong 4096 ulong 5 ulong 4 APP_ERR_FRAME_SEQ
186ret false
187end
188ret true
189end
190
191fn test_manifest_digest to bool
192d1 = new uchar 32 0
193d2 = new uchar 32 0
194app_manifest_digest t_rt_ok t_csp_ok d1
195app_manifest_digest t_rt_ok t_csp_ok d2
196if not app_digest_eq d1 d2
197ret false
198end
199app_manifest_digest t_rt_ok2 t_csp_ok d2
200if app_digest_eq d1 d2
201ret false
202end
203ret true
204end
205
206fn main to int
207fail = int 0
208fail = add fail report_case t_c1 test_csp
209fail = add fail report_case t_c2 test_routes
210fail = add fail report_case t_c3 test_consent
211fail = add fail report_case t_c4 test_forge_refs
212fail = add fail report_case t_c5 test_forge_exts
213fail = add fail report_case t_c6 test_hop_frames
214fail = add fail report_case t_c7 test_manifest_digest
215if ne fail int 0
216ret int 1
217end
218ok = app_write_all int 1 t_done
219if not ok
220ret int 1
221end
222ret int 0
223end