aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2016-09-03 11:31:43 -0500
committerAlex Gaynor <alex.gaynor@gmail.com>2016-09-03 12:31:43 -0400
commit8b89bcc5b95140514bf7a17b72ce34f40b97a60a (patch)
tree3dabc6659d01be8669eb7d1f187c5ea9a50da867 /tests
parenta2d0da9bcd7b5660b5038c79b7168d6fb645971f (diff)
downloadcryptography-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.py17
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