Make test in thrussh/src/lib pass

[?]
Jan 24, 2021, 11:11 AM
ZGJF6NR27RHVKL5VNPYVTAS5RVJSGNX7YRPBH5YX4UAVY7HAJHGAC

Dependencies

  • [2] ATANAS43 Fixing a test
  • [3] 2WEO7OZL Version updates: getting rid of anyhow + moving to Tokio 1.0
  • [4] YSLHJU3I Add a Close construct to ChannelMsg in the server
  • [5] 7FRJYUI6 Reboot because of a bad change
  • [6] 634OYCNM Tokio 0.3

Change contents

  • replacement in thrussh/src/lib.rs at line 643
    [3.298620][3.298620:298660]()
    use super::server::{Auth, Session};
    [3.298620]
    [3.298660]
    use super::server::{Auth, Server as _, Session};
  • replacement in thrussh/src/lib.rs at line 650
    [3.298823][3.298823:298857](),[3.298969][3.298969:298975]()
    test_compress(true).await
    }
    [3.298823]
    [3.298975]
    let _ = env_logger::try_init();
  • replacement in thrussh/src/lib.rs at line 652
    [3.298976][3.298976:300296]()
    async fn test_compress(local: bool) {
    env_logger::try_init().unwrap_or(());
    let (client_key, addr) = if local {
    let client_key = thrussh_keys::key::KeyPair::generate_ed25519().unwrap();
    let client_pubkey = Arc::new(client_key.clone_public_key());
    let mut config = super::server::Config::default();
    config.preferred = super::Preferred::COMPRESSED;
    config.auth_rejection_time = std::time::Duration::from_secs(0);
    config.connection_timeout = None; // Some(std::time::Duration::from_secs(3));
    config.auth_rejection_time = std::time::Duration::from_secs(3);
    config
    .keys
    .push(thrussh_keys::key::KeyPair::generate_ed25519().unwrap());
    let config = Arc::new(config);
    let sh = Server {
    client_pubkey,
    clients: Arc::new(Mutex::new(HashMap::new())),
    id: 0,
    };
    tokio::spawn(super::server::run(config, "0.0.0.0:2222", sh));
    std::thread::sleep(std::time::Duration::from_millis(100));
    (client_key, "127.0.0.1:2222")
    } else {
    let client_key = thrussh_keys::load_secret_key("id_ed25519", None).unwrap();
    (client_key, "127.0.0.1:2222")
    [3.298976]
    [3.300296]
    let client_key = thrussh_keys::key::KeyPair::generate_ed25519().unwrap();
    let client_pubkey = Arc::new(client_key.clone_public_key());
    let mut config = server::Config::default();
    config.preferred = Preferred::COMPRESSED;
    config.connection_timeout = None; // Some(std::time::Duration::from_secs(3));
    config.auth_rejection_time = std::time::Duration::from_secs(3);
    config
    .keys
    .push(thrussh_keys::key::KeyPair::generate_ed25519().unwrap());
    let config = Arc::new(config);
    let mut sh = Server {
    client_pubkey,
    clients: Arc::new(Mutex::new(HashMap::new())),
    id: 0,
  • replacement in thrussh/src/lib.rs at line 668
    [3.300308][3.300308:300424]()
    let mut config = super::client::Config::default();
    config.preferred = super::Preferred::COMPRESSED;
    [3.300308]
    [3.300424]
    let socket = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
    let addr = socket.local_addr().unwrap();
    tokio::spawn(async move {
    let (socket, _) = socket.accept().await.unwrap();
    let server = sh.new(socket.peer_addr().ok());
    server::run_stream(config, socket, server).await.unwrap();
    });
    let mut config = client::Config::default();
    config.preferred = Preferred::COMPRESSED;
  • edit in thrussh/src/lib.rs at line 680
    [3.300463][3.300463:300491]()
    let sh = Client {};
  • replacement in thrussh/src/lib.rs at line 681
    [3.300492][3.300492:300623]()
    let mut session = super::client::connect(config, addr, sh).await.unwrap();
    debug!("connected");
    if session
    [3.300492]
    [3.300623]
    dbg!(&addr);
    let mut session = client::connect(config, addr, Client {}).await.unwrap();
    let authenticated = session
  • replacement in thrussh/src/lib.rs at line 686
    [3.300732][3.300732:300877](),[3.300877][2.0:68](),[2.68][3.300945:301174](),[3.1265][3.300945:301174](),[3.300945][3.300945:301174]()
    .unwrap()
    {
    debug!("authenticated");
    if let Ok(mut channel) = session.channel_open_session().await {
    channel.data(&b"Hello, world!"[..]).await.unwrap();
    if let Some(msg) = channel.wait().await {
    println!("{:?}", msg)
    }
    }
    }
    if local {
    std::thread::sleep(std::time::Duration::from_secs(40));
    [3.300732]
    [3.301174]
    .unwrap();
    assert!(authenticated);
    let mut channel = session.channel_open_session().await.unwrap();
    let data = &b"Hello, world!"[..];
    channel.data(data).await.unwrap();
    let msg = channel.wait().await.unwrap();
    match msg {
    ChannelMsg::Data { data: msg_data } => { assert_eq!(*data, *msg_data) },
    msg => panic!("Unexpected message {:?}", msg),
  • replacement in thrussh/src/lib.rs at line 741
    [3.302831][3.302831:302927]()
    fn data(self, _channel: ChannelId, data: &[u8], session: Session) -> Self::FutureUnit {
    [3.302831]
    [3.302927]
    fn data(self, channel: ChannelId, data: &[u8], mut session: Session) -> Self::FutureUnit {
  • edit in thrussh/src/lib.rs at line 743
    [3.302996]
    [3.302996]
    session.data(channel, CryptoVec::from_slice(data));
  • edit in thrussh/src/lib.rs at line 767
    [3.303801][3.303801:304472]()
    }
    fn channel_open_confirmation(
    self,
    channel: ChannelId,
    _: u32,
    _: u32,
    session: client::Session,
    ) -> Self::FutureUnit {
    println!("channel_open_confirmation: {:?}", channel);
    self.finished(session)
    }
    fn data(
    self,
    channel: ChannelId,
    data: &[u8],
    session: client::Session,
    ) -> Self::FutureUnit {
    debug!(
    "client data on channel {:?}: {:?}",
    channel,
    std::str::from_utf8(data)
    );
    self.finished(session)