1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
#
# This copy of Ice is licensed to you under the terms described in the
# ICE_LICENSE file included in this distribution.
#
# **********************************************************************
import os, sys, threading, subprocess, getopt
path = [ ".", "..", "../..", "../../..", "../../../.." ]
head = os.path.dirname(sys.argv[0])
if len(head) > 0:
path = [os.path.join(head, p) for p in path]
path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ]
if len(path) == 0:
raise RuntimeError("can't find toplevel directory!")
sys.path.append(os.path.join(path[0], "scripts"))
#
# On OS X, provide an option to allow removing the trust settings
#
if sys.platform == "darwin":
try:
opts, args = getopt.getopt(sys.argv[1:], "", ["clean"])
if ("--clean", "") in opts:
serverCert = os.path.join(path[0], "certs", "s_rsa1024_pub.pem")
if os.system("security verify-cert -c " + serverCert + " >& /dev/null") == 0:
sys.stdout.write("removing trust settings for the HTTP server certificate... ")
sys.stdout.flush()
if os.system("security remove-trusted-cert " + serverCert) != 0:
print("error: couldn't remove trust settings for the HTTP server certificate")
print("ok")
else:
print("trust settings already removed")
sys.exit(0)
except getopt.GetoptError:
pass
#
# Run the script with the environment correctly set.
#
if os.environ.get("RUNNING_TEST_CONTROLLER_WITH_ENV", "") == "":
os.environ["TESTCONTROLLER"] = "yes" # Trick to prevent TestUtil.py from printing out diagnostic information
import TestUtil
del os.environ["TESTCONTROLLER"]
#
# Get environment to run Ice for Python script
#
env = TestUtil.getTestEnv("py", os.getcwd())
env["RUNNING_TEST_CONTROLLER_WITH_ENV"] = "yes"
try:
#
# The HttpServer relies on the ICE_HOME environment variable
# to find the Ice for JavaScript installation so we make sure
# here that ICE_HOME is set if we are running against a binary
# distribution (i.e.: TestUtil.iceHome is not None)
#
if TestUtil.iceHome:
env["ICE_HOME"] = TestUtil.iceHome
if TestUtil.printenv:
TestUtil.dumpenv(env, "py")
args = [sys.executable, "run.py"]
for a in sys.argv[1:]:
args.append(a)
sys.exit(os.spawnve(os.P_WAIT, sys.executable, args, env))
except KeyboardInterrupt:
sys.exit(0)
finally:
if sys.platform == "darwin":
print("")
print("To remove the certificate trust settings, run: `" + sys.argv[0] + " --clean'")
sys.exit(1)
import TestUtil, Ice, Expect
Ice.loadSlice("\"" + os.path.join(TestUtil.toplevel, "js", "test", "Common", "Controller.ice") + "\"")
import Test
class ServerI(Test.Server):
def __init__(self, name, process):
self.name = name
self.process = process
def waitTestSuccess(self, current):
if not self.process:
return
sys.stdout.write("waiting for " + self.name + " to terminate... ")
sys.stdout.flush()
self.process.waitTestSuccess()
self.process = None
try:
current.adapter.remove(current.id)
except:
pass
# Stop the WatchDog thread since we may not run any more tests
# for an extended period of time
TestUtil.stopWatchDog()
print("ok")
def terminate(self, current):
if not self.process:
return
sys.stdout.write("terminating " + self.name + "... ")
sys.stdout.flush()
self.process.terminate()
self.process = None
try:
current.adapter.remove(current.id)
except:
pass
# Stop the WatchDog thread since we may not run any more tests
# for an extended period of time
TestUtil.stopWatchDog()
print("ok")
class ControllerI(Test.Controller):
def __init__(self):
self.currentServer = None
def runServer(self, lang, name, protocol, host, options, current):
# If server is still running, terminate it
if self.currentServer:
try:
self.currentServer.terminate()
except:
pass
self.currentServer = None
pwd = os.getcwd()
try:
# Change current directory to the test directory
testDir = 'test' if lang != 'java' else 'test/src/main/java/test'
serverdir = os.path.join(TestUtil.toplevel, lang, testDir, name)
os.chdir(serverdir)
serverDesc = os.path.join(lang, 'test', name)
lang = TestUtil.getDefaultMapping()
server = TestUtil.getDefaultServerFile()
if lang != "java":
server = os.path.join(serverdir, server)
serverenv = TestUtil.getTestEnv(lang, serverdir)
sys.stdout.write("starting " + serverDesc + "... ")
sys.stdout.flush()
serverCfg = TestUtil.DriverConfig("server")
serverCfg.protocol = protocol
serverCfg.host = host
server = TestUtil.getCommandLine(server, serverCfg, options)
serverProc = TestUtil.spawnServer(server, env = serverenv, lang=serverCfg.lang, mx=serverCfg.mx)
print("ok")
finally:
os.chdir(pwd)
self.currentServer = Test.ServerPrx.uncheckedCast(current.adapter.addWithUUID(ServerI(serverDesc, serverProc)))
return self.currentServer
class Reader(threading.Thread):
def __init__(self, p):
self.p = p
threading.Thread.__init__(self)
def run(self):
while True:
line = self.p.stdout.readline()
if self.p.poll() is not None and not line:
#process terminated
return self.p.poll()
if type(line) != str:
line = line.decode()
sys.stdout.write(line)
sys.stdout.flush()
class Server(Ice.Application):
def run(self, args):
jsDir = os.path.join(TestUtil.toplevel, "js")
nodeCmd = TestUtil.getNodeCommand()
httpServer = subprocess.Popen(nodeCmd + " \"" + os.path.join(jsDir, "bin", "HttpServer.js") + "\"",
shell = True,
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = None,
bufsize = 0)
#
# Wait for the HttpServer to start
#
while True:
line = httpServer.stdout.readline()
if httpServer.poll() is not None and not line:
#process terminated
return httpServer.poll()
if type(line) != str:
line = line.decode()
line = line.strip("\n")
if len(line) > 0:
print(line)
if line.find("listening on ports 8080 (http) and 9090 (https)...") != -1:
break
reader = Reader(httpServer)
reader.start()
adapter = self.communicator().createObjectAdapter("ControllerAdapter")
adapter.add(ControllerI(), self.communicator().stringToIdentity("controller"))
adapter.activate()
self.communicator().waitForShutdown()
if httpServer.poll() is None:
httpServer.terminate()
reader.join()
return 0
app = Server()
initData = Ice.InitializationData()
initData.properties = Ice.createProperties();
initData.properties.setProperty("Ice.Plugin.IceSSL", "IceSSL:createIceSSL")
initData.properties.setProperty("IceSSL.DefaultDir", os.path.join(TestUtil.toplevel, "certs"));
initData.properties.setProperty("IceSSL.CertAuthFile", "cacert.pem");
initData.properties.setProperty("IceSSL.CertFile", "s_rsa1024_pub.pem");
initData.properties.setProperty("IceSSL.KeyFile", "s_rsa1024_priv.pem");
initData.properties.setProperty("IceSSL.Keychain", "test.keychain");
initData.properties.setProperty("IceSSL.KeychainPassword", "password");
initData.properties.setProperty("IceSSL.VerifyPeer", "0");
initData.properties.setProperty("Ice.ThreadPool.Server.SizeMax", "10")
initData.properties.setProperty("ControllerAdapter.Endpoints", "ws -p 12009:wss -p 12008")
if TestUtil.isDarwin():
#
# On OS X, we set the trust settings on the certificate to prevent
# the Web browsers from prompting the user about the unstrusted
# certificate. Some browsers such as Chrome don't provide the
# option to set this trust settings.
#
serverCert = os.path.join(TestUtil.toplevel, "certs", "s_rsa1024_pub.pem")
if os.system("security verify-cert -c " + serverCert + " >& /dev/null") != 0:
sys.stdout.write("adding trust settings for the HTTP server certificate... ")
sys.stdout.flush()
if os.system("security add-trusted-cert -r trustAsRoot " + serverCert) != 0:
print("error: couldn't add trust settings for the HTTP server certificate")
print("ok")
sys.exit(app.main(sys.argv, initData=initData))
|