Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / lib / python2.4 / test / test_socket_ssl.py
CommitLineData
86530b38
AT
1# Test just the SSL support in the socket module, in a moderately bogus way.
2
3from test import test_support
4import socket
5import time
6
7# Optionally test SSL support. This requires the 'network' resource as given
8# on the regrtest command line.
9skip_expected = not (test_support.is_resource_enabled('network') and
10 hasattr(socket, "ssl"))
11
12def test_basic():
13 test_support.requires('network')
14
15 import urllib
16
17 socket.RAND_status()
18 try:
19 socket.RAND_egd(1)
20 except TypeError:
21 pass
22 else:
23 print "didn't raise TypeError"
24 socket.RAND_add("this is a random string", 75.0)
25
26 f = urllib.urlopen('https://sf.net')
27 buf = f.read()
28 f.close()
29
30def test_rude_shutdown():
31 try:
32 import thread
33 except ImportError:
34 return
35
36 # some random port to connect to
37 PORT = 9934
38 def listener():
39 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
40 s.bind(('', PORT))
41 s.listen(5)
42 s.accept()
43 del s
44 thread.exit()
45
46 def connector():
47 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
48 s.connect(('localhost', PORT))
49 try:
50 ssl_sock = socket.ssl(s)
51 except socket.sslerror:
52 pass
53 else:
54 raise test_support.TestFailed, \
55 'connecting to closed SSL socket failed'
56
57 thread.start_new_thread(listener, ())
58 time.sleep(1)
59 connector()
60
61def test_main():
62 if not hasattr(socket, "ssl"):
63 raise test_support.TestSkipped("socket module has no ssl support")
64 test_rude_shutdown()
65 test_basic()
66
67if __name__ == "__main__":
68 test_main()