diff --git a/common/include/dialog_ui/js/BUILD.gn b/common/include/dialog_ui/js/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0792bde2900fd3ac9b5176e43f724b8de178ce9f --- /dev/null +++ b/common/include/dialog_ui/js/BUILD.gn @@ -0,0 +1,22 @@ +# Copyright (c) 2021 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("//foundation/ace/ace_engine/build/ace_gen_sa_dialog_js.gni") +import("//foundation/distributedhardware/devicemanager/devicemanager.gni") + +gen_sa_dialog_js("dialog_js_files_etc") { + project_path = "//foundation/distributedhardware/devicemanager/common/include/dialog_ui/js" + dialog_name = "config_dialog_service" + part_name = "device_manager_base" + subsystem_name = "distributedhardware" +} diff --git a/common/include/dialog_ui/js/common/pincode.png b/common/include/dialog_ui/js/common/pincode.png new file mode 100644 index 0000000000000000000000000000000000000000..6616f7659fcf1d5da5ab6796863e32efbe086cdc Binary files /dev/null and b/common/include/dialog_ui/js/common/pincode.png differ diff --git a/common/include/dialog_ui/js/i18n/en-US.json b/common/include/dialog_ui/js/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..0714fc75f8420ac089a6ee1c24c8f2d8472ff511 --- /dev/null +++ b/common/include/dialog_ui/js/i18n/en-US.json @@ -0,0 +1,5 @@ +{ + "message":{ + "hello": "hello world" + } +} \ No newline at end of file diff --git a/common/include/dialog_ui/js/i18n/zh-CN.json b/common/include/dialog_ui/js/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..53afe2047da6ff0423e5eae8d9f9af9f73d85d0b --- /dev/null +++ b/common/include/dialog_ui/js/i18n/zh-CN.json @@ -0,0 +1,5 @@ +{ + "message": { + "hello": "你好世界" + } +} \ No newline at end of file diff --git a/common/include/dialog_ui/js/pages/index/index.css b/common/include/dialog_ui/js/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..b87a3962adeda987fcc5ff2a8d8a48dacdccfdbd --- /dev/null +++ b/common/include/dialog_ui/js/pages/index/index.css @@ -0,0 +1,41 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; + opacity: 0.8; + background-color: azure; +} + +.title { + font-size: 48px; + line-height: 70px; + font-weight: 800; +} + +.but { + width: 85%; + margin-top: 10%; + text-align: center; + height: 45px; +} + +.but1 { + width: 40%; + height: 36px; + font-size: 26px; + margin-left: 10%; +} + +.but2 { + width: 20%; + height: 36px; + font-size: 26px; + margin-left: 55%; +} + + +.title-list { + font-size: 38px; + line-height: 40px; + font-weight: 800; +} diff --git a/common/include/dialog_ui/js/pages/index/index.hml b/common/include/dialog_ui/js/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..81ab90ff6fae66e5bfecc149c1c581ccc8f9446a --- /dev/null +++ b/common/include/dialog_ui/js/pages/index/index.hml @@ -0,0 +1,16 @@ +
+ + 是否允许对端连接本机 + + + 用于分享图片 + +
+ + +
+
diff --git a/common/include/dialog_ui/js/pages/index/index.js b/common/include/dialog_ui/js/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..85c42a6e66d7319f15ca304b73bacae1b9fa928b --- /dev/null +++ b/common/include/dialog_ui/js/pages/index/index.js @@ -0,0 +1,29 @@ +import router from '@ohos.router' + +var times = 60; +export default { + data: { + message: router.getParams().targetPkgName, + }, + onInit() { + console.info('getParams: ' + router.getParams()); + this.timeRemaining = times; + const next = () => { + --this.timeRemaining; + if (this.timeRemaining > 0) { + setTimeout(next, 1000) + } else { + onCancel(); + } + } + next() + }, + onConfirm() { + console.info('click confirm'); + callNativeHandler("EVENT_CONFIRM", "0"); + }, + onCancel() { + console.info('click cancel'); + callNativeHandler("EVENT_CANCEL", "1"); + } +} \ No newline at end of file diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 492de42c1eab4429d8646330cfea50dc3829c173..7878b42661bc2549346f6e0e6ca7596d3cc8b51b 100644 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -172,6 +172,12 @@ const std::string BR_MAC = "BR_MAC"; const std::string BLE_MAC = "BLE_MAC"; const std::string ETH_IP = "ETH_IP"; const std::string ETH_PORT = "ETH_PORT"; + +// ACE +const int32_t ACE_X = 50; +const int32_t ACE_Y = 200; +const int32_t ACE_WIDTH = 400; +const int32_t ACE_HEIGHT = 200; } // namespace DistributedHardware } // namespace OHOS #endif diff --git a/ext/input_pin_dialog/dialog_ui/js/BUILD.gn b/ext/input_pin_dialog/dialog_ui/js/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8abf88695e272f47842c8c6549920376cff6b74b --- /dev/null +++ b/ext/input_pin_dialog/dialog_ui/js/BUILD.gn @@ -0,0 +1,22 @@ +# Copyright (c) 2021 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("//foundation/ace/ace_engine/build/ace_gen_sa_dialog_js.gni") +import("//foundation/distributedhardware/devicemanager/devicemanager.gni") + +gen_sa_dialog_js("dialog_js_files_etc") { + project_path = "//foundation/distributedhardware/devicemanager/ext/input_pin_dialog/dialog_ui/js" + dialog_name = "input_pin_service" + part_name = "device_manager_base" + subsystem_name = "distributedhardware" +} diff --git a/ext/input_pin_dialog/dialog_ui/js/common/KeyBoard.js b/ext/input_pin_dialog/dialog_ui/js/common/KeyBoard.js new file mode 100644 index 0000000000000000000000000000000000000000..c3234a50dc7569ed8bf587f6ea22899f0671b0f2 --- /dev/null +++ b/ext/input_pin_dialog/dialog_ui/js/common/KeyBoard.js @@ -0,0 +1,86 @@ + +;(function(exports){ + var KeyBoard = function(input, options){ + var body = document.getElementsByTagName('body')[0]; + var DIV_ID = options && options.divId || '__w_l_h_v_c_z_e_r_o_divid'; + + if(document.getElementById(DIV_ID)){ + body.removeChild(document.getElementById(DIV_ID)); + } + + this.input = input; + this.el = document.createElement('div'); + + var self = this; + var zIndex = options && options.zIndex || 1000; + var width = options && options.width || '100%'; + var height = options && options.height || '193px'; + var fontSize = options && options.fontSize || '15px'; + var backgroundColor = options && options.backgroundColor || '#fff'; + var TABLE_ID = options && options.table_id || 'table_0909099'; + var mobile = typeof orientation !== 'undefined'; + + this.el.id = DIV_ID; + this.el.style.position = 'absolute'; + this.el.style.left = 0; + this.el.style.right = 0; + this.el.style.bottom = 0; + this.el.style.zIndex = zIndex; + this.el.style.width = width; + this.el.style.height = height; + this.el.style.backgroundColor = backgroundColor; + + //样式 + var cssStr = ''; + + //Button + var btnStr = '
完成
'; + + //table + var tableStr = ''; + tableStr += ''; + tableStr += ''; + tableStr += ''; + tableStr += ''; + tableStr += ''; + tableStr += '
123
456
789
.0删除
'; + this.el.innerHTML = cssStr + btnStr + tableStr; + + function addEvent(e){ + var ev = e || window.event; + var clickEl = ev.element || ev.target; + var value = clickEl.textContent || clickEl.innerText; + if(clickEl.tagName.toLocaleLowerCase() === 'td' && value !== "删除"){ + if(self.input){ + self.input.value += value; + } + }else if(clickEl.tagName.toLocaleLowerCase() === 'div' && value === "完成"){ + body.removeChild(self.el); + }else if(clickEl.tagName.toLocaleLowerCase() === 'td' && value === "删除"){ + var num = self.input.value; + if(num){ + var newNum = num.substr(0, num.length - 1); + self.input.value = newNum; + } + } + } + + if(mobile){ + this.el.ontouchstart = addEvent; + }else{ + this.el.onclick = addEvent; + } + body.appendChild(this.el); + } + + exports.KeyBoard = KeyBoard; + +})(window); \ No newline at end of file diff --git a/ext/input_pin_dialog/dialog_ui/js/common/index.hml b/ext/input_pin_dialog/dialog_ui/js/common/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..3566d9ba28b0696c15f59dcf87adaa6155fb5430 --- /dev/null +++ b/ext/input_pin_dialog/dialog_ui/js/common/index.hml @@ -0,0 +1,32 @@ +
+ + PIN码连接 + + + 请输入另一个设备显示的PIN码进行验证 + + + + + PIN码输入错误,请重新输入 + +
+ + +
+ + + +
diff --git a/ext/input_pin_dialog/dialog_ui/js/common/pincode.png b/ext/input_pin_dialog/dialog_ui/js/common/pincode.png new file mode 100644 index 0000000000000000000000000000000000000000..6616f7659fcf1d5da5ab6796863e32efbe086cdc Binary files /dev/null and b/ext/input_pin_dialog/dialog_ui/js/common/pincode.png differ diff --git a/ext/input_pin_dialog/dialog_ui/js/i18n/en-US.json b/ext/input_pin_dialog/dialog_ui/js/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..0714fc75f8420ac089a6ee1c24c8f2d8472ff511 --- /dev/null +++ b/ext/input_pin_dialog/dialog_ui/js/i18n/en-US.json @@ -0,0 +1,5 @@ +{ + "message":{ + "hello": "hello world" + } +} \ No newline at end of file diff --git a/ext/input_pin_dialog/dialog_ui/js/i18n/zh-CN.json b/ext/input_pin_dialog/dialog_ui/js/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..53afe2047da6ff0423e5eae8d9f9af9f73d85d0b --- /dev/null +++ b/ext/input_pin_dialog/dialog_ui/js/i18n/zh-CN.json @@ -0,0 +1,5 @@ +{ + "message": { + "hello": "你好世界" + } +} \ No newline at end of file diff --git a/ext/input_pin_dialog/dialog_ui/js/pages/index/index.css b/ext/input_pin_dialog/dialog_ui/js/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..cf763b2ac3189d4cca6fde7322153616eb97f076 --- /dev/null +++ b/ext/input_pin_dialog/dialog_ui/js/pages/index/index.css @@ -0,0 +1,50 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; + opacity: 0.8; + background-color: azure; +} + +.title { + font-size: 48px; + line-height: 40px; + font-weight: 800; +} + +.title-list { + font-size: 30px; + line-height: 35px; + font-weight: 800; +} + +.title-error { + font-size: 15px; + line-height: 20px; + font-weight: 800; + color: #ff0000; +} + +.title-pin { + font-size: 30px; + line-height: 35px; + font-weight: 800; +} + +.but { + margin: 10px 20px 10px 20px; + width: 85%; + height: 40px; +} + +.but1 { + width: 80px; + height: 36px; + font-size: 26px; +} + +.but2 { + width: 80px; + height: 36px; + font-size: 26px; +} \ No newline at end of file diff --git a/ext/input_pin_dialog/dialog_ui/js/pages/index/index.hml b/ext/input_pin_dialog/dialog_ui/js/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..7f629df7a555519cf5e30f2191be38a589090b70 --- /dev/null +++ b/ext/input_pin_dialog/dialog_ui/js/pages/index/index.hml @@ -0,0 +1,23 @@ +
+ + PIN码连接 + + + 请输入另一个设备显示的PIN码进行验证 + + + + + +
+ + +
+ +
diff --git a/ext/input_pin_dialog/dialog_ui/js/pages/index/index.js b/ext/input_pin_dialog/dialog_ui/js/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..8a38e6188acbaa66a39bc57603c2a50ec94b7bee --- /dev/null +++ b/ext/input_pin_dialog/dialog_ui/js/pages/index/index.js @@ -0,0 +1,34 @@ +import router from '@ohos.router' + +var numbs = 0; +export default { + data: { + pincode: router.getParams().pinCode, + }, + onInit() { + console.info('getParams: ' + router.getParams()); + }, + onConfirm() { + console.info('click confirm'); + numbs = numbs + 1; + if (numbs < 3){ + var input= document.getElementById("input").value; + console.info('input: ' + input); + console.info('pincode: ' + pincode); + if (input == pincode){ + console.info('pincode: = input'); + callNativeHandler(input, "0"); + } else { + console.info('pincode: != input'); + //刷新页面,提示输入错误 + } + } else { + console.info('click cancel'); + callNativeHandler("EVENT_CONFIRM", "1"); + } + }, + onCancel() { + console.info('click cancel'); + callNativeHandler("EVENT_CONFIRM", "1"); + } +} \ No newline at end of file diff --git a/ext/pin_auth/BUILD.gn b/ext/pin_auth/BUILD.gn index 603d4ff14d53df50cfdca566af1ab3cae631d406..8372234686b1d855b3940683177a7c80e5050305 100644 --- a/ext/pin_auth/BUILD.gn +++ b/ext/pin_auth/BUILD.gn @@ -25,10 +25,38 @@ if (defined(ohos_lite)) { include_dirs = [ "include", "${common_path}/include", - "${services_path}/include/adapter", "${ext_path}/pin_auth/include/ability", + "${services_path}/include/dependency/timer", + "${services_path}/include/config", + "${services_path}/include/adapter", "${services_path}/include/authentication", + "${services_path}/include/ability", + "${services_path}/include/deviceinfo", + "${services_path}/include/devicestate", + "${services_path}/include/discovery", + "${services_path}/include/dependency/commonevent", + "${services_path}/include/dependency/hichain", + "${services_path}/include/dependency/softbus", + "${services_path}/include/dependency/timer", + "${services_path}/include/ipc", + "${services_path}/include/ipc/standard", "${utils_path}/include", + "${utils_path}/include/ipc/standard", + "${services_path}/include", + "${innerkits_path}/native_cpp/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/ipc/standard", + "//third_party/json/include", + "//utils/native/base/include", + "//utils/system/safwk/native/include", + "//base/notification/ces_standard/frameworks/core/include", + "//base/notification/ces_standard/interfaces/innerkits/native/include", + "//base/security/deviceauth/interfaces/innerkits", + "//base/startup/syspara_lite/interfaces/kits", + "//base/startup/syspara_lite/adapter/native/syspara/include", ] sources = [ @@ -38,20 +66,33 @@ if (defined(ohos_lite)) { ] deps = [ + "${ext_path}/input_pin_dialog/dialog_ui/js:dialog_js_files_etc", + "${ext_path}/show_pin_dialog/dialog_ui/js:dialog_js_files_etc", + "${innerkits_path}/native_cpp:devicemanagersdk", "${utils_path}:devicemanagerutils", + "//base/security/deviceauth/services:deviceauth_sdk", "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", "//foundation/aafwk/standard/interfaces/innerkits/want:want", "//foundation/aafwk/standard/services/abilitymgr:abilityms", + "//foundation/ace/ace_engine/interfaces/innerkits/ui_service_manager:ui_service_mgr", + "//foundation/distributedhardware/devicemanager/services/devicemanagerservice:devicemanagerservice", + "//foundation/windowmanager/wm:libwm", "//utils/native/base:utils", ] external_deps = [ - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", + "appexecfwk_standard:appexecfwk_base", + "appexecfwk_standard:appexecfwk_core", + "appexecfwk_standard:libeventhandler", + "ces_standard:cesfwk_core", + "ces_standard:cesfwk_innerkits", + "dsoftbus_standard:softbus_client", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", "startup_l2:syspara", + "startup_l2:syspara_watchagent", ] defines = [ diff --git a/ext/pin_auth/include/pin_auth.h b/ext/pin_auth/include/pin_auth.h index 2129c94a1a5cd949d018fdb30bcca668f5efc474..b2636e0afdd1ce1906183fe10649debb1a3825ea 100644 --- a/ext/pin_auth/include/pin_auth.h +++ b/ext/pin_auth/include/pin_auth.h @@ -20,6 +20,7 @@ #include #include "authentication.h" +#include "dm_auth_manager.h" #include "dm_ability_manager.h" #include "pin_auth_ui.h" @@ -29,8 +30,8 @@ class PinAuth : public IAuthentication { public: PinAuth(); ~PinAuth(); - int32_t ShowAuthInfo() override; - int32_t StartAuth(std::shared_ptr dmAbilityManager) override; + int32_t ShowAuthInfo(int32_t code) override; + int32_t StartAuth(int32_t code, std::shared_ptr authManager) override; int32_t VerifyAuthentication(std::string pinToken, int32_t code, const std::string &authParam) override; private: diff --git a/ext/pin_auth/include/pin_auth_ui.h b/ext/pin_auth/include/pin_auth_ui.h index f8910cba26fe134c29fd199449c8ba622da6018d..61575797f893e15ade0b58883a0820823fbe6fb8 100644 --- a/ext/pin_auth/include/pin_auth_ui.h +++ b/ext/pin_auth/include/pin_auth_ui.h @@ -18,6 +18,7 @@ #include +#include "dm_auth_manager.h" #include "dm_ability_manager.h" namespace OHOS { @@ -25,8 +26,8 @@ namespace DistributedHardware { class PinAuthUi { public: PinAuthUi(); - int32_t ShowPinDialog(); - int32_t InputPinDialog(std::shared_ptr dmAbilityManager); + int32_t ShowPinDialog(int32_t code); + int32_t InputPinDialog(int32_t code, std::shared_ptr authManager); private: int32_t StartFaUiService(std::shared_ptr dmAbilityManager); diff --git a/ext/pin_auth/src/pin_auth.cpp b/ext/pin_auth/src/pin_auth.cpp index 5e123b0c550dc0f5b51059b318390dee00151e73..138abc56fa23141fe5a180e07d6bdeca3b271edd 100644 --- a/ext/pin_auth/src/pin_auth.cpp +++ b/ext/pin_auth/src/pin_auth.cpp @@ -33,15 +33,14 @@ PinAuth::~PinAuth() { } -int32_t PinAuth::ShowAuthInfo() +int32_t PinAuth::ShowAuthInfo(int32_t code) { - return pinAuthUi_->ShowPinDialog(); + return pinAuthUi_->ShowPinDialog(code); } -int32_t PinAuth::StartAuth(std::shared_ptr dmAbilityManager) +int32_t PinAuth::StartAuth(int32_t code, std::shared_ptr authManager) { - times_ = 0; - return pinAuthUi_->InputPinDialog(dmAbilityManager); + return pinAuthUi_->InputPinDialog(code, authManager); } int32_t PinAuth::VerifyAuthentication(std::string pinToken, int32_t code, const std::string &authParam) diff --git a/ext/pin_auth/src/pin_auth_ui.cpp b/ext/pin_auth/src/pin_auth_ui.cpp index 691e5005239562cdeed0aad76f73cabbbaf91826..a3cfeefe271caa8d20a610b19cd8124fa35476ff 100644 --- a/ext/pin_auth/src/pin_auth_ui.cpp +++ b/ext/pin_auth/src/pin_auth_ui.cpp @@ -18,6 +18,8 @@ #include "dm_ability_manager.h" #include "dm_constants.h" #include "dm_log.h" +#include "nlohmann/json.hpp" +#include "ui_service_mgr_client.h" namespace OHOS { namespace DistributedHardware { @@ -26,18 +28,47 @@ PinAuthUi::PinAuthUi() LOGI("AuthUi constructor"); } -int32_t PinAuthUi::ShowPinDialog() +int32_t PinAuthUi::ShowPinDialog(int32_t code) { + LOGI("ShowPinDialog start"); + nlohmann::json jsonObj; + jsonObj[PIN_CODE_KEY] = code; + jsonObj.dump(); + const std::string params = jsonObj.dump(); + + Ace::UIServiceMgrClient::GetInstance()->ShowDialog( + "show_pin_service", + params, + OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, + ACE_X, ACE_Y, ACE_WIDTH, ACE_HEIGHT, + [](int32_t id, const std::string& event, const std::string& params) { + LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + }); + LOGI("ShowConfigDialog end"); return DM_OK; } -int32_t PinAuthUi::InputPinDialog(std::shared_ptr dmAbilityManager) +int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr authManager) { - if (dmAbilityManager == nullptr) { - LOGE("PinAuthUi::dmAbilityManager is null"); - return DM_FAILED; - } - return StartFaUiService(dmAbilityManager); + LOGI("InputPinDialog start"); + nlohmann::json jsonObj; + jsonObj[PIN_CODE_KEY] = code; + jsonObj.dump(); + const std::string params = jsonObj.dump(); + + Ace::UIServiceMgrClient::GetInstance()->ShowDialog( + "input_pin_service", + params, + OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, + ACE_X, ACE_Y, ACE_WIDTH, ACE_HEIGHT, + [authManager](int32_t id, const std::string& event, const std::string& params) { + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); + authManager->VerifyPinAuthAuthentication(params.c_str()); + }); + LOGI("ShowConfigDialog end"); + return DM_OK; } int32_t PinAuthUi::StartFaUiService(std::shared_ptr dmAbilityManager) diff --git a/ext/show_pin_dialog/dialog_ui/js/BUILD.gn b/ext/show_pin_dialog/dialog_ui/js/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8c623e7f87ffeec940e5f3a0730114001f79f6e0 --- /dev/null +++ b/ext/show_pin_dialog/dialog_ui/js/BUILD.gn @@ -0,0 +1,22 @@ +# Copyright (c) 2021 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("//foundation/ace/ace_engine/build/ace_gen_sa_dialog_js.gni") +import("//foundation/distributedhardware/devicemanager/devicemanager.gni") + +gen_sa_dialog_js("dialog_js_files_etc") { + project_path = "//foundation/distributedhardware/devicemanager/ext/show_pin_dialog/dialog_ui/js" + dialog_name = "show_pin_service" + part_name = "device_manager_base" + subsystem_name = "distributedhardware" +} diff --git a/ext/show_pin_dialog/dialog_ui/js/common/pincode.png b/ext/show_pin_dialog/dialog_ui/js/common/pincode.png new file mode 100644 index 0000000000000000000000000000000000000000..6616f7659fcf1d5da5ab6796863e32efbe086cdc Binary files /dev/null and b/ext/show_pin_dialog/dialog_ui/js/common/pincode.png differ diff --git a/ext/show_pin_dialog/dialog_ui/js/i18n/en-US.json b/ext/show_pin_dialog/dialog_ui/js/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..0714fc75f8420ac089a6ee1c24c8f2d8472ff511 --- /dev/null +++ b/ext/show_pin_dialog/dialog_ui/js/i18n/en-US.json @@ -0,0 +1,5 @@ +{ + "message":{ + "hello": "hello world" + } +} \ No newline at end of file diff --git a/ext/show_pin_dialog/dialog_ui/js/i18n/zh-CN.json b/ext/show_pin_dialog/dialog_ui/js/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..53afe2047da6ff0423e5eae8d9f9af9f73d85d0b --- /dev/null +++ b/ext/show_pin_dialog/dialog_ui/js/i18n/zh-CN.json @@ -0,0 +1,5 @@ +{ + "message": { + "hello": "你好世界" + } +} \ No newline at end of file diff --git a/ext/show_pin_dialog/dialog_ui/js/pages/index/index.css b/ext/show_pin_dialog/dialog_ui/js/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..feb20b4fd6d734135fa8b35d2a8fce28b34b69f2 --- /dev/null +++ b/ext/show_pin_dialog/dialog_ui/js/pages/index/index.css @@ -0,0 +1,31 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; + opacity: 0.8; + background-color: azure; +} + +.title { + font-size: 48px; + line-height: 50px; + font-weight: 800; +} + +.title-list { + font-size: 38px; + line-height: 40px; + font-weight: 800; +} + +.title-pin { + font-size: 48px; + line-height: 50px; + font-weight: 800; +} + +.but { + width: 100%; + font-size: 26px; + height: 36px; +} \ No newline at end of file diff --git a/ext/show_pin_dialog/dialog_ui/js/pages/index/index.hml b/ext/show_pin_dialog/dialog_ui/js/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..9cb650aefdc7650e308f4202a3b9ca0ee11cba57 --- /dev/null +++ b/ext/show_pin_dialog/dialog_ui/js/pages/index/index.hml @@ -0,0 +1,14 @@ +
+ + PIN码连接 + + + 请在设备端输入链接码进行验证 + + + {{ pincode }} + + +
\ No newline at end of file diff --git a/ext/show_pin_dialog/dialog_ui/js/pages/index/index.js b/ext/show_pin_dialog/dialog_ui/js/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..114655c3a4d334a82a2e5a2186be08df84bea372 --- /dev/null +++ b/ext/show_pin_dialog/dialog_ui/js/pages/index/index.js @@ -0,0 +1,14 @@ +import router from '@ohos.router' + +export default { + data: { + pincode: router.getParams().pinCode, + }, + onInit() { + console.info('getParams: ' + router.getParams()); + }, + onConfirm() { + console.info('click confirm'); + callNativeHandler("EVENT_CONFIRM", "1"); + } +} \ No newline at end of file diff --git a/services/devicemanagerservice/BUILD.gn b/services/devicemanagerservice/BUILD.gn index ea83ecfab54b6214efdd8262f65c7d32968768ea..f4359edcc645959257b185de9c1af264a2656d47 100644 --- a/services/devicemanagerservice/BUILD.gn +++ b/services/devicemanagerservice/BUILD.gn @@ -57,6 +57,7 @@ if (defined(ohos_lite)) { "//base/startup/syspara_lite/interfaces/kits", "//base/startup/syspara_lite/adapter/native/syspara/include", "//third_party/json/include", + "//third_party/flutter/skia", ] sources = [ @@ -85,12 +86,15 @@ if (defined(ohos_lite)) { ] deps = [ + "${common_path}/include/dialog_ui/js:dialog_js_files_etc", "${innerkits_path}/native_cpp:devicemanagersdk", "${utils_path}:devicemanagerutils", "//base/security/deviceauth/services:deviceauth_sdk", "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", "//foundation/aafwk/standard/interfaces/innerkits/want:want", "//foundation/aafwk/standard/services/abilitymgr:abilityms", + "//foundation/ace/ace_engine/interfaces/innerkits/ui_service_manager:ui_service_mgr", + "//foundation/windowmanager/wm:libwm", "//utils/native/base:utils", ] @@ -102,12 +106,12 @@ if (defined(ohos_lite)) { external_deps = [ "ability_runtime:app_manager", - "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_core", "ces_standard:cesfwk_innerkits", "dsoftbus_standard:softbus_client", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/services/devicemanagerservice/include/authentication/authentication.h b/services/devicemanagerservice/include/authentication/authentication.h index 5783f11125a23e813979ae3249a9cfd3d3d97603..43c486511f474a6ff795b3554e82bb8a6f4f4665 100644 --- a/services/devicemanagerservice/include/authentication/authentication.h +++ b/services/devicemanagerservice/include/authentication/authentication.h @@ -20,11 +20,12 @@ namespace OHOS { namespace DistributedHardware { +class DmAuthManager; class IAuthentication { public: virtual ~IAuthentication() = default; - virtual int32_t ShowAuthInfo() = 0; - virtual int32_t StartAuth(std::shared_ptr dmAbilityManager) = 0; + virtual int32_t ShowAuthInfo(int32_t code) = 0; + virtual int32_t StartAuth(int32_t code, std::shared_ptr authManager) = 0; virtual int32_t VerifyAuthentication(std::string pinToken, int32_t code, const std::string &authParam) = 0; }; diff --git a/services/devicemanagerservice/include/authentication/dm_auth_manager.h b/services/devicemanagerservice/include/authentication/dm_auth_manager.h index 2ea42c9b7c8a6bbe7bff6a445610ba6f8ea97bf0..6b0298ec907ad3c7c70e83bf738b05e8cb741d5f 100644 --- a/services/devicemanagerservice/include/authentication/dm_auth_manager.h +++ b/services/devicemanagerservice/include/authentication/dm_auth_manager.h @@ -129,6 +129,7 @@ public: const std::string &extra); int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId); int32_t VerifyAuthentication(const std::string &authParam); + void VerifyPinAuthAuthentication(const std::string &action); void OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result); void OnSessionClosed(int32_t sessionId); void OnDataReceived(int32_t sessionId, std::string message); diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index 0f11031b5c4829619d234ceaad7f3f039bba1f6c..1e9976f44f3f49ccf3613bbc1dfaa33a1fabfc96 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -24,6 +24,9 @@ #include "dm_random.h" #include "nlohmann/json.hpp" #include "parameter.h" +#include "ui_service_mgr_client.h" +#include "dialog_callback_stub.h" +#include "dialog_callback.h" namespace OHOS { namespace DistributedHardware { @@ -97,7 +100,7 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au } if (extra.empty()) { LOGE("AuthenticateDevice failed, extra is empty"); - listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT, DM_AUTH_BUSINESS_BUSY); + listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT, DM_INPUT_PARA_EMPTY); return DM_INPUT_PARA_EMPTY; } @@ -652,31 +655,61 @@ int32_t DmAuthManager::GetPinCode() void DmAuthManager::ShowConfigDialog() { - std::shared_ptr authUi_ = std::make_shared(); - dmAbilityMgr_ = std::make_shared(); - authUi_->ShowConfirmDialog(dmAbilityMgr_); + LOGI("ShowConfigDialog start"); + nlohmann::json jsonObj; + jsonObj[TAG_AUTH_TYPE] = AUTH_TYPE_PIN; + jsonObj[TAG_TOKEN] = authResponseContext_->token; + jsonObj[TARGET_PKG_NAME_KEY] = authResponseContext_->targetPkgName; + jsonObj.dump(); + const std::string params = jsonObj.dump(); + std::shared_ptr authMgr_ = shared_from_this(); + + Ace::UIServiceMgrClient::GetInstance()->ShowDialog( + "config_dialog_service", + params, + OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, + ACE_X, ACE_Y, ACE_WIDTH, ACE_HEIGHT, + [authMgr_](int32_t id, const std::string& event, const std::string& params) { + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); + authMgr_->StartAuthProcess(atoi(params.c_str())); + }); + LOGI("ShowConfigDialog end"); } void DmAuthManager::ShowAuthInfoDialog() { - return; + LOGI("DmAuthManager::ShowAuthInfoDialog start"); + authResponseContext_->code = GeneratePincode(); + std::shared_ptr ptr; + if (authenticationMap_.find(1) == authenticationMap_.end()) { + LOGE("DmAuthManager::authenticationMap_ is null"); + return; + } + ptr = authenticationMap_[1]; + LOGI("ShowAuthInfoDialog code:%d", authResponseContext_->code); + ptr->ShowAuthInfo(authResponseContext_->code); } void DmAuthManager::ShowStartAuthDialog() { LOGI("DmAuthManager::ShowStartAuthDialog start"); - dmAbilityMgr_ = std::make_shared(); std::shared_ptr ptr; if (authenticationMap_.find(1) == authenticationMap_.end()) { LOGE("DmAuthManager::authenticationMap_ is null"); return; } ptr = authenticationMap_[1]; - ptr->StartAuth(dmAbilityMgr_); + ptr->StartAuth(authResponseContext_->code, shared_from_this()); } int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam) { + if (dmAbilityMgr_ == nullptr) { + LOGI("dmAbilityMgr_ is nullptr"); + return DM_POINT_NULL; + } + dmAbilityMgr_->StartAbilityDone(); AbilityRole role = dmAbilityMgr_->GetAbilityRole(); authParam.direction = (int32_t)role; @@ -737,5 +770,20 @@ void DmAuthManager::UserSwitchEventCallback (void) } } } + +void DmAuthManager::VerifyPinAuthAuthentication(const std::string &action) +{ + LOGI("DmAuthManager::VerifyPinAuthAuthentication"); + timerMap_[INPUT_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); + if (action == "0") { + authRequestState_->TransitionTo(std::make_shared()); + } + if (action == "1") { + authRequestContext_->reason = DM_AUTH_INPUT_FAILED; + authResponseContext_->state = authRequestState_->GetStateType(); + authRequestState_->TransitionTo(std::make_shared()); + } + LOGI("DmAuthManager::VerifyAuthentication complete"); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp index bc012d3f3c15def94a26b681ae77a77c7a2b76e3..4137339229c406342a6e13d77446dd981972f045 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp @@ -443,14 +443,15 @@ void SoftbusConnector::OnSoftBusDeviceOnline(NodeBasicInfo *info) return; } - if (discoveryDeviceInfoMap_.empty()) { - return; - } DmDeviceInfo dmDeviceInfo; CovertNodeBasicInfoToDmDevice(*info, dmDeviceInfo); for (auto &iter : stateCallbackMap_) { iter.second->OnDeviceOnline(iter.first, dmDeviceInfo); } + + if (discoveryDeviceInfoMap_.empty()) { + return; + } // remove the discovery node map uint8_t udid[UDID_BUF_LEN] = {0}; int32_t ret = diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index e0c86fdd81062d659da9768e3c75d2f71d12b7ec..fd0d387c720c81215493e802c43a7c7fea2765dc 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -358,12 +358,12 @@ ohos_static_library("device_manager_test") { ] external_deps = [ - "appexecfwk_standard:libeventhandler", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_core", "ces_standard:cesfwk_innerkits", "dsoftbus_standard:softbus_client", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/test/unittest/UTTest_auth_message_processor.cpp b/test/unittest/UTTest_auth_message_processor.cpp index 2aa55bf3f40809e3e26dcf2147701248c7d3a95c..c648ff9b52b6ae56a1021a068df91b8f230e7bc2 100644 --- a/test/unittest/UTTest_auth_message_processor.cpp +++ b/test/unittest/UTTest_auth_message_processor.cpp @@ -37,6 +37,9 @@ void AuthMessageProcessorTest::TearDownTestCase() } namespace { +std::shared_ptr softbusConnector = std::make_shared(); +std::shared_ptr listener = std::make_shared(); +std::shared_ptr hiChainConnector_ = std::make_shared(); /** * @tc.name: AuthMessageProcessor::CreateNegotiateMessage_001 * @tc.desc: 1 set cryptoAdapter_ to null @@ -47,10 +50,8 @@ namespace { */ HWTEST_F(AuthMessageProcessorTest, CreateNegotiateMessage_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr hiChainConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr data = std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr data = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->authResponseContext_ = std::make_shared(); @@ -73,7 +74,6 @@ HWTEST_F(AuthMessageProcessorTest, CreateNegotiateMessage_001, testing::ext::Tes jsonObject[TAG_LOCAL_DEVICE_ID] = authMessageProcessor->authResponseContext_->localDeviceId; std::string str2 = jsonObject.dump(); ASSERT_EQ(str1, str2); - sleep(15); } /** @@ -84,10 +84,9 @@ HWTEST_F(AuthMessageProcessorTest, CreateNegotiateMessage_001, testing::ext::Tes */ HWTEST_F(AuthMessageProcessorTest, CreateSyncGroupMessage_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr hiChainConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr data = std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr hiChainConnector_ = std::make_shared(); + std::shared_ptr data = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authMessageProcessor = std::make_shared(data); authMessageProcessor->authRequestContext_ = std::make_shared(); nlohmann::json jsona; @@ -102,7 +101,6 @@ HWTEST_F(AuthMessageProcessorTest, CreateSyncGroupMessage_001, testing::ext::Tes std::string str1 = jsona.dump(); std::string str2 = jsonObj.dump(); ASSERT_EQ(str1, str2); - sleep(15); } /** @@ -113,10 +111,9 @@ HWTEST_F(AuthMessageProcessorTest, CreateSyncGroupMessage_001, testing::ext::Tes */ HWTEST_F(AuthMessageProcessorTest, CreateResponseAuthMessage_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr hiChainConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr data = std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr hiChainConnector_ = std::make_shared(); + std::shared_ptr data = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authMessageProcessor = std::make_shared(data); authMessageProcessor->authResponseContext_ = std::make_shared(); nlohmann::json jsona; @@ -143,7 +140,6 @@ HWTEST_F(AuthMessageProcessorTest, CreateResponseAuthMessage_001, testing::ext:: std::string str1 = jsona.dump(); std::string str2 = jsonObj.dump(); ASSERT_EQ(str1, str2); - sleep(15); } /** @@ -154,9 +150,9 @@ HWTEST_F(AuthMessageProcessorTest, CreateResponseAuthMessage_001, testing::ext:: */ HWTEST_F(AuthMessageProcessorTest, CreateResponseFinishMessage_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr hiChainConnector_ = std::make_shared(); + std::shared_ptr data = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authMessageProcessor = std::make_shared(data); authMessageProcessor->authResponseContext_ = std::make_shared(); nlohmann::json jsona; @@ -167,7 +163,6 @@ HWTEST_F(AuthMessageProcessorTest, CreateResponseFinishMessage_001, testing::ext std::string str1 = jsona.dump(); std::string str2 = jsonObj.dump(); ASSERT_EQ(str1, str2); - sleep(15); } /** @@ -178,9 +173,9 @@ HWTEST_F(AuthMessageProcessorTest, CreateResponseFinishMessage_001, testing::ext */ HWTEST_F(AuthMessageProcessorTest, ParseResponseFinishMessage_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr hiChainConnector_ = std::make_shared(); + std::shared_ptr data = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->authResponseContext_ = std::make_shared(); @@ -190,7 +185,6 @@ HWTEST_F(AuthMessageProcessorTest, ParseResponseFinishMessage_001, testing::ext: authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseResponseFinishMessage(jsonObj); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); - sleep(15); } /** @@ -201,9 +195,9 @@ HWTEST_F(AuthMessageProcessorTest, ParseResponseFinishMessage_001, testing::ext: */ HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr hiChainConnector_ = std::make_shared(); + std::shared_ptr data = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); nlohmann::json jsona; @@ -226,7 +220,6 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_001, testing::ext::T authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseAuthResponseMessage(jsona); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); - sleep(15); } /** @@ -237,9 +230,9 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_001, testing::ext::T */ HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr hiChainConnector_ = std::make_shared(); + std::shared_ptr data = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->SetResponseContext(authResponseContext); @@ -262,7 +255,6 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_001, testing::ext::Te authMessageProcessor->authSplitJsonList_.push_back(jsonThumbnail); int32_t ret = authMessageProcessor->ParseAuthRequestMessage(); ASSERT_EQ(ret, DM_FAILED); - sleep(15); } /** @@ -273,9 +265,9 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_001, testing::ext::Te */ HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_002, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr hiChainConnector_ = std::make_shared(); + std::shared_ptr data = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->SetResponseContext(authResponseContext); @@ -298,7 +290,6 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_002, testing::ext::Te authMessageProcessor->authSplitJsonList_.push_back(jsonThumbnail); int32_t ret = authMessageProcessor->ParseAuthRequestMessage(); ASSERT_EQ(ret, DM_OK); - sleep(15); } /** @@ -309,9 +300,9 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_002, testing::ext::Te */ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr hiChainConnector_ = std::make_shared(); + std::shared_ptr data = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->authResponseContext_ = std::make_shared(); @@ -327,7 +318,6 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_001, testing::ext::Test authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseNegotiateMessage(jsonObj); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); - sleep(15); } /** @@ -338,9 +328,9 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_001, testing::ext::Test */ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_002, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr hiChainConnector_ = std::make_shared(); + std::shared_ptr data = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->authResponseContext_ = std::make_shared(); @@ -356,7 +346,6 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_002, testing::ext::Test authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseNegotiateMessage(jsonObj); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); - sleep(15); } /** @@ -367,9 +356,9 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_002, testing::ext::Test */ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_003, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr hiChainConnector_ = std::make_shared(); + std::shared_ptr data = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->authResponseContext_ = std::make_shared(); @@ -385,7 +374,6 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_003, testing::ext::Test authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseNegotiateMessage(jsonObj); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); - sleep(15); } /** @@ -396,9 +384,9 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_003, testing::ext::Test */ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_004, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr hiChainConnector_ = std::make_shared(); + std::shared_ptr data = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->authResponseContext_ = std::make_shared(); @@ -414,7 +402,6 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_004, testing::ext::Test authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseNegotiateMessage(jsonObj); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); - sleep(15); } /** @@ -425,9 +412,9 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_004, testing::ext::Test */ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_005, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr hiChainConnector_ = std::make_shared(); + std::shared_ptr data = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->authResponseContext_ = std::make_shared(); @@ -443,7 +430,6 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_005, testing::ext::Test authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseNegotiateMessage(jsonObj); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); - sleep(15); } /** @@ -454,14 +440,13 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_005, testing::ext::Test */ HWTEST_F(AuthMessageProcessorTest, SetRequestContext_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr hiChainConnector_ = std::make_shared(); + std::shared_ptr data = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authRequestContext = std::make_shared(); authMessageProcessor->SetRequestContext(authRequestContext); ASSERT_EQ(authMessageProcessor->authRequestContext_, authRequestContext); - sleep(15); } /** @@ -472,14 +457,13 @@ HWTEST_F(AuthMessageProcessorTest, SetRequestContext_001, testing::ext::TestSize */ HWTEST_F(AuthMessageProcessorTest, SetRequestContext_002, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr hiChainConnector_ = std::make_shared(); + std::shared_ptr data = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authRequestContext = std::make_shared(); authMessageProcessor->SetRequestContext(nullptr); ASSERT_EQ(authMessageProcessor->authRequestContext_, nullptr); - sleep(15); } /** @@ -490,14 +474,13 @@ HWTEST_F(AuthMessageProcessorTest, SetRequestContext_002, testing::ext::TestSize */ HWTEST_F(AuthMessageProcessorTest, SetResponseContext_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr hiChainConnector_ = std::make_shared(); + std::shared_ptr data = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->SetResponseContext(authResponseContext); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); - sleep(15); } /** @@ -508,14 +491,13 @@ HWTEST_F(AuthMessageProcessorTest, SetResponseContext_001, testing::ext::TestSiz */ HWTEST_F(AuthMessageProcessorTest, SetResponseContext_002, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr hiChainConnector_ = std::make_shared(); + std::shared_ptr data = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->SetResponseContext(nullptr); ASSERT_EQ(authMessageProcessor->authResponseContext_, nullptr); - sleep(15); } /** @@ -526,14 +508,13 @@ HWTEST_F(AuthMessageProcessorTest, SetResponseContext_002, testing::ext::TestSiz */ HWTEST_F(AuthMessageProcessorTest, GetResponseContext_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr hiChainConnector_ = std::make_shared(); + std::shared_ptr data = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authMessageProcessor = std::make_shared(data); authMessageProcessor->authResponseContext_ = std::make_shared(); std::shared_ptr authResponseContext = authMessageProcessor->GetResponseContext(); ASSERT_EQ(authResponseContext, authMessageProcessor->authResponseContext_); - sleep(15); } /** @@ -544,14 +525,13 @@ HWTEST_F(AuthMessageProcessorTest, GetResponseContext_001, testing::ext::TestSiz */ HWTEST_F(AuthMessageProcessorTest, GetResponseContext_002, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr hiChainConnector_ = std::make_shared(); + std::shared_ptr data = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authMessageProcessor = std::make_shared(data); authMessageProcessor->authResponseContext_ = std::make_shared(); std::shared_ptr authResponseContext = authMessageProcessor->GetResponseContext(); ASSERT_NE(authResponseContext, nullptr); - sleep(15); } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/UTTest_auth_request_state.cpp b/test/unittest/UTTest_auth_request_state.cpp index 92cf2951f39429e5811ac797ebbd016bbfb1455c..bf554ee3bb9573fa3e7d313bf449dd452b5fcfec 100644 --- a/test/unittest/UTTest_auth_request_state.cpp +++ b/test/unittest/UTTest_auth_request_state.cpp @@ -41,6 +41,9 @@ std::string CONFIRM_TIMEOUT_TASK = "confirmTimeoutTask"; std::string INPUT_TIMEOUT_TASK = "inputTimeoutTask"; std::string ADD_TIMEOUT_TASK = "addTimeoutTask"; +std::shared_ptr softbusConnector = std::make_shared(); +std::shared_ptr listener = std::make_shared(); +std::shared_ptr hiChainConnector = std::make_shared(); /** * @tc.name: AuthRequestInitState::SetAuthManager_001 * @tc.desc: 1 set authManager not null @@ -51,9 +54,6 @@ std::string ADD_TIMEOUT_TASK = "addTimeoutTask"; */ HWTEST_F(AuthRequestStateTest, SetAuthManager_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr hiChainConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); @@ -90,15 +90,13 @@ HWTEST_F(AuthRequestStateTest, SetAuthManager_002, testing::ext::TestSize.Level0 */ HWTEST_F(AuthRequestStateTest, TransitionTo_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); authManager = nullptr; authRequestState->authManager_ = authManager; int32_t ret = authRequestState->TransitionTo(std::make_shared()); ASSERT_EQ(ret, DM_FAILED); - sleep(15); } /** @@ -111,9 +109,8 @@ HWTEST_F(AuthRequestStateTest, TransitionTo_001, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, TransitionTo_002, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr context = std::make_shared(); std::shared_ptr authRequestState = std::make_shared(); std::shared_ptr negotiateStartTimer = std::make_shared(NEGOTIATE_TIMEOUT_TASK); @@ -126,11 +123,11 @@ HWTEST_F(AuthRequestStateTest, TransitionTo_002, testing::ext::TestSize.Level0) authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); context->sessionId = 123456; authManager->SetAuthRequestState(authRequestState); + authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); authRequestState->SetAuthContext(context); authRequestState->SetAuthManager(authManager); int32_t ret = authRequestState->TransitionTo(std::make_shared()); ASSERT_EQ(ret, DM_OK); - sleep(20); } /** @@ -145,7 +142,6 @@ HWTEST_F(AuthRequestStateTest, GetStateType_001, testing::ext::TestSize.Level0) std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_INIT); - sleep(15); } /** @@ -158,15 +154,13 @@ HWTEST_F(AuthRequestStateTest, GetStateType_001, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); authManager = nullptr; authRequestState->SetAuthManager(authManager); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); - sleep(15); } /** @@ -179,9 +173,8 @@ HWTEST_F(AuthRequestStateTest, Enter_001, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_002, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); @@ -192,7 +185,6 @@ HWTEST_F(AuthRequestStateTest, Enter_002, testing::ext::TestSize.Level0) authRequestState->SetAuthContext(context); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_OK); - sleep(15); } /** @@ -207,7 +199,6 @@ HWTEST_F(AuthRequestStateTest, GetStateType_002, testing::ext::TestSize.Level0) std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_NEGOTIATE); - sleep(15); } /** @@ -220,14 +211,12 @@ HWTEST_F(AuthRequestStateTest, GetStateType_002, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_003, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); - sleep(15); } /** @@ -240,11 +229,9 @@ HWTEST_F(AuthRequestStateTest, Enter_003, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_004, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); - std::shared_ptr hiChainConnector = std::make_shared(); authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); @@ -259,7 +246,6 @@ HWTEST_F(AuthRequestStateTest, Enter_004, testing::ext::TestSize.Level0) authRequestState->SetAuthContext(context); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_OK); - sleep(15); } /** @@ -274,7 +260,6 @@ HWTEST_F(AuthRequestStateTest, GetStateType_003, testing::ext::TestSize.Level0) std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_NEGOTIATE_DONE); - sleep(15); } /** @@ -287,14 +272,12 @@ HWTEST_F(AuthRequestStateTest, GetStateType_003, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_005, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); - sleep(15); } /** @@ -307,11 +290,9 @@ HWTEST_F(AuthRequestStateTest, Enter_005, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_006, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); - std::shared_ptr hiChainConnector = std::make_shared(); std::shared_ptr negotiateStartTimer = std::make_shared(NEGOTIATE_TIMEOUT_TASK); authManager->timerMap_[NEGOTIATE_TIMEOUT_TASK] = negotiateStartTimer; authManager->authMessageProcessor_ = std::make_shared(authManager); @@ -319,6 +300,7 @@ HWTEST_F(AuthRequestStateTest, Enter_006, testing::ext::TestSize.Level0) authManager->authRequestContext_ = std::make_shared(); authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); + authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); authManager->SetAuthRequestState(authRequestState); authRequestState->SetAuthManager(authManager); std::shared_ptr context = std::make_shared(); @@ -326,7 +308,6 @@ HWTEST_F(AuthRequestStateTest, Enter_006, testing::ext::TestSize.Level0) authRequestState->SetAuthContext(context); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_OK); - sleep(15); } /** @@ -341,7 +322,6 @@ HWTEST_F(AuthRequestStateTest, GetStateType_004, testing::ext::TestSize.Level0) std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_REPLY); - sleep(15); } /** @@ -354,14 +334,12 @@ HWTEST_F(AuthRequestStateTest, GetStateType_004, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_007, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); - sleep(15); } /** @@ -374,11 +352,9 @@ HWTEST_F(AuthRequestStateTest, Enter_007, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_008, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); - std::shared_ptr hiChainConnector = std::make_shared(); std::shared_ptr inputStartTimer = std::make_shared(CONFIRM_TIMEOUT_TASK); authManager->timerMap_[CONFIRM_TIMEOUT_TASK] = inputStartTimer; authManager->authMessageProcessor_ = std::make_shared(authManager); @@ -395,7 +371,6 @@ HWTEST_F(AuthRequestStateTest, Enter_008, testing::ext::TestSize.Level0) authRequestState->SetAuthContext(context); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_OK); - sleep(15); } /** @@ -410,7 +385,6 @@ HWTEST_F(AuthRequestStateTest, GetStateType_005, testing::ext::TestSize.Level0) std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_INPUT); - sleep(15); } /** @@ -423,14 +397,12 @@ HWTEST_F(AuthRequestStateTest, GetStateType_005, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_009, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); - sleep(15); } /** @@ -443,14 +415,12 @@ HWTEST_F(AuthRequestStateTest, Enter_009, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_010, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(authManager); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_OK); - sleep(15); } /** @@ -465,7 +435,6 @@ HWTEST_F(AuthRequestStateTest, GetStateType_006, testing::ext::TestSize.Level0) std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_JOIN); - sleep(15); } /** @@ -478,14 +447,12 @@ HWTEST_F(AuthRequestStateTest, GetStateType_006, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_011, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); - sleep(15); } /** @@ -498,10 +465,8 @@ HWTEST_F(AuthRequestStateTest, Enter_011, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_012, testing::ext::TestSize.Level0) { - printf("1\n"); - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); authManager->authMessageProcessor_ = std::make_shared(authManager); @@ -511,18 +476,16 @@ HWTEST_F(AuthRequestStateTest, Enter_012, testing::ext::TestSize.Level0) authManager->authResponseContext_->code = 123; authManager->authResponseContext_->requestId = 234; authManager->authResponseContext_->deviceId = "234"; - printf("3\n"); authRequestState->SetAuthManager(authManager); authManager->SetAuthRequestState(authRequestState); + authManager->hiChainConnector_->RegisterHiChainCallback(authManager); + authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); std::shared_ptr context = std::make_shared(); - printf("4\n"); context->deviceId = "44444"; context->sessionId = 55555; authRequestState->SetAuthContext(context); - printf("5\n"); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_OK); - sleep(15); } /** @@ -537,7 +500,6 @@ HWTEST_F(AuthRequestStateTest, GetStateType_007, testing::ext::TestSize.Level0) std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_NETWORK); - sleep(15); } /** @@ -550,14 +512,12 @@ HWTEST_F(AuthRequestStateTest, GetStateType_007, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_013, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); - sleep(15); } /** @@ -570,10 +530,8 @@ HWTEST_F(AuthRequestStateTest, Enter_013, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_014, testing::ext::TestSize.Level0) { - printf("1\n"); - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); std::shared_ptr authenticateStartTimer = std::make_shared(AUTHENTICATE_TIMEOUT_TASK); authManager->timerMap_[AUTHENTICATE_TIMEOUT_TASK] = authenticateStartTimer; @@ -583,13 +541,11 @@ HWTEST_F(AuthRequestStateTest, Enter_014, testing::ext::TestSize.Level0) authManager->authRequestState_ = std::make_shared(); authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); + authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); authManager->SetAuthRequestState(authRequestState); - printf("3\n"); authRequestState->SetAuthManager(authManager); int32_t ret = authRequestState->Enter(); - printf("4\n"); ASSERT_EQ(ret, DM_OK); - sleep(15); } /** @@ -604,7 +560,6 @@ HWTEST_F(AuthRequestStateTest, GetStateType_008, testing::ext::TestSize.Level0) std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_FINISH); - sleep(15); } /** @@ -617,14 +572,12 @@ HWTEST_F(AuthRequestStateTest, GetStateType_008, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_015, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); - sleep(15); } /** @@ -637,11 +590,9 @@ HWTEST_F(AuthRequestStateTest, Enter_015, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_016, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); - std::shared_ptr hiChainConnector = std::make_shared(); std::shared_ptr inputStartTimer = std::make_shared(CONFIRM_TIMEOUT_TASK); authManager->timerMap_[CONFIRM_TIMEOUT_TASK] = inputStartTimer; authManager->authMessageProcessor_ = std::make_shared(authManager); @@ -659,7 +610,6 @@ HWTEST_F(AuthRequestStateTest, Enter_016, testing::ext::TestSize.Level0) authRequestState->SetAuthContext(context); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_OK); - sleep(15); } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/UTTest_auth_response_state.cpp b/test/unittest/UTTest_auth_response_state.cpp index ace33012d5a642a874b89b6b62e69dd7d9dabf09..625f3444321fe67fa49be009083cbbbd3ac4c3c9 100644 --- a/test/unittest/UTTest_auth_response_state.cpp +++ b/test/unittest/UTTest_auth_response_state.cpp @@ -37,6 +37,9 @@ void AuthResponseStateTest::TearDownTestCase() } namespace { +std::shared_ptr softbusConnector = std::make_shared(); +std::shared_ptr listener = std::make_shared(); +std::shared_ptr hiChainConnector = std::make_shared(); /** * @tc.name: AuthResponseInitState::SetAuthManager_001 * @tc.desc: 1 set authManager not null @@ -47,14 +50,12 @@ namespace { */ HWTEST_F(AuthResponseStateTest, SetAuthManager_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(authManager); int32_t ret = authResponseState->authManager_.use_count(); ASSERT_EQ(ret, 1); - sleep(15); } /** @@ -71,7 +72,6 @@ HWTEST_F(AuthResponseStateTest, SetAuthManager_002, testing::ext::TestSize.Level authResponseState->SetAuthManager(nullptr); int32_t ret = authResponseState->authManager_.use_count(); ASSERT_EQ(ret, 0); - sleep(15); } /** @@ -84,15 +84,13 @@ HWTEST_F(AuthResponseStateTest, SetAuthManager_002, testing::ext::TestSize.Level */ HWTEST_F(AuthResponseStateTest, TransitionTo_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authResponseState = std::make_shared(); authManager = nullptr; authResponseState->authManager_ = authManager; int32_t ret = authResponseState->TransitionTo(std::make_shared()); ASSERT_EQ(ret, DM_FAILED); - sleep(15); } /** @@ -105,9 +103,8 @@ HWTEST_F(AuthResponseStateTest, TransitionTo_001, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, TransitionTo_002, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr context = std::make_shared(); std::shared_ptr authResponseState = std::make_shared(); authManager->authResponseState_ = std::make_shared(); @@ -118,7 +115,6 @@ HWTEST_F(AuthResponseStateTest, TransitionTo_002, testing::ext::TestSize.Level0) authResponseState->SetAuthManager(authManager); int32_t ret = authResponseState->TransitionTo(std::make_shared()); ASSERT_EQ(ret, DM_OK); - sleep(20); } /** @@ -133,7 +129,6 @@ HWTEST_F(AuthResponseStateTest, GetStateType_001, testing::ext::TestSize.Level0) std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_RESPONSE_INIT); - sleep(15); } /** @@ -148,7 +143,6 @@ HWTEST_F(AuthResponseStateTest, Enter_001, testing::ext::TestSize.Level0) std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_OK); - sleep(15); } /** @@ -163,7 +157,6 @@ HWTEST_F(AuthResponseStateTest, GetStateType_002, testing::ext::TestSize.Level0) std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_RESPONSE_NEGOTIATE); - sleep(15); } /** @@ -176,15 +169,13 @@ HWTEST_F(AuthResponseStateTest, GetStateType_002, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_002, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authResponseState = std::make_shared(); authManager = nullptr; authResponseState->SetAuthManager(authManager); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_FAILED); - sleep(15); } /** @@ -197,11 +188,9 @@ HWTEST_F(AuthResponseStateTest, Enter_002, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_003, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authResponseState = std::make_shared(); - std::shared_ptr hiChainConnector = std::make_shared(); authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); @@ -211,6 +200,7 @@ HWTEST_F(AuthResponseStateTest, Enter_003, testing::ext::TestSize.Level0) authManager->authResponseContext_->localDeviceId = "222"; authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); + authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); authResponseState->SetAuthManager(authManager); std::shared_ptr context = std::make_shared(); context->deviceId = "123456"; @@ -232,7 +222,6 @@ HWTEST_F(AuthResponseStateTest, GetStateType_003, testing::ext::TestSize.Level0) std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_RESPONSE_CONFIRM); - sleep(15); } /** @@ -245,14 +234,12 @@ HWTEST_F(AuthResponseStateTest, GetStateType_003, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_004, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(nullptr); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_FAILED); - sleep(15); } /** @@ -265,14 +252,12 @@ HWTEST_F(AuthResponseStateTest, Enter_004, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_005, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(authManager); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_OK); - sleep(15); } /** @@ -287,7 +272,6 @@ HWTEST_F(AuthResponseStateTest, GetStateType_004, testing::ext::TestSize.Level0) std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_RESPONSE_GROUP); - sleep(15); } /** @@ -300,14 +284,12 @@ HWTEST_F(AuthResponseStateTest, GetStateType_004, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_006, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(nullptr); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_FAILED); - sleep(15); } /** @@ -320,19 +302,14 @@ HWTEST_F(AuthResponseStateTest, Enter_006, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_007, testing::ext::TestSize.Level0) { - printf("1\n"); - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authResponseState = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authResponseState_ = std::make_shared(); - printf("2\n"); authResponseState->SetAuthManager(authManager); - printf("3\n"); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_OK); - sleep(15); } /** @@ -347,7 +324,6 @@ HWTEST_F(AuthResponseStateTest, GetStateType_005, testing::ext::TestSize.Level0) std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_RESPONSE_SHOW); - sleep(15); } /** @@ -360,14 +336,12 @@ HWTEST_F(AuthResponseStateTest, GetStateType_005, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_008, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(nullptr); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_FAILED); - sleep(15); } /** @@ -380,14 +354,12 @@ HWTEST_F(AuthResponseStateTest, Enter_008, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_009, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(authManager); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_OK); - sleep(15); } /** @@ -402,7 +374,6 @@ HWTEST_F(AuthResponseStateTest, GetStateType_006, testing::ext::TestSize.Level0) std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_RESPONSE_FINISH); - sleep(15); } /** @@ -415,14 +386,12 @@ HWTEST_F(AuthResponseStateTest, GetStateType_006, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_010, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(nullptr); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_FAILED); - sleep(15); } /** @@ -435,9 +404,8 @@ HWTEST_F(AuthResponseStateTest, Enter_010, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_011, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authResponseState = std::make_shared(); authManager->authRequestState_ = std::make_shared(); authManager->authResponseState_ = std::make_shared(); @@ -457,7 +425,6 @@ HWTEST_F(AuthResponseStateTest, Enter_011, testing::ext::TestSize.Level0) authResponseState->SetAuthContext(context); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_OK); - sleep(15); } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/UTTest_device_manager_service.cpp b/test/unittest/UTTest_device_manager_service.cpp index 3a995051dc71dcaab50607fddff79dc517a022b2..28256c67f467a01f7f0fc4414166ca89e4fc2b21 100644 --- a/test/unittest/UTTest_device_manager_service.cpp +++ b/test/unittest/UTTest_device_manager_service.cpp @@ -337,26 +337,6 @@ HWTEST_F(DeviceManagerServiceTest, VerifyAuthentication_001, testing::ext::TestS int ret = DeviceManagerService::GetInstance().VerifyAuthentication(authParam); EXPECT_EQ(ret, DM_NOT_INIT); } - -/** - * @tc.name: VerifyAuthentication_002 - * @tc.desc:Set intFlag for VerifyAuthentication to true and set authParam = "jdjjjj",The return value is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DeviceManagerServiceTest, VerifyAuthentication_002, testing::ext::TestSize.Level0) -{ - DeviceManagerService::GetInstance().intFlag_ = true; - std::string authParam = "jdjjjj"; - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener_ = std::make_shared(); - DeviceManagerService::GetInstance().authMgr_ = - std::make_shared(softbusConnector, listener_, nullptr); - std::shared_ptr inputStartTimer = std::make_shared(INPUT_TIMEOUT_TASK); - DeviceManagerService::GetInstance().authMgr_->timerMap_[INPUT_TIMEOUT_TASK] = inputStartTimer; - int ret = DeviceManagerService::GetInstance().VerifyAuthentication(authParam); - EXPECT_EQ(ret, DM_FAILED); -} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_device_manager_service_listener.cpp b/test/unittest/UTTest_device_manager_service_listener.cpp index 3cef42c3f85ed0a97dd7efa3fa879db05c7fa20d..8f85f3dd6f94b1b2c51c533eff81aea3b2a885c5 100644 --- a/test/unittest/UTTest_device_manager_service_listener.cpp +++ b/test/unittest/UTTest_device_manager_service_listener.cpp @@ -63,7 +63,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnDeviceStateChange_001, testing::ext std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); int32_t dmState = pReq->GetDeviceState(); - EXPECT_EQ(1, dmState); + EXPECT_EQ(0, dmState); } /** @@ -83,7 +83,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnAuthResult_001, testing::ext::TestS listener_->OnAuthResult(pkgName, deviceId, token, status, reason); std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); - std ::string ret = pReq->GetPkgName(); + std::string ret = pReq->GetPkgName(); EXPECT_EQ(ret, pkgName); } @@ -104,7 +104,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnVerifyAuthResult_001, testing::ext: listener_->OnVerifyAuthResult(pkgName, deviceId, resultCode, flag); std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); - std ::string ret = pReq->GetDeviceId(); + std::string ret = pReq->GetDeviceId(); EXPECT_EQ(ret, deviceId); } } // namespace diff --git a/test/unittest/UTTest_dm_auth_manager.cpp b/test/unittest/UTTest_dm_auth_manager.cpp index 651f58affc628cb8608f0a9d29d3dfc62a4986b9..65f84540613f1712c490f59505b839ff7bdde2da 100644 --- a/test/unittest/UTTest_dm_auth_manager.cpp +++ b/test/unittest/UTTest_dm_auth_manager.cpp @@ -44,6 +44,10 @@ std::string CONFIRM_TIMEOUT_TASK = "confirmTimeoutTask"; std::string INPUT_TIMEOUT_TASK = "inputTimeoutTask"; std::string ADD_TIMEOUT_TASK = "addTimeoutTask"; +std::shared_ptr softbusConnector = std::make_shared(); +std::shared_ptr listener = std::make_shared(); +std::shared_ptr hiChainConnector_ = std::make_shared(); + /** * @tc.name: DmAuthManager::UnAuthenticateDevice_001 * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_ FAILED @@ -52,9 +56,8 @@ std::string ADD_TIMEOUT_TASK = "addTimeoutTask"; */ HWTEST_F(DmAuthManagerTest, UnAuthenticateDevice_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr sessionSession = std::shared_ptr(); std::shared_ptr authRequestContext = std::make_shared(); std::string pkgName = ""; @@ -71,9 +74,8 @@ HWTEST_F(DmAuthManagerTest, UnAuthenticateDevice_001, testing::ext::TestSize.Lev */ HWTEST_F(DmAuthManagerTest, HandleAuthenticateTimeout_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authRequestState = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); @@ -81,7 +83,7 @@ HWTEST_F(DmAuthManagerTest, HandleAuthenticateTimeout_001, testing::ext::TestSiz authManager->authResponseContext_ = nullptr; authManager->SetAuthRequestState(authRequestState); int32_t ret = authManager->HandleAuthenticateTimeout(); - ASSERT_EQ(ret, DM_FAILED); + ASSERT_EQ(ret, DM_OK); } /** @@ -92,9 +94,8 @@ HWTEST_F(DmAuthManagerTest, HandleAuthenticateTimeout_001, testing::ext::TestSiz */ HWTEST_F(DmAuthManagerTest, HandleAuthenticateTimeout_002, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authRequestState = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); @@ -112,9 +113,8 @@ HWTEST_F(DmAuthManagerTest, HandleAuthenticateTimeout_002, testing::ext::TestSiz */ HWTEST_F(DmAuthManagerTest, EstablishAuthChannel_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr sessionSession = std::shared_ptr(); std::shared_ptr authRequestContext = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); @@ -133,17 +133,17 @@ HWTEST_F(DmAuthManagerTest, EstablishAuthChannel_001, testing::ext::TestSize.Lev */ HWTEST_F(DmAuthManagerTest, StartAuthProcess_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authResponseState = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); authManager->authResponseState_ = std::make_shared(); authManager->SetAuthResponseState(authResponseState); int32_t action = 0; - int32_t ret = authManager->StartAuthProcess(action); - ASSERT_EQ(ret, DM_FAILED); + authManager->StartAuthProcess(action); + bool ret = authManager->authRequestContext_->deviceName.empty(); + ASSERT_EQ(ret, true); } /** @@ -154,9 +154,8 @@ HWTEST_F(DmAuthManagerTest, StartAuthProcess_001, testing::ext::TestSize.Level0) */ HWTEST_F(DmAuthManagerTest, StartAuthProcess_002, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authResponseState = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); @@ -164,6 +163,7 @@ HWTEST_F(DmAuthManagerTest, StartAuthProcess_002, testing::ext::TestSize.Level0) authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->SetAuthResponseState(authResponseState); authManager->authResponseContext_->sessionId = 111; + authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); int32_t action = 1; int32_t ret = authManager->StartAuthProcess(action); ASSERT_EQ(ret, DM_OK); @@ -177,9 +177,8 @@ HWTEST_F(DmAuthManagerTest, StartAuthProcess_002, testing::ext::TestSize.Level0) */ HWTEST_F(DmAuthManagerTest, CreateGroup_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authResponseState = std::make_shared(); std::shared_ptr hiChainConnector = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); @@ -201,14 +200,11 @@ HWTEST_F(DmAuthManagerTest, CreateGroup_001, testing::ext::TestSize.Level0) */ HWTEST_F(DmAuthManagerTest, AddMember_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authResponseState = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); std::shared_ptr hiChainConnector = std::make_shared(); - std::shared_ptr joinStartTimer = std::make_shared(ADD_TIMEOUT_TASK); - authManager->timerMap_[ADD_TIMEOUT_TASK] = joinStartTimer; authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->authResponseContext_ = std::make_shared(); nlohmann::json jsonObject; @@ -217,12 +213,8 @@ HWTEST_F(DmAuthManagerTest, AddMember_001, testing::ext::TestSize.Level0) authManager->authResponseContext_->code = 123; authManager->authResponseContext_->requestId = 234; authManager->authResponseContext_->deviceId = "234"; - jsonObject[TAG_GROUP_ID] = authManager->authResponseContext_->groupId; - jsonObject[TAG_GROUP_NAME] = authManager->authResponseContext_->groupName; - jsonObject[PIN_CODE_KEY] = authManager->authResponseContext_->code; - jsonObject[TAG_REQUEST_ID] = authManager->authResponseContext_->requestId; - jsonObject[TAG_DEVICE_ID] = authManager->authResponseContext_->deviceId; std::string deviceId = "44444"; + authManager->hiChainConnector_->RegisterHiChainCallback(authManager); authManager->SetAuthResponseState(authResponseState); int32_t ret = authManager->AddMember(deviceId); ASSERT_EQ(ret, DM_OK); @@ -237,9 +229,8 @@ HWTEST_F(DmAuthManagerTest, AddMember_001, testing::ext::TestSize.Level0) */ HWTEST_F(DmAuthManagerTest, JoinNetwork_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authRequestState = std::make_shared(); std::shared_ptr authenticateStartTimer = std::make_shared(AUTHENTICATE_TIMEOUT_TASK); authManager->timerMap_[AUTHENTICATE_TIMEOUT_TASK] = authenticateStartTimer; @@ -260,9 +251,8 @@ HWTEST_F(DmAuthManagerTest, JoinNetwork_001, testing::ext::TestSize.Level0) */ HWTEST_F(DmAuthManagerTest, SetAuthResponseState_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); std::shared_ptr authResponseState = std::make_shared(); authManager->authResponseState_ = std::make_shared(); authManager->SetAuthResponseState(authResponseState); @@ -278,11 +268,9 @@ HWTEST_F(DmAuthManagerTest, SetAuthResponseState_001, testing::ext::TestSize.Lev */ HWTEST_F(DmAuthManagerTest, GetPinCode_001, testing::ext::TestSize.Level0) { - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); authManager->authResponseContext_ = std::make_shared(); - ; int32_t ret = authManager->GetPinCode(); ASSERT_EQ(ret, authManager->authResponseContext_->code); } diff --git a/test/unittest/UTTest_hichain_connector.cpp b/test/unittest/UTTest_hichain_connector.cpp index 3e1ea6e67d58b82314201e7a0ba7c28c8fee2664..ae46c25140fbd41a4557155c629a59945cbf5046 100644 --- a/test/unittest/UTTest_hichain_connector.cpp +++ b/test/unittest/UTTest_hichain_connector.cpp @@ -43,7 +43,9 @@ void HichainConnectorTest::TearDownTestCase() namespace { std::shared_ptr listener_ = std::make_shared(); std::shared_ptr softbusConnector = std::make_shared(); -std::shared_ptr discoveryMgr_ = std::make_shared(softbusConnector, listener_, nullptr); +std::shared_ptr hiChainConnector_ = std::make_shared(); +std::shared_ptr discoveryMgr_ = + std::make_shared(softbusConnector, listener_, hiChainConnector_); /** * @tc.name: CreateGroup_001 @@ -261,8 +263,7 @@ HWTEST_F(HichainConnectorTest, HiChainConnector_002, testing::ext::TestSize.Leve HWTEST_F(HichainConnectorTest, RegisterHiChainCallback_001, testing::ext::TestSize.Level0) { std::shared_ptr hichainConnector = std::make_shared(); - int ret = - hichainConnector->RegisterHiChainCallback(std::shared_ptr(discoveryMgr_)); + int ret = hichainConnector->RegisterHiChainCallback(std::shared_ptr(discoveryMgr_)); EXPECT_EQ(ret, DM_OK); } diff --git a/test/unittest/UTTest_softbus_session.cpp b/test/unittest/UTTest_softbus_session.cpp index b0d6e66a374f4eae75f2a8d220e073f5adce4233..8d14ff0e15e2f64120c6dabf195f78ad9dd3307f 100644 --- a/test/unittest/UTTest_softbus_session.cpp +++ b/test/unittest/UTTest_softbus_session.cpp @@ -40,7 +40,9 @@ namespace { std::shared_ptr softbusSession = std::make_shared(); std::shared_ptr listener_ = std::make_shared(); std::shared_ptr softbusConnector = std::make_shared(); -std::shared_ptr discoveryMgr_ = std::make_shared(softbusConnector, listener_, nullptr); +std::shared_ptr hiChainConnector = std::make_shared(); +std::shared_ptr discoveryMgr_ = + std::make_shared(softbusConnector, listener_, hiChainConnector); /** * @tc.name: OpenAuthSession_001