Revize c4ba6bb7
Přidáno uživatelem Jan Pašek před asi 4 roky(ů)
src/services/certificate_service.py | ||
---|---|---|
244 | 244 |
""" |
245 | 245 |
# TODO delete children? |
246 | 246 |
return self.certificate_repository.delete(unique_id) |
247 |
|
|
248 |
def get_subject_from_certificate(self, certificate: Certificate) -> Subject: |
|
249 |
""" |
|
250 |
Get Subject distinguished name from a Certificate |
|
251 |
:param certificate: certificate instance whose Subject shall be parsed |
|
252 |
:return: instance of Subject class containing resulting distinguished name |
|
253 |
""" |
|
254 |
(subject, _, _) = self.cryptography_service.parse_cert_pem(certificate.pem_data) |
|
255 |
return subject |
tests/integration_tests/services/certificate_service_test.py | ||
---|---|---|
223 | 223 |
assert not certificate_service.delete_certificate(root_ca_cert.certificate_id) |
224 | 224 |
|
225 | 225 |
assert len_inserted - 1 == len(certificate_service.get_certificates()) |
226 |
|
|
227 |
|
|
228 |
def test_get_subject_from_certificate(private_key_service, certificate_service): |
|
229 |
root_ca_private_key = private_key_service.create_new_key(passphrase="foobar") |
|
230 |
|
|
231 |
root_ca_cert = certificate_service.create_root_ca(root_ca_private_key, |
|
232 |
Subject(common_name="RootFoo", |
|
233 |
organization_unit="Department of Foo", |
|
234 |
email_address="root@ca.com", |
|
235 |
country="CZ")) |
|
236 |
|
|
237 |
subject = certificate_service.get_subject_from_certificate(root_ca_cert) |
|
238 |
|
|
239 |
assert subject.common_name == "RootFoo" |
|
240 |
assert subject.organization_unit == "Department of Foo" |
|
241 |
assert subject.email_address == "root@ca.com" |
|
242 |
assert subject.organization is None |
|
243 |
assert subject.locality is None |
|
244 |
assert subject.state is None |
|
245 |
assert subject.country == "CZ" |
Také k dispozici: Unified diff
Re #8473 - Added get_subject_from_certificate to certificate_service.py