- bootstrap INSERT 失败时不再回传/打印密钥(否则会打印一个永远登不上的死凭证), 且 main.rs 因「没有身份」直接退出进程 - me_payload_key_set_is_stable 改为走生产函数 me_payload 比对精确键集合(原先是字面量自证) - db_lock 改为进程级单例(pglite-rs 每进程只允许一个 PGlite ⇒ 一个进程只需要一把锁), main.rs 只造一个 AppState - 启动时每次回显生效的身份 id/identityCode;配置码与库中已有身份码不一致时明确告警 - 随机密钥挪到「确定要建身份」之后生成(签发即落库变成结构上的不变量) Co-Authored-By: Claude Code <[email protected]>
44 lines
1.6 KiB
Rust
44 lines
1.6 KiB
Rust
//! 引导失败的端到端用例:INSERT 失败 ⇒ **不得**回传密钥。
|
||
//!
|
||
//! ⚠️ 本文件是**独立测试二进制** ⇒ 独立进程 ⇒ 独立 PGlite
|
||
//! (pglite-rs 每进程只允许一个实例)。
|
||
|
||
use std::sync::Arc;
|
||
|
||
use pglite::PGlite;
|
||
use tdc_connector::config::Config;
|
||
use tdc_connector::domain::identity::bootstrap_identity;
|
||
use tdc_connector::session::SessionStore;
|
||
use tdc_connector::state::{AppState, BootstrapIdentity};
|
||
|
||
#[tokio::test]
|
||
async fn bootstrap_insert_failure_yields_no_secret() {
|
||
let db = Arc::new(PGlite::open_temp().await.expect("打开临时 PGlite 失败"));
|
||
tdc_connector::db::ensure_schema(db.as_ref()).await.expect("建表失败");
|
||
// 让 INSERT 必然失败:把目标表删掉
|
||
// (`PGlite::exec(&self, sql: &str)` 是无参版本;带参的是 `query(sql, &[&(dyn ToSql + Sync)])`)
|
||
db.exec("DROP TABLE tdc_identity").await.expect("删表失败");
|
||
|
||
let mut config = Config::from_env(std::env::current_dir().unwrap());
|
||
config.identity_code = "TEST-CONNECTOR".to_string();
|
||
let state = AppState::new(
|
||
config,
|
||
db,
|
||
Arc::new(SessionStore::new()),
|
||
BootstrapIdentity::default(),
|
||
);
|
||
|
||
let bootstrap = bootstrap_identity(&state).await;
|
||
// 🔴 失败 ⇒ 不得有密钥、不得有 id
|
||
assert!(
|
||
bootstrap.issued_secret.is_none(),
|
||
"引导失败时不得回传密钥,实际 {:?}",
|
||
bootstrap.issued_secret
|
||
);
|
||
assert!(
|
||
bootstrap.identity_id.is_empty(),
|
||
"引导失败时不得回传没落库的 id,实际 {:?}",
|
||
bootstrap.identity_id
|
||
);
|
||
}
|