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