Skip to content

Commit

Permalink
Update AZP test container version (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
jborean93 authored Jun 11, 2024
1 parent 8748e86 commit 9c8bade
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .azure-pipelines/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ variables:
resources:
containers:
- container: default
image: quay.io/ansible/azure-pipelines-test-container:4.0.1
image: quay.io/ansible/azure-pipelines-test-container:6.0.0

pool: Standard

Expand Down
4 changes: 4 additions & 0 deletions changelogs/fragments/datetime-utc-deprecation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bugfixes:
- >-
Removed usages of the python call ``datetime.datetime.utcnow()`` in favour of ``datetime.datetime.now(datetime.timezone.utc)``.
The original method is now deprecated in Python 3.12 and will be removed in a later version.
8 changes: 4 additions & 4 deletions plugins/plugin_utils/_reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def reboot_host(
if send_reboot_command:
_perform_reboot(task_action, connection, reboot_command)

start = datetime.datetime.utcnow()
start = datetime.datetime.now(datetime.timezone.utc)
result["changed"] = True
result["rebooted"] = True

Expand Down Expand Up @@ -291,7 +291,7 @@ def reboot_host(
result["exception"] = traceback.format_exc()

if start:
elapsed = datetime.datetime.utcnow() - start
elapsed = datetime.datetime.now(datetime.timezone.utc) - start
result["elapsed"] = elapsed.seconds

return result
Expand Down Expand Up @@ -358,10 +358,10 @@ def _do_until_success_or_timeout(
**kwargs: t.Any,
) -> t.Optional[T]:
"""Runs the function multiple times ignoring errors until a timeout occurs"""
max_end_time = datetime.datetime.utcnow() + datetime.timedelta(seconds=timeout)
max_end_time = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(seconds=timeout)

def wait_condition(idx):
return datetime.datetime.utcnow() < max_end_time
return datetime.datetime.now(datetime.timezone.utc) < max_end_time

try:
return _do_until_success_or_condition(
Expand Down
33 changes: 26 additions & 7 deletions tests/unit/plugins/plugin_utils/_ldap/test_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,19 @@ class TlsServer(t.NamedTuple):
@pytest.fixture(scope="module")
def tls_server(tmp_path_factory: pytest.TempPathFactory) -> TlsServer:
cn = "microsoft.ad.test"
now = datetime.datetime.utcnow()

now = datetime.datetime.now(datetime.timezone.utc)

ca_key_usage = x509.KeyUsage(
digital_signature=True,
content_commitment=False,
key_encipherment=False,
data_encipherment=False,
key_agreement=False,
key_cert_sign=True,
crl_sign=True,
encipher_only=False,
decipher_only=False,
)
ca_key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
ca_name = x509.Name([x509.NameAttribute(x509.NameOID.COMMON_NAME, "microsoft.ad")])
ca_cert = (
Expand All @@ -50,14 +61,18 @@ def tls_server(tmp_path_factory: pytest.TempPathFactory) -> TlsServer:
.not_valid_before(now)
.not_valid_after(now + datetime.timedelta(days=365))
.add_extension(x509.BasicConstraints(ca=True, path_length=None), critical=True)
.add_extension(ca_key_usage, critical=True)
.add_extension(x509.SubjectKeyIdentifier.from_public_key(ca_key.public_key()), critical=False)
.sign(ca_key, hashes.SHA256())
)

key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
ca_aki = x509.AuthorityKeyIdentifier.from_issuer_public_key(
ca_cert.public_key()) # type: ignore[arg-type]

name = x509.Name([x509.NameAttribute(x509.NameOID.COMMON_NAME, cn)])

now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)
cert = (
x509.CertificateBuilder()
.subject_name(name)
Expand All @@ -66,6 +81,7 @@ def tls_server(tmp_path_factory: pytest.TempPathFactory) -> TlsServer:
.serial_number(x509.random_serial_number())
.not_valid_before(now)
.not_valid_after(now + datetime.timedelta(days=365))
.add_extension(ca_aki, critical=False)
.sign(ca_key, hashes.SHA256())
)
cert_pem = cert.public_bytes(encoding=serialization.Encoding.PEM)
Expand Down Expand Up @@ -95,8 +111,10 @@ def tls_server(tmp_path_factory: pytest.TempPathFactory) -> TlsServer:

@pytest.fixture(scope="module")
def client_certificate(tls_server: TlsServer) -> t.Tuple["x509.Certificate", "rsa.RSAPrivateKey"]:
now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)

ca_aki = x509.AuthorityKeyIdentifier.from_issuer_public_key(
tls_server.ca.public_key()) # type: ignore[arg-type]
key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
name = x509.Name([x509.NameAttribute(x509.NameOID.COMMON_NAME, "client-auth")])
cert = (
Expand All @@ -119,6 +137,7 @@ def client_certificate(tls_server: TlsServer) -> t.Tuple["x509.Certificate", "rs
False,
)
.add_extension(x509.ExtendedKeyUsage([x509.oid.ExtendedKeyUsageOID.CLIENT_AUTH]), False)
.add_extension(ca_aki, critical=False)
.sign(tls_server.ca_key, hashes.SHA256())
)

Expand All @@ -143,7 +162,7 @@ def test_get_tls_binding_data_rsa(

key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
name = x509.Name([x509.NameAttribute(x509.NameOID.COMMON_NAME, "test")])
now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)
try:
cert = (
x509.CertificateBuilder()
Expand All @@ -154,7 +173,7 @@ def test_get_tls_binding_data_rsa(
.not_valid_before(now)
.not_valid_after(now + datetime.timedelta(days=365))
.add_extension(x509.ExtendedKeyUsage([x509.oid.ExtendedKeyUsageOID.SERVER_AUTH]), False)
.sign(key, cert_algo)
.sign(key, cert_algo) # type: ignore[arg-type]
).public_bytes(encoding=serialization.Encoding.DER)
except (UnsupportedAlgorithm, ValueError) as e:
pytest.skip(f"Hash algorithm is unavailable: {e}")
Expand All @@ -170,7 +189,7 @@ def test_get_tls_binding_data_rsa(
def test_get_tls_binding_data_ed25519() -> None:
key = ed25519.Ed25519PrivateKey.generate()
name = x509.Name([x509.NameAttribute(x509.NameOID.COMMON_NAME, "test")])
now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)
cert = (
x509.CertificateBuilder()
.subject_name(name)
Expand Down

0 comments on commit 9c8bade

Please sign in to comment.