Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 97856712

Přidáno uživatelem Stanislav Král před téměř 4 roky(ů)

Re #8585 - Edited certificate_service_test.py tests asserting that various extension field flags are set when certain usages are selected

Zobrazit rozdíly:

tests/integration_tests/services/certificate_service_test.py
29 29

  
30 30
    cert_loaded = certificate_service.get_certificate(cert.certificate_id)
31 31

  
32
    # verify that the loaded certificate is a CA
32
    # verify that the loaded certificate is a CA and contains SSL usage extension flags
33 33
    cert_loaded_printed = export_crt(cert_loaded.pem_data)
34
    expected = """            X509v3 Basic Constraints: critical
35
                CA:TRUE""".replace("\r", "").replace("\n", "")
34
    expected = """
35
        X509v3 extensions:
36
            X509v3 Basic Constraints: critical
37
                CA:TRUE
38
            X509v3 Key Usage: critical
39
                Digital Signature, Key Encipherment, Key Agreement, Certificate Sign, CRL Sign
40
            X509v3 Extended Key Usage: 
41
                TLS Web Server Authentication
42
    """.replace("\r", "").replace("\n", "")
36 43
    assert expected in cert_loaded_printed.replace("\n", "").replace("\r", "")
37 44

  
38 45
    assert cert.certificate_id == cert_loaded.certificate_id
......
54 61
                                                 Subject(common_name="RootFoo", organization_unit="Department of Foo"))
55 62

  
56 63
    inter_cert = certificate_service.create_ca(inter_ca_private_key, Subject(common_name="Intermediate CA"), root_ca,
57
                                               root_ca_private_key, usages={SSL_ID: True})
64
                                               root_ca_private_key, usages={AUTHENTICATION_ID: True})
58 65

  
59 66
    assert INTERMEDIATE_CA_ID == inter_cert.type_id
60 67

  
61 68
    assert inter_cert.usages[CA_ID]
62
    assert inter_cert.usages[SSL_ID]
63
    assert inter_cert.usages[AUTHENTICATION_ID] is False
69
    assert inter_cert.usages[SSL_ID] is False
70
    assert inter_cert.usages[AUTHENTICATION_ID] is True
64 71
    assert inter_cert.usages[SIGNATURE_ID] is False
65 72

  
66 73
    inter_cert_loaded = certificate_service.get_certificate(inter_cert.certificate_id)
67 74

  
68
    # verify that the loaded certificate is a CA
75
    # verify that the loaded certificate is a CA and contains AUTHENTICATION usage extension flags
69 76
    cert_loaded_printed = export_crt(inter_cert_loaded.pem_data)
70
    expected = """            X509v3 Basic Constraints: critical
71
                CA:TRUE""".replace("\n", "").replace("\r", "")
77
    expected = """
78
        X509v3 extensions:
79
            X509v3 Basic Constraints: critical
80
                CA:TRUE
81
            X509v3 Key Usage: critical
82
                Digital Signature, Certificate Sign, CRL Sign
83
            X509v3 Extended Key Usage: 
84
                TLS Web Client Authentication
85
    """.replace("\r", "").replace("\n", "")
86

  
72 87
    assert expected in cert_loaded_printed.replace("\n", "").replace("\r", "")
73 88

  
74 89
    assert inter_cert.certificate_id == inter_cert_loaded.certificate_id
......
98 113

  
99 114
    cert = certificate_service.create_end_cert(end_cert_private_key,
100 115
                                               Subject("Foo Child", email_address="foo@bar.cz"), inter_ca_cert,
101
                                               inter_ca_private_key, usages={AUTHENTICATION_ID: True})
116
                                               inter_ca_private_key, usages={SIGNATURE_ID: True})
102 117
    assert CERTIFICATE_ID == cert.type_id
103 118

  
104
    assert cert.usages[AUTHENTICATION_ID]
119
    assert cert.usages[AUTHENTICATION_ID] is False
105 120
    assert cert.usages[SSL_ID] is False
106
    assert cert.usages[SIGNATURE_ID] is False
121
    assert cert.usages[SIGNATURE_ID]
107 122
    assert cert.usages[CA_ID] is False
108 123

  
109 124
    cert_loaded = certificate_service.get_certificate(cert.certificate_id)
110 125

  
126
    # verify that the loaded certificate is a CA and contains AUTHENTICATION usage extension flags
127
    cert_loaded_printed = export_crt(cert_loaded.pem_data)
128
    print(cert_loaded_printed)
129
    expected = """
130
        X509v3 extensions:
131
            X509v3 Key Usage: 
132
                Digital Signature, Non Repudiation
133
            X509v3 Extended Key Usage: 
134
                Time Stamping
135
    """.replace("\r", "").replace("\n", "")
136

  
137
    assert expected in cert_loaded_printed.replace("\n", "").replace("\r", "")
138

  
111 139
    assert cert.certificate_id == cert_loaded.certificate_id
112 140
    assert cert.common_name == cert_loaded.common_name
113 141
    assert cert.valid_from == cert_loaded.valid_from
......
314 342
                                                             Subject(common_name="RootFoo",
315 343
                                                                     organization_unit="Department of Foo"))
316 344

  
317

  
318 345
    with pytest.raises(RevocationReasonInvalidException) as e:
319 346
        certificate_service_unique.set_certificate_revocation_status(root_ca_cert.certificate_id, "revoked", "foo")
320 347

  
......
329 356
    with pytest.raises(CertificateAlreadyRevokedException) as e:
330 357
        certificate_service_unique.set_certificate_revocation_status(root_ca_cert.certificate_id, "revoked",
331 358
                                                                     "unspecified")
332

  

Také k dispozici: Unified diff