diff --git a/apache/client/include/lauth/authorizer.hpp b/apache/client/include/lauth/authorizer.hpp index 7b610397..174003b6 100644 --- a/apache/client/include/lauth/authorizer.hpp +++ b/apache/client/include/lauth/authorizer.hpp @@ -18,7 +18,6 @@ namespace mlibrary::lauth { Authorizer& operator=(const Authorizer&&) = delete; virtual ~Authorizer() = default; - bool isPasswordOnly(std::string url); virtual bool isAllowed(Request req); protected: diff --git a/apache/client/include/lauth/http_client.hpp b/apache/client/include/lauth/http_client.hpp index 6c0ef132..bd2476b1 100644 --- a/apache/client/include/lauth/http_client.hpp +++ b/apache/client/include/lauth/http_client.hpp @@ -1,8 +1,6 @@ #ifndef __LAUTH_HTTP_CLIENT_HPP__ #define __LAUTH_HTTP_CLIENT_HPP__ -#include "lauth/request.hpp" - #include namespace mlibrary::lauth { @@ -11,10 +9,8 @@ namespace mlibrary::lauth { HttpClient(const std::string& baseUrl) : baseUrl(baseUrl) {}; virtual ~HttpClient() = default; - virtual bool isAllowed(Request req); virtual std::string get(const std::string& path); - protected: const std::string baseUrl; }; diff --git a/apache/client/src/lauth/api_client.cpp b/apache/client/src/lauth/api_client.cpp index 9309f9bc..3bc7d0e1 100644 --- a/apache/client/src/lauth/api_client.cpp +++ b/apache/client/src/lauth/api_client.cpp @@ -8,6 +8,6 @@ namespace mlibrary::lauth { std::stringstream url; url << "/users/" << req.user << "/is_allowed"; std::string result = client->get(url.str()); - return client->isAllowed(req); + return result == "yes"; } } diff --git a/apache/client/src/lauth/authorizer.cpp b/apache/client/src/lauth/authorizer.cpp index 9c68b62f..0624fc72 100644 --- a/apache/client/src/lauth/authorizer.cpp +++ b/apache/client/src/lauth/authorizer.cpp @@ -3,10 +3,6 @@ #include namespace mlibrary::lauth { - bool Authorizer::isPasswordOnly(std::string url) { - return false; - } - bool Authorizer::isAllowed(Request req) { return client->isAllowed(req); } diff --git a/apache/client/src/lauth/http_client.cpp b/apache/client/src/lauth/http_client.cpp index a6b352a4..f3e4cd5f 100644 --- a/apache/client/src/lauth/http_client.cpp +++ b/apache/client/src/lauth/http_client.cpp @@ -3,10 +3,6 @@ #include namespace mlibrary::lauth { - bool HttpClient::isAllowed(Request req) { - return req.user == "authorized"; - } - std::string HttpClient::get(const std::string& path) { httplib::Client client(baseUrl); diff --git a/apache/client/test/lauth/api_client_test.cpp b/apache/client/test/lauth/api_client_test.cpp index f1b76c33..a2e05f39 100644 --- a/apache/client/test/lauth/api_client_test.cpp +++ b/apache/client/test/lauth/api_client_test.cpp @@ -13,7 +13,6 @@ using namespace mlibrary::lauth; TEST(ApiClient, allowed_by_mock_http_client) { auto client = std::make_unique(); EXPECT_CALL(*client, get("/users/authorized/is_allowed")).WillOnce(Return("yes")); - EXPECT_CALL(*client, isAllowed(_)).WillOnce(Return(true)); ApiClient api_client(std::move(client)); Request req { @@ -28,7 +27,6 @@ TEST(ApiClient, allowed_by_mock_http_client) { TEST(ApiClient, denied_by_mock_http_client) { auto client = std::make_unique(); EXPECT_CALL(*client, get("/users/unauthorized/is_allowed")).WillOnce(Return("no")); - EXPECT_CALL(*client, isAllowed(_)).WillOnce(Return(false)); ApiClient api_client(std::move(client)); Request req { @@ -40,30 +38,6 @@ TEST(ApiClient, denied_by_mock_http_client) { EXPECT_THAT(allowed, false); } -TEST(ApiClient, allowed_by_mock) { - auto client = std::make_unique(); - EXPECT_CALL(*client, isAllowed(_)).WillOnce(Return(true)); - ApiClient api_client(std::move(client)); - - Request req {}; - - auto allowed = api_client.isAllowed(req); - - EXPECT_THAT(allowed, true); -} - -TEST(ApiClient, denied_by_mock) { - auto client = std::make_unique(); - EXPECT_CALL(*client, isAllowed(_)).WillOnce(Return(false)); - ApiClient api_client(std::move(client)); - - Request req {}; - - auto allowed = api_client.isAllowed(req); - - EXPECT_THAT(allowed, false); -} - TEST(ApiClient, a_request_with_no_user_is_denied) { ApiClient client; Request request; diff --git a/apache/client/test/lauth/mocks.hpp b/apache/client/test/lauth/mocks.hpp index 27f6e363..712c7b8c 100644 --- a/apache/client/test/lauth/mocks.hpp +++ b/apache/client/test/lauth/mocks.hpp @@ -14,7 +14,6 @@ class MockApiClient : public ApiClient { class MockHttpClient : public HttpClient { public: MockHttpClient() : HttpClient("http://localhost:9000") {}; - MOCK_METHOD(bool, isAllowed, (Request), (override)); MOCK_METHOD(std::string, get, (const std::string&), (override)); }; diff --git a/apache/client/test/mock_service.cpp b/apache/client/test/mock_service.cpp index 94bc75b1..3b91c08a 100644 --- a/apache/client/test/mock_service.cpp +++ b/apache/client/test/mock_service.cpp @@ -14,23 +14,23 @@ int main(int argc, char **argv) { port = server.bind_to_any_port(address); } - server.Get("/", [](const Request &req, Response &res) { + server.Get("/", [](const Request &, Response &res) { res.set_content("Root", "text/plain"); }); - server.Get("/ping", [](const Request &req, Response &res) { + server.Get("/ping", [](const Request &, Response &res) { res.set_content("pong", "text/plain"); }); - server.Get("/users/authorized/is_allowed", [](const Request &req, Response &res) { + server.Get("/users/authorized/is_allowed", [](const Request &, Response &res) { res.set_content("yes", "text/plain"); }); - server.Get("/users/unauthorized/is_allowed", [](const Request &req, Response &res) { + server.Get("/users/unauthorized/is_allowed", [](const Request &, Response &res) { res.set_content("no", "text/plain"); }); - server.Get("/stop", [&](const Request &req, Response &res) { + server.Get("/stop", [&](const Request &, Response &res) { res.set_content("Shutting down server...", "text/plain"); server.stop(); });