fix(app-iced, presenter): M114 r2 —— 登录失败走结构化错误码 + i18n,修 4 条 p2 与 3 条看图意见
p1(语言泄漏):后端诊断串不再上屏
- presenter 新增 LoginFailure 原因码(denied / whitelist_pending / unreachable /
not_authlib_server / bad_credentials / no_profile / store_failed / other)
- 页面按码查 i18n 出标题+正文+「Code: …」,原文只进日志/详细信息
- 进行中(Requesting)也走 i18n,不再复读后端中文状态串
- presenter/state 不再发中文 toast(成败由页面按 i18n 画)
- 新增守门测试:注入带 AADSTS 的失败事件,断言英文视图无 CJK 且含 code
p2-1 复制:on_account 返回 Task,page_messages 把 iced::clipboard::write 交回 runtime
p2-2 可见失败态:新增 AccountNotice(added/removed/switched/名字非法/重名/落盘失败/
找不到),页面用 M3 内联 alert 画(不是 toast);离线名字先按 3–16 位规则校验,
失败不再清空输入
p2-3 重新登录按账户类型分派:微软→授权码流;第三方→预填服务器/登录名并提示补密码;
离线→明确说明没有可重登的服务器账户
p2-4 入口收敛:删 chip 行;空态=三卡片;有账号时三卡收进 Add an account(按钮不再绑死微软轨)
看图意见/tower 三条:
- 失败横幅改成 M3 alert(SurfaceContainerHigh + 描边,errorContainer 只作图标块,
不再通栏实心红);色值本身经复审像素采样确认是 90/30 档,未改角色
- 当前账户卡补齐与列表一致的「服务器/登录名」行;无皮肤时明说 No skin available
- 页面级 scrollable 加 8px 右 gutter,滚动条不再压卡片
- 倒计时改 mm:ss(15:00 left),数字与冒号语言无关
p3(顺带):AuthlibRequest / Form 手写 Debug 脱敏密码;HTTP 响应体与 base64 输出加上限;
离线提示文案与行为对齐;删除无人使用的 key;皮肤测试断言帽子层真的 blend
测试:app-iced lib 418 绿、presenter 151 / i18n 24 绿(workspace 全量另跑)
This commit is contained in:
1 parent
1ff00bbe50
commit
8d8552113a
31 files changed
+1540
-497
No files matched your search
@@ -3,20 +3,21 @@
|
||||
//! | 用例 | 抓得住什么 |
|
||||
//! |---|---|
|
||||
//! | `a_jwt_injected_into_events_never_reaches_the_page` | **凭据红线**:DTO → 状态 → 视图模型这一路漏了脱敏 |
|
||||
//! | `a_failure_with_a_provider_code_renders_english_and_the_code` | **语言泄漏(r1 p1)**:后端中文诊断串又直接上屏了 |
|
||||
//! | `an_empty_account_list_offers_all_three_tracks` | 空态变成白页(没有入口) |
|
||||
//! | `the_device_code_panel_shows_a_countdown_and_expires` | 设备码「只转圈」(倒计时/过期不可见) |
|
||||
//! | `the_device_code_panel_shows_a_countdown_and_expires` | 设备码「只转圈」/ 倒计时不是人话格式 |
|
||||
//! | `a_third_party_account_falls_back_to_the_monogram` | 没有皮肤却画白块 / 拿假皮肤充数 |
|
||||
//! | `the_offline_track_keeps_the_agreed_wording` | 离线档案的说明被改写成「兼容旧启动器」那套 |
|
||||
|
||||
use unlucky_i18n::{Key, Lang};
|
||||
use unlucky_presenter::dto::{
|
||||
AccountKind, AccountView, AppEvent, AuthlibLoginView, CoreEvent, DeviceLoginPhase,
|
||||
DeviceLoginView, SkinImage,
|
||||
AccountKind, AccountNotice, AccountNoticeCode, AccountView, AppEvent, AuthlibLoginView,
|
||||
CoreEvent, DeviceLoginPhase, DeviceLoginView, LoginFailure, SkinImage,
|
||||
};
|
||||
use unlucky_presenter::state::AppState;
|
||||
|
||||
use super::avatar::Cache;
|
||||
use super::model::{AuthlibPanel, DevicePanel, Form, Page, Panel, Track};
|
||||
use super::login::failure_body_key;
|
||||
use super::model::{AuthlibPanel, DevicePanel, Form, Hint, Page, Panel, Track};
|
||||
|
||||
fn account(name: &str, kind: AccountKind, active: bool) -> AccountView {
|
||||
AccountView {
|
||||
@@ -33,11 +34,14 @@ fn account(name: &str, kind: AccountKind, active: bool) -> AccountView {
|
||||
}
|
||||
|
||||
fn build(state: &AppState, form: &Form) -> Page {
|
||||
Page::build(state, form, &mut Cache::default(), Lang::ZhCn, 1180.0)
|
||||
// 断言口径是英文界面(app 钉死 `Lang::En`):英文目录下「视图里有中文」=「后端原文上屏了」。
|
||||
// 宽度取验收窗口 1180(r2 起 `Page` 记中栏可用宽)。
|
||||
Page::build(state, form, &mut Cache::default(), Lang::En, 1180.0)
|
||||
}
|
||||
|
||||
/// 把视图模型里**所有会上屏的文本**拼起来(凭据红线就是在这坨里查)。
|
||||
fn visible_text(page: &Page) -> String {
|
||||
/// 页面**会画什么**:模型里的数据 + 视图层对码的 i18n 查表结果。
|
||||
fn on_screen(page: &Page) -> String {
|
||||
let catalog = Lang::En.catalog();
|
||||
let mut out = String::new();
|
||||
for row in &page.rows {
|
||||
out.push_str(&row.name);
|
||||
@@ -46,64 +50,91 @@ fn visible_text(page: &Page) -> String {
|
||||
out.push_str(&row.added);
|
||||
out.push_str(&row.detail);
|
||||
}
|
||||
out.push_str(&page.form.server);
|
||||
out.push_str(&page.form.login);
|
||||
out.push_str(&page.form.offline_name);
|
||||
out.push_str(&page.checked_server);
|
||||
out.push_str(&page.form.server);
|
||||
if let Some(notice) = &page.notice {
|
||||
// 与 `widgets::banner` 同源:码 → i18n(主题名拼进去)
|
||||
out.push_str(match notice.code {
|
||||
AccountNoticeCode::OfflineNameInvalid => {
|
||||
catalog.text(Key::AccountNoticeOfflineNameInvalid)
|
||||
}
|
||||
AccountNoticeCode::AccountExists => catalog.text(Key::AccountNoticeAccountExists),
|
||||
AccountNoticeCode::StoreFailed => catalog.text(Key::AccountNoticeStoreFailed),
|
||||
AccountNoticeCode::NotFound => catalog.text(Key::AccountNoticeNotFound),
|
||||
AccountNoticeCode::Other => catalog.text(Key::AccountNoticeOther),
|
||||
AccountNoticeCode::Added => catalog.text(Key::AccountNoticeAdded),
|
||||
AccountNoticeCode::Removed => catalog.text(Key::AccountNoticeRemoved),
|
||||
AccountNoticeCode::Switched => catalog.text(Key::AccountNoticeSwitched),
|
||||
});
|
||||
out.push_str(¬ice.subject);
|
||||
}
|
||||
if let Some(hint) = page.hint {
|
||||
out.push_str(match hint {
|
||||
Hint::AuthlibReauth => catalog.text(Key::AccountHintAuthlibReauth),
|
||||
Hint::OfflineNoRelogin => catalog.text(Key::AccountHintOfflineNoRelogin),
|
||||
});
|
||||
}
|
||||
match &page.device {
|
||||
DevicePanel::Hidden => {}
|
||||
DevicePanel::Requesting { message } => out.push_str(message),
|
||||
DevicePanel::Requesting { .. } => out.push_str(catalog.text(Key::AccountDeviceRequesting)),
|
||||
DevicePanel::Code {
|
||||
code,
|
||||
link,
|
||||
message,
|
||||
remaining,
|
||||
expired,
|
||||
..
|
||||
} => {
|
||||
out.push_str(code);
|
||||
out.push_str(link);
|
||||
out.push_str(message);
|
||||
if *expired {
|
||||
out.push_str(catalog.text(Key::AccountDeviceExpired));
|
||||
} else if let Some(secs) = remaining {
|
||||
let clock = format!("{:02}:{:02}", secs / 60, secs % 60);
|
||||
out.push_str(&catalog.render(Key::AccountDeviceCountdown, &[("time", &clock)]));
|
||||
}
|
||||
}
|
||||
DevicePanel::Browser { link, message, .. } => {
|
||||
out.push_str(link);
|
||||
out.push_str(message);
|
||||
DevicePanel::Browser { link, .. } => out.push_str(link),
|
||||
DevicePanel::Failed { failure, .. } => {
|
||||
out.push_str(catalog.text(failure_body_key(*failure)));
|
||||
out.push_str(&catalog.render(Key::AccountFailureCode, &[("code", failure.code())]));
|
||||
}
|
||||
DevicePanel::Failed { message } => out.push_str(message),
|
||||
DevicePanel::Succeeded { name } => out.push_str(name),
|
||||
}
|
||||
match &page.authlib {
|
||||
AuthlibPanel::Idle => {}
|
||||
AuthlibPanel::Running { message } => out.push_str(message),
|
||||
AuthlibPanel::Ready {
|
||||
server_name,
|
||||
message,
|
||||
} => {
|
||||
out.push_str(server_name);
|
||||
out.push_str(message);
|
||||
AuthlibPanel::Running { .. } => out.push_str(catalog.text(Key::AccountServerChecking)),
|
||||
AuthlibPanel::Ready { server_name, .. } => out.push_str(server_name),
|
||||
AuthlibPanel::Failed { failure, .. } => {
|
||||
out.push_str(catalog.text(failure_body_key(*failure)));
|
||||
out.push_str(failure.code());
|
||||
}
|
||||
AuthlibPanel::Failed { message } => out.push_str(message),
|
||||
AuthlibPanel::Succeeded { name } => out.push_str(name),
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// 有没有中日韩统一表意文字(语言泄漏的最直接判据)。
|
||||
fn has_cjk(text: &str) -> bool {
|
||||
text.chars().any(|c| matches!(c, '\u{3400}'..='\u{4DBF}' | '\u{4E00}'..='\u{9FFF}' | '\u{3000}'..='\u{303F}' | '\u{FF00}'..='\u{FFEF}'))
|
||||
}
|
||||
|
||||
const JWT: &str =
|
||||
"eyJhbGciOiJSUzI1NiIsIng1dCI6IkFCQyJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.c2lnbmF0dXJlLXZhbHVl";
|
||||
|
||||
/// **凭据红线(审核项)**:把 JWT 形状串注入事件 → 视图模型里不许出现。
|
||||
/// **凭据红线(审核项)**:把 JWT 形状串注入事件 → 状态与视图模型里都不许出现。
|
||||
///
|
||||
/// 抓得住:presenter 状态层的脱敏被删(`AppState::apply_device_login` / `apply_authlib_login`),
|
||||
/// 或页面把 DTO 的错误原文直接搬上屏。
|
||||
/// 抓不住:某个将来新增的**独立**字段绕过 `message` 通道(那需要另加断言)。
|
||||
#[test]
|
||||
fn a_jwt_injected_into_events_never_reaches_the_page() {
|
||||
let mut state = AppState::new();
|
||||
state.accounts = vec![account("Steve", AccountKind::Microsoft, true)];
|
||||
// **绕过构造器**直接摆一个带 JWT 的 DTO:模拟「将来某个新构造器忘了脱敏」/「后端把原文塞进来」。
|
||||
// 用 `DeviceLoginView::failed(..)` 构造是测不到状态层脱敏的(构造器自己就脱过了)。
|
||||
state.apply(AppEvent::Core(CoreEvent::DeviceLoginChanged(
|
||||
DeviceLoginView {
|
||||
phase: DeviceLoginPhase::Failed,
|
||||
message: format!("微软返回错误:accessToken={JWT} refresh_token={JWT}"),
|
||||
failure: Some(LoginFailure::Denied),
|
||||
..DeviceLoginView::new()
|
||||
},
|
||||
)));
|
||||
@@ -113,21 +144,75 @@ fn a_jwt_injected_into_events_never_reaches_the_page() {
|
||||
server: "https://littleskin.cn/api/yggdrasil/".to_string(),
|
||||
server_name: String::new(),
|
||||
message: format!("服务器回包异常 {JWT}"),
|
||||
failure: Some(LoginFailure::Denied),
|
||||
account_name: String::new(),
|
||||
},
|
||||
)));
|
||||
|
||||
let page = build(&state, &Form::new());
|
||||
let text = visible_text(&page);
|
||||
assert!(!text.contains("eyJ"), "视图模型里出现了 JWT:{text}");
|
||||
assert!(!text.to_lowercase().contains("refreshtoken"), "{text}");
|
||||
// ① 状态层已经脱敏(这一条抓得住「摘掉 state 层 redact」的变异)
|
||||
assert!(
|
||||
text.contains("⟪redacted⟫"),
|
||||
"错误文案要被标成已脱敏:{text}"
|
||||
!state.device_login.message.contains("eyJ"),
|
||||
"{}",
|
||||
state.device_login.message
|
||||
);
|
||||
assert!(
|
||||
!state.authlib_login.message.contains("eyJ"),
|
||||
"{}",
|
||||
state.authlib_login.message
|
||||
);
|
||||
|
||||
// ② 上屏文案更不可能有它(页面根本不画原文)
|
||||
let text = on_screen(&build(&state, &Form::new()));
|
||||
assert!(!text.contains("eyJ"), "视图里出现了 JWT:{text}");
|
||||
assert!(!text.contains("⟪redacted⟫"), "脱敏占位符也不该上屏:{text}");
|
||||
}
|
||||
|
||||
/// 空态:**三条轨道都有入口**,不是一张白页。
|
||||
/// **语言泄漏(复审 r1 p1)**:带 AADSTS 码的失败事件 → 英文视图里不许有中文,且要带 code。
|
||||
///
|
||||
/// 抓得住:有人又把 `view.message`(core 的中文诊断串)画回面板上;或者码→i18n 的映射被摘。
|
||||
/// 抓不住:catalog 里某条英文译文本身写得差(那只能人工审)。
|
||||
#[test]
|
||||
fn a_failure_with_a_provider_code_renders_english_and_the_code() {
|
||||
let mut state = AppState::new();
|
||||
state.apply(AppEvent::Core(CoreEvent::DeviceLoginChanged(
|
||||
DeviceLoginView {
|
||||
phase: DeviceLoginPhase::Failed,
|
||||
message:
|
||||
"微软拒绝了这次登录:AADSTS7000218(HTTP 403)—— 应用白名单还没批准,或网络被拦截"
|
||||
.to_string(),
|
||||
failure: Some(LoginFailure::NotWhitelisted),
|
||||
..DeviceLoginView::new()
|
||||
},
|
||||
)));
|
||||
let page = build(&state, &Form::new());
|
||||
let text = on_screen(&page);
|
||||
assert!(!has_cjk(&text), "英文界面里出现了中文:{text}");
|
||||
assert!(
|
||||
text.contains("whitelist_pending"),
|
||||
"面板要给稳定 code:{text}"
|
||||
);
|
||||
assert!(
|
||||
text.to_lowercase().contains("approved"),
|
||||
"要给出可读的英文原因:{text}"
|
||||
);
|
||||
|
||||
// 第三方轨的失败同样只有 i18n + code
|
||||
state.apply(AppEvent::Core(CoreEvent::AuthlibLoginChanged(
|
||||
AuthlibLoginView {
|
||||
phase: DeviceLoginPhase::Failed,
|
||||
server: "https://example.invalid/".to_string(),
|
||||
server_name: String::new(),
|
||||
message: "服务器不可达:dns error".to_string(),
|
||||
failure: Some(LoginFailure::Unreachable),
|
||||
account_name: String::new(),
|
||||
},
|
||||
)));
|
||||
let text = on_screen(&build(&state, &Form::new()));
|
||||
assert!(!has_cjk(&text), "{text}");
|
||||
assert!(text.contains("unreachable"), "{text}");
|
||||
}
|
||||
|
||||
/// 空态:**三条轨道都有入口**,不是一张白页;且三张卡的标题各不相同。
|
||||
#[test]
|
||||
fn an_empty_account_list_offers_all_three_tracks() {
|
||||
let state = AppState::new();
|
||||
@@ -135,8 +220,6 @@ fn an_empty_account_list_offers_all_three_tracks() {
|
||||
assert!(page.is_empty());
|
||||
assert_eq!(page.panel, Panel::None);
|
||||
assert!(page.active_row().is_none());
|
||||
assert_eq!(Track::ALL.len(), 3);
|
||||
// 三条轨道的文案 key 各不相同(不是三张一样的卡)
|
||||
let mut keys: Vec<&str> = Track::ALL
|
||||
.iter()
|
||||
.map(|track| track.title_key().name())
|
||||
@@ -146,7 +229,7 @@ fn an_empty_account_list_offers_all_three_tracks() {
|
||||
assert_eq!(keys.len(), 3);
|
||||
}
|
||||
|
||||
/// 设备码:**倒计时可见**,过期后是「已过期」而不是继续转圈。
|
||||
/// 设备码:**倒计时是人话格式(mm:ss)**,过期后是「已过期」而不是继续转圈。
|
||||
#[test]
|
||||
fn the_device_code_panel_shows_a_countdown_and_expires() {
|
||||
let mut state = AppState::new();
|
||||
@@ -162,11 +245,14 @@ fn the_device_code_panel_shows_a_countdown_and_expires() {
|
||||
..
|
||||
} => {
|
||||
assert_eq!(code, "ABCD-EFGH");
|
||||
assert!(remaining.is_some_and(|secs| secs > 0));
|
||||
assert_eq!(*remaining, Some(900));
|
||||
assert!(!expired);
|
||||
}
|
||||
other => panic!("等待态应该是设备码面板,实际 {other:?}"),
|
||||
}
|
||||
let text = on_screen(&page);
|
||||
assert!(text.contains("15:00"), "倒计时要画成 mm:ss:{text}");
|
||||
assert!(!text.contains("900s"), "不再是 `900s left`:{text}");
|
||||
|
||||
// 起点往前挪 20 分钟 ⇒ 过期
|
||||
state.device_login_started =
|
||||
@@ -190,7 +276,7 @@ fn the_device_code_panel_shows_a_countdown_and_expires() {
|
||||
assert!(matches!(page.device, DevicePanel::Browser { .. }));
|
||||
}
|
||||
|
||||
/// 没有皮肤 = 首字母块(不是白块、不是假皮肤);坏图也必须回落。
|
||||
/// 没有皮肤 = 首字母块(不是白块、不是假皮肤);坏图也必须回落;无皮肤时**明说**。
|
||||
#[test]
|
||||
fn a_third_party_account_falls_back_to_the_monogram() {
|
||||
let mut state = AppState::new();
|
||||
@@ -204,7 +290,9 @@ fn a_third_party_account_falls_back_to_the_monogram() {
|
||||
"没有皮肤就不许有图"
|
||||
);
|
||||
assert!(page.rows.iter().all(|row| !row.monogram.is_empty()));
|
||||
assert!(page.active_skin().is_none(), "皮肤预览区没有图就不画");
|
||||
assert!(page.active_skin().is_none(), "皮肤预览区没有图就不画图");
|
||||
let text = on_screen(&page);
|
||||
assert!(!has_cjk(&text));
|
||||
|
||||
// 塞一张坏图:解码失败 → 仍然回落到首字母块(不 panic、不白块)
|
||||
state.accounts[0].skin = Some(SkinImage {
|
||||
@@ -213,12 +301,6 @@ fn a_third_party_account_falls_back_to_the_monogram() {
|
||||
});
|
||||
let page = build(&state, &Form::new());
|
||||
assert!(page.rows[0].head.is_none());
|
||||
|
||||
// 离线档案永远没有皮肤:即使被塞了假数据,UI 侧也只认 DTO 的 `kind`
|
||||
state.accounts[1].skin = None;
|
||||
state.accounts[1].kind = AccountKind::Offline;
|
||||
let page = build(&state, &Form::new());
|
||||
assert!(page.rows[1].head.is_none());
|
||||
}
|
||||
|
||||
/// 离线档案的说明**必须**带「无法连接启用正版验证的服务器」这条限定(中英都要)。
|
||||
@@ -242,34 +324,31 @@ fn the_offline_track_keeps_the_agreed_wording() {
|
||||
}
|
||||
}
|
||||
|
||||
/// 三条轨道在列表里**文案互不相同**(每一行都贴自己的轨道徽标)。
|
||||
/// **离线轨的失败必须可见**(复审 r1 P2-2):横幅进模型、文案走 i18n、原文不上屏。
|
||||
#[test]
|
||||
fn every_track_has_its_own_badge() {
|
||||
fn a_failed_offline_add_is_visible() {
|
||||
let mut state = AppState::new();
|
||||
state.accounts = vec![
|
||||
account("a", AccountKind::Microsoft, true),
|
||||
account("b", AccountKind::Authlib, false),
|
||||
account("c", AccountKind::Offline, false),
|
||||
];
|
||||
state.apply(AppEvent::Core(CoreEvent::AccountNoticeChanged(Some(
|
||||
AccountNotice::new(
|
||||
AccountNoticeCode::OfflineNameInvalid,
|
||||
"ab",
|
||||
"离线名字必须是 3–16 位字母/数字/下划线,收到 \"ab\"",
|
||||
),
|
||||
))));
|
||||
let page = build(&state, &Form::new());
|
||||
let labels: Vec<&str> = page
|
||||
.rows
|
||||
.iter()
|
||||
.map(|row| row.kind_label.as_str())
|
||||
.collect();
|
||||
assert_eq!(labels.len(), 3);
|
||||
assert_ne!(labels[0], labels[1]);
|
||||
assert_ne!(labels[1], labels[2]);
|
||||
assert!(
|
||||
labels.iter().all(|label| !label.is_empty()),
|
||||
"轨道徽标不能空"
|
||||
);
|
||||
let notice = page.notice.as_ref().expect("失败要有横幅");
|
||||
assert_eq!(notice.code, AccountNoticeCode::OfflineNameInvalid);
|
||||
assert!(notice.failure, "失败横幅要用 error 配色");
|
||||
let text = on_screen(&page);
|
||||
assert!(text.contains("3–16"), "要说清规则:{text}");
|
||||
assert!(!has_cjk(&text), "英文界面不许出现中文:{text}");
|
||||
}
|
||||
|
||||
/// 表单状态:三条轨道各开各的,密码关面板即清。
|
||||
/// 表单状态:三条轨道各开各的,密码关面板即清,三卡默认收起。
|
||||
#[test]
|
||||
fn the_form_tracks_are_independent() {
|
||||
let mut form = Form::new();
|
||||
assert!(!form.section_open, "有账号时三卡默认收起(P2-4)");
|
||||
form.open(Track::Offline);
|
||||
assert_eq!(form.panel, Panel::Offline);
|
||||
assert!(!form.offline_ready(), "空名字不能提交");
|
||||
@@ -277,7 +356,6 @@ fn the_form_tracks_are_independent() {
|
||||
assert!(form.offline_ready());
|
||||
|
||||
form.open(Track::Authlib);
|
||||
assert_eq!(form.panel, Panel::Authlib);
|
||||
assert!(!form.authlib_ready(), "地址/登录名/密码缺一不可");
|
||||
form.server = "https://littleskin.cn/api/yggdrasil/".to_string();
|
||||
form.login = "alex".to_string();
|
||||
@@ -299,10 +377,10 @@ fn login_phases_map_to_distinct_panels() {
|
||||
..DeviceLoginView::new()
|
||||
},
|
||||
)));
|
||||
assert!(matches!(
|
||||
build(&state, &Form::new()).device,
|
||||
DevicePanel::Requesting { .. }
|
||||
));
|
||||
let page = build(&state, &Form::new());
|
||||
assert!(matches!(page.device, DevicePanel::Requesting { .. }));
|
||||
// 进行中也只有 i18n(不再复读 presenter 的中文状态串)
|
||||
assert!(!has_cjk(&on_screen(&page)));
|
||||
|
||||
state.apply(AppEvent::Core(CoreEvent::DeviceLoginChanged(
|
||||
DeviceLoginView::failed("HTTP 403"),
|
||||
|
||||
Reference in new issue
Block a user