repro_add_exchange_fails_silently.py (2971B)
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: adding a payment service with a bad URL fails without saying so. 15 16 cd /opt/taler-sim/driver 17 python3 ../findings/repro_add_exchange_fails_silently.py [emulator-5554] 18 19 Exits 0 when wallet-core rejected the URL and nothing said so on screen. 20 """ 21 22 from __future__ import annotations 23 24 import sys 25 import time 26 from pathlib import Path 27 28 sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) 29 30 from device import Device # noqa: E402 31 from wallet import Wallet # noqa: E402 32 33 BAD_URL = "file:///etc/passwd" 34 COMPLAINT = r"(?i)could not add|error|invalid|failed|not supported" 35 36 37 def main() -> int: 38 serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" 39 dev = Device(serial) 40 app = Wallet(dev) 41 app.fresh_start(dev_mode=True) 42 43 app.open_settings() 44 app.scroll_to_text(r"(?i)^Payment services$") 45 dev.tap_text(r"(?i)^Payment services$", timeout=30) 46 time.sleep(2) 47 dev.tap_text(r"(?i)^Add payment service$", timeout=30) 48 time.sleep(2) 49 50 screen = dev.dump() 51 fields = screen.editable() 52 if not fields: 53 print(f"no URL field: {screen.texts()}") 54 return 2 55 dev.tap_node(fields[0], screen) 56 dev.type_text(BAD_URL) 57 time.sleep(1) 58 dev.logcat(clear=True) 59 60 screen = dev.dump() 61 ok = screen.find(r"(?i)^OK$") 62 if ok is None: 63 print(f"no OK button: {screen.texts()}") 64 return 2 65 dev.tap_node(ok, screen) 66 67 # Watch for anything that explains the failure, for longer than a snackbar 68 # would last. 69 complaints = [] 70 for _ in range(6): 71 time.sleep(1.5) 72 current = dev.dump() 73 found = current.find(COMPLAINT) 74 if found is not None: 75 complaints.append(found.label) 76 log = dev.logcat() 77 rejected = [ln for ln in log.splitlines() 78 if "addExchange" in ln and '"code":7048' in ln] 79 80 print(f"wallet-core rejections logged: {len(rejected)}") 81 if rejected: 82 print(" " + rejected[0][-200:]) 83 print(f"anything shown to the user: {complaints or 'nothing'}") 84 print(f"screen now: {dev.dump().texts()[:8]}") 85 print(f"\nreproduced: {bool(rejected) and not complaints}") 86 return 0 if (rejected and not complaints) else 1 87 88 89 if __name__ == "__main__": 90 raise SystemExit(main())