Jean-Paul Calderone | 8b63d45 | 2008-03-21 18:31:12 -0400 | [diff] [blame] | 1 | # Copyright (C) Jean-Paul Calderone 2008, All rights reserved |
| 2 | |
Jean-Paul Calderone | 30c09ea | 2008-03-21 17:04:05 -0400 | [diff] [blame] | 3 | """ |
| 4 | Unit tests for L{OpenSSL.SSL}. |
| 5 | """ |
| 6 | |
| 7 | from unittest import TestCase |
| 8 | |
| 9 | from OpenSSL.crypto import TYPE_RSA, PKey |
| 10 | from OpenSSL.SSL import Context |
| 11 | from OpenSSL.SSL import SSLv2_METHOD, SSLv3_METHOD, SSLv23_METHOD, TLSv1_METHOD |
| 12 | |
| 13 | |
| 14 | class ContextTests(TestCase): |
| 15 | """ |
| 16 | Unit tests for L{OpenSSL.SSL.Context}. |
| 17 | """ |
| 18 | def test_method(self): |
| 19 | """ |
| 20 | L{Context} can be instantiated with one of L{SSLv2_METHOD}, |
| 21 | L{SSLv3_METHOD}, L{SSLv23_METHOD}, or L{TLSv1_METHOD}. |
| 22 | """ |
| 23 | for meth in [SSLv2_METHOD, SSLv3_METHOD, SSLv23_METHOD, TLSv1_METHOD]: |
| 24 | Context(meth) |
| 25 | self.assertRaises(TypeError, Context, "") |
| 26 | self.assertRaises(ValueError, Context, 10) |
| 27 | |
| 28 | |
| 29 | def test_use_privatekey(self): |
| 30 | """ |
| 31 | L{Context.use_privatekey} takes an L{OpenSSL.crypto.PKey} instance. |
| 32 | """ |
| 33 | key = PKey() |
| 34 | key.generate_key(TYPE_RSA, 128) |
| 35 | ctx = Context(TLSv1_METHOD) |
| 36 | ctx.use_privatekey(key) |
| 37 | self.assertRaises(TypeError, ctx.use_privatekey, "") |