Skip to content

Commit 93104bf

Browse files
committed
Fix tests
1 parent e00b917 commit 93104bf

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

sslyze/scanner.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def __init__(
159159
final_concurrent_server_scans_limit = concurrent_server_scans_limit
160160
self._concurrent_server_scans_count = final_concurrent_server_scans_limit
161161

162-
self._all_thread_pools: List[ThreadPoolExecutor] = []
162+
self._thread_pools: List[ThreadPoolExecutor] = []
163163
self._queued_server_scans: List[_QueuedServerScan] = []
164164

165165
def _get_assigned_thread_pool_index(self) -> int:
@@ -172,9 +172,9 @@ def _get_assigned_thread_pool_index(self) -> int:
172172
assigned_thread_pool_index = currently_queued_scans_count % allowed_thread_pools_count
173173

174174
try:
175-
self._all_thread_pools[assigned_thread_pool_index]
175+
self._thread_pools[assigned_thread_pool_index]
176176
except IndexError:
177-
self._all_thread_pools.append(ThreadPoolExecutor(max_workers=self._per_server_concurrent_connections_count))
177+
self._thread_pools.append(ThreadPoolExecutor(max_workers=self._per_server_concurrent_connections_count))
178178

179179
return assigned_thread_pool_index
180180

@@ -190,7 +190,7 @@ def queue_scan(self, server_scan: ServerScanRequest) -> None:
190190

191191
# Assign the server to scan to a thread pool
192192
assigned_thread_pool_index = self._get_assigned_thread_pool_index()
193-
assigned_thread_pool = self._all_thread_pools[assigned_thread_pool_index]
193+
assigned_thread_pool = self._thread_pools[assigned_thread_pool_index]
194194

195195
# Convert each scan command within the server scan request into jobs
196196
queued_futures_per_scan_command: Dict[ScanCommandType, Set[Future]] = {}
@@ -301,9 +301,9 @@ def get_results(self) -> Iterable[ServerScanResult]:
301301

302302
def _shutdown_thread_pools(self) -> None:
303303
self._queued_server_scans = []
304-
for thread_pool in self._all_thread_pools:
304+
for thread_pool in self._thread_pools:
305305
thread_pool.shutdown(wait=True)
306-
self._all_thread_pools = []
306+
self._thread_pools = []
307307

308308
# Force garbage collection because for some reason the Future objects created by ThreadPoolExecutor.submit()
309309
# take a ton of memory (compared to what they do - holding a function to call and its arguments):

tests/plugins_tests/certificate_info/test_certificate_info_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def test_certificate_with_no_cn(self):
178178
# When running the scan, it succeeds
179179
plugin_result = CertificateInfoImplementation.scan_server(server_info)
180180

181-
assert plugin_result.certificate_deployments[0].verified_certificate_chain
181+
assert plugin_result.certificate_deployments[0].received_certificate_chain
182182

183183
def test_certificate_with_no_subject(self):
184184
# Given a server to scan that has a certificate with no Subject

tests/test_scanner.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,16 @@ def test(self):
232232

233233
# And the right number of scans was performed
234234
assert total_server_scans_count == len(scanner._queued_server_scans)
235-
assert total_server_scans_count == len(scanner._server_to_thread_pool)
236235

237236
# And the chosen network settings were used
238-
assert concurrent_server_scans_limit == len(scanner._all_thread_pools)
239-
for pool in scanner._all_thread_pools:
237+
assert concurrent_server_scans_limit == len(scanner._thread_pools)
238+
for pool in scanner._thread_pools:
240239
assert per_server_concurrent_connections_limit == pool._max_workers
241240

242241
# And the server scans were evenly distributed among the thread pools to maximize performance
243242
expected_server_scans_per_pool = int(total_server_scans_count / concurrent_server_scans_limit)
244-
server_scans_per_pool_count = Counter(scanner._server_to_thread_pool.values())
243+
thread_pools_used = [server_scan.queued_on_thread_pool_at_index for server_scan in scanner._queued_server_scans]
244+
server_scans_per_pool_count = Counter(thread_pools_used)
245245
for pool_count in server_scans_per_pool_count.values():
246246
assert expected_server_scans_per_pool == pool_count
247247

@@ -266,5 +266,8 @@ def test_emergency_shutdown(self):
266266
scanner.emergency_shutdown()
267267

268268
# And all the queued jobs were done or cancelled
269-
for completed_future in as_completed(scanner._queued_future_to_server_and_scan_cmd.keys()):
269+
all_queued_futures = []
270+
for server_scan in scanner._queued_server_scans:
271+
all_queued_futures.extend(server_scan.all_queued_scan_jobs)
272+
for completed_future in as_completed(all_queued_futures):
270273
assert completed_future.done()

0 commit comments

Comments
 (0)