Changeset View
Standalone View
src/test/net_tests.cpp
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | void Serialize(CDataStream &s) const override { | ||||
CAddress addr = CAddress(serv, NODE_NONE); | CAddress addr = CAddress(serv, NODE_NONE); | ||||
CNetAddr resolved; | CNetAddr resolved; | ||||
LookupHost("252.2.2.2", resolved, false); | LookupHost("252.2.2.2", resolved, false); | ||||
CAddrInfo info = CAddrInfo(addr, resolved); | CAddrInfo info = CAddrInfo(addr, resolved); | ||||
s << info; | s << info; | ||||
} | } | ||||
}; | }; | ||||
class DummyConfigNetTest : public DummyConfig { | |||||
deadalnix: You don't need to postfix the name, boost tests are namespaced | |||||
FabienAuthorUnsubmitted Done Inline ActionsDummyConfig already exists Fabien: DummyConfig already exists | |||||
public: | |||||
bool SetMaxBlockSize(uint64_t maxBlockSize) override { | |||||
nMaxBlockSize = maxBlockSize; | |||||
return true; | |||||
} | |||||
uint64_t GetMaxBlockSize() const override { return nMaxBlockSize; } | |||||
private: | |||||
uint64_t nMaxBlockSize; | |||||
}; | |||||
CDataStream AddrmanToStream(CAddrManSerializationMock &_addrman) { | CDataStream AddrmanToStream(CAddrManSerializationMock &_addrman) { | ||||
CDataStream ssPeersIn(SER_DISK, CLIENT_VERSION); | CDataStream ssPeersIn(SER_DISK, CLIENT_VERSION); | ||||
ssPeersIn << FLATDATA(Params().DiskMagic()); | ssPeersIn << FLATDATA(Params().DiskMagic()); | ||||
ssPeersIn << _addrman; | ssPeersIn << _addrman; | ||||
std::string str = ssPeersIn.str(); | std::string str = ssPeersIn.str(); | ||||
std::vector<uint8_t> vchData(str.begin(), str.end()); | std::vector<uint8_t> vchData(str.begin(), str.end()); | ||||
return CDataStream(vchData, SER_DISK, CLIENT_VERSION); | return CDataStream(vchData, SER_DISK, CLIENT_VERSION); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(test_getSubVersionEB) { | ||||
BOOST_CHECK_EQUAL(getSubVersionEB(1540000), "1.5"); | BOOST_CHECK_EQUAL(getSubVersionEB(1540000), "1.5"); | ||||
BOOST_CHECK_EQUAL(getSubVersionEB(1560000), "1.5"); | BOOST_CHECK_EQUAL(getSubVersionEB(1560000), "1.5"); | ||||
BOOST_CHECK_EQUAL(getSubVersionEB(210000), "0.2"); | BOOST_CHECK_EQUAL(getSubVersionEB(210000), "0.2"); | ||||
BOOST_CHECK_EQUAL(getSubVersionEB(10000), "0.0"); | BOOST_CHECK_EQUAL(getSubVersionEB(10000), "0.0"); | ||||
BOOST_CHECK_EQUAL(getSubVersionEB(0), "0.0"); | BOOST_CHECK_EQUAL(getSubVersionEB(0), "0.0"); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(test_userAgentLength) { | BOOST_AUTO_TEST_CASE(test_userAgentLength) { | ||||
GlobalConfig config; | DummyConfigNetTest config; | ||||
config.SetMaxBlockSize(8000000); | config.SetMaxBlockSize(8000000); | ||||
std::string long_uacomment = "very very very very very very very very very " | std::string long_uacomment = "very very very very very very very very very " | ||||
"very very very very very very very very very " | "very very very very very very very very very " | ||||
"very very very very very very very very very " | "very very very very very very very very very " | ||||
"very very very very very very very very very " | "very very very very very very very very very " | ||||
"very very very very very very very very very " | "very very very very very very very very very " | ||||
"very very very very very very very very very " | "very very very very very very very very very " | ||||
Show All 9 Lines | versionMessage << "/Bitcoin ABC:" << CLIENT_VERSION_MAJOR << "." | ||||
"very very very very very very very very very very very " | "very very very very very very very very very very very " | ||||
"very very very very very very very very very very very " | "very very very very very very very very very very very " | ||||
"very very very very very very very ve)/"; | "very very very very very very very ve)/"; | ||||
BOOST_CHECK_EQUAL(userAgent(config).size(), MAX_SUBVERSION_LENGTH); | BOOST_CHECK_EQUAL(userAgent(config).size(), MAX_SUBVERSION_LENGTH); | ||||
BOOST_CHECK_EQUAL(userAgent(config), versionMessage.str()); | BOOST_CHECK_EQUAL(userAgent(config), versionMessage.str()); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(test_userAgentSanitize) { | |||||
DummyConfigNetTest config; | |||||
config.SetMaxBlockSize(32000000); | |||||
gArgs.ClearMultiArg("-uacomment"); | |||||
const std::string goodua = "A valid user agent comment .,;-_?@"; | |||||
gArgs.ForceSetMultiArg("-uacomment", goodua); | |||||
std::ostringstream goodSubversion; | |||||
goodSubversion << "/Bitcoin ABC:" << CLIENT_VERSION_MAJOR << "." | |||||
<< CLIENT_VERSION_MINOR << "." << CLIENT_VERSION_REVISION | |||||
<< "(EB32.0; " << goodua << ")/"; | |||||
BOOST_CHECK_EQUAL(userAgent(config), goodSubversion.str()); | |||||
gArgs.ClearMultiArg("-uacomment"); | |||||
const std::string badua = "A bad user agent comment /+:!"; | |||||
gArgs.ForceSetMultiArg("-uacomment", badua); | |||||
std::ostringstream sanSubversion; | |||||
sanSubversion << "/Bitcoin ABC:" << CLIENT_VERSION_MAJOR << "." | |||||
<< CLIENT_VERSION_MINOR << "." << CLIENT_VERSION_REVISION | |||||
<< "(EB32.0; A bad user agent comment )/"; | |||||
deadalnixUnsubmitted Not Done Inline ActionsWhat is so bad about it that we want to remove these characters ? deadalnix: What is so bad about it that we want to remove these characters ? | |||||
FabienAuthorUnsubmitted Done Inline Actions'/', ':', '(', ')' are forbidden by bip0014, the other chars are historically restricted to avoid any remote attack using their interpretation by various protocols. /** * safeChars chosen to allow simple messages/URLs/email addresses, but avoid anything * even possibly remotely dangerous like & or > */ Fabien: '/', ':', '(', ')' are forbidden by bip0014, the other chars are historically restricted to… | |||||
deadalnixUnsubmitted Not Done Inline ActionsIt still doesn't really explains what the problem is. deadalnix: It still doesn't really explains what the problem is. | |||||
deadalnixUnsubmitted Not Done Inline ActionsIf the use of these character is simply discouraged, then I don't see a reason to do anything else than warn. If the use of these character is a serious issue, then it'd be great to know what that issue is and mebe report it to the user instead of changing the comment behind his back. If the use of these character is a security concern, then it would be great to address that concern to begin with, as it seems pretty serious and this isn't cutting it. deadalnix: If the use of these character is simply discouraged, then I don't see a reason to do anything… | |||||
BOOST_CHECK_EQUAL(userAgent(config), sanSubversion.str()); | |||||
} | |||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |
You don't need to postfix the name, boost tests are namespaced