Paul Kehrer | acbd662 | 2017-11-20 22:25:18 +0800 | [diff] [blame] | 1 | # Copyright (c) Frederick Dean |
| 2 | # See LICENSE for details. |
| 3 | |
| 4 | """ |
| 5 | Unit tests for `OpenSSL.rand`. |
| 6 | """ |
| 7 | |
| 8 | import pytest |
| 9 | |
| 10 | from OpenSSL import rand |
| 11 | |
| 12 | |
| 13 | class TestRand(object): |
| 14 | |
| 15 | @pytest.mark.parametrize('args', [ |
| 16 | (b"foo", None), |
| 17 | (None, 3), |
| 18 | ]) |
| 19 | def test_add_wrong_args(self, args): |
| 20 | """ |
| 21 | `OpenSSL.rand.add` raises `TypeError` if called with arguments not of |
| 22 | type `str` and `int`. |
| 23 | """ |
| 24 | with pytest.raises(TypeError): |
| 25 | rand.add(*args) |
| 26 | |
| 27 | def test_add(self): |
| 28 | """ |
| 29 | `OpenSSL.rand.add` adds entropy to the PRNG. |
| 30 | """ |
| 31 | rand.add(b'hamburger', 3) |
| 32 | |
| 33 | def test_status(self): |
| 34 | """ |
| 35 | `OpenSSL.rand.status` returns `1` if the PRNG has sufficient entropy, |
| 36 | `0` otherwise. |
| 37 | """ |
| 38 | assert rand.status() == 1 |