Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that SSL support is enabled in HttpClient #81

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions apache/client/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ lauth_integration_tests = files([
'test/lauth/http_client_test.cpp',
])

os = host_machine.system()
if os == 'darwin'
httplib_links = []
else
httplib_links = ['-lssl', '-lcrypto']
endif

liblauth = shared_library(
'lauth',
lauth_sources,
Expand All @@ -39,9 +46,12 @@ liblauth = shared_library(
cpp_httplib,
json,
],
link_args: httplib_links,
install: true,
)

liblauth_dep = declare_dependency(include_directories: lauth_includes, link_with: liblauth)

install_headers(
'include/lauth/api_client.hpp',
'include/lauth/authorization_result.hpp',
Expand All @@ -64,8 +74,9 @@ if get_option('tests')
cpp_httplib,
json,
gtest,
gmock
]
gmock,
],
link_args: httplib_links,
)
test('lauth-test', tests)
endif
Expand All @@ -80,18 +91,12 @@ if get_option('integration-tests')
json,
gtest,
gmock
]
)
],
link_args: httplib_links,
)
test('lauth-integration-test', integration_tests)
endif

os = host_machine.system()
if os == 'darwin'
httplib_links = []
else
httplib_links = ['-lssl', '-lcrypto']
endif

executable(
'http-service',
files(['test/mock_service.cpp']),
Expand All @@ -110,3 +115,14 @@ executable(
],
link_args: httplib_links
)

executable(
'api-check',
files(['src/api_check.cpp']),
include_directories: lauth_includes,
dependencies: [
cpp_httplib,
liblauth_dep,
],
link_args: httplib_links,
)
35 changes: 35 additions & 0 deletions apache/client/src/api_check.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <exception>
#include <iostream>
#include <map>
#include <memory>

#include <lauth/authorizer.hpp>
#include <lauth/logging.hpp>

using namespace mlibrary::lauth;

int main(int argc, char **argv) {
if (argc != 6) {
std::cout << "Usage: api-check <host> <token> <uri> <ip> <username>" << std::endl;
return -1;
}

auto host = std::string(argv[1]);
auto token = std::string(argv[2]);
auto uri = std::string(argv[3]);
auto ip = std::string(argv[4]);
auto user = std::string(argv[5]);
std::cout << "Authorizing (via " << host << ") -- uri: " << uri << ", ip: " << ip << ", user: " << user << std::endl;

Logger::set(std::make_shared<Logger>(std::make_unique<StdOut>()));
auto auth = Authorizer(host, token);
Request req = Request {
.ip = ip,
.uri = uri,
.user = user
};

auto result = auth.authorize(req);
std::cout << "Authorizer worked... determination: " << result["determination"] << std::endl;
return 0;
}
4 changes: 4 additions & 0 deletions apache/client/src/lauth/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#include <optional>

#ifndef CPPHTTPLIB_OPENSSL_SUPPORT
#define CPPHTTPLIB_OPENSSL_SUPPORT 1
#endif

#include <httplib.h>

#include "lauth/http_params.hpp"
Expand Down
9 changes: 9 additions & 0 deletions apache/client/test/lauth/http_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using testing::_;
using testing::Eq;
using testing::HasSubstr;
using testing::IsTrue;

using namespace mlibrary::lauth;
Expand Down Expand Up @@ -85,3 +86,11 @@ TEST(HttpClient, GetRequestWithAuthorizationHeaderEncodesIt) {

EXPECT_THAT(*response, Eq(R"({"Bearer":"dGVzdA=="})"));
}

TEST(HttpClient, HttpsSchemeIsSupported) {
HttpClient client("https://example.com");

auto response = client.get("/");

EXPECT_THAT(*response, HasSubstr("Example Domain"));
}