mirror of
https://github.com/ansible-collections/community.crypto.git
synced 2026-05-06 21:33:00 +00:00
Add isort and flake8 to CI (#869)
* Run isort. * Clean up unused assignments. * Add flake8 linting step.
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
@@ -15,12 +17,11 @@ from ansible_collections.community.crypto.plugins.module_utils.acme.backends imp
|
||||
CertificateInformation,
|
||||
CryptoBackend,
|
||||
)
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.acme.errors import (
|
||||
BackendException,
|
||||
)
|
||||
|
||||
from ..test_time import cartesian_product, TIMEZONES
|
||||
from ..test_time import TIMEZONES, cartesian_product
|
||||
|
||||
|
||||
def load_fixture(name):
|
||||
|
||||
@@ -3,41 +3,40 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
import datetime
|
||||
|
||||
import pytest
|
||||
from freezegun import freeze_time
|
||||
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import MagicMock
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.acme.backend_cryptography import (
|
||||
HAS_CURRENT_CRYPTOGRAPHY,
|
||||
CryptographyBackend,
|
||||
)
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.crypto.cryptography_support import (
|
||||
CRYPTOGRAPHY_TIMEZONE,
|
||||
)
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.time import (
|
||||
ensure_utc_timezone,
|
||||
UTC,
|
||||
ensure_utc_timezone,
|
||||
)
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import (
|
||||
MagicMock,
|
||||
)
|
||||
from freezegun import freeze_time
|
||||
|
||||
from ..test_time import TIMEZONES
|
||||
from .backend_data import (
|
||||
TEST_KEYS,
|
||||
TEST_CSRS,
|
||||
TEST_CERT,
|
||||
TEST_CERT_DAYS,
|
||||
TEST_CERT_INFO,
|
||||
TEST_PARSE_ACME_TIMESTAMP,
|
||||
TEST_CSRS,
|
||||
TEST_INTERPOLATE_TIMESTAMP,
|
||||
TEST_KEYS,
|
||||
TEST_PARSE_ACME_TIMESTAMP,
|
||||
)
|
||||
|
||||
from ..test_time import TIMEZONES
|
||||
|
||||
|
||||
if not HAS_CURRENT_CRYPTOGRAPHY:
|
||||
pytest.skip('cryptography not found')
|
||||
|
||||
@@ -3,36 +3,37 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
import datetime
|
||||
|
||||
import pytest
|
||||
from freezegun import freeze_time
|
||||
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import MagicMock
|
||||
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.acme.backend_openssl_cli import (
|
||||
OpenSSLCLIBackend,
|
||||
)
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.time import (
|
||||
ensure_utc_timezone,
|
||||
UTC,
|
||||
ensure_utc_timezone,
|
||||
)
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import (
|
||||
MagicMock,
|
||||
)
|
||||
from freezegun import freeze_time
|
||||
|
||||
from .backend_data import (
|
||||
TEST_KEYS,
|
||||
TEST_CSRS,
|
||||
TEST_CERT,
|
||||
TEST_CERT_OPENSSL_OUTPUT,
|
||||
TEST_CERT_DAYS,
|
||||
TEST_CERT_INFO,
|
||||
TEST_PARSE_ACME_TIMESTAMP,
|
||||
TEST_CERT_OPENSSL_OUTPUT,
|
||||
TEST_CSRS,
|
||||
TEST_INTERPOLATE_TIMESTAMP,
|
||||
TEST_KEYS,
|
||||
TEST_PARSE_ACME_TIMESTAMP,
|
||||
)
|
||||
|
||||
|
||||
# from ..test_time import TIMEZONES
|
||||
|
||||
|
||||
|
||||
@@ -3,25 +3,25 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import MagicMock
|
||||
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.acme.challenges import (
|
||||
Authorization,
|
||||
Challenge,
|
||||
combine_identifier,
|
||||
split_identifier,
|
||||
Challenge,
|
||||
Authorization,
|
||||
)
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.acme.errors import (
|
||||
ACMEProtocolException,
|
||||
ModuleFailException,
|
||||
)
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import (
|
||||
MagicMock,
|
||||
)
|
||||
|
||||
|
||||
def test_combine_identifier():
|
||||
|
||||
@@ -3,17 +3,18 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import MagicMock
|
||||
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.acme.errors import (
|
||||
format_error_problem,
|
||||
ACMEProtocolException,
|
||||
format_error_problem,
|
||||
)
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import (
|
||||
MagicMock,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -3,16 +3,18 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import MagicMock
|
||||
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.acme.io import (
|
||||
read_file,
|
||||
write_file,
|
||||
)
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import (
|
||||
MagicMock,
|
||||
)
|
||||
|
||||
|
||||
TEST_TEXT = r"""1234
|
||||
|
||||
@@ -3,21 +3,19 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import MagicMock
|
||||
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.acme.orders import (
|
||||
Order,
|
||||
)
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.acme.errors import (
|
||||
ACMEProtocolException,
|
||||
)
|
||||
from ansible_collections.community.crypto.plugins.module_utils.acme.orders import Order
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import (
|
||||
MagicMock,
|
||||
)
|
||||
|
||||
|
||||
def test_order_from_json():
|
||||
|
||||
@@ -3,28 +3,26 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
import datetime
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.acme.backends import (
|
||||
CertificateInformation,
|
||||
)
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.acme.utils import (
|
||||
compute_cert_id,
|
||||
nopad_b64,
|
||||
parse_retry_after,
|
||||
pem_to_der,
|
||||
process_links,
|
||||
parse_retry_after,
|
||||
compute_cert_id,
|
||||
)
|
||||
|
||||
from .backend_data import (
|
||||
TEST_PEM_DERS,
|
||||
)
|
||||
from .backend_data import TEST_PEM_DERS
|
||||
|
||||
|
||||
NOPAD_B64 = [
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
import base64
|
||||
@@ -12,10 +14,9 @@ import re
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.crypto._asn1 import (
|
||||
serialize_asn1_string_as_der,
|
||||
pack_asn1,
|
||||
serialize_asn1_string_as_der,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -5,27 +5,27 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
import re
|
||||
|
||||
import cryptography
|
||||
import pytest
|
||||
|
||||
from cryptography.x509 import NameAttribute, oid
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import (
|
||||
OpenSSLObjectError,
|
||||
)
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.crypto.cryptography_support import (
|
||||
cryptography_get_name,
|
||||
_adjust_idn,
|
||||
_parse_dn_component,
|
||||
_parse_dn,
|
||||
_parse_dn_component,
|
||||
cryptography_get_name,
|
||||
)
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.version import LooseVersion
|
||||
from ansible_collections.community.crypto.plugins.module_utils.version import (
|
||||
LooseVersion,
|
||||
)
|
||||
from cryptography.x509 import NameAttribute, oid
|
||||
|
||||
|
||||
@pytest.mark.parametrize('unicode, idna, cycled_unicode', [
|
||||
@@ -71,7 +71,7 @@ def test_adjust_idn(unicode, idna, cycled_unicode):
|
||||
])
|
||||
def test_adjust_idn_fail_valueerror(value, idn_rewrite, message):
|
||||
with pytest.raises(ValueError, match=message):
|
||||
result = _adjust_idn(value, idn_rewrite)
|
||||
_adjust_idn(value, idn_rewrite)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('value, idn_rewrite, message', [
|
||||
@@ -86,7 +86,7 @@ def test_adjust_idn_fail_valueerror(value, idn_rewrite, message):
|
||||
])
|
||||
def test_adjust_idn_fail_user_error(value, idn_rewrite, message):
|
||||
with pytest.raises(OpenSSLObjectError, match=message):
|
||||
result = _adjust_idn(value, idn_rewrite)
|
||||
_adjust_idn(value, idn_rewrite)
|
||||
|
||||
|
||||
def test_cryptography_get_name_invalid_prefix():
|
||||
@@ -149,7 +149,7 @@ if LooseVersion('2.9') <= LooseVersion(cryptography.__version__) < LooseVersion(
|
||||
])
|
||||
def test_parse_dn_component_failure(name, options, message):
|
||||
with pytest.raises(OpenSSLObjectError, match=u'^%s$' % re.escape(message)):
|
||||
result = _parse_dn_component(name, **options)
|
||||
_parse_dn_component(name, **options)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('name, expected', [
|
||||
@@ -169,4 +169,4 @@ def test_parse_dn(name, expected):
|
||||
])
|
||||
def test_parse_dn_failure(name, message):
|
||||
with pytest.raises(OpenSSLObjectError, match=u'^%s$' % re.escape(message)):
|
||||
result = _parse_dn(name)
|
||||
_parse_dn(name)
|
||||
|
||||
@@ -5,17 +5,18 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.crypto.math import (
|
||||
binary_exp_mod,
|
||||
simple_gcd,
|
||||
quick_is_not_prime,
|
||||
convert_bytes_to_int,
|
||||
convert_int_to_bytes,
|
||||
convert_int_to_hex,
|
||||
convert_bytes_to_int,
|
||||
quick_is_not_prime,
|
||||
simple_gcd,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -5,15 +5,16 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.crypto.pem import (
|
||||
extract_first_pem,
|
||||
identify_pem_format,
|
||||
identify_private_key_format,
|
||||
split_pem_list,
|
||||
extract_first_pem,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -5,17 +5,19 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.openssh.certificate import (
|
||||
OpensshCertificate,
|
||||
OpensshCertificateOption,
|
||||
OpensshCertificateTimeParameters,
|
||||
parse_option_list
|
||||
parse_option_list,
|
||||
)
|
||||
|
||||
|
||||
# Type: ssh-rsa-cert-v01@openssh.com user certificate
|
||||
# Public key: RSA-CERT SHA256:SvUwwUer4AwsdePYseJR3LcZS8lnKi6BqiL51Dop030
|
||||
# Signing CA: DSA SHA256:YCdJ2lYU+FSkWUud7zg1SJszprXoRGNU/GVcqXUjgC8
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
import pytest
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
import os.path
|
||||
from getpass import getuser
|
||||
@@ -15,17 +15,19 @@ from os import remove, rmdir
|
||||
from socket import gethostname
|
||||
from tempfile import mkdtemp
|
||||
|
||||
import pytest
|
||||
from ansible_collections.community.crypto.plugins.module_utils.openssh.cryptography import (
|
||||
HAS_OPENSSH_SUPPORT,
|
||||
InvalidCommentError,
|
||||
InvalidPrivateKeyFileError,
|
||||
InvalidPublicKeyFileError,
|
||||
InvalidKeySizeError,
|
||||
InvalidKeyTypeError,
|
||||
InvalidPassphraseError,
|
||||
OpensshKeypair
|
||||
InvalidPrivateKeyFileError,
|
||||
InvalidPublicKeyFileError,
|
||||
OpensshKeypair,
|
||||
)
|
||||
|
||||
|
||||
DEFAULT_KEY_PARAMS = [
|
||||
(
|
||||
'rsa',
|
||||
|
||||
@@ -5,16 +5,18 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.openssh.utils import (
|
||||
parse_openssh_version,
|
||||
OpensshParser,
|
||||
_OpensshWriter
|
||||
_OpensshWriter,
|
||||
parse_openssh_version,
|
||||
)
|
||||
|
||||
|
||||
SSH_VERSION_STRING = "OpenSSH_7.9p1, OpenSSL 1.1.0i-fips 14 Aug 2018"
|
||||
SSH_VERSION_NUMBER = "7.9"
|
||||
|
||||
@@ -135,7 +137,6 @@ def test_valid_seek():
|
||||
|
||||
|
||||
def test_invalid_seek():
|
||||
result = False
|
||||
buffer = b'buffer'
|
||||
parser = OpensshParser(buffer)
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
@@ -10,21 +12,19 @@ import datetime
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
from freezegun import freeze_time
|
||||
|
||||
from ansible.module_utils.common.collections import is_sequence
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.time import (
|
||||
UTC,
|
||||
add_or_remove_timezone,
|
||||
get_now_datetime,
|
||||
convert_relative_to_datetime,
|
||||
ensure_utc_timezone,
|
||||
from_epoch_seconds,
|
||||
get_epoch_seconds,
|
||||
get_now_datetime,
|
||||
get_relative_time_option,
|
||||
remove_timezone,
|
||||
UTC,
|
||||
)
|
||||
from freezegun import freeze_time
|
||||
|
||||
|
||||
TIMEZONES = [
|
||||
|
||||
Reference in New Issue
Block a user