diff --git a/frameworks/libs/distributeddb/common/src/param_check_utils.cpp b/frameworks/libs/distributeddb/common/src/param_check_utils.cpp index 868448d185228d5de42e86b2115f32c93d0e3308..5b80769bb8d74597e8b3c0ebe33e498eb6bfdd57 100644 --- a/frameworks/libs/distributeddb/common/src/param_check_utils.cpp +++ b/frameworks/libs/distributeddb/common/src/param_check_utils.cpp @@ -169,7 +169,7 @@ int ParamCheckUtils::CheckAndTransferAutoLaunchParam(const AutoLaunchParam ¶ LOGE("[AutoLaunch] CheckConflictNotifierType is invalid."); return -E_INVALID_ARGS; } - if (!ParamCheckUtils::CheckStoreParameter(param.storeId, param.appId, param.userId)) { + if (!ParamCheckUtils::CheckStoreParameter(param.storeId, param.appId, param.userId, false, param.subUser)) { LOGE("[AutoLaunch] CheckStoreParameter is invalid."); return -E_INVALID_ARGS; } diff --git a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_executor_utils.cpp b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_executor_utils.cpp index 30dcbc47822be47c856167b21e56a658379a30f9..f543632177127f77510595a13eb0833d7a9915d2 100644 --- a/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_executor_utils.cpp +++ b/frameworks/libs/distributeddb/storage/src/sqlite/sqlite_cloud_kv_executor_utils.cpp @@ -60,7 +60,6 @@ Timestamp SqliteCloudKvExecutorUtils::GetMaxTimeStamp(const std::vector { Timestamp maxTimeStamp = 0; if (dataExtend.empty()) { - LOGE("[SqliteCloudKvExecutorUtils] [GetMaxTimeStamp] data extend is empty."); return maxTimeStamp; } VBucket lastRecord = dataExtend.back(); diff --git a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync.cpp b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync.cpp index 536125edf921a85f04a810b6701609e9a0d61af2..8901c9f1774dbb1007cfed3e769f92600c917f8e 100644 --- a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync.cpp +++ b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync.cpp @@ -946,7 +946,7 @@ int SingleVerDataSync::DoAbilitySyncIfNeed(SingleVerSyncTaskContext *context, co } } -int SingleVerDataSync::DataRequestRecvPre(SingleVerSyncTaskContext *context, const Message *message) +int SingleVerDataSync::DataRequestRecvPre(SingleVerSyncTaskContext *context, const Message *message, bool &isDeniedSend) { if (context == nullptr || message == nullptr) { return -E_INVALID_ARGS; @@ -970,7 +970,7 @@ int SingleVerDataSync::DataRequestRecvPre(SingleVerSyncTaskContext *context, con LOGE("[DataSync][DataRequestRecvPre] remote pullResponse getData sendCode=%d", sendCode); return sendCode; } - int errCode = RunPermissionCheck(context, message, packet); + int errCode = RunPermissionCheck(context, message, packet, isDeniedSend); if (errCode != E_OK) { return errCode; } @@ -1047,11 +1047,16 @@ int SingleVerDataSync::DataRequestRecvInner(SingleVerSyncTaskContext *context, c int SingleVerDataSync::DataRequestRecv(SingleVerSyncTaskContext *context, const Message *message, WaterMark &pullEndWatermark) { - int errCode = DataRequestRecvPre(context, message); + bool isDeniedSend = false; + int errCode = DataRequestRecvPre(context, message, isDeniedSend); if (errCode != E_OK) { return errCode; } - return DataRequestRecvInner(context, message, pullEndWatermark); + errCode = DataRequestRecvInner(context, message, pullEndWatermark); + if (isDeniedSend) { + pullEndWatermark = 0; + } + return errCode; } int SingleVerDataSync::SendDataPacket(SyncType syncType, DataRequestPacket *packet, @@ -1345,7 +1350,7 @@ int SingleVerDataSync::DealWaterMarkException(SingleVerSyncTaskContext *context, } int SingleVerDataSync::RunPermissionCheck(SingleVerSyncTaskContext *context, const Message *message, - const DataRequestPacket *packet) + const DataRequestPacket *packet, bool &isDeniedSend) { int mode = SyncOperation::TransferSyncMode(packet->GetMode()); auto checkRet = SingleVerDataSyncUtils::RunPermissionCheck(context, storage_, label_, packet); @@ -1377,6 +1382,7 @@ int SingleVerDataSync::RunPermissionCheck(SingleVerSyncTaskContext *context, con if (checkRet.ret == DataFlowCheckRet::DENIED_SEND && ((mode == PUSH_AND_PULL) || (mode == PULL))) { SyncEntry entry; errCode = SendPullResponseDataPkt(SEND_FINISHED, entry, context, packet->GetSessionId()); + isDeniedSend = true; } return errCode; } diff --git a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync.h b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync.h index 06cc51c25211525c5c401d40a0447835c2a099e1..dba4c91023b6d1ff20133ea849519dfa52e93578 100644 --- a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync.h +++ b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync.h @@ -195,7 +195,7 @@ protected: int DoAbilitySyncIfNeed(SingleVerSyncTaskContext *context, const Message *message, bool isControlMsg = false); - int DataRequestRecvPre(SingleVerSyncTaskContext *context, const Message *message); + int DataRequestRecvPre(SingleVerSyncTaskContext *context, const Message *message, bool &isDeniedSend); void GetPullEndWatermark(const SingleVerSyncTaskContext *context, const DataRequestPacket *packet, WaterMark &pullEndWatermark) const; @@ -204,7 +204,7 @@ protected: const std::vector &reserved); int RunPermissionCheck(SingleVerSyncTaskContext *context, const Message *message, - const DataRequestPacket *packet); + const DataRequestPacket *packet, bool &isDeniedSend); void SendResetWatchDogPacket(SingleVerSyncTaskContext *context, uint32_t packetLen); diff --git a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync_utils.cpp b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync_utils.cpp index 83046a5ab25c40198e6983bf16e88baa4765c921..a1618552b7a64986ccdd8a9b1f87e18948c35025 100644 --- a/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync_utils.cpp +++ b/frameworks/libs/distributeddb/syncer/src/device/singlever/single_ver_data_sync_utils.cpp @@ -26,6 +26,7 @@ void FillPermissionCheckParam(const SyncGenericInterface* storage, int mode, Per param.appId = storage->GetDbProperties().GetStringProp(DBProperties::APP_ID, ""); param.userId = storage->GetDbProperties().GetStringProp(DBProperties::USER_ID, ""); param.storeId = storage->GetDbProperties().GetStringProp(DBProperties::STORE_ID, ""); + param.subUserId = storage->GetDbProperties().GetStringProp(DBProperties::SUB_USER, ""); param.instanceId = storage->GetDbProperties().GetIntProp(DBProperties::INSTANCE_ID, 0); switch (mode) { case SyncModeType::PUSH: diff --git a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_auto_launch_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_auto_launch_test.cpp index 846a733a339381ca2801a363a3b9fe92b09b8c6b..bb248643ee2697831daaf5a0b3fa061f99a22585 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_auto_launch_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/interfaces/distributeddb_interfaces_auto_launch_test.cpp @@ -472,7 +472,7 @@ HWTEST_F(DistributedDBInterfacesAutoLaunchTest, EnableKvStoreAutoLaunch005, Test } /** - * @tc.name: EnableKvStoreAutoLaunch005 + * @tc.name: EnableKvStoreAutoLaunch006 * @tc.desc: test the over limits for the enable list. * @tc.type: FUNC * @tc.require: @@ -529,6 +529,25 @@ HWTEST_F(DistributedDBInterfacesAutoLaunchTest, EnableKvStoreAutoLaunch006, Test EXPECT_EQ(KvStoreDelegateManager::DisableKvStoreAutoLaunch(USER_ID1, APP_ID1, "store_1"), NOT_FOUND); } +/** + * @tc.name: EnableKvStoreAutoLaunch007 + * @tc.desc: test invalid enable auto launch. + * @tc.type: FUNC + * @tc.author: zqq + */ +HWTEST_F(DistributedDBInterfacesAutoLaunchTest, EnableKvStoreAutoLaunch007, TestSize.Level0) +{ + CipherPassword passwd; + AutoLaunchOption launchOption = {true, false, CipherType::DEFAULT, passwd, "", false, g_testDir}; + AutoLaunchParam param; + param.storeId = "store_id"; + param.userId = USER_ID1; + param.appId = APP_ID1; + param.option = launchOption; + param.subUser.resize(129, 'u'); // 129 is invalid length + EXPECT_EQ(KvStoreDelegateManager::EnableKvStoreAutoLaunch(param), INVALID_ARGS); +} + namespace { void SetAutoLaunchLifeCycleTime(const std::string &storeId, uint32_t time) { @@ -545,7 +564,7 @@ void SetAutoLaunchLifeCycleTime(const std::string &storeId, uint32_t time) } } /** - * @tc.name: EnableKvStoreAutoLaunch007 + * @tc.name: DisableKvStoreAutoLaunch001 * @tc.desc: test the over limits for the enable list. * @tc.type: FUNC * @tc.require: diff --git a/frameworks/libs/distributeddb/test/unittest/common/store_test/kv/distributeddb_kv_permission_sync_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/store_test/kv/distributeddb_kv_permission_sync_test.cpp index d5c92c868aba9c40fd27d29ff3a33dcdd34682ae..addd708e9fbda7494e9537fee94befeb91c27b0c 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/store_test/kv/distributeddb_kv_permission_sync_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/store_test/kv/distributeddb_kv_permission_sync_test.cpp @@ -33,6 +33,7 @@ protected: void CheckData(const StoreInfo &info, const Entry &expectEntry, DBStatus status); static constexpr const char *DEVICE_A = "DEVICE_A"; static constexpr const char *DEVICE_B = "DEVICE_B"; + std::atomic callbackCount_ = 0; }; void DistributedDBKvPermissionSyncTest::SetUp() @@ -43,8 +44,9 @@ void DistributedDBKvPermissionSyncTest::SetUp() auto storeInfo2 = GetStoreInfo2(); ASSERT_EQ(BasicUnitTest::InitDelegate(storeInfo2, DEVICE_B), E_OK); ASSERT_NO_FATAL_FAILURE(PrepareData()); - RuntimeConfig::SetDataFlowCheckCallback([storeInfo1, storeInfo2](const PermissionCheckParam ¶m, + RuntimeConfig::SetDataFlowCheckCallback([storeInfo1, storeInfo2, this](const PermissionCheckParam ¶m, const Property &property) { + callbackCount_++; if (param.storeId == storeInfo2.storeId) { EXPECT_EQ(property.size(), 1); return DataFlowCheckRet::DEFAULT; @@ -56,6 +58,7 @@ void DistributedDBKvPermissionSyncTest::SetUp() void DistributedDBKvPermissionSyncTest::TearDown() { + callbackCount_ = 0; RuntimeConfig::SetDataFlowCheckCallback(nullptr); PermissionCheckCallbackV4 callbackV4 = nullptr; RuntimeConfig::SetPermissionCheckCallback(callbackV4); @@ -189,6 +192,7 @@ HWTEST_F(DistributedDBKvPermissionSyncTest, KVPermissionSync005, TestSize.Level0 DBStatus::OK); EXPECT_NO_FATAL_FAILURE(CheckData(GetStoreInfo1(), DistributedDBToolsUnitTest::GetK1V1(), OK)); EXPECT_NO_FATAL_FAILURE(CheckData(GetStoreInfo2(), DistributedDBToolsUnitTest::GetK1V1(), NOT_FOUND)); + EXPECT_EQ(callbackCount_.load(), 3); // check callback 3 times } /** diff --git a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_multi_sub_user_test.cpp b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_multi_sub_user_test.cpp index 1f612d0e368600b22b49b41b8b87f5f58712f854..0e385ce58ad33dac8067899c5de53733e7fc79d5 100644 --- a/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_multi_sub_user_test.cpp +++ b/frameworks/libs/distributeddb/test/unittest/common/syncer/distributeddb_single_ver_multi_sub_user_test.cpp @@ -837,9 +837,20 @@ HWTEST_F(DistributedDBSingleVerMultiSubUserTest, MultiSubUserDelegateSync002, Te ASSERT_NE(delegatePtr1, nullptr); std::map result; + std::atomic count = 0; + RuntimeConfig::SetPermissionCheckCallback([&count](const PermissionCheckParam ¶m, uint8_t flag) { + if (param.storeId == STORE_ID_1) { + EXPECT_EQ(param.subUserId, SUB_USER_1); + count++; + } + return true; + }); DBStatus status = g_tool.SyncTest(delegatePtr1, { DEVICE_B }, SYNC_MODE_PUSH_ONLY, result); EXPECT_EQ(status, OK); EXPECT_EQ(result[DEVICE_B], OK); + PermissionCheckCallbackV3 callback = nullptr; + RuntimeConfig::SetPermissionCheckCallback(callback); + EXPECT_GE(count, 1); CloseDelegate(delegatePtr1, mgr1, STORE_ID_1); }