@@ -626,6 +626,27 @@ def test_shell_solution(self):
626626 ],
627627 )
628628
629+ def test_shell_solution_with_private_key (self ):
630+ private_key = "-----BEGIN OPENSSH PRIVATE KEY-----\n key-content\n -----END OPENSSH PRIVATE KEY-----"
631+ host = models .Host .objects .get (bk_host_id = self .obj_factory .bk_host_ids [0 ])
632+ models .IdentityData .objects .filter (bk_host_id = host .bk_host_id ).update (
633+ auth_type = constants .AuthType .KEY , key = private_key
634+ )
635+ host .identity = models .IdentityData .objects .get (bk_host_id = host .bk_host_id )
636+ escaped_private_key = private_key .replace ("\n " , "\\ n" )
637+
638+ installation_tool = gen_commands (
639+ self .LEGACY_SETUP_INFO , host , mock_data_utils .JOB_TASK_PIPELINE_ID , is_uninstall = False , sub_inst_id = 0
640+ )
641+ solution_parse_result : Dict [str , Any ] = self .execution_solution_parser (
642+ installation_tool = installation_tool ,
643+ solution_type = constants .CommonExecutionSolutionType .SHELL .value ,
644+ run_cmd_param_extract = {"host_solutions_json_b64" : r"(.*) -HSJB (.*)" },
645+ )
646+
647+ self .assertIn (f"--host-identity='{ escaped_private_key } '" , solution_parse_result ["cmds" ][0 ])
648+ self .assertIn (f" -HAT { constants .AuthType .KEY } " , solution_parse_result ["cmds" ][0 ])
649+
629650 def test_target_host_shell_solution (self ):
630651 host = models .Host .objects .get (bk_host_id = self .obj_factory .bk_host_ids [0 ])
631652 installation_tool = gen_commands (
0 commit comments