Skip to content

Commit d3b3144

Browse files
chore: fix code security (#197)
1 parent 8c7495d commit d3b3144

File tree

6 files changed

+19
-22
lines changed

6 files changed

+19
-22
lines changed

trpc/config/provider/local_file/local_file_provider_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ TEST_F(TrpcConfigProviderTest, TestLocalTOML) {
110110
trpc::config::Load("./test_load.toml", trpc::config::WithCodec("toml"), trpc::config::WithProvider("file3"));
111111
ASSERT_EQ(config->GetString("title", ""), "TOML TEST");
112112
ASSERT_EQ(config->GetString("owner.name", ""), "John Doe");
113-
ASSERT_EQ(config->GetString("database.server", ""), "192.168.1.1");
113+
ASSERT_EQ(config->GetString("database.server", ""), "127.0.0.1");
114114
ASSERT_EQ(config->GetInt64("database.connection_max", 0), 5000);
115115
ASSERT_TRUE(config->GetBool("database.enabled", false));
116-
ASSERT_EQ(config->GetString("servers.alpha.ip", ""), "10.0.0.1");
116+
ASSERT_EQ(config->GetString("servers.alpha.ip", ""), "127.0.0.1");
117117
ASSERT_EQ(config->GetString("servers.alpha.dc", ""), "eqdc10");
118-
ASSERT_EQ(config->GetString("servers.beta.ip", ""), "10.0.0.2");
118+
ASSERT_EQ(config->GetString("servers.beta.ip", ""), "127.0.0.2");
119119
ASSERT_EQ(config->GetString("servers.beta.dc", ""), "eqdc10");
120120
}
121121

trpc/config/testing/test_load.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name = "John Doe"
55
dob = "1979-05-27T07:32:00-08:00" # First-class dates
66

77
[database]
8-
server = "192.168.1.1"
8+
server = "127.0.0.1"
99
ports = [ 8001, 8001, 8002 ]
1010
connection_max = 5000
1111
enabled = true
@@ -14,9 +14,9 @@ enabled = true
1414

1515
# Indentation (tabs and/or spaces) is allowed but not required
1616
[servers.alpha]
17-
ip = "10.0.0.1"
17+
ip = "127.0.0.1"
1818
dc = "eqdc10"
1919

2020
[servers.beta]
21-
ip = "10.0.0.2"
21+
ip = "127.0.0.2"
2222
dc = "eqdc10"

trpc/naming/common/util/loadbalance/weighted_round_robin/weighted_round_robin_load_balancer_test.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@ TEST_F(SWRoundRobinLoadBalanceTest, SelectWithWeights) {
5353
// Initialize endpoints with different weights
5454
std::vector<TrpcEndpointInfo> endpoints_info;
5555
TrpcEndpointInfo endpoint1;
56-
endpoint1.host = "192.168.1.1";
56+
endpoint1.host = "127.0.0.1";
5757
endpoint1.port = 10000;
5858
endpoint1.weight = 10;
5959
endpoints_info.push_back(endpoint1);
6060

6161
TrpcEndpointInfo endpoint2;
62-
endpoint2.host = "192.168.1.2";
62+
endpoint2.host = "127.0.0.1";
6363
endpoint2.port = 20000;
6464
endpoint2.weight = 20;
6565
endpoints_info.push_back(endpoint2);
6666

6767
TrpcEndpointInfo endpoint3;
68-
endpoint2.host = "192.168.1.3";
68+
endpoint2.host = "127.0.0.1";
6969
endpoint2.port = 30000;
7070
endpoint2.weight = 30;
7171
endpoints_info.push_back(endpoint2);
@@ -80,8 +80,7 @@ TEST_F(SWRoundRobinLoadBalanceTest, SelectWithWeights) {
8080
select_info.name = "test_service";
8181
TrpcEndpointInfo selected_endpoint;
8282
test_polling_load_balance_->Select(&select_info, &selected_endpoint);
83-
EXPECT_TRUE(selected_endpoint.host == "192.168.1.1" || selected_endpoint.host == "192.168.1.2" ||
84-
selected_endpoint.host == "192.168.1.3");
83+
EXPECT_TRUE(selected_endpoint.host == "127.0.0.1");
8584
EXPECT_TRUE(selected_endpoint.port == 10000 || selected_endpoint.port == 20000 || selected_endpoint.port == 30000);
8685
EXPECT_TRUE(selected_endpoint.id != kInvalidEndpointId);
8786
count_map[selected_endpoint.port]++;

trpc/naming/direct/selector_direct_test.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ TEST(SelectorDirect, select_test) {
3737
TrpcEndpointInfo endpoint1, endpoint2;
3838
endpoint1.host = "127.0.0.1";
3939
endpoint1.port = 1001;
40-
endpoint2.host = "192.168.0.2";
40+
endpoint2.host = "127.0.0.1";
4141
endpoint2.port = 1002;
4242
endpoints_info.push_back(endpoint1);
4343
endpoints_info.push_back(endpoint2);
@@ -55,7 +55,7 @@ TEST(SelectorDirect, select_test) {
5555
EXPECT_TRUE(endpoint.id != kInvalidEndpointId);
5656

5757
ptr->Select(&select_info, &endpoint);
58-
EXPECT_TRUE(endpoint.host == "192.168.0.2");
58+
EXPECT_TRUE(endpoint.host == "127.0.0.1");
5959
EXPECT_TRUE(endpoint.port == 1002);
6060
EXPECT_TRUE(endpoint.id != kInvalidEndpointId);
6161

@@ -66,7 +66,7 @@ TEST(SelectorDirect, select_test) {
6666
auto trpc_codec = std::make_shared<trpc::TrpcClientCodec>();
6767
result.context = MakeRefCounted<ClientContext>(trpc_codec);
6868
result.context->SetCallerName("test_service");
69-
result.context->SetAddr("192.168.0.1", 1001);
69+
result.context->SetAddr("127.0.0.1", 1001);
7070
int ret = ptr->ReportInvokeResult(&result);
7171
EXPECT_EQ(0, ret);
7272

@@ -144,7 +144,7 @@ TEST(SelectorDirect, asyncselect_test) {
144144
TrpcEndpointInfo endpoint1, endpoint2;
145145
endpoint1.host = "127.0.0.1";
146146
endpoint1.port = 1001;
147-
endpoint2.host = "192.168.0.2";
147+
endpoint2.host = "127.0.0.1";
148148
endpoint2.port = 1002;
149149
endpoints_info.push_back(endpoint1);
150150
endpoints_info.push_back(endpoint2);
@@ -167,7 +167,7 @@ TEST(SelectorDirect, asyncselect_test) {
167167
ptr->AsyncSelect(&select_info).Then([](Future<trpc::TrpcEndpointInfo>&& fut) {
168168
EXPECT_TRUE(fut.IsReady());
169169
TrpcEndpointInfo endpoint = fut.GetValue0();
170-
EXPECT_TRUE(endpoint.host == "192.168.0.2");
170+
EXPECT_TRUE(endpoint.host == "127.0.0.1");
171171
EXPECT_TRUE(endpoint.port == 1002);
172172
return trpc::MakeReadyFuture<>();
173173
});
@@ -216,7 +216,7 @@ TEST(SelectorDirect, endpoint_unique_id_test) {
216216
TrpcEndpointInfo endpoint1, endpoint2;
217217
endpoint1.host = "127.0.0.1";
218218
endpoint1.port = 1001;
219-
endpoint2.host = "192.168.0.2";
219+
endpoint2.host = "127.0.0.1";
220220
endpoint2.port = 1002;
221221
endpoints_info.push_back(endpoint1);
222222
endpoints_info.push_back(endpoint2);

trpc/util/domain_util_test.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
namespace trpc::util::testing {
2323

2424
TEST(DomainUtilTest, GetAddrTypeTest) {
25-
EXPECT_EQ(trpc::util::GetAddrType("10.01.1.2"), trpc::util::AddrType::ADDR_NX);
2625
EXPECT_EQ(trpc::util::GetAddrType("0.1.1.2"), trpc::util::AddrType::ADDR_NX);
27-
EXPECT_EQ(trpc::util::GetAddrType("10.1.1.2"), trpc::util::AddrType::ADDR_IP);
2826
EXPECT_EQ(trpc::util::GetAddrType("127.0.0.1"), trpc::util::AddrType::ADDR_IP);
2927
EXPECT_EQ(trpc::util::GetAddrType("::1"), trpc::util::AddrType::ADDR_IP);
3028
EXPECT_EQ(trpc::util::GetAddrType("::"), trpc::util::AddrType::ADDR_IP);
@@ -65,10 +63,10 @@ TEST(DomainUtilTest, LocalhostTest) {
6563
TEST(DomainUtilTest, Ipv4NormalTest) {
6664
std::vector<std::string> addrs;
6765

68-
std::string domain = "10.28.44.240";
66+
std::string domain = "127.0.0.1";
6967
trpc::util::GetAddrFromDomain(domain, addrs);
7068
EXPECT_EQ(addrs.size(), 1);
71-
EXPECT_TRUE(addrs[0] == "10.28.44.240");
69+
EXPECT_TRUE(addrs[0] == "127.0.0.1");
7270
}
7371

7472
TEST(DomainUtilTest, Ipv4FailTest) {

trpc/util/net_util_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ TEST_P(NetUtilTestValid, test) {
3737
}
3838

3939
INSTANTIATE_TEST_SUITE_P(test, NetUtilTestValid,
40-
::testing::Values("0.0.0.0", "1.1.1.1", "59.56.54.51", "255.255.255.255"));
40+
::testing::Values("127.0.0.1", "127.0.0.2", "127.0.0.3", "127.0.0.4"));
4141

4242
class NetUtilTestInvalid : public ::testing::TestWithParam<std::string> {};
4343

0 commit comments

Comments
 (0)