sarth-akvaish commented on code in PR #60739:
URL: https://github.com/apache/airflow/pull/60739#discussion_r2798107584


##########
task-sdk/tests/task_sdk/execution_time/test_task_runner.py:
##########
@@ -2702,6 +2702,119 @@ def execute(self, context):
             == '[{"name": "var1", "value": "This is a test phrase.", 
"value_from": null}, {"name": "var2", "value": "***", "value_from": null}, 
{"name": "var3", "value": "***", "value_from": null}]'
         )
 
+    def test_rendered_fields_are_redacted_before_validation(self, 
create_runtime_ti, mock_supervisor_comms):
+        """
+        Ensure that redact() is applied before JsonValue validation
+        and the redacted value is what is sent in SetRenderedFields.
+        """
+        from airflow.sdk.execution_time.comms import SetRenderedFields
+        from airflow.sdk.execution_time.task_runner import run
+
+        secret_value = "super_secret_password"
+
+        class CustomOperator(BaseOperator):
+            template_fields = ("password",)
+
+            def __init__(self, password, *args, **kwargs):
+                super().__init__(*args, **kwargs)
+                self.password = password
+
+            def execute(self, context):
+                pass
+
+        task = CustomOperator(
+            task_id="redact_test",
+            password=secret_value,
+        )
+
+        runtime_ti = create_runtime_ti(task=task, dag_id="redact_test_dag")
+
+        with mock.patch(
+            "airflow.sdk._shared.secrets_masker.redact",
+            return_value="***REDACTED***",
+        ) as mock_redact:
+            run(runtime_ti, context=runtime_ti.get_template_context(), 
log=mock.MagicMock())
+
+        mock_redact.assert_called_once_with(secret_value, "password")
+
+        assert any(
+            isinstance(call.kwargs.get("msg"), SetRenderedFields)
+            and call.kwargs["msg"].rendered_fields["password"] == 
"***REDACTED***"
+            for call in mock_supervisor_comms.send.mock_calls
+        )

Review Comment:
   Ok, will remove these tests and update the PR. Thanks



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to