source: flexoentity/tests/conftest.py@ 100c1d2

Last change on this file since 100c1d2 was 100c1d2, checked in by Enrico Schwass <ennoausberlin@…>, 7 weeks ago

typos fixed

  • Property mode set to 100644
File size: 3.8 KB
Line 
1import pytest
2import platform
3from pathlib import Path
4from datetime import datetime
5from flexoentity import Domain, FlexoSignature
6from flexoentity import get_signing_backend, CertificateReference
7
8
9@pytest.fixture
10def fixed_datetime(monkeypatch):
11 class FixedDate(datetime):
12 @classmethod
13 def now(cls, tz=None):
14 return datetime(2025, 11, 1, tzinfo=tz)
15 monkeypatch.setattr("flexoentity.id_factory.datetime", FixedDate)
16 return FixedDate
17
18
19@pytest.fixture
20def sample_domain():
21 domain_id = "PY_ARITHM"
22 return Domain.with_domain_id(domain_id=domain_id,
23 fullname="PYTHON_ARITHMETIC",
24 description="ALL ABOUT ARITHMETIC IN PYTHON")
25
26
27SYSTEM = platform.system()
28
29
30# ─────────────────────────────────────────────────────────────
31# Basic test data directory + PEM test files
32# ─────────────────────────────────────────────────────────────
33
34@pytest.fixture(scope="session")
35def test_data_dir():
36 return Path(__file__).parent / "data"
37
38
39@pytest.fixture(scope="session")
40def test_cert(test_data_dir):
41 return test_data_dir / "testcert.pem"
42
43
44@pytest.fixture(scope="session")
45def test_key(test_data_dir):
46 return test_data_dir / "testkey.pem"
47
48
49# ─────────────────────────────────────────────────────────────
50# CertificateReference fixtures for each platform
51# ─────────────────────────────────────────────────────────────
52
53@pytest.fixture(scope="session")
54def cert_ref_linux(test_cert, test_key):
55 """Linux: Uses OpenSSL CMS with PEM cert + PEM private key."""
56 return CertificateReference(
57 platform="LINUX",
58 identifier=str(test_cert),
59 private_key_path=str(test_key),
60 public_cert_path=str(test_cert),
61 )
62
63
64@pytest.fixture(scope="session")
65def cert_ref_macos(test_cert):
66 """
67 macOS: Uses Keychain identity with Common Name (CN).
68 The test cert must be imported into the login keychain with CN=FlexOSignerTest.
69 """
70 return CertificateReference(
71 platform="MACOS",
72 identifier="FlexOSignerTest",
73 public_cert_path=str(test_cert),
74 )
75
76
77@pytest.fixture(scope="session")
78def backend(test_cert, test_key):
79 """Return the correct backend for the current platform."""
80
81 if SYSTEM == "Linux":
82 cert_ref = CertificateReference(
83 platform="LINUX",
84 identifier=str(test_cert),
85 private_key_path=str(test_key),
86 public_cert_path=str(test_cert),
87 )
88
89 elif SYSTEM == "Darwin":
90 cert_ref = CertificateReference(
91 platform="MACOS",
92 identifier="FlexOSignerTest",
93 public_cert_path=str(test_cert),
94 )
95
96 elif SYSTEM == "Windows":
97 pytest.skip("Windows signing tests not implemented yet")
98
99 else:
100 pytest.skip(f"Unsupported platform: {SYSTEM}")
101
102 try:
103 backend = get_signing_backend(cert_ref)
104 # sanity check: ensures cert exists and command is available
105 _ = backend.certificate_thumbprint
106 return backend
107 except Exception as e:
108 pytest.skip(f"Backend unavailable or misconfigured: {e}")
109
110
111@pytest.fixture
112def sample_signature(sample_domain, cert_ref_linux):
113 return FlexoSignature.with_domain_id(domain_id="SIG", signed_entity=sample_domain,
114 certificate_reference=cert_ref_linux,
115 comment="This is a mock signature")
Note: See TracBrowser for help on using the repository browser.