Add tests for alerts enabling RPC safe mode
This commit is contained in:
parent
a40034f7d6
commit
6567a7b534
|
@ -13,6 +13,8 @@
|
|||
#include "data/alertTests.raw.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "rpcprotocol.h"
|
||||
#include "rpcserver.h"
|
||||
#include "serialize.h"
|
||||
#include "streams.h"
|
||||
#include "util.h"
|
||||
|
@ -25,6 +27,7 @@
|
|||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "json/json_spirit_reader_template.h"
|
||||
|
||||
#include "key.h"
|
||||
#include "alertkeys.h"
|
||||
|
@ -182,9 +185,22 @@ void GenerateAlertTests()
|
|||
++alert.nID;
|
||||
SignAndSerialize(alert, sBuffer);
|
||||
|
||||
++alert.nID;
|
||||
alert.nPriority = 5000;
|
||||
alert.strStatusBar = "Alert 3, disables RPC";
|
||||
alert.strRPCError = "RPC disabled";
|
||||
SignAndSerialize(alert, sBuffer);
|
||||
|
||||
++alert.nID;
|
||||
alert.nPriority = 5000;
|
||||
alert.strStatusBar = "Alert 4, re-enables RPC";
|
||||
alert.strRPCError = "";
|
||||
SignAndSerialize(alert, sBuffer);
|
||||
|
||||
++alert.nID;
|
||||
alert.nMinVer = 11;
|
||||
alert.nMaxVer = 22;
|
||||
alert.nPriority = 100;
|
||||
SignAndSerialize(alert, sBuffer);
|
||||
|
||||
++alert.nID;
|
||||
|
@ -320,7 +336,7 @@ BOOST_AUTO_TEST_CASE(AlertNotify)
|
|||
alert.ProcessAlert(alertKey, false);
|
||||
|
||||
std::vector<std::string> r = read_lines(temp);
|
||||
BOOST_CHECK_EQUAL(r.size(), 4u);
|
||||
BOOST_CHECK_EQUAL(r.size(), 6u);
|
||||
|
||||
// Windows built-in echo semantics are different than posixy shells. Quotes and
|
||||
// whitespace are printed literally.
|
||||
|
@ -329,16 +345,43 @@ BOOST_AUTO_TEST_CASE(AlertNotify)
|
|||
BOOST_CHECK_EQUAL(r[0], "Alert 1");
|
||||
BOOST_CHECK_EQUAL(r[1], "Alert 2, cancels 1");
|
||||
BOOST_CHECK_EQUAL(r[2], "Alert 2, cancels 1");
|
||||
BOOST_CHECK_EQUAL(r[3], "Evil Alert; /bin/ls; echo "); // single-quotes should be removed
|
||||
BOOST_CHECK_EQUAL(r[3], "Alert 3, disables RPC");
|
||||
BOOST_CHECK_EQUAL(r[4], "Alert 4, reenables RPC"); // dashes should be removed
|
||||
BOOST_CHECK_EQUAL(r[5], "Evil Alert; /bin/ls; echo "); // single-quotes should be removed
|
||||
#else
|
||||
BOOST_CHECK_EQUAL(r[0], "'Alert 1' ");
|
||||
BOOST_CHECK_EQUAL(r[1], "'Alert 2, cancels 1' ");
|
||||
BOOST_CHECK_EQUAL(r[2], "'Alert 2, cancels 1' ");
|
||||
BOOST_CHECK_EQUAL(r[3], "'Evil Alert; /bin/ls; echo ' ");
|
||||
BOOST_CHECK_EQUAL(r[3], "'Alert 3, disables RPC' ");
|
||||
BOOST_CHECK_EQUAL(r[4], "'Alert 4, reenables RPC' "); // dashes should be removed
|
||||
BOOST_CHECK_EQUAL(r[5], "'Evil Alert; /bin/ls; echo ' ");
|
||||
#endif
|
||||
boost::filesystem::remove(temp);
|
||||
|
||||
SetMockTime(0);
|
||||
mapAlerts.clear();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(AlertDisablesRPC)
|
||||
{
|
||||
SetMockTime(11);
|
||||
const std::vector<unsigned char>& alertKey = Params(CBaseChainParams::MAIN).AlertKey();
|
||||
|
||||
// Command should work before alerts
|
||||
BOOST_CHECK_EQUAL(GetWarnings("rpc"), "");
|
||||
|
||||
// First alert should disable RPC
|
||||
alerts[5].ProcessAlert(alertKey, false);
|
||||
BOOST_CHECK_EQUAL(alerts[5].strRPCError, "RPC disabled");
|
||||
BOOST_CHECK_EQUAL(GetWarnings("rpc"), "RPC disabled");
|
||||
|
||||
// Second alert should re-enable RPC
|
||||
alerts[6].ProcessAlert(alertKey, false);
|
||||
BOOST_CHECK_EQUAL(alerts[6].strRPCError, "");
|
||||
BOOST_CHECK_EQUAL(GetWarnings("rpc"), "");
|
||||
|
||||
SetMockTime(0);
|
||||
mapAlerts.clear();
|
||||
}
|
||||
|
||||
static bool falseFunc() { return false; }
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue