Exemplo n.º 1
0
    def setUp(self):
        self.sshd_config = FilePath(self.mktemp())
        self.server = create_ssh_server(self.sshd_config)
        self.addCleanup(self.server.restore)

        self.agent = create_ssh_agent(self.server.key_path)
        self.addCleanup(self.agent.restore)
Exemplo n.º 2
0
    def setUp(self):
        self.sshd_config = FilePath(self.mktemp())
        self.server = create_ssh_server(self.sshd_config)
        self.addCleanup(self.server.restore)

        self.agent = create_ssh_agent(self.server.key_path)
        self.addCleanup(self.agent.restore)
Exemplo n.º 3
0
    def assert_upload(self, local_path, matcher):
        """
        Assert that the ``local_path`` can be uploaded to and then downloaded
        from a remote SSH server and that the contents are preserved.

        :param FilePath local_path: The local file or directory to upload.
        :param matcher: A ``testtools`` matcher which will be compared to the
            downloaded ``FilePath.path``.
        :returns: A ``Deferred`` that fires when the assertion is complete.
        """
        self.ssh_server = create_ssh_server(base_path=self.make_temporary_directory())
        self.addCleanup(self.ssh_server.restore)

        username = u"root"
        host = bytes(self.ssh_server.ip)

        remote_file = self.ssh_server.home.child(random_name(self))

        d = upload(
            reactor=reactor,
            username=username,
            host=host,
            local_path=local_path,
            remote_path=remote_file,
            port=self.ssh_server.port,
            identity_file=self.ssh_server.key_path,
        )

        download_directory = self.make_temporary_directory()
        download_path = download_directory.child("download")

        d.addCallback(
            lambda ignored: download(
                reactor=reactor,
                username=username,
                host=host,
                remote_path=remote_file,
                local_path=download_path,
                port=self.ssh_server.port,
                identity_file=self.ssh_server.key_path,
            )
        )

        def check(ignored):
            self.assertThat(download_path.path, matcher)

        d.addCallback(check)

        return d