repro_unreachable_host_zombie_purchase.py (2893B)
1 # This file is part of GNU Taler 2 # (C) 2026 Taler Systems S.A. 3 # 4 # GNU Taler is free software; you can redistribute it and/or modify it under the 5 # terms of the GNU General Public License as published by the Free Software 6 # Foundation; either version 3, or (at your option) any later version. 7 # 8 # GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY 9 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 10 # A PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 # 12 # You should have received a copy of the GNU General Public License along with 13 # GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 14 """Reproducer: a pay URI the app may never fetch leaves an empty, retrying purchase. 15 16 cd /opt/taler-sim/driver 17 python3 ../findings/repro_unreachable_host_zombie_purchase.py [emulator-5554] 18 19 Exits 0 when the purchase screen comes up empty and the request keeps being 20 retried. 21 """ 22 23 from __future__ import annotations 24 25 import sys 26 import time 27 from pathlib import Path 28 29 sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) 30 31 import oracles # noqa: E402 32 from device import Device # noqa: E402 33 from wallet import Wallet # noqa: E402 34 35 # 127.0.0.1 is the same machine as localhost, but the app's network security 36 # config names only "localhost", so the platform refuses the connection. 37 URI = "taler+http://pay/127.0.0.1:8080/instances/sim/" + "A" * 52 + "/" 38 39 40 def main() -> int: 41 serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" 42 dev = Device(serial) 43 app = Wallet(dev) 44 app.fresh_start(dev_mode=True) 45 dev.logcat(clear=True) 46 47 app.handle_uri(URI) 48 time.sleep(10) 49 screen = dev.dump() 50 labels = screen.texts() 51 empty = [t for t in labels 52 if t.strip().lower() not in ("go back", "purchase", "internal event log")] 53 refusals = [ln for ln in dev.logcat(lines=800).splitlines() if "CLEARTEXT" in ln] 54 55 print(f"screen: {labels[:10]}") 56 print(f"content beyond the title and back button: {empty or 'none'}") 57 print(f"cleartext refusals in the first 10 s: {len(refusals)}") 58 if refusals: 59 print(" " + refusals[0][-140:]) 60 61 # Watch the retry counter climb rather than the transaction giving up. 62 counts = [] 63 for _ in range(2): 64 time.sleep(25) 65 for finding in oracles.background_failures(dev): 66 if finding.kind == "stuck-operation": 67 counts.append(finding.detail) 68 for line in counts: 69 print(f" {line}") 70 71 blank = not empty 72 retrying = len(refusals) > 1 and bool(counts) 73 print(f"\nblank purchase screen: {blank}") 74 print(f"still retrying a request that can never succeed: {retrying}") 75 print(f"reproduced: {blank and retrying}") 76 return 0 if (blank and retrying) else 1 77 78 79 if __name__ == "__main__": 80 raise SystemExit(main())