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 "fingerprint_auth_plugin.h"
17
18 #include <gtest/gtest.h>
19
20 #include "edm_ipc_interface_code.h"
21 #include "iplugin_manager.h"
22 #include "parameters.h"
23 #include "utils.h"
24
25 using namespace testing::ext;
26 using namespace testing;
27
28 namespace OHOS {
29 namespace EDM {
30 namespace TEST {
31 const std::string PERSIST_FINGERPRINT_AUTH_CONTROL = "persist.useriam.enable.fingerprintauth";
32 class FingerprintAuthPluginTest : public testing::Test {
33 protected:
34 static void SetUpTestSuite(void);
35
36 static void TearDownTestSuite(void);
37 };
38
SetUpTestSuite(void)39 void FingerprintAuthPluginTest::SetUpTestSuite(void)
40 {
41 Utils::SetEdmInitialEnv();
42 setegid(Utils::USERIAM_UID);
43 ASSERT_TRUE(getegid() == Utils::USERIAM_UID);
44 }
45
TearDownTestSuite(void)46 void FingerprintAuthPluginTest::TearDownTestSuite(void)
47 {
48 Utils::ResetTokenTypeAndUid();
49 setegid(Utils::EDM_UID);
50 ASSERT_TRUE(getegid() == Utils::EDM_UID);
51 ASSERT_TRUE(Utils::IsOriginalUTEnv());
52 std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
53 }
54
55 /**
56 * @tc.name: TestFingerprintAuthPluginTestSetFalse
57 * @tc.desc: Test FingerprintAuthPluginTest::OnSetPolicy function.
58 * @tc.type: FUNC
59 */
60 HWTEST_F(FingerprintAuthPluginTest, TestFingerprintAuthPluginTestSetFalse, TestSize.Level1)
61 {
62 bool policyValue = false;
63 FingerprintAuthPlugin plugin;
64 ErrCode ret = plugin.OnSetPolicy(policyValue);
65 ASSERT_TRUE(ret == ERR_OK);
66 ASSERT_TRUE(policyValue != system::GetBoolParameter(PERSIST_FINGERPRINT_AUTH_CONTROL, true));
67 }
68
69 /**
70 * @tc.name: TestFingerprintAuthPluginTestSetTrue
71 * @tc.desc: Test FingerprintAuthPluginTest::OnSetPolicy function.
72 * @tc.type: FUNC
73 */
74 HWTEST_F(FingerprintAuthPluginTest, TestFingerprintAuthPluginTestSetTrue, TestSize.Level1)
75 {
76 bool policyValue = true;
77 FingerprintAuthPlugin plugin;
78 ErrCode ret = plugin.OnSetPolicy(policyValue);
79 ASSERT_TRUE(ret == ERR_OK);
80 ASSERT_TRUE(policyValue != system::GetBoolParameter(PERSIST_FINGERPRINT_AUTH_CONTROL, true));
81 }
82
83 /**
84 * @tc.name: TestFingerprintAuthPluginTestGet
85 * @tc.desc: Test FingerprintAuthPluginTest::OnGetPolicy function.
86 * @tc.type: FUNC
87 */
88 HWTEST_F(FingerprintAuthPluginTest, TestFingerprintAuthPluginTestGet, TestSize.Level1)
89 {
90 std::shared_ptr<IPlugin> plugin = FingerprintAuthPlugin::GetPlugin();
91 std::string policyData{"false"};
92 MessageParcel data;
93 MessageParcel reply;
94 ErrCode ret = plugin->OnGetPolicy(policyData, data, reply, DEFAULT_USER_ID);
95 int32_t flag = ERR_INVALID_VALUE;
96 ASSERT_TRUE(reply.ReadInt32(flag) && (flag == ERR_OK));
97 bool result = false;
98 reply.ReadBool(result);
99 ASSERT_TRUE(ret == ERR_OK);
100 ASSERT_TRUE(result != system::GetBoolParameter(PERSIST_FINGERPRINT_AUTH_CONTROL, true));
101 }
102 } // namespace TEST
103 } // namespace EDM
104 } // namespace OHOS