tlsLibHunter 0.3.2__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/CHANGELOG.md +40 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/MANIFEST.in +1 -0
- {tlslibhunter-0.3.2/tlsLibHunter.egg-info → tlslibhunter-0.4.0}/PKG-INFO +26 -2
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/README.md +25 -1
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/setup.py +1 -0
- tlslibhunter-0.4.0/tests/test_discover_cli.py +92 -0
- tlslibhunter-0.4.0/tests/test_discovery_engine.py +269 -0
- tlslibhunter-0.4.0/tests/test_discovery_handoff.py +68 -0
- tlslibhunter-0.4.0/tests/test_discovery_probe.py +257 -0
- tlslibhunter-0.4.0/tests/test_discovery_profile.py +92 -0
- tlslibhunter-0.4.0/tests/test_discovery_shared_delegates.py +33 -0
- tlslibhunter-0.4.0/tests/test_discovery_sockets.py +161 -0
- tlslibhunter-0.4.0/tests/test_discovery_text.py +101 -0
- tlslibhunter-0.4.0/tests/test_discovery_tls_libs.py +124 -0
- tlslibhunter-0.4.0/tests/test_discovery_topology.py +67 -0
- tlslibhunter-0.4.0/tests/test_discovery_uids.py +56 -0
- tlslibhunter-0.4.0/tests/test_discovery_watch.py +202 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0/tlsLibHunter.egg-info}/PKG-INFO +26 -2
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlsLibHunter.egg-info/SOURCES.txt +27 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/about.py +1 -1
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/backends/frida_backend.py +4 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/cli.py +11 -0
- tlslibhunter-0.4.0/tlslibhunter/discover_cli.py +261 -0
- tlslibhunter-0.4.0/tlslibhunter/discovery/__init__.py +1 -0
- tlslibhunter-0.4.0/tlslibhunter/discovery/binder_descriptors.json +34 -0
- tlslibhunter-0.4.0/tlslibhunter/discovery/engine.py +465 -0
- tlslibhunter-0.4.0/tlslibhunter/discovery/handoff.py +111 -0
- tlslibhunter-0.4.0/tlslibhunter/discovery/probe.py +258 -0
- tlslibhunter-0.4.0/tlslibhunter/discovery/probe_agent.js +13732 -0
- tlslibhunter-0.4.0/tlslibhunter/discovery/profile.py +85 -0
- tlslibhunter-0.4.0/tlslibhunter/discovery/shared_delegates.json +13 -0
- tlslibhunter-0.4.0/tlslibhunter/discovery/shared_delegates.py +25 -0
- tlslibhunter-0.4.0/tlslibhunter/discovery/sockets.py +157 -0
- tlslibhunter-0.4.0/tlslibhunter/discovery/text.py +47 -0
- tlslibhunter-0.4.0/tlslibhunter/discovery/topology.py +72 -0
- tlslibhunter-0.4.0/tlslibhunter/discovery/uids.py +52 -0
- tlslibhunter-0.4.0/tlslibhunter/discovery/watch.py +132 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/LICENSE +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/pyproject.toml +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/setup.cfg +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_adb.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_android_extractor_serial.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_android_process.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_android_related.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_classifier.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_cli.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_config.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_encoding.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_evidence_classification.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_fingerprints.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_memory_extractor.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_module_scanner_gates.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_multi_process.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_native_dsc_extractor.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_output_formatters.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_pipeline_filtering.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_platform_overrides.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_reattach_session_adoption.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_resource_release.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_scan_truncation.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_tls_indicators.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_unfreeze_attach.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tests/test_wrong_target_attach.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlsLibHunter.egg-info/dependency_links.txt +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlsLibHunter.egg-info/entry_points.txt +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlsLibHunter.egg-info/requires.txt +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlsLibHunter.egg-info/top_level.txt +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/__init__.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/__main__.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/backends/__init__.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/backends/base.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/config.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/extractor/__init__.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/extractor/android_extractor.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/extractor/base.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/extractor/disk_extractor.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/extractor/dyld_cache_extractor.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/extractor/ios_extractor.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/extractor/memory_extractor.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/extractor/native_dsc_extractor.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/extractor/strategy.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/hunter.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/multi_process.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/output/__init__.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/output/_utils.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/output/json_formatter.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/output/plain_formatter.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/output/table_formatter.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/platforms/__init__.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/platforms/android.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/platforms/base.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/platforms/detection.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/platforms/ios.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/platforms/linux.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/platforms/macos.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/platforms/windows.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/scanner/__init__.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/scanner/classifier.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/scanner/fingerprints.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/scanner/module_scanner.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/scanner/results.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/scanner/tls_indicators.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/scripts/extractor_agent.js +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/scripts/scanner_agent.js +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/utils/__init__.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/utils/adb.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/utils/android_process.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/utils/android_related.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/utils/encoding.py +0 -0
- {tlslibhunter-0.3.2 → tlslibhunter-0.4.0}/tlslibhunter/utils/process_resolver.py +0 -0
|
@@ -5,6 +5,46 @@ All notable changes to tlsLibHunter will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
6
6
|
This file starts at 0.2.9; earlier versions are documented only in git history.
|
|
7
7
|
|
|
8
|
+
## [0.4.0]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **`tlsLibHunter discover <app>`** (Android) — finds the processes that
|
|
12
|
+
carry an app's TLS traffic without attaching Frida: samples the device
|
|
13
|
+
(`ps`, `pm list packages -U`, `/proc/net/{tcp,tcp6,udp,udp6}`, `dumpsys`)
|
|
14
|
+
for `--duration` seconds every `--interval` seconds and prints each
|
|
15
|
+
candidate with its role and evidence, or with `--json` / `--write-profile`
|
|
16
|
+
a capture profile (schema `tlslibhunter.profile/1`: gate packages, process
|
|
17
|
+
patterns, device fingerprint, versionCode, candidates).
|
|
18
|
+
- **Topology**: roles `target`, `sibling` (same app UID), `delegate`,
|
|
19
|
+
`sdk_sandbox` and `shared_system` (GMS, Play Store, ...).
|
|
20
|
+
- **Socket ownership**: with root, sockets are attributed per PID through
|
|
21
|
+
the socket inode → PID map from `/proc/<pid>/fd` (`net:tcp:443`,
|
|
22
|
+
`net:udp-connected:443`, ...); without root only per UID
|
|
23
|
+
(`net:uid-attributed`, port 443).
|
|
24
|
+
- **Hand-off**: the package hosting the foreground UI (`foreground_host`)
|
|
25
|
+
and services bound by the target in `dumpsys activity oom`
|
|
26
|
+
(`oom_bound_by:<process>`) make delegates. Shared system delegates are
|
|
27
|
+
never promoted to attributable candidates or gate packages; they are kept
|
|
28
|
+
only with a TLS socket of their own.
|
|
29
|
+
- **TLS-library confirmation** (root) — each attributable candidate's
|
|
30
|
+
`/proc/<pid>/maps` adds `tls_lib:` evidence and may mark it `confirmed`.
|
|
31
|
+
The zygote-preloaded Conscrypt `libssl.so` and tethering
|
|
32
|
+
`libhttpengine.so` are mapped into every app process and count only as weak
|
|
33
|
+
evidence (confirmed together with a TLS socket of that process).
|
|
34
|
+
- **`discover --probe`** — a small Frida agent attached to the running app
|
|
35
|
+
(launched if needed, thawed if frozen) records the binder interfaces it
|
|
36
|
+
calls and its `connect()`s; packages behind known interfaces
|
|
37
|
+
(`binder_descriptors.json`) become delegates with `handoff:binder:<descriptor>`
|
|
38
|
+
evidence, unmapped interfaces are listed in the profile's
|
|
39
|
+
`binder_descriptors` (escaped, capped).
|
|
40
|
+
- **`discover --watch`** — follows process churn (restarts, new delegates)
|
|
41
|
+
without Frida: one JSON line per event on stdout (schema
|
|
42
|
+
`tlslibhunter.watch/1`: `event`, `pid`, `process`, `package`, `role`,
|
|
43
|
+
`evidence`, `ts`) for `process_added`, `process_restarted`, `process_gone`
|
|
44
|
+
and `evidence_added`, until Ctrl+C (exit 0) or `--duration` when given.
|
|
45
|
+
- **Package-name validation** — package names are validated before they
|
|
46
|
+
reach an `adb shell` command line.
|
|
47
|
+
|
|
8
48
|
## [0.3.2]
|
|
9
49
|
|
|
10
50
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tlsLibHunter
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Identifies TLS/SSL libraries in running processes using Frida-based dynamic instrumentation.
|
|
5
5
|
Home-page: https://github.com/monkeywave/tlsLibHunter
|
|
6
6
|
Author: Daniel Baier
|
|
@@ -46,7 +46,7 @@ Dynamic: summary
|
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
# TLSLibHunter
|
|
49
|
-
 [](https://badge.fury.io/py/tlslibhunter) [](https://github.com/monkeywave/tlsLibHunter/actions/workflows/publish.yml)
|
|
50
50
|
[](https://github.com/monkeywave/tlsLibHunter/actions/workflows/lint.yml)
|
|
51
51
|
|
|
52
52
|
|
|
@@ -155,6 +155,30 @@ continue. Each process gets its usual results table, followed by a combined summ
|
|
|
155
155
|
Extracted libraries go to `./tls_libs_<pid>` per related process, or to `<DIR>/<pid>` with
|
|
156
156
|
`-o DIR`. On other platforms the flag logs a warning and only the target is scanned.
|
|
157
157
|
|
|
158
|
+
## Process discovery (Android)
|
|
159
|
+
|
|
160
|
+
`tlsLibHunter discover <app>` finds the processes that carry an app's TLS traffic, without
|
|
161
|
+
attaching Frida. It samples the device (`ps`, `/proc/net`, `dumpsys`) and lists every candidate
|
|
162
|
+
with its role (`target`, `sibling`, `delegate`, `sdk_sandbox`, `shared_system`) and evidence
|
|
163
|
+
(TLS sockets, foreground UI host, oom bindings, mapped TLS libraries with root).
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
# Sample for 20 s (default) while you use the app; print the candidate table
|
|
167
|
+
tlsLibHunter discover com.google.android.apps.bard --serial ABC123
|
|
168
|
+
|
|
169
|
+
# Save a capture profile (schema tlslibhunter.profile/1)
|
|
170
|
+
tlsLibHunter discover Gemini --duration 30 --json --write-profile gemini.profile.json
|
|
171
|
+
|
|
172
|
+
# Also learn delegates from the binder interfaces the app calls (Frida probe)
|
|
173
|
+
tlsLibHunter discover Gemini --probe
|
|
174
|
+
|
|
175
|
+
# Follow restarts and new delegates: one JSON line (tlslibhunter.watch/1) per event, Ctrl+C to stop
|
|
176
|
+
tlsLibHunter discover Gemini --watch --interval 2
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Shared system processes (GMS, Play Store, ...) are reported but never promoted to gate packages,
|
|
180
|
+
because their traffic mixes many apps. Without root, sockets are attributed per UID only.
|
|
181
|
+
|
|
158
182
|
## Result filtering & scan depth
|
|
159
183
|
|
|
160
184
|
By default the results table is curated to show only **genuine, hookable TLS stacks** so the
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
# TLSLibHunter
|
|
9
|
-
 [](https://badge.fury.io/py/tlslibhunter) [](https://github.com/monkeywave/tlsLibHunter/actions/workflows/publish.yml)
|
|
10
10
|
[](https://github.com/monkeywave/tlsLibHunter/actions/workflows/lint.yml)
|
|
11
11
|
|
|
12
12
|
|
|
@@ -115,6 +115,30 @@ continue. Each process gets its usual results table, followed by a combined summ
|
|
|
115
115
|
Extracted libraries go to `./tls_libs_<pid>` per related process, or to `<DIR>/<pid>` with
|
|
116
116
|
`-o DIR`. On other platforms the flag logs a warning and only the target is scanned.
|
|
117
117
|
|
|
118
|
+
## Process discovery (Android)
|
|
119
|
+
|
|
120
|
+
`tlsLibHunter discover <app>` finds the processes that carry an app's TLS traffic, without
|
|
121
|
+
attaching Frida. It samples the device (`ps`, `/proc/net`, `dumpsys`) and lists every candidate
|
|
122
|
+
with its role (`target`, `sibling`, `delegate`, `sdk_sandbox`, `shared_system`) and evidence
|
|
123
|
+
(TLS sockets, foreground UI host, oom bindings, mapped TLS libraries with root).
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Sample for 20 s (default) while you use the app; print the candidate table
|
|
127
|
+
tlsLibHunter discover com.google.android.apps.bard --serial ABC123
|
|
128
|
+
|
|
129
|
+
# Save a capture profile (schema tlslibhunter.profile/1)
|
|
130
|
+
tlsLibHunter discover Gemini --duration 30 --json --write-profile gemini.profile.json
|
|
131
|
+
|
|
132
|
+
# Also learn delegates from the binder interfaces the app calls (Frida probe)
|
|
133
|
+
tlsLibHunter discover Gemini --probe
|
|
134
|
+
|
|
135
|
+
# Follow restarts and new delegates: one JSON line (tlslibhunter.watch/1) per event, Ctrl+C to stop
|
|
136
|
+
tlsLibHunter discover Gemini --watch --interval 2
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Shared system processes (GMS, Play Store, ...) are reported but never promoted to gate packages,
|
|
140
|
+
because their traffic mixes many apps. Without root, sockets are attributed per UID only.
|
|
141
|
+
|
|
118
142
|
## Result filtering & scan depth
|
|
119
143
|
|
|
120
144
|
By default the results table is curated to show only **genuine, hookable TLS stacks** so the
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""Tests for the ``tlsLibHunter discover`` subcommand."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from tests.conftest import FixtureRunner
|
|
8
|
+
from tlslibhunter import cli, discover_cli
|
|
9
|
+
|
|
10
|
+
BARD = "com.google.android.apps.bard"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TestDiscoverParser:
|
|
14
|
+
def test_defaults(self):
|
|
15
|
+
args = discover_cli.build_discover_parser().parse_args([BARD])
|
|
16
|
+
assert (args.app, args.duration, args.interval, args.json) == (BARD, None, 2.0, False)
|
|
17
|
+
assert discover_cli.sampling_duration(args) == 20.0 and args.watch is False
|
|
18
|
+
assert args.write_profile is None and args.serial is None
|
|
19
|
+
|
|
20
|
+
def test_all_options(self):
|
|
21
|
+
args = discover_cli.build_discover_parser().parse_args(
|
|
22
|
+
[
|
|
23
|
+
"Gemini",
|
|
24
|
+
"--duration",
|
|
25
|
+
"30",
|
|
26
|
+
"--interval",
|
|
27
|
+
"1.5",
|
|
28
|
+
"--json",
|
|
29
|
+
"--write-profile",
|
|
30
|
+
"p.json",
|
|
31
|
+
"--serial",
|
|
32
|
+
"ABC",
|
|
33
|
+
]
|
|
34
|
+
)
|
|
35
|
+
assert (args.duration, args.interval, args.json, args.write_profile, args.serial) == (
|
|
36
|
+
30.0,
|
|
37
|
+
1.5,
|
|
38
|
+
True,
|
|
39
|
+
"p.json",
|
|
40
|
+
"ABC",
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class TestMainDispatch:
|
|
45
|
+
def test_discover_subcommand_is_dispatched(self, monkeypatch):
|
|
46
|
+
seen = []
|
|
47
|
+
monkeypatch.setattr(discover_cli, "discover_main", lambda argv: seen.append(argv) or 0)
|
|
48
|
+
assert cli.main(["discover", BARD, "--json"]) == 0
|
|
49
|
+
assert seen == [[BARD, "--json"]]
|
|
50
|
+
|
|
51
|
+
def test_regular_target_still_uses_scan_parser(self):
|
|
52
|
+
assert cli.build_parser().parse_args(["firefox", "-l"]).target == "firefox"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class TestResolvePackage:
|
|
56
|
+
def test_installed_package_is_used_as_is(self):
|
|
57
|
+
assert discover_cli.resolve_package(BARD, FixtureRunner(), None, frida_resolver=pytest.fail) == BARD
|
|
58
|
+
|
|
59
|
+
def test_label_resolved_via_frida(self):
|
|
60
|
+
resolved = discover_cli.resolve_package("Gemini", FixtureRunner(), "ABC", lambda app, serial: BARD)
|
|
61
|
+
assert resolved == BARD
|
|
62
|
+
|
|
63
|
+
def test_unknown_app_raises(self):
|
|
64
|
+
with pytest.raises(ValueError):
|
|
65
|
+
discover_cli.resolve_package("Nope", FixtureRunner(), None, lambda app, serial: "Nope")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class TestRunDiscover:
|
|
69
|
+
def run(self, argv, capsys):
|
|
70
|
+
args = discover_cli.build_discover_parser().parse_args(argv + ["--duration", "0"])
|
|
71
|
+
code = discover_cli.run_discover(args, runner=FixtureRunner())
|
|
72
|
+
return code, capsys.readouterr()
|
|
73
|
+
|
|
74
|
+
def test_table_output_and_cue(self, capsys):
|
|
75
|
+
code, out = self.run([BARD], capsys)
|
|
76
|
+
assert code == 0
|
|
77
|
+
assert "exercise the app now" in out.err
|
|
78
|
+
header = out.out.splitlines()[2]
|
|
79
|
+
assert header.split() == ["PROCESS", "PID", "ROLE", "TLS", "EVIDENCE"]
|
|
80
|
+
assert "net:udp-connected:443" in out.out
|
|
81
|
+
|
|
82
|
+
def test_json_output_and_profile_file(self, capsys, tmp_path):
|
|
83
|
+
path = tmp_path / "profile.json"
|
|
84
|
+
code, out = self.run([BARD, "--json", "--write-profile", str(path)], capsys)
|
|
85
|
+
assert code == 0
|
|
86
|
+
assert json.loads(out.out)["target_package"] == BARD
|
|
87
|
+
assert json.loads(path.read_text())["schema"] == "tlslibhunter.profile/1"
|
|
88
|
+
|
|
89
|
+
def test_unresolvable_app_returns_1(self, monkeypatch, capsys):
|
|
90
|
+
monkeypatch.setattr(discover_cli, "_resolve_with_frida", lambda app, serial: "x")
|
|
91
|
+
code, _ = self.run(["Nope"], capsys)
|
|
92
|
+
assert code == 1
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"""Tests for discovery orchestration on recorded Pixel 5 (Android 14) Gemini fixtures.
|
|
2
|
+
|
|
3
|
+
Facts of that session: Gemini (bard, uid 10298) has no internet sockets; the
|
|
4
|
+
Google app's ``:search`` process (uid 10156) hosts its UI and owns the QUIC
|
|
5
|
+
sockets; GMS is uid 10162; Cloudflare WARP (uid 10274) owns a QUIC tunnel.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
|
|
10
|
+
from tests.conftest import FixtureRunner
|
|
11
|
+
from tlslibhunter.discovery import engine
|
|
12
|
+
from tlslibhunter.discovery.profile import Candidate
|
|
13
|
+
|
|
14
|
+
BARD = "com.google.android.apps.bard"
|
|
15
|
+
GSA = "com.google.android.googlequicksearchbox"
|
|
16
|
+
GSA_SEARCH = f"{GSA}:search"
|
|
17
|
+
GMS = "com.google.android.gms"
|
|
18
|
+
WARP_UID = 10274
|
|
19
|
+
|
|
20
|
+
# GMS (pid 19016) holding its CLOSE_WAIT 443 socket; absent from the real fd listing.
|
|
21
|
+
GMS_FD_LISTING = "PID 19016\nlrwx------ 1 root root 64 d 7 -> socket:[8338687]\n"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def classify(runner: FixtureRunner, root: bool = True) -> dict[str, Candidate]:
|
|
25
|
+
return {cand.process: cand for cand in engine.classify(engine.collect_snapshot(runner, root), BARD)}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class TestCollectSnapshot:
|
|
29
|
+
def test_root_snapshot_scans_fds_only_for_tls_socket_uids(self):
|
|
30
|
+
runner = FixtureRunner()
|
|
31
|
+
snapshot = engine.collect_snapshot(runner, root=True)
|
|
32
|
+
fd_scans = [cmd for cmd in runner.commands if "/proc/$p/fd" in cmd]
|
|
33
|
+
assert fd_scans == [
|
|
34
|
+
engine.as_root(
|
|
35
|
+
'for p in 568 5334 6371 19016 29615 32457 2267; do echo "PID $p"; ls -l /proc/$p/fd 2>/dev/null; done'
|
|
36
|
+
)
|
|
37
|
+
]
|
|
38
|
+
assert snapshot.root and snapshot.foreground_package == GSA
|
|
39
|
+
|
|
40
|
+
def test_root_snapshot_reads_proc_net_via_su(self):
|
|
41
|
+
runner = FixtureRunner()
|
|
42
|
+
engine.collect_snapshot(runner, root=True)
|
|
43
|
+
assert engine.as_root("cat /proc/net/udp6") in runner.commands
|
|
44
|
+
|
|
45
|
+
def test_no_root_snapshot_has_no_fd_scan(self):
|
|
46
|
+
runner = FixtureRunner()
|
|
47
|
+
snapshot = engine.collect_snapshot(runner, root=False)
|
|
48
|
+
assert not snapshot.root
|
|
49
|
+
assert not any("su -c" in cmd for cmd in runner.commands)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class TestClassifyRoot:
|
|
53
|
+
def test_gsa_search_is_delegate_with_quic_evidence(self):
|
|
54
|
+
search = classify(FixtureRunner())[GSA_SEARCH]
|
|
55
|
+
assert search.role == "delegate" and search.pid == 568
|
|
56
|
+
assert "net:udp-connected:443" in search.evidence
|
|
57
|
+
assert "foreground_host" in search.evidence
|
|
58
|
+
|
|
59
|
+
def test_bard_is_target_without_sockets(self):
|
|
60
|
+
bard = classify(FixtureRunner())[BARD]
|
|
61
|
+
assert (bard.role, bard.pid, bard.evidence) == ("target", 11192, [])
|
|
62
|
+
|
|
63
|
+
def test_warp_vpn_is_never_attributed(self):
|
|
64
|
+
assert all(cand.uid != WARP_UID for cand in classify(FixtureRunner()).values())
|
|
65
|
+
|
|
66
|
+
def test_gms_absent_when_it_owns_no_sockets(self):
|
|
67
|
+
assert not any(cand.package == GMS for cand in classify(FixtureRunner()).values())
|
|
68
|
+
|
|
69
|
+
def test_gms_is_shared_system_when_it_owns_sockets(self):
|
|
70
|
+
gms = classify(FixtureRunner({"su -c 'for p in": GMS_FD_LISTING}))[GMS]
|
|
71
|
+
assert gms.role == "shared_system"
|
|
72
|
+
assert gms.evidence == ["net:tcp:443", f"oom_bound_by:{GSA_SEARCH}"]
|
|
73
|
+
|
|
74
|
+
def test_interactor_bound_by_delegate_is_delegate(self):
|
|
75
|
+
interactor = classify(FixtureRunner())[f"{GSA}:interactor"]
|
|
76
|
+
assert interactor.evidence == [f"oom_bound_by:{GSA_SEARCH}"]
|
|
77
|
+
|
|
78
|
+
def test_target_first_in_order(self):
|
|
79
|
+
assert list(classify(FixtureRunner()))[0] == BARD
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class TestClassifyNoRoot:
|
|
83
|
+
def test_uid_attributed_evidence(self):
|
|
84
|
+
search = classify(FixtureRunner(), root=False)[GSA_SEARCH]
|
|
85
|
+
assert search.evidence[0] == "net:uid-attributed"
|
|
86
|
+
assert not any(item.startswith("net:udp") for item in search.evidence)
|
|
87
|
+
|
|
88
|
+
def test_warp_still_not_attributed(self):
|
|
89
|
+
assert all(cand.uid != WARP_UID for cand in classify(FixtureRunner(), root=False).values())
|
|
90
|
+
|
|
91
|
+
def test_dns_and_dot_ports_are_ignored(self):
|
|
92
|
+
from tlslibhunter.discovery.sockets import SocketEntry
|
|
93
|
+
from tlslibhunter.utils.android_related import ProcessEntry
|
|
94
|
+
|
|
95
|
+
dot = SocketEntry("udp", "10.0.0.2", 4000, "1.1.1.1", 853, "01", 10156, 77)
|
|
96
|
+
dns = SocketEntry("udp", "10.0.0.2", 4001, "1.1.1.1", 53, "01", 10156, 78)
|
|
97
|
+
snapshot = engine.Snapshot(
|
|
98
|
+
processes=[ProcessEntry(568, 10156, GSA_SEARCH)],
|
|
99
|
+
sockets=[dot, dns],
|
|
100
|
+
package_uids={GSA: [10156]},
|
|
101
|
+
foreground_package=GSA,
|
|
102
|
+
)
|
|
103
|
+
(search,) = engine.classify(snapshot, BARD)
|
|
104
|
+
assert search.evidence == ["foreground_host"]
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class TestClassifyRoles:
|
|
108
|
+
def snapshot(self, processes):
|
|
109
|
+
return engine.Snapshot(processes=processes, package_uids={"com.app": [10500], "com.other": [10500]})
|
|
110
|
+
|
|
111
|
+
def test_sdk_sandbox_and_same_uid_sibling(self):
|
|
112
|
+
from tlslibhunter.utils.android_related import ProcessEntry
|
|
113
|
+
|
|
114
|
+
procs = [
|
|
115
|
+
ProcessEntry(1, 10500, "com.app"),
|
|
116
|
+
ProcessEntry(2, 20500, "com.app_sdk_sandbox"),
|
|
117
|
+
ProcessEntry(3, 10500, "com.other"),
|
|
118
|
+
]
|
|
119
|
+
roles = {cand.process: (cand.role, cand.evidence) for cand in engine.classify(self.snapshot(procs), "com.app")}
|
|
120
|
+
assert roles == {
|
|
121
|
+
"com.app": ("target", []),
|
|
122
|
+
"com.app_sdk_sandbox": ("sdk_sandbox", []),
|
|
123
|
+
"com.other": ("sibling", ["same_uid"]),
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class TestMergeAndSampling:
|
|
128
|
+
def test_merge_unions_evidence_and_keeps_latest_pid(self):
|
|
129
|
+
merged = engine.merge_candidates({}, [Candidate(1, "p", "pkg", 10001, "delegate", ["a"])])
|
|
130
|
+
engine.merge_candidates(merged, [Candidate(2, "p", "pkg", 10001, "delegate", ["b", "a"])])
|
|
131
|
+
assert (merged["p"].pid, merged["p"].evidence) == (2, ["a", "b"])
|
|
132
|
+
|
|
133
|
+
def test_merge_confirms_socket_and_preloaded_lib_from_different_samples(self):
|
|
134
|
+
merged = engine.merge_candidates({}, [Candidate(1, "p", "pkg", 10001, "target", ["net:tcp:443"])])
|
|
135
|
+
engine.merge_candidates(merged, [Candidate(1, "p", "pkg", 10001, "target", ["tls_lib:conscrypt/libssl.so"])])
|
|
136
|
+
assert merged["p"].confirmed
|
|
137
|
+
|
|
138
|
+
@pytest.mark.parametrize(("duration", "interval", "expected"), [(0, 2, 1), (10, 2, 5), (3, 2, 1), (5, 0, 1)])
|
|
139
|
+
def test_sample_count(self, duration, interval, expected):
|
|
140
|
+
assert engine.sample_count(duration, interval) == expected
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class TestDiscover:
|
|
144
|
+
def runner(self):
|
|
145
|
+
return FixtureRunner(
|
|
146
|
+
{
|
|
147
|
+
"getprop ro.build.fingerprint": "google/redfin/redfin:14/UP1A/123:user/release-keys\n",
|
|
148
|
+
"dumpsys package com.google.android.apps.bard": " versionCode=1009090390 minSdk=28 targetSdk=35\n",
|
|
149
|
+
}
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
def test_builds_profile_from_merged_samples(self):
|
|
153
|
+
sleeps = []
|
|
154
|
+
profile = engine.discover(self.runner(), BARD, duration=6, interval=2, target="Gemini", sleep=sleeps.append)
|
|
155
|
+
assert sleeps == [2, 2]
|
|
156
|
+
assert (profile.target, profile.target_package) == ("Gemini", BARD)
|
|
157
|
+
assert profile.gate_packages == [BARD, GSA]
|
|
158
|
+
assert profile.process_patterns[0] == BARD and GSA_SEARCH in profile.process_patterns
|
|
159
|
+
assert profile.version_code == 1009090390
|
|
160
|
+
assert profile.device_fingerprint.startswith("google/redfin")
|
|
161
|
+
|
|
162
|
+
def test_auto_detects_root(self):
|
|
163
|
+
runner = self.runner()
|
|
164
|
+
profile = engine.discover(runner, BARD, sleep=lambda _: None)
|
|
165
|
+
assert "su -c id" in runner.commands
|
|
166
|
+
assert "net:udp-connected:443" in {e for c in profile.candidates for e in c.evidence}
|
|
167
|
+
|
|
168
|
+
def test_without_root_uses_uid_attribution(self):
|
|
169
|
+
runner = FixtureRunner(root=False)
|
|
170
|
+
profile = engine.discover(runner, BARD, sleep=lambda _: None)
|
|
171
|
+
assert "net:uid-attributed" in {e for c in profile.candidates for e in c.evidence}
|
|
172
|
+
assert profile.version_code is None and profile.device_fingerprint is None
|
|
173
|
+
|
|
174
|
+
def test_shared_system_excluded_from_patterns(self):
|
|
175
|
+
profile = engine.discover(FixtureRunner(root=False), BARD, sleep=lambda _: None)
|
|
176
|
+
assert GMS not in profile.process_patterns and GMS not in profile.gate_packages
|
|
177
|
+
|
|
178
|
+
def test_rejects_shell_unsafe_package(self):
|
|
179
|
+
with pytest.raises(ValueError):
|
|
180
|
+
engine.discover(FixtureRunner(), "com.app; reboot", sleep=lambda _: None)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
class TestAdbRunner:
|
|
184
|
+
def test_returns_output_or_empty(self, monkeypatch):
|
|
185
|
+
results = iter([(0, "ok"), (1, "error: no devices")])
|
|
186
|
+
monkeypatch.setattr(engine, "adb_shell", lambda cmd, serial=None: next(results))
|
|
187
|
+
run = engine.make_adb_runner("ABC")
|
|
188
|
+
assert (run("id"), run("id")) == ("ok", "")
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
class TestPackageNameValidation:
|
|
192
|
+
@pytest.mark.parametrize("name", ["com.example.app", "com.google.android.apps.bard", "a.b_c.d1", "x.1y"])
|
|
193
|
+
def test_accepts_package_names(self, name):
|
|
194
|
+
from tlslibhunter.discovery.topology import is_valid_android_package
|
|
195
|
+
|
|
196
|
+
assert is_valid_android_package(name)
|
|
197
|
+
assert engine.validate_package_name(name) == name
|
|
198
|
+
|
|
199
|
+
@pytest.mark.parametrize(
|
|
200
|
+
"name",
|
|
201
|
+
[
|
|
202
|
+
"",
|
|
203
|
+
"app",
|
|
204
|
+
"com.example\n",
|
|
205
|
+
"com.example;reboot",
|
|
206
|
+
"com.example app",
|
|
207
|
+
"com.$(id).x",
|
|
208
|
+
"1com.example",
|
|
209
|
+
".com.x",
|
|
210
|
+
"com..x",
|
|
211
|
+
None,
|
|
212
|
+
],
|
|
213
|
+
)
|
|
214
|
+
def test_rejects_non_package_names(self, name):
|
|
215
|
+
from tlslibhunter.discovery.topology import is_valid_android_package
|
|
216
|
+
|
|
217
|
+
assert not is_valid_android_package(name)
|
|
218
|
+
with pytest.raises(ValueError, match="invalid Android package name"):
|
|
219
|
+
engine.validate_package_name(name)
|
|
220
|
+
|
|
221
|
+
def test_version_code_command_quotes_and_validates(self):
|
|
222
|
+
assert engine.version_code_command("com.example.app") == "dumpsys package com.example.app | grep versionCode"
|
|
223
|
+
with pytest.raises(ValueError):
|
|
224
|
+
engine.version_code_command("com.example;rm -rf /")
|
|
225
|
+
|
|
226
|
+
def test_discover_rejects_injection_before_any_device_command(self):
|
|
227
|
+
calls = []
|
|
228
|
+
|
|
229
|
+
def runner(cmd):
|
|
230
|
+
calls.append(cmd)
|
|
231
|
+
return ""
|
|
232
|
+
|
|
233
|
+
with pytest.raises(ValueError):
|
|
234
|
+
engine.discover(runner, "com.x`reboot`", root=False)
|
|
235
|
+
assert calls == []
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
MAPS_SCAN = "PID 1\n7000-8000 r-xp 00000000 fd:21 77 /data/app/x/lib/arm64/libflutter.so\n"
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
class TestTlsLibConfirmation:
|
|
242
|
+
def candidates(self):
|
|
243
|
+
return [
|
|
244
|
+
Candidate(1, "com.app", "com.app", 10001, "target"),
|
|
245
|
+
Candidate(2, "com.google.android.gms", "com.google.android.gms", 10002, "shared_system", ["net:tcp:443"]),
|
|
246
|
+
]
|
|
247
|
+
|
|
248
|
+
def test_reads_maps_once_for_attributable_pids_only(self):
|
|
249
|
+
runner = FixtureRunner({"su -c 'for p in 1;": MAPS_SCAN})
|
|
250
|
+
target, shared = engine.confirm_candidates(runner, self.candidates())
|
|
251
|
+
maps_cmds = [cmd for cmd in runner.commands if "/maps" in cmd]
|
|
252
|
+
assert maps_cmds == [engine.as_root('for p in 1; do echo "PID $p"; grep r-xp /proc/$p/maps 2>/dev/null; done')]
|
|
253
|
+
assert target.evidence == ["tls_lib:libflutter.so"] and target.confirmed
|
|
254
|
+
assert not shared.confirmed and shared.evidence == ["net:tcp:443"]
|
|
255
|
+
|
|
256
|
+
def test_no_pids_no_command(self):
|
|
257
|
+
runner = FixtureRunner()
|
|
258
|
+
assert engine.read_tls_libs(runner, []) == {}
|
|
259
|
+
assert runner.commands == []
|
|
260
|
+
|
|
261
|
+
def test_discover_with_root_scans_maps(self):
|
|
262
|
+
runner = FixtureRunner()
|
|
263
|
+
engine.discover(runner, BARD, sleep=lambda _: None)
|
|
264
|
+
assert any("/proc/$p/maps" in cmd for cmd in runner.commands)
|
|
265
|
+
|
|
266
|
+
def test_discover_without_root_skips_maps(self):
|
|
267
|
+
runner = FixtureRunner(root=False)
|
|
268
|
+
engine.discover(runner, BARD, sleep=lambda _: None)
|
|
269
|
+
assert not any("/maps" in cmd for cmd in runner.commands)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""Tests for dumpsys oom adj-source parsing and delegate package selection."""
|
|
2
|
+
|
|
3
|
+
from tests.conftest import read_discovery_fixture
|
|
4
|
+
from tlslibhunter.discovery import handoff
|
|
5
|
+
from tlslibhunter.discovery.handoff import OomLink
|
|
6
|
+
from tlslibhunter.utils.android_related import parse_foreground_package
|
|
7
|
+
|
|
8
|
+
BARD = "com.google.android.apps.bard"
|
|
9
|
+
GSA = "com.google.android.googlequicksearchbox"
|
|
10
|
+
GMS = "com.google.android.gms"
|
|
11
|
+
SHARED = {GMS, "com.android.chrome"}
|
|
12
|
+
|
|
13
|
+
HEADER = " Proc # 2: vis F/ /BTOP LCMNFU t: 0 19016:com.google.android.gms/u0a162 (service)"
|
|
14
|
+
ADJ = " com.google.android.gms/.Svc<=Proc{568:com.google.android.googlequicksearchbox:search/u0a156}"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class TestParseOomProcesses:
|
|
18
|
+
def test_header_fields(self):
|
|
19
|
+
assert handoff.parse_oom_processes(HEADER) == [handoff.OomProcess(19016, GMS, "service")]
|
|
20
|
+
|
|
21
|
+
def test_pers_header_and_padded_index(self):
|
|
22
|
+
text = " PERS #52: sys F/ /PER LCMNFU t: 0 27734:system/1000 (fixed)\n"
|
|
23
|
+
assert handoff.parse_oom_processes(text) == [handoff.OomProcess(27734, "system", "fixed")]
|
|
24
|
+
|
|
25
|
+
def test_real_fixture_top_activity_is_gsa_search(self):
|
|
26
|
+
processes = handoff.parse_oom_processes(read_discovery_fixture("dumpsys_oom.txt"))
|
|
27
|
+
assert len(processes) == 53
|
|
28
|
+
assert handoff.top_activity_pids(processes) == [568]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class TestParseOomAdjSources:
|
|
32
|
+
def test_link_points_from_client_to_preceding_header(self):
|
|
33
|
+
links = handoff.parse_oom_adj_sources(f"{HEADER}\n{ADJ}\n")
|
|
34
|
+
assert links == [(f"{GSA}:search", 568, GMS, 19016)]
|
|
35
|
+
|
|
36
|
+
def test_adj_line_without_header_is_ignored(self):
|
|
37
|
+
assert handoff.parse_oom_adj_sources(ADJ) == []
|
|
38
|
+
|
|
39
|
+
def test_non_proc_sources_are_ignored(self):
|
|
40
|
+
assert handoff.parse_oom_adj_sources(f"{HEADER}\n x/.y<=Activity{{abc u0 x/.A}}\n") == []
|
|
41
|
+
|
|
42
|
+
def test_real_fixture_gsa_search_binds_interactor_and_gms(self):
|
|
43
|
+
links = handoff.parse_oom_adj_sources(read_discovery_fixture("dumpsys_oom.txt"))
|
|
44
|
+
served_by_search = [link.served_process for link in links if link.client_pid == 568]
|
|
45
|
+
assert served_by_search == [f"{GSA}:interactor", GMS, "com.google.android.gms.unstable"]
|
|
46
|
+
assert all(link.served_pid != 11192 for link in links)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class TestDelegatePackages:
|
|
50
|
+
def test_foreground_host_is_delegate(self):
|
|
51
|
+
foreground = parse_foreground_package(read_discovery_fixture("dumpsys_activities_resumed.txt"))
|
|
52
|
+
assert handoff.delegate_packages(BARD, foreground, [], SHARED) == [GSA]
|
|
53
|
+
|
|
54
|
+
def test_packages_bound_by_target_are_delegates(self):
|
|
55
|
+
links = [OomLink(f"{BARD}:bg", 1, "com.example.helper:svc", 2)]
|
|
56
|
+
assert handoff.delegate_packages(BARD, None, links, SHARED) == ["com.example.helper"]
|
|
57
|
+
|
|
58
|
+
def test_links_from_other_clients_are_ignored(self):
|
|
59
|
+
links = [OomLink(f"{GSA}:search", 568, "com.example.helper", 2)]
|
|
60
|
+
assert handoff.delegate_packages(BARD, None, links, SHARED) == []
|
|
61
|
+
|
|
62
|
+
def test_excludes_shared_target_launcher_and_systemui(self):
|
|
63
|
+
links = [OomLink(BARD, 1, pkg, 2) for pkg in (GMS, BARD, "com.android.systemui")]
|
|
64
|
+
assert handoff.delegate_packages(BARD, "com.google.android.apps.nexuslauncher", links, SHARED) == []
|
|
65
|
+
|
|
66
|
+
def test_deduplicates_keeping_foreground_first(self):
|
|
67
|
+
links = [OomLink(BARD, 1, "com.example.helper", 2), OomLink(BARD, 1, GSA, 3)]
|
|
68
|
+
assert handoff.delegate_packages(BARD, GSA, links, SHARED) == [GSA, "com.example.helper"]
|