repro_pos_confirmation_codes.py (2924B)
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: the point-of-sale confirmation shows every code in the window. 15 16 An order that names a merchant OTP device gets a `pos_confirmation` in its pay 17 reply, and the wallet prints it verbatim -- which is every T-OTP code in the 18 valid time range, newline separated, under the singular label "Confirmation 19 code". 20 21 cd /opt/taler-sim/driver 22 python3 ../findings/repro_pos_confirmation_codes.py [emulator-5554] 23 """ 24 25 from __future__ import annotations 26 27 import re 28 import sys 29 import time 30 from pathlib import Path 31 32 sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver")) 33 34 import scenarios # noqa: E402 35 from device import Device # noqa: E402 36 from stack import Env, Merchant # noqa: E402 37 from wallet import Wallet # noqa: E402 38 39 DEVICE_ID = "reprotill" 40 41 42 def main() -> int: 43 serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554" 44 dev = Device(serial) 45 app = Wallet(dev) 46 env = Env.load() 47 merchant = Merchant(env.merchant) 48 49 scenarios.fund_wallet(app, env, "EUR:10") 50 merchant.create_otp_device(DEVICE_ID) 51 order = merchant.create_order("EUR:1", summary="Reproducer till order", 52 otp_id=DEVICE_ID) 53 app.handle_uri(order["pay_uri"]) 54 dev.tap_text(r"(?i)^pay\b|confirm payment", timeout=60) 55 56 deadline = time.time() + 90 57 while time.time() < deadline: 58 if merchant.order_status(order["order_id"], 59 order["token"]).get("order_status") == "paid": 60 break 61 time.sleep(2) 62 else: 63 print("the order was never paid") 64 return 2 65 66 screen = dev.wait_for(r"(?i)Confirmation code|completed successfully", timeout=45) 67 time.sleep(2) 68 screen = dev.dump() 69 codes = [line.strip() for t in screen.texts() for line in t.splitlines() 70 if re.fullmatch(r"\d{6,}", line.strip())] 71 labelled = screen.find(r"(?i)^Confirmation code$") is not None 72 73 print(f"screen: {screen.texts()[:12]}") 74 print(f"'Confirmation code' label present: {labelled}") 75 print(f"codes shown: {codes}") 76 print(f"\nreproduced: {labelled and len(codes) > 1}") 77 return 0 if (labelled and len(codes) > 1) else 1 78 79 80 if __name__ == "__main__": 81 raise SystemExit(main())