1 /*
2 * Copyright (c) 2023 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 "edm_ipc_interface_code.h"
19 #include "global_proxy_plugin.h"
20 #include "iplugin_manager.h"
21 #include "plugin_singleton.h"
22 #include "utils.h"
23
24 using namespace testing::ext;
25 using namespace testing;
26
27 namespace OHOS {
28 namespace EDM {
29 namespace TEST {
30
31
32 class GlobalProxyPluginTest : public testing::Test {
33 protected:
34 static void SetUpTestSuite(void);
35
36 static void TearDownTestSuite(void);
37 };
38
SetUpTestSuite(void)39 void GlobalProxyPluginTest::SetUpTestSuite(void)
40 {
41 Utils::SetEdmInitialEnv();
42 }
43
TearDownTestSuite(void)44 void GlobalProxyPluginTest::TearDownTestSuite(void)
45 {
46 Utils::ResetTokenTypeAndUid();
47 ASSERT_TRUE(Utils::IsOriginalUTEnv());
48 std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
49 }
50
51 /**
52 * @tc.name: TestSetGlobalHttpProxyParamError
53 * @tc.desc: Test SetGlobalHttpProxy
54 * @tc.type: FUNC
55 */
56 HWTEST_F(GlobalProxyPluginTest, TestSetGlobalHttpProxyParamError, TestSize.Level1)
57 {
58 GlobalProxyPlugin plugin;
59 NetManagerStandard::HttpProxy httpProxy;
60 httpProxy.SetPort(9090);
61 httpProxy.SetHost("192.168.1.1");
62 std::list<std::string> list = {"192.168.2.2", "baidu.com"};
63 httpProxy.SetExclusionList(list);
64 ErrCode ret = plugin.OnSetPolicy(httpProxy);
65 ASSERT_TRUE(ret == ERR_OK);
66 }
67
68 /**
69 * @tc.name: TestSetGlobalHttpProxyAnyParam
70 * @tc.desc: Test SetGlobalHttpProxy
71 * @tc.type: FUNC
72 */
73 HWTEST_F(GlobalProxyPluginTest, TestSetGlobalHttpProxyAnyParam, TestSize.Level1)
74 {
75 GlobalProxyPlugin plugin;
76 NetManagerStandard::HttpProxy httpProxy;
77 httpProxy.SetPort(1234);
78 httpProxy.SetHost("any host");
79 std::list<std::string> list = {"any list", "any list2"};
80 httpProxy.SetExclusionList(list);
81 ErrCode ret = plugin.OnSetPolicy(httpProxy);
82 ASSERT_TRUE(ret == ERR_OK);
83 }
84
85 /**
86 * @tc.name: TestSetGlobalHttpProxyEmpty
87 * @tc.desc: Test SetGlobalHttpProxy
88 * @tc.type: FUNC
89 */
90 HWTEST_F(GlobalProxyPluginTest, TestSetGlobalHttpProxyEmpty, TestSize.Level1)
91 {
92 GlobalProxyPlugin plugin;
93 NetManagerStandard::HttpProxy httpProxy;
94 ErrCode ret = plugin.OnSetPolicy(httpProxy);
95 ASSERT_TRUE(ret == ERR_OK);
96 }
97
98 /**
99 * @tc.name: TestGetGlobalHttpProxy
100 * @tc.desc: Test GetGlobalHttpProxy
101 * @tc.type: FUNC
102 */
103 HWTEST_F(GlobalProxyPluginTest, TestGetGlobalHttpProxy, TestSize.Level1)
104 {
105 std::shared_ptr<IPlugin> plugin = GlobalProxyPlugin::GetPlugin();
106 MessageParcel data;
107 MessageParcel reply;
108 std::string policyStr;
109 ErrCode ret = plugin->OnGetPolicy(policyStr, data, reply, DEFAULT_USER_ID);
110 ASSERT_TRUE(ret == ERR_OK);
111 }
112 } // namespace TEST
113 } // namespace EDM
114 } // namespace OHOS