Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
d2eca37c
Commit
d2eca37c
authored
Oct 29, 2010
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up socket closing in test_ssl and test.ssl_servers
parent
77b7de6d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
24 deletions
+35
-24
Lib/test/ssl_servers.py
Lib/test/ssl_servers.py
+4
-1
Lib/test/test_ssl.py
Lib/test/test_ssl.py
+31
-23
No files found.
Lib/test/ssl_servers.py
View file @
d2eca37c
...
...
@@ -133,7 +133,10 @@ class HTTPSServerThread(threading.Thread):
def
run
(
self
):
if
self
.
flag
:
self
.
flag
.
set
()
self
.
server
.
serve_forever
(
0.05
)
try
:
self
.
server
.
serve_forever
(
0.05
)
finally
:
self
.
server
.
server_close
()
def
stop
(
self
):
self
.
server
.
shutdown
()
...
...
Lib/test/test_ssl.py
View file @
d2eca37c
...
...
@@ -198,13 +198,16 @@ class BasicSocketTests(unittest.TestCase):
self
.
assertRaisesRegexp
(
ValueError
,
"can't connect in server-side mode"
,
s
.
connect
,
(
HOST
,
8080
))
with
self
.
assertRaises
(
IOError
)
as
cm
:
ssl
.
wrap_socket
(
socket
.
socket
(),
certfile
=
WRONGCERT
)
with
socket
.
socket
()
as
sock
:
ssl
.
wrap_socket
(
sock
,
certfile
=
WRONGCERT
)
self
.
assertEqual
(
cm
.
exception
.
errno
,
errno
.
ENOENT
)
with
self
.
assertRaises
(
IOError
)
as
cm
:
ssl
.
wrap_socket
(
socket
.
socket
(),
certfile
=
CERTFILE
,
keyfile
=
WRONGCERT
)
with
socket
.
socket
()
as
sock
:
ssl
.
wrap_socket
(
sock
,
certfile
=
CERTFILE
,
keyfile
=
WRONGCERT
)
self
.
assertEqual
(
cm
.
exception
.
errno
,
errno
.
ENOENT
)
with
self
.
assertRaises
(
IOError
)
as
cm
:
ssl
.
wrap_socket
(
socket
.
socket
(),
certfile
=
WRONGCERT
,
keyfile
=
WRONGCERT
)
with
socket
.
socket
()
as
sock
:
ssl
.
wrap_socket
(
sock
,
certfile
=
WRONGCERT
,
keyfile
=
WRONGCERT
)
self
.
assertEqual
(
cm
.
exception
.
errno
,
errno
.
ENOENT
)
def
test_match_hostname
(
self
):
...
...
@@ -281,9 +284,9 @@ class BasicSocketTests(unittest.TestCase):
def
test_server_side
(
self
):
# server_hostname doesn't work for server sockets
ctx
=
ssl
.
SSLContext
(
ssl
.
PROTOCOL_SSLv23
)
sock
=
socket
.
socket
()
self
.
assertRaises
(
ValueError
,
ctx
.
wrap_socket
,
sock
,
True
,
server_hostname
=
"some.hostname"
)
with
socket
.
socket
()
as
sock
:
self
.
assertRaises
(
ValueError
,
ctx
.
wrap_socket
,
sock
,
True
,
server_hostname
=
"some.hostname"
)
class
ContextTests
(
unittest
.
TestCase
):
...
...
@@ -579,9 +582,10 @@ class NetworkedTests(unittest.TestCase):
s
.
connect
(
remote
)
# Error checking can happen at instantiation or when connecting
with
self
.
assertRaisesRegexp
(
ssl
.
SSLError
,
"No cipher can be selected"
):
s
=
ssl
.
wrap_socket
(
socket
.
socket
(
socket
.
AF_INET
),
cert_reqs
=
ssl
.
CERT_NONE
,
ciphers
=
"^$:,;?*'dorothyx"
)
s
.
connect
(
remote
)
with
socket
.
socket
(
socket
.
AF_INET
)
as
sock
:
s
=
ssl
.
wrap_socket
(
sock
,
cert_reqs
=
ssl
.
CERT_NONE
,
ciphers
=
"^$:,;?*'dorothyx"
)
s
.
connect
(
remote
)
def
test_algorithms
(
self
):
# Issue #8484: all algorithms should be available when verifying a
...
...
@@ -903,10 +907,11 @@ else:
# try to connect
try
:
try
:
s
=
ssl
.
wrap_socket
(
socket
.
socket
(),
certfile
=
certfile
,
ssl_version
=
ssl
.
PROTOCOL_TLSv1
)
s
.
connect
((
HOST
,
server
.
port
))
with
socket
.
socket
()
as
sock
:
s
=
ssl
.
wrap_socket
(
sock
,
certfile
=
certfile
,
ssl_version
=
ssl
.
PROTOCOL_TLSv1
)
s
.
connect
((
HOST
,
server
.
port
))
except
ssl
.
SSLError
as
x
:
if
support
.
verbose
:
sys
.
stdout
.
write
(
"
\
n
SSLError is %s
\
n
"
%
x
.
args
[
1
])
...
...
@@ -1093,21 +1098,22 @@ else:
def
listener
():
s
.
listen
(
5
)
listener_ready
.
set
()
s
.
accept
()
newsock
,
addr
=
s
.
accept
()
newsock
.
close
()
s
.
close
()
listener_gone
.
set
()
def
connector
():
listener_ready
.
wait
()
c
=
socket
.
socket
()
c
.
connect
((
HOST
,
port
))
listener_gone
.
wait
()
try
:
ssl_sock
=
ssl
.
wrap_socket
(
c
)
except
IOError
:
pass
else
:
self
.
fail
(
'connecting to closed SSL socket should have failed'
)
with
socket
.
socket
()
as
c
:
c
.
connect
((
HOST
,
port
))
listener_gone
.
wait
()
try
:
ssl_sock
=
ssl
.
wrap_socket
(
c
)
except
IOError
:
pass
else
:
self
.
fail
(
'connecting to closed SSL socket should have failed'
)
t
=
threading
.
Thread
(
target
=
listener
)
t
.
start
()
...
...
@@ -1469,6 +1475,8 @@ else:
# Let the socket hang around rather than having
# it closed by garbage collection.
conns
.
append
(
server
.
accept
()[
0
])
for
sock
in
conns
:
sock
.
close
()
t
=
threading
.
Thread
(
target
=
serve
)
t
.
start
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment