Skip to content

Commit

Permalink
Only run proxy_command unit tests when nc is available
Browse files Browse the repository at this point in the history
  • Loading branch information
ronf committed Apr 27, 2023
1 parent 1469ac9 commit 1bc77c1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
16 changes: 4 additions & 12 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import os
from pathlib import Path
import socket
import subprocess
import sys
import unittest
from unittest.mock import patch
Expand All @@ -51,17 +50,10 @@

from .server import Server, ServerTestCase

from .util import asynctest, gss_available, patch_gss, run
from .util import asynctest, gss_available, nc_available, patch_gss
from .util import patch_getnameinfo, x509_available


try:
run('which nc')
_nc_available = True
except subprocess.CalledProcessError: # pragma: no cover
_nc_available = False


class _CheckAlgsClientConnection(asyncssh.SSHClientConnection):
"""Test specification of encryption algorithms"""

Expand Down Expand Up @@ -609,7 +601,7 @@ async def test_get_server_host_key_connect_failure(self):
with self.assertRaises(OSError):
await asyncssh.get_server_host_key('\xff')

@unittest.skipUnless(_nc_available, 'Netcat not available')
@unittest.skipUnless(nc_available, 'Netcat not available')
@asynctest
async def test_get_server_host_key_proxy(self):
"""Test retrieving a server host key using proxy command"""
Expand All @@ -621,7 +613,7 @@ async def test_get_server_host_key_proxy(self):

self.assertEqual(key, keylist[0])

@unittest.skipUnless(_nc_available, 'Netcat not available')
@unittest.skipUnless(nc_available, 'Netcat not available')
@asynctest
async def test_get_server_host_key_proxy_failure(self):
"""Test failure retrieving a server host key using proxy command"""
Expand Down Expand Up @@ -1624,7 +1616,7 @@ async def test_run_server(self):
async with self.run_server(sock):
pass

@unittest.skipUnless(_nc_available, 'Netcat not available')
@unittest.skipUnless(nc_available, 'Netcat not available')
@asynctest
async def test_connect_reverse_proxy(self):
"""Test reverse direction SSH connection with proxy command"""
Expand Down
3 changes: 2 additions & 1 deletion tests/test_connection_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from .keysign_stub import create_subprocess_exec_stub
from .server import Server, ServerTestCase
from .util import asynctest, gss_available, patch_getnameinfo, patch_gss
from .util import make_certificate, x509_available
from .util import make_certificate, nc_available, x509_available


class _FailValidateHostSSHServerConnection(asyncssh.SSHServerConnection):
Expand Down Expand Up @@ -658,6 +658,7 @@ async def test_get_server_auth_methods(self):

self.assertEqual(auth_methods, ['hostbased'])

@unittest.skipUnless(nc_available, 'Netcat not available')
@asynctest
async def test_get_server_auth_methods_no_sockname(self):
"""Test getting auth methods from the test server"""
Expand Down
21 changes: 12 additions & 9 deletions tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import binascii
import functools
import os
import shutil
import subprocess
import sys
import tempfile
Expand All @@ -33,14 +34,23 @@

from cryptography.hazmat.backends.openssl import backend

# pylint: disable=unused-import
from asyncssh.gss import gss_available
from asyncssh.logging import logger
from asyncssh.misc import ConnectionLost, SignalReceived
from asyncssh.packet import Byte, String, UInt32, UInt64
from asyncssh.public_key import generate_private_key


# pylint: disable=ungrouped-imports, unused-import

try:
import bcrypt
bcrypt_available = hasattr(bcrypt, 'kdf')
except ImportError: # pragma: no cover
bcrypt_available = False

nc_available = bool(shutil.which('nc'))

try:
import uvloop
uvloop_available = True
Expand All @@ -53,14 +63,7 @@
except ImportError: # pragma: no cover
x509_available = False

# pylint: enable=unused-import

from asyncssh.gss import gss_available
from asyncssh.logging import logger
from asyncssh.misc import ConnectionLost, SignalReceived
from asyncssh.packet import Byte, String, UInt32, UInt64
from asyncssh.public_key import generate_private_key

# pylint: enable=ungrouped-imports, unused-import

# pylint: disable=no-member

Expand Down

0 comments on commit 1bc77c1

Please sign in to comment.