diff options
| author | Mike Frysinger <vapier@google.com> | 2021-05-05 15:53:03 -0400 |
|---|---|---|
| committer | Mike Frysinger <vapier@google.com> | 2021-05-06 19:09:16 +0000 |
| commit | 5291eafa412117b80ebbf645fc51559dd0b2caaf (patch) | |
| tree | f92dd1030f36cbf8aaa3c208bee7b94cd9c72927 /tests | |
| parent | 8e768eaaa722a99405f6542ac718880c8c22f060 (diff) | |
| download | git-repo-5291eafa412117b80ebbf645fc51559dd0b2caaf.tar.gz | |
ssh: move all ssh logic to a common place
We had ssh logic sprinkled between two git modules, and neither was
quite the right home for it. This largely moves the logic as-is to
its new home. We'll leave major refactoring to followup commits.
Bug: https://crbug.com/gerrit/12389
Change-Id: I300a8f7dba74f2bd132232a5eb1e856a8490e0e9
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/305483
Reviewed-by: Chris Mcdonald <cjmcdonald@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_git_command.py | 32 | ||||
| -rw-r--r-- | tests/test_ssh.py | 52 |
2 files changed, 52 insertions, 32 deletions
diff --git a/tests/test_git_command.py b/tests/test_git_command.py index 76c092f4..93300a6f 100644 --- a/tests/test_git_command.py +++ b/tests/test_git_command.py | |||
| @@ -26,38 +26,6 @@ import git_command | |||
| 26 | import wrapper | 26 | import wrapper |
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | class SSHUnitTest(unittest.TestCase): | ||
| 30 | """Tests the ssh functions.""" | ||
| 31 | |||
| 32 | def test_parse_ssh_version(self): | ||
| 33 | """Check parse_ssh_version() handling.""" | ||
| 34 | ver = git_command._parse_ssh_version('Unknown\n') | ||
| 35 | self.assertEqual(ver, ()) | ||
| 36 | ver = git_command._parse_ssh_version('OpenSSH_1.0\n') | ||
| 37 | self.assertEqual(ver, (1, 0)) | ||
| 38 | ver = git_command._parse_ssh_version('OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.13, OpenSSL 1.0.1f 6 Jan 2014\n') | ||
| 39 | self.assertEqual(ver, (6, 6, 1)) | ||
| 40 | ver = git_command._parse_ssh_version('OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017\n') | ||
| 41 | self.assertEqual(ver, (7, 6)) | ||
| 42 | |||
| 43 | def test_ssh_version(self): | ||
| 44 | """Check ssh_version() handling.""" | ||
| 45 | with mock.patch('git_command._run_ssh_version', return_value='OpenSSH_1.2\n'): | ||
| 46 | self.assertEqual(git_command.ssh_version(), (1, 2)) | ||
| 47 | |||
| 48 | def test_ssh_sock(self): | ||
| 49 | """Check ssh_sock() function.""" | ||
| 50 | with mock.patch('tempfile.mkdtemp', return_value='/tmp/foo'): | ||
| 51 | # old ssh version uses port | ||
| 52 | with mock.patch('git_command.ssh_version', return_value=(6, 6)): | ||
| 53 | self.assertTrue(git_command.ssh_sock().endswith('%p')) | ||
| 54 | git_command._ssh_sock_path = None | ||
| 55 | # new ssh version uses hash | ||
| 56 | with mock.patch('git_command.ssh_version', return_value=(6, 7)): | ||
| 57 | self.assertTrue(git_command.ssh_sock().endswith('%C')) | ||
| 58 | git_command._ssh_sock_path = None | ||
| 59 | |||
| 60 | |||
| 61 | class GitCallUnitTest(unittest.TestCase): | 29 | class GitCallUnitTest(unittest.TestCase): |
| 62 | """Tests the _GitCall class (via git_command.git).""" | 30 | """Tests the _GitCall class (via git_command.git).""" |
| 63 | 31 | ||
diff --git a/tests/test_ssh.py b/tests/test_ssh.py new file mode 100644 index 00000000..5a4f27e4 --- /dev/null +++ b/tests/test_ssh.py | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | # Copyright 2019 The Android Open Source Project | ||
| 2 | # | ||
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | # you may not use this file except in compliance with the License. | ||
| 5 | # You may obtain a copy of the License at | ||
| 6 | # | ||
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | # | ||
| 9 | # Unless required by applicable law or agreed to in writing, software | ||
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | # See the License for the specific language governing permissions and | ||
| 13 | # limitations under the License. | ||
| 14 | |||
| 15 | """Unittests for the ssh.py module.""" | ||
| 16 | |||
| 17 | import unittest | ||
| 18 | from unittest import mock | ||
| 19 | |||
| 20 | import ssh | ||
| 21 | |||
| 22 | |||
| 23 | class SshTests(unittest.TestCase): | ||
| 24 | """Tests the ssh functions.""" | ||
| 25 | |||
| 26 | def test_parse_ssh_version(self): | ||
| 27 | """Check _parse_ssh_version() handling.""" | ||
| 28 | ver = ssh._parse_ssh_version('Unknown\n') | ||
| 29 | self.assertEqual(ver, ()) | ||
| 30 | ver = ssh._parse_ssh_version('OpenSSH_1.0\n') | ||
| 31 | self.assertEqual(ver, (1, 0)) | ||
| 32 | ver = ssh._parse_ssh_version('OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.13, OpenSSL 1.0.1f 6 Jan 2014\n') | ||
| 33 | self.assertEqual(ver, (6, 6, 1)) | ||
| 34 | ver = ssh._parse_ssh_version('OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017\n') | ||
| 35 | self.assertEqual(ver, (7, 6)) | ||
| 36 | |||
| 37 | def test_version(self): | ||
| 38 | """Check version() handling.""" | ||
| 39 | with mock.patch('ssh._run_ssh_version', return_value='OpenSSH_1.2\n'): | ||
| 40 | self.assertEqual(ssh.version(), (1, 2)) | ||
| 41 | |||
| 42 | def test_ssh_sock(self): | ||
| 43 | """Check sock() function.""" | ||
| 44 | with mock.patch('tempfile.mkdtemp', return_value='/tmp/foo'): | ||
| 45 | # old ssh version uses port | ||
| 46 | with mock.patch('ssh.version', return_value=(6, 6)): | ||
| 47 | self.assertTrue(ssh.sock().endswith('%p')) | ||
| 48 | ssh._ssh_sock_path = None | ||
| 49 | # new ssh version uses hash | ||
| 50 | with mock.patch('ssh.version', return_value=(6, 7)): | ||
| 51 | self.assertTrue(ssh.sock().endswith('%C')) | ||
| 52 | ssh._ssh_sock_path = None | ||
