Skip to content
This repository was archived by the owner on Dec 30, 2025. It is now read-only.

Commit cefc6b5

Browse files
committed
fix: update IRC service port references from 6667 to 6697 for enhanced security
- Changed all instances of the default IRC port from 6667 to 6697 across test configurations and fixtures. - Updated connection details in various test classes to ensure compatibility with the new secure port. - Adjusted comments and documentation to reflect the port change and clarify the use of TLS for the IRC service.
1 parent 39a7786 commit cefc6b5

File tree

11 files changed

+70
-84
lines changed

11 files changed

+70
-84
lines changed

tests/conftest.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ def prepared_config_dir(tmp_path):
6767
unrealircd_container = container(
6868
image="{unrealircd_image.id}",
6969
ports={
70-
"6667/tcp": None, # Main IRC port
71-
"6697/tcp": None, # TLS port
70+
"6697/tcp": None, # Main IRC port (TLS only)
7271
},
7372
volumes={
7473
"{prepared_config_dir}": {"bind": "/home/unrealircd/unrealircd/conf", "mode": "rw"},
@@ -168,7 +167,7 @@ def docker_cleanup():
168167
return ["down -v"]
169168

170169

171-
def is_irc_service_responsive(host, port=6667):
170+
def is_irc_service_responsive(host, port=6697):
172171
"""Check if IRC service is responsive."""
173172
import socket
174173

@@ -185,7 +184,7 @@ def is_irc_service_responsive(host, port=6667):
185184
@pytest.fixture(scope="session")
186185
def irc_service(docker_ip, docker_services):
187186
"""Ensure IRC service is up and responsive."""
188-
port = docker_services.port_for("unrealircd", 6667)
187+
port = docker_services.port_for("unrealircd", 6697)
189188
url = f"{docker_ip}:{port}"
190189

191190
docker_services.wait_until_responsive(
@@ -218,7 +217,7 @@ def sample_config_data() -> dict:
218217
return {
219218
"irc_server": {
220219
"host": "localhost",
221-
"port": 6667,
220+
"port": 6697,
222221
"ssl_port": 6697,
223222
"network_name": "test.network",
224223
},
@@ -314,7 +313,7 @@ def docker_compose_helper(compose_file: Path, project_root: Path) -> DockerCompo
314313
class IRCTestHelper:
315314
"""Helper class for IRC-related testing operations."""
316315

317-
def __init__(self, host: str = "localhost", port: int = 6667):
316+
def __init__(self, host: str = "localhost", port: int = 6697):
318317
self.host = host
319318
self.port = port
320319

@@ -489,7 +488,7 @@ def _inject_controller_if_needed(request):
489488
# Set up connection details
490489
container_ports = controller.get_container_ports()
491490
request.instance.hostname = "localhost"
492-
request.instance.port = container_ports.get("6667/tcp", 6667)
491+
request.instance.port = container_ports.get("6697/tcp", 6697)
493492

494493

495494
@pytest.fixture(autouse=True)

tests/controllers/unrealircd_controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __init__(self, test_config, container_fixture=None):
6363
# Set port from container if available
6464
if self.container:
6565
container_ports = self.get_container_ports()
66-
self.port = container_ports.get("6667/tcp", 6667)
66+
self.port = container_ports.get("6697/tcp", 6697)
6767

6868
def create_config(self) -> None:
6969
"""Create the configuration directory and basic files."""
@@ -93,7 +93,7 @@ def run(
9393
# The container is already running via pytest-docker-tools
9494
# Get the actual mapped ports from the container
9595
container_ports = self.get_container_ports()
96-
self.port = container_ports.get("6667/tcp", port)
96+
self.port = container_ports.get("6697/tcp", port)
9797
if ssl:
9898
self.tls_port = container_ports.get("6697/tcp", port + 30)
9999

tests/fixtures/irc_test_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
IRC_SERVER_CONFIGS = {
77
"basic": {
88
"host": "localhost",
9-
"port": 6667,
9+
"port": 6697,
1010
"ssl_port": 6697,
1111
"network": "TestNet",
1212
"description": "Basic test IRC server",

tests/fixtures/sample_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"description": "Test IRC Server",
1010
"network": "TestNet",
1111
},
12-
"listen": [{"port": 6667, "ssl": False}, {"port": 6697, "ssl": True}],
12+
"listen": [{"port": 6697, "ssl": True}],
1313
"operators": [{"name": "testop", "password": "$2a$10$hashedpassword", "class": "netadmin"}],
1414
}
1515

@@ -19,7 +19,7 @@
1919
"services": {
2020
"ircd": {
2121
"image": "unrealircd:latest",
22-
"ports": ["6667:6667", "6697:6697"],
22+
"ports": ["6697:6697"],
2323
"volumes": ["./data:/data"],
2424
"environment": ["IRC_NETWORK=testnet"],
2525
},
@@ -35,7 +35,7 @@
3535
SAMPLE_IRC_LOGS = [
3636
"[2024-01-01 12:00:00] IRC Server starting",
3737
"[2024-01-01 12:00:01] Loading configuration",
38-
"[2024-01-01 12:00:02] Server ready on port 6667",
38+
"[2024-01-01 12:00:02] Server ready on port 6697",
3939
"[2024-01-01 12:00:05] Client connecting: testuser",
4040
"[2024-01-01 12:00:06] JOIN #testchannel testuser",
4141
]

tests/integration/test_clients.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ async def on_quit(self, user, reason=None):
119119
class IRCClientTest(client.SimpleIRCClient if client else object):
120120
"""IRC client for testing purposes using the python-irc library."""
121121

122-
def __init__(self, host: str = "localhost", port: int = 6667):
122+
def __init__(self, host: str = "localhost", port: int = 6697):
123123
if client:
124124
client.SimpleIRCClient.__init__(self)
125125
self.host = host
@@ -265,7 +265,7 @@ async def test_pydle_basic_connection(self, controller):
265265
# Set up connection details from controller
266266
container_ports = self.controller.get_container_ports()
267267
self.hostname = "localhost"
268-
self.port = container_ports.get("6667/tcp", 6667)
268+
self.port = container_ports.get("6697/tcp", 6697)
269269

270270
client = PydleTestBot(f"pydle_test_{int(time.time())}")
271271

@@ -292,7 +292,7 @@ async def test_pydle_channel_operations(self, controller):
292292
# Set up connection details from controller
293293
container_ports = self.controller.get_container_ports()
294294
self.hostname = "localhost"
295-
self.port = container_ports.get("6667/tcp", 6667)
295+
self.port = container_ports.get("6697/tcp", 6697)
296296

297297
client = PydleTestBot(f"pydle_chan_{int(time.time())}")
298298

@@ -325,7 +325,7 @@ async def test_pydle_messaging(self, controller):
325325
# Set up connection details from controller
326326
container_ports = self.controller.get_container_ports()
327327
self.hostname = "localhost"
328-
self.port = container_ports.get("6667/tcp", 6667)
328+
self.port = container_ports.get("6697/tcp", 6697)
329329

330330
client1 = PydleTestBot(f"pydle_msg1_{int(time.time())}")
331331
client2 = PydleTestBot(f"pydle_msg2_{int(time.time())}")
@@ -376,7 +376,7 @@ async def test_pydle_private_messaging(self, controller):
376376
# Set up connection details from controller
377377
container_ports = self.controller.get_container_ports()
378378
self.hostname = "localhost"
379-
self.port = container_ports.get("6667/tcp", 6667)
379+
self.port = container_ports.get("6697/tcp", 6697)
380380

381381
client1 = PydleTestBot(f"pydle_priv1_{int(time.time())}")
382382
client2 = PydleTestBot(f"pydle_priv2_{int(time.time())}")
@@ -424,7 +424,7 @@ def irc_client(self, controller):
424424
self.controller = controller
425425
container_ports = self.controller.get_container_ports()
426426
self.hostname = "localhost"
427-
self.port = container_ports.get("6667/tcp", 6667)
427+
self.port = container_ports.get("6697/tcp", 6697)
428428

429429
client = IRCClientTest(self.hostname, self.port)
430430
yield client

tests/integration/test_irc_functionality.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_irc_server_connection(self, irc_helper):
1717
# This test requires an actual IRC server to be running
1818
# It will skip if no server is available
1919
if not irc_helper.wait_for_irc_server(timeout=10):
20-
pytest.skip("No IRC server running on localhost:6667")
20+
pytest.skip("No IRC server running on localhost:6697")
2121

2222
# If we get here, server is running, test basic connection
2323
response = irc_helper.send_irc_command("PING test")
@@ -125,7 +125,7 @@ def test_irc_connection_mock(self, mock_socket):
125125
# Create a mock helper object
126126
helper = Mock()
127127
helper.host = "localhost"
128-
helper.port = 6667
128+
helper.port = 6697
129129
helper.send_irc_command = Mock(return_value=":server 001 test :Welcome")
130130

131131
response = helper.send_irc_command("TEST")

tests/integration/test_protocol.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,28 @@ def controller(unrealircd_container, prepared_config_dir):
3737
class TestConnectionProtocol(BaseServerTestCase):
3838
"""Test basic IRC connection and registration protocols."""
3939

40-
def setup_method(self, method, controller):
40+
def setup_method(self, method):
4141
"""Override setup to use controller fixture."""
42-
self.controller = controller
42+
# Controller will be injected via autouse fixture
43+
if hasattr(self, "controller") and self.controller is not None:
44+
# Set default test parameters
45+
self.password = None
46+
self.ssl = True # Port 6697 is TLS-only
47+
self.run_services = False
48+
self.faketime = None
49+
self.server_support = None
50+
51+
# Run the controller (hostname/port already set by inject_controller fixture)
52+
self.controller.run(
53+
self.hostname,
54+
self.port,
55+
password=self.password,
56+
ssl=self.ssl,
57+
run_services=self.run_services,
58+
faketime=self.faketime,
59+
)
60+
4361
self.clients = {}
44-
self.server_support = None
45-
# Set up connection details from controller
46-
container_ports = self.controller.get_container_ports()
47-
self.hostname = "localhost"
48-
self.port = container_ports.get("6667/tcp", 6667)
4962

5063
@mark_specifications("RFC1459", "RFC2812")
5164
@pytest.mark.integration
@@ -134,7 +147,7 @@ def setup_method(self, method):
134147
if hasattr(self, "controller") and self.controller is not None:
135148
# Set default test parameters
136149
self.password = None
137-
self.ssl = False
150+
self.ssl = True # Port 6697 is TLS-only
138151
self.run_services = False
139152
self.faketime = None
140153
self.server_support = None
@@ -209,7 +222,7 @@ def setup_method(self, method):
209222
if hasattr(self, "controller") and self.controller is not None:
210223
# Set default test parameters
211224
self.password = None
212-
self.ssl = False
225+
self.ssl = True # Port 6697 is TLS-only
213226
self.run_services = False
214227
self.faketime = None
215228
self.server_support = None
@@ -324,7 +337,7 @@ def setup_method(self, method):
324337
if hasattr(self, "controller") and self.controller is not None:
325338
# Set default test parameters
326339
self.password = None
327-
self.ssl = False
340+
self.ssl = True # Port 6697 is TLS-only
328341
self.run_services = False
329342
self.faketime = None
330343
self.server_support = None
@@ -411,7 +424,7 @@ def setup_method(self, method):
411424
if hasattr(self, "controller") and self.controller is not None:
412425
# Set default test parameters
413426
self.password = None
414-
self.ssl = False
427+
self.ssl = True # Port 6697 is TLS-only
415428
self.run_services = False
416429
self.faketime = None
417430
self.server_support = None

tests/integration/test_services.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class IRCIntegrationClient:
1717
"""Enhanced IRC client for service integration testing."""
1818

19-
def __init__(self, host: str = "localhost", port: int = 6667, use_ssl: bool = False):
19+
def __init__(self, host: str = "localhost", port: int = 6697, use_ssl: bool = True):
2020
self.host = host
2121
self.port = port
2222
self.use_ssl = use_ssl

tests/legacy/integration/test_docker_services.py

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
"""Integration tests for Docker services."""
22

3-
import pytest
4-
import time
53
import socket
6-
import subprocess
7-
import requests
8-
from pathlib import Path
4+
import time
5+
96
import docker
10-
import os
7+
import pytest
8+
import requests
119

1210

1311
class TestDockerServices:
@@ -57,9 +55,7 @@ def running_services(self, docker_client, project_root):
5755
"""Ensure Docker services are running for integration tests."""
5856
# Check if services are already running
5957
try:
60-
containers = docker_client.containers.list(
61-
filters={"label": "com.docker.compose.project=irc.atl.chat"}
62-
)
58+
containers = docker_client.containers.list(filters={"label": "com.docker.compose.project=irc.atl.chat"})
6359

6460
if not containers:
6561
pytest.skip("Docker services not running. Run 'make up' first.")
@@ -81,18 +77,14 @@ def test_unrealircd_container_running(self, running_services):
8177
unrealircd_container = container
8278
break
8379

84-
assert unrealircd_container is not None, (
85-
"UnrealIRCd container should be running"
86-
)
80+
assert unrealircd_container is not None, "UnrealIRCd container should be running"
8781
assert unrealircd_container.status == "running", "UnrealIRCd should be running"
8882

8983
# Check health status if available
9084
container_info = unrealircd_container.attrs
9185
health = container_info.get("State", {}).get("Health", {}).get("Status")
9286
if health:
93-
assert health in ["healthy", "starting"], (
94-
f"UnrealIRCd health status: {health}"
95-
)
87+
assert health in ["healthy", "starting"], f"UnrealIRCd health status: {health}"
9688

9789
@pytest.mark.integration
9890
@pytest.mark.docker
@@ -125,15 +117,15 @@ def test_webpanel_container_running(self, running_services):
125117
@pytest.mark.slow
126118
def test_irc_ports_open(self, running_services):
127119
"""Test that IRC ports are open and accepting connections."""
128-
ports_to_test = [6667, 6697] # Standard IRC and SSL ports
120+
ports_to_test = [6697] # TLS only
129121

130122
for port in ports_to_test:
131123
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
132124
sock.settimeout(5)
133125
try:
134126
result = sock.connect_ex(("localhost", port))
135127
assert result == 0, f"Port {port} should be open"
136-
except socket.error:
128+
except OSError:
137129
pytest.fail(f"Could not connect to port {port}")
138130

139131
@pytest.mark.integration
@@ -165,9 +157,7 @@ def test_container_logs_accessible(self, running_services):
165157
for container in running_services:
166158
try:
167159
logs = container.logs(tail=10)
168-
assert logs is not None, (
169-
f"Logs should be accessible for {container.name}"
170-
)
160+
assert logs is not None, f"Logs should be accessible for {container.name}"
171161
except docker.errors.DockerException:
172162
pytest.fail(f"Could not access logs for {container.name}")
173163

@@ -188,9 +178,7 @@ def test_service_dependencies(self, running_services):
188178

189179
if unrealircd_start and atheme_start:
190180
# Atheme should start after UnrealIRCd
191-
assert atheme_start > unrealircd_start, (
192-
"Atheme should start after UnrealIRCd"
193-
)
181+
assert atheme_start > unrealircd_start, "Atheme should start after UnrealIRCd"
194182

195183
@pytest.mark.integration
196184
@pytest.mark.docker
@@ -202,9 +190,7 @@ def test_container_resource_limits(self, running_services):
202190
# Check if memory limits are set (optional but good practice)
203191
memory_limit = config.get("Memory")
204192
if memory_limit:
205-
assert memory_limit > 0, (
206-
f"Container {container.name} should have memory limit"
207-
)
193+
assert memory_limit > 0, f"Container {container.name} should have memory limit"
208194

209195
@pytest.mark.integration
210196
@pytest.mark.docker
@@ -215,7 +201,7 @@ def test_environment_variables_passed(self, running_services, project_root):
215201
if env_file.exists():
216202
# Read expected variables
217203
expected_vars = {}
218-
with open(env_file, "r") as f:
204+
with open(env_file) as f:
219205
for line in f:
220206
line = line.strip()
221207
if line and not line.startswith("#") and "=" in line:
@@ -234,24 +220,18 @@ def test_environment_variables_passed(self, running_services, project_root):
234220

235221
# Check some key variables are present
236222
for var in ["TZ", "PUID", "PGID"]:
237-
assert var in env_dict, (
238-
f"Environment variable {var} should be set"
239-
)
223+
assert var in env_dict, f"Environment variable {var} should be set"
240224

241225
@pytest.mark.integration
242226
@pytest.mark.docker
243227
@pytest.mark.slow
244228
def test_container_restart_policy(self, running_services):
245229
"""Test that containers have appropriate restart policies."""
246230
for container in running_services:
247-
restart_policy = container.attrs.get("HostConfig", {}).get(
248-
"RestartPolicy", {}
249-
)
231+
restart_policy = container.attrs.get("HostConfig", {}).get("RestartPolicy", {})
250232

251233
# Most services should have unless-stopped policy
252-
if (
253-
"ssl-monitor" not in container.name
254-
): # SSL monitor might have different policy
234+
if "ssl-monitor" not in container.name: # SSL monitor might have different policy
255235
assert restart_policy.get("Name") in ["unless-stopped", "always"], (
256236
f"Container {container.name} should have restart policy"
257237
)

0 commit comments

Comments
 (0)