010-upnp-support.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. // SPDX-FileCopyrightText: 2019-2023 Ivan Baidakou
  3. #include "test-utils.h"
  4. #include "proto/upnp_support.h"
  5. #include <boost/filesystem.hpp>
  6. #include <iostream>
  7. namespace sys = boost::system;
  8. namespace bfs = boost::filesystem;
  9. using namespace syncspirit::proto;
  10. using namespace syncspirit::test;
  11. TEST_CASE("parse IGD description", "[support]") {
  12. auto xml = read_file(locate_path("data/49652gatedesc.xml"));
  13. auto wan_service = parse_igd(xml.c_str(), xml.size());
  14. REQUIRE(wan_service);
  15. REQUIRE(wan_service.value().control_path == "/upnp/control/WANIPConn1");
  16. REQUIRE(wan_service.value().description_path == "/gateconnSCPD.xml");
  17. }
  18. TEST_CASE("parse external IP", "[support]") {
  19. auto xml = read_file(locate_path("data/external-ip.xml"));
  20. auto ip = parse_external_ip(xml.c_str(), xml.size());
  21. REQUIRE(ip);
  22. REQUIRE(ip.value() == "81.31.113.9");
  23. }
  24. TEST_CASE("parse successful port mapping", "[support]") {
  25. auto xml = read_file(locate_path("data/port-mapping-success.xml"));
  26. auto r = parse_mapping(xml.c_str(), xml.size());
  27. REQUIRE(r);
  28. REQUIRE(r.value() == true);
  29. }
  30. TEST_CASE("parse failed port mapping", "[support]") {
  31. auto xml = read_file(locate_path("data/soap-failure.xml"));
  32. auto r = parse_mapping(xml.c_str(), xml.size());
  33. REQUIRE(r);
  34. REQUIRE(r.value() == false);
  35. }
  36. TEST_CASE("parse failed port unmapping", "[support]") {
  37. auto xml = read_file(locate_path("data/port-unmapping-failure.xml"));
  38. auto r = parse_unmapping(xml.c_str(), xml.size());
  39. REQUIRE(r);
  40. REQUIRE(r.value() == false);
  41. }