Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ def connect(self):
try:
if self.target_host.password:
self.session.connect(self.target_host.ip, username=self.target_host.username, password=self.target_host.password)
else:
elif self.target_host.access_key:
key_stream = StringIO(self.target_host.access_key)
key_obj = RSAKey.from_private_key(key_stream)
self.session.connect(self.target_host.ip, username=self.target_host.username, pkey=key_obj)
else:
raise Exception('Both password and access key are empty.')
except NoValidConnectionsError as e:
error_code = next(e.errors.itervalues(), type('e', (object,), {'errno': 0})).errno
raise ExcutorConnectionError(error_code, e)
Expand Down
7 changes: 7 additions & 0 deletions package/tests/test_linux_script_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ def test_pem_file(self):
executor.connect()
self.session.connect.assert_called_with('1.2.3.4', username='root', pkey=key_obj)

def test_no_password_nor_pen_file(self):
self.host.username = 'root'
executor = LinuxScriptExecutor(self.logger, self.host, self.cancel_sampler)
with self.assertRaises(Exception) as e:
executor.connect()
self.assertEqual('Both password and access key are empty.', e.exception.inner_error.message)

def test_create_temp_folder_success(self):
self._mock_session_answer(0,'tmp123','')
result = self.executor.create_temp_folder()
Expand Down