1 |
d3fa9147
|
Stanislav Král
|
import os
|
2 |
e39e138f
|
Stanislav Král
|
import sqlite3
|
3 |
|
|
from sqlite3 import Connection
|
4 |
|
|
|
5 |
|
|
import pytest
|
6 |
d3fa9147
|
Stanislav Král
|
|
7 |
20b33bd4
|
Jan Pašek
|
from src.config.configuration import test_configuration, Configuration
|
8 |
2bb3759c
|
Stanislav Král
|
from src.config.connection_provider import ConnectionProvider
|
9 |
d3fa9147
|
Stanislav Král
|
from src.dao.certificate_repository import CertificateRepository
|
10 |
|
|
from src.dao.private_key_repository import PrivateKeyRepository
|
11 |
e39e138f
|
Stanislav Král
|
from src.db.init_queries import SCHEMA_SQL, DEFAULT_VALUES_SQL
|
12 |
b484b79b
|
Stanislav Král
|
from src.model.subject import Subject
|
13 |
d3fa9147
|
Stanislav Král
|
from src.services.certificate_service import CertificateService
|
14 |
5cd65ab4
|
Captain_Trojan
|
from src.services.crl_ocsp.crl_ocsp_service import CrlOcspService
|
15 |
d3fa9147
|
Stanislav Král
|
from src.services.cryptography import CryptographyService
|
16 |
|
|
from src.services.key_service import KeyService
|
17 |
|
|
|
18 |
|
|
|
19 |
e39e138f
|
Stanislav Král
|
# scope="module" means that this fixture is run once per module
|
20 |
|
|
@pytest.fixture(scope="module")
|
21 |
d3fa9147
|
Stanislav Král
|
def connection():
|
22 |
2bb3759c
|
Stanislav Král
|
return ConnectionProvider().connect(test_configuration())
|
23 |
d3fa9147
|
Stanislav Král
|
|
24 |
|
|
|
25 |
e39e138f
|
Stanislav Král
|
# scope defaults to "function" which means that the fixture is run once per test (function)
|
26 |
d3fa9147
|
Stanislav Král
|
@pytest.fixture
|
27 |
2bb3759c
|
Stanislav Král
|
def certificate_repository(connection):
|
28 |
3195e946
|
Jan Pašek
|
return CertificateRepository(connection)
|
29 |
d3fa9147
|
Stanislav Král
|
|
30 |
|
|
|
31 |
|
|
@pytest.fixture
|
32 |
2bb3759c
|
Stanislav Král
|
def private_key_repository(connection):
|
33 |
3195e946
|
Jan Pašek
|
return PrivateKeyRepository(connection)
|
34 |
d3fa9147
|
Stanislav Král
|
|
35 |
|
|
|
36 |
|
|
@pytest.fixture
|
37 |
|
|
def cryptography_service():
|
38 |
|
|
return CryptographyService()
|
39 |
|
|
|
40 |
|
|
|
41 |
20b33bd4
|
Jan Pašek
|
@pytest.fixture
|
42 |
|
|
def configuration():
|
43 |
|
|
return Configuration()
|
44 |
|
|
|
45 |
|
|
|
46 |
d3fa9147
|
Stanislav Král
|
@pytest.fixture
|
47 |
|
|
def private_key_service(private_key_repository, cryptography_service):
|
48 |
|
|
return KeyService(cryptography_service, private_key_repository)
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
@pytest.fixture
|
52 |
20b33bd4
|
Jan Pašek
|
def certificate_service(certificate_repository, cryptography_service, configuration):
|
53 |
|
|
return CertificateService(cryptography_service, certificate_repository, configuration)
|
54 |
2a90f4fd
|
Stanislav Král
|
|
55 |
|
|
|
56 |
|
|
@pytest.fixture
|
57 |
|
|
def connection_unique():
|
58 |
2bb3759c
|
Stanislav Král
|
return ConnectionProvider().connect(test_configuration())
|
59 |
2a90f4fd
|
Stanislav Král
|
|
60 |
|
|
|
61 |
b484b79b
|
Stanislav Král
|
@pytest.fixture
|
62 |
|
|
def sample_private_key(private_key_service):
|
63 |
|
|
return private_key_service.create_new_key()
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
@pytest.fixture
|
67 |
|
|
def sample_certificate(certificate_service, sample_private_key):
|
68 |
|
|
return certificate_service.create_root_ca(sample_private_key, Subject("Foo"))
|
69 |
|
|
|
70 |
|
|
|
71 |
2a90f4fd
|
Stanislav Král
|
# scope defaults to "function" which means that the fixture is run once per test (function)
|
72 |
|
|
@pytest.fixture
|
73 |
2bb3759c
|
Stanislav Král
|
def certificate_repository_unique(connection_unique):
|
74 |
3195e946
|
Jan Pašek
|
return CertificateRepository(connection_unique)
|
75 |
2a90f4fd
|
Stanislav Král
|
|
76 |
|
|
|
77 |
|
|
@pytest.fixture
|
78 |
2bb3759c
|
Stanislav Král
|
def private_key_repository_unique(connection_unique):
|
79 |
3195e946
|
Jan Pašek
|
return PrivateKeyRepository(connection_unique)
|
80 |
2a90f4fd
|
Stanislav Král
|
|
81 |
|
|
|
82 |
|
|
@pytest.fixture
|
83 |
9896ec36
|
Stanislav Král
|
def private_key_service_unique(private_key_repository_unique, cryptography_service):
|
84 |
|
|
return KeyService(cryptography_service, private_key_repository_unique)
|
85 |
2a90f4fd
|
Stanislav Král
|
|
86 |
|
|
|
87 |
|
|
@pytest.fixture
|
88 |
9896ec36
|
Stanislav Král
|
def certificate_service_unique(certificate_repository_unique, cryptography_service, configuration):
|
89 |
|
|
return CertificateService(cryptography_service, certificate_repository_unique, configuration)
|
90 |
7313994f
|
Stanislav Král
|
|
91 |
|
|
|
92 |
|
|
@pytest.fixture
|
93 |
94e89bb1
|
Jan Pašek
|
def crl_service_unique(certificate_repository_unique, private_key_repository_unique, cryptography_service):
|
94 |
5cd65ab4
|
Captain_Trojan
|
return CrlOcspService(certificate_repository_unique, private_key_repository_unique, cryptography_service)
|