diff --git a/BUILD.gn b/BUILD.gn index 9e318da81c3daae2f0c777d3bfb7259f91619ded..32147476ac439751c154179ce6868d565f80159d 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -29,6 +29,9 @@ group("accesstoken_build_module_test") { "//base/security/access_token/services/accesstokenmanager/test:unittest", "//base/security/access_token/services/common/database/test:unittest", ] + if (ability_base_enable == true) { + deps += [ "//base/security/access_token/services/privacymanager/test/unittest:unittest" ] + } } if (token_sync_enable == true) { deps += [ diff --git a/frameworks/common/src/random_mbedtls.cpp b/frameworks/common/src/random_mbedtls.cpp index 1a6ad4013f32d63d3f96f7412bbe802cd98c426a..52e1db4151fdecd231de3084a8d03c774395e2f1 100644 --- a/frameworks/common/src/random_mbedtls.cpp +++ b/frameworks/common/src/random_mbedtls.cpp @@ -43,7 +43,7 @@ int RandomMbedtls::GenerateRandomArray(unsigned char *randStr, unsigned int len) if (!initFlag_) { mbedtls_ctr_drbg_init(&ctrDrbg_); mbedtls_entropy_init(&entropy_); - ret = mbedtls_ctr_drbg_seed(&ctrDrbg_, mbedtls_entropy_func, &entropy_, NULL, 0); + ret = mbedtls_ctr_drbg_seed(&ctrDrbg_, mbedtls_entropy_func, &entropy_, nullptr, 0); if (ret != 0) { return RET_FAILED; } diff --git a/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp b/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp index 35373394a693f2a02c3b9beeb60e6256c4c31739..978e917e304da729a3707777812f70e42548c42e 100644 --- a/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp +++ b/interfaces/innerkits/accesstoken/test/unittest/src/accesstoken_kit_test.cpp @@ -2422,7 +2422,7 @@ static void *ThreadTestFunc01(void *args) GTEST_LOG_(INFO) << "ThreadTestFunc01 failed" << tokenID; } } - return NULL; + return nullptr; } static void *ThreadTestFunc02(void *args) @@ -2440,7 +2440,7 @@ static void *ThreadTestFunc02(void *args) GTEST_LOG_(INFO) << "ThreadTestFunc02 failed" << tokenID; } } - return NULL; + return nullptr; } /** @@ -2456,15 +2456,15 @@ HWTEST_F(AccessTokenKitTest, Mulitpulthread001, TestSize.Level1) tokenIdEx = AccessTokenKit::AllocHapToken(g_infoManagerTestInfoParms, g_infoManagerTestPolicyPrams); ASSERT_NE(0, tokenIdEx.tokenIdExStruct.tokenID); pthread_t tid[2]; - (void)pthread_create(&tid[0], 0, &ThreadTestFunc01, NULL); - (void)pthread_create(&tid[1], 0, &ThreadTestFunc01, NULL); - (void)pthread_join(tid[0], NULL); - (void)pthread_join(tid[1], NULL); - - (void)pthread_create(&tid[0], 0, &ThreadTestFunc02, NULL); - (void)pthread_create(&tid[1], 0, &ThreadTestFunc02, NULL); - (void)pthread_join(tid[0], NULL); - (void)pthread_join(tid[1], NULL); + (void)pthread_create(&tid[0], 0, &ThreadTestFunc01, nullptr); + (void)pthread_create(&tid[1], 0, &ThreadTestFunc01, nullptr); + (void)pthread_join(tid[0], nullptr); + (void)pthread_join(tid[1], nullptr); + + (void)pthread_create(&tid[0], 0, &ThreadTestFunc02, nullptr); + (void)pthread_create(&tid[1], 0, &ThreadTestFunc02, nullptr); + (void)pthread_join(tid[0], nullptr); + (void)pthread_join(tid[1], nullptr); ret = AccessTokenKit::DeleteToken(tokenIdEx.tokenIdExStruct.tokenID); ASSERT_EQ(RET_SUCCESS, ret); diff --git a/services/accesstokenmanager/test/BUILD.gn b/services/accesstokenmanager/test/BUILD.gn index acbb43f0d6215475013a4c2ac54c33cd309256f8..f6215400d8dd4bcdf570d5464d22fa6e80fb5de4 100644 --- a/services/accesstokenmanager/test/BUILD.gn +++ b/services/accesstokenmanager/test/BUILD.gn @@ -63,6 +63,7 @@ ohos_unittest("libaccesstoken_manager_service_standard_test") { external_deps = [ "c_utils:utils", "hiviewdfx_hilog_native:libhilog", + "safwk:system_ability_fwk", ] } diff --git a/services/accesstokenmanager/test/unittest/cpp/src/accesstoken_info_manager_test.cpp b/services/accesstokenmanager/test/unittest/cpp/src/accesstoken_info_manager_test.cpp index fb33d9c021c49d7d1941273685b03af3069f13c7..34fbc7a67d61e598b7b7c990d1459ae1da3ab61e 100644 --- a/services/accesstokenmanager/test/unittest/cpp/src/accesstoken_info_manager_test.cpp +++ b/services/accesstokenmanager/test/unittest/cpp/src/accesstoken_info_manager_test.cpp @@ -26,8 +26,10 @@ #undef private #endif #include "permission_manager.h" +#include "string_ex.h" using namespace testing::ext; +using namespace OHOS; using namespace OHOS::Security::AccessToken; namespace { @@ -174,10 +176,15 @@ void AccessTokenInfoManagerTest::TearDownTestCase() {} void AccessTokenInfoManagerTest::SetUp() -{} +{ + atManagerService_ = DelayedSingleton::GetInstance(); + EXPECT_NE(nullptr, atManagerService_); +} void AccessTokenInfoManagerTest::TearDown() -{} +{ + atManagerService_ = nullptr; +} HWTEST_F(AccessTokenInfoManagerTest, Init001, TestSize.Level1) { @@ -970,4 +977,50 @@ HWTEST_F(AccessTokenInfoManagerTest, DlpPermissionConfig006, TestSize.Level1) ASSERT_EQ(RET_SUCCESS, ret); GTEST_LOG_(INFO) << "remove the token info"; } -#endif \ No newline at end of file +#endif + +/** + * @tc.name: Dump001 + * @tc.desc: Dump tokeninfo. + * @tc.type: FUNC + * @tc.require: issueI4V02P + */ +HWTEST_F(AccessTokenInfoManagerTest, Dump001, TestSize.Level1) +{ + int fd = -1; + std::vector args; + + // fd is 0 + ASSERT_NE(RET_SUCCESS, atManagerService_->Dump(fd, args)); + + fd = 1; // 1: std output + + // hidumper + ASSERT_EQ(RET_SUCCESS, atManagerService_->Dump(fd, args)); + + // hidumper -h + args.emplace_back(Str8ToStr16("-h")); + ASSERT_EQ(RET_SUCCESS, atManagerService_->Dump(fd, args)); + + args.clear(); + // hidumper -a + args.emplace_back(Str8ToStr16("-a")); + ASSERT_EQ(RET_SUCCESS, atManagerService_->Dump(fd, args)); + + args.clear(); + // hidumper -t + args.emplace_back(Str8ToStr16("-t")); + ASSERT_NE(RET_SUCCESS, atManagerService_->Dump(fd, args)); + + args.clear(); + // hidumper -t + args.emplace_back(Str8ToStr16("-t")); + args.emplace_back(Str8ToStr16("-1")); // illegal tokenId + ASSERT_NE(RET_SUCCESS, atManagerService_->Dump(fd, args)); + + args.clear(); + // hidumper -t + args.emplace_back(Str8ToStr16("-t")); + args.emplace_back(Str8ToStr16("123")); // invalid tokenId + ASSERT_EQ(RET_SUCCESS, atManagerService_->Dump(fd, args)); +} \ No newline at end of file diff --git a/services/accesstokenmanager/test/unittest/cpp/src/accesstoken_info_manager_test.h b/services/accesstokenmanager/test/unittest/cpp/src/accesstoken_info_manager_test.h index 03cbc7d1ca1a4d911f9b9e199085d3161cbf3e1c..9358b78c2c4564761a657aac08a8da428897ff99 100644 --- a/services/accesstokenmanager/test/unittest/cpp/src/accesstoken_info_manager_test.h +++ b/services/accesstokenmanager/test/unittest/cpp/src/accesstoken_info_manager_test.h @@ -17,6 +17,7 @@ #define ACCESSTOKEN_INFO_MANAGER_TEST_H #include +#include "accesstoken_manager_service.h" namespace OHOS { namespace Security { @@ -30,6 +31,8 @@ public: void SetUp(); void TearDown(); + + std::shared_ptr atManagerService_; }; } // namespace AccessToken } // namespace Security diff --git a/services/privacymanager/include/service/privacy_manager_service.h b/services/privacymanager/include/service/privacy_manager_service.h index 8461b8e0e09ef8bb91854ca23958811baf3930fd..6eebcff0e2fc8d7a0bb5404c7e5b33cc181079f3 100644 --- a/services/privacymanager/include/service/privacy_manager_service.h +++ b/services/privacymanager/include/service/privacy_manager_service.h @@ -49,10 +49,10 @@ public: std::vector& permList, const sptr& callback) override; int32_t UnRegisterPermActiveStatusCallback(const sptr& callback) override; bool IsAllowedUsingPermission(AccessTokenID tokenId, const std::string& permissionName) override; - int32_t Dump(int fd, const std::vector& args) override; - int32_t ResponseDumpCommand(int fd, const std::vector& args); + int32_t Dump(int32_t fd, const std::vector& args) override; private: bool Initialize() const; + int32_t ResponseDumpCommand(int32_t fd, const std::vector& args); ServiceRunningState state_; }; diff --git a/services/privacymanager/src/common/time_util.cpp b/services/privacymanager/src/common/time_util.cpp index eff098ca94f6de4a0c15b42164334a3f18944c75..474223ede33fddcab2326df0bcfb96f68b1abd02 100644 --- a/services/privacymanager/src/common/time_util.cpp +++ b/services/privacymanager/src/common/time_util.cpp @@ -21,7 +21,7 @@ namespace Security { namespace AccessToken { int64_t TimeUtil::GetCurrentTimestamp() { - const time_t timestamp = time(NULL); + const time_t timestamp = time(nullptr); return static_cast(timestamp); } } // namespace AccessToken diff --git a/services/privacymanager/src/service/privacy_manager_service.cpp b/services/privacymanager/src/service/privacy_manager_service.cpp index fedbf036e449f6f31e71b64608ac8927bd405556..1ff35ddc00cdd1d70018b5548748b463e8b9332f 100644 --- a/services/privacymanager/src/service/privacy_manager_service.cpp +++ b/services/privacymanager/src/service/privacy_manager_service.cpp @@ -30,7 +30,7 @@ namespace { static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacyManagerService" }; -constexpr int PERMISSION_USAGE_RECORDS_MAXNUM = 100; +constexpr int PERMISSION_USAGE_RECORDS_MAX_NUM = 100; } const bool REGISTER_RESULT = @@ -116,38 +116,36 @@ int32_t PrivacyManagerService::RegisterPermActiveStatusCallback( return PermissionRecordManager::GetInstance().RegisterPermActiveStatusCallback(permList, callback); } -int32_t PrivacyManagerService::ResponseDumpCommand(int fd, const std::vector& args) +int32_t PrivacyManagerService::ResponseDumpCommand(int32_t fd, const std::vector& args) { - if (args.size() < 2) { // 2 :need two args 0:command 1:tokenID + if (args.size() < 2) { // 2 :need two args 0:command 1:tokenId return ERR_INVALID_VALUE; } - long long tokenID = atoll(static_cast(Str16ToStr8(args.at(1)).c_str())); + long long tokenId = atoll(static_cast(Str16ToStr8(args.at(1)).c_str())); PermissionUsedRequest request; - if (tokenID <= 0) { + if (tokenId <= 0) { return ERR_INVALID_VALUE; } - request.tokenId = static_cast(tokenID); + request.tokenId = static_cast(tokenId); request.flag = FLAG_PERMISSION_USAGE_SUMMARY; PermissionUsedResult result; if (PermissionRecordManager::GetInstance().GetPermissionUsedRecords(request, result) != 0) { return ERR_INVALID_VALUE; } std::string infos; - int RecordsNum = 0; - for (int index = result.bundleRecords[0].permissionRecords.size() - 1; index >= 0; index--) { - if (RecordsNum > PERMISSION_USAGE_RECORDS_MAXNUM) { + if (result.bundleRecords.empty() || result.bundleRecords[0].permissionRecords.empty()) { + dprintf(fd, "No Record \n"); + return ERR_OK; + } + int32_t RecordsNum = 0; + for (int32_t index = result.bundleRecords[0].permissionRecords.size() - 1; index >= 0; index--) { + if (RecordsNum > PERMISSION_USAGE_RECORDS_MAX_NUM) { break; } infos.append(R"( "permissionRecord": [)"); infos.append("\n"); infos.append(R"( "bundleName": )" + result.bundleRecords[0].bundleName + ",\n"); - if (result.bundleRecords[0].isRemote) { - std::string status = "true"; - infos.append(R"( "isRemote": )" + status + ",\n"); - } else { - std::string status = "false"; - infos.append(R"( "isRemote": )" + status + ",\n"); - } + infos.append(R"( "isRemote": )" + std::to_string(result.bundleRecords[0].isRemote) + ",\n"); infos.append(R"( "permissionName": ")" + result.bundleRecords[0].permissionRecords[index].permissionName + R"(")" + ",\n"); time_t lastAccessTime = static_cast(result.bundleRecords[0].permissionRecords[index].lastAccessTime); @@ -165,24 +163,27 @@ int32_t PrivacyManagerService::ResponseDumpCommand(int fd, const std::vector& args) +int32_t PrivacyManagerService::Dump(int32_t fd, const std::vector& args) { if (fd < 0) { ACCESSTOKEN_LOG_ERROR(LABEL, "Dump fd invalid value"); return ERR_INVALID_VALUE; } - int ReturnValue = ERR_OK; + int32_t ret = ERR_OK; dprintf(fd, "Privacy Dump:\n"); - dprintf(fd, "please use hidumper -s said -a '-h' command help\n"); std::string arg0 = ((args.size() == 0) ? "" : Str16ToStr8(args.at(0))); if (arg0.compare("-h") == 0) { dprintf(fd, "Usage:\n"); dprintf(fd, " -h: command help\n"); dprintf(fd, " -t : according to specific token id dump permission used records\n"); } else if (arg0.compare("-t") == 0) { - ReturnValue = PrivacyManagerService::ResponseDumpCommand(fd, args); + ret = PrivacyManagerService::ResponseDumpCommand(fd, args); } - return ReturnValue; + + if (ret != ERR_OK) { + dprintf(fd, "please use hidumper -s said -a '-h' command help\n"); + } + return ret; } int32_t PrivacyManagerService::UnRegisterPermActiveStatusCallback(const sptr& callback) diff --git a/services/privacymanager/test/unittest/BUILD.gn b/services/privacymanager/test/unittest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d7178178abb7c3bd4cc35da2f0e91c75e646955c --- /dev/null +++ b/services/privacymanager/test/unittest/BUILD.gn @@ -0,0 +1,52 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/security/access_token/access_token.gni") +import("//build/test.gni") + +if (is_standard_system && ability_base_enable == true) { + ohos_unittest("libprivacy_manager_service_standard_test") { + subsystem_name = "security" + part_name = "access_token" + module_out_path = part_name + "/" + part_name + + include_dirs = [ + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + "//base/security/access_token/frameworks/privacy/include", + "//base/security/access_token/interfaces/innerkits/privacy/include", + "//base/security/access_token/services/privacymanager/include/service", + "//third_party/googletest/include", + "//commonlibrary/c_utils/base/include", + ] + + sources = [ "privacy_manager_service_test.cpp" ] + + configs = [ "//base/security/access_token/config:coverage_flags" ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//base/security/access_token/services/privacymanager:privacy_manager_service", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "c_utils:utils", + "safwk:system_ability_fwk", + ] + } +} + +group("unittest") { + testonly = true + deps = [ ":libprivacy_manager_service_standard_test" ] +} diff --git a/services/privacymanager/test/unittest/add_permission_used_record_test.cpp b/services/privacymanager/test/unittest/add_permission_used_record_test.cpp deleted file mode 100644 index c139fe2ab0b812c572b4d82ed44d9f84a68c0956..0000000000000000000000000000000000000000 --- a/services/privacymanager/test/unittest/add_permission_used_record_test.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "add_permission_used_record_test.h" - -using namespace testing::ext; -using namespace OHOS::Security::AccessToken; - -void AddPermissionUsedRecordTest::SetUpTestCase() -{} - -void AddPermissionUsedRecordTest::TearDownTestCase() -{ -} - -void AddPermissionUsedRecordTest::SetUp() -{ -} - -void AddPermissionUsedRecordTest::TearDown() -{ -} - -/** - * @tc.name: AddPermissionUsedRecord_001 - * @tc.desc: cannot AddPermissionUsedRecord with invalid tokenID and permission. - * @tc.type: FUNC - * @tc.require:AR000GK6TD===== - */ -HWTEST_F(AddPermissionUsedRecordTest, AddPermissionUsedRecord_001, TestSize.Level1) -{ - int32_t successCount = 1; - int32_t fasilCount = 0; - std::string permission = "ohon.permission.READ_CONTACTS"; - AccessTokenID tokenID = AccessTokenKit::GetHapTokenID(g_InfoParmsA.userID, - g_InfoParmsA.bundleName, - g_InfoParmsA.instIndex); - int32_t ret = PrivacyKit::AddPermissionUsedRecord(0, permission, successCount, fasilCount); - ASSERT_EQ(RET_FAILED, ret); - - ret = PrivacyKit::AddPermissionUsedRecord(tokenID, "", successCount, fasilCount); - ASSERT_EQ(RET_FAILED, ret); -} diff --git a/services/privacymanager/test/unittest/privacy_manager_service_test.cpp b/services/privacymanager/test/unittest/privacy_manager_service_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..885562c1c623469b7fd2dcceb51918d410e80cae --- /dev/null +++ b/services/privacymanager/test/unittest/privacy_manager_service_test.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "privacy_manager_service_test.h" +#include "accesstoken_kit.h" +#include "string_ex.h" + +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Security::AccessToken; + +namespace { +constexpr int32_t PERMISSION_USAGE_RECORDS_MAX_NUM = 10; +static PermissionStateFull g_testState = { + .permissionName = "ohos.permission.CAMERA", + .grantFlags = {1}, + .grantStatus = {PermissionState::PERMISSION_GRANTED}, + .isGeneral = true, + .resDeviceID = {"local"} +}; + +static HapPolicyParams g_PolicyPrams = { + .apl = APL_NORMAL, + .domain = "test.domain.A", + .permList = {}, + .permStateList = {g_testState} +}; + +static HapInfoParams g_InfoParms = { + .userID = 1, + .bundleName = "ohos.privacy_test.bundleA", + .instIndex = 0, + .appIDDesc = "privacy_test.bundleA" +}; + +} +void PrivacyManagerServiceTest::SetUpTestCase() +{ +} + +void PrivacyManagerServiceTest::TearDownTestCase() +{ +} + +void PrivacyManagerServiceTest::SetUp() +{ + privacyManagerService_ = DelayedSingleton::GetInstance(); + EXPECT_NE(nullptr, privacyManagerService_); + AccessTokenKit::AllocHapToken(g_InfoParms, g_PolicyPrams); +} + +void PrivacyManagerServiceTest::TearDown() +{ + privacyManagerService_ = nullptr; + AccessTokenID tokenId = AccessTokenKit::GetHapTokenID(g_InfoParms.userID, + g_InfoParms.bundleName, + g_InfoParms.instIndex); + AccessTokenKit::DeleteToken(tokenId); +} + +/** + * @tc.name: Dump001 + * @tc.desc: Dump record info. + * @tc.type: FUNC + * @tc.require: issueI4V02P + */ +HWTEST_F(PrivacyManagerServiceTest, Dump001, TestSize.Level1) +{ + int32_t fd = -1; + std::vector args; + + // fd is 0 + ASSERT_NE(RET_SUCCESS, privacyManagerService_->Dump(fd, args)); + + fd = 1; // 1: std output + + // hidumper + ASSERT_EQ(RET_SUCCESS, privacyManagerService_->Dump(fd, args)); + + // hidumper -h + args.emplace_back(Str8ToStr16("-h")); + ASSERT_EQ(RET_SUCCESS, privacyManagerService_->Dump(fd, args)); + + args.clear(); + // hidumper -t + args.emplace_back(Str8ToStr16("-t")); + ASSERT_NE(RET_SUCCESS, privacyManagerService_->Dump(fd, args)); + + args.clear(); + // hidumper -t + args.emplace_back(Str8ToStr16("-t")); + args.emplace_back(Str8ToStr16("-1")); // illegal tokenId // illegal tokenId + ASSERT_NE(RET_SUCCESS, privacyManagerService_->Dump(fd, args)); + + args.clear(); + // hidumper -t + args.emplace_back(Str8ToStr16("-t")); + args.emplace_back(Str8ToStr16("123")); // 123: invalid tokenId + ASSERT_EQ(RET_SUCCESS, privacyManagerService_->Dump(fd, args)); +} + +/** + * @tc.name: Dump002 + * @tc.desc: Dump record info. + * @tc.type: FUNC + * @tc.require: issueI4V02P + */ +HWTEST_F(PrivacyManagerServiceTest, Dump002, TestSize.Level1) +{ + int32_t fd = 1; // 1: std output + std::vector args; + AccessTokenID tokenId = AccessTokenKit::GetHapTokenID(g_InfoParms.userID, + g_InfoParms.bundleName, + g_InfoParms.instIndex); + args.emplace_back(Str8ToStr16("-t")); + std::string tokenIdStr = std::to_string(tokenId); + args.emplace_back(Str8ToStr16(tokenIdStr)); + + ASSERT_EQ(RET_SUCCESS, privacyManagerService_->Dump(fd, args)); + + std::string permission = "ohos.permission.CAMERA"; + for (int32_t i = 0; i < PERMISSION_USAGE_RECORDS_MAX_NUM; i++) { + privacyManagerService_->AddPermissionUsedRecord(tokenId, permission, 1, 0); + } + + ASSERT_EQ(RET_SUCCESS, privacyManagerService_->Dump(fd, args)); + + privacyManagerService_->AddPermissionUsedRecord(tokenId, permission, 1, 0); + ASSERT_EQ(RET_SUCCESS, privacyManagerService_->Dump(fd, args)); +} diff --git a/services/privacymanager/test/unittest/add_permission_used_record_test.h b/services/privacymanager/test/unittest/privacy_manager_service_test.h similarity index 76% rename from services/privacymanager/test/unittest/add_permission_used_record_test.h rename to services/privacymanager/test/unittest/privacy_manager_service_test.h index 8f6f83d318ffc07700083e1b442c73945c12461d..6f8c016413d5399ff8eb7897621853d02bb78c31 100644 --- a/services/privacymanager/test/unittest/add_permission_used_record_test.h +++ b/services/privacymanager/test/unittest/privacy_manager_service_test.h @@ -13,15 +13,16 @@ * limitations under the License. */ -#ifndef ADD_PERMISSION_USED_RECORD_TEST_H -#define ADD_PERMISSION_USED_RECORD_TEST_H +#ifndef PRIVACY_MANAGER_SERVICE_TEST_H +#define PRIVACY_MANAGER_SERVICE_TEST_H #include +#include "privacy_manager_service.h" namespace OHOS { namespace Security { namespace AccessToken { -class AddPermissionUsedRecordTest : public testing::Test { +class PrivacyManagerServiceTest : public testing::Test { public: static void SetUpTestCase(); @@ -30,8 +31,9 @@ public: void SetUp(); void TearDown(); + std::shared_ptr privacyManagerService_; }; } // namespace AccessToken } // namespace Security } // namespace OHOS -#endif // ADD_PERMISSION_USED_RECORD_TEST_H +#endif // PRIVACY_MANAGER_SERVICE_TEST_H