summaryrefslogtreecommitdiffstats
path: root/tests/test_ssh.py
diff options
context:
space:
mode:
authorGavin Mak <gavinmak@google.com>2023-03-11 06:46:20 +0000
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-22 17:46:28 +0000
commitea2e330e43c182dc16b0111ebc69ee5a71ee4ce1 (patch)
treedc33ba0e56825b3e007d0589891756724725a465 /tests/test_ssh.py
parent1604cf255f8c1786a23388db6d5277ac7949a24a (diff)
downloadgit-repo-ea2e330e43c182dc16b0111ebc69ee5a71ee4ce1.tar.gz
Format codebase with black and check formatting in CQ
Apply rules set by https://gerrit-review.googlesource.com/c/git-repo/+/362954/ across the codebase and fix any lingering errors caught by flake8. Also check black formatting in run_tests (and CQ). Bug: b/267675342 Change-Id: I972d77649dac351150dcfeb1cd1ad0ea2efc1956 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/363474 Reviewed-by: Mike Frysinger <vapier@google.com> Tested-by: Gavin Mak <gavinmak@google.com> Commit-Queue: Gavin Mak <gavinmak@google.com>
Diffstat (limited to 'tests/test_ssh.py')
-rw-r--r--tests/test_ssh.py90
1 files changed, 47 insertions, 43 deletions
diff --git a/tests/test_ssh.py b/tests/test_ssh.py
index ffb5cb94..a9c1be7f 100644
--- a/tests/test_ssh.py
+++ b/tests/test_ssh.py
@@ -23,52 +23,56 @@ import ssh
23 23
24 24
25class SshTests(unittest.TestCase): 25class SshTests(unittest.TestCase):
26 """Tests the ssh functions.""" 26 """Tests the ssh functions."""
27 27
28 def test_parse_ssh_version(self): 28 def test_parse_ssh_version(self):
29 """Check _parse_ssh_version() handling.""" 29 """Check _parse_ssh_version() handling."""
30 ver = ssh._parse_ssh_version('Unknown\n') 30 ver = ssh._parse_ssh_version("Unknown\n")
31 self.assertEqual(ver, ()) 31 self.assertEqual(ver, ())
32 ver = ssh._parse_ssh_version('OpenSSH_1.0\n') 32 ver = ssh._parse_ssh_version("OpenSSH_1.0\n")
33 self.assertEqual(ver, (1, 0)) 33 self.assertEqual(ver, (1, 0))
34 ver = ssh._parse_ssh_version('OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.13, OpenSSL 1.0.1f 6 Jan 2014\n') 34 ver = ssh._parse_ssh_version(
35 self.assertEqual(ver, (6, 6, 1)) 35 "OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.13, OpenSSL 1.0.1f 6 Jan 2014\n"
36 ver = ssh._parse_ssh_version('OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017\n') 36 )
37 self.assertEqual(ver, (7, 6)) 37 self.assertEqual(ver, (6, 6, 1))
38 ver = ssh._parse_ssh_version(
39 "OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017\n"
40 )
41 self.assertEqual(ver, (7, 6))
38 42
39 def test_version(self): 43 def test_version(self):
40 """Check version() handling.""" 44 """Check version() handling."""
41 with mock.patch('ssh._run_ssh_version', return_value='OpenSSH_1.2\n'): 45 with mock.patch("ssh._run_ssh_version", return_value="OpenSSH_1.2\n"):
42 self.assertEqual(ssh.version(), (1, 2)) 46 self.assertEqual(ssh.version(), (1, 2))
43 47
44 def test_context_manager_empty(self): 48 def test_context_manager_empty(self):
45 """Verify context manager with no clients works correctly.""" 49 """Verify context manager with no clients works correctly."""
46 with multiprocessing.Manager() as manager: 50 with multiprocessing.Manager() as manager:
47 with ssh.ProxyManager(manager): 51 with ssh.ProxyManager(manager):
48 pass 52 pass
49 53
50 def test_context_manager_child_cleanup(self): 54 def test_context_manager_child_cleanup(self):
51 """Verify orphaned clients & masters get cleaned up.""" 55 """Verify orphaned clients & masters get cleaned up."""
52 with multiprocessing.Manager() as manager: 56 with multiprocessing.Manager() as manager:
53 with ssh.ProxyManager(manager) as ssh_proxy: 57 with ssh.ProxyManager(manager) as ssh_proxy:
54 client = subprocess.Popen(['sleep', '964853320']) 58 client = subprocess.Popen(["sleep", "964853320"])
55 ssh_proxy.add_client(client) 59 ssh_proxy.add_client(client)
56 master = subprocess.Popen(['sleep', '964853321']) 60 master = subprocess.Popen(["sleep", "964853321"])
57 ssh_proxy.add_master(master) 61 ssh_proxy.add_master(master)
58 # If the process still exists, these will throw timeout errors. 62 # If the process still exists, these will throw timeout errors.
59 client.wait(0) 63 client.wait(0)
60 master.wait(0) 64 master.wait(0)
61 65
62 def test_ssh_sock(self): 66 def test_ssh_sock(self):
63 """Check sock() function.""" 67 """Check sock() function."""
64 manager = multiprocessing.Manager() 68 manager = multiprocessing.Manager()
65 proxy = ssh.ProxyManager(manager) 69 proxy = ssh.ProxyManager(manager)
66 with mock.patch('tempfile.mkdtemp', return_value='/tmp/foo'): 70 with mock.patch("tempfile.mkdtemp", return_value="/tmp/foo"):
67 # old ssh version uses port 71 # Old ssh version uses port.
68 with mock.patch('ssh.version', return_value=(6, 6)): 72 with mock.patch("ssh.version", return_value=(6, 6)):
69 self.assertTrue(proxy.sock().endswith('%p')) 73 self.assertTrue(proxy.sock().endswith("%p"))
70 74
71 proxy._sock_path = None 75 proxy._sock_path = None
72 # new ssh version uses hash 76 # New ssh version uses hash.
73 with mock.patch('ssh.version', return_value=(6, 7)): 77 with mock.patch("ssh.version", return_value=(6, 7)):
74 self.assertTrue(proxy.sock().endswith('%C')) 78 self.assertTrue(proxy.sock().endswith("%C"))