Changeset d7499ca in flexoentity for tests


Ignore:
Timestamp:
11/24/25 15:17:00 (7 weeks ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
master
Children:
2fd0536
Parents:
376e21b
Message:

Signature support for Linux and MacOS added

Location:
tests
Files:
4 added
1 edited

Legend:

Unmodified
Added
Removed
  • tests/conftest.py

    r376e21b rd7499ca  
    11# tests/stubs/single_choice_question.py
     2from dataclasses import dataclass, field
    23import pytest
     4import platform
     5from pathlib import Path
    36from datetime import datetime
    4 from dataclasses import dataclass, field
    57from typing import List
    6 from flexoentity import FlexOID, FlexoEntity, EntityType, EntityState, Domain
     8from flexoentity import FlexOID, FlexoEntity, EntityType, EntityState, Domain, get_signing_backend, CertificateReference
     9
    710
    811@pytest.fixture
     
    98101    q._update_fingerprint()
    99102    return q
     103
     104SYSTEM = platform.system()
     105
     106
     107# ─────────────────────────────────────────────────────────────
     108# Basic test data directory + PEM test files
     109# ─────────────────────────────────────────────────────────────
     110
     111@pytest.fixture(scope="session")
     112def test_data_dir():
     113    return Path(__file__).parent / "data"
     114
     115
     116@pytest.fixture(scope="session")
     117def test_cert(test_data_dir):
     118    return test_data_dir / "testcert.pem"
     119
     120
     121@pytest.fixture(scope="session")
     122def test_key(test_data_dir):
     123    return test_data_dir / "testkey.pem"
     124
     125
     126# ─────────────────────────────────────────────────────────────
     127# CertificateReference fixtures for each platform
     128# ─────────────────────────────────────────────────────────────
     129
     130@pytest.fixture(scope="session")
     131def cert_ref_linux(test_cert, test_key):
     132    """Linux: Uses OpenSSL CMS with PEM cert + PEM private key."""
     133    return CertificateReference(
     134        platform="LINUX",
     135        identifier=str(test_cert),
     136        private_key_path=str(test_key),
     137        public_cert_path=str(test_cert),
     138    )
     139
     140
     141@pytest.fixture(scope="session")
     142def cert_ref_macos(test_cert):
     143    """
     144    macOS: Uses Keychain identity with Common Name (CN).
     145    The test cert must be imported into the login keychain with CN=FlexOSignerTest.
     146    """
     147    return CertificateReference(
     148        platform="MACOS",
     149        identifier="FlexOSignerTest",
     150        public_cert_path=str(test_cert),
     151    )
     152
     153@pytest.fixture(scope="session")
     154def backend(test_cert, test_key):
     155    """Return the correct backend for the current platform."""
     156
     157    if SYSTEM == "Linux":
     158        cert_ref = CertificateReference(
     159            platform="LINUX",
     160            identifier=str(test_cert),
     161            private_key_path=str(test_key),
     162            public_cert_path=str(test_cert),
     163        )
     164
     165    elif SYSTEM == "Darwin":
     166        cert_ref = CertificateReference(
     167            platform="MACOS",
     168            identifier="FlexOSignerTest",
     169            public_cert_path=str(test_cert),
     170        )
     171
     172    elif SYSTEM == "Windows":
     173        pytest.skip("Windows signing tests not implemented yet")
     174
     175    else:
     176        pytest.skip(f"Unsupported platform: {SYSTEM}")
     177
     178    try:
     179        backend = get_signing_backend(cert_ref)
     180        # sanity check: ensures cert exists and command is available
     181        _ = backend.certificate_thumbprint
     182        return backend
     183    except Exception as e:
     184        pytest.skip(f"Backend unavailable or misconfigured: {e}")
Note: See TracChangeset for help on using the changeset viewer.