From fd42dbd345aa526a32524a6016e3ab3be4e317b0 Mon Sep 17 00:00:00 2001 From: wuliushuan Date: Wed, 30 Apr 2025 11:38:15 +0800 Subject: [PATCH] =?UTF-8?q?DT=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9250430?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuliushuan Change-Id: Ifadfb86397988dbb9825785b6f279437d3e5cd6b --- .../test/unittest/src/privacy_kit_test.cpp | 27 +++++++++---------- .../unittest/src/tokensetproc_kit_test.cpp | 5 ++++ .../unittest/short_grant_manager_test.cpp | 25 +++++++++-------- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/interfaces/innerkits/privacy/test/unittest/src/privacy_kit_test.cpp b/interfaces/innerkits/privacy/test/unittest/src/privacy_kit_test.cpp index b24f9a7d1..d440f889a 100644 --- a/interfaces/innerkits/privacy/test/unittest/src/privacy_kit_test.cpp +++ b/interfaces/innerkits/privacy/test/unittest/src/privacy_kit_test.cpp @@ -1490,10 +1490,10 @@ HWTEST_F(PrivacyKitTest, IsAllowedUsingPermission004, TestSize.Level1) ASSERT_EQ(0, ret); if (list.empty()) { GTEST_LOG_(INFO) << "GetForegroundApplications empty "; - return; + } else { + uint32_t tokenIdForeground = list[0].accessTokenId; + ASSERT_EQ(true, PrivacyKit::IsAllowedUsingPermission(tokenIdForeground, permissionName)); } - uint32_t tokenIdForeground = list[0].accessTokenId; - ASSERT_EQ(true, PrivacyKit::IsAllowedUsingPermission(tokenIdForeground, permissionName)); } /** @@ -1508,18 +1508,17 @@ HWTEST_F(PrivacyKitTest, IsAllowedUsingPermission005, TestSize.Level1) ASSERT_EQ(0, AppManagerAccessClient::GetInstance().GetForegroundApplications(list)); if (list.empty()) { GTEST_LOG_(INFO) << "GetForegroundApplications empty "; - return; + } else { + uint32_t tokenIdForeground = list[0].accessTokenId; + int32_t pidForground = list[0].pid; + std::string permissionName = "ohos.permission.MICROPHONE"; + ASSERT_EQ(false, PrivacyKit::IsAllowedUsingPermission(tokenIdForeground, permissionName, NOT_EXSIT_PID)); + ASSERT_EQ(true, PrivacyKit::IsAllowedUsingPermission(tokenIdForeground, permissionName, pidForground)); + + permissionName = "ohos.permission.CAMERA"; + ASSERT_EQ(false, PrivacyKit::IsAllowedUsingPermission(tokenIdForeground, permissionName, NOT_EXSIT_PID)); + ASSERT_EQ(true, PrivacyKit::IsAllowedUsingPermission(tokenIdForeground, permissionName, pidForground)); } - - uint32_t tokenIdForeground = list[0].accessTokenId; - int32_t pidForground = list[0].pid; - std::string permissionName = "ohos.permission.MICROPHONE"; - ASSERT_EQ(false, PrivacyKit::IsAllowedUsingPermission(tokenIdForeground, permissionName, NOT_EXSIT_PID)); - ASSERT_EQ(true, PrivacyKit::IsAllowedUsingPermission(tokenIdForeground, permissionName, pidForground)); - - permissionName = "ohos.permission.CAMERA"; - ASSERT_EQ(false, PrivacyKit::IsAllowedUsingPermission(tokenIdForeground, permissionName, NOT_EXSIT_PID)); - ASSERT_EQ(true, PrivacyKit::IsAllowedUsingPermission(tokenIdForeground, permissionName, pidForground)); } /** diff --git a/interfaces/innerkits/token_setproc/test/unittest/src/tokensetproc_kit_test.cpp b/interfaces/innerkits/token_setproc/test/unittest/src/tokensetproc_kit_test.cpp index 92a6df1e3..0d138e61d 100644 --- a/interfaces/innerkits/token_setproc/test/unittest/src/tokensetproc_kit_test.cpp +++ b/interfaces/innerkits/token_setproc/test/unittest/src/tokensetproc_kit_test.cpp @@ -427,6 +427,8 @@ static void *ThreadTestFunc02(void *args) HWTEST_F(TokensetprocKitTest, Mulitpulthread001, TestSize.Level1) { setuid(ACCESS_TOKEN_UID); + int64_t beginTime = std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()).count(); pthread_t tid[2]; (void)pthread_create(&tid[0], nullptr, &ThreadTestFunc01, nullptr); (void)pthread_create(&tid[1], nullptr, &ThreadTestFunc01, nullptr); @@ -437,8 +439,11 @@ HWTEST_F(TokensetprocKitTest, Mulitpulthread001, TestSize.Level1) (void)pthread_create(&tid[1], nullptr, &ThreadTestFunc02, nullptr); (void)pthread_join(tid[0], nullptr); (void)pthread_join(tid[1], nullptr); + int64_t endTime = std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()).count(); setuid(g_selfUid); + ASSERT_TRUE(endTime - beginTime < 1000 * 100); } /** diff --git a/services/accesstokenmanager/test/unittest/short_grant_manager_test.cpp b/services/accesstokenmanager/test/unittest/short_grant_manager_test.cpp index 3c79b55d3..80643d02b 100644 --- a/services/accesstokenmanager/test/unittest/short_grant_manager_test.cpp +++ b/services/accesstokenmanager/test/unittest/short_grant_manager_test.cpp @@ -224,20 +224,19 @@ HWTEST_F(ShortGrantManagerTest, RefreshPermission004, TestSize.Level1) ASSERT_EQ(PERMISSION_GRANTED, AccessTokenInfoManager::GetInstance().VerifyAccessToken(tokenID, SHORT_TEMP_PERMISSION)); - if (appStateObserver_ != nullptr) { - return; + if (appStateObserver_ == nullptr) { + appStateObserver_ = sptr::MakeSptr(); + AppStateData appStateData; + appStateData.state = static_cast(ApplicationState::APP_STATE_TERMINATED); + appStateData.accessTokenId = tokenID; + appStateObserver_->OnAppStopped(appStateData); + + EXPECT_EQ(PERMISSION_DENIED, + AccessTokenInfoManager::GetInstance().VerifyAccessToken(tokenID, SHORT_TEMP_PERMISSION)); + + ret = AccessTokenInfoManager::GetInstance().RemoveHapTokenInfo(tokenID); + ASSERT_EQ(RET_SUCCESS, ret); } - appStateObserver_ = sptr::MakeSptr(); - AppStateData appStateData; - appStateData.state = static_cast(ApplicationState::APP_STATE_TERMINATED); - appStateData.accessTokenId = tokenID; - appStateObserver_->OnAppStopped(appStateData); - - EXPECT_EQ(PERMISSION_DENIED, - AccessTokenInfoManager::GetInstance().VerifyAccessToken(tokenID, SHORT_TEMP_PERMISSION)); - - ret = AccessTokenInfoManager::GetInstance().RemoveHapTokenInfo(tokenID); - ASSERT_EQ(RET_SUCCESS, ret); } } // namespace AccessToken } // namespace Security -- Gitee