69 BEAST_EXPECT(trustedSites->load(emptyCfgSites));
73 {
"http://ripple.com/",
74 "http://ripple.com/validators",
75 "http://ripple.com:8080/validators",
76 "http://207.261.33.37/validators",
77 "http://207.261.33.37:8080/validators",
78 "https://ripple.com/validators",
79 "https://ripple.com:443/validators",
80 "file:///etc/xrpld/validators.txt",
81 "file:///C:/Lib/validators.txt"
87 BEAST_EXPECT(trustedSites->load(cfgSites));
91 BEAST_EXPECT(!trustedSites->load(badSites));
93 badSites[0] =
"wss://ripple.com/validators";
94 BEAST_EXPECT(!trustedSites->load(badSites));
96 badSites[0] =
"ripple.com/validators";
97 BEAST_EXPECT(!trustedSites->load(badSites));
100 badSites[0] =
"file://ripple.com/vl.txt";
101 BEAST_EXPECT(!trustedSites->load(badSites));
104 badSites[0] =
"file://localhost/home/user/vl.txt";
105 BEAST_EXPECT(!trustedSites->load(badSites));
108 badSites[0] =
"file://127.0.0.1/home/user/vl.txt";
109 BEAST_EXPECT(!trustedSites->load(badSites));
112 badSites[0] =
"file://";
113 BEAST_EXPECT(!trustedSites->load(badSites));
118 badSites[0] =
"file:///";
119 BEAST_EXPECT(!trustedSites->load(badSites));
152 << boost::algorithm::join(
153 paths | boost::adaptors::transformed([](FetchListConfig
const& cfg) {
154 return cfg.path + (cfg.ssl ?
" [https] v" :
" [http] v") +
160 using namespace std::chrono_literals;
167 auto& trustedKeys = env.app().getValidators();
168 env.timeKeeper().set(env.timeKeeper().now() + 30s);
170 test::StreamSink sink;
173 std::vector<std::string>
const emptyCfgKeys;
176 Publisher(FetchListConfig
const& c) : cfg{c}
179 std::shared_ptr<TrustedPublisherServer> server;
180 std::vector<Validator> list;
182 FetchListConfig
const& cfg;
185 std::vector<Publisher> servers;
187 static constexpr auto kListSize = 20;
188 std::vector<std::string> cfgPublishers;
190 for (
auto const& cfg : paths)
193 auto& item = servers.
back();
194 item.isRetry = cfg.path ==
"/bad-resource";
195 item.list.reserve(kListSize);
196 while (item.list.size() < kListSize)
203 env.app().getIOContext(),
206 {{effective2, expires2}},
209 std::string
const pubHex =
strHex(item.server->publisherPublic());
212 if (item.cfg.failFetch)
215 auto const name = good.
subdir() / (
"cache." + pubHex);
216 std::ofstream o(name.string());
220 std::stringstream uri;
221 uri << (cfg.ssl ?
"https://" :
"http://") << item.server->localEndpoint() << cfg.path;
222 item.uri = uri.
str();
225 BEAST_EXPECT(trustedKeys.load({}, emptyCfgKeys, cfgPublishers));
232 std::vector<std::string> uris;
233 for (
auto const& u : servers)
242 auto const jv = sites->getJson();
243 for (
auto const& u : servers)
245 for (
auto const& val : u.list)
247 BEAST_EXPECT(trustedKeys.listed(val.masterPublic) != u.cfg.failApply);
248 BEAST_EXPECT(trustedKeys.listed(val.signingPublic) != u.cfg.failApply);
251 json::Value myStatus;
252 for (
auto const& vs : jv[jss::validator_sites])
254 if (vs[jss::uri].asString().contains(u.uri))
258 myStatus[jss::last_refresh_message].asString().
empty() != u.cfg.failFetch,
259 to_string(myStatus) +
"\n" + sink.messages().str());
261 if (!u.cfg.msg.empty())
263 BEAST_EXPECTS(sink.messages().str().contains(u.cfg.msg), sink.messages().str());
266 if (u.cfg.expectedRefreshMin != 0)
269 myStatus[jss::refresh_interval_min].asInt() == u.cfg.expectedRefreshMin,
275 using namespace std::chrono;
276 std::stringstream nextRefreshStr{myStatus[jss::next_refresh_time].
asString()};
277 system_clock::time_point nextRefresh;
278 date::from_stream(nextRefreshStr,
"%Y-%b-%d %T", nextRefresh);
279 BEAST_EXPECT(!nextRefreshStr.
fail());
282 nextRefresh <= now + (u.isRetry ? seconds{30} : minutes{5}),
283 "Now: " +
to_string(now) +
", NR: " + nextRefreshStr.
str());
388 for (
auto const ssl : {
true,
false})
391 testFetchList(good, {{.path =
"/validators", .msg =
"", .ssl = ssl}});
392 testFetchList(good, {{.path =
"/validators2", .msg =
"", .ssl = ssl}});
397 {.path =
"/validators", .msg =
"", .ssl = ssl},
398 {.path =
"/validators", .msg =
"", .ssl = ssl},
403 {.path =
"/validators", .msg =
"", .ssl = ssl},
404 {.path =
"/validators2", .msg =
"", .ssl = ssl},
409 {.path =
"/validators2", .msg =
"", .ssl = ssl},
410 {.path =
"/validators", .msg =
"", .ssl = ssl},
415 {.path =
"/validators2", .msg =
"", .ssl = ssl},
416 {.path =
"/validators2", .msg =
"", .ssl = ssl},
419 testFetchList(good, {{.path =
"/redirect_once/301", .msg =
"", .ssl = ssl}});
420 testFetchList(good, {{.path =
"/redirect_once/302", .msg =
"", .ssl = ssl}});
421 testFetchList(good, {{.path =
"/redirect_once/307", .msg =
"", .ssl = ssl}});
422 testFetchList(good, {{.path =
"/redirect_once/308", .msg =
"", .ssl = ssl}});
427 {.path =
"/validators", .msg =
"", .ssl = ssl},
428 {.path =
"/redirect_once/302", .msg =
"", .ssl = ssl},
433 {.path =
"/validators2", .msg =
"", .ssl = ssl},
434 {.path =
"/redirect_once/302", .msg =
"", .ssl = ssl},
442 .path =
"/validators2",
457 .path =
"/redirect_forever/301",
458 .msg =
"Exceeded max redirects",
469 .path =
"/redirect_forever/307",
470 .msg =
"Exceeded max redirects",
476 .path =
"/redirect_forever/308",
477 .msg =
"Exceeded max redirects",
487 {.path =
"/validators", .msg =
"", .ssl = ssl},
489 .path =
"/redirect_forever/302",
490 .msg =
"Exceeded max redirects",
500 {.path =
"/validators2", .msg =
"", .ssl = ssl},
502 .path =
"/redirect_forever/302",
503 .msg =
"Exceeded max redirects",
514 .path =
"/redirect_to/ftp://invalid-url/302",
515 .msg =
"Invalid redirect location",
525 .path =
"/redirect_to/file://invalid-url/302",
526 .msg =
"Invalid redirect location",
537 .path =
"/validators/bad",
538 .msg =
"Unable to parse JSON response",
548 .path =
"/validators2/bad",
549 .msg =
"Unable to parse JSON response",
560 .path =
"/bad-resource",
561 .msg =
"returned bad status",
572 .path =
"/redirect_nolo/308",
573 .msg =
"returned a redirect with no Location",
584 .path =
"/validators/missing",
585 .msg =
"Missing fields in JSON response",
595 .path =
"/validators2/missing",
596 .msg =
"Missing fields in JSON response",
608 .msg =
"took too long",
621 .path =
"/validators",
622 .msg =
"Missing fields",
634 .path =
"/validators2",
635 .msg =
"Missing fields",
650 .path =
"/validators",
651 .msg =
"Missing fields",
662 .path =
"/validators2",
663 .msg =
"1 unsupported version",
670 using namespace std::chrono_literals;
676 .path =
"/validators",
677 .msg =
"Applied 1 expired validator list(s)",
682 .expiresFromNow = 0s,
689 .path =
"/validators2",
690 .msg =
"Applied 1 expired validator list(s)",
695 .expiresFromNow = 0s,
696 .effectiveOverlap = -1s,
704 .path =
"/validators",
705 .msg =
"1 invalid validator list(s)",
720 .path =
"/validators2",
727 .effectiveOverlap = 299s,
737 .path =
"/validators2",
744 .effectiveOverlap = 301s,
752 .path =
"/validators2",
753 .msg =
"2 invalid validator list(s)",
767 .path =
"/validators/refresh/0",
775 .expectedRefreshMin = 1,
782 .path =
"/validators2/refresh/0",
790 .expectedRefreshMin = 1,
797 .path =
"/validators/refresh/10",
805 .expectedRefreshMin = 10,
812 .path =
"/validators2/refresh/10",
820 .expectedRefreshMin = 10,
827 .path =
"/validators/refresh/2000",
835 .expectedRefreshMin = 60 * 24,
842 .path =
"/validators2/refresh/2000",
850 .expectedRefreshMin = 60 * 24,