Skip to content

Commit

Permalink
Make secret rendering test more resilient to implementation details (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
potiuk authored Jan 2, 2023
1 parent 60f24da commit 81cd6c7
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions tests/www/views/test_views_rendered.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 }}"
Expand All @@ -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</span> *** <span class="o">&amp;&amp;</span> <span class="nb">echo</span> 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

0 comments on commit 81cd6c7

Please sign in to comment.