Skip to content

Commit

Permalink
Add AuthorizationResult type
Browse files Browse the repository at this point in the history
  • Loading branch information
antmoth committed Nov 14, 2023
1 parent 63408dc commit bf07fb8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions apache/client/include/lauth/api_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "lauth/http_client.hpp"
#include "lauth/request.hpp"
#include "lauth/authorization_result.hpp"

namespace mlibrary::lauth {
class ApiClient {
Expand All @@ -18,6 +19,7 @@ namespace mlibrary::lauth {
virtual ~ApiClient() = default;

virtual bool authorized(Request req);
virtual AuthorizationResult authorize(Request req);

protected:
std::unique_ptr<HttpClient> client;
Expand Down
12 changes: 12 additions & 0 deletions apache/client/include/lauth/authorization_result.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef __LAUTH_AUTHORIZATION_RESULT_HPP__
#define __LAUTH_AUTHORIZATION_RESULT_HPP__

#include <string>

namespace mlibrary::lauth {
struct AuthorizationResult {
std::string determination;
};
}

#endif // __LAUTH_AUTHORIZATION_RESULT_HPP__
1 change: 1 addition & 0 deletions apache/client/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
12 changes: 12 additions & 0 deletions apache/client/src/lauth/api_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
}
}
5 changes: 3 additions & 2 deletions apache/client/test/lauth/api_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
}

0 comments on commit bf07fb8

Please sign in to comment.