Skip to content

Commit 81cd6c7

Browse files
authored
Make secret rendering test more resilient to implementation details (apache#28673)
The newly released Pygments 2.14.0 changed slightly the way it wraps tags around rendeered variables and tour test made far too many assumptions about the rendered output which started to fail on main with the new Pygments. This PR fixes it by actually testing only what it was supposed to test: - lack of the secret in rendered output - presence of *** masking in the output
1 parent 60f24da commit 81cd6c7

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

tests/www/views/test_views_rendered.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from airflow.utils.state import DagRunState, TaskInstanceState
3131
from airflow.utils.types import DagRunType
3232
from tests.test_utils.db import clear_db_dags, clear_db_runs, clear_rendered_ti_fields
33-
from tests.test_utils.www import check_content_in_response
33+
from tests.test_utils.www import check_content_in_response, check_content_not_in_response
3434

3535
DEFAULT_DATE = timezone.datetime(2020, 3, 1)
3636

@@ -186,7 +186,7 @@ def test_user_defined_filter_and_macros_raise_error(admin_client, create_dag_run
186186
@pytest.mark.usefixtures("patch_app")
187187
def test_rendered_template_secret(admin_client, create_dag_run, task_secret):
188188
"""Test that the Rendered View masks values retrieved from secret variables."""
189-
Variable.set("my_secret", "foo")
189+
Variable.set("my_secret", "secret_unlikely_to_happen_accidentally")
190190
Variable.set("spam", "egg")
191191

192192
assert task_secret.bash_command == "echo {{ var.value.my_secret }} && echo {{ var.value.spam }}"
@@ -202,8 +202,7 @@ def test_rendered_template_secret(admin_client, create_dag_run, task_secret):
202202
url = f"rendered-templates?task_id=task_secret&dag_id=testdag&execution_date={date}"
203203

204204
resp = admin_client.get(url, follow_redirects=True)
205-
check_content_in_response(
206-
'echo</span> *** <span class="o">&amp;&amp;</span> <span class="nb">echo</span> egg', resp
207-
)
205+
check_content_in_response("***", resp)
206+
check_content_not_in_response("secret_unlikely_to_happen_accidentally", resp)
208207
ti.refresh_from_task(task_secret)
209208
assert ti.state == TaskInstanceState.QUEUED

0 commit comments

Comments
 (0)