@@ -1003,8 +1003,6 @@ async fn check_ssh_tunnel_setup() {
10031003
10041004 let mock_access_token = oauth2:: AccessToken :: new ( "test_token_mock" . to_string ( ) ) ;
10051005
1006- let mut config = ssh:: Config :: new ( "test-backend" , Some ( tr. pathbuf ( ) ) , None , None ) . unwrap ( ) ;
1007-
10081006 let server = MockServer :: start ( ) ;
10091007
10101008 let request_reply = r#"{
@@ -1025,58 +1023,58 @@ async fn check_ssh_tunnel_setup() {
10251023 . body ( request_reply) ;
10261024 } ) ;
10271025
1028- config. set_backend ( url :: Url :: parse ( & server. base_url ( ) ) . unwrap ( ) ) ;
1026+ let config = ssh :: Config :: new ( server. base_url ( ) , Some ( tr . pathbuf ( ) ) , None , None ) . unwrap ( ) ;
10291027
10301028 ssh:: ssh_create_tunnel ( "test_device" , "test_user" , config, mock_access_token)
10311029 . await
10321030 . unwrap ( ) ;
10331031
10341032 assert ! (
10351033 tr. pathbuf( )
1036- . join( "config " )
1034+ . join( "test_device_config " )
10371035 . try_exists( )
10381036 . is_ok_and( |exists| exists)
10391037 ) ;
10401038 assert ! (
10411039 tr. pathbuf( )
1042- . join( "id_ed25519 " )
1040+ . join( "test_device_id_ed25519 " )
10431041 . try_exists( )
10441042 . is_ok_and( |exists| exists)
10451043 ) ;
10461044 assert ! (
10471045 tr. pathbuf( )
1048- . join( "id_ed25519 .pub" )
1046+ . join( "test_device_id_ed25519 .pub" )
10491047 . try_exists( )
10501048 . is_ok_and( |exists| exists)
10511049 ) ;
10521050 assert ! (
10531051 tr. pathbuf( )
1054- . join( "bastion -cert.pub" )
1052+ . join( "test_device_bastion -cert.pub" )
10551053 . try_exists( )
10561054 . is_ok_and( |exists| exists)
10571055 ) ;
10581056 assert ! (
10591057 tr. pathbuf( )
1060- . join( "device -cert.pub" )
1058+ . join( "test_device_device -cert.pub" )
10611059 . try_exists( )
10621060 . is_ok_and( |exists| exists)
10631061 ) ;
10641062
1065- let ssh_config = std:: fs:: read_to_string ( tr. pathbuf ( ) . join ( "config " ) ) . unwrap ( ) ;
1063+ let ssh_config = std:: fs:: read_to_string ( tr. pathbuf ( ) . join ( "test_device_config " ) ) . unwrap ( ) ;
10661064 let expected_config = format ! (
10671065 r#"Host bastion
10681066 User bastion_user
10691067 Hostname 132.23.0.1
10701068 Port 22
1071- IdentityFile {}/id_ed25519
1072- CertificateFile {}/bastion -cert.pub
1069+ IdentityFile {}/test_device_id_ed25519
1070+ CertificateFile {}/test_device_bastion -cert.pub
10731071 ProxyCommand none
10741072
10751073Host test_device
10761074 User test_user
1077- IdentityFile {}/id_ed25519
1078- CertificateFile {}/device -cert.pub
1079- ProxyCommand ssh -F {}/config bastion
1075+ IdentityFile {}/test_device_id_ed25519
1076+ CertificateFile {}/test_device_device -cert.pub
1077+ ProxyCommand ssh -F {}/test_device_config bastion
10801078"# ,
10811079 tr. pathbuf( ) . to_string_lossy( ) ,
10821080 tr. pathbuf( ) . to_string_lossy( ) ,
@@ -1088,6 +1086,110 @@ Host test_device
10881086 assert_eq ! ( ssh_config, expected_config) ;
10891087}
10901088
1089+ #[ tokio:: test]
1090+ async fn check_multi_ssh_tunnel_setup ( ) {
1091+ let tr = Testrunner :: new ( "check_multi_ssh_tunnel_setup" ) ;
1092+
1093+ let mock_access_token = oauth2:: AccessToken :: new ( "test_token_mock" . to_string ( ) ) ;
1094+
1095+ let server = MockServer :: start ( ) ;
1096+
1097+ let request_reply = r#"{
1098+ "clientBastionCert": "-----BEGIN CERTIFICATE-----\nMIIFrjCCA5agAwIBAgIBATANBgkqhkiG...",
1099+ "clientDeviceCert": "-----BEGIN CERTIFICATE-----\nMIIFrjCCA5agAwIBAgIBATANBgkqhkiG...",
1100+ "host": "132.23.0.1",
1101+ "port": 22,
1102+ "bastionUser": "bastion_user"
1103+ }
1104+ "# ;
1105+
1106+ let _ = server. mock ( |when, then| {
1107+ when. method ( POST )
1108+ . path ( "/api/devices/prepareSSHConnection" )
1109+ . header ( "authorization" , "Bearer test_token_mock" ) ;
1110+ then. status ( 200 )
1111+ . header ( "content-type" , "application/json" )
1112+ . body ( request_reply) ;
1113+ } ) ;
1114+
1115+ ssh:: ssh_create_tunnel (
1116+ "test_device_a" ,
1117+ "test_user" ,
1118+ ssh:: Config :: new ( server. base_url ( ) , Some ( tr. pathbuf ( ) ) , None , None ) . unwrap ( ) ,
1119+ mock_access_token. clone ( ) ,
1120+ )
1121+ . await
1122+ . unwrap ( ) ;
1123+
1124+ ssh:: ssh_create_tunnel (
1125+ "test_device_b" ,
1126+ "test_user" ,
1127+ ssh:: Config :: new ( server. base_url ( ) , Some ( tr. pathbuf ( ) ) , None , None ) . unwrap ( ) ,
1128+ mock_access_token,
1129+ )
1130+ . await
1131+ . unwrap ( ) ;
1132+
1133+ for device in [ "test_device_a" , "test_device_b" ] {
1134+ assert ! (
1135+ tr. pathbuf( )
1136+ . join( format!( "{device}_config" ) )
1137+ . try_exists( )
1138+ . is_ok_and( |exists| exists)
1139+ ) ;
1140+ assert ! (
1141+ tr. pathbuf( )
1142+ . join( format!( "{device}_id_ed25519" ) )
1143+ . try_exists( )
1144+ . is_ok_and( |exists| exists)
1145+ ) ;
1146+ assert ! (
1147+ tr. pathbuf( )
1148+ . join( format!( "{device}_id_ed25519.pub" ) )
1149+ . try_exists( )
1150+ . is_ok_and( |exists| exists)
1151+ ) ;
1152+ assert ! (
1153+ tr. pathbuf( )
1154+ . join( format!( "{device}_bastion-cert.pub" ) )
1155+ . try_exists( )
1156+ . is_ok_and( |exists| exists)
1157+ ) ;
1158+ assert ! (
1159+ tr. pathbuf( )
1160+ . join( format!( "{device}_device-cert.pub" ) )
1161+ . try_exists( )
1162+ . is_ok_and( |exists| exists)
1163+ ) ;
1164+
1165+ let ssh_config =
1166+ std:: fs:: read_to_string ( tr. pathbuf ( ) . join ( format ! ( "{device}_config" ) ) ) . unwrap ( ) ;
1167+ let expected_config = format ! (
1168+ r#"Host bastion
1169+ User bastion_user
1170+ Hostname 132.23.0.1
1171+ Port 22
1172+ IdentityFile {}/{device}_id_ed25519
1173+ CertificateFile {}/{device}_bastion-cert.pub
1174+ ProxyCommand none
1175+
1176+ Host {device}
1177+ User test_user
1178+ IdentityFile {}/{device}_id_ed25519
1179+ CertificateFile {}/{device}_device-cert.pub
1180+ ProxyCommand ssh -F {}/{device}_config bastion
1181+ "# ,
1182+ tr. pathbuf( ) . to_string_lossy( ) ,
1183+ tr. pathbuf( ) . to_string_lossy( ) ,
1184+ tr. pathbuf( ) . to_string_lossy( ) ,
1185+ tr. pathbuf( ) . to_string_lossy( ) ,
1186+ tr. pathbuf( ) . to_string_lossy( )
1187+ ) ;
1188+
1189+ assert_eq ! ( ssh_config, expected_config) ;
1190+ }
1191+ }
1192+
10911193// currently disabled as we have no way to test this in our pipeline were we
10921194// don't have docker installed
10931195#[ ignore]
0 commit comments