From bbe795a47f6d656762881683a328ceeb89647aeb Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Mon, 2 Jan 2023 09:38:20 +0100 Subject: [PATCH] Make secret rendering test more resilient to implementation details 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 --- tests/www/views/test_views_rendered.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/www/views/test_views_rendered.py b/tests/www/views/test_views_rendered.py index 970c56d4f081d..c54212dc9f9db 100644 --- a/tests/www/views/test_views_rendered.py +++ b/tests/www/views/test_views_rendered.py @@ -30,7 +30,7 @@ from airflow.utils.state import DagRunState, TaskInstanceState from airflow.utils.types import DagRunType from tests.test_utils.db import clear_db_dags, clear_db_runs, clear_rendered_ti_fields -from tests.test_utils.www import check_content_in_response +from tests.test_utils.www import check_content_in_response, check_content_not_in_response DEFAULT_DATE = timezone.datetime(2020, 3, 1) @@ -186,7 +186,7 @@ def test_user_defined_filter_and_macros_raise_error(admin_client, create_dag_run @pytest.mark.usefixtures("patch_app") def test_rendered_template_secret(admin_client, create_dag_run, task_secret): """Test that the Rendered View masks values retrieved from secret variables.""" - Variable.set("my_secret", "foo") + Variable.set("my_secret", "secret_unlikely_to_happen_accidentally") Variable.set("spam", "egg") 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): url = f"rendered-templates?task_id=task_secret&dag_id=testdag&execution_date={date}" resp = admin_client.get(url, follow_redirects=True) - check_content_in_response( - 'echo *** && echo egg', resp - ) + check_content_in_response("***", resp) + check_content_not_in_response("secret_unlikely_to_happen_accidentally", resp) ti.refresh_from_task(task_secret) assert ti.state == TaskInstanceState.QUEUED