Beispiel #1
0
 def test_pending(self):
     bio = ssl.MemoryBIO()
     self.assertEqual(bio.pending, 0)
     bio.write(b'foo')
     self.assertEqual(bio.pending, 3)
     for i in range(3):
         bio.read(1)
         self.assertEqual(bio.pending, 3 - i - 1)
     for i in range(3):
         bio.write(b'x')
         self.assertEqual(bio.pending, i + 1)
     bio.read()
     self.assertEqual(bio.pending, 0)
Beispiel #2
0
 def test_read_write(self):
     bio = ssl.MemoryBIO()
     bio.write(b'foo')
     self.assertEqual(bio.read(), b'foo')
     self.assertEqual(bio.read(), b'')
     bio.write(b'foo')
     bio.write(b'bar')
     self.assertEqual(bio.read(), b'foobar')
     self.assertEqual(bio.read(), b'')
     bio.write(b'baz')
     self.assertEqual(bio.read(2), b'ba')
     self.assertEqual(bio.read(1), b'z')
     self.assertEqual(bio.read(1), b'')
Beispiel #3
0
 def test_eof(self):
     bio = ssl.MemoryBIO()
     self.assertFalse(bio.eof)
     self.assertEqual(bio.read(), b'')
     self.assertFalse(bio.eof)
     bio.write(b'foo')
     self.assertFalse(bio.eof)
     bio.write_eof()
     self.assertFalse(bio.eof)
     self.assertEqual(bio.read(2), b'fo')
     self.assertFalse(bio.eof)
     self.assertEqual(bio.read(1), b'o')
     self.assertTrue(bio.eof)
     self.assertEqual(bio.read(), b'')
     self.assertTrue(bio.eof)
Beispiel #4
0
 def test_error_types(self):
     bio = ssl.MemoryBIO()
     self.assertRaises(TypeError, bio.write, 'foo')
     self.assertRaises(TypeError, bio.write, None)
     self.assertRaises(TypeError, bio.write, True)
     self.assertRaises(TypeError, bio.write, 1)
Beispiel #5
0
def test():
  for _ in range(9999):
    bio = _ssl.MemoryBIO()
    for _ in range(fint()):
      if fint():
        try: bio.write(fstr())
        except _ssl.SSLError: pass
      if fint(): bio.read()
      if fint(): bio.write_eof()
      bio.pending
      bio.eof

    _ssl.RAND_add(fstr(), fdouble())
    _ssl.RAND_status()
    try:
      _ssl.RAND_bytes(fint())
      _ssl.RAND_pseudo_bytes(fint())
    except _ssl.SSLError:
      pass

    while True:
      try: ctx = _ssl._SSLContext(rnd.randint(-1,20)) ; break
      except ValueError: continue
    
    try: ctx.set_ciphers(str(fstr()))
    except _ssl.SSLError: pass
    
    try: ctx.set_alpn_protocols(flst())
    except (AttributeError, _ssl.SSLError): pass
    
    try: ctx.set_npn_protocols(flst())
    except (AttributeError, _ssl.SSLError): pass

    try: ctx.set_ecdh_curve(fstr())
    except (ValueError, _ssl.SSLError): pass

    ctx.get_ciphers()
    ctx.check_hostname
    ctx.check_hostname = fbool()
    ctx._host_flags
    ctx._host_flags = flong()
    ctx.minimum_version
    try: ctx.minimum_version = flong()
    except (ValueError, _ssl.SSLError): pass
    ctx.maximum_version
    try: ctx.maximum_version = flong()
    except (ValueError, _ssl.SSLError): pass
    ctx.sni_callback
    try: ctx.sni_callback = flong
    except (ValueError, _ssl.SSLError): pass
    ctx.options
    ctx.options = flong()
    ctx.protocol
    ctx.verify_flags
    ctx.verify_flags = flong()
    ctx.verify_mode
    try: ctx.verify_mode = flong()
    except (ValueError, _ssl.SSLError): pass

    sock = socket.socket()
    sock = ctx._wrap_socket(sock, fbool())
    sock.compression()
    sock.cipher()
    sock.shared_ciphers()
    sock.version()
    sock.selected_alpn_protocol()
    sock.selected_npn_protocol()
    
    try: sock.do_handshake()
    except _ssl.SSLError: pass
    
    try: sock.write(fstr())
    except _ssl.SSLError: pass
    
    try: sock.read(fint())
    except _ssl.SSLError: pass
    
    sock.pending()
    sock.context
    sock.server_side
    sock.server_hostname
    sock.owner
    sock.session
    sock.session_reused

    try: sock.shutdown()
    except _ssl.SSLError: pass