|
| 1 | +import os |
| 2 | +import unittest |
| 3 | +from pysqa import QueueAdapter |
| 4 | + |
| 5 | +try: |
| 6 | + import paramiko |
| 7 | + from tqdm import tqdm |
| 8 | + from pysqa.base.remote import get_transport |
| 9 | + |
| 10 | + skip_remote_test = False |
| 11 | +except ImportError: |
| 12 | + skip_remote_test = True |
| 13 | + |
| 14 | + |
| 15 | +@unittest.skipIf( |
| 16 | + skip_remote_test, |
| 17 | + "Either paramiko or tqdm are not installed, so the remote queue adapter tests are skipped.", |
| 18 | +) |
| 19 | +class TestRemoteQueueAdapterAuth(unittest.TestCase): |
| 20 | + def test_password_auth(self): |
| 21 | + path = os.path.dirname(os.path.abspath(__file__)) |
| 22 | + remote = QueueAdapter(directory=os.path.join(path, "config/remote_rebex")) |
| 23 | + remote._adapter._ssh_ask_for_password = False |
| 24 | + remote._adapter._ssh_key = None |
| 25 | + self.assertIsNotNone(remote._adapter._open_ssh_connection()) |
| 26 | + |
| 27 | + def test_key_auth(self): |
| 28 | + path = os.path.dirname(os.path.abspath(__file__)) |
| 29 | + remote = QueueAdapter(directory=os.path.join(path, "config/remote_rebex")) |
| 30 | + remote._adapter._ssh_password = None |
| 31 | + with self.assertRaises(ValueError): |
| 32 | + remote._adapter._open_ssh_connection() |
| 33 | + |
| 34 | + def test_two_factor_auth(self): |
| 35 | + path = os.path.dirname(os.path.abspath(__file__)) |
| 36 | + remote = QueueAdapter(directory=os.path.join(path, "config/remote_rebex")) |
| 37 | + remote._adapter._ssh_two_factor_authentication = True |
| 38 | + with self.assertRaises(paramiko.ssh_exception.AuthenticationException): |
| 39 | + remote._adapter._open_ssh_connection() |
0 commit comments