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
a0da5c7b
Commit
a0da5c7b
authored
Apr 03, 2007
by
Facundo Batista
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed the whole structure of startup and checking if the
server is available. Hope to not get more false alarms.
parent
e6dae6c6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
26 deletions
+36
-26
Lib/test/test_socket_ssl.py
Lib/test/test_socket_ssl.py
+36
-26
No files found.
Lib/test/test_socket_ssl.py
View file @
a0da5c7b
...
@@ -110,32 +110,24 @@ class BasicTests(unittest.TestCase):
...
@@ -110,32 +110,24 @@ class BasicTests(unittest.TestCase):
class
OpenSSLTests
(
unittest
.
TestCase
):
class
OpenSSLTests
(
unittest
.
TestCase
):
def
testBasic
(
self
):
def
testBasic
(
self
):
time
.
sleep
(.
2
)
s
=
socket
.
socket
()
s
=
socket
.
socket
()
s
.
connect
((
"localhost"
,
4433
))
s
.
connect
((
"localhost"
,
4433
))
ss
=
socket
.
ssl
(
s
)
ss
=
socket
.
ssl
(
s
)
ss
.
write
(
"Foo
\
n
"
)
ss
.
write
(
"Foo
\
n
"
)
i
=
ss
.
read
(
4
)
i
=
ss
.
read
(
4
)
self
.
assertEqual
(
i
,
"Foo
\
n
"
)
self
.
assertEqual
(
i
,
"Foo
\
n
"
)
s
.
close
()
def
haveOpenSSL
():
try
:
s
=
subprocess
.
Popen
(
"openssl rand 1"
.
split
(),
stdout
=
subprocess
.
PIPE
)
s
.
stdout
.
read
(
1
)
except
OSError
,
err
:
if
err
.
errno
==
2
:
return
False
raise
return
True
class
OpenSSLServer
(
threading
.
Thread
):
class
OpenSSLServer
(
threading
.
Thread
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
s
=
None
self
.
s
=
None
self
.
keepServing
=
True
self
.
keepServing
=
True
threading
.
Thread
.
__init__
(
self
)
self
.
_external
()
if
self
.
haveServer
:
threading
.
Thread
.
__init__
(
self
)
def
run
(
self
):
def
_external
(
self
):
if
os
.
access
(
"ssl_cert.pem"
,
os
.
F_OK
):
if
os
.
access
(
"ssl_cert.pem"
,
os
.
F_OK
):
cert_file
=
"ssl_cert.pem"
cert_file
=
"ssl_cert.pem"
elif
os
.
access
(
"./Lib/test/ssl_cert.pem"
,
os
.
F_OK
):
elif
os
.
access
(
"./Lib/test/ssl_cert.pem"
,
os
.
F_OK
):
...
@@ -149,10 +141,27 @@ class OpenSSLServer(threading.Thread):
...
@@ -149,10 +141,27 @@ class OpenSSLServer(threading.Thread):
else
:
else
:
raise
ValueError
(
"No cert file found!"
)
raise
ValueError
(
"No cert file found!"
)
cmd
=
"openssl s_server -cert %s -key %s -quiet"
%
(
cert_file
,
key_file
)
try
:
self
.
s
=
subprocess
.
Popen
(
cmd
.
split
(),
stdin
=
subprocess
.
PIPE
,
cmd
=
"openssl s_server -cert %s -key %s -quiet"
%
(
cert_file
,
key_file
)
self
.
s
=
subprocess
.
Popen
(
cmd
.
split
(),
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
stderr
=
subprocess
.
STDOUT
)
time
.
sleep
(
1
)
except
:
self
.
haveServer
=
False
else
:
# let's try if it is actually up
try
:
s
=
socket
.
socket
()
s
.
connect
((
"localhost"
,
4433
))
s
.
close
()
assert
self
.
s
.
stdout
.
readline
()
==
"ERROR
\
n
"
except
:
self
.
haveServer
=
False
else
:
self
.
haveServer
=
True
def
run
(
self
):
while
self
.
keepServing
:
while
self
.
keepServing
:
time
.
sleep
(.
5
)
time
.
sleep
(.
5
)
l
=
self
.
s
.
stdout
.
readline
()
l
=
self
.
s
.
stdout
.
readline
()
...
@@ -181,22 +190,23 @@ def test_main():
...
@@ -181,22 +190,23 @@ def test_main():
# in these platforms we can kill the openssl process
# in these platforms we can kill the openssl process
if
sys
.
platform
in
(
"sunos5"
,
"darwin"
,
"linux1"
,
if
sys
.
platform
in
(
"sunos5"
,
"darwin"
,
"linux1"
,
"linux2"
,
"win32"
,
"hp-ux11"
):
"linux2"
,
"win32"
,
"hp-ux11"
):
if
haveOpenSSL
():
haveServer
=
True
tests
.
append
(
OpenSSLTests
)
else
:
haveServer
=
False
if
haveServer
:
server
=
OpenSSLServer
()
server
=
OpenSSLServer
()
server
.
start
()
if
server
.
haveServer
:
tests
.
append
(
OpenSSLTests
)
server
.
start
()
else
:
server
=
None
thread_info
=
test_support
.
threading_setup
()
thread_info
=
test_support
.
threading_setup
()
test_support
.
run_unittest
(
*
tests
)
test_support
.
threading_cleanup
(
*
thread_info
)
if
haveServer
:
try
:
server
.
shutdown
()
test_support
.
run_unittest
(
*
tests
)
finally
:
if
server
is
not
None
and
server
.
haveServer
:
server
.
shutdown
()
test_support
.
threading_cleanup
(
*
thread_info
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
test_main
()
test_main
()
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