kopia lustrzana https://github.com/micropython/micropython
tests/extmod/ussl_basic: Make test run on axtls and mbedtls.
Fixes issue #4364. Signed-off-by: Damien George <damien@micropython.org>pull/8916/head
rodzic
1d23c01dd6
commit
18ecc29bb8
|
@ -7,40 +7,49 @@ except ImportError:
|
||||||
print("SKIP")
|
print("SKIP")
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
|
|
||||||
|
class TestSocket(io.IOBase):
|
||||||
|
def write(self, buf):
|
||||||
|
return len(buf)
|
||||||
|
|
||||||
|
def readinto(self, buf):
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def ioctl(self, cmd, arg):
|
||||||
|
print("TestSocket.ioctl", cmd, arg)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def setblocking(self, value):
|
||||||
|
print("TestSocket.setblocking({})".format(value))
|
||||||
|
|
||||||
|
|
||||||
# create in client mode
|
# create in client mode
|
||||||
try:
|
try:
|
||||||
ss = ssl.wrap_socket(io.BytesIO(), server_hostname="test.example.com")
|
ss = ssl.wrap_socket(TestSocket(), server_hostname="test.example.com")
|
||||||
except OSError as er:
|
except OSError as er:
|
||||||
print("wrap_socket:", repr(er))
|
print("OSError: client")
|
||||||
|
|
||||||
# create in server mode (can use this object for further tests)
|
# create in server mode (can use this object for further tests)
|
||||||
socket = io.BytesIO()
|
ss = ssl.wrap_socket(TestSocket(), server_side=1, do_handshake=0)
|
||||||
ss = ssl.wrap_socket(socket, server_side=1)
|
|
||||||
|
|
||||||
# print
|
# print
|
||||||
print(repr(ss)[:12])
|
print(repr(ss)[:12])
|
||||||
|
|
||||||
# setblocking() propagates call to the underlying stream object, and
|
# setblocking() propagates call to the underlying stream object
|
||||||
# io.BytesIO doesn't have setblocking() (in CPython too).
|
ss.setblocking(False)
|
||||||
# try:
|
ss.setblocking(True)
|
||||||
# ss.setblocking(False)
|
|
||||||
# except NotImplementedError:
|
|
||||||
# print('setblocking: NotImplementedError')
|
|
||||||
# ss.setblocking(True)
|
|
||||||
|
|
||||||
# write
|
# write
|
||||||
print(ss.write(b"aaaa"))
|
try:
|
||||||
|
ss.write(b"aaaa")
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
# read (underlying socket has no data)
|
# read (underlying socket has no data)
|
||||||
print(ss.read(8))
|
|
||||||
|
|
||||||
# read (underlying socket has data, but it's bad data)
|
|
||||||
socket.write(b"aaaaaaaaaaaaaaaa")
|
|
||||||
socket.seek(0)
|
|
||||||
try:
|
try:
|
||||||
ss.read(8)
|
ss.read(8)
|
||||||
except OSError as er:
|
except OSError:
|
||||||
print("read:", repr(er))
|
pass
|
||||||
|
|
||||||
# close
|
# close
|
||||||
ss.close()
|
ss.close()
|
||||||
|
@ -51,10 +60,10 @@ ss.close()
|
||||||
try:
|
try:
|
||||||
ss.read(10)
|
ss.read(10)
|
||||||
except OSError as er:
|
except OSError as er:
|
||||||
print("read:", repr(er))
|
print("OSError: read")
|
||||||
|
|
||||||
# write on closed socket
|
# write on closed socket
|
||||||
try:
|
try:
|
||||||
ss.write(b"aaaa")
|
ss.write(b"aaaa")
|
||||||
except OSError as er:
|
except OSError as er:
|
||||||
print("write:", repr(er))
|
print("OSError: write")
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
wrap_socket: OSError(-256, 'CONN_LOST')
|
OSError: client
|
||||||
<_SSLSocket
|
<_SSLSocket
|
||||||
4
|
TestSocket.setblocking(False)
|
||||||
b''
|
TestSocket.setblocking(True)
|
||||||
read: OSError(-261,)
|
TestSocket.ioctl 4 0
|
||||||
read: OSError(9,)
|
TestSocket.ioctl 4 0
|
||||||
write: OSError(9,)
|
OSError: read
|
||||||
|
OSError: write
|
||||||
|
|
Ładowanie…
Reference in New Issue