diff --git a/config/BUILD.gn b/config/BUILD.gn index c66738cb14bd7d1be7e6898a5ddc9ddb3c62d6c9..6194badd5b1e2288e6e361b038688778dab1919e 100644 --- a/config/BUILD.gn +++ b/config/BUILD.gn @@ -9,10 +9,10 @@ # 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. +# limitations under the License. declare_args() { - access_token_feature_coverage = false + access_token_feature_coverage = true } config("coverage_flags") { diff --git a/interfaces/innerkits/accesstoken/test/BUILD.gn b/interfaces/innerkits/accesstoken/test/BUILD.gn index 468d6af8eaead2f63a3da48dae4b88ef96e39feb..75f0410c8c5d49195921b257395e3d27ebf37cee 100644 --- a/interfaces/innerkits/accesstoken/test/BUILD.gn +++ b/interfaces/innerkits/accesstoken/test/BUILD.gn @@ -48,13 +48,54 @@ ohos_unittest("libaccesstoken_sdk_test") { "dsoftbus:softbus_client", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_single", + "samgr:samgr_proxy", ] if (token_sync_enable == true) { cflags_cc += [ "-DTOKEN_SYNC_ENABLE" ] } } +ohos_unittest("accesstoken_manager_client_test") { + subsystem_name = "security" + part_name = "access_token" + module_out_path = part_name + "/" + part_name + + include_dirs = [ + "//commonlibrary/c_utils/base/include", + "//third_party/googletest/include", + "//base/security/access_token/frameworks/common/include", + "//base/security/access_token/frameworks/accesstoken/include", + "//base/security/access_token/frameworks/tokensync/include", + "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/src", + ] + + sources = [ + "//base/security/access_token/interfaces/innerkits/accesstoken/test/mock/src/iservice_registry.cpp", + "//base/security/access_token/interfaces/innerkits/accesstoken/test/unittest/accesstoken_manager_client_test/accesstoken_manager_client_test.cpp", + ] + + configs = [ "//base/security/access_token/config:coverage_flags" ] + + deps = [ + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "c_utils:utils", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + ] +} + group("unittest") { testonly = true - deps = [ ":libaccesstoken_sdk_test" ] + deps = [ + ":accesstoken_manager_client_test", + ":libaccesstoken_sdk_test", + ] } diff --git a/interfaces/innerkits/accesstoken/test/mock/src/iservice_registry.cpp b/interfaces/innerkits/accesstoken/test/mock/src/iservice_registry.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ac3c849c1a8492e85d50b02aae25c3f1f4ee6df0 --- /dev/null +++ b/interfaces/innerkits/accesstoken/test/mock/src/iservice_registry.cpp @@ -0,0 +1,33 @@ +/* + * 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 "iservice_registry.h" +#include "system_ability_manager.h" + +namespace OHOS { +SystemAbilityManagerClient& SystemAbilityManagerClient::GetInstance() +{ + static auto instance = new SystemAbilityManagerClient(); + return *instance; +} + +sptr SystemAbilityManagerClient::GetSystemAbilityManager() +{ + return nullptr; +} + +void SystemAbilityManagerClient::DestroySystemAbilityManagerObject() +{} +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/accesstoken/test/unittest/accesstoken_manager_client_test/accesstoken_manager_client_test.cpp b/interfaces/innerkits/accesstoken/test/unittest/accesstoken_manager_client_test/accesstoken_manager_client_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e1223247c5daef68db2dc36fed19a5bcb264634c --- /dev/null +++ b/interfaces/innerkits/accesstoken/test/unittest/accesstoken_manager_client_test/accesstoken_manager_client_test.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2021-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 + +#include "accesstoken_manager_client_test.h" + +using namespace testing::ext; + +namespace OHOS { +namespace Security { +namespace AccessToken { + +void AccessTokenManagerClientTest::SetUpTestCase() +{ +} + +void AccessTokenManagerClientTest::TearDownTestCase() +{ +} + +void AccessTokenManagerClientTest::SetUp() +{ +} + +void AccessTokenManagerClientTest::TearDown() +{ +} + +/** + * @tc.name: GetNativeTokenId001 + * @tc.desc: get native tokenid with processName. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(AccessTokenManagerClientTest, GetNativeTokenId001, TestSize.Level1) +{ + std::string processName = "hdcd"; + AccessTokenID tokenID = AccessTokenManagerClient::GetNativeTokenId(processName); + ASSERT_EQ(0, tokenID); +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/accesstoken/test/unittest/accesstoken_manager_client_test/accesstoken_manager_client_test.h b/interfaces/innerkits/accesstoken/test/unittest/accesstoken_manager_client_test/accesstoken_manager_client_test.h new file mode 100644 index 0000000000000000000000000000000000000000..ce7df31346f387ff023ad12a3d75d50d13779c90 --- /dev/null +++ b/interfaces/innerkits/accesstoken/test/unittest/accesstoken_manager_client_test/accesstoken_manager_client_test.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2021-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. + */ +/* + * Copyright (c) 2021-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. + */ + +#ifndef TOKENSYNC_KIT_TEST_H +#define TOKENSYNC_KIT_TEST_H + +#include + +#include "access_token.h" +#include "accesstoken_manager_client.h" +#include "accesstoken_log.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +class AccessTokenManagerClientTest : public testing::Test { +public: + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); + +}; +} // namespace AccessToken +} // namespace Security +} // namespace OHOS +#endif // PRIVACY_KIT_TEST_H diff --git a/interfaces/innerkits/nativetoken/src/nativetoken_json_oper.c b/interfaces/innerkits/nativetoken/src/nativetoken_json_oper.c index 38ad52b813074eae13ca12cd8896c87f55323fb4..99a5a815a6eeb6645b47e7f21d99f1fd7e303dec 100644 --- a/interfaces/innerkits/nativetoken/src/nativetoken_json_oper.c +++ b/interfaces/innerkits/nativetoken/src/nativetoken_json_oper.c @@ -279,12 +279,12 @@ uint32_t UpdateGoalItemFromRecord(const NativeTokenList *tokenNode, cJSON *recor int32_t arraySize = cJSON_GetArraySize(record); for (int32_t i = 0; i < arraySize; i++) { cJSON *cjsonItem = cJSON_GetArrayItem(record, i); - if (cjsonItem == NULL) { + if ((cjsonItem == NULL) || (!cJSON_IsString(cjsonItem))) { AT_LOG_ERROR("[ATLIB-%s]:cJSON_GetArrayItem failed.", __func__); return ATRET_FAILED; } cJSON *processNameJson = cJSON_GetObjectItem(cjsonItem, PROCESS_KEY_NAME); - if ((processNameJson == NULL) || (processNameJson->valuestring == NULL)) { + if ((processNameJson == NULL) || (!cJSON_IsString(processNameJson)) || (processNameJson->valuestring == NULL)) { AT_LOG_ERROR("[ATLIB-%s]:processNameJson is null.", __func__); return ATRET_FAILED; }