repro_fresh_instance_unusable.py (3276B)
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 """A freshly provisioned merchant instance cannot be used at all. 15 16 An instance with no products and no categories is refused outright -- so a 17 merchant who has just created one cannot even charge an amount, which needs no 18 inventory. 19 20 cd /tmp/taler-pos-sim/driver && . ../env.sh 21 python3 ../findings/repro_fresh_instance_unusable.py 22 23 Exits 0 when the refusal reproduces, 1 when the terminal comes up anyway. 24 """ 25 26 import os 27 import sys 28 import threading 29 import time 30 from pathlib import Path 31 32 HERE = Path(__file__).resolve().parent 33 sys.path.insert(0, str(HERE.parent / "driver")) 34 sys.path.insert(0, str(HERE.parent / "backend")) 35 36 import mockd 37 from device import Device, serial_for 38 from pos import Pos 39 40 SERIAL = serial_for() 41 PORT = int(os.environ.get("POS_MOCK_PORT", "19443")) 42 INSTANCE = "freshshop" 43 44 45 def main() -> int: 46 print("1. a merchant instance with no categories and no products") 47 server, state = mockd.build_server("fresh", PORT, INSTANCE, 48 f"localhost:{PORT}") 49 threading.Thread(target=server.serve_forever, daemon=True).start() 50 time.sleep(1) 51 52 dev = Device(SERIAL) 53 app = Pos(dev) 54 dev.adb("reverse", f"tcp:{PORT}", f"tcp:{PORT}", check=False) 55 56 print("2. logging the terminal in to it") 57 app.fresh_start() 58 app.provision_by_form(f"localhost:{PORT}", INSTANCE, "mock-secret", 59 expect_success=False) 60 61 print("3. waiting to see where the terminal ends up") 62 dialog = None 63 deadline = time.monotonic() + 60 64 while time.monotonic() < deadline: 65 screen = dev.dump() 66 if screen.find(r"Charge|Create order|Bill|Everything"): 67 break 68 dialog = app.read_dialog(screen) 69 if dialog: 70 break 71 time.sleep(2) 72 73 screen = dev.dump() 74 print() 75 print(f"paths requested: {state.paths()}") 76 print(f"screen: {screen.texts()[:10]}") 77 server.shutdown() 78 server.server_close() 79 80 print() 81 if dialog: 82 print(f"REPRODUCED: the terminal refused the instance with") 83 print(f" {dialog}") 84 print("An instance with no categories fails OrderManager's " 85 "configuration check (config_error_category), ConfigManager " 86 "treats a receiver error as a configuration failure, and the " 87 "terminal never reaches a screen -- not even the amount keypad, " 88 "which needs no inventory at all.") 89 return 0 90 print("not reproduced: the terminal came up on an order screen.") 91 return 1 92 93 94 if __name__ == "__main__": 95 sys.exit(main())