1 /*
2 * Copyright (c) 2022 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 "pin_auth_register_test.h"
17
18 #include "file_ex.h"
19 #include "accesstoken_kit.h"
20 #include "nativetoken_kit.h"
21 #include "token_setproc.h"
22
23 #include "iam_logger.h"
24 #include "iam_ptr.h"
25 #include "mock_inputer.h"
26 #include "mock_pin_auth_interface.h"
27 #include "mock_inputer_get_data.h"
28 #include "pinauth_register.h"
29 #include "pinauth_register_impl.h"
30
31 namespace OHOS {
32 namespace UserIam {
33 namespace PinAuth {
34 using namespace testing;
35 using namespace testing::ext;
36
37 static uint64_t tokenId;
38
SetUpTestCase()39 void PinAuthRegisterTest::SetUpTestCase()
40 {
41 static const char *PERMS[] = {
42 "ohos.permission.ACCESS_PIN_AUTH"
43 };
44 string isEnforcing;
45 NativeTokenInfoParams infoInstance = {
46 .dcapsNum = 0,
47 .permsNum = 1,
48 .aclsNum = 0,
49 .dcaps = nullptr,
50 .perms = PERMS,
51 .acls = nullptr,
52 .processName = "pin_auth_service_test",
53 .aplStr = "system_core",
54 };
55 tokenId = GetAccessTokenId(&infoInstance);
56 SetSelfTokenID(tokenId);
57 Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
58 LoadStringFromFile("/sys/fs/selinux/enforce", isEnforcing);
59 if (isEnforcing.compare("1") == 0) {
60 PinAuthRegisterTest::isEnforcing_ = true;
61 SaveStringToFile("/sys/fs/selinux/enforce", "0");
62 }
63 }
64
TearDownTestCase()65 void PinAuthRegisterTest::TearDownTestCase()
66 {
67 Security::AccessToken::AccessTokenKit::DeleteToken(tokenId);
68 Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
69 if (PinAuthRegisterTest::isEnforcing_) {
70 SaveStringToFile("/sys/fs/selinux/enforce", "1");
71 }
72 }
73
SetUp()74 void PinAuthRegisterTest::SetUp()
75 {
76 }
77
TearDown()78 void PinAuthRegisterTest::TearDown()
79 {
80 }
81
82 bool PinAuthRegisterTest::isEnforcing_ = false;
83
84 HWTEST_F(PinAuthRegisterTest, PinAuthRegisterTest001, TestSize.Level0)
85 {
86 std::shared_ptr<IInputer> testInputer = nullptr;
87 EXPECT_EQ(PinAuthRegister::GetInstance().RegisterInputer(testInputer), false);
88 PinAuthRegister::GetInstance().UnRegisterInputer();
89 }
90 } // namespace PinAuth
91 } // namespace UserIam
92 } // namespace OHOS
93