Secrets lus uniquement dans l'environnement (MC_JETON_INFOCLIMAT, MC_CLE_ROMMA)
Plus aucun fichier de secret : la valeur est lue au moment de l'appel, jamais copiee, jamais affichee (--config indique seulement definie/absente). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cette révision appartient à :
1 Parent
b0088e636f
révision
c1e87e91be
8 fichiers modifiés
+62
-24
Aucun fichier ne correspond à votre recherche
@@ -46,6 +46,27 @@ class TestSecrets(unittest.TestCase):
|
||||
j("erreur SECRET123")
|
||||
self.assertNotIn("SECRET123", (Path(d) / "j.log").read_text(encoding="utf-8"))
|
||||
|
||||
def test_secret_lu_seulement_dans_l_environnement(self):
|
||||
cfg = Config.depuis_env({"MC_BASE": "x", "MC_JETON_INFOCLIMAT": " VAL "})
|
||||
self.assertEqual(cfg.secret("MC_JETON_INFOCLIMAT"), "VAL")
|
||||
with self.assertRaises(LookupError):
|
||||
cfg.secret("MC_CLE_ROMMA")
|
||||
self.assertNotIn("VAL", repr(cfg)) # l'environnement n'apparaît pas dans repr()
|
||||
|
||||
def test_config_n_affiche_pas_les_secrets(self):
|
||||
import contextlib
|
||||
import io
|
||||
from unittest import mock
|
||||
from meteo_collecte import ordonnanceur
|
||||
env = {"MC_BASE": "x", "MC_JETON_INFOCLIMAT": "JETON_TRES_SECRET", "MC_CLE_ROMMA": "CLE_TRES_SECRETE"}
|
||||
sortie = io.StringIO()
|
||||
with mock.patch.dict("os.environ", env), contextlib.redirect_stdout(sortie):
|
||||
ordonnanceur.main(["--config"])
|
||||
texte = sortie.getvalue()
|
||||
self.assertNotIn("TRES_SECRET", texte)
|
||||
self.assertIn("MC_JETON_INFOCLIMAT", texte)
|
||||
self.assertIn("valeur masquée", texte)
|
||||
|
||||
|
||||
class TestFichiers(unittest.TestCase):
|
||||
def test_ecriture_atomique(self):
|
||||
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur