1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <fstream>
17 #include <gtest/gtest.h>
18 #include <iostream>
19 #include <openssl/rsa.h>
20 #include <openssl/ssl.h>
21 #include <sstream>
22 #include <string>
23 #include <string_view>
24 #include <unistd.h>
25 #include <vector>
26
27 #include "net_address.h"
28 #include "secure_data.h"
29 #include "socket_error.h"
30 #include "socket_state_base.h"
31 #include "tls.h"
32 #include "tls_certificate.h"
33 #include "tls_configuration.h"
34 #include "tls_key.h"
35 #include "tls_socket.h"
36
37 namespace OHOS {
38 namespace NetStack {
39 namespace {
40 const std::string_view PRIVATE_KEY_PEM_CHAIN = "/data/ClientCertChain/privekey.pem.unsecure";
41 const std::string_view CA_PATH_CHAIN = "/data/ClientCertChain/cacert.crt";
42 const std::string_view MID_CA_PATH_CHAIN = "/data/ClientCertChain/caMidcert.crt";
43 const std::string_view CLIENT_CRT_CHAIN = "/data/ClientCertChain/secondServer.crt";
44 const std::string_view IP_ADDRESS = "/data/Ip/address.txt";
45 const std::string_view PORT = "/data/Ip/port.txt";
46
CheckCaFileExistence(const char * function)47 inline bool CheckCaFileExistence(const char *function)
48 {
49 if (access(CA_PATH_CHAIN.data(), 0)) {
50 std::cout << "CA file does not exist! (" << function << ")";
51 return false;
52 }
53 return true;
54 }
55
ReadFileContent(const std::string_view fileName)56 std::string ReadFileContent(const std::string_view fileName)
57 {
58 std::ifstream file;
59 file.open(fileName);
60 std::stringstream ss;
61 ss << file.rdbuf();
62 std::string infos = ss.str();
63 file.close();
64 return infos;
65 }
66
GetIp(std::string ip)67 std::string GetIp(std::string ip)
68 {
69 return ip.substr(0, ip.length() - 1);
70 }
71 } // namespace
72
73 class TlsSocketTest : public testing::Test {
74 public:
SetUpTestCase()75 static void SetUpTestCase() {}
76
TearDownTestCase()77 static void TearDownTestCase() {}
78
SetUp()79 virtual void SetUp() {}
80
TearDown()81 virtual void TearDown() {}
82 };
83
84 HWTEST_F(TlsSocketTest, bindInterface, testing::ext::TestSize.Level2)
85 {
86 if (!CheckCaFileExistence("bindInterface")) {
87 return;
88 }
89
90 TLSSocket server;
91 NetAddress address;
92
93 address.SetAddress(GetIp(ReadFileContent(IP_ADDRESS)));
94 address.SetPort(std::atoi(ReadFileContent(PORT).c_str()));
95 address.SetFamilyBySaFamily(AF_INET);
96
__anonf67415490202(int32_t errCode) 97 server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
98 }
99
100 HWTEST_F(TlsSocketTest, connectInterface, testing::ext::TestSize.Level2)
101 {
102 if (!CheckCaFileExistence("connectInterface")) {
103 return;
104 }
105 TLSConnectOptions options;
106 TLSSocket server;
107
108 TLSSecureOptions secureOption;
109 NetAddress address;
110
111 address.SetAddress(GetIp(ReadFileContent(IP_ADDRESS)));
112 address.SetPort(std::atoi(ReadFileContent(PORT).c_str()));
113 address.SetFamilyBySaFamily(AF_INET);
114
115 secureOption.SetKey(SecureData(ReadFileContent(PRIVATE_KEY_PEM_CHAIN)));
116 std::vector<std::string> caVec = {ReadFileContent(CA_PATH_CHAIN), ReadFileContent(MID_CA_PATH_CHAIN)};
117 secureOption.SetCaChain(caVec);
118 secureOption.SetCert(ReadFileContent(CLIENT_CRT_CHAIN));
119
120 options.SetNetAddress(address);
121 options.SetTlsSecureOptions(secureOption);
122
__anonf67415490302(int32_t errCode) 123 server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
124
__anonf67415490402(int32_t errCode) 125 server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
126
127 const std::string data = "how do you do? this is connectInterface";
128 TCPSendOptions tcpSendOptions;
129 tcpSendOptions.SetData(data);
__anonf67415490502(int32_t errCode) 130 server.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
131 sleep(2);
132
__anonf67415490602(int32_t errCode) 133 (void)server.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
134 sleep(2);
135 }
136
137 HWTEST_F(TlsSocketTest, closeInterface, testing::ext::TestSize.Level2)
138 {
139 if (!CheckCaFileExistence("closeInterface")) {
140 return;
141 }
142
143 TLSConnectOptions options;
144 TLSSocket server;
145
146 TLSSecureOptions secureOption;
147 NetAddress address;
148
149 address.SetAddress(GetIp(ReadFileContent(IP_ADDRESS)));
150 address.SetPort(std::atoi(ReadFileContent(PORT).c_str()));
151 address.SetFamilyBySaFamily(AF_INET);
152
153 secureOption.SetKey(SecureData(ReadFileContent(PRIVATE_KEY_PEM_CHAIN)));
154 std::vector<std::string> caVec = {ReadFileContent(CA_PATH_CHAIN), ReadFileContent(MID_CA_PATH_CHAIN)};
155 secureOption.SetCaChain(caVec);
156 secureOption.SetCert(ReadFileContent(CLIENT_CRT_CHAIN));
157
158 options.SetNetAddress(address);
159 options.SetTlsSecureOptions(secureOption);
160
__anonf67415490702(int32_t errCode) 161 server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
162
__anonf67415490802(int32_t errCode) 163 server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
164
165 const std::string data = "how do you do? this is closeInterface";
166 TCPSendOptions tcpSendOptions;
167 tcpSendOptions.SetData(data);
168
__anonf67415490902(int32_t errCode) 169 server.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
170 sleep(2);
171
__anonf67415490a02(int32_t errCode) 172 (void)server.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
173 }
174
175 HWTEST_F(TlsSocketTest, sendInterface, testing::ext::TestSize.Level2)
176 {
177 if (!CheckCaFileExistence("sendInterface")) {
178 return;
179 }
180 TLSConnectOptions options;
181 TLSSocket server;
182
183 TLSSecureOptions secureOption;
184 NetAddress address;
185
186 address.SetAddress(GetIp(ReadFileContent(IP_ADDRESS)));
187 address.SetPort(std::atoi(ReadFileContent(PORT).c_str()));
188 address.SetFamilyBySaFamily(AF_INET);
189
190 secureOption.SetKey(SecureData(ReadFileContent(PRIVATE_KEY_PEM_CHAIN)));
191 std::vector<std::string> caVec = {ReadFileContent(CA_PATH_CHAIN), ReadFileContent(MID_CA_PATH_CHAIN)};
192 secureOption.SetCaChain(caVec);
193 secureOption.SetCert(ReadFileContent(CLIENT_CRT_CHAIN));
194
195 options.SetNetAddress(address);
196 options.SetTlsSecureOptions(secureOption);
197
__anonf67415490b02(int32_t errCode) 198 server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
199
__anonf67415490c02(int32_t errCode) 200 server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
201
202 const std::string data = "how do you do? this is sendInterface";
203 TCPSendOptions tcpSendOptions;
204 tcpSendOptions.SetData(data);
205
__anonf67415490d02(int32_t errCode) 206 server.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
207 sleep(2);
208
__anonf67415490e02(int32_t errCode) 209 (void)server.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
210 }
211
212 HWTEST_F(TlsSocketTest, getRemoteAddressInterface, testing::ext::TestSize.Level2)
213 {
214 if (!CheckCaFileExistence("getRemoteAddressInterface")) {
215 return;
216 }
217
218 TLSConnectOptions options;
219 TLSSocket server;
220 TLSSecureOptions secureOption;
221 NetAddress address;
222
223 address.SetAddress(GetIp(ReadFileContent(IP_ADDRESS)));
224 address.SetPort(std::atoi(ReadFileContent(PORT).c_str()));
225 address.SetFamilyBySaFamily(AF_INET);
226
227 secureOption.SetKey(SecureData(ReadFileContent(PRIVATE_KEY_PEM_CHAIN)));
228 std::vector<std::string> caVec = {ReadFileContent(CA_PATH_CHAIN), ReadFileContent(MID_CA_PATH_CHAIN)};
229 secureOption.SetCaChain(caVec);
230 secureOption.SetCert(ReadFileContent(CLIENT_CRT_CHAIN));
231
232 options.SetNetAddress(address);
233 options.SetTlsSecureOptions(secureOption);
234
__anonf67415490f02(int32_t errCode) 235 server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
236
__anonf67415491002(int32_t errCode) 237 server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
238
239 NetAddress netAddress;
__anonf67415491102(int32_t errCode, const NetAddress &address) 240 server.GetRemoteAddress([&netAddress](int32_t errCode, const NetAddress &address) {
241 EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS);
242 netAddress.SetAddress(address.GetAddress());
243 netAddress.SetPort(address.GetPort());
244 netAddress.SetFamilyBySaFamily(address.GetSaFamily());
245 });
246 EXPECT_STREQ(netAddress.GetAddress().c_str(), GetIp(ReadFileContent(IP_ADDRESS)).c_str());
247 EXPECT_EQ(address.GetPort(), std::atoi(ReadFileContent(PORT).c_str()));
248 EXPECT_EQ(netAddress.GetSaFamily(), AF_INET);
249
250 const std::string data = "how do you do? this is getRemoteAddressInterface";
251 TCPSendOptions tcpSendOptions;
252 tcpSendOptions.SetData(data);
253
__anonf67415491202(int32_t errCode) 254 server.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
255 sleep(2);
256
__anonf67415491302(int32_t errCode) 257 (void)server.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
258 }
259
260 HWTEST_F(TlsSocketTest, getStateInterface, testing::ext::TestSize.Level2)
261 {
262 if (!CheckCaFileExistence("getRemoteAddressInterface")) {
263 return;
264 }
265
266 TLSConnectOptions options;
267 TLSSocket server;
268 TLSSecureOptions secureOption;
269 NetAddress address;
270
271 address.SetAddress(GetIp(ReadFileContent(IP_ADDRESS)));
272 address.SetPort(std::atoi(ReadFileContent(PORT).c_str()));
273 address.SetFamilyBySaFamily(AF_INET);
274
275 secureOption.SetKey(SecureData(ReadFileContent(PRIVATE_KEY_PEM_CHAIN)));
276 std::vector<std::string> caVec = {ReadFileContent(CA_PATH_CHAIN), ReadFileContent(MID_CA_PATH_CHAIN)};
277 secureOption.SetCaChain(caVec);
278 secureOption.SetCert(ReadFileContent(CLIENT_CRT_CHAIN));
279
280 options.SetNetAddress(address);
281 options.SetTlsSecureOptions(secureOption);
282
__anonf67415491402(int32_t errCode) 283 server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
__anonf67415491502(int32_t errCode) 284 server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
285
286 SocketStateBase TlsSocketstate;
__anonf67415491602(int32_t errCode, const SocketStateBase &state) 287 server.GetState([&TlsSocketstate](int32_t errCode, const SocketStateBase &state) {
288 EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS);
289 TlsSocketstate = state;
290 });
291 std::cout << "TlsSocketstate.IsClose(): " << TlsSocketstate.IsClose() << std::endl;
292 EXPECT_TRUE(TlsSocketstate.IsBound());
293 EXPECT_TRUE(!TlsSocketstate.IsClose());
294 EXPECT_TRUE(TlsSocketstate.IsConnected());
295
296 const std::string data = "how do you do? this is getStateInterface";
297 TCPSendOptions tcpSendOptions;
298 tcpSendOptions.SetData(data);
__anonf67415491702(int32_t errCode) 299 server.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
300
301 sleep(2);
302
__anonf67415491802(int32_t errCode) 303 (void)server.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
304 }
305
306 HWTEST_F(TlsSocketTest, getRemoteCertificateInterface, testing::ext::TestSize.Level2)
307 {
308 if (!CheckCaFileExistence("getRemoteCertificateInterface")) {
309 return;
310 }
311 TLSSocket server;
312 TLSConnectOptions options;
313 TCPSendOptions tcpSendOptions;
314 TLSSecureOptions secureOption;
315 NetAddress address;
316 const std::string data = "how do you do? This is UT test getRemoteCertificateInterface";
317
318 address.SetAddress(GetIp(ReadFileContent(IP_ADDRESS)));
319 address.SetPort(std::atoi(ReadFileContent(PORT).c_str()));
320 address.SetFamilyBySaFamily(AF_INET);
321
322 secureOption.SetKey(SecureData(ReadFileContent(PRIVATE_KEY_PEM_CHAIN)));
323 std::vector<std::string> caVec = {ReadFileContent(CA_PATH_CHAIN), ReadFileContent(MID_CA_PATH_CHAIN)};
324 secureOption.SetCaChain(caVec);
325 secureOption.SetCert(ReadFileContent(CLIENT_CRT_CHAIN));
326
327 options.SetNetAddress(address);
328 options.SetTlsSecureOptions(secureOption);
329
__anonf67415491902(int32_t errCode) 330 server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
331
__anonf67415491a02(int32_t errCode) 332 server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
333
334 tcpSendOptions.SetData(data);
335
__anonf67415491b02(int32_t errCode) 336 server.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
337
338 server.GetRemoteCertificate(
__anonf67415491c02(int32_t errCode, const X509CertRawData &cert) 339 [](int32_t errCode, const X509CertRawData &cert) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
340
341 sleep(2);
__anonf67415491d02(int32_t errCode) 342 (void)server.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
343 }
344
345 HWTEST_F(TlsSocketTest, protocolInterface, testing::ext::TestSize.Level2)
346 {
347 if (!CheckCaFileExistence("protocolInterface")) {
348 return;
349 }
350 TLSConnectOptions options;
351 TLSSocket server;
352 TLSSecureOptions secureOption;
353 NetAddress address;
354
355 address.SetAddress(GetIp(ReadFileContent(IP_ADDRESS)));
356 address.SetPort(std::atoi(ReadFileContent(PORT).c_str()));
357 address.SetFamilyBySaFamily(AF_INET);
358
359 secureOption.SetKey(SecureData(ReadFileContent(PRIVATE_KEY_PEM_CHAIN)));
360 std::vector<std::string> caVec = {ReadFileContent(CA_PATH_CHAIN), ReadFileContent(MID_CA_PATH_CHAIN)};
361 secureOption.SetCaChain(caVec);
362 secureOption.SetCert(ReadFileContent(CLIENT_CRT_CHAIN));
363 secureOption.SetCipherSuite("AES256-SHA256");
364 std::string protocolV13 = "TLSv1.3";
365 std::vector<std::string> protocolVec = {protocolV13};
366 secureOption.SetProtocolChain(protocolVec);
367
368 options.SetNetAddress(address);
369 options.SetTlsSecureOptions(secureOption);
370
__anonf67415491e02(int32_t errCode) 371 server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
372
__anonf67415491f02(int32_t errCode) 373 server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
374
375 const std::string data = "how do you do? this is protocolInterface";
376 TCPSendOptions tcpSendOptions;
377 tcpSendOptions.SetData(data);
378
__anonf67415492002(int32_t errCode) 379 server.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
380 std::string getProtocolVal;
__anonf67415492102(int32_t errCode, const std::string &protocol) 381 server.GetProtocol([&getProtocolVal](int32_t errCode, const std::string &protocol) {
382 EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS);
383 getProtocolVal = protocol;
384 });
385 EXPECT_STREQ(getProtocolVal.c_str(), "TLSv1.3");
386 sleep(2);
387
__anonf67415492202(int32_t errCode) 388 (void)server.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
389 }
390
391 HWTEST_F(TlsSocketTest, getCipherSuiteInterface, testing::ext::TestSize.Level2)
392 {
393 if (!CheckCaFileExistence("getCipherSuiteInterface")) {
394 return;
395 }
396
397 TLSConnectOptions options;
398 TLSSocket server;
399 TLSSecureOptions secureOption;
400 NetAddress address;
401
402 address.SetAddress(GetIp(ReadFileContent(IP_ADDRESS)));
403 address.SetPort(std::atoi(ReadFileContent(PORT).c_str()));
404 address.SetFamilyBySaFamily(AF_INET);
405
406 secureOption.SetKey(SecureData(ReadFileContent(PRIVATE_KEY_PEM_CHAIN)));
407 std::vector<std::string> caVec = {ReadFileContent(CA_PATH_CHAIN), ReadFileContent(MID_CA_PATH_CHAIN)};
408 secureOption.SetCaChain(caVec);
409 secureOption.SetCert(ReadFileContent(CLIENT_CRT_CHAIN));
410 secureOption.SetCipherSuite("AES256-SHA256");
411 std::string protocolV13 = "TLSv1.3";
412 std::vector<std::string> protocolVec = {protocolV13};
413 secureOption.SetProtocolChain(protocolVec);
414
415 options.SetNetAddress(address);
416 options.SetTlsSecureOptions(secureOption);
417
418 bool flag = false;
__anonf67415492302(int32_t errCode) 419 server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
__anonf67415492402(int32_t errCode) 420 server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
421
422 const std::string data = "how do you do? This is getCipherSuiteInterface";
423 TCPSendOptions tcpSendOptions;
424 tcpSendOptions.SetData(data);
__anonf67415492502(int32_t errCode) 425 server.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
426
427 std::vector<std::string> cipherSuite;
__anonf67415492602(int32_t errCode, const std::vector<std::string> &suite) 428 server.GetCipherSuite([&cipherSuite](int32_t errCode, const std::vector<std::string> &suite) {
429 EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS);
430 cipherSuite = suite;
431 });
432
433 for (auto const &iter : cipherSuite) {
434 if (iter == "AES256-SHA256") {
435 flag = true;
436 }
437 }
438
439 EXPECT_TRUE(flag);
440 sleep(2);
441
__anonf67415492702(int32_t errCode) 442 (void)server.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
443 }
444
445 HWTEST_F(TlsSocketTest, onMessageDataInterface, testing::ext::TestSize.Level2)
446 {
447 if (!CheckCaFileExistence("tlsSocketOnMessageData")) {
448 return;
449 }
450 std::string getData = "server->client";
451 TLSConnectOptions options;
452 TLSSocket server;
453 TLSSecureOptions secureOption;
454 NetAddress address;
455
456 address.SetAddress(GetIp(ReadFileContent(IP_ADDRESS)));
457 address.SetPort(std::atoi(ReadFileContent(PORT).c_str()));
458 address.SetFamilyBySaFamily(AF_INET);
459
460 secureOption.SetKey(SecureData(ReadFileContent(PRIVATE_KEY_PEM_CHAIN)));
461 std::vector<std::string> caVec = {ReadFileContent(CA_PATH_CHAIN), ReadFileContent(MID_CA_PATH_CHAIN)};
462 secureOption.SetCaChain(caVec);
463 secureOption.SetCert(ReadFileContent(CLIENT_CRT_CHAIN));
464 secureOption.SetCipherSuite("AES256-SHA256");
465 std::string protocolV13 = "TLSv1.3";
466 std::vector<std::string> protocolVec = {protocolV13};
467 secureOption.SetProtocolChain(protocolVec);
468
469 options.SetNetAddress(address);
470 options.SetTlsSecureOptions(secureOption);
471
__anonf67415492802(int32_t errCode) 472 server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
473
__anonf67415492902(int32_t errCode) 474 server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
__anonf67415492a02(const std::string &data, const SocketRemoteInfo &remoteInfo) 475 server.OnMessage([&getData](const std::string &data, const SocketRemoteInfo &remoteInfo) {
476 if (data == getData) {
477 EXPECT_TRUE(true);
478 } else {
479 EXPECT_TRUE(false);
480 }
481 });
482
483 const std::string data = "how do you do? this is tlsSocketOnMessageData";
484 TCPSendOptions tcpSendOptions;
485 tcpSendOptions.SetData(data);
__anonf67415492b02(int32_t errCode) 486 server.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
487
488 sleep(2);
__anonf67415492c02(int32_t errCode) 489 (void)server.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
490 }
491 } // namespace NetStack
492 } // namespace OHOS
493