33
44#include " baldr/rapidjson_utils.h"
55#include " midgard/logging.h"
6- #include " proto/api.pb.h"
7- #include " proto_conversions.h"
8-
96#include < boost/property_tree/ptree.hpp>
107#include < prime_server/http_protocol.hpp>
118#include < prime_server/prime_server.hpp>
@@ -330,17 +327,27 @@ const std::vector<std::pair<uint16_t, std::string>> osrm_responses{
330327 {400 ,
331328 R"( {"code":"InvalidValue","message":"The successfully parsed query parameters are invalid."})" }};
332329
333- boost::property_tree::ptree make_config (
334- const std::string& actions =
335- R"( [ "locate", "route", "sources_to_targets", "optimized_route", "isochrone", "trace_route", "trace_attributes" ])" ) {
330+ zmq::context_t context;
331+ void start_service () {
332+ // server
333+ std::thread server (
334+ std::bind (&http_server_t ::serve,
335+ http_server_t (context, " ipc:///tmp/test_loki_server" , " ipc:///tmp/test_loki_proxy_in" ,
336+ " ipc:///tmp/test_loki_results" , " ipc:///tmp/test_loki_interrupt" )));
337+ server.detach ();
338+
339+ // load balancer
340+ std::thread proxy (std::bind (&proxy_t ::forward, proxy_t (context, " ipc:///tmp/test_loki_proxy_in" ,
341+ " ipc:///tmp/test_loki_proxy_out" )));
342+ proxy.detach ();
343+
344+ // make the config file
336345 boost::property_tree::ptree config;
337346 std::stringstream json;
338347 json << R"( {
339348 "meili": { "default": { "breakage_distance": 2000} },
340349 "mjolnir": { "tile_dir": "test/tiles" },
341- "loki": { "actions": )" ;
342- json << actions;
343- json << R"( ,
350+ "loki": { "actions": [ "locate", "route", "sources_to_targets", "optimized_route", "isochrone", "trace_route", "trace_attributes" ],
344351 "logging": { "long_request": 100.0 },
345352 "service": { "proxy": "ipc:///tmp/test_loki_proxy" },
346353 "service_defaults": { "minimum_reachability": 50, "radius": 0,"search_cutoff": 35000, "node_snap_tolerance": 5, "street_side_tolerance": 5, "street_side_max_distance": 1000, "heading_tolerance": 60} },
@@ -363,25 +370,6 @@ boost::property_tree::ptree make_config(
363370 "costing_directions_options": { "auto": {}, "pedestrian": {} }
364371 })" ;
365372 rapidjson::read_json (json, config);
366- return config;
367- }
368-
369- zmq::context_t context;
370- void start_service () {
371- // server
372- std::thread server (
373- std::bind (&http_server_t ::serve,
374- http_server_t (context, " ipc:///tmp/test_loki_server" , " ipc:///tmp/test_loki_proxy_in" ,
375- " ipc:///tmp/test_loki_results" , " ipc:///tmp/test_loki_interrupt" )));
376- server.detach ();
377-
378- // load balancer
379- std::thread proxy (std::bind (&proxy_t ::forward, proxy_t (context, " ipc:///tmp/test_loki_proxy_in" ,
380- " ipc:///tmp/test_loki_proxy_out" )));
381- proxy.detach ();
382-
383- // make the config file
384- auto config = make_config ();
385373
386374 // service worker
387375 std::thread worker (valhalla::loki::run_service, config);
@@ -440,37 +428,7 @@ TEST(LokiService, test_osrm_failure_requests) {
440428 run_requests (osrm_requests, osrm_responses);
441429}
442430
443- TEST (LokiService, test_actions_whitelist) {
444- http_request_info_t info{};
445-
446- // check that you only get in if your on the configured list
447- for (auto action = Options::Action_MIN; action < Options::Action_ARRAYSIZE;
448- action = static_cast <Options::Action>(static_cast <int >(action) + 1 )) {
449-
450- auto wrong_action = static_cast <Options::Action>(static_cast <int >(action) +
451- (action == Options::Action_MAX ? -1 : 1 ));
452- auto whitelist = R"( [")" + Options_Action_Enum_Name (wrong_action) + R"( "])" ;
453- auto config = make_config (whitelist);
454- loki::loki_worker_t worker (config);
455- http_request_t request (method_t ::GET, " /" + Options_Action_Enum_Name (action));
456- auto req_str = request.to_string ();
457- auto msg = zmq::message_t {reinterpret_cast <void *>(&req_str.front ()), req_str.size (),
458- [](void *, void *) {}};
459- auto result = worker.work ({msg}, reinterpret_cast <void *>(&info), []() {});
460-
461- // failed to find that action in the whitelist
462- EXPECT_TRUE (result.messages .front ().find (" Try any" ) != std::string::npos);
463-
464- http_request_t request1 (method_t ::GET, " /" + Options_Action_Enum_Name (wrong_action));
465- req_str = request1.to_string ();
466- msg = zmq::message_t {reinterpret_cast <void *>(&req_str.front ()), req_str.size (),
467- [](void *, void *) {}};
468- result = worker.work ({msg}, reinterpret_cast <void *>(&info), []() {});
469-
470- // found the action this time but failed for no locations
471- EXPECT_TRUE (result.messages .front ().find (" Try any" ) == std::string::npos);
472- }
473- }
431+ // todo: test_success_requests??
474432
475433} // namespace
476434
0 commit comments