fix(fallback): DDL 前置守卫跑在 ServeDir 之前,README 与代码对齐
- src/routes/fallback.rs: spa_fallback 返回 Router 并挂 from_fn(ddl_guard) 前置守卫(axum 0.8.9 的 Router::layer 同时包住 fallback_router 与 catch_all_fallback ⇒ 守卫必然先于 ServeDir);决策层的 DDL 判定移除(死代码), is_api_path/is_ddl_path 统一改用 percent-decode 之后的路径 - src/main.rs: 注释改成事实——真正的守卫是 ddl_guard,不是那条字面路由 - tests/spa_fallback.rs: 新增 ddl_in_web_root_is_still_not_downloadable (临时 web root 里放 migrate.sql ⇒ 仍须 404 + JSON 且不含 CREATE TABLE), 并在既有用例里追加 /api%2Ffoo ⇒ 404 JSON、/apifoo ⇒ 不被误吞 - README.md: 删虚构的「契约网关」与「6 条脱敏规则 + 默认环境空间」, 换成真实的 30 张表,并把已删除的旧控制台生命周期能力改成现状说明 (动作端点属后续分期、尚未实现 ⇒ 前端点这些按钮会 404) Co-Authored-By: Claude Code <[email protected]>
This commit is contained in:
1 parent
e72345a958
commit
1af08c1db7
4 files changed
+169
-37
No files matched your search
@@ -3,7 +3,7 @@
|
||||
把 `ssw-mvp/boot/ssw-tdc`(Spring Boot / JNPF 重底座的「数据接入连接器」子系统)重做成
|
||||
**本地优先、零外部服务**的 MVP:
|
||||
|
||||
- **Rust (axum)** —— 控制面 + 数据面 + 静态托管 + 契约网关
|
||||
- **Rust (axum)** —— 控制面 + 数据面 + 静态托管
|
||||
- **上游(Java/Vue)完整前端的构建产物** —— 托管在 `static/`,**零自研前端、零构建步骤**
|
||||
- **PGlite(pglite-rs,进程内原生 PostgreSQL)** —— 内嵌在 Rust 进程里,承载全部 `tdc_*` 业务数据,
|
||||
数据落在 `data/tdc.pg/`(磁盘持久化,非浏览器 WASM/IndexedDB)
|
||||
@@ -14,8 +14,9 @@
|
||||
> 前端只发 REST 请求,不直接持有数据库。
|
||||
|
||||
> 红线:原 TDC 与 TDS **只走 HTTP 契约、不编译期耦合**。
|
||||
> 本实现**不代理** TDS(TDS 侧出向客户端属后续任务);前端登录走 JNPF 门户账号
|
||||
> (`POST /api/oauth/Login`),该端点属后续任务。
|
||||
> 本实现**不代理** TDS(TDS 侧出向客户端属后续任务)。
|
||||
> 🔴 上游前端登录走 JNPF 门户账号(`POST /api/oauth/Login`)——**该端点本仓尚未实现**
|
||||
> (属后续任务)⇒ 现在登录请用 `/api/ssw/tdc/Auth/Login`。
|
||||
|
||||
## 运行
|
||||
|
||||
@@ -27,7 +28,7 @@ PORT=30000 ./target/debug/tdc-connector
|
||||
```
|
||||
|
||||
- 启动即初始化:Rust 进程内 `PGlite::open(data/tdc.pg)`,若 `tdc_identity` 不存在则执行
|
||||
内嵌的 `schema/migrate.sql`(`include_str!` 进二进制,30 张表 + 6 条内置脱敏规则 + 默认开发环境空间)。
|
||||
内嵌的 `schema/migrate.sql`(`include_str!` 进二进制,**30 张表**,上游 `tdc_*` schema 的生成产物)。
|
||||
- 数据全部落在 Rust 进程内嵌库;控制台(上游 SPA)通过 `/api/ssw/tdc/*` 读写。
|
||||
- schema DDL 在 `schema/migrate.sql`(**编译期内嵌**,**刻意不在 web root**)⇒ 不可从 HTTP 下载。
|
||||
|
||||
@@ -86,20 +87,29 @@ sccache 0.18 经 `~/.cargo/config.toml` 的 `[build] rustc-wrapper` + `[env] SCC
|
||||
## 已实现范围
|
||||
|
||||
**30 张表**(上游 `tdc_*` schema 的生成产物,含 9 系统列 / 逻辑删除 / partial 唯一索引):
|
||||
身份、数据源、资源、资源字段、脱敏规则、产品、需求、订单、合约、使用控制策略、
|
||||
策略校验记录、API 交付服务、交付任务、交付日志、TDS 同步日志、审计日志、环境空间、成员、机密文件。
|
||||
|
||||
**控制台能力**(schema 自省驱动的通用 CRUD + 按表生命周期操作):
|
||||
| 域 | 表 |
|
||||
|---|---|
|
||||
| 身份 / 凭据 | `tdc_identity`、`tdc_credential`、`tdc_p2p_session` |
|
||||
| 数据源 / 接口 | `tdc_datasource`、`tdc_data_interface`、`tdc_data_interface_field`、`tdc_data_interface_param` |
|
||||
| 资源 / 脱敏 | `tdc_resource`、`tdc_resource_field`、`tdc_resource_mask_rule` |
|
||||
| 目录 / 交易 | `tdc_product`、`tdc_order`、`tdc_contract` |
|
||||
| 策略 | `tdc_policy`、`tdc_policy_template`、`tdc_policy_check_log` |
|
||||
| 交付 | `tdc_delivery_task`、`tdc_delivery_task_participant`、`tdc_delivery_log`、`tdc_delivery_outbox` |
|
||||
| 执行 / 销毁 | `tdc_privacy_exec_run`、`tdc_sandbox_exec_run`、`tdc_destroy_log` |
|
||||
| 日志 / 通知 | `tdc_audit_log`、`tdc_api_consume_log`、`tdc_sync_log`、`tdc_notify` |
|
||||
| 上游示例 | `tdc_demo_car_insurance`、`tdc_demo_insurance_claims`、`tdc_demo_pii` |
|
||||
|
||||
- 通用:新建 / 编辑 / 逻辑删除 / 搜索(所有表)
|
||||
- 数据源:测试连接、同步资源
|
||||
- 资源:启用 / 停用
|
||||
- 产品:发布 / 下架 / 提交审核
|
||||
- 需求:发布 / 关闭
|
||||
- 订单:通过 / 驳回 / 签署
|
||||
- 合约:生效 / 终止
|
||||
- 交付任务:策略校验(写 `tdc_policy_check_log`)/ 完成 / 取消 / 销毁(留证写 `tdc_delivery_log`)
|
||||
- 身份(Rust 侧):登录 / 会话 / 空间列表
|
||||
**控制台能力**(**当前只实现通用 CRUD 与聚合详情**):
|
||||
|
||||
- 18 个实体的通用 CRUD:`列表` / `新建` / `详情` / `修改` / `逻辑删除` / `/All`(不分页全量)
|
||||
- 2 个聚合详情:`/api/ssw/tdc/Resource/{id}/Detail`、`/api/ssw/tdc/Dataset/{id}/Detail`
|
||||
- 4 个 `Auth` 端点:`Auth/Login`、`Auth/Me`、`Auth/Spaces`、`Auth/SsoConfig`
|
||||
- `GET /api/health`
|
||||
|
||||
> 🔴 **上游那 100+ 个「动作端点」(发布 / 下架 / 提交审核 / 通过 / 驳回 / 签署 / 生效 / 终止 /
|
||||
> 策略校验 / 测试连接 / 同步资源 / 启用停用 / 完成 / 取消 / 销毁 …)属后续分期,尚未实现**
|
||||
> ⇒ 前端点到这些按钮会 **404**。本仓**不提供**这些动作端点的占位实现。
|
||||
|
||||
## 明确不在 MVP 内(原 `ssw-tdc` 的隐私计算作业)
|
||||
|
||||
|
||||
+5
-2
@@ -143,11 +143,14 @@ async fn main() {
|
||||
// ② `schema/migrate.sql` 是编译期内嵌的 schema 唯一来源(99 KB 全量 DDL)
|
||||
// ⇒ **绝不能**从 HTTP 下载(上游部署里 DDL 不在 web root)。
|
||||
// 🔴 该文件**已移出 web root**(现在在 `schema/`)⇒ ServeDir 根本读不到它;
|
||||
// 这里再显式注册一条路由是**纵深防御**:万一有人日后把它放回 `static/`,
|
||||
// 这个字面路径也回不去。
|
||||
// 这条字面路由只是**额外**兜住这个字面路径。
|
||||
// 🔴 **真正的守卫**是 `routes::fallback::ddl_guard`(**跑在 `ServeDir` 之前**
|
||||
// 的前置中间件)⇒ 即便 DDL 文件被放回 `static/`,也**下不到**
|
||||
// (大小写 / `%2E` / 尾斜杠 / 双斜杠等变体一律拦)。
|
||||
.route("/migrate.sql", any(api_not_found))
|
||||
// ③ 静态托管挂**根**(vite base 是 `/`,产物引用 `/assets/...`)
|
||||
// 兜底服务(`routes::fallback::spa_fallback`):
|
||||
// - **前置守卫** `ddl_guard` ⇒ DDL 文件名一律 404 + JSON(先于 ServeDir)
|
||||
// - 命中 `static/` 里的真实文件 ⇒ 直接出(`/assets/*.js`、`/logo.png` …)
|
||||
// - `/api`、`/api/`、`/api/**` ⇒ 404 + JSON(**不是** SPA 的 HTML)
|
||||
// - 其余(`/tdc/home`、`/login` 等 SPA 深链)⇒ 200 + `index.html`
|
||||
|
||||
+62
-17
@@ -8,25 +8,35 @@
|
||||
//! | 请求路径 | 响应 |
|
||||
//! |---|---|
|
||||
//! | `/api`、`/api/`、`/api/**` | **404 + JSON**(`api_not_found()`) |
|
||||
//! | schema DDL 文件名(`migrate.sql` 及其大小写 / `%2E` / 尾斜杠 / 双斜杠变体) | **404 + JSON** |
|
||||
//! | schema DDL 文件名(`migrate.sql` 及其大小写 / `%2E` / 尾斜杠 / 双斜杠变体) | **404 + JSON**(**前置守卫** `ddl_guard`) |
|
||||
//! | 其余(`/tdc/home`、`/login` 等 SPA 深链) | **200 + `text/html`**(`static/index.html`) |
|
||||
//! | 命中 `static/` 里的真实文件(`/assets/*.js`、`/logo.png` …) | 由 `ServeDir` 直接出 |
|
||||
//!
|
||||
//! ## 为什么 DDL 要单独判
|
||||
//!
|
||||
//! 🔴 `static/migrate.sql` **已被移出 web root**(现在在 `schema/`,编译期 `include_str!` 内嵌),
|
||||
//! 所以 `ServeDir` 根本读不到它 ⇒ 「文件不在 web root」才是根因修复。
|
||||
//! 这里的判定是**纵深防御**:即便有人日后把 DDL 放回 `static/`,
|
||||
//! 也**不会**被任何路径变体(大小写 / `%2E` / 尾斜杠 / 双斜杠)下载走。
|
||||
//! 🔴 **根因修复**:DDL 文件**已移出 web root**(现在在 `schema/`,编译期 `include_str!` 内嵌),
|
||||
//! 所以 `ServeDir` 根本读不到它。
|
||||
//! 🔴 **第二道(前置守卫)**:`ddl_guard` 是**跑在 `ServeDir` 之前**的中间件
|
||||
//! (`Router::layer` 在 axum 0.8.9 会同时包住 `fallback_router` 与 `catch_all_fallback`
|
||||
//! ⇒ 守卫必然先于 `ServeDir` 执行)——它**独立于文件位置**:
|
||||
//! 即便 DDL 被放回 `static/`,也**下不到**(任何路径变体都拦)。
|
||||
//!
|
||||
//! ## 为什么 `/api` 用「精确前缀」而不是裸 `starts_with`
|
||||
//!
|
||||
//! `/apifoo` 这类**非** `/api` 命名空间的 SPA 深链仍应回 `index.html`(前端路由接管),
|
||||
//! 不能被误吞成 404 JSON。
|
||||
//!
|
||||
//! ## 路径判定口径(守卫与决策层**必须一致**)
|
||||
//!
|
||||
//! 两处都先 **percent-decode** 再判定:
|
||||
//! - `/api%2Ffoo` 解码后是 `/api/foo` ⇒ 落在 `/api` 命名空间 ⇒ **404 JSON**;
|
||||
//! - `/apifoo` 解码后仍是 `/apifoo` ⇒ **不被误吞**(回 SPA HTML)。
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use axum::extract::Request;
|
||||
use axum::http::{header, StatusCode, Uri};
|
||||
use axum::middleware::Next;
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use axum::routing::any;
|
||||
use axum::Router;
|
||||
@@ -57,11 +67,16 @@ pub async fn api_not_found() -> Response {
|
||||
/// 兜底服务:`ServeDir`(出 `static/` 里的真实文件)+ **找不到文件时**的决策层。
|
||||
///
|
||||
/// 决策层是一个内层 `Router<()>`(`Router` 本身就是 `Service`,可直接当 `ServeDir` 的 fallback):
|
||||
/// `/api` 命名空间与 DDL 文件名 ⇒ 404 JSON;其余 ⇒ `static/index.html`(200 `text/html`)。
|
||||
/// `/api` 命名空间 ⇒ 404 JSON;其余 ⇒ `static/index.html`(200 `text/html`)。
|
||||
///
|
||||
/// 🔴 返回的是 `Router`(不是 `ServeDir`)——因为 **DDL 前置守卫 `ddl_guard` 必须跑在
|
||||
/// `ServeDir` 之前**:`axum 0.8.9` 的 `Router::layer` 会同时包住 `fallback_router`
|
||||
/// 与 `catch_all_fallback`(`axum-0.8.9/src/routing/mod.rs:303-317`)
|
||||
/// ⇒ 守卫必然先于 `ServeDir` 执行 ⇒ DDL 即便被放回 web root 也**下不到**。
|
||||
///
|
||||
/// ⚠️ 为什么不用 `tower::service_fn`:`tower` 只是 **dev-dependency**,
|
||||
/// **lib 代码里不许用** `tower::service_fn` / `ServiceExt` ⇒ 用 axum 自己的 `any(handler)`。
|
||||
pub fn spa_fallback(static_dir: impl Into<PathBuf>) -> ServeDir<Router> {
|
||||
pub fn spa_fallback(static_dir: impl Into<PathBuf>) -> Router {
|
||||
let static_dir = static_dir.into();
|
||||
let index_file = static_dir.join("index.html");
|
||||
// 内层 Router:把「找不到文件」的决策交给 handler(`Router<()>` ⇒ 状态类型被钉死为 `()`)。
|
||||
@@ -69,13 +84,30 @@ pub fn spa_fallback(static_dir: impl Into<PathBuf>) -> ServeDir<Router> {
|
||||
let index_file = index_file.clone();
|
||||
async move { fallback_response(&index_file, &uri).await }
|
||||
}));
|
||||
ServeDir::new(&static_dir).fallback(decision)
|
||||
Router::new()
|
||||
.fallback_service(ServeDir::new(&static_dir).fallback(decision))
|
||||
.layer(axum::middleware::from_fn(ddl_guard))
|
||||
}
|
||||
|
||||
/// 兜底决策:`/api` 命名空间 / DDL ⇒ 404 JSON;否则 ⇒ `index.html`。
|
||||
/// 🔴 **DDL 前置守卫**:路径的**最后一段**是 DDL 文件名 ⇒ 404 + JSON。
|
||||
///
|
||||
/// 🔴 **跑在 `ServeDir` 之前**(见 `spa_fallback` 的说明)——它**独立于文件位置**:
|
||||
/// 即便 DDL 被放回 web root,`ServeDir` 也**没机会**把它读出来。
|
||||
///
|
||||
/// 判定用的是 **percent-decode 之后**的路径(与决策层同一口径):
|
||||
/// 大小写变体、`%2E`、`%2F`、尾斜杠、双斜杠一律拦得住。
|
||||
pub async fn ddl_guard(request: Request, next: Next) -> Response {
|
||||
if is_ddl_path(&decoded_path(request.uri().path())) {
|
||||
return api_not_found().await;
|
||||
}
|
||||
next.run(request).await
|
||||
}
|
||||
|
||||
/// 兜底决策:`/api` 命名空间 ⇒ 404 JSON;否则 ⇒ `index.html`。
|
||||
///
|
||||
/// ⚠️ DDL 判定**不在这里**(已由前置守卫 `ddl_guard` 拦在 `ServeDir` 之前 ⇒ 此处再判是死代码)。
|
||||
async fn fallback_response(index_file: &Path, uri: &Uri) -> Response {
|
||||
let path = uri.path();
|
||||
if is_api_path(path) || is_ddl_path(path) {
|
||||
if is_api_path(&decoded_path(uri.path())) {
|
||||
return api_not_found().await;
|
||||
}
|
||||
// SPA 深链 ⇒ 回 index.html(前端路由接管)。
|
||||
@@ -94,15 +126,28 @@ async fn fallback_response(index_file: &Path, uri: &Uri) -> Response {
|
||||
///
|
||||
/// 🔴 用 `== "/api" || starts_with("/api/")` 而不是裸 `starts_with("/api")`:
|
||||
/// 后者会把 `/apifoo` 这类**非** API 的 SPA 深链也吞成 404 JSON。
|
||||
fn is_api_path(path: &str) -> bool {
|
||||
path == "/api" || path.starts_with("/api/")
|
||||
///
|
||||
/// ⚠️ 入参**必须**是 [`decoded_path`] 之后的路径(守卫与决策层同一口径):
|
||||
/// `/api%2Ffoo` 解码后是 `/api/foo` ⇒ 属于 `/api` 命名空间 ⇒ 404 JSON。
|
||||
fn is_api_path(decoded_path: &str) -> bool {
|
||||
decoded_path == "/api" || decoded_path.starts_with("/api/")
|
||||
}
|
||||
|
||||
/// 路径的**最后一段**(去尾斜杠、percent-decode、忽略大小写)是否等于 DDL 文件名。
|
||||
fn is_ddl_path(path: &str) -> bool {
|
||||
let trimmed = path.trim_end_matches('/');
|
||||
/// 路径的**最后一段**(去尾斜杠、忽略大小写)是否等于 DDL 文件名。
|
||||
///
|
||||
/// ⚠️ 入参**必须**是 [`decoded_path`] 之后的路径(守卫与决策层同一口径)。
|
||||
fn is_ddl_path(decoded_path: &str) -> bool {
|
||||
let trimmed = decoded_path.trim_end_matches('/');
|
||||
let last = trimmed.rsplit('/').next().unwrap_or("");
|
||||
percent_decode(last).eq_ignore_ascii_case(DDL_FILENAME)
|
||||
last.eq_ignore_ascii_case(DDL_FILENAME)
|
||||
}
|
||||
|
||||
/// 判定用的**归一化路径**:percent-decode 之后的结果。
|
||||
///
|
||||
/// 🔴 守卫(`ddl_guard`)与决策层(`fallback_response`)**必须**用同一个口径,
|
||||
/// 否则会出现「一边认为在 `/api` 下、另一边不认为」的不一致。
|
||||
fn decoded_path(raw_path: &str) -> String {
|
||||
percent_decode(raw_path)
|
||||
}
|
||||
|
||||
/// 最小实现的 percent-decode(只处理 `%XX`;非法的 `%` 原样保留)。
|
||||
|
||||
+76
-2
@@ -4,7 +4,7 @@
|
||||
//! (接了就会先吃 401,测不到 404)。
|
||||
//! ⚠️ 本测试二进制**不需要 PGlite**(兜底不碰 DB)⇒ 不建 PGlite 实例。
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use axum::body::Body;
|
||||
use axum::http::{header, Request, StatusCode};
|
||||
@@ -20,7 +20,12 @@ fn static_dir() -> PathBuf {
|
||||
|
||||
/// 打一个请求到兜底服务,返回 `(状态码, content-type, body 文本)`。
|
||||
async fn call(uri: &str) -> (StatusCode, String, String) {
|
||||
let svc = spa_fallback(static_dir());
|
||||
call_dir(&static_dir(), uri).await
|
||||
}
|
||||
|
||||
/// 打一个请求到**指定** web root 的兜底服务,返回 `(状态码, content-type, body 文本)`。
|
||||
async fn call_dir(dir: &Path, uri: &str) -> (StatusCode, String, String) {
|
||||
let svc = spa_fallback(dir);
|
||||
let req = Request::builder()
|
||||
.uri(uri)
|
||||
.body(Body::empty())
|
||||
@@ -44,6 +49,11 @@ async fn call(uri: &str) -> (StatusCode, String, String) {
|
||||
}
|
||||
|
||||
/// `/api/**` 未命中 ⇒ 404 + JSON(**无 `data` 键**)。
|
||||
///
|
||||
/// 🔴 附带断言(R2-3):
|
||||
/// - `/api%2Ffoo`(**编码斜杠**)⇒ 判定前先 percent-decode ⇒ 解码后是 `/api/foo`
|
||||
/// ⇒ 落在 `/api` 命名空间 ⇒ **404 + JSON**(**不是** SPA 的 HTML);
|
||||
/// - `/apifoo`(**非** `/api` 命名空间)⇒ **不能**被误吞 ⇒ 仍回 SPA HTML(200 `text/html`)。
|
||||
#[tokio::test]
|
||||
async fn api_prefix_returns_404_json_without_data_key() {
|
||||
let (status, ct, body) = call("/api/anything").await;
|
||||
@@ -57,6 +67,18 @@ async fn api_prefix_returns_404_json_without_data_key() {
|
||||
"404 信封不得有 data 键(与 auth::reject 同族):{:?}",
|
||||
v
|
||||
);
|
||||
|
||||
// R2-3:编码斜杠 ⇒ 解码后属于 `/api` 命名空间 ⇒ 404 + JSON。
|
||||
let (status, ct, body) = call("/api%2Ffoo").await;
|
||||
assert_eq!(status, StatusCode::NOT_FOUND, "body={}", body);
|
||||
assert_eq!(ct, "application/json", "body={}", body);
|
||||
let v: serde_json::Value = serde_json::from_str(&body).expect("body 必须是 JSON");
|
||||
assert_eq!(v["code"], 404);
|
||||
|
||||
// R2-3:`/apifoo` 不是 `/api` 命名空间 ⇒ 不能被误吞成 404 JSON。
|
||||
let (status, ct, _body) = call("/apifoo").await;
|
||||
assert_eq!(status, StatusCode::OK, "`/apifoo` 不应被误吞");
|
||||
assert!(ct.starts_with("text/html"), "content-type={:?}", ct);
|
||||
}
|
||||
|
||||
/// `/api/`(**带尾斜杠**)⇒ 404 + JSON。
|
||||
@@ -131,3 +153,55 @@ async fn static_assets_are_still_served() {
|
||||
&body[..body.len().min(200)]
|
||||
);
|
||||
}
|
||||
|
||||
/// 🔴 **回归点(R2-1)**:DDL 文件**就在 web root 里**时,也**必须**下不到。
|
||||
///
|
||||
/// 这条测试证明的是「前置守卫 `ddl_guard` 真的跑在 `ServeDir` **之前**」:
|
||||
/// - 若守卫只在 `ServeDir` 的 decision 层(文件没找到时)判定 ⇒ 这里会 **200 + 完整 DDL**;
|
||||
/// - 若守卫是前置中间件 ⇒ 无论文件在不在 web root,都是 **404 + JSON**。
|
||||
#[tokio::test]
|
||||
async fn ddl_in_web_root_is_still_not_downloadable() {
|
||||
// 在临时目录里造一个「含 migrate.sql 的 web root」。
|
||||
let tmp = std::env::temp_dir().join(format!(
|
||||
"tdc-ddl-guard-{}-{}",
|
||||
std::process::id(),
|
||||
std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.map(|d| d.as_nanos())
|
||||
.unwrap_or(0)
|
||||
));
|
||||
std::fs::create_dir_all(&tmp).expect("创建临时 web root 失败");
|
||||
std::fs::write(
|
||||
tmp.join("migrate.sql"),
|
||||
"CREATE TABLE tdc_secret (id text);\n-- DDL MUST NOT LEAK\n",
|
||||
)
|
||||
.expect("写临时 migrate.sql 失败");
|
||||
std::fs::write(tmp.join("index.html"), "<title>tmp</title>").expect("写临时 index.html 失败");
|
||||
|
||||
let mut failures: Vec<String> = Vec::new();
|
||||
for uri in [
|
||||
"/migrate.sql",
|
||||
"/MIGRATE.SQL",
|
||||
"/migrate%2Esql",
|
||||
"//migrate.sql",
|
||||
] {
|
||||
let (status, ct, body) = call_dir(&tmp, uri).await;
|
||||
let head: String = body.chars().take(200).collect();
|
||||
if status != StatusCode::NOT_FOUND {
|
||||
failures.push(format!(
|
||||
"uri={uri} 必须是 404(DDL 在 web root 里也下不到),实际 {status},body={head}"
|
||||
));
|
||||
}
|
||||
if ct != "application/json" {
|
||||
failures.push(format!("uri={uri} 必须是 JSON,实际 {ct},body={head}"));
|
||||
}
|
||||
if body.contains("CREATE TABLE") {
|
||||
failures.push(format!("uri={uri} 响应体不得含 DDL:{head}"));
|
||||
}
|
||||
}
|
||||
|
||||
// 只删**自己**在 temp_dir 下建的那个目录(不碰仓库里任何东西)。
|
||||
let _ = std::fs::remove_dir_all(&tmp);
|
||||
|
||||
assert!(failures.is_empty(), "{}", failures.join("\n"));
|
||||
}
|
||||
Reference in new issue
Block a user