tests: cover a peer restarting with the same key

A node restarting with the same key and contacting a peer by address gets answers encrypted with the ephemeral key of its previous run.
This commit is contained in:
Adrien Beraud committed 2026-10-29 23:28:48 -04:00
1 parent e78e54b8c5
commit d23cb42b27
2 files changed
+29

No files matched your search

+27
View File
@@ -1634,6 +1634,33 @@ NetworkEngineTester::testTransportEphemeralBoundToAddress()
CPPUNIT_ASSERT_EQUAL((size_t) 1, b.socket->sends.size());
}
void
NetworkEngineTester::testTransportRestartedPeerReconnects()
{
TransportConfig configA;
configA.key = transport::KeyPair::generate();
auto a = std::make_unique<TransportTestNode>("127.0.0.2", configA, 1);
TransportTestNode b("127.0.0.3", {}, 2);
bool done = false;
a->ping(b.addr, done);
a->deliverTo(b);
b.deliverTo(*a);
for (int i = 0; i < 2; i++) {
a->ping(a->node(b), done);
a->deliverTo(b);
b.deliverTo(*a);
}
// a restarts with the same key, and contacts b by address: b must forget a's ephemeral key
a = std::make_unique<TransportTestNode>("127.0.0.2", configA, 3);
done = false;
a->ping(b.addr, done);
a->deliverTo(b);
CPPUNIT_ASSERT(isEnvelope(b.socket->sends.at(0), transport::EnvelopeType::Initial));
b.deliverTo(*a);
CPPUNIT_ASSERT(done);
}
} // namespace test
#endif
+2
View File
@@ -41,6 +41,7 @@ class NetworkEngineTester : public CppUnit::TestFixture
CPPUNIT_TEST(testTransportSessionAuthorizesWrites);
CPPUNIT_TEST(testTransportInitialWriteIsUnauthorized);
CPPUNIT_TEST(testTransportEphemeralBoundToAddress);
CPPUNIT_TEST(testTransportRestartedPeerReconnects);
#endif
CPPUNIT_TEST_SUITE_END();
@@ -79,6 +80,7 @@ public:
void testTransportSessionAuthorizesWrites();
void testTransportInitialWriteIsUnauthorized();
void testTransportEphemeralBoundToAddress();
void testTransportRestartedPeerReconnects();
#endif
};