Skip to content

Commit 9f58c0b

Browse files
committed
Explicit root cert cleanup calls
1 parent 87156b0 commit 9f58c0b

8 files changed

Lines changed: 30 additions & 9 deletions

tests/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ def assert_connection_rejected(client, server, name, timeout_ok=True):
277277
def create_default_certs(algorithm='ecdsa'):
278278
"""Create standard root, server, and client certificates.
279279
280-
Returns the RootCert object. Callers must keep a reference to it
281-
alive for the duration of the test to prevent __del__ cleanup."""
280+
Returns the RootCert object. Callers should call root.cleanup()
281+
in their finally block to clean up temporary cert files."""
282282
root = RootCert('root', algorithm=algorithm)
283283
root.create_signed_cert('server')
284284
root.create_signed_cert('client')

tests/test-client-handles-client-closes-connection.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
from common import SocketPair, TcpClient, TlsServer, print_ok, terminate, LISTEN_PORT, TARGET_PORT, create_default_certs, start_ghostunnel_client
88

99
ghostunnel = None
10+
root = None
1011
try:
11-
_root = create_default_certs() # keep RootCert alive for cert lifecycle
12+
root = create_default_certs()
1213
ghostunnel = start_ghostunnel_client(extra_args=['--close-timeout=10s'])
1314

1415
# connect to server, confirm that the tunnel is up
@@ -31,3 +32,5 @@
3132
print_ok("OK")
3233
finally:
3334
terminate(ghostunnel)
35+
if root:
36+
root.cleanup()

tests/test-client-handles-no-server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
from common import SocketPair, TcpClient, TlsServer, print_ok, terminate, LISTEN_PORT, TARGET_PORT, create_default_certs, start_ghostunnel_client, get_free_port
88

99
ghostunnel = None
10+
root = None
1011
try:
11-
_root = create_default_certs() # keep RootCert alive for cert lifecycle
12+
root = create_default_certs()
1213
ghostunnel = start_ghostunnel_client()
1314

1415
# client should fail to connect since nothing is listening on wrong_port
@@ -26,3 +27,5 @@
2627
print_ok("OK")
2728
finally:
2829
terminate(ghostunnel)
30+
if root:
31+
root.cleanup()

tests/test-client-handles-server-closes-connection.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
from common import SocketPair, TcpClient, TlsServer, print_ok, terminate, LISTEN_PORT, TARGET_PORT, create_default_certs, start_ghostunnel_client
88

99
ghostunnel = None
10+
root = None
1011
try:
11-
_root = create_default_certs() # keep RootCert alive for cert lifecycle
12+
root = create_default_certs()
1213
ghostunnel = start_ghostunnel_client(extra_args=['--close-timeout=10s'])
1314

1415
# connect with client, confirm that the tunnel is up
@@ -31,3 +32,5 @@
3132
print_ok("OK")
3233
finally:
3334
terminate(ghostunnel)
35+
if root:
36+
root.cleanup()

tests/test-server-handles-client-closes-connection.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
from common import SocketPair, TcpServer, TlsClient, print_ok, terminate, LISTEN_PORT, TARGET_PORT, create_default_certs, start_ghostunnel_server
88

99
ghostunnel = None
10+
root = None
1011
try:
11-
_root = create_default_certs() # keep RootCert alive for cert lifecycle
12+
root = create_default_certs()
1213
ghostunnel = start_ghostunnel_server(extra_args=['--close-timeout=10s'])
1314

1415
# connect with client, confirm that the tunnel is up
@@ -31,3 +32,5 @@
3132
print_ok("OK")
3233
finally:
3334
terminate(ghostunnel)
35+
if root:
36+
root.cleanup()

tests/test-server-handles-no-server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
from common import SocketPair, TcpServer, TlsClient, print_ok, terminate, LISTEN_PORT, TARGET_PORT, create_default_certs, start_ghostunnel_server, get_free_port
88

99
ghostunnel = None
10+
root = None
1011
try:
11-
_root = create_default_certs() # keep RootCert alive for cert lifecycle
12+
root = create_default_certs()
1213
ghostunnel = start_ghostunnel_server()
1314

1415
# client should fail to connect since nothing is listening on wrong_port
@@ -26,3 +27,5 @@
2627
print_ok("OK")
2728
finally:
2829
terminate(ghostunnel)
30+
if root:
31+
root.cleanup()

tests/test-server-handles-server-closes-connection.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
from common import SocketPair, TcpServer, TlsClient, print_ok, terminate, LISTEN_PORT, TARGET_PORT, create_default_certs, start_ghostunnel_server
88

99
ghostunnel = None
10+
root = None
1011
try:
11-
_root = create_default_certs() # keep RootCert alive for cert lifecycle
12+
root = create_default_certs()
1213
ghostunnel = start_ghostunnel_server(extra_args=['--close-timeout=10s'])
1314

1415
# connect with client, confirm that the tunnel is up
@@ -31,3 +32,5 @@
3132
print_ok("OK")
3233
finally:
3334
terminate(ghostunnel)
35+
if root:
36+
root.cleanup()

tests/test-server-split-cert-key.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
from common import LOCALHOST, STATUS_PORT, print_ok, run_ghostunnel, terminate, SocketPair, TlsClient, TcpServer, LISTEN_PORT, TARGET_PORT, create_default_certs
88

99
ghostunnel = None
10+
root = None
1011
try:
11-
_root = create_default_certs() # keep RootCert alive for cert lifecycle
12+
root = create_default_certs()
1213

1314
# start ghostunnel with --cert/--key instead of --keystore
1415
ghostunnel = run_ghostunnel(['server',
@@ -34,3 +35,5 @@
3435
print_ok("OK")
3536
finally:
3637
terminate(ghostunnel)
38+
if root:
39+
root.cleanup()

0 commit comments

Comments
 (0)