code wiki / (root) / nx_site_prepare_gate_t198.nx

nx_site_prepare_gate_t198.nx source

↩ module page · 30 lines · 2021 B

1import "nx_site_publish_prepare_t198.nx" 2import "nx_gate_verdict.nx" 3func pp_test(site:*u8,rel:*u8)->i64{ 4 let av:*i64=sys_mmap(5*8) as *i64 5 av[0]="nx_site_publish" as i64;av[1]="prepare-path" as i64;av[2]=site as i64;av[3]=rel as i64;av[4]=0 6 let rc:i64=sp_main(4,av);sys_munmap(av as *u8,5*8);return rc 7} 8func main()->i64{ 9 if sys_mkdir("/tmp/nishi-publish-prepare-t198",0x1ed)!=0{return 2} 10 if sys_chdir("/tmp/nishi-publish-prepare-t198")!=0{return 2} 11 sys_mkdir("sites",0x1ed);sys_mkdir("sites/test",0x1ed);sys_mkdir("knowledge",0x1ed) 12 let conf:*u8="test\tsites/test\tknowledge/pub-\thttps://test.invalid\tTest\t\n" 13 if fsx_write("knowledge/pub_sites.conf",conf,vw_slen(conf))<0{return 2} 14 let rows:*u8="1\tAlpha\tengine\tdraft\tAlpha\talpha/beach/index.html\tFixture\n2\tBlocked\tengine\tdraft\tAlpha\tblocked/view/index.html\tFixture\n" 15 if sts_seed("knowledge/pub-",rows,vw_slen(rows))<0{return 2} 16 let c:*i64=gv_ctr() 17 gv_check("registered nested preparation",pp_test("test","alpha/beach/index.html")==0,c) 18 let fd:i64=sys_openat_directory("sites/test/alpha/beach") 19 gv_check("actual directory exists",fd>=0,c);if fd>=0{sys_close(fd)} 20 gv_check("repeat preparation idempotent",pp_test("test","alpha/beach/index.html")==0,c) 21 gv_check("unknown site refused",pp_test("unknown","alpha/beach/index.html")==FSX_RC_DENIED,c) 22 gv_check("unregistered target refused",pp_test("test","unregistered/index.html")==FSX_RC_DENIED,c) 23 gv_check("parent traversal refused",pp_test("test","../escape/index.html")==FSX_RC_DENIED,c) 24 gv_check("absolute target refused",pp_test("test","/escape/index.html")==FSX_RC_DENIED,c) 25 fsx_write("sites/test/blocked","file",4) 26 gv_check("file in directory chain refused",pp_test("test","blocked/view/index.html")==FSX_RC_IO,c) 27 let f:i64=sys_openat_rd("sites/test/alpha/beach/index.html") 28 gv_check("preparation never publishes content",f==(0-2),c);if f>=0{sys_close(f)} 29 return gv_verdict("publish-prepare" as *u8,c,"registered path provisioning only; publication remains guarded" as *u8) 30}