forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge bitcoin#22362: Drop only invalid entries when reading banlist.json
faa6c3d net: Drop only invalid entries when reading banlist.json (MarcoFalke) Pull request description: All entries will be dropped when there is at least one invalid one in `banlist.json`. Fix this by only dropping invalid ones. Also suggested in bitcoin#20966 (comment) ACKs for top commit: laanwj: Re-ACK faa6c3d Tree-SHA512: 5a58e7f1dcabf78d0c65d8c6d5d997063af1efeaa50ca7730fc00056fda7e0061b6f7a38907ea045fe667c9f61d392e01e556b425a95e6b126e3c41cd33deb83
- Loading branch information
1 parent
b32add5
commit 9dc526f
Showing
3 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |