1194
1194
self.assertRaises(TypeError, session.set_timeout, 123, 456)
1197
def test_asn1(self):
1199
:py:method:`Session.to_asn1` returns a :py:obj:`str` giving the ASN.1
1200
representation of the session which can be turned back into a
1201
:py:class:`Session` instance by passing it to
1202
:py:method:`Session.from_asn1`.
1204
session = self._create_session(Context(TLSv1_METHOD))
1205
serialized = session.to_asn1()
1206
reloaded = Session.from_asn1(serialized)
1207
self.assertEqual(session.get_time(), reloaded.get_time())
1208
self.assertEqual(session.get_timeout(), reloaded.get_timeout())
1211
def test_to_asn1_wrong_args(self):
1213
If any arguments are passed to :py:method:`Session.to_asn1`,
1214
:py:obj:`TypeError` is raised.
1216
session = self._create_session(Context(TLSv1_METHOD))
1217
self.assertRaises(TypeError, session.to_asn1, 123)
1218
self.assertRaises(TypeError, session.to_asn1, "hello, world")
1219
self.assertRaises(TypeError, session.to_asn1, object())
1222
def test_to_asn1_uninitialized(self):
1224
If :py:method:`Session.to_asn1` is called on an uninitialized
1225
:py:class:`Session`, :py:obj:`ValueError` is raised.
1228
self.assertRaises(ValueError, session.to_asn1)
1231
def test_from_asn1_wrong_args(self):
1233
If a non-bytes argument is passed to :py:method:`Session.from_asn1`, or
1234
if other than one argument is passed, :py:obj:`TypeError` is raised.
1236
self.assertRaises(TypeError, Session.from_asn1)
1237
self.assertRaises(TypeError, Session.from_asn1, object())
1238
self.assertRaises(TypeError, Session.from_asn1, b("hello"), b("world"))
1241
def test_from_asn1_bad_serialized_data(self):
1243
If bytes not representing a serialized session are passed to
1244
:py:method:`Session.from_asn1`, :py:obj:`OpenSSL.SSL.Error` is raised.
1246
self.assertRaises(Error, Session.from_asn1, b("hello"))
1198
1250
class ConnectionTests(TestCase, _LoopbackMixin):