Skip to content

Commit 469d06d

Browse files
committed
Improved performance of local webserver in unit-tests.
1 parent 224730c commit 469d06d

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

test/test_angular_scope.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_inside_app(self):
4949

5050
exitcode = process.wait()
5151
except Exception as e:
52-
print(e)
52+
print("Exception: " + str(e))
5353
exitcode = 1
5454

5555
server.stop()
@@ -71,7 +71,7 @@ def test_outside_app(self):
7171

7272
exitcode = process.wait()
7373
except Exception as e:
74-
print(e)
74+
print("Exception: " + str(e))
7575
exitcode = 1
7676

7777
server.stop()
@@ -93,7 +93,7 @@ def test_inside_non_bindable(self):
9393

9494
exitcode = process.wait()
9595
except Exception as e:
96-
print(e)
96+
print("Exception: " + str(e))
9797
exitcode = 1
9898

9999
server.stop()
@@ -115,7 +115,7 @@ def test_inside_script(self):
115115

116116
exitcode = process.wait()
117117
except Exception as e:
118-
print(e)
118+
print("Exception: " + str(e))
119119
exitcode = 1
120120

121121
server.stop()

test/test_payloads.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def test_payloads(self):
168168

169169
exitcode = process.wait()
170170
except Exception as e:
171-
print(e)
171+
print("Exception: " + str(e))
172172
exitcode = 1
173173

174174
server.stop()

test/tools/LocalAngularServer.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,20 @@ def start(self, handler, data):
6363

6464
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
6565
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
66-
self.sock.settimeout(30)
66+
self.sock.settimeout(1)
6767
self.sock.bind(("127.0.0.1", 0))
6868
self.sock.listen(1)
6969

70+
self.url = "127.0.0.1:" + str(self.sock.getsockname()[1])
71+
7072
self.thread = threading.Thread(target=getattr(self, handler))
7173
self.thread.start()
7274

73-
self.url = "127.0.0.1:" + str(self.sock.getsockname()[1])
74-
7575
def handler_vulnerable_test(self):
7676
"""Serve a vulnerable AngularJS application for every HTTP request."""
7777

78-
try:
79-
while self.running:
78+
while self.running:
79+
try:
8080
csock, caddr = self.sock.accept()
8181
request = csock.recv(1024)
8282

@@ -98,14 +98,14 @@ def handler_vulnerable_test(self):
9898

9999
csock.sendall(b"""HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=utf-8\r\n\r\n""" + bytes(html.encode("UTF-8")))
100100
csock.close()
101-
except Exception as e:
102-
self.running = False
101+
except Exception as e:
102+
pass
103103

104104
def handler_scope_test(self):
105105
"""Serve a vulnerable AngularJS application for every HTTP request."""
106106

107-
try:
108-
while self.running:
107+
while self.running:
108+
try:
109109
csock, caddr = self.sock.accept()
110110
request = csock.recv(1024)
111111

@@ -137,8 +137,8 @@ def handler_scope_test(self):
137137

138138
csock.sendall(b"""HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=utf-8\r\n\r\n""" + bytes(html.encode("UTF-8")))
139139
csock.close()
140-
except Exception as e:
141-
self.running = False
140+
except Exception as e:
141+
pass
142142

143143
def stop(self):
144144
"""Stop the websocket."""

0 commit comments

Comments
 (0)