Reformat code with black and isort.

This commit is contained in:
Felix Fontein
2025-10-06 18:34:59 +02:00
parent f45232635c
commit d65d37e9e9
132 changed files with 17581 additions and 14729 deletions
@@ -7,19 +7,23 @@
# It is licensed under the Apache 2.0 license (see LICENSES/Apache-2.0.txt in this collection)
# SPDX-License-Identifier: Apache-2.0
from __future__ import (absolute_import, division, print_function)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import unittest
from ansible_collections.community.docker.plugins.module_utils._api.transport.sshconn import SSHSocket, SSHHTTPAdapter
from ansible_collections.community.docker.plugins.module_utils._api.transport.sshconn import (
SSHHTTPAdapter,
SSHSocket,
)
class SSHAdapterTest(unittest.TestCase):
@staticmethod
def test_ssh_hostname_prefix_trim():
conn = SSHHTTPAdapter(
base_url="ssh://user@hostname:1234", shell_out=True)
conn = SSHHTTPAdapter(base_url="ssh://user@hostname:1234", shell_out=True)
assert conn.ssh_host == "user@hostname:1234"
@staticmethod
@@ -7,30 +7,30 @@
# It is licensed under the Apache 2.0 license (see LICENSES/Apache-2.0.txt in this collection)
# SPDX-License-Identifier: Apache-2.0
from __future__ import (absolute_import, division, print_function)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import unittest
import pytest
from ansible_collections.community.docker.plugins.module_utils._api.transport import (
ssladapter,
)
from ansible_collections.community.docker.plugins.module_utils._api.transport import ssladapter
HAS_MATCH_HOSTNAME = True
try:
from backports.ssl_match_hostname import (
match_hostname, CertificateError
)
from backports.ssl_match_hostname import CertificateError, match_hostname
except ImportError:
try:
from ssl import (
match_hostname, CertificateError
)
from ssl import CertificateError, match_hostname
except ImportError:
HAS_MATCH_HOSTNAME = False
try:
from ssl import OP_NO_SSLv3, OP_NO_SSLv2, OP_NO_TLSv1
from ssl import OP_NO_SSLv2, OP_NO_SSLv3, OP_NO_TLSv1
except ImportError:
OP_NO_SSLv2 = 0x1000000
OP_NO_SSLv3 = 0x2000000
@@ -47,51 +47,51 @@ class SSLAdapterTest(unittest.TestCase):
assert not ssl_context.options & OP_NO_TLSv1
@pytest.mark.skipif(not HAS_MATCH_HOSTNAME, reason='match_hostname is not available')
@pytest.mark.skipif(not HAS_MATCH_HOSTNAME, reason="match_hostname is not available")
class MatchHostnameTest(unittest.TestCase):
cert = {
'issuer': (
(('countryName', 'US'),),
(('stateOrProvinceName', 'California'),),
(('localityName', 'San Francisco'),),
(('organizationName', 'Docker Inc'),),
(('organizationalUnitName', 'Docker-Python'),),
(('commonName', 'localhost'),),
(('emailAddress', 'info@docker.com'),)
"issuer": (
(("countryName", "US"),),
(("stateOrProvinceName", "California"),),
(("localityName", "San Francisco"),),
(("organizationName", "Docker Inc"),),
(("organizationalUnitName", "Docker-Python"),),
(("commonName", "localhost"),),
(("emailAddress", "info@docker.com"),),
),
'notAfter': 'Mar 25 23:08:23 2030 GMT',
'notBefore': 'Mar 25 23:08:23 2016 GMT',
'serialNumber': 'BD5F894C839C548F',
'subject': (
(('countryName', 'US'),),
(('stateOrProvinceName', 'California'),),
(('localityName', 'San Francisco'),),
(('organizationName', 'Docker Inc'),),
(('organizationalUnitName', 'Docker-Python'),),
(('commonName', 'localhost'),),
(('emailAddress', 'info@docker.com'),)
"notAfter": "Mar 25 23:08:23 2030 GMT",
"notBefore": "Mar 25 23:08:23 2016 GMT",
"serialNumber": "BD5F894C839C548F",
"subject": (
(("countryName", "US"),),
(("stateOrProvinceName", "California"),),
(("localityName", "San Francisco"),),
(("organizationName", "Docker Inc"),),
(("organizationalUnitName", "Docker-Python"),),
(("commonName", "localhost"),),
(("emailAddress", "info@docker.com"),),
),
'subjectAltName': (
('DNS', 'localhost'),
('DNS', '*.gensokyo.jp'),
('IP Address', '127.0.0.1'),
"subjectAltName": (
("DNS", "localhost"),
("DNS", "*.gensokyo.jp"),
("IP Address", "127.0.0.1"),
),
'version': 3
"version": 3,
}
def test_match_ip_address_success(self):
assert match_hostname(self.cert, '127.0.0.1') is None
assert match_hostname(self.cert, "127.0.0.1") is None
def test_match_localhost_success(self):
assert match_hostname(self.cert, 'localhost') is None
assert match_hostname(self.cert, "localhost") is None
def test_match_dns_success(self):
assert match_hostname(self.cert, 'touhou.gensokyo.jp') is None
assert match_hostname(self.cert, "touhou.gensokyo.jp") is None
def test_match_ip_address_failure(self):
with pytest.raises(CertificateError):
match_hostname(self.cert, '192.168.0.25')
match_hostname(self.cert, "192.168.0.25")
def test_match_dns_failure(self):
with pytest.raises(CertificateError):
match_hostname(self.cert, 'foobar.co.uk')
match_hostname(self.cert, "foobar.co.uk")