Network gains a fourth entry that starts script/reverse_proxy/main.py with the web and bus ports read from config.conf, falling back to the older xmlrpc_port and longpolling_port names. It asks for this machine only or the whole network, local by default, and warns when proxy_mode is off or workers is 0: the first makes Odoo ignore X-Forwarded-*, the second leaves no bus port, so /websocket fails behind the proxy too. Checked: 48 tests pass (proxy, config reading, menu wiring, i18n); the French screen renders with the real config.conf. --- FR --- [ADD] todo network : lancer le mandataire inverse Odoo, local ou réseau Network gagne une quatrième entrée qui lance script/reverse_proxy/main.py avec les ports web et bus lus dans config.conf, repli sur les anciens noms xmlrpc_port et longpolling_port. Elle demande cette machine seule ou tout le réseau, local par défaut, et prévient quand proxy_mode est éteint ou workers vaut 0 : le premier fait ignorer X-Forwarded-* à Odoo, le second ne laisse aucun port de bus, et /websocket échoue aussi derrière le proxy. Vérifié : 48 tests passent (mandataire, lecture du config, câblage du menu, i18n) ; l'écran français s'affiche avec le vrai config.conf. Assisted-by: Claude Opus 5.5
85 lines
2.9 KiB
Python
85 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
|
# © 2026 TechnoLibre (http://www.technolibre.ca)
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
|
|
|
"""L'entrée « mandataire inverse » du menu Network de TODO."""
|
|
|
|
import os
|
|
import tempfile
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from script.todo.todo import TODO
|
|
|
|
|
|
class TestMenuNetwork(unittest.TestCase):
|
|
def test_l_option_4_lance_le_mandataire(self):
|
|
"""Les choix du menu et ses branches sont tenus à la main : [4] doit
|
|
afficher le mandataire ET appeler sa méthode."""
|
|
todo = TODO()
|
|
with (
|
|
patch.object(TODO, "network_reverse_proxy") as mock_rp,
|
|
patch("click.prompt", side_effect=["4", "0"]) as mock_prompt,
|
|
patch("script.todo.todo_telemetry.record"),
|
|
):
|
|
todo.prompt_execute_network()
|
|
mock_rp.assert_called_once_with()
|
|
self.assertIn("[4]", mock_prompt.call_args_list[0].args[0])
|
|
|
|
|
|
class TestLancement(unittest.TestCase):
|
|
def config(self, contenu):
|
|
f = tempfile.NamedTemporaryFile(
|
|
"w", suffix=".conf", delete=False, encoding="utf-8"
|
|
)
|
|
f.write(contenu)
|
|
f.close()
|
|
self.addCleanup(os.unlink, f.name)
|
|
return f.name
|
|
|
|
def lancer(self, reponse, contenu):
|
|
todo = TODO()
|
|
with (
|
|
patch("builtins.input", return_value=reponse),
|
|
patch.object(todo.execute, "exec_command_live") as mock_exec,
|
|
patch("builtins.print") as mock_print,
|
|
):
|
|
todo.network_reverse_proxy(config_path=self.config(contenu))
|
|
imprime = " ".join(
|
|
str(a) for c in mock_print.call_args_list for a in c.args
|
|
)
|
|
return mock_exec.call_args.args[0], imprime
|
|
|
|
def test_local_par_defaut_avec_les_ports_du_config(self):
|
|
cmd, _ = self.lancer(
|
|
"",
|
|
"[options]\nhttp_port = 9069\ngevent_port = 9072\n"
|
|
"proxy_mode = True\nworkers = 2\n",
|
|
)
|
|
self.assertIn("./script/reverse_proxy/main.py", cmd)
|
|
self.assertIn("--listen 127.0.0.1", cmd)
|
|
self.assertIn("--web-port 9069", cmd)
|
|
self.assertIn("--websocket-port 9072", cmd)
|
|
|
|
def test_reseau_ecoute_sur_toutes_les_interfaces(self):
|
|
cmd, _ = self.lancer(
|
|
"2", "[options]\nproxy_mode = True\nworkers = 2\n"
|
|
)
|
|
self.assertIn("--listen 0.0.0.0", cmd)
|
|
|
|
def test_les_reglages_manquants_sont_signales(self):
|
|
# Sans proxy_mode Odoo ignore X-Forwarded-*, sans workers le bus
|
|
# (8072) n'existe pas : le mandataire n'y changerait rien.
|
|
_, imprime = self.lancer("1", "[options]\nworkers = 0\n")
|
|
self.assertIn("proxy_mode", imprime)
|
|
self.assertIn("workers", imprime)
|
|
|
|
def test_rien_n_est_signale_quand_tout_est_regle(self):
|
|
_, imprime = self.lancer(
|
|
"1", "[options]\nproxy_mode = True\nworkers = 2\n"
|
|
)
|
|
self.assertNotIn("proxy_mode", imprime)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|