@@ -185,6 +185,47 @@ def test_get_dag_by_pickle(self, session, dag_maker):
185185 with pytest .raises (AirflowException , match = "pickle_id could not be found .* -42" ):
186186 get_dag_by_pickle (pickle_id = - 42 , session = session )
187187
188+ @pytest .mark .parametrize (
189+ ["given_command" , "expected_masked_command" ],
190+ [
191+ (
192+ "airflow variables set --description 'needed for dag 4' client_secret_234 7fh4375f5gy353wdf" ,
193+ "airflow variables set --description 'needed for dag 4' client_secret_234 ********" ,
194+ ),
195+ (
196+ "airflow variables set cust_secret_234 7fh4375f5gy353wdf" ,
197+ "airflow variables set cust_secret_234 ********" ,
198+ ),
199+ ],
200+ )
201+ def test_cli_set_variable_supplied_sensitive_value_is_masked (
202+ self , given_command , expected_masked_command , session
203+ ):
204+ args = given_command .split ()
205+
206+ expected_command = expected_masked_command .split ()
207+
208+ exec_date = timezone .utcnow ()
209+ namespace = Namespace (dag_id = "foo" , task_id = "bar" , subcommand = "test" , execution_date = exec_date )
210+ with mock .patch .object (sys , "argv" , args ), mock .patch (
211+ "airflow.utils.session.create_session"
212+ ) as mock_create_session :
213+ metrics = cli ._build_metrics (args [1 ], namespace )
214+ # Make it so the default_action_log doesn't actually commit the txn, by giving it a next txn
215+ # instead
216+ mock_create_session .return_value = session .begin_nested ()
217+ mock_create_session .return_value .bulk_insert_mappings = session .bulk_insert_mappings
218+ cli_action_loggers .default_action_log (** metrics )
219+
220+ log = session .query (Log ).order_by (Log .dttm .desc ()).first ()
221+
222+ assert metrics .get ("start_datetime" ) <= timezone .utcnow ()
223+
224+ command : str = json .loads (log .extra ).get ("full_command" )
225+ # Replace single quotes to double quotes to avoid json decode error
226+ command = ast .literal_eval (command )
227+ assert command == expected_command
228+
188229
189230@contextmanager
190231def fail_action_logger_callback ():
0 commit comments