Page MenuHomePhorge

D372.1792402423.diff
No OneTemporary

Size
6 KB
Referenced Files
None
Subscribers
None

D372.1792402423.diff

diff --git a/src/client/client.cpp b/src/client/client.cpp
--- a/src/client/client.cpp
+++ b/src/client/client.cpp
@@ -27,14 +27,19 @@
static Client::PromiseT sendMultiVerificationEvents(Client::ContextT ctx, VerificationTracker::PendingEvents pendingEvents)
{
- std::vector<Client::PromiseT> ps;
+ auto p = ctx.createResolvedPromise({});
for (auto ed : pendingEvents) {
- ps.push_back(ctx.dispatch(SendToDeviceMessageAction{
- ed.event,
- {{ed.toUserId, {ed.toDeviceId}}}
- }));
+ p = p.then([ctx, ed](auto &&stat) {
+ return ctx.dispatch(SendToDeviceMessageAction{
+ ed.event,
+ {{ed.toUserId, {ed.toDeviceId}}}
+ }).then([stat](auto &&cur) {
+ using PromiseCombination::dataCombine;
+ return dataCombine(stat, cur);
+ });
+ });
}
- return ctx.promiseInterface().all(ps);
+ return p;
}
static Client::PromiseT maybeMarkDevicesVerified(Client::ContextT ctx, VerificationTracker::PendingEvents pendingEvents)
diff --git a/src/tests/client/verification-processing-test.cpp b/src/tests/client/verification-processing-test.cpp
--- a/src/tests/client/verification-processing-test.cpp
+++ b/src/tests/client/verification-processing-test.cpp
@@ -492,6 +492,117 @@
}
}
+TEST_CASE("Client verification processing - mac sent before done", "[client][verification]")
+{
+ boost::asio::io_context io;
+
+ VerificationTestSetup setup(io.get_executor());
+
+ bool macResolved = false;
+
+ auto dispatcherA = setup.utilA.getMockDispatcher(
+ makeHandler<EnsureKeysFromDevicesAction>([&setup](auto &ph, auto &ctx, EnsureKeysFromDevicesAction action) mutable {
+ return setup.handleKeyRequest(ph, ctx, action);
+ }),
+ returnEmpty<SendToDeviceMessageAction>(),
+ passDown<NotifyVerificationTrackerModelAction>(),
+ passDown<SetDevicesTrustLevelsAction>()
+ );
+ auto dispatcherB = setup.utilB.getMockDispatcher(
+ makeHandler<EnsureKeysFromDevicesAction>([&setup](auto &ph, auto &ctx, EnsureKeysFromDevicesAction action) mutable {
+ return setup.handleKeyRequest(ph, ctx, action);
+ }),
+ makeHandler<SendToDeviceMessageAction>([&io, &macResolved](auto &ph, auto &, SendToDeviceMessageAction a) {
+ if (a.event.type() == tMac) {
+ return ph.createResolveToPromise([&io, &macResolved, ph](auto resolve) {
+ auto timer = std::make_shared<boost::asio::steady_timer>(io);
+ timer->expires_after(std::chrono::milliseconds(100));
+ timer->async_wait([&macResolved, ph, resolve, timer](const boost::system::error_code &) {
+ macResolved = true;
+ resolve(ph.createResolved({}));
+ });
+ });
+ }
+ if (a.event.type() == tDone) {
+ REQUIRE(macResolved);
+ }
+ return ph.createResolved({});
+ }),
+ passDown<NotifyVerificationTrackerModelAction>(),
+ passDown<SetDevicesTrustLevelsAction>()
+ );
+
+ auto clientA = setup.utilA.getClient(dispatcherA);
+ auto clientB = setup.utilB.getClient(dispatcherB);
+
+ clientA.requestOutgoingToDeviceVerification(setup.userIdB, setup.deviceIdB)
+ .then([&](auto stat) {
+ REQUIRE(stat.success());
+ auto requestEvent = withSender(dispatcherA.of<SendToDeviceMessageAction>().at(0).event, setup.userIdA);
+ dispatcherA.clear();
+ return clientB.processVerificationEventsFromSync({requestEvent});
+ })
+ .then([&](auto stat) {
+ REQUIRE(stat.success());
+ dispatcherB.clear();
+ return clientB.readyForVerification(setup.userIdA, setup.deviceIdA);
+ })
+ .then([&](auto stat) {
+ REQUIRE(stat.success());
+ auto readyEvent = withSender(dispatcherB.of<SendToDeviceMessageAction>().at(0).event, setup.userIdB);
+ dispatcherB.clear();
+ return clientA.processVerificationEventsFromSync({readyEvent});
+ })
+ .then([&](auto stat) {
+ REQUIRE(stat.success());
+ auto startEvent = withSender(dispatcherA.of<SendToDeviceMessageAction>().at(0).event, setup.userIdA);
+ dispatcherA.clear();
+ return clientB.processVerificationEventsFromSync({startEvent});
+ })
+ .then([&](auto stat) {
+ REQUIRE(stat.success());
+ auto acceptEvent = withSender(dispatcherB.of<SendToDeviceMessageAction>().at(0).event, setup.userIdB);
+ dispatcherB.clear();
+ return clientA.processVerificationEventsFromSync({acceptEvent});
+ })
+ .then([&](auto stat) {
+ REQUIRE(stat.success());
+ auto keyEventA = withSender(dispatcherA.of<SendToDeviceMessageAction>().at(0).event, setup.userIdA);
+ dispatcherA.clear();
+ return clientB.processVerificationEventsFromSync({keyEventA});
+ })
+ .then([&](auto stat) {
+ REQUIRE(stat.success());
+ auto keyEventB = withSender(dispatcherB.of<SendToDeviceMessageAction>().at(0).event, setup.userIdB);
+ dispatcherB.clear();
+ return clientA.processVerificationEventsFromSync({keyEventB});
+ })
+ .then([&](auto stat) {
+ REQUIRE(stat.success());
+ return clientA.confirmVerificationSasMatch(setup.userIdB, setup.deviceIdB);
+ })
+ .then([&](auto stat) {
+ REQUIRE(stat.success());
+ auto macEventA = withSender(dispatcherA.of<SendToDeviceMessageAction>().at(0).event, setup.userIdA);
+ dispatcherA.clear();
+ return clientB.processVerificationEventsFromSync({macEventA});
+ })
+ .then([&](auto stat) {
+ REQUIRE(stat.success());
+ dispatcherB.clear();
+ return clientB.confirmVerificationSasMatch(setup.userIdA, setup.deviceIdA);
+ })
+ .then([&](auto stat) {
+ REQUIRE(stat.success());
+ auto sent = dispatcherB.of<SendToDeviceMessageAction>();
+ REQUIRE(sent.size() == 2);
+ REQUIRE(sent.at(0).event.type() == tMac);
+ REQUIRE(sent.at(1).event.type() == tDone);
+ io.stop();
+ });
+ io.run();
+}
+
TEST_CASE("Client verification processing - tracker model updates", "[client][verification]")
{
boost::asio::io_context io;

File Metadata

Mime Type
text/plain
Expires
Mon, Oct 19, 2:33 AM (22 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1789506
Default Alt Text
D372.1792402423.diff (6 KB)

Event Timeline