11from __future__ import annotations
22
33import diffctx
4-
54from tests .framework .pygit2_backend import Pygit2Repo
65
76
87def _build_repo_with_changed_private_keys (tmp_path ):
98 repo = Pygit2Repo (tmp_path / "repo" )
109 repo .add_file ("app.py" , "import os\n KEY = os.environ['K']\n " )
11- repo .add_file ("id_rsa" , "-----BEGIN PRIVATE KEY----- \n LEAK_RSA_INITIAL \ n " )
12- repo .add_file ("tls.key" , "-----BEGIN PRIVATE KEY----- \n LEAK_KEY_INITIAL \ n " )
10+ repo .add_file ("id_rsa" , "private-key-material LEAK_RSA_INITIAL \ n " ) # pragma: allowlist secret
11+ repo .add_file ("tls.key" , "private-key-material LEAK_KEY_INITIAL \ n " ) # pragma: allowlist secret
1312 repo .add_file ("server.pem" , "-----BEGIN CERTIFICATE-----\n LEAK_PEM_INITIAL\n " )
1413 repo .commit ("initial" )
1514
1615 repo .add_file ("app.py" , "import os\n KEY = os.environ['K']\n TOKEN = os.environ['T']\n " )
17- repo .add_file ("id_rsa" , "-----BEGIN PRIVATE KEY----- \n LEAK_RSA_CHANGED \ n " )
18- repo .add_file ("tls.key" , "-----BEGIN PRIVATE KEY----- \n LEAK_KEY_CHANGED \ n " )
16+ repo .add_file ("id_rsa" , "private-key-material LEAK_RSA_CHANGED \ n " ) # pragma: allowlist secret
17+ repo .add_file ("tls.key" , "private-key-material LEAK_KEY_CHANGED \ n " ) # pragma: allowlist secret
1918 repo .add_file ("server.pem" , "-----BEGIN CERTIFICATE-----\n LEAK_PEM_CHANGED\n " )
2019 repo .commit ("change app and private keys" )
2120 return repo
@@ -28,9 +27,7 @@ def test_diff_context_excludes_changed_private_keys(tmp_path):
2827 repo = _build_repo_with_changed_private_keys (tmp_path )
2928
3029 for full in (False , True ):
31- rendered = diffctx .to_yaml (
32- diffctx .build_diff_context (root_dir = repo .path , diff_range = "HEAD~1" , full = full )
33- )
30+ rendered = diffctx .to_yaml (diffctx .build_diff_context (root_dir = repo .path , diff_range = "HEAD~1" , full = full ))
3431 for marker in SECRET_MARKERS :
3532 assert marker not in rendered , (full , marker )
3633 assert "id_rsa" not in rendered and "tls.key" not in rendered and "server.pem" not in rendered
0 commit comments