From 116976f717bfb83f9ffb864f78154ce9a612fca8 Mon Sep 17 00:00:00 2001 From: y1585740638 Date: Sat, 24 Sep 2022 16:37:33 +0800 Subject: [PATCH 1/3] =?UTF-8?q?UpdateGoalItemFromRecord=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: y1585740638 Change-Id: I64cf8e0f200ac4607fc9f103e62ee4e28bddc422 --- interfaces/innerkits/nativetoken/src/nativetoken_json_oper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/innerkits/nativetoken/src/nativetoken_json_oper.c b/interfaces/innerkits/nativetoken/src/nativetoken_json_oper.c index 38ad52b81..99a5a815a 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; } -- Gitee From 4d5d8be50e0335817c15e340e800d6e1f61a21d3 Mon Sep 17 00:00:00 2001 From: y1585740638 Date: Sat, 24 Sep 2022 20:22:44 +0800 Subject: [PATCH 2/3] mock Signed-off-by: y1585740638 Change-Id: I8f24c8b284547f538f0888767c5d93974c1a4cdb --- BUILD.gn | 1 + .../accesstoken_kit_test/BUILD.gn | 72 +++++++++++++++++++ .../accesstoken_kit_test.cpp | 57 +++++++++++++++ .../accesstoken_kit_test.h | 44 ++++++++++++ .../mock/src/iservice_registry.cpp | 33 +++++++++ 5 files changed, 207 insertions(+) create mode 100644 test/unittest/access_token/accesstoken_kit_test/BUILD.gn create mode 100644 test/unittest/access_token/accesstoken_kit_test/accesstoken_kit_test.cpp create mode 100644 test/unittest/access_token/accesstoken_kit_test/accesstoken_kit_test.h create mode 100644 test/unittest/access_token/mock/src/iservice_registry.cpp diff --git a/BUILD.gn b/BUILD.gn index db3edd2f5..1570db56c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -27,6 +27,7 @@ group("accesstoken_build_module_test") { "//base/security/access_token/interfaces/innerkits/token_setproc/test:unittest", "//base/security/access_token/services/accesstokenmanager/test:unittest", "//base/security/access_token/services/common/database/test:unittest", + "//base/security/access_token/test/unittest/access_token/accesstoken_kit_test:unittest", ] if (ability_base_enable == true) { deps += [ "//base/security/access_token/services/privacymanager/test/unittest:unittest" ] diff --git a/test/unittest/access_token/accesstoken_kit_test/BUILD.gn b/test/unittest/access_token/accesstoken_kit_test/BUILD.gn new file mode 100644 index 000000000..175dad47d --- /dev/null +++ b/test/unittest/access_token/accesstoken_kit_test/BUILD.gn @@ -0,0 +1,72 @@ +# 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("accesstoken_kit_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", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + "//base/security/access_token/interfaces/innerkits/nativetoken/include", + "//base/security/access_token/frameworks/common/include", + "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk", + "//foundation/systemabilitymgr/samgr/interfaces/innerkits/common/include", + "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include", + "//foundation/systemabilitymgr/samgr/services/samgr/native/include", + "//foundation/systemabilitymgr/samgr/services/samgr/dfx/include", + "//foundation/systemabilitymgr/samgr/services/samgr/lsamgr/include", + ] + + sources = [ + "//base/security/access_token/test/unittest/access_token/accesstoken_kit_test/accesstoken_kit_test.cpp", + "//base/security/access_token/test/unittest/access_token/mock/src/iservice_registry.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:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "c_utils:utils", + "eventhandler:libeventhandler", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", + "hiviewdfx_hilog_native:libhilog", + "init:libbeget_proxy", + "init:libbegetutil", + "ipc:ipc_core", + "ipc:libdbinder", + "safwk:system_ability_fwk", + ] + } +} + +group("unittest") { + testonly = true + deps = [ ":accesstoken_kit_test" ] +} diff --git a/test/unittest/access_token/accesstoken_kit_test/accesstoken_kit_test.cpp b/test/unittest/access_token/accesstoken_kit_test/accesstoken_kit_test.cpp new file mode 100644 index 000000000..7a367506e --- /dev/null +++ b/test/unittest/access_token/accesstoken_kit_test/accesstoken_kit_test.cpp @@ -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. + */ + +#include + +#include "accesstoken_kit_test.h" + + +using namespace testing::ext; + +namespace OHOS { +namespace Security { +namespace AccessToken { + +void AccessTokenKitTest::SetUpTestCase() +{ +} + +void AccessTokenKitTest::TearDownTestCase() +{ +} + +void AccessTokenKitTest::SetUp() +{ +} + +void AccessTokenKitTest::TearDown() +{ +} + +/** + * @tc.name: GetNativeTokenId001 + * @tc.desc: get native tokenid with processName. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(AccessTokenKitTest, GetNativeTokenId001, TestSize.Level1) +{ + std::string processName = "hdcd"; + AccessTokenID tokenID = AccessTokenKit::GetNativeTokenId(processName); + ASSERT_EQ(0, tokenID); +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/access_token/accesstoken_kit_test/accesstoken_kit_test.h b/test/unittest/access_token/accesstoken_kit_test/accesstoken_kit_test.h new file mode 100644 index 000000000..d1a0ae928 --- /dev/null +++ b/test/unittest/access_token/accesstoken_kit_test/accesstoken_kit_test.h @@ -0,0 +1,44 @@ +/* + * 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_kit.h" +#include "accesstoken_log.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace Security { +namespace AccessToken { +class AccessTokenKitTest : 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/test/unittest/access_token/mock/src/iservice_registry.cpp b/test/unittest/access_token/mock/src/iservice_registry.cpp new file mode 100644 index 000000000..ac3c849c1 --- /dev/null +++ b/test/unittest/access_token/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 -- Gitee From c94965a57f4f6e0cd69b16d063fbbca897524fe6 Mon Sep 17 00:00:00 2001 From: y1585740638 Date: Mon, 26 Sep 2022 11:03:48 +0800 Subject: [PATCH 3/3] Signed-off-by: y1585740638 Change-Id: I1bbaf6ef46c654769db0b602b8502fc880be8bbe --- BUILD.gn | 1 - config/BUILD.gn | 4 +- .../innerkits/accesstoken/test/BUILD.gn | 43 ++++++++++- .../test}/mock/src/iservice_registry.cpp | 0 .../accesstoken_manager_client_test.cpp | 15 ++-- .../accesstoken_manager_client_test.h | 19 ++++- .../accesstoken_kit_test/BUILD.gn | 72 ------------------- 7 files changed, 67 insertions(+), 87 deletions(-) rename {test/unittest/access_token => interfaces/innerkits/accesstoken/test}/mock/src/iservice_registry.cpp (100%) rename test/unittest/access_token/accesstoken_kit_test/accesstoken_kit_test.cpp => interfaces/innerkits/accesstoken/test/unittest/accesstoken_manager_client_test/accesstoken_manager_client_test.cpp (71%) rename test/unittest/access_token/accesstoken_kit_test/accesstoken_kit_test.h => interfaces/innerkits/accesstoken/test/unittest/accesstoken_manager_client_test/accesstoken_manager_client_test.h (60%) delete mode 100644 test/unittest/access_token/accesstoken_kit_test/BUILD.gn diff --git a/BUILD.gn b/BUILD.gn index 1570db56c..db3edd2f5 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -27,7 +27,6 @@ group("accesstoken_build_module_test") { "//base/security/access_token/interfaces/innerkits/token_setproc/test:unittest", "//base/security/access_token/services/accesstokenmanager/test:unittest", "//base/security/access_token/services/common/database/test:unittest", - "//base/security/access_token/test/unittest/access_token/accesstoken_kit_test:unittest", ] if (ability_base_enable == true) { deps += [ "//base/security/access_token/services/privacymanager/test/unittest:unittest" ] diff --git a/config/BUILD.gn b/config/BUILD.gn index c66738cb1..6194badd5 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 468d6af8e..75f0410c8 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/test/unittest/access_token/mock/src/iservice_registry.cpp b/interfaces/innerkits/accesstoken/test/mock/src/iservice_registry.cpp similarity index 100% rename from test/unittest/access_token/mock/src/iservice_registry.cpp rename to interfaces/innerkits/accesstoken/test/mock/src/iservice_registry.cpp diff --git a/test/unittest/access_token/accesstoken_kit_test/accesstoken_kit_test.cpp b/interfaces/innerkits/accesstoken/test/unittest/accesstoken_manager_client_test/accesstoken_manager_client_test.cpp similarity index 71% rename from test/unittest/access_token/accesstoken_kit_test/accesstoken_kit_test.cpp rename to interfaces/innerkits/accesstoken/test/unittest/accesstoken_manager_client_test/accesstoken_manager_client_test.cpp index 7a367506e..e1223247c 100644 --- a/test/unittest/access_token/accesstoken_kit_test/accesstoken_kit_test.cpp +++ b/interfaces/innerkits/accesstoken/test/unittest/accesstoken_manager_client_test/accesstoken_manager_client_test.cpp @@ -15,8 +15,7 @@ #include -#include "accesstoken_kit_test.h" - +#include "accesstoken_manager_client_test.h" using namespace testing::ext; @@ -24,19 +23,19 @@ namespace OHOS { namespace Security { namespace AccessToken { -void AccessTokenKitTest::SetUpTestCase() +void AccessTokenManagerClientTest::SetUpTestCase() { } -void AccessTokenKitTest::TearDownTestCase() +void AccessTokenManagerClientTest::TearDownTestCase() { } -void AccessTokenKitTest::SetUp() +void AccessTokenManagerClientTest::SetUp() { } -void AccessTokenKitTest::TearDown() +void AccessTokenManagerClientTest::TearDown() { } @@ -46,10 +45,10 @@ void AccessTokenKitTest::TearDown() * @tc.type: FUNC * @tc.require: Issue Number */ -HWTEST_F(AccessTokenKitTest, GetNativeTokenId001, TestSize.Level1) +HWTEST_F(AccessTokenManagerClientTest, GetNativeTokenId001, TestSize.Level1) { std::string processName = "hdcd"; - AccessTokenID tokenID = AccessTokenKit::GetNativeTokenId(processName); + AccessTokenID tokenID = AccessTokenManagerClient::GetNativeTokenId(processName); ASSERT_EQ(0, tokenID); } } // namespace AccessToken diff --git a/test/unittest/access_token/accesstoken_kit_test/accesstoken_kit_test.h b/interfaces/innerkits/accesstoken/test/unittest/accesstoken_manager_client_test/accesstoken_manager_client_test.h similarity index 60% rename from test/unittest/access_token/accesstoken_kit_test/accesstoken_kit_test.h rename to interfaces/innerkits/accesstoken/test/unittest/accesstoken_manager_client_test/accesstoken_manager_client_test.h index d1a0ae928..ce7df3134 100644 --- a/test/unittest/access_token/accesstoken_kit_test/accesstoken_kit_test.h +++ b/interfaces/innerkits/accesstoken/test/unittest/accesstoken_manager_client_test/accesstoken_manager_client_test.h @@ -12,6 +12,20 @@ * 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 @@ -19,14 +33,14 @@ #include #include "access_token.h" -#include "accesstoken_kit.h" +#include "accesstoken_manager_client.h" #include "accesstoken_log.h" #include "iservice_registry.h" namespace OHOS { namespace Security { namespace AccessToken { -class AccessTokenKitTest : public testing::Test { +class AccessTokenManagerClientTest : public testing::Test { public: static void SetUpTestCase(); @@ -41,4 +55,3 @@ public: } // namespace Security } // namespace OHOS #endif // PRIVACY_KIT_TEST_H - diff --git a/test/unittest/access_token/accesstoken_kit_test/BUILD.gn b/test/unittest/access_token/accesstoken_kit_test/BUILD.gn deleted file mode 100644 index 175dad47d..000000000 --- a/test/unittest/access_token/accesstoken_kit_test/BUILD.gn +++ /dev/null @@ -1,72 +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. - -import("//base/security/access_token/access_token.gni") -import("//build/test.gni") - -if (is_standard_system && ability_base_enable == true) { - ohos_unittest("accesstoken_kit_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", - "//base/security/access_token/interfaces/innerkits/accesstoken/include", - "//base/security/access_token/interfaces/innerkits/nativetoken/include", - "//base/security/access_token/frameworks/common/include", - "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk", - "//foundation/systemabilitymgr/samgr/interfaces/innerkits/common/include", - "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include", - "//foundation/systemabilitymgr/samgr/services/samgr/native/include", - "//foundation/systemabilitymgr/samgr/services/samgr/dfx/include", - "//foundation/systemabilitymgr/samgr/services/samgr/lsamgr/include", - ] - - sources = [ - "//base/security/access_token/test/unittest/access_token/accesstoken_kit_test/accesstoken_kit_test.cpp", - "//base/security/access_token/test/unittest/access_token/mock/src/iservice_registry.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:gmock_main", - "//third_party/googletest:gtest_main", - ] - - external_deps = [ - "c_utils:utils", - "eventhandler:libeventhandler", - "hisysevent_native:libhisysevent", - "hitrace_native:hitrace_meter", - "hiviewdfx_hilog_native:libhilog", - "init:libbeget_proxy", - "init:libbegetutil", - "ipc:ipc_core", - "ipc:libdbinder", - "safwk:system_ability_fwk", - ] - } -} - -group("unittest") { - testonly = true - deps = [ ":accesstoken_kit_test" ] -} -- Gitee