From bf07fb80d6cf609fe4804297466e15663242853d Mon Sep 17 00:00:00 2001 From: Anthony Thomas Date: Tue, 14 Nov 2023 16:26:39 -0500 Subject: [PATCH] Add AuthorizationResult type --- apache/client/include/lauth/api_client.hpp | 2 ++ apache/client/include/lauth/authorization_result.hpp | 12 ++++++++++++ apache/client/meson.build | 1 + apache/client/src/lauth/api_client.cpp | 12 ++++++++++++ apache/client/test/lauth/api_client_test.cpp | 5 +++-- 5 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 apache/client/include/lauth/authorization_result.hpp diff --git a/apache/client/include/lauth/api_client.hpp b/apache/client/include/lauth/api_client.hpp index bc8a1752..fd82f302 100644 --- a/apache/client/include/lauth/api_client.hpp +++ b/apache/client/include/lauth/api_client.hpp @@ -5,6 +5,7 @@ #include "lauth/http_client.hpp" #include "lauth/request.hpp" +#include "lauth/authorization_result.hpp" namespace mlibrary::lauth { class ApiClient { @@ -18,6 +19,7 @@ namespace mlibrary::lauth { virtual ~ApiClient() = default; virtual bool authorized(Request req); + virtual AuthorizationResult authorize(Request req); protected: std::unique_ptr client; diff --git a/apache/client/include/lauth/authorization_result.hpp b/apache/client/include/lauth/authorization_result.hpp new file mode 100644 index 00000000..a44e1dad --- /dev/null +++ b/apache/client/include/lauth/authorization_result.hpp @@ -0,0 +1,12 @@ +#ifndef __LAUTH_AUTHORIZATION_RESULT_HPP__ +#define __LAUTH_AUTHORIZATION_RESULT_HPP__ + +#include + +namespace mlibrary::lauth { + struct AuthorizationResult { + std::string determination; + }; +} + +#endif // __LAUTH_AUTHORIZATION_RESULT_HPP__ diff --git a/apache/client/meson.build b/apache/client/meson.build index 1f5122ba..58679901 100644 --- a/apache/client/meson.build +++ b/apache/client/meson.build @@ -42,6 +42,7 @@ liblauth = shared_library( install_headers( 'include/lauth/api_client.hpp', + 'include/lauth/authorization_result.hpp', 'include/lauth/authorizer.hpp', 'include/lauth/http_client.hpp', 'include/lauth/http_params.hpp', diff --git a/apache/client/src/lauth/api_client.cpp b/apache/client/src/lauth/api_client.cpp index 8459f8f5..3e9f15a5 100644 --- a/apache/client/src/lauth/api_client.cpp +++ b/apache/client/src/lauth/api_client.cpp @@ -18,4 +18,16 @@ namespace mlibrary::lauth { return rvalue["result"] == "allowed"; } + + AuthorizationResult ApiClient::authorize(Request req) { + HttpParams params { + {"uri", req.uri}, + {"user", req.user} + }; + + auto result = client->get("/authorized", params); + json rvalue = json::parse(*result); + + return AuthorizationResult{.determination = "denied"}; + } } diff --git a/apache/client/test/lauth/api_client_test.cpp b/apache/client/test/lauth/api_client_test.cpp index 95e9f658..795bcc39 100644 --- a/apache/client/test/lauth/api_client_test.cpp +++ b/apache/client/test/lauth/api_client_test.cpp @@ -9,6 +9,7 @@ using ::testing::Return; #include "lauth/api_client.hpp" #include "lauth/request.hpp" +#include "lauth/authorization_result.hpp" using namespace mlibrary::lauth; @@ -54,6 +55,6 @@ TEST(ApiClient, ResponseOfDeniedReturnsFalse) { EXPECT_CALL(*client, get(_, _)).WillOnce(Return(body)); ApiClient api_client(std::move(client)); - auto allowed = api_client.authorized(Request()); - EXPECT_THAT(allowed, false); + auto authorized = api_client.authorize(Request()); + EXPECT_THAT(authorized.determination, "denied"); }