28 lines
1.3 KiB
Python
28 lines
1.3 KiB
Python
|
|
import socket
|
||
|
|
import unittest
|
||
|
|
from unittest.mock import patch
|
||
|
|
|
||
|
|
from cleanup_closed_scanner_fixture import recover
|
||
|
|
|
||
|
|
|
||
|
|
class ClosedScannerFixtureGuardTest(unittest.TestCase):
|
||
|
|
def test_customer_or_incomplete_batch_is_rejected_before_database_access(self):
|
||
|
|
with patch('cleanup_closed_scanner_fixture.ResourceStore') as database:
|
||
|
|
for prefix in ('am-freescan-sim-robot','DEMO-20261022-091650','E2E-SCANNER-'):
|
||
|
|
with self.assertRaises(AssertionError):recover(prefix,58071,True)
|
||
|
|
database.assert_not_called()
|
||
|
|
|
||
|
|
def test_live_localhost_listener_cannot_be_cleaned(self):
|
||
|
|
with socket.socket() as server:
|
||
|
|
server.bind(('127.0.0.1',0));server.listen(1)
|
||
|
|
with patch('cleanup_closed_scanner_fixture.ResourceStore') as database:
|
||
|
|
with self.assertRaisesRegex(AssertionError,'still listening'):
|
||
|
|
recover('E2E-SCANNER-1022215306-f5f3',server.getsockname()[1],True)
|
||
|
|
database.assert_not_called()
|
||
|
|
|
||
|
|
def test_privileged_and_invalid_ports_are_rejected(self):
|
||
|
|
with patch('cleanup_closed_scanner_fixture.ResourceStore') as database:
|
||
|
|
for port in (0,80,65536):
|
||
|
|
with self.assertRaisesRegex(AssertionError,'Invalid fixture port'):recover('E2E-SCANNER-1022215306-f5f3',port,True)
|
||
|
|
database.assert_not_called()
|