2021-02-18 14:56:46 +03:00
|
|
|
import unittest
|
2024-01-03 22:23:04 +03:00
|
|
|
|
2021-02-18 14:56:46 +03:00
|
|
|
import docker
|
|
|
|
from docker.transport.sshconn import SSHSocket
|
|
|
|
|
2021-03-11 02:43:37 +03:00
|
|
|
|
2021-02-18 14:56:46 +03:00
|
|
|
class SSHAdapterTest(unittest.TestCase):
|
2021-03-11 02:43:37 +03:00
|
|
|
@staticmethod
|
|
|
|
def test_ssh_hostname_prefix_trim():
|
|
|
|
conn = docker.transport.SSHHTTPAdapter(
|
|
|
|
base_url="ssh://user@hostname:1234", shell_out=True)
|
2021-02-18 14:56:46 +03:00
|
|
|
assert conn.ssh_host == "user@hostname:1234"
|
|
|
|
|
2021-03-11 02:43:37 +03:00
|
|
|
@staticmethod
|
|
|
|
def test_ssh_parse_url():
|
2021-02-18 14:56:46 +03:00
|
|
|
c = SSHSocket(host="user@hostname:1234")
|
|
|
|
assert c.host == "hostname"
|
|
|
|
assert c.port == "1234"
|
|
|
|
assert c.user == "user"
|
|
|
|
|
2021-03-11 02:43:37 +03:00
|
|
|
@staticmethod
|
|
|
|
def test_ssh_parse_hostname_only():
|
2021-02-18 14:56:46 +03:00
|
|
|
c = SSHSocket(host="hostname")
|
|
|
|
assert c.host == "hostname"
|
2021-03-11 02:43:37 +03:00
|
|
|
assert c.port is None
|
|
|
|
assert c.user is None
|
2021-02-18 14:56:46 +03:00
|
|
|
|
2021-03-11 02:43:37 +03:00
|
|
|
@staticmethod
|
|
|
|
def test_ssh_parse_user_and_hostname():
|
2021-02-18 14:56:46 +03:00
|
|
|
c = SSHSocket(host="user@hostname")
|
|
|
|
assert c.host == "hostname"
|
2021-03-11 02:43:37 +03:00
|
|
|
assert c.port is None
|
2021-02-18 14:56:46 +03:00
|
|
|
assert c.user == "user"
|
|
|
|
|
2021-03-11 02:43:37 +03:00
|
|
|
@staticmethod
|
|
|
|
def test_ssh_parse_hostname_and_port():
|
2021-02-18 14:56:46 +03:00
|
|
|
c = SSHSocket(host="hostname:22")
|
|
|
|
assert c.host == "hostname"
|
|
|
|
assert c.port == "22"
|
2021-03-11 02:43:37 +03:00
|
|
|
assert c.user is None
|