aboutsummaryrefslogtreecommitdiff
path: root/src/test/i2p_tests.cpp
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2021-03-11 16:27:22 +0100
committerVasil Dimov <vd@FreeBSD.org>2021-03-16 14:58:38 +0100
commit40316a37cb02cf8a9a8b2cbd4d7153ffa57e7ec5 (patch)
tree19db70f0951663b02a31139f8afe47cc1d2c7f0f /src/test/i2p_tests.cpp
parent2d8ac779708322e1235e823edfc9c8f6e2dd65e4 (diff)
downloadbitcoin-40316a37cb02cf8a9a8b2cbd4d7153ffa57e7ec5.tar.xz
test: add I2P test for a runaway SAM proxy
Add a regression test for https://github.com/bitcoin/bitcoin/pull/21407. The test creates a socket that, upon read, returns some data, but never the expected terminator `\n`, injects that socket into the I2P code and expects `i2p::sam::Session::Connect()` to fail, printing a specific error message to the log.
Diffstat (limited to 'src/test/i2p_tests.cpp')
-rw-r--r--src/test/i2p_tests.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/test/i2p_tests.cpp b/src/test/i2p_tests.cpp
new file mode 100644
index 0000000000..334f71106c
--- /dev/null
+++ b/src/test/i2p_tests.cpp
@@ -0,0 +1,44 @@
+// Copyright (c) 2021-2021 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <i2p.h>
+#include <netaddress.h>
+#include <test/util/logging.h>
+#include <test/util/net.h>
+#include <test/util/setup_common.h>
+#include <threadinterrupt.h>
+#include <util/system.h>
+
+#include <boost/test/unit_test.hpp>
+
+#include <memory>
+#include <string>
+
+BOOST_FIXTURE_TEST_SUITE(i2p_tests, BasicTestingSetup)
+
+BOOST_AUTO_TEST_CASE(unlimited_recv)
+{
+ auto CreateSockOrig = CreateSock;
+
+ // Mock CreateSock() to create MockSock.
+ CreateSock = [](const CService&) {
+ return std::make_unique<StaticContentsSock>(std::string(i2p::sam::MAX_MSG_SIZE + 1, 'a'));
+ };
+
+ CThreadInterrupt interrupt;
+ i2p::sam::Session session(GetDataDir() / "test_i2p_private_key", CService{}, &interrupt);
+
+ {
+ ASSERT_DEBUG_LOG("Creating SAM session");
+ ASSERT_DEBUG_LOG("too many bytes without a terminator");
+
+ i2p::Connection conn;
+ bool proxy_error;
+ BOOST_REQUIRE(!session.Connect(CService{}, conn, proxy_error));
+ }
+
+ CreateSock = CreateSockOrig;
+}
+
+BOOST_AUTO_TEST_SUITE_END()