1 /*
2 * Copyright (c) 2024 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 <gtest/gtest.h>
17
18 #include "l2tpvpn_config.h"
19
20 namespace OHOS {
21 namespace NetManagerStandard {
22 namespace {
23 constexpr const char *TEST_VPNID = "vpnId_";
24 constexpr const char *TEST_VPN_NAME = "vpnName_";
25 constexpr const char *TEST_USER_NAME = "userName_";
26 constexpr const char *TEST_PASSWORD = "password_";
27 constexpr bool TEST_SAVE_LOGIN = false;
28 constexpr int32_t TEST_USERID = 0;
29 constexpr const char *TEST_FORWARD = "forwardingRoutes_";
30
31 constexpr const char *TEST_SHARED_KEY = "ipsecPreSharedKey_";
32 constexpr const char *TEST_IDENRIFIER = "ipsecIdentifier_";
33 constexpr const char *TEST_STRONG_SWAN_CONFIG = "strongswanConf_";
34 constexpr const char *TEST_CA_CERT_CONFIG = "ipsecCaCertConf_";
35 constexpr const char *TEST_PRIVATE_USER_CERT_CONFIG = "ipsecPrivateUserCertConf_";
36 constexpr const char *TEST_PUBLIC_USER_CERT_CONFIG = "ipsecPublicUserCertConf_";
37 constexpr const char *TEST_PRIVATE_SERVER_CERT_CONFIG = "ipsecPrivateServerCertConf_";
38 constexpr const char *TEST_PUBLIC_SERVER_CERT_CONFIG = "ipsecPublicServerCertConf_";
39 constexpr const char *TEST_CA_CERT_FILE_PATH = "ipsecCaCertFilePath_";
40 constexpr const char *TEST_PRIVATE_USER_CERT_FILE_PATH = "ipsecPrivateUserCertFilePath_";
41 constexpr const char *TEST_PUBLIC_USER_CERT_FILE_PATH = "ipsecPublicUserCertFilePath_";
42 constexpr const char *TEST_PRIVATE_SERVER_CERT_FILE_PATH = "ipsecPrivateServerCertFilePath_";
43 constexpr const char *TEST_PUBLIC_SERVER_CERT_FILE_PATH = "ipsecPublicServerCertFilePath_";
44 constexpr const char *TEST_IPSEC_CONFIG = "ipsecConf_";
45 constexpr const char *TEST_IPSEC_SECRETS = "ipsecSecrets_";
46 constexpr const char *TEST_OPTION_CLIENT = "optionsL2tpdClient_";
47 constexpr const char *TEST_XL2TPD_CONFIG = "xl2tpdConf_";
48 constexpr const char *TEST_L2TP_SHARED_KEY = "l2tpSharedKey_";
49
GetL2tpVpnConfigData()50 L2tpVpnConfig GetL2tpVpnConfigData()
51 {
52 L2tpVpnConfig infoSequence;
53
54 infoSequence.vpnId_ = TEST_VPNID;
55 infoSequence.vpnName_ = TEST_VPN_NAME;
56 infoSequence.vpnType_ = VpnType::L2TP_IPSEC_PSK;
57 infoSequence.userName_ = TEST_USER_NAME;
58 infoSequence.password_ = TEST_PASSWORD;
59 infoSequence.saveLogin_ = TEST_SAVE_LOGIN;
60 infoSequence.userId_ = TEST_USERID;
61 infoSequence.forwardingRoutes_ = TEST_FORWARD;
62
63 infoSequence.ipsecPreSharedKey_ = TEST_SHARED_KEY;
64 infoSequence.ipsecIdentifier_ = TEST_IDENRIFIER;
65 infoSequence.strongswanConf_ = TEST_STRONG_SWAN_CONFIG;
66 infoSequence.ipsecCaCertConf_ = TEST_CA_CERT_CONFIG;
67 infoSequence.ipsecPrivateUserCertConf_ = TEST_PRIVATE_USER_CERT_CONFIG;
68 infoSequence.ipsecPublicUserCertConf_ = TEST_PUBLIC_USER_CERT_CONFIG;
69 infoSequence.ipsecPrivateServerCertConf_ = TEST_PRIVATE_SERVER_CERT_CONFIG;
70 infoSequence.ipsecPublicServerCertConf_ = TEST_PUBLIC_SERVER_CERT_CONFIG;
71 infoSequence.ipsecCaCertFilePath_ = TEST_CA_CERT_FILE_PATH;
72 infoSequence.ipsecPrivateUserCertFilePath_ = TEST_PRIVATE_USER_CERT_FILE_PATH;
73 infoSequence.ipsecPublicUserCertFilePath_ = TEST_PUBLIC_USER_CERT_FILE_PATH;
74 infoSequence.ipsecPrivateServerCertFilePath_ = TEST_PRIVATE_SERVER_CERT_FILE_PATH;
75 infoSequence.ipsecPublicServerCertFilePath_ = TEST_PUBLIC_SERVER_CERT_FILE_PATH;
76 infoSequence.ipsecConf_ = TEST_IPSEC_CONFIG;
77 infoSequence.ipsecSecrets_ = TEST_IPSEC_SECRETS;
78 infoSequence.optionsL2tpdClient_ = TEST_OPTION_CLIENT;
79 infoSequence.xl2tpdConf_ = TEST_XL2TPD_CONFIG;
80 infoSequence.l2tpSharedKey_ = TEST_L2TP_SHARED_KEY;
81 return infoSequence;
82 }
83 } // namespace
84
85 using namespace testing::ext;
86 class L2tpVpnConfigTest : public testing::Test {
87 public:
88 static void SetUpTestCase();
89 static void TearDownTestCase();
90 void SetUp();
91 void TearDown();
92 };
93
SetUpTestCase()94 void L2tpVpnConfigTest::SetUpTestCase() {}
95
TearDownTestCase()96 void L2tpVpnConfigTest::TearDownTestCase() {}
97
SetUp()98 void L2tpVpnConfigTest::SetUp() {}
99
TearDown()100 void L2tpVpnConfigTest::TearDown() {}
101
102 HWTEST_F(L2tpVpnConfigTest, MarshallingUnmarshallingTest001, TestSize.Level1)
103 {
104 Parcel parcel;
105 L2tpVpnConfig info = GetL2tpVpnConfigData();
106 EXPECT_TRUE(info.Marshalling(parcel));
107 int32_t type;
108 parcel.ReadInt32(type);
109 sptr<L2tpVpnConfig> result = L2tpVpnConfig::Unmarshalling(parcel);
110 ASSERT_TRUE(result != nullptr);
111 EXPECT_EQ(result->ipsecPreSharedKey_, info.ipsecPreSharedKey_);
112 EXPECT_EQ(result->ipsecIdentifier_, info.ipsecIdentifier_);
113 EXPECT_EQ(result->strongswanConf_, info.strongswanConf_);
114 EXPECT_EQ(result->ipsecCaCertConf_, info.ipsecCaCertConf_);
115 EXPECT_EQ(result->ipsecPrivateUserCertConf_, info.ipsecPrivateUserCertConf_);
116 EXPECT_EQ(result->ipsecPublicUserCertConf_, info.ipsecPublicUserCertConf_);
117 EXPECT_EQ(result->ipsecPrivateServerCertConf_, info.ipsecPrivateServerCertConf_);
118 EXPECT_EQ(result->ipsecPublicServerCertConf_, info.ipsecPublicServerCertConf_);
119 EXPECT_EQ(result->ipsecCaCertFilePath_, info.ipsecCaCertFilePath_);
120 EXPECT_EQ(result->ipsecPrivateUserCertFilePath_, info.ipsecPrivateUserCertFilePath_);
121 EXPECT_EQ(result->ipsecPublicUserCertFilePath_, info.ipsecPublicUserCertFilePath_);
122 EXPECT_EQ(result->ipsecPrivateServerCertFilePath_, info.ipsecPrivateServerCertFilePath_);
123 EXPECT_EQ(result->ipsecPublicServerCertFilePath_, info.ipsecPublicServerCertFilePath_);
124 EXPECT_EQ(result->ipsecConf_, info.ipsecConf_);
125 EXPECT_EQ(result->ipsecSecrets_, info.ipsecSecrets_);
126 EXPECT_EQ(result->optionsL2tpdClient_, info.optionsL2tpdClient_);
127 EXPECT_EQ(result->xl2tpdConf_, info.xl2tpdConf_);
128 EXPECT_EQ(result->l2tpSharedKey_, info.l2tpSharedKey_);
129 }
130 }
131 }
132