Unverified Commit 3f0698cd authored by Dennis Jenkins's avatar Dennis Jenkins Committed by GitHub

Merge pull request #617 from kiplingw/kip-ssl-servefile-test

Added basic_tls_request_with_servefile unit test to try and reproduce…
parents dd5e155d 0f66592e
pistache (0.0.001-git20191017-kip1) disco; urgency=medium
* Latest upstream.
-- Kip Warner <kip@thevertigo.com> Thu, 17 Oct 2019 21:57:28 -0700
pistache (0.0.001-git20190920-kip1~disco) disco; urgency=medium
* Added DEP-8 compliant test for autopkgtest.
......
#include <array>
#include <pistache/http.h>
#include <pistache/client.h>
#include <pistache/endpoint.h>
......@@ -26,6 +28,16 @@ struct HelloHandler : public Http::Handler {
}
};
struct ServeFileHandler : public Http::Handler {
HTTP_PROTOTYPE(ServeFileHandler)
void onRequest(const Http::Request&, Http::ResponseWriter writer) override {
Http::serveFile(writer, "./certs/rootCA.crt").then([](ssize_t bytes) {
std::cout << "Sent " << bytes << " bytes" << std::endl;
}, Async::NoExcept);
}
};
TEST(http_client_test, basic_tls_request) {
Http::Endpoint server(ADDRESS "1");
auto flags = Tcp::Options::ReuseAddr;
......@@ -236,3 +248,48 @@ TEST(http_client_test, basic_tls_request_with_auth_with_cb) {
server.shutdown();
}
TEST(http_client_test, basic_tls_request_with_servefile) {
Http::Endpoint server(ADDRESS "6");
auto flags = Tcp::Options::ReuseAddr;
auto server_opts = Http::Endpoint::options().flags(flags);
server.init(server_opts);
server.setHandler(Http::make_handler<ServeFileHandler>());
server.useSSL("./certs/server.crt", "./certs/server.key");
server.serveThreaded();
CURL *curl;
CURLcode res;
std::string buffer;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
ASSERT_NE(curl, nullptr);
curl_easy_setopt(curl, CURLOPT_URL, "https://" ADDRESS "6");
curl_easy_setopt(curl, CURLOPT_CAINFO, "./certs/rootCA.crt");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_cb);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
std::array<char, CURL_ERROR_SIZE> errorstring;
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorstring.data());
//curl_easy_setopt(curl, CURLOPT_VERBOSE, true);
/* Skip hostname check */
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
std::cerr << errorstring.data() << std::endl;
ASSERT_EQ(res, CURLE_OK);
ASSERT_EQ(buffer.rfind("-----BEGIN CERTIFICATE-----", 0), 0);
curl_easy_cleanup(curl);
curl_global_cleanup();
server.shutdown();
}
VERSION_MAJOR 0
VERSION_MINOR 0
VERSION_PATCH 001
VERSION_GIT_DATE 20190920
VERSION_GIT_DATE 20191017
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment