Skip to content

Commit

Permalink
Move cert fixture to filesystem test folder (#814)
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Coetzee <[email protected]>
  • Loading branch information
Pipboyguy committed Dec 28, 2023
1 parent 8a3a25e commit 2265e7d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 46 deletions.
48 changes: 2 additions & 46 deletions tests/load/conftest.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import os
import tempfile
from dlt.common.pendulum import timedelta, __utcnow
from typing import Iterator

import pytest
from cryptography import x509
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.x509.oid import NameOID
from typing import Iterator

from tests.load.utils import DEFAULT_BUCKETS, ALL_BUCKETS
from tests.utils import preserve_environ


@pytest.fixture(scope="function", params=DEFAULT_BUCKETS)
Expand All @@ -31,40 +24,3 @@ def all_buckets_env(request) -> Iterator[str]:
bucket_url = request.param
os.environ["DESTINATION__FILESYSTEM__BUCKET_URL"] = bucket_url
yield bucket_url


@pytest.fixture(scope="function")
def self_signed_cert() -> Iterator[str]:
key = rsa.generate_private_key(public_exponent=65537, key_size=2048, backend=default_backend())

subject = issuer = x509.Name(
[
x509.NameAttribute(NameOID.COUNTRY_NAME, "DE"),
x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, "Berlin"),
x509.NameAttribute(NameOID.LOCALITY_NAME, "Britz"),
x509.NameAttribute(NameOID.ORGANIZATION_NAME, "dltHub"),
x509.NameAttribute(NameOID.COMMON_NAME, "localhost"),
]
)
cert = (
x509.CertificateBuilder()
.subject_name(subject)
.issuer_name(issuer)
.public_key(key.public_key())
.serial_number(x509.random_serial_number())
.not_valid_before(__utcnow())
.not_valid_after(__utcnow() + timedelta(days=1))
.add_extension(
x509.SubjectAlternativeName([x509.DNSName("localhost")]),
critical=False,
)
.sign(key, hashes.SHA256(), default_backend())
)

with tempfile.NamedTemporaryFile(suffix=".crt", delete=False) as cert_file:
cert_file.write(cert.public_bytes(serialization.Encoding.PEM))
cert_path = cert_file.name

yield cert_path

os.remove(cert_path)
49 changes: 49 additions & 0 deletions tests/load/filesystem/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import os
import tempfile
from typing import Iterator

import pytest
from cryptography import x509
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.x509.oid import NameOID

from dlt.common.pendulum import timedelta, __utcnow


@pytest.fixture(scope="function")
def self_signed_cert() -> Iterator[str]:
key = rsa.generate_private_key(public_exponent=65537, key_size=2048, backend=default_backend())

subject = issuer = x509.Name(
[
x509.NameAttribute(NameOID.COUNTRY_NAME, "DE"),
x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, "Berlin"),
x509.NameAttribute(NameOID.LOCALITY_NAME, "Britz"),
x509.NameAttribute(NameOID.ORGANIZATION_NAME, "dltHub"),
x509.NameAttribute(NameOID.COMMON_NAME, "localhost"),
]
)
cert = (
x509.CertificateBuilder()
.subject_name(subject)
.issuer_name(issuer)
.public_key(key.public_key())
.serial_number(x509.random_serial_number())
.not_valid_before(__utcnow())
.not_valid_after(__utcnow() + timedelta(days=1))
.add_extension(
x509.SubjectAlternativeName([x509.DNSName("localhost")]),
critical=False,
)
.sign(key, hashes.SHA256(), default_backend())
)

with tempfile.NamedTemporaryFile(suffix=".crt", delete=False) as cert_file:
cert_file.write(cert.public_bytes(serialization.Encoding.PEM))
cert_path = cert_file.name

yield cert_path

os.remove(cert_path)

0 comments on commit 2265e7d

Please sign in to comment.