// This builds slightly on the previous test by checking that the filesystem // can be destroyed _after_ the session is moved. It still isn't a test that // the filesystem is usable afterwards (though we probably want that // property too), just that the object is valid (can be destroyed). // // In an earlier version, the filesystem destructor tried to use the moved // session causing a crash. It's very hard sometimes to ensure the filesystem // is destroyed before the exact (non-moved) session it came from, so its // important we allow destruction to happen after moving the session (but // before moved-to session is destroyed). BOOST_FIXTURE_TEST_CASE( move_session_with_live_filesystem_connection, session_fixture ) { session& s = test_session(); s.authenticate_by_key_files( user(), public_key_path(), private_key_path(), ""); sftp_filesystem fs = s.connect_to_filesystem(); session s2(move(s)); // The rules are that the last session must outlive the last FS so moving // FS to inner scope ensures this sftp_filesystem(move(fs)); }
// This is the third part of the session-movement tests. It strengthens the // requirements a bit more to ensure the filesystem is not just valid for // destruction but also still functions as a filesystem connection. BOOST_FIXTURE_TEST_CASE( moving_session_leaves_working_filesystem, basic_sftp_fixture ) { session& s = test_session(); s.authenticate_by_key_files( user(), public_key_path(), private_key_path(), ""); sftp_filesystem fs = s.connect_to_filesystem(); session s2(move(s)); // The rules are that the last session must outlive the last FS so moving // FS to inner scope ensures this sftp_filesystem fs2(move(fs)); BOOST_CHECK(directory_is_empty(fs2, to_remote_path(sandbox()))); }
// This tests the very basic requirements of any sensible relationship between // a filesystem and a session. It must be possible to create a filesystem // before moving the session. That's it. // // In particular, we destroy the filesystem before moving the object because // we don't want to test an added requirement that the filesystem's lifetime // can extend beyond the session's move. Whatever else we might decide the // semantics of the session-filesystem relationship should be now or in the // future, this tests must pass. Anything else would mean moving depends on // what you've used the session for in the past, which would just be broken. // // In other words, even the most careful caller would run into trouble // if this test failed. BOOST_FIXTURE_TEST_CASE( move_session_after_connecting_filesystem, session_fixture ) { session& s = test_session(); s.authenticate_by_key_files( user(), public_key_path(), private_key_path(), ""); { sftp_filesystem(s.connect_to_filesystem()); } session(move(s)); }
running_session create_and_authenticate( const wstring& host, unsigned int port, const wstring& user, com_ptr<ISftpConsumer> consumer) { running_session session(host, port); verify_host_key(host, session, consumer); // Legal to fail here, e.g. user refused to accept host key authenticate_user(user, session, consumer); // Legal to fail here, e.g. wrong password/key assert(session.get_session().authenticated()); return move(session); }
{ connect_socket_to_host(socket, host, port, io); return ssh::session(socket.native(), disconnection_message); } } running_session::running_session(const wstring& host, unsigned int port) : m_io(new io_service(0)), m_socket(new tcp::socket(*m_io)), m_session( session_on_socket(*m_socket, host, port, *m_io, "Swish says goodbye.")) {} running_session::running_session(BOOST_RV_REF(running_session) other) : m_io(move(other.m_io)), m_socket(move(other.m_socket)), m_session(move(other.m_session)) {} running_session& running_session::operator=(BOOST_RV_REF(running_session) other) { swap(running_session(move(other)), *this); return *this; } session& running_session::get_session() { return m_session; } bool running_session::is_dead() {