diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-06-28 16:41:11 +0200 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-12-14 18:58:45 +0100 |
commit | faa6c3d44c861c0486c1369e1d098b7645ab07cd (patch) | |
tree | 39accfea009e495729b4daa51a978b432f2a9b67 /src/test/banman_tests.cpp | |
parent | 9015d118425df4a5b34455da15334901ece85ed3 (diff) | |
download | bitcoin-faa6c3d44c861c0486c1369e1d098b7645ab07cd.tar.xz |
net: Drop only invalid entries when reading banlist.json
Currently all entries in the file are dropped. Fix that by only dropping the invalid ones
Diffstat (limited to 'src/test/banman_tests.cpp')
-rw-r--r-- | src/test/banman_tests.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/test/banman_tests.cpp b/src/test/banman_tests.cpp new file mode 100644 index 0000000000..27ce9ad638 --- /dev/null +++ b/src/test/banman_tests.cpp @@ -0,0 +1,43 @@ +// Copyright (c) 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 <banman.h> +#include <chainparams.h> +#include <netbase.h> +#include <streams.h> +#include <test/util/logging.h> +#include <test/util/setup_common.h> +#include <util/readwritefile.h> + + +#include <boost/test/unit_test.hpp> + +BOOST_FIXTURE_TEST_SUITE(banman_tests, BasicTestingSetup) + +BOOST_AUTO_TEST_CASE(file) +{ + SetMockTime(777s); + const fs::path banlist_path{m_args.GetDataDirBase() / "banlist_test"}; + { + const std::string entries_write{ + "{ \"banned_nets\": [" + " { \"version\": 1, \"ban_created\": 0, \"banned_until\": 778, \"address\": \"aaaaaaaaa\" }," + " { \"version\": 2, \"ban_created\": 0, \"banned_until\": 778, \"address\": \"bbbbbbbbb\" }," + " { \"version\": 1, \"ban_created\": 0, \"banned_until\": 778, \"address\": \"1.0.0.0/8\" }" + "] }", + }; + assert(WriteBinaryFile(banlist_path + ".json", entries_write)); + { + // The invalid entries will be dropped, but the valid one remains + ASSERT_DEBUG_LOG("Dropping entry with unparseable address or subnet (aaaaaaaaa) from ban list"); + ASSERT_DEBUG_LOG("Dropping entry with unknown version (2) from ban list"); + BanMan banman{banlist_path, /*client_interface=*/nullptr, /*default_ban_time=*/0}; + banmap_t entries_read; + banman.GetBanned(entries_read); + assert(entries_read.size() == 1); + } + } +} + +BOOST_AUTO_TEST_SUITE_END() |