@@ -196,24 +196,31 @@ fn message_sign_does_not_leak_secret_in_error_output() {
196196}
197197
198198#[ test]
199- fn message_sign_escapes_control_characters_in_preview ( ) {
199+ fn message_sign_does_not_echo_message_to_stderr ( ) {
200200 let sandbox = TestEnv :: default ( ) ;
201201 let secret_key = "SAKICEVQLYWGSOJS4WW7HZJWAHZVEEBS527LHK5V4MLJALYKICQCJXMW" ;
202- let malicious = "\x1b [31mRED \x1b [0m " ;
202+ let secret_message = "TOP_SECRET_TOKEN_abc123_DO_NOT_LEAK " ;
203203
204204 let output = sandbox
205205 . new_assert_cmd ( "message" )
206- . args ( [ "sign" , malicious , "--sign-with-key" , secret_key] )
206+ . args ( [ "sign" , secret_message , "--sign-with-key" , secret_key] )
207207 . assert ( )
208208 . success ( ) ;
209-
210209 let stderr = String :: from_utf8_lossy ( & output. get_output ( ) . stderr ) . into_owned ( ) ;
211210 assert ! (
212- !stderr. contains( '\x1b' ) ,
213- "stderr should not contain raw ESC bytes , got: {stderr:?}"
211+ !stderr. contains( secret_message ) ,
212+ "stderr must not echo the message (arg input) , got: {stderr:?}"
214213 ) ;
214+
215+ let output = sandbox
216+ . new_assert_cmd ( "message" )
217+ . write_stdin ( secret_message)
218+ . args ( [ "sign" , "--sign-with-key" , secret_key] )
219+ . assert ( )
220+ . success ( ) ;
221+ let stderr = String :: from_utf8_lossy ( & output. get_output ( ) . stderr ) . into_owned ( ) ;
215222 assert ! (
216- stderr. contains( " \\ x1b" ) ,
217- "stderr should contain escaped ESC as \\ x1b , got: {stderr:?}"
223+ ! stderr. contains( secret_message ) ,
224+ "stderr must not echo the message (stdin input) , got: {stderr:?}"
218225 ) ;
219226}
0 commit comments