diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2016-09-03 11:31:43 -0500 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2016-09-03 12:31:43 -0400 |
commit | 8b89bcc5b95140514bf7a17b72ce34f40b97a60a (patch) | |
tree | 3dabc6659d01be8669eb7d1f187c5ea9a50da867 /tests | |
parent | a2d0da9bcd7b5660b5038c79b7168d6fb645971f (diff) | |
download | cryptography-8b89bcc5b95140514bf7a17b72ce34f40b97a60a.tar.gz cryptography-8b89bcc5b95140514bf7a17b72ce34f40b97a60a.tar.bz2 cryptography-8b89bcc5b95140514bf7a17b72ce34f40b97a60a.zip |
support random_serial_number in the CertificateBuilder (#3132)
* support random_serial_number in the CertificateBuilder
* turns out pytest's monkeypatch has an undo
* random_serial_number now a function
* just certs
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_x509.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/test_x509.py b/tests/test_x509.py index dcfbe4fd..468eb397 100644 --- a/tests/test_x509.py +++ b/tests/test_x509.py @@ -3724,3 +3724,20 @@ class TestName(object): def test_not_nameattribute(self): with pytest.raises(TypeError): x509.Name(["not-a-NameAttribute"]) + + +def test_random_serial_number(monkeypatch): + sample_data = os.urandom(20) + + def notrandom(size): + assert size == len(sample_data) + return sample_data + + monkeypatch.setattr(os, "urandom", notrandom) + + serial_number = x509.random_serial_number() + + assert ( + serial_number == utils.int_from_bytes(sample_data, "big") >> 1 + ) + assert utils.bit_length(serial_number) < 160 |