• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ptr.h"
24 #include "mock_inputer.h"
25 #include "pinauth_register.h"
26 
27 namespace OHOS {
28 namespace UserIam {
29 namespace PinAuth {
30 using namespace testing;
31 using namespace testing::ext;
32 
33 static uint64_t tokenId;
34 
SetUpTestCase()35 void PinAuthRegisterTest::SetUpTestCase()
36 {
37     static const char *PERMS[] = {
38         "ohos.permission.ACCESS_PIN_AUTH"
39     };
40     NativeTokenInfoParams infoInstance = {
41         .dcapsNum = 0,
42         .permsNum = 1,
43         .aclsNum = 0,
44         .dcaps = nullptr,
45         .perms = PERMS,
46         .acls = nullptr,
47         .processName = "pin_auth_service_test",
48         .aplStr = "system_core",
49     };
50     tokenId = GetAccessTokenId(&infoInstance);
51     SetSelfTokenID(tokenId);
52     Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
53     SaveStringToFile("/sys/fs/selinux/enforce", "0");
54 }
55 
TearDownTestCase()56 void PinAuthRegisterTest::TearDownTestCase()
57 {
58     Security::AccessToken::AccessTokenKit::DeleteToken(tokenId);
59     Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
60     SaveStringToFile("/sys/fs/selinux/enforce", "1");
61 }
62 
SetUp()63 void PinAuthRegisterTest::SetUp()
64 {
65 }
66 
TearDown()67 void PinAuthRegisterTest::TearDown()
68 {
69 }
70 
71 HWTEST_F(PinAuthRegisterTest, PinAuthRegisterTest001, TestSize.Level0)
72 {
73     std::shared_ptr<IInputer> testInputer = nullptr;
74     EXPECT_EQ(PinAuthRegister::GetInstance().RegisterInputer(testInputer), false);
75     PinAuthRegister::GetInstance().UnRegisterInputer();
76 }
77 
78 HWTEST_F(PinAuthRegisterTest, PinAuthRegisterTest002, TestSize.Level0)
79 {
80     std::shared_ptr<IInputer> testInputer = Common::MakeShared<MockInputer>();
81     EXPECT_NE(testInputer, nullptr);
82     EXPECT_EQ(PinAuthRegister::GetInstance().RegisterInputer(testInputer), true);
83     PinAuthRegister::GetInstance().UnRegisterInputer();
84 }
85 } // namespace PinAuth
86 } // namespace UserIam
87 } // namespace OHOS
88