Extend network stack: session/auth, WebSocket, cookie/multipart primitives
Add the network-extension wave to lib/net and the web ABI plugin:
- lib/net cookie_parse / multipart_parse host primitives (EN/ZH)
- plugins/web session store + /admin login gate + WebSocket client/server
- ext/web author surface (EN/ZH) for session, auth, ws
- form update flow and page-level validation echo tests
- fix string escapes: \xHH, \u{...}, unknown escapes kept verbatim
- map Chinese component slots (导航/侧栏/页脚) so sidebar renders
- resolve relative static/db paths against the entry script dir (entry_dir)
- new tutorial chapter 14, EN/ZH example sites, and gold tests
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
7dfa161422
commit
7645dd4c1f
47 files changed
+3380
-75
No files matched your search
@@ -84,3 +84,10 @@ import json:lib/json.mq.md
|
||||
> print text=required-should-fail
|
||||
2. *
|
||||
> print text=required-ok
|
||||
|
||||
*errs = > json.get value=`bad` key="errors"*
|
||||
*nerr = > len value=`errs`*
|
||||
1. `nerr` >= 1
|
||||
> print text=errors-echoed-ok
|
||||
2. *
|
||||
> print text=errors-echoed-fail
|
||||
@@ -0,0 +1,39 @@
|
||||
---
|
||||
title: web entry-dir relative path smoke
|
||||
description: Relative db path resolves against the entry script dir, not cwd.
|
||||
import web:ext/web/web.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
<!--
|
||||
Run from a different cwd than the script dir (e.g. repo root):
|
||||
the sqlite file must land under <script dir>/entrydir-fixtures/data,
|
||||
NOT under the process cwd.
|
||||
-->
|
||||
|
||||
*store = > web.db url="sqlite:entrydir-fixtures/data/entrydir.db"*
|
||||
|
||||
`schema` =
|
||||
|
||||
| 字段 | 类型 |
|
||||
|------|------|
|
||||
| title | text |
|
||||
|
||||
> `store`.init name=items fields=`schema`
|
||||
|
||||
`one` =
|
||||
|
||||
| 行 | title |
|
||||
|----|-------|
|
||||
| 1 | hello |
|
||||
|
||||
> `store`.insert table=items rows=`one`
|
||||
|
||||
*rows = > `store`.select table="items" limit=10*
|
||||
*n = > len value=`rows`*
|
||||
|
||||
1. `n` == 1
|
||||
> print text=entrydir-db-ok
|
||||
2. *
|
||||
> print text=entrydir-db-fail
|
||||
@@ -0,0 +1,148 @@
|
||||
---
|
||||
title: web network-extension smoke
|
||||
description: Session/auth/ws ABI primitives (offline).
|
||||
import web:ext/web/web.mq.md
|
||||
import plugin:lib/plugin.mq.md
|
||||
import sys:lib/sys.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
<!-- load web plugin so ABI primitives are registered -->
|
||||
|
||||
*p = > plugin.native_path name="web"*
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
2. *
|
||||
> sys.exit code=1
|
||||
|
||||
<!-- admin users table (row-oriented records) -->
|
||||
|
||||
`users` =
|
||||
|
||||
| 行 | 用户 | 密码 |
|
||||
|----|------|------|
|
||||
| 1 | admin | secret |
|
||||
| 2 | 站长 | pw123 |
|
||||
|
||||
<!-- session CRUD -->
|
||||
|
||||
*sess = > web_session_new ttl_sec=120*
|
||||
*sid = sess[^id]*
|
||||
1. `sid` != ""
|
||||
> print text=session-new-ok
|
||||
2. *
|
||||
> print text=session-new-fail
|
||||
|
||||
*set1 = > web_session_set id=`sid` key="theme" value="dark"*
|
||||
*ok1 = set1[^ok]*
|
||||
1. `ok1`
|
||||
> print text=session-set-ok
|
||||
2. *
|
||||
> print text=session-set-fail
|
||||
|
||||
*get1 = > web_session_get id=`sid` key="theme"*
|
||||
*v1 = get1[^value]*
|
||||
1. `v1` == "dark"
|
||||
> print text=session-get-ok
|
||||
2. *
|
||||
> print text=session-get-fail
|
||||
|
||||
*del1 = > web_session_del id=`sid` key="theme"*
|
||||
*ok2 = del1[^ok]*
|
||||
1. `ok2`
|
||||
> print text=session-del-ok
|
||||
2. *
|
||||
> print text=session-del-fail
|
||||
|
||||
*get2 = > web_session_get id=`sid` key="theme"*
|
||||
*ok3 = get2[^ok]*
|
||||
1. `ok3`
|
||||
> print text=session-del-confirm-fail
|
||||
2. *
|
||||
> print text=session-del-confirm
|
||||
|
||||
<!-- auth login/check/logout -->
|
||||
|
||||
*login = > web_auth_login username="admin" password="secret" users=`users` session_ttl=120*
|
||||
*lok = login[^ok]*
|
||||
1. `lok`
|
||||
> print text=auth-login-ok
|
||||
2. *
|
||||
> print text=auth-login-fail
|
||||
|
||||
*sid2 = login[^session_id]*
|
||||
*check = > web_auth_check session_id=`sid2`*
|
||||
*cok = check[^ok]*
|
||||
1. `cok`
|
||||
> print text=auth-check-ok
|
||||
2. *
|
||||
> print text=auth-check-fail
|
||||
|
||||
*badlogin = > web_auth_login username="admin" password="wrong" users=`users` session_ttl=120*
|
||||
*bok = badlogin[^ok]*
|
||||
1. `bok`
|
||||
> print text=auth-bad-should-fail
|
||||
2. *
|
||||
> print text=auth-bad-ok
|
||||
|
||||
*zhlogin = > web_auth_login username="站长" password="pw123" users=`users` session_ttl=120*
|
||||
*zhok = zhlogin[^ok]*
|
||||
1. `zhok`
|
||||
> print text=auth-zh-ok
|
||||
2. *
|
||||
> print text=auth-zh-fail
|
||||
|
||||
*logout = > web_auth_logout session_id=`sid2`*
|
||||
*dok = logout[^ok]*
|
||||
1. `dok`
|
||||
> print text=auth-logout-ok
|
||||
2. *
|
||||
> print text=auth-logout-fail
|
||||
|
||||
*check2 = > web_auth_check session_id=`sid2`*
|
||||
*cok2 = check2[^ok]*
|
||||
1. `cok2`
|
||||
> print text=auth-logout-confirm-fail
|
||||
2. *
|
||||
> print text=auth-logout-confirm
|
||||
|
||||
<!-- route ws + app auth (offline) -->
|
||||
|
||||
*pg = > web.page title="ws-test"*
|
||||
*app = > web.app page=`pg` admin=True*
|
||||
*app = > `app`.route_ws path="/live" echo=True*
|
||||
*routes = app[^ws_routes]*
|
||||
*has_live = routes[^/live]*
|
||||
1. `has_live`
|
||||
> print text=ws-route-ok
|
||||
2. *
|
||||
> print text=ws-route-fail
|
||||
|
||||
*app = > `app`.auth users=`users` session_ttl=120*
|
||||
*authobj = app[^auth]*
|
||||
*ausers = authobj[^users]*
|
||||
*au1 = ausers[^1][^用户]*
|
||||
*ou1 = users[^1][^用户]*
|
||||
1. `au1` == `ou1`
|
||||
> print text=app-auth-ok
|
||||
2. *
|
||||
> print text=app-auth-fail
|
||||
|
||||
<!-- via ext/web author surface -->
|
||||
|
||||
*authz = > web.auth users=`users` session_ttl=120*
|
||||
*login2 = > `authz`.login username="admin" password="secret"*
|
||||
*lok2 = login2[^ok]*
|
||||
1. `lok2`
|
||||
> print text=ext-auth-ok
|
||||
2. *
|
||||
> print text=ext-auth-fail
|
||||
|
||||
*ws = > web.ws timeout_sec=1*
|
||||
*badurl = > `ws`.connect url="ws://127.0.0.1:1" message="hi"*
|
||||
*bwok = badurl[^ok]*
|
||||
1. `bwok`
|
||||
> print text=ws-connect-should-fail
|
||||
2. *
|
||||
> print text=ws-connect-error-ok
|
||||
Reference in new issue
Block a user