feat(defender): 可集成静态库 + readoor 接入方案(检测→分级→数据毒化闭环)
在 iOSGuard 侧产出可集成产物与接入文档,不修改 readoor 代码。 - defender/: anti_hook/anti_frida/anti_debug/anti_jailbreak 探针 + syscall 直发、 policy 分级层、poison 数据依赖毒化、dispatch/resolve/call_bridge 等子模块 - poison: 三副本冗余、无分支掩码;健康恒等、毒化破坏 key(替代 if-exit 处置) - policy: STRONG/MEDIUM/WEAK 分级,守误报底线,仅 DETECTED 参与、组合命中才毒化 - anti_jailbreak: IGSyscall 直发 svc 检测越狱文件(400)/沙盒逃逸(401),绕 libc hook - tools/build_defender_lib.sh: 一键交叉编译打包 libIGDefender.a(arm64) + umbrella 头 - docs/18_READOOR_DEFENDER_INTEGRATION.md: 精确到文件/bridging/替换点/代码片段 - docs/05-17 + evidence + tests + macho_guard/static_sdk_redirect 工具链 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
ff0aee7f47
commit
599e1da5ce
@@ -0,0 +1,231 @@
|
||||
import XCTest
|
||||
import UIKit
|
||||
|
||||
/// 访问真实观察包;不使用 --UITesting,不注入 token,不调用购买接口。
|
||||
final class IGBusinessRegressionTests: XCTestCase {
|
||||
private let bundleID = "cn.touchv.iosguard.observe.20261110"
|
||||
|
||||
override func setUpWithError() throws { continueAfterFailure = false }
|
||||
|
||||
private func capture(_ app: XCUIApplication, _ name: String) {
|
||||
// 截图遮盖输入框,文本树移除输入值,避免登录排查留存凭证。
|
||||
let source = app.screenshot().image
|
||||
let fields = app.textFields.allElementsBoundByIndex + app.secureTextFields.allElementsBoundByIndex
|
||||
let screenshotImage = UIGraphicsImageRenderer(size: source.size).image { context in
|
||||
source.draw(at: .zero)
|
||||
UIColor.lightGray.setFill()
|
||||
let sx = source.size.width / app.frame.width
|
||||
let sy = source.size.height / app.frame.height
|
||||
for field in fields {
|
||||
let frame = field.frame
|
||||
context.fill(CGRect(x: frame.minX * sx, y: frame.minY * sy,
|
||||
width: frame.width * sx, height: frame.height * sy))
|
||||
}
|
||||
}
|
||||
let screenshot = XCTAttachment(image: screenshotImage)
|
||||
screenshot.name = name
|
||||
screenshot.lifetime = .keepAlways
|
||||
add(screenshot)
|
||||
let redactedTree = app.debugDescription.components(separatedBy: "\n").map { line in
|
||||
guard line.contains("TextField"), let value = line.range(of: ", value:") else { return line }
|
||||
return String(line[..<value.lowerBound]) + ", value: [redacted]"
|
||||
}.joined(separator: "\n")
|
||||
let tree = XCTAttachment(string: redactedTree)
|
||||
tree.name = name + "-accessibility"
|
||||
tree.lifetime = .keepAlways
|
||||
add(tree)
|
||||
}
|
||||
|
||||
func testInspectLaunch() {
|
||||
let app = XCUIApplication(bundleIdentifier: bundleID)
|
||||
app.launch()
|
||||
XCTAssertTrue(app.wait(for: .runningForeground, timeout: 30))
|
||||
capture(app, "observation-launch")
|
||||
}
|
||||
|
||||
func testInspectCurrentPage() {
|
||||
let app = XCUIApplication(bundleIdentifier: bundleID)
|
||||
app.activate()
|
||||
capture(app, "observation-current")
|
||||
}
|
||||
|
||||
func testAllowWifiAndInspect() {
|
||||
let app = XCUIApplication(bundleIdentifier: bundleID)
|
||||
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
|
||||
let wifi = springboard.buttons["仅限无线局域网"]
|
||||
if wifi.waitForExistence(timeout: 5) { wifi.tap() }
|
||||
app.activate()
|
||||
_ = app.images["splash"].waitForNonExistence(timeout: 20)
|
||||
capture(app, "after-network-permission")
|
||||
}
|
||||
|
||||
func testHomeResourceAndForeground() throws {
|
||||
let app = XCUIApplication(bundleIdentifier: bundleID)
|
||||
app.activate()
|
||||
let home = app.otherElements["home_page_anchor"]
|
||||
XCTAssertTrue(home.waitForExistence(timeout: 30), "需先完成真实登录与启动流程")
|
||||
// 实际首页资源由 TableCell 内自绘卡片承载,使用已观察到的资源标题。
|
||||
let resource = app.staticTexts["[pdf]MW书籍测试读"].firstMatch
|
||||
XCTAssertTrue(resource.waitForExistence(timeout: 20))
|
||||
capture(app, "home-before-resource")
|
||||
resource.tap()
|
||||
let detail = app.otherElements["detail_page_anchor"]
|
||||
XCTAssertTrue(detail.waitForExistence(timeout: 20), "首个首页卡片未进入商品详情")
|
||||
capture(app, "resource-detail")
|
||||
XCUIDevice.shared.press(.home)
|
||||
XCTAssertTrue(app.wait(for: .runningBackground, timeout: 10))
|
||||
app.activate()
|
||||
XCTAssertTrue(app.wait(for: .runningForeground, timeout: 10))
|
||||
XCTAssertTrue(detail.waitForExistence(timeout: 10))
|
||||
capture(app, "resource-after-foreground")
|
||||
}
|
||||
|
||||
func testTrialResourceAndInspect() {
|
||||
let app = XCUIApplication(bundleIdentifier: bundleID)
|
||||
app.activate()
|
||||
let trial = app.buttons["试读"].firstMatch
|
||||
XCTAssertTrue(trial.waitForExistence(timeout: 15))
|
||||
trial.tap()
|
||||
// 入口可能先展示课件/规格选择,先留存真实页面再决定下一步。
|
||||
capture(app, "after-trial-entry")
|
||||
}
|
||||
|
||||
func testColdRestartAndInspect() {
|
||||
let app = XCUIApplication(bundleIdentifier: bundleID)
|
||||
app.terminate()
|
||||
app.launch()
|
||||
XCTAssertTrue(app.wait(for: .runningForeground, timeout: 30))
|
||||
XCTAssertTrue(app.otherElements["home_page_anchor"].waitForExistence(timeout: 30))
|
||||
capture(app, "after-cold-restart")
|
||||
}
|
||||
|
||||
func testPDFTrialAndPageTurn() {
|
||||
let app = XCUIApplication(bundleIdentifier: bundleID)
|
||||
app.terminate()
|
||||
app.launch()
|
||||
XCTAssertTrue(app.otherElements["home_page_anchor"].waitForExistence(timeout: 30))
|
||||
let resource = app.staticTexts["[pdf]MW书籍测试读"].firstMatch
|
||||
XCTAssertTrue(resource.waitForExistence(timeout: 15))
|
||||
resource.tap()
|
||||
XCTAssertTrue(app.otherElements["detail_page_anchor"].waitForExistence(timeout: 20))
|
||||
let trial = app.buttons["试读"].firstMatch
|
||||
XCTAssertTrue(trial.waitForExistence(timeout: 15))
|
||||
trial.tap()
|
||||
XCTAssertTrue(app.buttons["titlebar return phone"].waitForExistence(timeout: 20))
|
||||
_ = app.progressIndicators["进度"].waitForNonExistence(timeout: 30)
|
||||
XCTAssertTrue(app.wait(for: .runningForeground, timeout: 5))
|
||||
capture(app, "pdf-before-page-turn")
|
||||
app.swipeLeft()
|
||||
XCTAssertTrue(app.wait(for: .runningForeground, timeout: 5), "PDF 翻页后进程退出")
|
||||
capture(app, "pdf-after-page-turn")
|
||||
}
|
||||
|
||||
func testEPUBResourceAndForeground() {
|
||||
let app = XCUIApplication(bundleIdentifier: bundleID)
|
||||
app.terminate()
|
||||
app.launch()
|
||||
XCTAssertTrue(app.otherElements["home_page_anchor"].waitForExistence(timeout: 30))
|
||||
let resource = app.staticTexts["【epub】会员免费书籍"].firstMatch
|
||||
XCTAssertTrue(resource.waitForExistence(timeout: 15))
|
||||
resource.tap()
|
||||
XCTAssertTrue(app.otherElements["detail_page_anchor"].waitForExistence(timeout: 20))
|
||||
capture(app, "epub-detail")
|
||||
let read = app.buttons["开始阅读"].firstMatch
|
||||
let trial = app.buttons["试读"].firstMatch
|
||||
if read.exists { read.tap() }
|
||||
else {
|
||||
XCTAssertTrue(trial.waitForExistence(timeout: 10), "本账号没有可用阅读入口")
|
||||
trial.tap()
|
||||
}
|
||||
capture(app, "epub-entry")
|
||||
XCTAssertTrue(app.webViews.firstMatch.waitForExistence(timeout: 30), "尚未出现 EPUB 内容视图")
|
||||
capture(app, "epub-content")
|
||||
XCUIDevice.shared.press(.home)
|
||||
XCTAssertTrue(app.wait(for: .runningBackground, timeout: 10))
|
||||
app.activate()
|
||||
XCTAssertTrue(app.wait(for: .runningForeground, timeout: 10))
|
||||
XCTAssertTrue(app.webViews.firstMatch.waitForExistence(timeout: 15))
|
||||
capture(app, "epub-after-foreground")
|
||||
}
|
||||
func testWordbookOpenAndInspect() {
|
||||
openWordbook(replayStyle: true)
|
||||
}
|
||||
|
||||
private func openWordbook(replayStyle: Bool) {
|
||||
let app = XCUIApplication(bundleIdentifier: bundleID)
|
||||
app.launchArguments = replayStyle ? ["--IGArchiveReplayStyle"] : []
|
||||
app.terminate()
|
||||
app.launch()
|
||||
XCTAssertTrue(app.otherElements["home_page_anchor"].waitForExistence(timeout: 30))
|
||||
let popupClose = app.buttons["rd pop close"]
|
||||
if popupClose.waitForExistence(timeout: 5) { popupClose.tap() }
|
||||
capture(app, "wordbook-home")
|
||||
let resource = app.staticTexts["31单词书(稳操胜券)-勿动"].firstMatch
|
||||
XCTAssertTrue(resource.waitForExistence(timeout: 20))
|
||||
resource.tap()
|
||||
XCTAssertTrue(app.otherElements["detail_page_anchor"].waitForExistence(timeout: 20))
|
||||
capture(app, "wordbook-detail")
|
||||
}
|
||||
|
||||
func testWordbookReadAndForeground() {
|
||||
let app = XCUIApplication(bundleIdentifier: bundleID)
|
||||
app.activate()
|
||||
let read = app.buttons["开始阅读"].firstMatch
|
||||
let section = app.staticTexts["稳操胜券"].firstMatch
|
||||
XCTAssertTrue(section.waitForExistence(timeout: 20), "需先打开指定单词书详情")
|
||||
capture(app, "wordbook-loaded-detail")
|
||||
if read.exists { read.tap() } else { section.tap() }
|
||||
capture(app, "wordbook-after-read-entry")
|
||||
let ready = app.staticTexts["今日学习单词了吗?"].firstMatch
|
||||
XCTAssertTrue(ready.waitForExistence(timeout: 120), "单词书未准备完成")
|
||||
XCTAssertTrue(ready.isHittable, "单词书就绪内容不可见")
|
||||
capture(app, "wordbook-ready")
|
||||
XCUIDevice.shared.press(.home)
|
||||
XCTAssertTrue(app.wait(for: .runningBackground, timeout: 10))
|
||||
app.activate()
|
||||
XCTAssertTrue(app.wait(for: .runningForeground, timeout: 10))
|
||||
XCTAssertTrue(ready.waitForExistence(timeout: 15))
|
||||
capture(app, "wordbook-after-foreground")
|
||||
}
|
||||
|
||||
func testWordbookReentryAndCache() {
|
||||
let app = XCUIApplication(bundleIdentifier: bundleID)
|
||||
app.activate()
|
||||
let back = app.buttons["mw backBar img"].firstMatch
|
||||
XCTAssertTrue(back.waitForExistence(timeout: 10))
|
||||
back.tap()
|
||||
let section = app.staticTexts["稳操胜券"].firstMatch
|
||||
XCTAssertTrue(section.waitForExistence(timeout: 15))
|
||||
section.tap()
|
||||
let ready = app.staticTexts["今日学习单词了吗?"].firstMatch
|
||||
XCTAssertTrue(ready.waitForExistence(timeout: 60))
|
||||
XCTAssertTrue(ready.isHittable)
|
||||
capture(app, "wordbook-reentry-cache")
|
||||
XCUIDevice.shared.press(.home)
|
||||
XCTAssertTrue(app.wait(for: .runningBackground, timeout: 10))
|
||||
app.activate()
|
||||
XCTAssertTrue(app.wait(for: .runningForeground, timeout: 10))
|
||||
XCTAssertTrue(ready.waitForExistence(timeout: 15))
|
||||
capture(app, "wordbook-reentry-foreground")
|
||||
}
|
||||
|
||||
func testWordbookFreshExtraction() {
|
||||
testWordbookOpenAndInspect()
|
||||
testWordbookReadAndForeground()
|
||||
}
|
||||
|
||||
func testWordbookCachedEntryAndReentry() {
|
||||
// 由单独无参数启动步骤进入首页,避免将短暂营销弹窗的自动消失误记为业务失败。
|
||||
let app = XCUIApplication(bundleIdentifier: bundleID)
|
||||
app.activate()
|
||||
XCTAssertTrue(app.otherElements["home_page_anchor"].waitForExistence(timeout: 20))
|
||||
let resource = app.staticTexts["31单词书(稳操胜券)-勿动"].firstMatch
|
||||
XCTAssertTrue(resource.waitForExistence(timeout: 15))
|
||||
XCTAssertTrue(resource.isHittable)
|
||||
resource.tap()
|
||||
XCTAssertTrue(app.otherElements["detail_page_anchor"].waitForExistence(timeout: 20))
|
||||
testWordbookReadAndForeground()
|
||||
testWordbookReentryAndCache()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,436 @@
|
||||
import XCTest
|
||||
import UIKit
|
||||
|
||||
/// 反 Hook 门禁按钮级回归(强制模式 dev 包 cn.touchv.a4YX061)。
|
||||
///
|
||||
/// 相位(按方法名字典序执行):
|
||||
/// A1 干净启动勘察;A2 登出到登录页(个人中心 退出登录);
|
||||
/// B1 注入启动·密码登录门禁;B2 注入启动·第三方登录门禁;
|
||||
/// C1 干净启动·密码登录放行(DEBUG 预填测试账号真实登录);
|
||||
/// D1 注入启动·VIP 购买门禁(会员页);E1 注入启动·激活码门禁(我的页探测入口)。
|
||||
///
|
||||
/// 注入:编排器(run_gate_regression.sh)以 devicectl `-e DYLD_INSERT_LIBRARIES`
|
||||
/// 调试启动通道预先注入启动(空壳 libfrida-sim.dylib),注入相位测试仅 activate()
|
||||
/// attach 到该进程——v4 教训:XCUITest launchEnvironment 的 DYLD_INSERT 经
|
||||
/// SpringBoard 启动链被剥离,门禁不触发。各相位以 -only-testing 分批执行(v6 序,
|
||||
/// XCUITest↔devicectl 切换仅 2 次):干净批 A1/A2(游客态)→ 注入批 B1/B2(游客)
|
||||
/// → 干净批 C1(放行证明)→ 注入批 D1/E1(登录态,未登成则游客守卫跳过)。
|
||||
/// v5e 教训:devicectl `--console` 通道在连续会话后整体卡死(零输出+进程即死),
|
||||
/// 注入启动不用 console,注入生效由测试内门禁 toast 端到端自证。
|
||||
/// 教训(B2 首版崩溃):营销弹窗自动消失瞬间盲点「rd pop close」会落到其下方的
|
||||
/// 首页搜索按钮,触发路由重复注册 assertion 崩溃(业务既有 bug)——先等自然消失再点,
|
||||
/// 且点击前复核存在与可点性。
|
||||
/// 凭证不入日志:截图遮盖输入框、文本树脱敏(沿用业务观察 Runner 做法)。
|
||||
final class IGGateRegressionTests: XCTestCase {
|
||||
private let bundleID = "cn.touchv.a4YX061"
|
||||
private var injectLib: String? { ProcessInfo.processInfo.environment["INJECT_LIB"] }
|
||||
private let blockLoginToast = "当前环境暂时无法登录,请稍后重试"
|
||||
private let blockVipToast = "当前环境暂时无法购买,请稍后重试"
|
||||
private let blockActivationToast = "当前环境暂时无法激活,请稍后重试"
|
||||
|
||||
override func setUpWithError() throws { continueAfterFailure = false }
|
||||
|
||||
// MARK: - 工具
|
||||
|
||||
/// 脱敏截图(遮盖输入框)+ 脱敏文本树,全部 keepAlways 留证。
|
||||
private func capture(_ app: XCUIApplication, _ name: String) {
|
||||
let source = app.screenshot().image
|
||||
let fields = app.textFields.allElementsBoundByIndex + app.secureTextFields.allElementsBoundByIndex
|
||||
let screenshotImage = UIGraphicsImageRenderer(size: source.size).image { context in
|
||||
source.draw(at: .zero)
|
||||
UIColor.lightGray.setFill()
|
||||
let sx = source.size.width / app.frame.width
|
||||
let sy = source.size.height / app.frame.height
|
||||
for field in fields {
|
||||
let frame = field.frame
|
||||
context.fill(CGRect(x: frame.minX * sx, y: frame.minY * sy,
|
||||
width: frame.width * sx, height: frame.height * sy))
|
||||
}
|
||||
}
|
||||
let screenshot = XCTAttachment(image: screenshotImage)
|
||||
screenshot.name = name
|
||||
screenshot.lifetime = .keepAlways
|
||||
add(screenshot)
|
||||
let redactedTree = app.debugDescription.components(separatedBy: "\n").map { line in
|
||||
guard line.contains("TextField"), let value = line.range(of: ", value:") else { return line }
|
||||
return String(line[..<value.lowerBound]) + ", value: [redacted]"
|
||||
}.joined(separator: "\n")
|
||||
let tree = XCTAttachment(string: redactedTree)
|
||||
tree.name = name + "-accessibility"
|
||||
tree.lifetime = .keepAlways
|
||||
add(tree)
|
||||
}
|
||||
|
||||
private func step(_ message: String) {
|
||||
NSLog("[GateRegression] %@", message)
|
||||
}
|
||||
|
||||
private func launchApp(_ app: XCUIApplication, injected: Bool) throws {
|
||||
if injected {
|
||||
// v4 教训:XCUITest launchEnvironment 的 DYLD_INSERT_LIBRARIES 经 SpringBoard
|
||||
// 启动链被剥离(B1 门禁 toast 不出现)——注入进程由编排器以 devicectl
|
||||
// `-e` 调试启动通道预先启动,测试只 attach(activate 不重启,注入保持)。
|
||||
guard app.state == .runningForeground || app.state == .runningBackground else {
|
||||
try skipAndCapture("注入进程未运行(编排器须先 devicectl 注入启动本 App)")
|
||||
}
|
||||
app.activate()
|
||||
XCTAssertTrue(app.wait(for: .runningForeground, timeout: 30), "注入进程未进前台")
|
||||
return
|
||||
}
|
||||
app.terminate()
|
||||
app.launch()
|
||||
XCTAssertTrue(app.wait(for: .runningForeground, timeout: 40), "应用未进入前台")
|
||||
}
|
||||
|
||||
private func skipAndCapture(_ reason: String) throws -> Never {
|
||||
step("SKIP: \(reason)")
|
||||
throw XCTSkip(reason)
|
||||
}
|
||||
|
||||
/// 等待登录页或首页锚点,返回 "login" / "home" / "unknown"。
|
||||
private func waitLoginOrHome(_ app: XCUIApplication, timeout: TimeInterval = 25) -> String {
|
||||
if app.otherElements["login_page_anchor"].waitForExistence(timeout: timeout) { return "login" }
|
||||
if app.otherElements["home_page_anchor"].waitForExistence(timeout: 10) { return "home" }
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
/// 关闭可能遮挡的营销弹窗:先等自然消失(约 6 秒),仍在且可点才点关闭。
|
||||
/// 不盲点:弹窗消失瞬间点击会落到其下方控件(首版曾误触首页搜索引发路由崩溃)。
|
||||
private func dismissPopups(_ app: XCUIApplication) {
|
||||
let popupClose = app.buttons["rd pop close"]
|
||||
if popupClose.waitForNonExistence(timeout: 6) { return }
|
||||
if popupClose.exists && popupClose.isHittable {
|
||||
popupClose.tap()
|
||||
_ = popupClose.waitForNonExistence(timeout: 3)
|
||||
}
|
||||
}
|
||||
|
||||
/// 勾选登录协议(v3 登录页树:勾选框暴露 identifier login_agreement_checkbox)。
|
||||
private func selectAgreementIfNeeded(_ app: XCUIApplication) {
|
||||
let agreement = app.otherElements["login_agreement_view"]
|
||||
_ = agreement.waitForExistence(timeout: 10)
|
||||
let checkbox = app.buttons["login_agreement_checkbox"].firstMatch
|
||||
if checkbox.exists {
|
||||
if checkbox.isHittable { checkbox.tap() }
|
||||
step("已点击协议勾选框")
|
||||
} else {
|
||||
let fallback = agreement.buttons.firstMatch
|
||||
if fallback.exists, fallback.isHittable {
|
||||
fallback.tap()
|
||||
step("勾选框无 identifier,已点协议视图内按钮")
|
||||
} else {
|
||||
step("协议勾选框未暴露,跳过勾选")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 断言门禁 toast 出现并等其消失。
|
||||
private func assertToast(_ app: XCUIApplication, text: String, label: String) {
|
||||
let toast = app.staticTexts[text].firstMatch
|
||||
XCTAssertTrue(toast.waitForExistence(timeout: 6), "\(label):未出现门禁 toast「\(text)」")
|
||||
capture(app, label + "-toast")
|
||||
_ = toast.waitForNonExistence(timeout: 8)
|
||||
}
|
||||
|
||||
/// 首页就绪并稳定(弹窗处理完成)。
|
||||
private func waitHomeStable(_ app: XCUIApplication, timeout: TimeInterval = 30) throws {
|
||||
XCTAssertTrue(app.otherElements["home_page_anchor"].waitForExistence(timeout: timeout), "未进入首页")
|
||||
dismissPopups(app)
|
||||
}
|
||||
|
||||
/// 游客态从首页导航到登录页:「我的」页「登录/注册」按钮(v2 勘察树确认)。
|
||||
/// 返回 false 表示入口不可达(多为已登录态),由调用方决定跳过或走既有会话判定。
|
||||
/// v3 教训:启动偶发落在无 tab bar 的推广落地页(AllTypes 书城页)——
|
||||
/// 先等待/返回自救,仍无 tab 则重启一次重抽落地页。
|
||||
private func navigateToLoginFromHome(_ app: XCUIApplication, allowRelaunch: Bool = true) -> Bool {
|
||||
func attempt() -> Bool {
|
||||
let mineTab = app.tabBars.buttons["我的"].firstMatch
|
||||
if !mineTab.waitForExistence(timeout: 12) {
|
||||
// 落地页自救:点导航返回键(若在二级页)后再等 tab。
|
||||
let back = app.buttons["nav black goback"].firstMatch
|
||||
if back.exists, back.isHittable {
|
||||
back.tap()
|
||||
step("落地页无 tab,已点返回")
|
||||
}
|
||||
if !mineTab.waitForExistence(timeout: 12) { return false }
|
||||
}
|
||||
mineTab.tap()
|
||||
_ = app.otherElements["personal_center_page_anchor"].waitForExistence(timeout: 10)
|
||||
dismissPopups(app)
|
||||
let guestEntry = app.buttons["登录/注册"].firstMatch
|
||||
guard guestEntry.waitForExistence(timeout: 8), guestEntry.isHittable else { return false }
|
||||
guestEntry.tap()
|
||||
return app.otherElements["login_page_anchor"].waitForExistence(timeout: 20)
|
||||
}
|
||||
if attempt() { return true }
|
||||
guard allowRelaunch else { return false }
|
||||
step("首轮导航失败,重启重抽落地页")
|
||||
app.terminate()
|
||||
app.launch()
|
||||
guard app.wait(for: .runningForeground, timeout: 40) else { return false }
|
||||
_ = app.otherElements["home_page_anchor"].waitForExistence(timeout: 25)
|
||||
dismissPopups(app)
|
||||
return attempt()
|
||||
}
|
||||
|
||||
// MARK: - A 勘察与登出
|
||||
|
||||
func testA1InspectCleanState() throws {
|
||||
let app = XCUIApplication(bundleIdentifier: bundleID)
|
||||
step("A1 干净启动勘察开始,INJECT_LIB=\(injectLib ?? "未传入")")
|
||||
try launchApp(app, injected: false)
|
||||
let state = waitLoginOrHome(app)
|
||||
step("A1 启动状态=\(state)")
|
||||
if state == "home" { dismissPopups(app) }
|
||||
capture(app, "a1-clean-\(state)")
|
||||
}
|
||||
|
||||
func testA2LogoutIfNeeded() throws {
|
||||
let app = XCUIApplication(bundleIdentifier: bundleID)
|
||||
step("A2 确保登录页可达(游客直进;登录态经设置页登出)")
|
||||
try launchApp(app, injected: false)
|
||||
let state = waitLoginOrHome(app)
|
||||
if state == "login" {
|
||||
step("A2 已在登录页")
|
||||
capture(app, "a2-already-login")
|
||||
return
|
||||
}
|
||||
guard state == "home" else { try skipAndCapture("A2 首页不可达(状态 \(state))") }
|
||||
dismissPopups(app)
|
||||
let mineTab = app.tabBars.buttons["我的"].firstMatch
|
||||
XCTAssertTrue(mineTab.waitForExistence(timeout: 10), "未找到「我的」页签")
|
||||
mineTab.tap()
|
||||
_ = app.otherElements["personal_center_page_anchor"].waitForExistence(timeout: 10)
|
||||
sleep(2)
|
||||
dismissPopups(app)
|
||||
capture(app, "a2-mine-page")
|
||||
// 游客态(v2 树:登录/注册按钮)直接进登录页,B 阶段即可测登录门禁。
|
||||
let guestEntry = app.buttons["登录/注册"].firstMatch
|
||||
if guestEntry.exists, guestEntry.isHittable {
|
||||
guestEntry.tap()
|
||||
XCTAssertTrue(app.otherElements["login_page_anchor"].waitForExistence(timeout: 20), "游客点「登录/注册」未进入登录页")
|
||||
step("A2 游客态进入登录页")
|
||||
capture(app, "a2-guest-login-page")
|
||||
return
|
||||
}
|
||||
// 登录态:右上角设置图标(v2 树:personalCenter setting)→ 设置页底部「退出登录」。
|
||||
let settingIcon = app.buttons["personalCenter setting"].firstMatch
|
||||
XCTAssertTrue(settingIcon.exists && settingIcon.isHittable, "未找到设置入口(见 a2 勘察树)")
|
||||
settingIcon.tap()
|
||||
sleep(2)
|
||||
capture(app, "a2-settings-page")
|
||||
// 退出登录在设置列表尾部,滚动查找(cell 标签为文本)。
|
||||
var confirmedLogout = false
|
||||
for _ in 0..<4 where !confirmedLogout {
|
||||
let logoutBtn = app.buttons.containing(NSPredicate(format: "label CONTAINS '退出登录'")).firstMatch
|
||||
let logoutText = app.staticTexts.containing(NSPredicate(format: "label CONTAINS '退出登录'")).firstMatch
|
||||
if logoutBtn.exists { logoutBtn.tap(); confirmedLogout = true }
|
||||
else if logoutText.exists { logoutText.tap(); confirmedLogout = true }
|
||||
else { app.swipeUp() }
|
||||
}
|
||||
XCTAssertTrue(confirmedLogout, "设置页未找到退出登录入口(见 a2-settings-page 树)")
|
||||
sleep(1)
|
||||
capture(app, "a2-logout-confirm")
|
||||
// 确认弹窗(自定义两键弹窗,右侧确认键常见文案逐个尝试)。
|
||||
for confirm in ["确定", "退出", "确认", "退出登录"] {
|
||||
let button = app.buttons[confirm].firstMatch
|
||||
if button.waitForExistence(timeout: 2) && button.isHittable {
|
||||
button.tap()
|
||||
step("A2 确认退出(「\(confirm)」)")
|
||||
break
|
||||
}
|
||||
}
|
||||
let back = waitLoginOrHome(app, timeout: 30)
|
||||
step("A2 登出后状态=\(back)")
|
||||
capture(app, "a2-after-logout-\(back)")
|
||||
XCTAssertEqual(back, "login", "登出后未回到登录页")
|
||||
}
|
||||
|
||||
// MARK: - B 拦截相位(注入启动·登录入口)
|
||||
|
||||
func testB1BlockPasswordLogin() throws {
|
||||
let app = XCUIApplication(bundleIdentifier: bundleID)
|
||||
step("B1 注入启动·密码登录门禁")
|
||||
try launchApp(app, injected: true)
|
||||
// 注入相位严禁 clean 重启(activate 之外的 launch 会丢 DYLD 注入),
|
||||
// navigate 不带 relaunch 自救;导航失败即跳过留证。
|
||||
var state = waitLoginOrHome(app)
|
||||
if state == "home", navigateToLoginFromHome(app, allowRelaunch: false) { state = "login" }
|
||||
capture(app, "b1-inject-\(state)")
|
||||
guard state == "login" else {
|
||||
try skipAndCapture("B1 登录页不可达(状态 \(state),游客入口缺失)")
|
||||
}
|
||||
capture(app, "b1-login-page")
|
||||
// 门禁在输入校验之前:空输入点击提交也必须先命中门禁 toast。
|
||||
let submit = app.buttons["login_submit_button"]
|
||||
XCTAssertTrue(submit.waitForExistence(timeout: 10), "未找到登录提交按钮")
|
||||
submit.tap()
|
||||
assertToast(app, text: blockLoginToast, label: "b1-block-password-login")
|
||||
// 门禁 toast 之外不应出现协议弹窗(出现说明执行越过了门禁)。
|
||||
let agreementAlert = app.alerts["请先阅读并同意协议"]
|
||||
XCTAssertFalse(agreementAlert.waitForExistence(timeout: 2), "点击越过了门禁(出现协议弹窗)")
|
||||
capture(app, "b1-block-after")
|
||||
}
|
||||
|
||||
func testB2BlockOtherLogins() throws {
|
||||
let app = XCUIApplication(bundleIdentifier: bundleID)
|
||||
step("B2 注入启动·第三方登录门禁(微信/QQ/Apple/Weread)")
|
||||
try launchApp(app, injected: true)
|
||||
var state = waitLoginOrHome(app)
|
||||
if state == "home", navigateToLoginFromHome(app, allowRelaunch: false) { state = "login" }
|
||||
guard state == "login" else {
|
||||
try skipAndCapture("B2 登录页不可达(状态 \(state),游客入口缺失)")
|
||||
}
|
||||
selectAgreementIfNeeded(app)
|
||||
capture(app, "b2-login-page")
|
||||
// v3 登录页树:第三方按钮为纯图片,label 即图片名(rd login wechat/qq/apple/wjOauth2)。
|
||||
var tapped = 0
|
||||
for label in ["rd login wechat", "rd login qq", "rd login apple", "rd login wjOauth2"] {
|
||||
let entry = app.buttons[label].firstMatch
|
||||
guard entry.waitForExistence(timeout: 3), entry.isHittable else { continue }
|
||||
entry.tap()
|
||||
tapped += 1
|
||||
step("B2 点击第三方入口「\(label)」")
|
||||
assertToast(app, text: blockLoginToast, label: "b2-block-\(label)")
|
||||
}
|
||||
if tapped == 0 {
|
||||
capture(app, "b2-no-third-party-buttons")
|
||||
try skipAndCapture("登录页未暴露可识别的第三方登录按钮(见 b2-login-page 树)")
|
||||
}
|
||||
step("B2 完成,拦截入口数=\(tapped)")
|
||||
}
|
||||
|
||||
// MARK: - C 放行相位(干净启动·真实登录)
|
||||
|
||||
func testC1AllowPasswordLogin() throws {
|
||||
let app = XCUIApplication(bundleIdentifier: bundleID)
|
||||
step("C1 干净启动·密码登录放行")
|
||||
try launchApp(app, injected: false)
|
||||
let bootState = waitLoginOrHome(app)
|
||||
var loginReached = bootState == "login"
|
||||
if !loginReached, bootState == "home" {
|
||||
// 游客态(home ≠ 已登录)也从「我的」页进入登录页做真实登录。
|
||||
loginReached = navigateToLoginFromHome(app)
|
||||
}
|
||||
if !loginReached {
|
||||
step("C1 登录页不可达且我的页无「登录/注册」(已登录态),放行以启动期零拦截与既有会话为证")
|
||||
capture(app, "c1-already-home")
|
||||
return
|
||||
}
|
||||
capture(app, "c1-login-page")
|
||||
selectAgreementIfNeeded(app)
|
||||
let submit = app.buttons["login_submit_button"]
|
||||
XCTAssertTrue(submit.waitForExistence(timeout: 10), "未找到登录提交按钮")
|
||||
if !submit.isEnabled {
|
||||
// 提交钮不可用才尝试补输入(v5d 教训:验证码框存在不代表必填,
|
||||
// 盲填占位值反而制造服务端拒绝)。先补图形验证码占位值,再退化到账号框刷新。
|
||||
let captcha = app.textFields.containing(NSPredicate(format: "placeholderValue CONTAINS '验证码'")).firstMatch
|
||||
if captcha.exists {
|
||||
captcha.tap()
|
||||
captcha.typeText("1111")
|
||||
step("C1 提交钮不可用,已补图形验证码占位值 isEnabled=\(submit.isEnabled)")
|
||||
}
|
||||
if !submit.isEnabled {
|
||||
let account = app.textFields["login_phone_input"].firstMatch
|
||||
if account.exists { account.tap(); account.typeText("1") }
|
||||
step("C1 仍不可用,已触发账号输入刷新 isEnabled=\(submit.isEnabled)")
|
||||
}
|
||||
}
|
||||
capture(app, "c1-before-submit")
|
||||
submit.tap()
|
||||
// 放行判定(v6 修订):核心断言 = 门禁 toast 不出现(门禁放行)。
|
||||
// 业务进展尽力而为留证:DEBUG 预填账号的图形验证码无法自动识别,服务端
|
||||
// 拒绝时停留登录页属业务侧限制而非门禁问题(v5e 留证:干净提交后门禁
|
||||
// toast 与协议弹窗均未出现)。登录态若未建立,D1/E1 以游客守卫跳过。
|
||||
let gateToast = app.staticTexts[blockLoginToast].firstMatch
|
||||
XCTAssertFalse(gateToast.waitForExistence(timeout: 6), "干净环境出现门禁 toast(误拦截)")
|
||||
let home = app.otherElements["home_page_anchor"]
|
||||
let agreementAlert = app.alerts["请先阅读并同意协议"]
|
||||
let progress = home.waitForExistence(timeout: 45)
|
||||
|| agreementAlert.waitForExistence(timeout: 5)
|
||||
step("C1 门禁放行成立;业务进展标记=\(progress)(验证码服务端拒绝属业务侧限制)")
|
||||
capture(app, "c1-after-login-attempt")
|
||||
}
|
||||
|
||||
// MARK: - D/E 拦截相位(注入启动·VIP 与激活入口)
|
||||
|
||||
func testD1BlockVipPurchase() throws {
|
||||
let app = XCUIApplication(bundleIdentifier: bundleID)
|
||||
step("D1 注入启动·VIP 购买门禁")
|
||||
try launchApp(app, injected: true)
|
||||
try waitHomeStable(app, timeout: 90)
|
||||
let vipTab = app.tabBars.buttons["会员"].firstMatch
|
||||
XCTAssertTrue(vipTab.waitForExistence(timeout: 10), "未找到「会员」页签")
|
||||
vipTab.tap()
|
||||
// v3 树:会员页用户区游客显示「游客」——登录态缺失时购买被业务游客检查
|
||||
// 拦在 sendPayVip 门禁之前,skip 留证而不误判门禁失效。
|
||||
_ = app.staticTexts["游客"].waitForExistence(timeout: 5)
|
||||
if app.staticTexts["游客"].firstMatch.exists {
|
||||
capture(app, "d1-guest-state")
|
||||
try skipAndCapture("会员页为游客态(C1 未建立登录态),VIP 门禁需登录后重跑")
|
||||
}
|
||||
// v2 树:购买按钮为富文本 label(如「立即购买 · ¥6.00 100.00」),已会员时为「立即续费 …」。
|
||||
let buyPred = NSPredicate(format: "label BEGINSWITH '立即购买' OR label BEGINSWITH '立即续费'")
|
||||
let buyBtn = app.buttons.containing(buyPred).firstMatch
|
||||
XCTAssertTrue(buyBtn.waitForExistence(timeout: 15), "会员页未出现购买按钮(见 d1 勘察树)")
|
||||
sleep(2)
|
||||
dismissPopups(app)
|
||||
capture(app, "d1-vip-page")
|
||||
// 先勾选 VIP 协议(未勾选时点购买先弹协议提示,越不过门禁汇合点)。
|
||||
let checkbox = app.buttons["rd vip checkbox unselect"].firstMatch
|
||||
if checkbox.exists, checkbox.isHittable {
|
||||
checkbox.tap()
|
||||
step("D1 已勾选 VIP 协议")
|
||||
} else {
|
||||
capture(app, "d1-checkbox-missing")
|
||||
}
|
||||
buyBtn.tap()
|
||||
step("D1 点击购买按钮「\(buyBtn.label)」")
|
||||
assertToast(app, text: blockVipToast, label: "d1-block-vip")
|
||||
}
|
||||
|
||||
func testE1BlockActivation() throws {
|
||||
let app = XCUIApplication(bundleIdentifier: bundleID)
|
||||
step("E1 注入启动·激活码门禁")
|
||||
try launchApp(app, injected: true)
|
||||
try waitHomeStable(app, timeout: 90)
|
||||
let mineTab = app.tabBars.buttons["我的"].firstMatch
|
||||
XCTAssertTrue(mineTab.waitForExistence(timeout: 10), "未找到「我的」页签")
|
||||
mineTab.tap()
|
||||
sleep(2)
|
||||
dismissPopups(app)
|
||||
capture(app, "e1-mine-page")
|
||||
// 激活入口探测(标签以勘察树为准)。
|
||||
var activationEntered = false
|
||||
for keyword in ["激活码", "激活"] {
|
||||
let entryBtn = app.buttons.containing(NSPredicate(format: "label CONTAINS %@", keyword)).firstMatch
|
||||
let entryText = app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", keyword)).firstMatch
|
||||
if entryBtn.exists { entryBtn.tap(); activationEntered = true; step("E1 点击「\(keyword)」按钮入口"); break }
|
||||
if entryText.exists { entryText.tap(); activationEntered = true; step("E1 点击「\(keyword)」文本入口"); break }
|
||||
}
|
||||
guard activationEntered else {
|
||||
capture(app, "e1-no-activation-entry")
|
||||
try skipAndCapture("「我的」页未找到激活入口,需按勘察树修正导航")
|
||||
}
|
||||
sleep(2)
|
||||
// v3 教训:游客点「激活码」被带到登录页(激活需登录态)——先判定落点。
|
||||
if app.otherElements["login_page_anchor"].waitForExistence(timeout: 5) {
|
||||
capture(app, "e1-guest-to-login")
|
||||
try skipAndCapture("激活入口要求登录态(C1 未建立登录会话),激活门禁需登录后重跑")
|
||||
}
|
||||
capture(app, "e1-activation-page")
|
||||
// 激活码输入(被拦截环境填占位值即可,请求不会发出)。
|
||||
let codeField = (app.textFields.firstMatch.exists ? app.textFields : app.secureTextFields).firstMatch
|
||||
if codeField.exists {
|
||||
codeField.tap()
|
||||
codeField.typeText("1")
|
||||
}
|
||||
var activated = false
|
||||
for label in ["立即激活", "激活", "确定"] {
|
||||
let button = app.buttons[label].firstMatch
|
||||
if button.exists, button.isHittable { button.tap(); activated = true; step("E1 点击激活按钮「\(label)」"); break }
|
||||
}
|
||||
XCTAssertTrue(activated, "激活页未找到激活按钮(见 e1-activation-page 树)")
|
||||
assertToast(app, text: blockActivationToast, label: "e1-block-activation")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user