Skip to content
Snippets Groups Projects
client_session_test.cc 1.91 KiB
Newer Older
  • Learn to ignore specific revisions
  • #include <vereign/restapi/client.hh>
    #include <vereign/restapi/client_session.hh>
    #include <vereign/core/scope_guard.hh>
    
    #include <vereign/client_library/passport_types.gen.pb.h>
    
    #include <util/env.hh>
    #include <util/protobuf.hh>
    
    #include "catch.hpp"
    
    #include <boost/asio/io_context.hpp>
    #include <boost/asio/ssl/context.hpp>
    #include <fmt/core.h>
    
    TEST_CASE("ClientSession::Post", "[vereign/restapi/client_session][.integration]") {
      namespace asio = boost::asio;
      namespace beast = boost::beast;
      asio::io_context ioc;
      auto work_guard = boost::asio::make_work_guard(ioc);
      asio::ssl::context ctx(asio::ssl::context::tlsv12_client);
    
      auto publicKey = vereign::test::RequireEnv("TEST_VEREIGN_PUB_KEY");
      auto host = vereign::test::RequireEnv("TEST_VEREIGN_API_HOST");
      auto port = vereign::test::GetEnv("TEST_VEREIGN_API_PORT", "https");
    
      // Verify the remote server's certificate
      // ctx.set_verify_mode(ssl::verify_peer);
    
      vereign::restapi::Client client{ioc, ctx, host, port};
      vereign::restapi::ClientSession client_session{client, publicKey};
    
      std::thread ioc_thread([&ioc]{
        ioc.run();
      });
      auto on_exit = vereign::core::MakeScopeGuard(
        [&client, &ioc_thread, &work_guard] {
          client.Close();
          work_guard.reset();
          ioc_thread.join();
        }
      );
    
      for (int i = 0; i < 1; i++) {
        auto list_result = client_session.Post(
          "/passport/listPassports",
    
          std::make_unique<vereign::client_library::ListPassportsForm>(),
          std::make_unique<vereign::client_library::ListPassportsFormResponse>()
    
        );
    
        auto result = list_result.get();
    
        // std::cout << vereign::test::ProtobufToJson(*result.Response) << std::endl;
    
        auto& list = result.Response;
        REQUIRE(list->error() == "");
        CHECK(list->status() == "OK");
        CHECK(list->code() == "200");
        CHECK(list->data().size() > 0);
        for (auto& passport : list->data()) {
          CHECK(passport.uuid().size() == 36);
        }
      }
    }