Skip to content

Commit

Permalink
small fix on certs utils for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dkmstr committed Aug 11, 2024
1 parent 111d2ec commit e2893e5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tests/utils/certs.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from cryptography.hazmat.primitives.asymmetric import rsa


def selfSignedCert(ip: str, use_password: bool = True) -> typing.Tuple[str, str, str]:
def selfsigned_cert(ip: str, use_password: bool = True) -> typing.Tuple[str, str, str]:
key = rsa.generate_private_key(
public_exponent=65537,
key_size=2048,
Expand All @@ -59,7 +59,7 @@ def selfSignedCert(ip: str, use_password: bool = True) -> typing.Tuple[str, str,
san = x509.SubjectAlternativeName([x509.IPAddress(ipaddress.ip_address(ip))])

basic_contraints = x509.BasicConstraints(ca=True, path_length=0)
now = datetime.datetime.utcnow()
now = datetime.datetime.now(tz=datetime.timezone.utc)
cert = (
x509.CertificateBuilder()
.subject_name(name)
Expand Down Expand Up @@ -88,7 +88,7 @@ def selfSignedCert(ip: str, use_password: bool = True) -> typing.Tuple[str, str,
)


def sslContext() -> typing.Tuple[ssl.SSLContext, str, str]: # pylint: disable=unused-argument
def generate_ssl_context() -> typing.Tuple[ssl.SSLContext, str, str]: # pylint: disable=unused-argument
"""Returns an ssl context an the certificate & password for an ip
Args:
Expand All @@ -101,7 +101,7 @@ def sslContext() -> typing.Tuple[ssl.SSLContext, str, str]: # pylint: disable=u
# First, create server cert and key on temp dir
tmpdir = tempfile.gettempdir()
tmpname = secrets.token_urlsafe(32)
cert, key, password = selfSignedCert('127.0.0.1')
cert, key, password = selfsigned_cert('127.0.0.1')
cert_file = f'{tmpdir}/{tmpname}.pem'
with open(cert_file, 'w', encoding='utf-8') as f:
f.write(key)
Expand All @@ -126,7 +126,7 @@ def ssl_context() -> typing.Generator[typing.Tuple[ssl.SSLContext, str], None, N
ssl.SSLContext: ssl context
"""
# First, create server cert and key on temp dir
ssl_ctx, cert_file, password = sslContext() # pylint: disable=unused-variable
ssl_ctx, cert_file, _password = generate_ssl_context() # pylint: disable=unused-variable

yield ssl_ctx, cert_file

Expand Down

0 comments on commit e2893e5

Please sign in to comment.