在 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>
232 lines
10 KiB
Swift
232 lines
10 KiB
Swift
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()
|
|
}
|
|
|
|
}
|