• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     httpProxy.SetUserId(100);
65     ErrCode ret = plugin.OnSetPolicy(httpProxy);
66     ASSERT_TRUE(ret == ERR_OK);
67 }
68 
69 /**
70  * @tc.name: TestSetGlobalHttpProxyAnyParam
71  * @tc.desc: Test SetGlobalHttpProxy
72  * @tc.type: FUNC
73  */
74 HWTEST_F(GlobalProxyPluginTest, TestSetGlobalHttpProxyAnyParam, TestSize.Level1)
75 {
76     GlobalProxyPlugin plugin;
77     NetManagerStandard::HttpProxy httpProxy;
78     httpProxy.SetPort(1234);
79     httpProxy.SetHost("any host");
80     std::list<std::string> list = {"any list", "any list2"};
81     httpProxy.SetExclusionList(list);
82     httpProxy.SetUserId(100);
83     ErrCode ret = plugin.OnSetPolicy(httpProxy);
84     ASSERT_TRUE(ret == ERR_OK);
85 }
86 
87 /**
88  * @tc.name: TestSetGlobalHttpProxyEmpty
89  * @tc.desc: Test SetGlobalHttpProxy
90  * @tc.type: FUNC
91  */
92 HWTEST_F(GlobalProxyPluginTest, TestSetGlobalHttpProxyEmpty, TestSize.Level1)
93 {
94     GlobalProxyPlugin plugin;
95     NetManagerStandard::HttpProxy httpProxy;
96     httpProxy.SetUserId(100);
97     ErrCode ret = plugin.OnSetPolicy(httpProxy);
98     ASSERT_TRUE(ret == ERR_OK);
99 }
100 
101 /**
102  * @tc.name: TestGetGlobalHttpProxy
103  * @tc.desc: Test GetGlobalHttpProxy
104  * @tc.type: FUNC
105  */
106 HWTEST_F(GlobalProxyPluginTest, TestGetGlobalHttpProxy, TestSize.Level1)
107 {
108     std::shared_ptr<IPlugin> plugin = GlobalProxyPlugin::GetPlugin();
109     MessageParcel data;
110     MessageParcel reply;
111     std::string policyStr;
112     ErrCode ret = plugin->OnGetPolicy(policyStr, data, reply, DEFAULT_USER_ID);
113     ASSERT_TRUE(ret == ERR_OK);
114 }
115 } // namespace TEST
116 } // namespace EDM
117 } // namespace OHOS