mirror of
https://github.com/openharmony/device_manager.git
synced 2026-07-21 06:05:22 -04:00
@@ -94,7 +94,7 @@ public:
|
||||
* @tc.desc: Cancel complete verification of device
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
virtual int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId) = 0;
|
||||
virtual int32_t UnAuthenticateDevice(const std::string &pkgName, const DmDeviceInfo &deviceInfo) = 0;
|
||||
/**
|
||||
* @tc.name: DeviceManagerImpl::VerifyAuthentication
|
||||
* @tc.desc: Verify device authentication
|
||||
|
||||
@@ -95,7 +95,7 @@ public:
|
||||
* @tc.desc: Cancel complete verification of device
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
virtual int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId) override;
|
||||
virtual int32_t UnAuthenticateDevice(const std::string &pkgName, const DmDeviceInfo &deviceInfo) override;
|
||||
/**
|
||||
* @tc.name: DeviceManagerImpl::VerifyAuthentication
|
||||
* @tc.desc: Verify device authentication
|
||||
|
||||
@@ -275,26 +275,20 @@ int32_t DeviceManagerImpl::AuthenticateDevice(const std::string &pkgName, int32_
|
||||
return DM_OK;
|
||||
}
|
||||
|
||||
int32_t DeviceManagerImpl::UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId)
|
||||
int32_t DeviceManagerImpl::UnAuthenticateDevice(const std::string &pkgName, const DmDeviceInfo &deviceInfo)
|
||||
{
|
||||
LOGI("DeviceManager::UnAuthenticateDevice start , pkgName: %s, deviceId: %s", pkgName.c_str(), deviceId.c_str());
|
||||
|
||||
if (deviceId.empty()) {
|
||||
LOGI("DeviceManager::UnAuthenticateDevice start , pkgName: %s, deviceId: %s", pkgName.c_str(),
|
||||
deviceInfo.deviceId);
|
||||
if (pkgName.empty()) {
|
||||
LOGE("UnAuthenticateDevice error: Invalid para");
|
||||
return DM_INVALID_VALUE;
|
||||
}
|
||||
|
||||
DmDeviceInfo deviceInfo;
|
||||
int32_t ret = strcpy_s(deviceInfo.deviceId, DM_MAX_DEVICE_ID_LEN, deviceId.c_str());
|
||||
if (ret != DM_OK) {
|
||||
LOGE("UnAuthenticateDevice error: copy deviceId failed");
|
||||
return DM_INVALID_VALUE;
|
||||
}
|
||||
std::shared_ptr<IpcUnAuthenticateDeviceReq> req = std::make_shared<IpcUnAuthenticateDeviceReq>();
|
||||
std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
|
||||
req->SetPkgName(pkgName);
|
||||
req->SetDeviceInfo(deviceInfo);
|
||||
ret = ipcClientProxy_->SendRequest(UNAUTHENTICATE_DEVICE, req, rsp);
|
||||
int32_t ret = ipcClientProxy_->SendRequest(UNAUTHENTICATE_DEVICE, req, rsp);
|
||||
if (ret != DM_OK) {
|
||||
LOGE("UnAuthenticateDevice error: Send Request failed ret: %d", ret);
|
||||
return DM_IPC_SEND_REQUEST_FAILED;
|
||||
|
||||
@@ -1573,15 +1573,17 @@ napi_value DeviceManagerNapi::UnAuthenticateDevice(napi_env env, napi_callback_i
|
||||
{
|
||||
LOGI("UnAuthenticateDevice");
|
||||
napi_value result = nullptr;
|
||||
napi_valuetype deviceInfoType;
|
||||
GET_PARAMS(env, info, DM_NAPI_ARGS_TWO);
|
||||
napi_valuetype deviceInfoType = napi_undefined;
|
||||
napi_typeof(env, argv[0], &deviceInfoType);
|
||||
NAPI_ASSERT(env, deviceInfoType == napi_string, "Wrong argument type. String expected.");
|
||||
std::string deviceId = JsObjectToString(env, argv[0]);
|
||||
LOGI("UnAuthenticateDevice deviceId=%s", deviceId.c_str());
|
||||
NAPI_ASSERT(env, deviceInfoType == napi_object, "Wrong argument type. Object expected.");
|
||||
|
||||
DmDeviceInfo deviceInfo;
|
||||
JsToDmDeviceInfo(env, argv[0], deviceInfo);
|
||||
LOGI("UnAuthenticateDevice deviceId = %s", deviceInfo.deviceId);
|
||||
DeviceManagerNapi *deviceManagerWrapper = nullptr;
|
||||
napi_unwrap(env, thisVar, reinterpret_cast<void **>(&deviceManagerWrapper));
|
||||
int32_t ret = DeviceManager::GetInstance().UnAuthenticateDevice(deviceManagerWrapper->bundleName_, deviceId);
|
||||
int32_t ret = DeviceManager::GetInstance().UnAuthenticateDevice(deviceManagerWrapper->bundleName_, deviceInfo);
|
||||
if (ret != 0) {
|
||||
LOGE("UnAuthenticateDevice for bunderName %s failed, ret %d", deviceManagerWrapper->bundleName_.c_str(), ret);
|
||||
}
|
||||
|
||||
@@ -146,9 +146,9 @@ void UnAuthenticateDeviceFuzzTest(const uint8_t* data, size_t size)
|
||||
}
|
||||
|
||||
std::string bundleName(reinterpret_cast<const char*>(data), size);
|
||||
std::string deviceId(reinterpret_cast<const char*>(data), size);
|
||||
DmDeviceInfo deviceInfo;
|
||||
|
||||
DeviceManager::GetInstance().UnAuthenticateDevice(bundleName, deviceId);
|
||||
DeviceManager::GetInstance().UnAuthenticateDevice(bundleName, deviceInfo);
|
||||
}
|
||||
|
||||
void RegisterDeviceManagerFaCallbackFuzzTest(const uint8_t* data, size_t size)
|
||||
|
||||
@@ -1281,9 +1281,9 @@ HWTEST_F(DeviceManagerImplTest, UnAuthenticateDevice_001, testing::ext::TestSize
|
||||
{
|
||||
// 1. set packName = null
|
||||
std::string packName = "";
|
||||
std::string deviceId = "";
|
||||
DmDeviceInfo deviceInfo;
|
||||
// 2. call DeviceManagerImpl::AuthenticateDevice with parameter
|
||||
int32_t ret= DeviceManager::GetInstance().UnAuthenticateDevice(packName, deviceId);
|
||||
int32_t ret= DeviceManager::GetInstance().UnAuthenticateDevice(packName, deviceInfo);
|
||||
// 3. check ret is DEVICEMANAGER_INVALID_VALUE
|
||||
ASSERT_EQ(ret, DM_INVALID_VALUE);
|
||||
}
|
||||
@@ -1306,9 +1306,9 @@ HWTEST_F(DeviceManagerImplTest, UnAuthenticateDevice_002, testing::ext::TestSize
|
||||
{
|
||||
// 1. set packName = null
|
||||
std::string packName = "com.ohos.helloworld";
|
||||
std::string deviceId = "";
|
||||
DmDeviceInfo deviceInfo;
|
||||
// 2. call DeviceManagerImpl::AuthenticateDevice with parameter
|
||||
int32_t ret= DeviceManager::GetInstance().UnAuthenticateDevice(packName, deviceId);
|
||||
int32_t ret= DeviceManager::GetInstance().UnAuthenticateDevice(packName, deviceInfo);
|
||||
// 3. check ret is DEVICEMANAGER_INVALID_VALUE
|
||||
ASSERT_EQ(ret, DM_INVALID_VALUE);
|
||||
}
|
||||
@@ -1332,7 +1332,7 @@ HWTEST_F(DeviceManagerImplTest, UnAuthenticateDevice_003, testing::ext::TestSize
|
||||
// 1. set packName not null
|
||||
std::string packName = "com.ohos.helloworld";
|
||||
// set callback null
|
||||
std::string deviceId = "1";
|
||||
DmDeviceInfo deviceInfo;
|
||||
std::shared_ptr<AuthenticateCallback> callback = nullptr;
|
||||
// 2. MOCK IpcClientProxy SendRequest return DM_OK
|
||||
std::shared_ptr<MockIpcClientProxy> mockInstance = std::make_shared<MockIpcClientProxy>();
|
||||
@@ -1340,7 +1340,7 @@ HWTEST_F(DeviceManagerImplTest, UnAuthenticateDevice_003, testing::ext::TestSize
|
||||
EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_))
|
||||
.Times(1).WillOnce(testing::Return(DM_OK));
|
||||
// 3. call DeviceManagerImpl::AuthenticateDevice with parameter
|
||||
int32_t ret= DeviceManager::GetInstance().UnAuthenticateDevice(packName, deviceId);
|
||||
int32_t ret= DeviceManager::GetInstance().UnAuthenticateDevice(packName, deviceInfo);
|
||||
// 4. check ret is DM_OK
|
||||
ASSERT_EQ(ret, DM_OK);
|
||||
DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr;
|
||||
@@ -1365,7 +1365,7 @@ HWTEST_F(DeviceManagerImplTest, UnAuthenticateDevice_004, testing::ext::TestSize
|
||||
// 1. set packName not null
|
||||
std::string packName = "com.ohos.helloworld";
|
||||
// set dmDeviceInfo null
|
||||
std::string deviceId = "1";
|
||||
DmDeviceInfo deviceInfo;
|
||||
std::shared_ptr<AuthenticateCallback> callback = nullptr;
|
||||
// 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY
|
||||
std::shared_ptr<MockIpcClientProxy> mockInstance = std::make_shared<MockIpcClientProxy>();
|
||||
@@ -1373,7 +1373,7 @@ HWTEST_F(DeviceManagerImplTest, UnAuthenticateDevice_004, testing::ext::TestSize
|
||||
EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_))
|
||||
.Times(1).WillOnce(testing::Return(DM_SERVICE_NOT_READY));
|
||||
// 3. call DeviceManagerImpl::AuthenticateDevice with parameter
|
||||
int32_t ret= DeviceManager::GetInstance().UnAuthenticateDevice(packName, deviceId);
|
||||
int32_t ret= DeviceManager::GetInstance().UnAuthenticateDevice(packName, deviceInfo);
|
||||
// 4. check ret is DM_IPC_SEND_REQUEST_FAILED
|
||||
ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED);
|
||||
DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr;
|
||||
@@ -1398,7 +1398,7 @@ HWTEST_F(DeviceManagerImplTest, UnAuthenticateDevice_005, testing::ext::TestSize
|
||||
// 1. set packName not null
|
||||
std::string packName = "com.ohos.helloworld";
|
||||
// set dmDeviceInfo null
|
||||
std::string deviceId = "1";
|
||||
DmDeviceInfo deviceInfo;
|
||||
std::shared_ptr<AuthenticateCallback> callback = nullptr;
|
||||
// 2. MOCK IpcClientProxy SendRequest return DM_POINT_NULL
|
||||
std::shared_ptr<MockIpcClientProxy> mockInstance = std::make_shared<MockIpcClientProxy>();
|
||||
@@ -1406,7 +1406,7 @@ HWTEST_F(DeviceManagerImplTest, UnAuthenticateDevice_005, testing::ext::TestSize
|
||||
EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_))
|
||||
.Times(1).WillOnce(testing::Return(DM_POINT_NULL));
|
||||
// 3. call DeviceManagerImpl::AuthenticateDevice with parameter
|
||||
int32_t ret= DeviceManager::GetInstance().UnAuthenticateDevice(packName, deviceId);
|
||||
int32_t ret= DeviceManager::GetInstance().UnAuthenticateDevice(packName, deviceInfo);
|
||||
// 4. check ret is DM_IPC_SEND_REQUEST_FAILED
|
||||
ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED);
|
||||
DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user