diff --git a/BUILD.gn b/BUILD.gn index 6802cea87c5146b9b0d81ad73b5f7c2556aade42..8a73ec08746ec163035c69bca9bd584c107e88e6 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -66,6 +66,7 @@ group("deviceauth_test_build") { "test/unittest/deviceauth:device_auth_ipc_test", "test/unittest/deviceauth:deviceauth_llt", "test/unittest/deviceauth:deviceauth_unit_test", + "test/unittest/tdd_framework/function_test/auth_device:auth_device_test", "test/unittest/tdd_framework/unit_test/services/creds_manager:creds_manager_test", "test/unittest/tdd_framework/unit_test/services/session_manager/session/v2/auth_sub_session:auth_sub_session_test", "test/unittest/tdd_framework/unit_test/services/session_manager/session/v2/auth_sub_session/protocol_lib:ec_speke_protocol_test", diff --git a/services/BUILD.gn b/services/BUILD.gn index 934d1210c54feffdd0b7160ec2baf6ae3bd765f3..2a40bccd94fad947a4eff3a0b0ffad1ec99419cf 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -29,7 +29,6 @@ if (os_level == "mini" || os_level == "small") { "//foundation/communication/dsoftbus/interfaces/kits/common", "//foundation/communication/dsoftbus/interfaces/kits/transport", "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = deviceauth_files defines = [ "HILOG_ENABLE" ] @@ -98,7 +97,6 @@ if (os_level == "mini" || os_level == "small") { "//third_party/bounds_checking_function/include", "${frameworks_path}/inc/lite", "//foundation/systemabilitymgr/samgr_lite/interfaces/kits/samgr", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = deviceauth_ipc_files @@ -135,7 +133,6 @@ if (os_level == "mini" || os_level == "small") { "${frameworks_path}/inc/lite", "//foundation/communication/ipc/interfaces/innerkits/c/ipc/include", "//foundation/systemabilitymgr/samgr_lite/interfaces/kits/samgr", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = deviceauth_ipc_files @@ -165,7 +162,6 @@ if (os_level == "mini" || os_level == "small") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = deviceauth_files @@ -227,7 +223,6 @@ if (os_level == "mini" || os_level == "small") { "//third_party/cJSON", "${frameworks_path}/inc/standard", "${dev_frameworks_path}/inc/permission_adapter", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = deviceauth_ipc_files @@ -271,7 +266,6 @@ if (os_level == "mini" || os_level == "small") { "//third_party/cJSON", "${frameworks_path}/inc/standard", "${dev_frameworks_path}/inc/permission_adapter", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = deviceauth_ipc_files diff --git a/services/deviceauth.gni b/services/deviceauth.gni index 12f98f43f3a18b11b45bd0e8a211bab5cc4a46f2..a5e2640815612cc5e7d68d240e64b3b3b9a6442f 100644 --- a/services/deviceauth.gni +++ b/services/deviceauth.gni @@ -47,6 +47,7 @@ inc_path = [ "${group_manager_path}/inc/channel_manager", "${group_manager_path}/inc/channel_manager/soft_bus_channel", "${dev_frameworks_path}/inc/", + "${dev_frameworks_path}/inc/hiview_adapter", "${dev_frameworks_path}/inc/module", "${dev_frameworks_path}/inc/session", "${dev_frameworks_path}/inc/os_account_adapter", diff --git a/services/session_manager/src/session/v2/expand_sub_session/expand_sub_session.c b/services/session_manager/src/session/v2/expand_sub_session/expand_sub_session.c index 9f15216a1fed91918908977c1ad9b362945f04d4..01c47674b7f26a83208ac5593ab001b62f20cf1c 100644 --- a/services/session_manager/src/session/v2/expand_sub_session/expand_sub_session.c +++ b/services/session_manager/src/session/v2/expand_sub_session/expand_sub_session.c @@ -305,17 +305,24 @@ static int32_t StartCmd(BaseCmd *cmd, CJson *sendCmdList) static int32_t StartNewCmds(ExpandSubSessionImpl *impl, CJson *sendCmdList) { - uint32_t index; - BaseCmd **iter; - FOR_EACH_HC_VECTOR(impl->cmdList, index, iter) { - BaseCmd *cmd = *iter; + uint32_t index = 0; + while (index < HC_VECTOR_SIZE(&impl->cmdList)) { + BaseCmd *cmd = impl->cmdList.get(&impl->cmdList, index); if ((!cmd->isCaller) || (cmd->curState != cmd->beginState)) { + index++; continue; } int32_t res = StartCmd(cmd, sendCmdList); - if (res != HC_SUCCESS && cmd->strategy == ABORT_IF_ERROR) { + if (res == HC_SUCCESS) { + index++; + continue; + } + if (cmd->strategy == ABORT_IF_ERROR) { return res; } + BaseCmd *popCmd = NULL; + HC_VECTOR_POPELEMENT(&impl->cmdList, &popCmd, index); + popCmd->destroy(popCmd); } return HC_SUCCESS; } diff --git a/test/fuzztest/devauth_fuzzer/BUILD.gn b/test/fuzztest/devauth_fuzzer/BUILD.gn index 399bd7192fe0d29ad1a59cfe91d6e9c4a9441ca4..2d78f2cdf446d33115176d9ce0cf741f9dccc126 100644 --- a/test/fuzztest/devauth_fuzzer/BUILD.gn +++ b/test/fuzztest/devauth_fuzzer/BUILD.gn @@ -29,7 +29,6 @@ ohos_fuzztest("DevAuthFuzzTest") { ".", "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", "${dev_frameworks_path}/inc/permission_adapter", ] sources = [ "devauth_fuzzer.cpp" ] diff --git a/test/fuzztest/devauth_fuzzer/devauth_fuzzer.cpp b/test/fuzztest/devauth_fuzzer/devauth_fuzzer.cpp index 33b17a67a07350b5a676cbac86cfcf30005ccca1..82f9aec9dbf5161cdf3ceb3c9560c7a8113b5021 100644 --- a/test/fuzztest/devauth_fuzzer/devauth_fuzzer.cpp +++ b/test/fuzztest/devauth_fuzzer/devauth_fuzzer.cpp @@ -60,7 +60,6 @@ static void NativeTokenSet(const char *procName) bool FuzzDoRegCallback(const uint8_t* data, size_t size) { - NativeTokenSet("device_manager"); (void)InitDeviceAuthService(); (void)MainRescInit(); ServiceDevAuth *serviceObj = new(std::nothrow) ServiceDevAuth(); @@ -71,6 +70,13 @@ bool FuzzDoRegCallback(const uint8_t* data, size_t size) uintptr_t serviceCtx = reinterpret_cast(serviceObj); (void)AddMethodMap(serviceCtx); for (int32_t i = IPC_CALL_ID_REG_CB; i <= IPC_CALL_ID_GET_PSEUDONYM_ID; i++) { + if (i == IPC_CALL_ID_AUTH_DEVICE || i == IPC_CALL_ID_GA_PROC_DATA || i == IPC_CALL_GA_CANCEL_REQUEST) { + NativeTokenSet("softbus_server"); + } else if (i == IPC_CALL_ID_GET_PK_INFO_LIST) { + NativeTokenSet("dslm_service"); + } else { + NativeTokenSet("device_manager"); + } MessageParcel datas; datas.WriteInterfaceToken(DEV_AUTH_SERVICE_INTERFACE_TOKEN); datas.WriteInt32(i); diff --git a/test/fuzztest/devauthcb_fuzzer/BUILD.gn b/test/fuzztest/devauthcb_fuzzer/BUILD.gn index f31218fd38aec07012dae3a5f8670a3a1bd0a5bc..277c20cc25495c122d2b3d9b981d742a3456a93e 100644 --- a/test/fuzztest/devauthcb_fuzzer/BUILD.gn +++ b/test/fuzztest/devauthcb_fuzzer/BUILD.gn @@ -29,7 +29,6 @@ ohos_fuzztest("DevAuthCbFuzzTest") { ".", "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", "${dev_frameworks_path}/inc/permission_adapter", ] sources = [ "devauthcb_fuzzer.cpp" ] diff --git a/test/fuzztest/device_auth_service/devauthservaddmembertogroup_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservaddmembertogroup_fuzzer/BUILD.gn index 08089848fe22c94221cc838ca42477b458bcc228..68e664c2b1e29ac2574f5fd69ffff80e7a8d9475 100644 --- a/test/fuzztest/device_auth_service/devauthservaddmembertogroup_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservaddmembertogroup_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServAddMemberToGroupFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservaddmembertogroup_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservaddmultimemberstogroup_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservaddmultimemberstogroup_fuzzer/BUILD.gn index 405f1b57554804ac00a93396bf2446c2114b5ba5..8b6c6560ecca988243e8fe16a5017518e49a025e 100644 --- a/test/fuzztest/device_auth_service/devauthservaddmultimemberstogroup_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservaddmultimemberstogroup_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServAddMultiMembersToGroupFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservaddmultimemberstogroup_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservauthdevice_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservauthdevice_fuzzer/BUILD.gn index 3de7041f08151f336e21f0231edea1435009c025..eb2b5ffdc5dab1b2bf70a931025aab4a82252998 100644 --- a/test/fuzztest/device_auth_service/devauthservauthdevice_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservauthdevice_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServAuthDeviceFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservauthdevice_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservcancelauthrequest_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservcancelauthrequest_fuzzer/BUILD.gn index 963c0f0d4680ba0b8d6726a72ee0f1360e9f0ae9..b91f4a556805b9935cdc53b7794965d0e931a82e 100644 --- a/test/fuzztest/device_auth_service/devauthservcancelauthrequest_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservcancelauthrequest_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServCancelAuthRequestFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservcancelauthrequest_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservcancelbindrequest_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservcancelbindrequest_fuzzer/BUILD.gn index 4ad9c23f7696fee93408dd14780131b03d94556c..0a754236b82f13e1cf2a1e64058078ee727bec89 100644 --- a/test/fuzztest/device_auth_service/devauthservcancelbindrequest_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservcancelbindrequest_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServCancelBindRequestFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservcancelbindrequest_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservcheckaccesstogroup_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservcheckaccesstogroup_fuzzer/BUILD.gn index c187936344bdeb20dfefadfcd96e8553db6123f5..d11240c9ffda88abf7b647d3566542a13e0bc798 100644 --- a/test/fuzztest/device_auth_service/devauthservcheckaccesstogroup_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservcheckaccesstogroup_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServCheckAccessToGroupFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservcheckaccesstogroup_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservcreategroup_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservcreategroup_fuzzer/BUILD.gn index 41c1b9a1c2a5c4362e47a1ecf1698082d75abf4b..1be4a9bf63deb4b438127619607132859cfa3398 100644 --- a/test/fuzztest/device_auth_service/devauthservcreategroup_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservcreategroup_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServCreateGroupFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservcreategroup_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservdeletegroup_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservdeletegroup_fuzzer/BUILD.gn index c96455968b9c8eaaf7c590fed5f5207a2cfd24b9..751b1a3ac1e2b242e26e34aab4a3f0768af0dad6 100644 --- a/test/fuzztest/device_auth_service/devauthservdeletegroup_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservdeletegroup_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServDeleteGroupFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservdeletegroup_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservdeletememberfromgroup_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservdeletememberfromgroup_fuzzer/BUILD.gn index f6aad65bf507e49bec7fa9023ce1114ccb7c90de..ddbcd32ced830ae6f585dee179620eb14665d61c 100644 --- a/test/fuzztest/device_auth_service/devauthservdeletememberfromgroup_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservdeletememberfromgroup_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServDeleteMemberFromGroupFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservdeletememberfromgroup_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservdeletemultimembersfromgroup_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservdeletemultimembersfromgroup_fuzzer/BUILD.gn index 1939c8240956d7cf192c73b55b40272ca6aa4568..996ec35b737d4a1947192a816078ac61e25a3c56 100644 --- a/test/fuzztest/device_auth_service/devauthservdeletemultimembersfromgroup_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservdeletemultimembersfromgroup_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServDeleteMultiMembersFromGroupFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservdeletemultimembersfromgroup_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservgetdeviceinfobyid_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservgetdeviceinfobyid_fuzzer/BUILD.gn index 09aba6d79eec36d721d9c3d8247cff9d778d91d4..76e5f3d0256b72d7187d43356377e8c01eec1388 100644 --- a/test/fuzztest/device_auth_service/devauthservgetdeviceinfobyid_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservgetdeviceinfobyid_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServGetDeviceInfoByIdFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservgetdeviceinfobyid_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservgetgroupinfo_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservgetgroupinfo_fuzzer/BUILD.gn index 610c6268db1053bcf220ad524672513490482360..2afc81f671f2ccc26e703991e7cd70a1afd3d40a 100644 --- a/test/fuzztest/device_auth_service/devauthservgetgroupinfo_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservgetgroupinfo_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServGetGroupInfoFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservgetgroupinfo_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservgetgroupinfobyid_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservgetgroupinfobyid_fuzzer/BUILD.gn index 3844a6094abd7a41735c9db158b4ea35b1948139..35e75c14b7988769fc784e74f88748785bef5215 100644 --- a/test/fuzztest/device_auth_service/devauthservgetgroupinfobyid_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservgetgroupinfobyid_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServGetGroupInfoByIdFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservgetgroupinfobyid_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservgetjoinedgroups_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservgetjoinedgroups_fuzzer/BUILD.gn index 7a5a5fca394d637947ced6191a6fac7a2dcb858e..e51d84ba0323b4f462ca25365f71ef2ac9ead8f8 100644 --- a/test/fuzztest/device_auth_service/devauthservgetjoinedgroups_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservgetjoinedgroups_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServGetJoinedGroupsFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservgetjoinedgroups_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservgetpkinfolist_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservgetpkinfolist_fuzzer/BUILD.gn index 6dd1609757d89aa385e5ee780d3aa097b6e15917..f80dda97f9311ab33f4f886cf43e042d82f87ce1 100644 --- a/test/fuzztest/device_auth_service/devauthservgetpkinfolist_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservgetpkinfolist_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServGetPkInfoListFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservgetpkinfolist_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservgetregisterinfo_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservgetregisterinfo_fuzzer/BUILD.gn index ebb43c1385bfbeac3291af5dab1aa9155be8bb04..b224335ea40d8a00aa4748391c25cc7ee7c1a4b3 100644 --- a/test/fuzztest/device_auth_service/devauthservgetregisterinfo_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservgetregisterinfo_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServGetRegisterInfoFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservgetregisterinfo_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservgetrelatedgroups_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservgetrelatedgroups_fuzzer/BUILD.gn index df52bc3270804839fb268ef8675a4f2923571be6..1bd0f41cdb2d01e8dc62be426459a4d5e7c01447 100644 --- a/test/fuzztest/device_auth_service/devauthservgetrelatedgroups_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservgetrelatedgroups_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServGetRelatedGroupsFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservgetrelatedgroups_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservgettrusteddevices_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservgettrusteddevices_fuzzer/BUILD.gn index b4617c0911b8d26aebf5cd21cbc0fec4cc1f4b5f..c2cacccdabe659ded5f31e59bfedf4d96be8e1d4 100644 --- a/test/fuzztest/device_auth_service/devauthservgettrusteddevices_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservgettrusteddevices_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServGetTrustedDevicesFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservgettrusteddevices_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservisdeviceingroup_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservisdeviceingroup_fuzzer/BUILD.gn index 27d3aa518e891b5958ed7bf9a76c084741116747..8bcc44ad368426be184297e4a545025af7159e83 100644 --- a/test/fuzztest/device_auth_service/devauthservisdeviceingroup_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservisdeviceingroup_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServIsDeviceInGroupFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservisdeviceingroup_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservprocessauthdata_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservprocessauthdata_fuzzer/BUILD.gn index 5cc202782257e1ba4bca048d122ad3ef2d545ff1..df8e31b8d0aa5fc62f18e5052040ec2d4ebceefa 100644 --- a/test/fuzztest/device_auth_service/devauthservprocessauthdata_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservprocessauthdata_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServProcessAuthDataFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservprocessauthdata_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservprocessbinddata_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservprocessbinddata_fuzzer/BUILD.gn index c5b9fc35cc32493b365da6927e645d3dd30f7bd3..0b3bbc641cc570fce0fc57b65616a5d5c342c496 100644 --- a/test/fuzztest/device_auth_service/devauthservprocessbinddata_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservprocessbinddata_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServProcessBindDataFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservprocessbinddata_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservregcallback_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservregcallback_fuzzer/BUILD.gn index 24998ff5b41b21b201b3ab00ac429ef70a328c4a..516f157999f671e6f75ff0f6fec6c6bf948d3866 100644 --- a/test/fuzztest/device_auth_service/devauthservregcallback_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservregcallback_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServRegCallbackFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservregcallback_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservregdatachangelistener_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservregdatachangelistener_fuzzer/BUILD.gn index 48e8b1cb99d8f48534cb336e65dfc945131ff746..157d6041af76478eacb3adba9dc00343f128b021 100644 --- a/test/fuzztest/device_auth_service/devauthservregdatachangelistener_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservregdatachangelistener_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServRegDataChangeListenerFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservregdatachangelistener_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservunregcallback_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservunregcallback_fuzzer/BUILD.gn index 0775ee0aa4e6c02eeb4ac1038cf80879187e40d6..02cdb017ce5001da30e4dd982a9b115f2c42bf27 100644 --- a/test/fuzztest/device_auth_service/devauthservunregcallback_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservunregcallback_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServUnregCallbackFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservunregcallback_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/fuzztest/device_auth_service/devauthservunregdatachangelistener_fuzzer/BUILD.gn b/test/fuzztest/device_auth_service/devauthservunregdatachangelistener_fuzzer/BUILD.gn index a22d697d9d066b30b255de02f4836d431677863f..70bba760e5763c05bfc2302b887083a76e7549a3 100644 --- a/test/fuzztest/device_auth_service/devauthservunregdatachangelistener_fuzzer/BUILD.gn +++ b/test/fuzztest/device_auth_service/devauthservunregdatachangelistener_fuzzer/BUILD.gn @@ -28,7 +28,6 @@ ohos_fuzztest("DevAuthServUnregDataChangeListenerFuzzTest") { include_dirs += [ "//third_party/cJSON", "${frameworks_path}/inc/standard", - "${dev_frameworks_path}/inc/hiview_adapter", ] sources = [ "devauthservunregdatachangelistener_fuzzer.cpp" ] sources += deviceauth_files diff --git a/test/unittest/deviceauth/BUILD.gn b/test/unittest/deviceauth/BUILD.gn index 59dd7ed3b6b92642ff84af62d566bf7e5fb867da..fcf252e1c5cc81d1e3a8d4a3d7ef955e598947fc 100644 --- a/test/unittest/deviceauth/BUILD.gn +++ b/test/unittest/deviceauth/BUILD.gn @@ -28,7 +28,6 @@ ohos_unittest("deviceauth_llt") { include_dirs += [ "./include", "./unit_test/include", - "${dev_frameworks_path}/inc/hiview_adapter", ] include_dirs += [ @@ -141,7 +140,6 @@ ohos_unittest("device_auth_func_test") { include_dirs += [ "./include", "./unit_test/include", - "${dev_frameworks_path}/inc/hiview_adapter", ] include_dirs += [ @@ -264,7 +262,6 @@ ohos_unittest("deviceauth_unit_test") { include_dirs += [ "./include", "./unit_test/include", - "${dev_frameworks_path}/inc/hiview_adapter", ] include_dirs += [ diff --git a/test/unittest/tdd_framework/function_test/auth_device/BUILD.gn b/test/unittest/tdd_framework/function_test/auth_device/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..092a3ee6e5e8c313f6243c3cc92996fce4187670 --- /dev/null +++ b/test/unittest/tdd_framework/function_test/auth_device/BUILD.gn @@ -0,0 +1,77 @@ +# Copyright (C) 2023 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("../../tdd_framework.gni") + +module_output_path = "device_auth/deviceauth_test" + +ohos_unittest("auth_device_test") { + module_out_path = module_output_path + + include_dirs = device_auth_lib_inc + + include_dirs += [ + "${tdd_framework_path}/tdd_helper/dev_info_mock/inc", + "${tdd_framework_path}/tdd_helper/exception_controller/inc", + "${tdd_framework_path}/tdd_helper/memory_mock/inc", + "${tdd_framework_path}/tdd_helper/memory_monitor/inc", + "${tdd_framework_path}/tdd_helper/protocol_controller/inc", + ] + + sources = device_auth_lib_src + sources -= [ + "${authenticators_path}/src/account_unrelated/iso_task/iso_task_main.c", + "${authenticators_path}/src/account_unrelated/pake_task/pake_v1_task/pake_v1_task_main.c", + ] + sources += [ + "${tdd_framework_path}/tdd_helper/os_account_adapter_mock/src/os_account_adapter_mock.c", + "${tdd_framework_path}/tdd_helper/protocol_controller/src/protocol_controller.c", + ] + sources += [ "auth_device_test.cpp" ] + + defines = [ + "P2P_PAKE_DL_PRIME_LEN_384", + "P2P_PAKE_EC_TYPE", + "ENABLE_EC_SPEKE", + "ENABLE_ISO", + "ENABLE_AUTH_CODE_IMPORT", + "ENABLE_PUB_KEY_EXCHANGE", + "ENABLE_SAVE_TRUSTED_INFO", + "ENABLE_ACCOUNT_AUTH_ISO", + "ENABLE_ACCOUNT_AUTH_EC_SPEKE", + "ENABLE_P2P_BIND_ISO", + "ENABLE_P2P_BIND_EC_SPEKE", + "ENABLE_P2P_AUTH_ISO", + "ENABLE_P2P_AUTH_EC_SPEKE", + "ENABLE_PSEUDONYM", + "DEV_AUTH_MEMORY_DEBUG", + "DEV_AUTH_FUNC_TEST", + ] + + cflags = [ "-DHILOG_ENABLE" ] + + deps = [ + "${tdd_framework_path}/tdd_helper:device_auth_test_hal", + "//third_party/cJSON:cjson", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + "//third_party/mbedtls:mbedtls_shared", + "//third_party/openssl:libcrypto_static", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "huks:libhukssdk", + ] +} diff --git a/test/unittest/tdd_framework/function_test/auth_device/auth_device_test.cpp b/test/unittest/tdd_framework/function_test/auth_device/auth_device_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2c41a79f2ea221d6da0c0abd1b164208392e0398 --- /dev/null +++ b/test/unittest/tdd_framework/function_test/auth_device/auth_device_test.cpp @@ -0,0 +1,637 @@ +/* + * Copyright (C) 2023 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 +#include +#include "account_module_defines.h" +#include "alg_loader.h" +#include "common_defs.h" +#include "device_auth.h" +#include "device_auth_defines.h" +#include "exception_controller.h" +#include "dev_info_mock.h" +#include "json_utils.h" +#include "memory_mock.h" +#include "memory_monitor.h" +#include "uint8buff_utils.h" +#include "protocol_controller.h" +#include "securec.h" + +using namespace std; +using namespace testing::ext; + +namespace { +#define TEST_REQ_ID 123 +#define TEST_REQ_ID2 321 +#define TEST_APP_ID "TestAppId" +#define TEST_APP_ID2 "TestAppId2" +#define TEST_GROUP_NAME "TestGroup" +#define TEST_AUTH_ID "TestAuthId" +#define TEST_AUTH_ID2 "TestAuthId2" +#define TEST_AUTH_ID3 "TestAuthId3" +#define TEST_UDID "TestUdid" +#define TEST_UDID2 "TestUdid2" +#define TEST_UDID_CLIENT "5420459D93FE773F9945FD64277FBA2CAB8FB996DDC1D0B97676FBB1242B3930" +#define TEST_UDID_SERVER "52E2706717D5C39D736E134CC1E3BE1BAA2AA52DB7C76A37C749558BD2E6492C" +#define TEST_USER_ID_AUTH "4269DC28B639681698809A67EDAD08E39F207900038F91FEF95DD042FE2874E4" +#define TEST_USER_ID "4269DC28B639681698809A67EDAD08E39F207900038F91FEF95DD042FE2874E4" +#define TEST_USER_ID2 "9F207900038F91FEF95DD042FE2874E44269DC28B639681698809A67EDAD08E3" +#define TEST_GROUP_ID "E2EE6F830B176B2C96A9F99BFAE2A61F5D1490B9F4A090E9D8C2874C230C7C21" +#define TEST_GROUP_ID2 "F2AA208B1E010542B20A34B03B4B6289EA7C7F6DFE97DA2E370348B826682D3D" +#define TEST_GROUP_ID3 "1234ABCD" +#define TEST_GROUP_ID4 "6B7B805962B8EB8275D73128BFDAA7ECD755A2EC304E36543941874A277FA75F" +#define TEST_AUTH_CODE "37364761534f454d33567a73424e794f33573330507069434b31676f7254706b" +#define TEST_AUTH_CODE2 "2f7562744654535564586e665467546b322b4b506b65626373466f48766a4335" +#define TEST_AUTH_CODE3 "1234567812345678123456781234567812345678123456781234567812345678" +#define TEST_AUTH_TOKEN3 "10F9F0576E61730193D2052B7F771887124A68F1607EFCF7796C1491F834CD92" +#define TEST_QUERY_PARAMS "bac" +#define TEST_PIN_CODE "123456" +#define TEST_DEV_AUTH_TEMP_KEY_PAIR_LEN 32 +#define TEST_DEV_AUTH_SLEEP_TIME 100000 +static const int32_t TEST_AUTH_OS_ACCOUNT_ID = 100; +static const int TEST_DEV_AUTH_BUFFER_SIZE = 128; +static const char *g_createParams = "{\"groupName\":\"TestGroup\",\"deviceId\":\"TestAuthId\",\"groupType\":256,\"group" + "Visibility\":-1,\"userType\":0,\"expireTime\":-1}"; +static const char *g_addParams = + "{\"groupId\":\"E2EE6F830B176B2C96A9F99BFAE2A61F5D1490B9F4A090E9D8C2874C230C7C21\"," + "\"groupType\":256,\"pinCode\":\"123456\"}"; +static const char *g_addParams4 = + "{\"groupType\":1,\"groupId\":\"4269DC28B639681698809A67EDAD08E39F207900038F91FEF95DD042FE2874E4\"," + "\"deviceList\":[{\"deviceId\":\"52E2706717D5C39D736E134CC1E3BE1BAA2AA52DB7C76A37C749558BD2E6492C\"," + "\"udid\":\"52E2706717D5C39D736E134CC1E3BE1BAA2AA52DB7C76A37C749558BD2E6492C\"," + "\"userId\":\"4269DC28B639681698809A67EDAD08E39F207900038F91FEF95DD042FE2874E4\"," + "\"credential\":{\"credentialType\":1," + "\"authCode\":\"10F9F0576E61730193D2052B7F771887124A68F1607EFCF7796C1491F834CD92\"}}," + "{\"deviceId\":\"TestAuthId3\",\"udid\":\"TestUdid2\"," + "\"userId\":\"4269DC28B639681698809A67EDAD08E39F207900038F91FEF95DD042FE2874E4\"," + "\"credential\":{\"credentialType\":1," + "\"authCode\":\"2f7562744654535564586e665467546b322b4b506b65626373466f48766a4335\"}}]}"; +static const char *g_addParams5 = + "{\"groupType\":1,\"groupId\":\"4269DC28B639681698809A67EDAD08E39F207900038F91FEF95DD042FE2874E4\"," + "\"deviceList\":[{\"deviceId\":\"5420459D93FE773F9945FD64277FBA2CAB8FB996DDC1D0B97676FBB1242B3930\"," + "\"udid\":\"5420459D93FE773F9945FD64277FBA2CAB8FB996DDC1D0B97676FBB1242B3930\"," + "\"userId\":\"4269DC28B639681698809A67EDAD08E39F207900038F91FEF95DD042FE2874E4\"," + "\"credential\":{\"credentialType\":1," + "\"authCode\":\"10F9F0576E61730193D2052B7F771887124A68F1607EFCF7796C1491F834CD92\"}}," + "{\"deviceId\":\"TestAuthId3\",\"udid\":\"TestUdid2\"," + "\"userId\":\"4269DC28B639681698809A67EDAD08E39F207900038F91FEF95DD042FE2874E4\"," + "\"credential\":{\"credentialType\":1," + "\"authCode\":\"2f7562744654535564586e665467546b322b4b506b65626373466f48766a4335\"}}]}"; +static const char *g_authParams = "{\"peerConnDeviceId\":\"52E2706717D5C39D736E134CC1E3BE1BAA2AA52DB7C76A37C" + "749558BD2E6492C\",\"servicePkgName\":\"TestAppId\",\"isClient\":true}"; +static const char *g_getRegisterInfoParams = "{\"version\":\"1.0.0\",\"deviceId\":\"client\"," + "\"userId\":\"4269DC28B639681698809A67EDAD08E39F207900038F91FEF95DD042FE2874E4\"}"; +static const char *g_getRegisterInfoParams2 = "{\"version\":\"1.0.0\",\"deviceId\":\"server\"," + "\"userId\":\"4269DC28B639681698809A67EDAD08E39F207900038F91FEF95DD042FE2874E4\"}"; + +enum AsyncStatus { + ASYNC_STATUS_WAITING = 0, + ASYNC_STATUS_TRANSMIT = 1, + ASYNC_STATUS_FINISH = 2, + ASYNC_STATUS_ERROR = 3 +}; + +static AsyncStatus volatile g_asyncStatus; +static uint32_t g_transmitDataMaxLen = 2048; +static uint8_t g_transmitData[2048] = { 0 }; +static uint32_t g_transmitDataLen = 0; + +static bool OnTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen) +{ + if (memcpy_s(g_transmitData, g_transmitDataMaxLen, data, dataLen) != EOK) { + return false; + } + g_transmitDataLen = dataLen; + g_asyncStatus = ASYNC_STATUS_TRANSMIT; + return true; +} + +static void OnSessionKeyReturned(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen) +{ + (void)requestId; + (void)sessionKey; + (void)sessionKeyLen; + return; +} + +static void OnFinish(int64_t requestId, int operationCode, const char *authReturn) +{ + g_asyncStatus = ASYNC_STATUS_FINISH; +} + +static void OnError(int64_t requestId, int operationCode, int errorCode, const char *errorReturn) +{ + g_asyncStatus = ASYNC_STATUS_ERROR; +} + +static char *OnBindRequest(int64_t requestId, int operationCode, const char* reqParam) +{ + CJson *json = CreateJson(); + AddIntToJson(json, FIELD_CONFIRMATION, REQUEST_ACCEPTED); + AddIntToJson(json, FIELD_OS_ACCOUNT_ID, TEST_AUTH_OS_ACCOUNT_ID); + AddStringToJson(json, FIELD_PIN_CODE, TEST_PIN_CODE); + AddStringToJson(json, FIELD_DEVICE_ID, TEST_AUTH_ID2); + char *returnDataStr = PackJsonToString(json); + FreeJson(json); + return returnDataStr; +} + +static char *OnAuthRequest(int64_t requestId, int operationCode, const char* reqParam) +{ + CJson *json = CreateJson(); + AddIntToJson(json, FIELD_CONFIRMATION, REQUEST_ACCEPTED); + AddIntToJson(json, FIELD_OS_ACCOUNT_ID, TEST_AUTH_OS_ACCOUNT_ID); + AddStringToJson(json, FIELD_PEER_CONN_DEVICE_ID, TEST_UDID_CLIENT); + AddStringToJson(json, FIELD_SERVICE_PKG_NAME, TEST_APP_ID); + char *returnDataStr = PackJsonToString(json); + FreeJson(json); + return returnDataStr; +} + +static DeviceAuthCallback g_gmCallback = { + .onTransmit = OnTransmit, + .onSessionKeyReturned = OnSessionKeyReturned, + .onFinish = OnFinish, + .onError = OnError, + .onRequest = OnBindRequest +}; + +static DeviceAuthCallback g_gaCallback = { + .onTransmit = OnTransmit, + .onSessionKeyReturned = OnSessionKeyReturned, + .onFinish = OnFinish, + .onError = OnError, + .onRequest = OnAuthRequest +}; + +static void RemoveDir(const char *path) +{ + char strBuf[TEST_DEV_AUTH_BUFFER_SIZE] = {0}; + if (path == nullptr) { + return; + } + if (sprintf_s(strBuf, sizeof(strBuf) - 1, "rm -rf %s", path) < 0) { + return; + } + system(strBuf); + return; +} + +static void DeleteDatabase() +{ + const char *groupPath = "/data/service/el1/public/deviceauthMock"; + RemoveDir(groupPath); + return; +} + +static bool GenerateTempKeyPair(Uint8Buff *keyAlias) +{ + int ret = GetLoaderInstance()->checkKeyExist(keyAlias); + if (ret != HC_SUCCESS) { + printf("Key pair not exist, start to generate\n"); + int32_t authId = 0; + Uint8Buff authIdBuff = { reinterpret_cast(&authId), sizeof(int32_t)}; + ExtraInfo extInfo = {authIdBuff, -1, -1}; + ret = GetLoaderInstance()->generateKeyPairWithStorage(keyAlias, TEST_DEV_AUTH_TEMP_KEY_PAIR_LEN, P256, + KEY_PURPOSE_SIGN_VERIFY, &extInfo); + } else { + printf("Server key pair already exists\n"); + } + + if (ret != HC_SUCCESS) { + printf("Generate key pair failed\n"); + return false; + } else { + printf("Generate key pair for server success\n"); + } + return true; +} + +static CJson *GetAsyCredentialJson(string registerInfo) +{ + uint8_t keyAliasValue[] = "TestServerKeyPair"; + int32_t keyAliasLen = 18; + Uint8Buff keyAlias = { + .val = keyAliasValue, + .length = keyAliasLen + }; + if (!GenerateTempKeyPair(&keyAlias)) { + return nullptr; + } + uint8_t *serverPkVal = reinterpret_cast(HcMalloc(SERVER_PK_SIZE, 0)); + Uint8Buff serverPk = { + .val = serverPkVal, + .length = SERVER_PK_SIZE + }; + + int32_t ret = GetLoaderInstance()->exportPublicKey(&keyAlias, &serverPk); + if (ret != HC_SUCCESS) { + printf("export PublicKey failed\n"); + HcFree(serverPkVal); + return nullptr; + } + + Uint8Buff messageBuff = { + .val = reinterpret_cast(const_cast(registerInfo.c_str())), + .length = registerInfo.length() + 1 + }; + uint8_t *signatureValue = reinterpret_cast(HcMalloc(SIGNATURE_SIZE, 0)); + Uint8Buff signature = { + .val = signatureValue, + .length = SIGNATURE_SIZE + }; + ret = GetLoaderInstance()->sign(&keyAlias, &messageBuff, P256, &signature, true); + if (ret != HC_SUCCESS) { + printf("Sign pkInfo failed.\n"); + HcFree(serverPkVal); + HcFree(signatureValue); + return nullptr; + } + + CJson *pkInfoJson = CreateJsonFromString(registerInfo.c_str()); + CJson *credentialJson = CreateJson(); + (void)AddIntToJson(credentialJson, FIELD_CREDENTIAL_TYPE, ASYMMETRIC_CRED); + (void)AddByteToJson(credentialJson, FIELD_SERVER_PK, serverPkVal, serverPk.length); + (void)AddByteToJson(credentialJson, FIELD_PK_INFO_SIGNATURE, signatureValue, signature.length); + (void)AddObjToJson(credentialJson, FIELD_PK_INFO, pkInfoJson); + FreeJson(pkInfoJson); + HcFree(serverPkVal); + HcFree(signatureValue); + return credentialJson; +} + +static void CreateDemoGroup(int32_t osAccountId, int64_t reqId, const char *appId, const char *createParams) +{ + g_asyncStatus = ASYNC_STATUS_WAITING; + const DeviceGroupManager *gm = GetGmInstance(); + int32_t ret = gm->createGroup(osAccountId, reqId, appId, createParams); + if (ret != HC_SUCCESS) { + g_asyncStatus = ASYNC_STATUS_ERROR; + return; + } + while (g_asyncStatus == ASYNC_STATUS_WAITING) { + usleep(TEST_DEV_AUTH_SLEEP_TIME); + } + usleep(TEST_DEV_AUTH_SLEEP_TIME); +} + +static void CreateDemoIdenticalAccountGroup(int32_t osAccountId, int64_t reqId, const char *appId, + const char *registerInfoParams) +{ + g_asyncStatus = ASYNC_STATUS_WAITING; + const DeviceGroupManager *gm = GetGmInstance(); + ASSERT_NE(gm, nullptr); + char *returnData = nullptr; + int32_t ret = gm->getRegisterInfo(registerInfoParams, &returnData); + ASSERT_EQ(ret, HC_SUCCESS); + ASSERT_NE(returnData, nullptr); + string registerInfo(returnData); + + CJson *credJson = GetAsyCredentialJson(registerInfo); + ASSERT_NE(credJson, nullptr); + CJson *json = CreateJson(); + AddIntToJson(json, FIELD_GROUP_TYPE, IDENTICAL_ACCOUNT_GROUP); + AddStringToJson(json, FIELD_USER_ID, TEST_USER_ID); + AddObjToJson(json, FIELD_CREDENTIAL, credJson); + char *jsonStr = PackJsonToString(json); + FreeJson(credJson); + FreeJson(json); + gm->destroyInfo(&returnData); + ASSERT_NE(jsonStr, nullptr); + ret = gm->createGroup(osAccountId, reqId, appId, jsonStr); + FreeJsonString(jsonStr); + ASSERT_EQ(ret, HC_SUCCESS); + while (g_asyncStatus == ASYNC_STATUS_WAITING) { + usleep(TEST_DEV_AUTH_SLEEP_TIME); + } + usleep(TEST_DEV_AUTH_SLEEP_TIME); +} + +static void CreateDemoSymClientIdenticalAccountGroup(void) +{ + g_asyncStatus = ASYNC_STATUS_WAITING; + const DeviceGroupManager *gm = GetGmInstance(); + ASSERT_NE(gm, nullptr); + + CJson *credJson = CreateJson(); + (void)AddIntToJson(credJson, FIELD_CREDENTIAL_TYPE, SYMMETRIC_CRED); + (void)AddStringToJson(credJson, FIELD_AUTH_CODE, TEST_AUTH_CODE3); + CJson *json = CreateJson(); + AddIntToJson(json, FIELD_GROUP_TYPE, IDENTICAL_ACCOUNT_GROUP); + AddStringToJson(json, FIELD_USER_ID, TEST_USER_ID_AUTH); + AddObjToJson(json, FIELD_CREDENTIAL, credJson); + char *jsonStr = PackJsonToString(json); + FreeJson(credJson); + FreeJson(json); + if (jsonStr == nullptr) { + return; + } + int32_t ret = gm->createGroup(DEFAULT_OS_ACCOUNT, TEST_REQ_ID, TEST_APP_ID, jsonStr); + FreeJsonString(jsonStr); + ASSERT_EQ(ret, HC_SUCCESS); + while (g_asyncStatus == ASYNC_STATUS_WAITING) { + usleep(TEST_DEV_AUTH_SLEEP_TIME); + } + ASSERT_EQ(g_asyncStatus, ASYNC_STATUS_FINISH); +} + +static void CreateDemoSymServerIdenticalAccountGroup(void) +{ + g_asyncStatus = ASYNC_STATUS_WAITING; + const DeviceGroupManager *gm = GetGmInstance(); + ASSERT_NE(gm, nullptr); + + CJson *credJson = CreateJson(); + (void)AddIntToJson(credJson, FIELD_CREDENTIAL_TYPE, SYMMETRIC_CRED); + (void)AddStringToJson(credJson, FIELD_AUTH_CODE, TEST_AUTH_CODE3); + CJson *json = CreateJson(); + AddIntToJson(json, FIELD_GROUP_TYPE, IDENTICAL_ACCOUNT_GROUP); + AddStringToJson(json, FIELD_USER_ID, TEST_USER_ID_AUTH); + AddObjToJson(json, FIELD_CREDENTIAL, credJson); + char *jsonStr = PackJsonToString(json); + FreeJson(credJson); + FreeJson(json); + if (jsonStr == nullptr) { + return; + } + + int32_t ret = gm->createGroup(TEST_AUTH_OS_ACCOUNT_ID, TEST_REQ_ID, TEST_APP_ID, jsonStr); + FreeJsonString(jsonStr); + ASSERT_EQ(ret, HC_SUCCESS); + while (g_asyncStatus == ASYNC_STATUS_WAITING) { + usleep(TEST_DEV_AUTH_SLEEP_TIME); + } + ASSERT_EQ(g_asyncStatus, ASYNC_STATUS_FINISH); +} + +static void AddDemoMember(void) +{ + g_asyncStatus = ASYNC_STATUS_WAITING; + bool isClient = true; + SetDeviceStatus(isClient); + const DeviceGroupManager *gm = GetGmInstance(); + int32_t ret = gm->addMemberToGroup(DEFAULT_OS_ACCOUNT, TEST_REQ_ID, TEST_APP_ID, g_addParams); + if (ret != HC_SUCCESS) { + g_asyncStatus = ASYNC_STATUS_ERROR; + return; + } + while (g_asyncStatus == ASYNC_STATUS_WAITING) { + usleep(TEST_DEV_AUTH_SLEEP_TIME); + } + while (g_asyncStatus == ASYNC_STATUS_TRANSMIT) { + isClient = !isClient; + SetDeviceStatus(isClient); + g_asyncStatus = ASYNC_STATUS_WAITING; + if (isClient) { + ret = gm->processData(TEST_REQ_ID, g_transmitData, g_transmitDataLen); + } else { + ret = gm->processData(TEST_REQ_ID2, g_transmitData, g_transmitDataLen); + } + (void)memset_s(g_transmitData, g_transmitDataMaxLen, 0, g_transmitDataMaxLen); + g_transmitDataLen = 0; + if (ret != HC_SUCCESS) { + g_asyncStatus = ASYNC_STATUS_ERROR; + return; + } + while (g_asyncStatus == ASYNC_STATUS_WAITING) { + usleep(TEST_DEV_AUTH_SLEEP_TIME); + } + if (g_asyncStatus == ASYNC_STATUS_ERROR) { + break; + } + if (g_transmitDataLen > 0) { + g_asyncStatus = ASYNC_STATUS_TRANSMIT; + } + } + usleep(TEST_DEV_AUTH_SLEEP_TIME); + SetDeviceStatus(true); +} + +static void AuthDemoMember(void) +{ + g_asyncStatus = ASYNC_STATUS_WAITING; + bool isClient = true; + SetDeviceStatus(isClient); + const GroupAuthManager *ga = GetGaInstance(); + ASSERT_NE(ga, nullptr); + int32_t ret = ga->authDevice(DEFAULT_OS_ACCOUNT, TEST_REQ_ID, g_authParams, &g_gaCallback); + if (ret != HC_SUCCESS) { + g_asyncStatus = ASYNC_STATUS_ERROR; + return; + } + while (g_asyncStatus == ASYNC_STATUS_WAITING) { + usleep(TEST_DEV_AUTH_SLEEP_TIME); + } + while (g_asyncStatus == ASYNC_STATUS_TRANSMIT) { + isClient = !isClient; + SetDeviceStatus(isClient); + g_asyncStatus = ASYNC_STATUS_WAITING; + if (isClient) { + ret = ga->processData(TEST_REQ_ID, g_transmitData, g_transmitDataLen, &g_gaCallback); + } else { + ret = ga->processData(TEST_REQ_ID2, g_transmitData, g_transmitDataLen, &g_gaCallback); + } + (void)memset_s(g_transmitData, g_transmitDataMaxLen, 0, g_transmitDataMaxLen); + g_transmitDataLen = 0; + if (ret != HC_SUCCESS) { + g_asyncStatus = ASYNC_STATUS_ERROR; + return; + } + printf("start to wait...\n"); + while (g_asyncStatus == ASYNC_STATUS_WAITING) { + usleep(TEST_DEV_AUTH_SLEEP_TIME); + } + printf("wait finish...\n"); + if (g_asyncStatus == ASYNC_STATUS_ERROR) { + break; + } + if (g_transmitDataLen > 0) { + g_asyncStatus = ASYNC_STATUS_TRANSMIT; + } + } + SetDeviceStatus(true); +} + +class AuthDeviceFuncTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void AuthDeviceFuncTest::SetUpTestCase() {} +void AuthDeviceFuncTest::TearDownTestCase() {} + +void AuthDeviceFuncTest::SetUp() +{ + DeleteDatabase(); + InitExceptionController(); + HcInitMallocMonitor(); + cJSON_Hooks hooks = { + .malloc_fn = MockMallocForJson, + .free_fn = MockFree + }; + cJSON_InitHooks(&hooks); +} + +void AuthDeviceFuncTest::TearDown() +{ + bool isMemoryLeak = IsMemoryLeak(); + EXPECT_FALSE(isMemoryLeak); + if (isMemoryLeak) { + ReportMonitor(); + } + cJSON_Hooks hooks = { + .malloc_fn = malloc, + .free_fn = free + }; + cJSON_InitHooks(&hooks); + HcDestroyMallocMonitor(); + DestroyExceptionController(); +} + +HWTEST_F(AuthDeviceFuncTest, AuthDeviceFuncTest001, TestSize.Level0) +{ + int32_t ret = InitDeviceAuthService(); + ASSERT_EQ(ret, HC_SUCCESS); + const GroupAuthManager *ga = GetGaInstance(); + ASSERT_NE(ga, nullptr); + ret = ga->authDevice(DEFAULT_OS_ACCOUNT, TEST_REQ_ID, nullptr, &g_gmCallback); + ASSERT_EQ(ret, HC_ERR_INVALID_PARAMS); + DestroyDeviceAuthService(); +} + +HWTEST_F(AuthDeviceFuncTest, AuthDeviceFuncTest002, TestSize.Level0) +{ + int32_t ret = InitDeviceAuthService(); + ASSERT_EQ(ret, HC_SUCCESS); + const GroupAuthManager *ga = GetGaInstance(); + ASSERT_NE(ga, nullptr); + ret = ga->authDevice(DEFAULT_OS_ACCOUNT, TEST_REQ_ID, g_authParams, nullptr); + ASSERT_NE(ret, HC_SUCCESS); + DestroyDeviceAuthService(); +} + +HWTEST_F(AuthDeviceFuncTest, AuthDeviceFuncTest003, TestSize.Level0) +{ + SetIsoSupported(true); + SetPakeV1Supported(false); + int32_t ret = InitDeviceAuthService(); + ASSERT_EQ(ret, HC_SUCCESS); + const DeviceGroupManager *gm = GetGmInstance(); + ASSERT_NE(gm, nullptr); + ret = gm->regCallback(TEST_APP_ID, &g_gmCallback); + ASSERT_EQ(ret, HC_SUCCESS); + CreateDemoGroup(DEFAULT_OS_ACCOUNT, TEST_REQ_ID, TEST_APP_ID, g_createParams); + ASSERT_EQ(g_asyncStatus, ASYNC_STATUS_FINISH); + AddDemoMember(); + ASSERT_EQ(g_asyncStatus, ASYNC_STATUS_FINISH); + AuthDemoMember(); + ASSERT_EQ(g_asyncStatus, ASYNC_STATUS_FINISH); + DestroyDeviceAuthService(); +} + +HWTEST_F(AuthDeviceFuncTest, AuthDeviceFuncTest004, TestSize.Level0) +{ + SetIsoSupported(false); + SetPakeV1Supported(true); + int32_t ret = InitDeviceAuthService(); + ASSERT_EQ(ret, HC_SUCCESS); + const DeviceGroupManager *gm = GetGmInstance(); + ASSERT_NE(gm, nullptr); + ret = gm->regCallback(TEST_APP_ID, &g_gmCallback); + ASSERT_EQ(ret, HC_SUCCESS); + CreateDemoGroup(DEFAULT_OS_ACCOUNT, TEST_REQ_ID, TEST_APP_ID, g_createParams); + ASSERT_EQ(g_asyncStatus, ASYNC_STATUS_FINISH); + AddDemoMember(); + ASSERT_EQ(g_asyncStatus, ASYNC_STATUS_FINISH); + AuthDemoMember(); + ASSERT_EQ(g_asyncStatus, ASYNC_STATUS_FINISH); + DestroyDeviceAuthService(); +} + +HWTEST_F(AuthDeviceFuncTest, AuthDeviceFuncTest005, TestSize.Level0) +{ + SetIsoSupported(true); + SetPakeV1Supported(true); + int32_t ret = InitDeviceAuthService(); + ASSERT_EQ(ret, HC_SUCCESS); + const DeviceGroupManager *gm = GetGmInstance(); + ASSERT_NE(gm, nullptr); + ret = gm->regCallback(TEST_APP_ID, &g_gmCallback); + ASSERT_EQ(ret, HC_SUCCESS); + + SetDeviceStatus(true); + CreateDemoIdenticalAccountGroup(DEFAULT_OS_ACCOUNT, TEST_REQ_ID, TEST_APP_ID, g_getRegisterInfoParams); + ASSERT_EQ(g_asyncStatus, ASYNC_STATUS_FINISH); + + SetDeviceStatus(false); + CreateDemoIdenticalAccountGroup(TEST_AUTH_OS_ACCOUNT_ID, TEST_REQ_ID2, TEST_APP_ID, g_getRegisterInfoParams2); + ASSERT_EQ(g_asyncStatus, ASYNC_STATUS_FINISH); + + SetDeviceStatus(true); + AuthDemoMember(); + ASSERT_EQ(g_asyncStatus, ASYNC_STATUS_FINISH); + + DestroyDeviceAuthService(); +} + +HWTEST_F(AuthDeviceFuncTest, AuthDeviceFuncTest006, TestSize.Level0) +{ + SetIsoSupported(true); + SetPakeV1Supported(false); + int32_t ret = InitDeviceAuthService(); + ASSERT_EQ(ret, HC_SUCCESS); + const DeviceGroupManager *gm = GetGmInstance(); + ASSERT_NE(gm, nullptr); + ret = gm->regCallback(TEST_APP_ID, &g_gmCallback); + ASSERT_EQ(ret, HC_SUCCESS); + CreateDemoSymClientIdenticalAccountGroup(); + ASSERT_EQ(ret, HC_SUCCESS); + SetDeviceStatus(false); + CreateDemoSymServerIdenticalAccountGroup(); + SetDeviceStatus(true); + AuthDemoMember(); + ASSERT_EQ(g_asyncStatus, ASYNC_STATUS_FINISH); + DestroyDeviceAuthService(); +} + +HWTEST_F(AuthDeviceFuncTest, AuthDeviceFuncTest007, TestSize.Level0) +{ + SetIsoSupported(true); + SetPakeV1Supported(false); + int32_t ret = InitDeviceAuthService(); + ASSERT_EQ(ret, HC_SUCCESS); + const DeviceGroupManager *gm = GetGmInstance(); + ASSERT_NE(gm, nullptr); + ret = gm->regCallback(TEST_APP_ID, &g_gmCallback); + ASSERT_EQ(ret, HC_SUCCESS); + CreateDemoSymClientIdenticalAccountGroup(); + SetDeviceStatus(false); + CreateDemoSymServerIdenticalAccountGroup(); + SetDeviceStatus(true); + ret = gm->addMultiMembersToGroup(DEFAULT_OS_ACCOUNT, TEST_APP_ID, g_addParams4); + ASSERT_EQ(ret, HC_SUCCESS); + SetDeviceStatus(false); + ret = gm->addMultiMembersToGroup(TEST_AUTH_OS_ACCOUNT_ID, TEST_APP_ID, g_addParams5); + ASSERT_EQ(ret, HC_SUCCESS); + SetDeviceStatus(true); + AuthDemoMember(); + ASSERT_EQ(g_asyncStatus, ASYNC_STATUS_FINISH); + DestroyDeviceAuthService(); +} +} diff --git a/test/unittest/tdd_framework/tdd_framework.gni b/test/unittest/tdd_framework/tdd_framework.gni index f26277061602fa8f59a7aee99407b38e76d97cd6..93201c2e660947707862f417b10dae9dacfd8841 100644 --- a/test/unittest/tdd_framework/tdd_framework.gni +++ b/test/unittest/tdd_framework/tdd_framework.gni @@ -17,3 +17,25 @@ import("//base/security/huks/build/config.gni") import("//build/test.gni") tdd_framework_path = "//base/security/device_auth/test/unittest/tdd_framework" + +third_inc_path = [ + "//third_party/cJSON", + "//commonlibrary/c_utils/base/include", + "//third_party/openssl/include/", + "//third_party/mbedtls/include", + "//third_party/mbedtls/include/mbedtls", +] + +device_auth_lib_inc = inc_path + hals_inc_path + third_inc_path +device_auth_lib_src = + dev_frameworks_files + deviceauth_common_files + database_manager_files + + cred_manager_files + session_manager_files + session_v1_files + + session_v2_files + iso_protocol_files + ec_speke_protocol_files + + auth_code_import_files + pub_key_exchange_files + save_trusted_info_files + + creds_manager_files + broadcast_manager_files + + soft_bus_channel_mock_files + group_auth_files + + group_auth_account_unrelated_files + group_manager_files + + group_manager_peer_to_peer_files + authenticators_p2p_files + + authenticators_p2p_iso_files + authenticators_p2p_pake_files + + authenticators_standard_exchange_task_files + account_related_files + + privacy_enhancement_files + mk_agree_files diff --git a/test/unittest/tdd_framework/tdd_helper/dev_info_mock/inc/dev_info_mock.h b/test/unittest/tdd_framework/tdd_helper/dev_info_mock/inc/dev_info_mock.h index 0134f588964c78ef3ab23603587fc76096823fc2..13dff9a33b8ade21f993c496d74d7d90ed0a5d15 100644 --- a/test/unittest/tdd_framework/tdd_helper/dev_info_mock/inc/dev_info_mock.h +++ b/test/unittest/tdd_framework/tdd_helper/dev_info_mock/inc/dev_info_mock.h @@ -39,6 +39,7 @@ int32_t HcGetUdid(uint8_t *udid, int32_t udidLen); const char *GetStoragePath(void); const char *GetStorageDirPath(void); const char *GetAccountStoragePath(void); +const char *GetPseudonymStoragePath(void); void SetDeviceStatus(bool isClient); void SetAccountStorageTest(bool isAccountStorageTest); diff --git a/test/unittest/tdd_framework/tdd_helper/dev_info_mock/src/dev_info_mock.c b/test/unittest/tdd_framework/tdd_helper/dev_info_mock/src/dev_info_mock.c index 68029dde410fff832d2abb927b6301dac6b6e4bc..2d047d53d98a179626dbddd140d9570c730d3809 100644 --- a/test/unittest/tdd_framework/tdd_helper/dev_info_mock/src/dev_info_mock.c +++ b/test/unittest/tdd_framework/tdd_helper/dev_info_mock/src/dev_info_mock.c @@ -21,6 +21,7 @@ #define MOCK_STORAGE_FILE "/data/service/el1/public/deviceauthMock/hcgroup.dat" #define MOCK_STORAGE_DIR "/data/service/el1/public/deviceauthMock" #define MOCK_ACCOUNT_STORAGE_DIR "/data/service/el1/public/deviceauthMock/account" +#define MOCK_PSEUDONYM_STORAGE_DIR "/data/service/el1/public/deviceauthMock/pseudonym" static bool g_isClient = true; static char *g_clientDevUdid = "5420459D93FE773F9945FD64277FBA2CAB8FB996DDC1D0B97676FBB1242B3930"; @@ -65,3 +66,8 @@ const char *GetAccountStoragePath(void) { return MOCK_ACCOUNT_STORAGE_DIR; } + +const char *GetPseudonymStoragePath(void) +{ + return MOCK_PSEUDONYM_STORAGE_DIR; +} diff --git a/test/unittest/tdd_framework/tdd_helper/os_account_adapter_mock/src/os_account_adapter_mock.c b/test/unittest/tdd_framework/tdd_helper/os_account_adapter_mock/src/os_account_adapter_mock.c new file mode 100644 index 0000000000000000000000000000000000000000..c37116b76d08bab5b0ccd174deb0361273937eea --- /dev/null +++ b/test/unittest/tdd_framework/tdd_helper/os_account_adapter_mock/src/os_account_adapter_mock.c @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2023 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 "os_account_adapter.h" + +int32_t DevAuthGetRealOsAccountLocalId(int32_t inputId) +{ + return inputId; +} diff --git a/test/unittest/tdd_framework/tdd_helper/protocol_controller/inc/protocol_controller.h b/test/unittest/tdd_framework/tdd_helper/protocol_controller/inc/protocol_controller.h new file mode 100644 index 0000000000000000000000000000000000000000..1fa4ec0c582f3c4d25834058f3980cf8143e2804 --- /dev/null +++ b/test/unittest/tdd_framework/tdd_helper/protocol_controller/inc/protocol_controller.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2023 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 PROTOCOL_CONTROLLER_H +#define PROTOCOL_CONTROLLER_H + +#include "base_sub_task.h" +#include "json_utils.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void SetIsoSupported(bool isSupported); +void SetPakeV1Supported(bool isSupported); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/test/unittest/tdd_framework/tdd_helper/protocol_controller/src/protocol_controller.c b/test/unittest/tdd_framework/tdd_helper/protocol_controller/src/protocol_controller.c new file mode 100644 index 0000000000000000000000000000000000000000..5462f666aea60f2e405ddd26ef255c4a28717400 --- /dev/null +++ b/test/unittest/tdd_framework/tdd_helper/protocol_controller/src/protocol_controller.c @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2023 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 "hc_log.h" +#include "hc_types.h" +#include "iso_task_main.h" +#include "iso_base_cur_task.h" +#include "iso_client_task.h" +#include "iso_server_task.h" +#include "pake_v1_task_main.h" +#include "pake_base_cur_task.h" +#include "pake_v1_client_task.h" +#include "pake_v1_server_task.h" +#include "protocol_controller.h" + +static bool g_isIsoSupported = true; +static bool g_isPakeV1Supported = true; + +void SetPakeV1Supported(bool isSupported) +{ + g_isPakeV1Supported = isSupported; +} + +bool IsSupportPakeV1() +{ + if (g_isPakeV1Supported) { + LOGI("pake v1 support."); + } else { + LOGI("pake v1 not support."); + } + return g_isPakeV1Supported; +} + +SubTaskBase *CreatePakeV1SubTask(const CJson *in) +{ + bool isClient = true; + if (GetBoolFromJson(in, FIELD_IS_CLIENT, &isClient) != HC_SUCCESS) { + LOGE("Get isClient failed."); + return NULL; + } + if (isClient) { + return CreatePakeV1ClientTask(in); + } else { + return CreatePakeV1ServerTask(in); + } +} + +void SetIsoSupported(bool isSupported) +{ + g_isIsoSupported = isSupported; +} + +bool IsIsoSupported(void) +{ + if (g_isIsoSupported) { + LOGI("iso support."); + } else { + LOGI("iso not support."); + } + return g_isIsoSupported; +} + +SubTaskBase *CreateIsoSubTask(const CJson *in) +{ + bool isClient = true; + if (GetBoolFromJson(in, FIELD_IS_CLIENT, &isClient) != HC_SUCCESS) { + LOGE("Get isClient failed."); + return NULL; + } + if (isClient) { + return CreateIsoClientTask(in); + } else { + return CreateIsoServerTask(in); + } +} \ No newline at end of file diff --git a/test/unittest/tdd_framework/unit_test/services/creds_manager/BUILD.gn b/test/unittest/tdd_framework/unit_test/services/creds_manager/BUILD.gn index 309cccac44253dd2523bda29e61f02f038c0be76..c76d8e212b20a58d5c0b50ce90f6c0d5823f436d 100644 --- a/test/unittest/tdd_framework/unit_test/services/creds_manager/BUILD.gn +++ b/test/unittest/tdd_framework/unit_test/services/creds_manager/BUILD.gn @@ -20,7 +20,6 @@ ohos_unittest("creds_manager_test") { include_dirs = inc_path + hals_inc_path include_dirs += [ - "${dev_frameworks_path}/inc/hiview_adapter", "${tdd_framework_path}/common/inc", "//third_party/cJSON", "//third_party/openssl/include/",