예제 #1
0
파일: test_util.py 프로젝트: Abioy/paramiko
    def test_10_proxycommand_interpolation(self):
        """
        ProxyCommand should perform interpolation on the value
        """
        config = paramiko.util.parse_ssh_config(cStringIO.StringIO("""
Host specific
    Port 37
    ProxyCommand host %h port %p lol

Host portonly
    Port 155

Host *
    Port 25
    ProxyCommand host %h port %p
"""))
        for host, val in (
            ('foo.com', "host foo.com port 25"),
            ('specific', "host specific port 37 lol"),
            ('portonly', "host portonly port 155"),
        ):
            self.assertEquals(
                host_config(host, config)['proxycommand'],
                val
            )
예제 #2
0
    def test_proxycommand_interpolation(self):
        """
        ProxyCommand should perform interpolation on the value
        """
        config = paramiko.util.parse_ssh_config(StringIO(textwrap.dedent("""\
            Host specific
                Port 37
                ProxyCommand host %h port %p lol %%r-tricky%%

            Host portonly
                Port 155

            Host *
                Port 25
                ProxyCommand host %h port %p
            """)))
        for host, val in (
            ('foo.com', "host foo.com port 25"),
            ('specific', "host specific port 37 lol %r-tricky%"),
            ('portonly', "host portonly port 155"),
        ):
            self.assertEqual(
                host_config(host, config)['proxycommand'],
                val
            )
예제 #3
0
    def test_proxycommand_interpolation(self):
        """
        ProxyCommand should perform interpolation on the value
        """
        config = paramiko.util.parse_ssh_config(
            StringIO(
                """
Host specific
    Port 37
    ProxyCommand host %h port %p lol

Host portonly
    Port 155

Host *
    Port 25
    ProxyCommand host %h port %p
"""
            )
        )
        for host, val in (
            ("foo.com", "host foo.com port 25"),
            ("specific", "host specific port 37 lol"),
            ("portonly", "host portonly port 155"),
        ):
            self.assertEqual(host_config(host, config)["proxycommand"], val)
예제 #4
0
    def test_proxycommand_tilde_expansion(self):
        """
        Tilde (~) should be expanded inside ProxyCommand
        """
        config = paramiko.util.parse_ssh_config(StringIO("""
Host test
    ProxyCommand    ssh -F ~/.ssh/test_config bastion nc %h %p
"""))
        self.assertEqual(
            'ssh -F %s/.ssh/test_config bastion nc test 22' % os.path.expanduser('~'),
            host_config('test', config)['proxycommand']
        )
예제 #5
0
    def test_proxycommand_tilde_expansion(self):
        """
        Tilde (~) should be expanded inside ProxyCommand
        """
        config = paramiko.util.parse_ssh_config(StringIO("""
Host test
    ProxyCommand    ssh -F ~/.ssh/test_config bastion nc %h %p
"""))
        self.assertEqual(
            'ssh -F %s/.ssh/test_config bastion nc test 22' % os.path.expanduser('~'),
            host_config('test', config)['proxycommand']
        )
예제 #6
0
    def test_9_proxycommand_config_equals_parsing(self):
        """
        ProxyCommand should not split on equals signs within the value.
        """
        conf = """
Host space-delimited
    ProxyCommand foo bar=biz baz

Host equals-delimited
    ProxyCommand=foo bar=biz baz
"""
        f = cStringIO.StringIO(conf)
        config = paramiko.util.parse_ssh_config(f)
        for host in ("space-delimited", "equals-delimited"):
            self.assertEquals(host_config(host, config)["proxycommand"], "foo bar=biz baz")
예제 #7
0
    def test_proxycommand_config_equals_parsing(self):
        """
        ProxyCommand should not split on equals signs within the value.
        """
        conf = """
Host space-delimited
    ProxyCommand foo bar=biz baz
Host equals-delimited
    ProxyCommand=foo bar=biz baz
"""
        f = StringIO(conf)
        config = paramiko.util.parse_ssh_config(f)
        for host in ('space-delimited', 'equals-delimited'):
            self.assertEqual(
                host_config(host, config)['proxycommand'], 'foo bar=biz baz')
예제 #8
0
    def test_proxycommand_config_equals_parsing(self):
        """
        ProxyCommand should not split on equals signs within the value.
        """
        conf = """
Host space-delimited
    ProxyCommand foo bar=biz baz

Host equals-delimited
    ProxyCommand=foo bar=biz baz
"""
        f = StringIO(conf)
        config = paramiko.util.parse_ssh_config(f)
        for host in ('space-delimited', 'equals-delimited'):
            self.assertEqual(
                host_config(host, config)['proxycommand'],
                'foo bar=biz baz'
            )
예제 #9
0
    def test_10_proxycommand_interpolation(self):
        """
        ProxyCommand should perform interpolation on the value
        """
        config = paramiko.util.parse_ssh_config(
            cStringIO.StringIO("""
Host *
    Port 25
    ProxyCommand host %h port %p

Host specific
    Port 37
    ProxyCommand host %h port %p lol

Host portonly
    Port 155
"""))
        for host, val in (
            ('foo.com', "host foo.com port 25"),
            ('specific', "host specific port 37 lol"),
            ('portonly', "host portonly port 155"),
        ):
            self.assertEquals(host_config(host, config)['proxycommand'], val)
예제 #10
0
    def test_proxycommand_interpolation(self):
        """
        ProxyCommand should perform interpolation on the value
        """
        config = paramiko.util.parse_ssh_config(
            StringIO("""
Host specific
    Port 37
    ProxyCommand host %h port %p lol

Host portonly
    Port 155

Host *
    Port 25
    ProxyCommand host %h port %p
"""))
        for host, val in (
            ("foo.com", "host foo.com port 25"),
            ("specific", "host specific port 37 lol"),
            ("portonly", "host portonly port 155"),
        ):
            self.assertEqual(host_config(host, config)["proxycommand"], val)