Newer
Older
#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>
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#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);
}
}
}