11e934351Sopenharmony_ci/*
21e934351Sopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
31e934351Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
41e934351Sopenharmony_ci * you may not use this file except in compliance with the License.
51e934351Sopenharmony_ci * You may obtain a copy of the License at
61e934351Sopenharmony_ci *
71e934351Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
81e934351Sopenharmony_ci *
91e934351Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
101e934351Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
111e934351Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
121e934351Sopenharmony_ci * See the License for the specific language governing permissions and
131e934351Sopenharmony_ci * limitations under the License.
141e934351Sopenharmony_ci */
151e934351Sopenharmony_ci
161e934351Sopenharmony_ci#include "net_address.h"
171e934351Sopenharmony_ci#include "secure_data.h"
181e934351Sopenharmony_ci#include "socket_error.h"
191e934351Sopenharmony_ci#include "socket_state_base.h"
201e934351Sopenharmony_ci#include "tls.h"
211e934351Sopenharmony_ci#include "tls_certificate.h"
221e934351Sopenharmony_ci#include "tls_configuration.h"
231e934351Sopenharmony_ci#include "tls_key.h"
241e934351Sopenharmony_ci#include "tls_socket.h"
251e934351Sopenharmony_ci#include "tls_utils_test.h"
261e934351Sopenharmony_ci
271e934351Sopenharmony_cinamespace OHOS {
281e934351Sopenharmony_cinamespace NetStack {
291e934351Sopenharmony_cinamespace TlsSocket {
301e934351Sopenharmony_civoid MockOneWayNetAddress(Socket::NetAddress &address)
311e934351Sopenharmony_ci{
321e934351Sopenharmony_ci    address.SetAddress(TlsUtilsTest::GetIp(TlsUtilsTest::ChangeToFile(IP_ADDRESS)));
331e934351Sopenharmony_ci    address.SetPort(std::atoi(TlsUtilsTest::ChangeToFile(PORT).c_str()));
341e934351Sopenharmony_ci    address.SetFamilyBySaFamily(AF_INET);
351e934351Sopenharmony_ci}
361e934351Sopenharmony_ci
371e934351Sopenharmony_civoid MockOneWayParamOptions(Socket::NetAddress &address, TLSSecureOptions &secureOption, TLSConnectOptions &options)
381e934351Sopenharmony_ci{
391e934351Sopenharmony_ci    secureOption.SetKey(SecureData(TlsUtilsTest::ChangeToFile(PRIVATE_KEY_PEM)));
401e934351Sopenharmony_ci    secureOption.SetCert(TlsUtilsTest::ChangeToFile(CLIENT_CRT));
411e934351Sopenharmony_ci
421e934351Sopenharmony_ci    MockOneWayNetAddress(address);
431e934351Sopenharmony_ci    options.SetTlsSecureOptions(secureOption);
441e934351Sopenharmony_ci    options.SetNetAddress(address);
451e934351Sopenharmony_ci}
461e934351Sopenharmony_ci
471e934351Sopenharmony_civoid SetOneWayHwTestShortParam(TLSSocket &server)
481e934351Sopenharmony_ci{
491e934351Sopenharmony_ci    TLSSecureOptions secureOption;
501e934351Sopenharmony_ci    Socket::NetAddress address;
511e934351Sopenharmony_ci    TLSConnectOptions options;
521e934351Sopenharmony_ci    std::vector<std::string> caVec = {TlsUtilsTest::ChangeToFile(CA_DER)};
531e934351Sopenharmony_ci    secureOption.SetCaChain(caVec);
541e934351Sopenharmony_ci    MockOneWayParamOptions(address, secureOption, options);
551e934351Sopenharmony_ci
561e934351Sopenharmony_ci    server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
571e934351Sopenharmony_ci    server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
581e934351Sopenharmony_ci}
591e934351Sopenharmony_ci
601e934351Sopenharmony_civoid SetOneWayHwTestLongParam(TLSSocket &server)
611e934351Sopenharmony_ci{
621e934351Sopenharmony_ci    Socket::NetAddress address;
631e934351Sopenharmony_ci    TLSSecureOptions secureOption;
641e934351Sopenharmony_ci
651e934351Sopenharmony_ci    std::vector<std::string> caVec = {TlsUtilsTest::ChangeToFile(CA_DER)};
661e934351Sopenharmony_ci    secureOption.SetCaChain(caVec);
671e934351Sopenharmony_ci    secureOption.SetCipherSuite("AES256-SHA256");
681e934351Sopenharmony_ci    std::string protocolV13 = "TLSv1.3";
691e934351Sopenharmony_ci    std::vector<std::string> protocolVec = {protocolV13};
701e934351Sopenharmony_ci    secureOption.SetProtocolChain(protocolVec);
711e934351Sopenharmony_ci    TLSConnectOptions options;
721e934351Sopenharmony_ci    MockOneWayParamOptions(address, secureOption, options);
731e934351Sopenharmony_ci    server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
741e934351Sopenharmony_ci    server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
751e934351Sopenharmony_ci}
761e934351Sopenharmony_ci
771e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, bindInterface, testing::ext::TestSize.Level2)
781e934351Sopenharmony_ci{
791e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaFileExistence("bindInterface")) {
801e934351Sopenharmony_ci        return;
811e934351Sopenharmony_ci    }
821e934351Sopenharmony_ci
831e934351Sopenharmony_ci    TLSSocket oneWayService;
841e934351Sopenharmony_ci    Socket::NetAddress address;
851e934351Sopenharmony_ci    MockOneWayNetAddress(address);
861e934351Sopenharmony_ci
871e934351Sopenharmony_ci    oneWayService.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
881e934351Sopenharmony_ci}
891e934351Sopenharmony_ci
901e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, connectInterface, testing::ext::TestSize.Level2)
911e934351Sopenharmony_ci{
921e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaFileExistence("connectInterface")) {
931e934351Sopenharmony_ci        return;
941e934351Sopenharmony_ci    }
951e934351Sopenharmony_ci
961e934351Sopenharmony_ci    TLSSocket oneWayService;
971e934351Sopenharmony_ci    SetOneWayHwTestShortParam(oneWayService);
981e934351Sopenharmony_ci
991e934351Sopenharmony_ci    const std::string data = "how do you do? this is connectInterface";
1001e934351Sopenharmony_ci    Socket::TCPSendOptions tcpSendOptions;
1011e934351Sopenharmony_ci    tcpSendOptions.SetData(data);
1021e934351Sopenharmony_ci    oneWayService.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1031e934351Sopenharmony_ci    sleep(2);
1041e934351Sopenharmony_ci
1051e934351Sopenharmony_ci    (void)oneWayService.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1061e934351Sopenharmony_ci    sleep(2);
1071e934351Sopenharmony_ci}
1081e934351Sopenharmony_ci
1091e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, closeInterface, testing::ext::TestSize.Level2)
1101e934351Sopenharmony_ci{
1111e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaFileExistence("closeInterface")) {
1121e934351Sopenharmony_ci        return;
1131e934351Sopenharmony_ci    }
1141e934351Sopenharmony_ci
1151e934351Sopenharmony_ci    TLSSocket oneWayService;
1161e934351Sopenharmony_ci    SetOneWayHwTestShortParam(oneWayService);
1171e934351Sopenharmony_ci
1181e934351Sopenharmony_ci    const std::string data = "how do you do? this is closeInterface";
1191e934351Sopenharmony_ci    Socket::TCPSendOptions tcpSendOptions;
1201e934351Sopenharmony_ci    tcpSendOptions.SetData(data);
1211e934351Sopenharmony_ci
1221e934351Sopenharmony_ci    oneWayService.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1231e934351Sopenharmony_ci    sleep(2);
1241e934351Sopenharmony_ci
1251e934351Sopenharmony_ci    (void)oneWayService.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1261e934351Sopenharmony_ci}
1271e934351Sopenharmony_ci
1281e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, sendInterface, testing::ext::TestSize.Level2)
1291e934351Sopenharmony_ci{
1301e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaFileExistence("sendInterface")) {
1311e934351Sopenharmony_ci        return;
1321e934351Sopenharmony_ci    }
1331e934351Sopenharmony_ci
1341e934351Sopenharmony_ci    TLSSocket oneWayService;
1351e934351Sopenharmony_ci    SetOneWayHwTestShortParam(oneWayService);
1361e934351Sopenharmony_ci
1371e934351Sopenharmony_ci    const std::string data = "how do you do? this is sendInterface";
1381e934351Sopenharmony_ci    Socket::TCPSendOptions tcpSendOptions;
1391e934351Sopenharmony_ci    tcpSendOptions.SetData(data);
1401e934351Sopenharmony_ci
1411e934351Sopenharmony_ci    oneWayService.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1421e934351Sopenharmony_ci    sleep(2);
1431e934351Sopenharmony_ci
1441e934351Sopenharmony_ci    (void)oneWayService.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1451e934351Sopenharmony_ci}
1461e934351Sopenharmony_ci
1471e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, getRemoteAddressInterface, testing::ext::TestSize.Level2)
1481e934351Sopenharmony_ci{
1491e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaFileExistence("getRemoteAddressInterface")) {
1501e934351Sopenharmony_ci        return;
1511e934351Sopenharmony_ci    }
1521e934351Sopenharmony_ci
1531e934351Sopenharmony_ci    TLSSocket oneWayService;
1541e934351Sopenharmony_ci    TLSConnectOptions options;
1551e934351Sopenharmony_ci    TLSSecureOptions secureOption;
1561e934351Sopenharmony_ci    Socket::NetAddress address;
1571e934351Sopenharmony_ci
1581e934351Sopenharmony_ci    std::vector<std::string> caVec = {TlsUtilsTest::ChangeToFile(CA_DER)};
1591e934351Sopenharmony_ci    secureOption.SetCaChain(caVec);
1601e934351Sopenharmony_ci    MockOneWayParamOptions(address, secureOption, options);
1611e934351Sopenharmony_ci
1621e934351Sopenharmony_ci    oneWayService.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1631e934351Sopenharmony_ci    oneWayService.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1641e934351Sopenharmony_ci
1651e934351Sopenharmony_ci    Socket::NetAddress netAddress;
1661e934351Sopenharmony_ci    oneWayService.GetRemoteAddress([&netAddress](int32_t errCode, const Socket::NetAddress &address) {
1671e934351Sopenharmony_ci        EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS);
1681e934351Sopenharmony_ci        netAddress.SetAddress(address.GetAddress());
1691e934351Sopenharmony_ci        netAddress.SetPort(address.GetPort());
1701e934351Sopenharmony_ci        netAddress.SetFamilyBySaFamily(address.GetSaFamily());
1711e934351Sopenharmony_ci    });
1721e934351Sopenharmony_ci    EXPECT_STREQ(netAddress.GetAddress().c_str(), TlsUtilsTest::GetIp(TlsUtilsTest::ChangeToFile(IP_ADDRESS)).c_str());
1731e934351Sopenharmony_ci    EXPECT_EQ(address.GetPort(), std::atoi(TlsUtilsTest::ChangeToFile(PORT).c_str()));
1741e934351Sopenharmony_ci    EXPECT_EQ(netAddress.GetSaFamily(), AF_INET);
1751e934351Sopenharmony_ci
1761e934351Sopenharmony_ci    const std::string data = "how do you do? this is getRemoteAddressInterface";
1771e934351Sopenharmony_ci    Socket::TCPSendOptions tcpSendOptions;
1781e934351Sopenharmony_ci    tcpSendOptions.SetData(data);
1791e934351Sopenharmony_ci
1801e934351Sopenharmony_ci    oneWayService.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1811e934351Sopenharmony_ci
1821e934351Sopenharmony_ci    (void)oneWayService.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1831e934351Sopenharmony_ci}
1841e934351Sopenharmony_ci
1851e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, getStateInterface, testing::ext::TestSize.Level2)
1861e934351Sopenharmony_ci{
1871e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaFileExistence("getRemoteAddressInterface")) {
1881e934351Sopenharmony_ci        return;
1891e934351Sopenharmony_ci    }
1901e934351Sopenharmony_ci
1911e934351Sopenharmony_ci    TLSSocket oneWayService;
1921e934351Sopenharmony_ci    SetOneWayHwTestShortParam(oneWayService);
1931e934351Sopenharmony_ci
1941e934351Sopenharmony_ci    Socket::SocketStateBase TlsSocketstate;
1951e934351Sopenharmony_ci    oneWayService.GetState([&TlsSocketstate](int32_t errCode, const Socket::SocketStateBase &state) {
1961e934351Sopenharmony_ci        EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS);
1971e934351Sopenharmony_ci        TlsSocketstate = state;
1981e934351Sopenharmony_ci    });
1991e934351Sopenharmony_ci    std::cout << "TlsSocketTest TlsSocketstate.IsClose(): " << TlsSocketstate.IsClose() << std::endl;
2001e934351Sopenharmony_ci    EXPECT_TRUE(TlsSocketstate.IsBound());
2011e934351Sopenharmony_ci    EXPECT_TRUE(!TlsSocketstate.IsClose());
2021e934351Sopenharmony_ci    EXPECT_TRUE(TlsSocketstate.IsConnected());
2031e934351Sopenharmony_ci
2041e934351Sopenharmony_ci    const std::string tlsSocketTestData = "how do you do? this is getStateInterface";
2051e934351Sopenharmony_ci    Socket::TCPSendOptions tcpSendOptions;
2061e934351Sopenharmony_ci    tcpSendOptions.SetData(tlsSocketTestData);
2071e934351Sopenharmony_ci    oneWayService.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
2081e934351Sopenharmony_ci
2091e934351Sopenharmony_ci    sleep(2);
2101e934351Sopenharmony_ci
2111e934351Sopenharmony_ci    (void)oneWayService.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
2121e934351Sopenharmony_ci}
2131e934351Sopenharmony_ci
2141e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, getRemoteCertificateInterface, testing::ext::TestSize.Level2)
2151e934351Sopenharmony_ci{
2161e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaFileExistence("getRemoteCertificateInterface")) {
2171e934351Sopenharmony_ci        return;
2181e934351Sopenharmony_ci    }
2191e934351Sopenharmony_ci    TLSSocket oneWayService;
2201e934351Sopenharmony_ci    SetOneWayHwTestShortParam(oneWayService);
2211e934351Sopenharmony_ci
2221e934351Sopenharmony_ci    const std::string data = "how do you do? This is UT test getRemoteCertificateInterface";
2231e934351Sopenharmony_ci    Socket::TCPSendOptions tcpSendOptions;
2241e934351Sopenharmony_ci    tcpSendOptions.SetData(data);
2251e934351Sopenharmony_ci
2261e934351Sopenharmony_ci    oneWayService.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
2271e934351Sopenharmony_ci
2281e934351Sopenharmony_ci    oneWayService.GetRemoteCertificate(
2291e934351Sopenharmony_ci        [](int32_t errCode, const X509CertRawData &cert) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
2301e934351Sopenharmony_ci
2311e934351Sopenharmony_ci    sleep(2);
2321e934351Sopenharmony_ci    (void)oneWayService.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
2331e934351Sopenharmony_ci}
2341e934351Sopenharmony_ci
2351e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, protocolInterface, testing::ext::TestSize.Level2)
2361e934351Sopenharmony_ci{
2371e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaFileExistence("protocolInterface")) {
2381e934351Sopenharmony_ci        return;
2391e934351Sopenharmony_ci    }
2401e934351Sopenharmony_ci    TLSSocket oneWayService;
2411e934351Sopenharmony_ci    SetOneWayHwTestLongParam(oneWayService);
2421e934351Sopenharmony_ci
2431e934351Sopenharmony_ci    const std::string data = "how do you do? this is protocolInterface";
2441e934351Sopenharmony_ci    Socket::TCPSendOptions tcpSendOptions;
2451e934351Sopenharmony_ci    tcpSendOptions.SetData(data);
2461e934351Sopenharmony_ci
2471e934351Sopenharmony_ci    oneWayService.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
2481e934351Sopenharmony_ci    std::string protocolVal;
2491e934351Sopenharmony_ci    oneWayService.GetProtocol([&protocolVal](int32_t errCode, const std::string &protocol) {
2501e934351Sopenharmony_ci        EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS);
2511e934351Sopenharmony_ci        protocolVal = protocol;
2521e934351Sopenharmony_ci    });
2531e934351Sopenharmony_ci    EXPECT_STREQ(protocolVal.c_str(), "TLSv1.3");
2541e934351Sopenharmony_ci
2551e934351Sopenharmony_ci    Socket::SocketStateBase stateBase;
2561e934351Sopenharmony_ci    oneWayService.GetState([&stateBase](int32_t errCode, Socket::SocketStateBase state) {
2571e934351Sopenharmony_ci        if (errCode == TLSSOCKET_SUCCESS) {
2581e934351Sopenharmony_ci            EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS);
2591e934351Sopenharmony_ci            stateBase.SetIsBound(state.IsBound());
2601e934351Sopenharmony_ci            stateBase.SetIsClose(state.IsClose());
2611e934351Sopenharmony_ci            stateBase.SetIsConnected(state.IsConnected());
2621e934351Sopenharmony_ci        }
2631e934351Sopenharmony_ci    });
2641e934351Sopenharmony_ci    EXPECT_TRUE(stateBase.IsConnected());
2651e934351Sopenharmony_ci    sleep(2);
2661e934351Sopenharmony_ci
2671e934351Sopenharmony_ci    (void)oneWayService.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
2681e934351Sopenharmony_ci}
2691e934351Sopenharmony_ci
2701e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, getCipherSuiteInterface, testing::ext::TestSize.Level2)
2711e934351Sopenharmony_ci{
2721e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaFileExistence("getCipherSuiteInterface")) {
2731e934351Sopenharmony_ci        return;
2741e934351Sopenharmony_ci    }
2751e934351Sopenharmony_ci    TLSSocket oneWayService;
2761e934351Sopenharmony_ci    SetOneWayHwTestLongParam(oneWayService);
2771e934351Sopenharmony_ci
2781e934351Sopenharmony_ci    bool flag = false;
2791e934351Sopenharmony_ci    const std::string data = "how do you do? This is getCipherSuiteInterface";
2801e934351Sopenharmony_ci    Socket::TCPSendOptions tcpSendOptions;
2811e934351Sopenharmony_ci    tcpSendOptions.SetData(data);
2821e934351Sopenharmony_ci    oneWayService.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
2831e934351Sopenharmony_ci
2841e934351Sopenharmony_ci    std::vector<std::string> testSuite;
2851e934351Sopenharmony_ci    oneWayService.GetCipherSuite([&testSuite](int32_t errCode, const std::vector<std::string> &suite) {
2861e934351Sopenharmony_ci        if (errCode == TLSSOCKET_SUCCESS) {
2871e934351Sopenharmony_ci            testSuite = suite;
2881e934351Sopenharmony_ci        }
2891e934351Sopenharmony_ci    });
2901e934351Sopenharmony_ci
2911e934351Sopenharmony_ci    for (auto const &iter : testSuite) {
2921e934351Sopenharmony_ci        if (iter == "AES256-SHA256") {
2931e934351Sopenharmony_ci            flag = true;
2941e934351Sopenharmony_ci        }
2951e934351Sopenharmony_ci    }
2961e934351Sopenharmony_ci
2971e934351Sopenharmony_ci    EXPECT_TRUE(flag);
2981e934351Sopenharmony_ci    sleep(2);
2991e934351Sopenharmony_ci
3001e934351Sopenharmony_ci    (void)oneWayService.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
3011e934351Sopenharmony_ci}
3021e934351Sopenharmony_ci
3031e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, onMessageDataInterface, testing::ext::TestSize.Level2)
3041e934351Sopenharmony_ci{
3051e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaFileExistence("tlsSocketOnMessageData")) {
3061e934351Sopenharmony_ci        return;
3071e934351Sopenharmony_ci    }
3081e934351Sopenharmony_ci    std::string getData = "server->client";
3091e934351Sopenharmony_ci    TLSSocket oneWayService;
3101e934351Sopenharmony_ci    SetOneWayHwTestLongParam(oneWayService);
3111e934351Sopenharmony_ci
3121e934351Sopenharmony_ci    oneWayService.OnMessage([&getData](const std::string &data, const Socket::SocketRemoteInfo &remoteInfo) {
3131e934351Sopenharmony_ci        EXPECT_TRUE(data == getData);
3141e934351Sopenharmony_ci    });
3151e934351Sopenharmony_ci
3161e934351Sopenharmony_ci    const std::string data = "how do you do? this is tlsSocketOnMessageData";
3171e934351Sopenharmony_ci    Socket::TCPSendOptions tcpSendOptions;
3181e934351Sopenharmony_ci    tcpSendOptions.SetData(data);
3191e934351Sopenharmony_ci    oneWayService.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
3201e934351Sopenharmony_ci
3211e934351Sopenharmony_ci    sleep(2);
3221e934351Sopenharmony_ci    (void)oneWayService.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
3231e934351Sopenharmony_ci}
3241e934351Sopenharmony_ci} // namespace TlsSocket
3251e934351Sopenharmony_ci} // namespace NetStack
3261e934351Sopenharmony_ci} // namespace OHOS
327