Skip to content

Commit 99bb544

Browse files
committed
Revert "add back whitelisting and unit tests for it (#2545)"
This reverts commit 0cedbb9.
1 parent f20abd6 commit 99bb544

File tree

4 files changed

+26
-70
lines changed

4 files changed

+26
-70
lines changed

proto/options.proto

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ message Options {
137137
enum Action {
138138
route = 1;
139139
locate = 2;
140-
sources_to_targets = 3;
141-
optimized_route = 4;
142-
isochrone = 5;
143-
trace_route = 6;
144-
trace_attributes = 7;
145-
height = 8;
146-
transit_available = 9;
147-
expansion = 10;
140+
sources_to_targets = 6;
141+
optimized_route = 7;
142+
isochrone = 8;
143+
trace_route = 9;
144+
trace_attributes = 10;
145+
height = 11;
146+
transit_available = 12;
147+
expansion = 13;
148148
}
149149

150150
enum DateTimeType {

src/loki/worker.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ loki_worker_t::loki_worker_t(const boost::property_tree::ptree& config,
163163
if (!Options_Action_Enum_Parse(path, &action)) {
164164
throw std::runtime_error("Action not supported " + path);
165165
}
166-
actions.insert(action);
167166
action_str.append("'/" + path + "' ");
168167
}
169168
// Make sure we have at least something to support!
@@ -265,7 +264,7 @@ loki_worker_t::work(const std::list<zmq::message_t>& job,
265264
const auto& options = request.options();
266265

267266
// check there is a valid action
268-
if (!options.has_action() || actions.find(options.action()) == actions.cend()) {
267+
if (!options.has_action()) {
269268
return jsonify_error({106, action_str}, info, request);
270269
}
271270

test/loki_service.cc

Lines changed: 17 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
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

valhalla/loki/worker.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class loki_worker_t : public service_worker_t {
6767
sif::cost_ptr_t costing;
6868
std::shared_ptr<baldr::GraphReader> reader;
6969
std::shared_ptr<baldr::connectivity_map_t> connectivity_map;
70-
std::unordered_set<Options::Action> actions;
7170
std::string action_str;
7271
std::unordered_map<std::string, size_t> max_locations;
7372
std::unordered_map<std::string, float> max_distance;

0 commit comments

Comments
 (0)