@@ -11,8 +11,8 @@ use std::time::Duration;
1111use remotefs:: { RemoteError , RemoteErrorType , RemoteResult } ;
1212use ssh2:: { MethodType as SshMethodType , Session } ;
1313
14- use super :: config:: Config ;
1514use super :: SshOpts ;
15+ use super :: config:: Config ;
1616use crate :: SshAgentIdentity ;
1717
1818// -- connect
@@ -30,7 +30,7 @@ pub fn connect(opts: &SshOpts) -> RemoteResult<Session> {
3030 return Err ( RemoteError :: new_ex (
3131 RemoteErrorType :: BadAddress ,
3232 err. to_string ( ) ,
33- ) )
33+ ) ) ;
3434 }
3535 } ;
3636 let mut stream = None ;
@@ -312,7 +312,7 @@ pub fn perform_shell_cmd<S: AsRef<str>>(session: &mut Session, cmd: S) -> Remote
312312 return Err ( RemoteError :: new_ex (
313313 RemoteErrorType :: ProtocolError ,
314314 format ! ( "Could not open channel: {err}" ) ,
315- ) )
315+ ) ) ;
316316 }
317317 } ;
318318 // Execute command
@@ -364,7 +364,7 @@ pub fn perform_shell_cmd_with_rc<S: AsRef<str>>(
364364 return Err ( RemoteError :: new_ex (
365365 RemoteErrorType :: ProtocolError ,
366366 "Failed to get command exit code" ,
367- ) )
367+ ) ) ;
368368 }
369369 } ;
370370 debug ! ( r#"Command output: "{}"; exit code: {}"# , actual_output, rc) ;
@@ -383,18 +383,21 @@ pub fn perform_shell_cmd_with_rc<S: AsRef<str>>(
383383#[ cfg( test) ]
384384mod test {
385385
386- #[ cfg( feature = "with-containers" ) ]
387386 use ssh2_config:: ParseRule ;
388387
389388 use super :: * ;
390- #[ cfg( feature = "with-containers" ) ]
391389 use crate :: mock:: ssh as ssh_mock;
392390
393391 #[ test]
394- # [ cfg ( feature = "with-containers" ) ]
392+
395393 fn should_connect_to_ssh_server_auth_user_password ( ) {
394+ use crate :: ssh:: container:: OpensshServer ;
395+
396+ let container = OpensshServer :: start ( ) ;
397+ let port = container. port ( ) ;
398+
396399 crate :: mock:: logger ( ) ;
397- let config_file = ssh_mock:: create_ssh_config ( ) ;
400+ let config_file = ssh_mock:: create_ssh_config ( port ) ;
398401 let opts = SshOpts :: new ( "sftp" )
399402 . config_file ( config_file. path ( ) , ParseRule :: ALLOW_UNKNOWN_FIELDS )
400403 . password ( "password" ) ;
@@ -404,13 +407,20 @@ mod test {
404407 }
405408 let session = connect ( & opts) . unwrap ( ) ;
406409 assert ! ( session. authenticated( ) ) ;
410+
411+ drop ( container) ;
407412 }
408413
409414 #[ test]
410- # [ cfg ( feature = "with-containers" ) ]
415+
411416 fn should_connect_to_ssh_server_auth_key ( ) {
417+ use crate :: ssh:: container:: OpensshServer ;
418+
419+ let container = OpensshServer :: start ( ) ;
420+ let port = container. port ( ) ;
421+
412422 crate :: mock:: logger ( ) ;
413- let config_file = ssh_mock:: create_ssh_config ( ) ;
423+ let config_file = ssh_mock:: create_ssh_config ( port ) ;
414424 let opts = SshOpts :: new ( "sftp" )
415425 . config_file ( config_file. path ( ) , ParseRule :: ALLOW_UNKNOWN_FIELDS )
416426 . key_storage ( Box :: new ( ssh_mock:: MockSshKeyStorage :: default ( ) ) ) ;
@@ -419,11 +429,14 @@ mod test {
419429 }
420430
421431 #[ test]
422- # [ cfg ( feature = "with-containers" ) ]
432+
423433 fn should_perform_shell_command_on_server ( ) {
424434 crate :: mock:: logger ( ) ;
435+ let container = crate :: ssh:: container:: OpensshServer :: start ( ) ;
436+ let port = container. port ( ) ;
437+
425438 let opts = SshOpts :: new ( "127.0.0.1" )
426- . port ( 10022 )
439+ . port ( port )
427440 . username ( "sftp" )
428441 . password ( "password" ) ;
429442 let mut session = connect ( & opts) . unwrap ( ) ;
@@ -433,11 +446,14 @@ mod test {
433446 }
434447
435448 #[ test]
436- # [ cfg ( feature = "with-containers" ) ]
449+
437450 fn should_perform_shell_command_on_server_and_return_exit_code ( ) {
438451 crate :: mock:: logger ( ) ;
452+ let container = crate :: ssh:: container:: OpensshServer :: start ( ) ;
453+ let port = container. port ( ) ;
454+
439455 let opts = SshOpts :: new ( "127.0.0.1" )
440- . port ( 10022 )
456+ . port ( port )
441457 . username ( "sftp" )
442458 . password ( "password" ) ;
443459 let mut session = connect ( & opts) . unwrap ( ) ;
@@ -459,11 +475,14 @@ mod test {
459475 }
460476
461477 #[ test]
462- # [ cfg ( feature = "with-containers" ) ]
478+
463479 fn should_fail_authentication ( ) {
464480 crate :: mock:: logger ( ) ;
481+ let container = crate :: ssh:: container:: OpensshServer :: start ( ) ;
482+ let port = container. port ( ) ;
483+
465484 let opts = SshOpts :: new ( "127.0.0.1" )
466- . port ( 10022 )
485+ . port ( port )
467486 . username ( "sftp" )
468487 . password ( "ippopotamo" ) ;
469488 assert ! ( connect( & opts) . is_err( ) ) ;
0 commit comments