Browse Source

now correctly handles invalid torrents

master
Jørgen Lien Sellæg 9 years ago
parent
commit
ada05fe896
  1. 7
      toREST/include/torrent.hpp
  2. 17
      toREST/tests/torrent_test.cpp

7
toREST/include/torrent.hpp

@ -67,6 +67,13 @@ void patch(torrent_session &session, response resp, request req) {
if (!session.is_valid()) {
return respond(http::service_unavailable);
}
const auto hash = req->path.substr(18, req->path.size() - 18); //TODO hacky
const auto torrent = session.find_torrent(util::sha1::info_hash(hash));
if (!torrent.is_valid()) {
return respond(http::bad_request);
}
}
}
}

17
toREST/tests/torrent_test.cpp

@ -48,4 +48,21 @@ SCENARIO("We are running a PATCH /session/torrents/id resource") {
CommonResponse::service_unavailable(response);
}
}
auto torrent = TestTorrent();
torrent_session.valid = true;
GIVEN("we have the server is working properly and we recive a request") {
WHEN("the request path is a proper id") {
request->path = "/session/torrents/" + torrent_id;
GIVEN("we have the torrent") {
torrent_session.theTorrentExists();
WHEN("The torrent isn't valid") {
torrent_session.torrents_.back().valid = false;
THEN("the server should reply with bad request") {
tr::session::torrents::id::patch(torrent_session, response, request);
CommonResponse::bad_request(response);
}
}
}
}
}
}

Loading…
Cancel
Save