Files
DarkflameServer/tests/dCommonTests/BindAddressTests.cpp
Aaron Kimbrell e36f894f1f feat: bind_ip setting for the server sockets
bind_ip in sharedconfig.ini picks the local IPv4 address every server's
RakNet sockets listen on (auth, chat, master, world, the dashboard's
connection to master), separate from external_ip, the address players
are sent. Empty or 0.0.0.0 keeps listening on all interfaces; localhost
means 127.0.0.1. Anything that isn't an IPv4 address stops the server
with an error, and each server logs what it bound to.

Fixes #225

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:30:54 -05:00

26 lines
1.1 KiB
C++

#include <gtest/gtest.h>
#include "GeneralUtils.h"
TEST(BindAddressTests, EmptyMeansAllInterfaces) {
EXPECT_EQ(GeneralUtils::ParseBindAddress(""), std::string{});
EXPECT_EQ(GeneralUtils::ParseBindAddress(" "), std::string{});
EXPECT_EQ(GeneralUtils::ParseBindAddress("0.0.0.0"), std::string{});
EXPECT_EQ(GeneralUtils::ParseBindAddress("*"), std::string{});
}
TEST(BindAddressTests, AcceptsIPv4) {
EXPECT_EQ(GeneralUtils::ParseBindAddress("127.0.0.1"), "127.0.0.1");
EXPECT_EQ(GeneralUtils::ParseBindAddress(" 192.168.1.20\r"), "192.168.1.20");
EXPECT_EQ(GeneralUtils::ParseBindAddress("255.255.255.255"), "255.255.255.255");
EXPECT_EQ(GeneralUtils::ParseBindAddress("localhost"), "127.0.0.1");
EXPECT_EQ(GeneralUtils::ParseBindAddress("LocalHost"), "127.0.0.1");
}
TEST(BindAddressTests, RejectsEverythingElse) {
for (const auto* bad : { "256.0.0.1", "1.2.3", "1.2.3.4.5", "1..2.3", "a.b.c.d", "010.0.0.1", "-1.0.0.1",
"1.2.3.4:2000", "example.com", "::1", "1.2.3.4 5", "+1.2.3.4" }) {
EXPECT_FALSE(GeneralUtils::ParseBindAddress(bad).has_value()) << bad;
}
}