|
2 | 2 |
|
3 | 3 | from typing import TYPE_CHECKING
|
4 | 4 |
|
| 5 | +import pytest |
| 6 | + |
| 7 | +from tox.tox_env.api import redact_value |
| 8 | + |
5 | 9 | if TYPE_CHECKING:
|
6 | 10 | from pathlib import Path
|
7 | 11 |
|
@@ -32,3 +36,31 @@ def test_setenv_section_substitution(tox_project: ToxProjectCreator) -> None:
|
32 | 36 | project = tox_project({"tox.ini": ini})
|
33 | 37 | result = project.run()
|
34 | 38 | result.assert_success()
|
| 39 | + |
| 40 | + |
| 41 | +@pytest.mark.parametrize( |
| 42 | + ("key", "do_redact"), |
| 43 | + [ |
| 44 | + pytest.param("SOME_KEY", True, id="key"), |
| 45 | + pytest.param("API_FOO", True, id="api"), |
| 46 | + pytest.param("AUTH", True, id="auth"), |
| 47 | + pytest.param("CLIENT", True, id="client"), |
| 48 | + pytest.param("DB_PASSWORD", True, id="password"), |
| 49 | + pytest.param("FOO", False, id="foo"), |
| 50 | + pytest.param("GITHUB_TOKEN", True, id="token"), |
| 51 | + pytest.param("NORMAL_VAR", False, id="other"), |
| 52 | + pytest.param("S_PASSWD", True, id="passwd"), |
| 53 | + pytest.param("SECRET", True, id="secret"), |
| 54 | + pytest.param("SOME_ACCESS", True, id="access"), |
| 55 | + pytest.param("MY_CRED", True, id="cred"), |
| 56 | + pytest.param("MY_PRIVATE", True, id="private"), |
| 57 | + pytest.param("MY_PWD", True, id="pwd"), |
| 58 | + ], |
| 59 | +) |
| 60 | +def test_redact(key: str, do_redact: bool) -> None: |
| 61 | + """Ensures that redact_value works as expected.""" |
| 62 | + result = redact_value(key, "foo") |
| 63 | + if do_redact: |
| 64 | + assert result == "***" |
| 65 | + else: |
| 66 | + assert result == "foo" |
0 commit comments