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 b24f9a7d19964450fd666405227845b986bf9f9a..d440f889a86ef0e94150705efce5d9147e9edd12 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 92a6df1e3b5785f82598bda5058db98d2763b147..0d138e61dbd23ca2f7bc0336e33df537e823b246 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 3c79b55d3164f9558d2edfd28959feed64d1bd78..80643d02bc04b2089fe2b57006cd96f898242cde 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