|
25 | 25 | import pytest |
26 | 26 |
|
27 | 27 |
|
| 28 | +def get_test_cert(): |
| 29 | + private_key = ec.generate_private_key( |
| 30 | + ALGORITHM.EC_P256.to_curve(), default_backend() |
| 31 | + ) |
| 32 | + name = x509.Name( |
| 33 | + [x509.NameAttribute(x509.oid.NameOID.COMMON_NAME, "Test Certificate")] |
| 34 | + ) |
| 35 | + one_day = datetime.timedelta(1, 0, 0) |
| 36 | + certificate = ( |
| 37 | + x509.CertificateBuilder() |
| 38 | + .subject_name(name) |
| 39 | + .issuer_name(name) |
| 40 | + .not_valid_before(datetime.datetime.today() - one_day) |
| 41 | + .not_valid_after(datetime.datetime.today() + one_day) |
| 42 | + .serial_number(int(uuid.uuid4())) |
| 43 | + .public_key(private_key.public_key()) |
| 44 | + .sign(private_key, hashes.SHA256(), default_backend()) |
| 45 | + ) |
| 46 | + return certificate |
| 47 | + |
| 48 | + |
28 | 49 | def test_put_empty(session): |
29 | 50 | # Can't put an empty object |
30 | 51 | with pytest.raises(ValueError): |
@@ -74,27 +95,37 @@ def test_put_too_big(session): |
74 | 95 |
|
75 | 96 |
|
76 | 97 | def test_certificate(session): |
77 | | - private_key = ec.generate_private_key( |
78 | | - ALGORITHM.EC_P256.to_curve(), default_backend() |
79 | | - ) |
80 | | - name = x509.Name( |
81 | | - [x509.NameAttribute(x509.oid.NameOID.COMMON_NAME, "Test Certificate")] |
82 | | - ) |
83 | | - one_day = datetime.timedelta(1, 0, 0) |
84 | | - certificate = ( |
85 | | - x509.CertificateBuilder() |
86 | | - .subject_name(name) |
87 | | - .issuer_name(name) |
88 | | - .not_valid_before(datetime.datetime.today() - one_day) |
89 | | - .not_valid_after(datetime.datetime.today() + one_day) |
90 | | - .serial_number(int(uuid.uuid4())) |
91 | | - .public_key(private_key.public_key()) |
92 | | - .sign(private_key, hashes.SHA256(), default_backend()) |
93 | | - ) |
94 | | - |
| 98 | + certificate = get_test_cert() |
95 | 99 | certobj = Opaque.put_certificate( |
96 | 100 | session, 0, "Test certificate Opaque", 1, CAPABILITY.NONE, certificate |
97 | 101 | ) |
98 | 102 |
|
99 | 103 | assert certificate == certobj.get_certificate() |
100 | 104 | certobj.delete() |
| 105 | + |
| 106 | + |
| 107 | +def test_compressed_certificate(session): |
| 108 | + certificate = get_test_cert() |
| 109 | + |
| 110 | + certobj = Opaque.put_certificate( |
| 111 | + session, |
| 112 | + 0, |
| 113 | + "Test certificate Opaque", |
| 114 | + 1, |
| 115 | + CAPABILITY.NONE, |
| 116 | + certificate, |
| 117 | + ) |
| 118 | + compressed_certobj = Opaque.put_certificate( |
| 119 | + session, |
| 120 | + 0, |
| 121 | + "Test certificate Opaque Compressed", |
| 122 | + 1, |
| 123 | + CAPABILITY.NONE, |
| 124 | + certificate, |
| 125 | + compress=True, |
| 126 | + ) |
| 127 | + assert certobj.get_certificate() == compressed_certobj.get_certificate( |
| 128 | + decompress=True |
| 129 | + ) |
| 130 | + assert certobj.get() != compressed_certobj.get() |
| 131 | + assert len(certobj.get()) > len(compressed_certobj.get()) |
0 commit comments