Changeset: 27acf312b076 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/27acf312b076
Modified Files:
clients/mapilib/Tests/tlssecurity.py
sql/jdbc/tests/Tests/TLSTester.py
testing/tlstester.py
Branch: Dec2025
Log Message:
Do not hardcode localhost.localdomain
diffs (101 lines):
diff --git a/clients/mapilib/Tests/tlssecurity.py
b/clients/mapilib/Tests/tlssecurity.py
--- a/clients/mapilib/Tests/tlssecurity.py
+++ b/clients/mapilib/Tests/tlssecurity.py
@@ -13,7 +13,7 @@ import re
import subprocess
import sys
-from MonetDBtesting.tlstester import TLSTesterClient
+from MonetDBtesting.tlstester import TLSTesterClient, LOCALHOST_ALIAS
log_level = logging.WARNING
log_format = '%(levelname)s:t=%(relativeCreated)d:%(name)s:%(message)s'# if
sys.platform == 'win32':
@@ -25,6 +25,8 @@ logging.addLevelName(logging.INFO, '#INF
logging.basicConfig(level=log_level,format=log_format)
+logging.debug(f"LOCALHOST_ALIAS={LOCALHOST_ALIAS}")
+
# A tmpdir to write certificates to
tgtdir = os.environ['TSTTRGDIR']
assert os.path.isdir(tgtdir)
@@ -114,7 +116,7 @@ attempt('refuse_wrong_cert', 'server1',
# For example, `localhost.localdomain` instead of `localhost`.
# The client should refuse to let the connection proceed.
-attempt('refuse_wrong_host', 'server1', 'verify failed',
host='localhost.localdomain', cert=certpath('ca1.crt'))
+attempt('refuse_wrong_host', 'server1', 'verify failed', host=LOCALHOST_ALIAS,
cert=certpath('ca1.crt'))
# refuse_tlsv12
#
diff --git a/sql/jdbc/tests/Tests/TLSTester.py
b/sql/jdbc/tests/Tests/TLSTester.py
--- a/sql/jdbc/tests/Tests/TLSTester.py
+++ b/sql/jdbc/tests/Tests/TLSTester.py
@@ -1,5 +1,6 @@
import os, sys
from subprocess import run, PIPE, CalledProcessError
+from MonetDBtesting.tlstester import LOCALHOST_ALIAS
PORT=os.environ['TST_TLSTESTERPORT']
@@ -7,7 +8,7 @@ cmd = [
'java', 'TLSTester',
# '-v',
f'localhost:{PORT}',
- '-a', 'localhost.localdomain'
+ '-a', LOCALHOST_ALIAS
]
try:
p = run(cmd, stdout=PIPE, stderr=PIPE, check=True, encoding='utf-8')
diff --git a/testing/tlstester.py b/testing/tlstester.py
--- a/testing/tlstester.py
+++ b/testing/tlstester.py
@@ -52,6 +52,30 @@ DESCRIPTION = f"tlstester.py version {VE
log = logging.getLogger("tlstester")
+# For some tests we need an alias for localhost, that is, a name other than
+# 'localhost' that still resolves to either 127.0.0.1 or ::1.
+LOCALHOST_ALIAS = None
+candidates = [
+ "localhost.localdomain",
+ "localhost4", "localhost6",
+ "ip4-localhost", "ip6-localhost",
+ "localhost.local",
+ "alias.localhost",
+ "127.0.0.1",
+]
+for candidate in candidates:
+ try:
+ if socket.getaddrinfo(candidate, 0):
+ LOCALHOST_ALIAS = candidate
+ break
+ except:
+ continue
+else:
+ log.error(f"No suitable LOCALHOST_ALIAS among {candidates!r}")
+ exit(1)
+del candidates, candidate
+assert LOCALHOST_ALIAS
+
argparser = ArgumentParser("tlstester", description=DESCRIPTION)
argparser.add_argument(
"-p",
@@ -79,7 +103,7 @@ argparser.add_argument(
action="append",
type=str,
default=[],
- help="server name to sign certificates for, can be repeated,
default=localhost.localdomain",
+ help="server name to sign certificates for, can be repeated,
default=localhost",
)
argparser.add_argument(
"--sequential",
@@ -805,7 +829,7 @@ def main(args):
if args.base_port == 0 and args.sequential:
sys.exit("--sequential requires a nonzero base port")
- hostnames = args.hostname or ["localhost.localdomain"]
+ hostnames = args.hostname or ["localhost"]
log.debug(f"Creating certs for {hostnames}")
certs = Certs(hostnames)
if args.write:
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]