Skip to content

Commit

Permalink
remove isPasswordOnly method from apache client
Browse files Browse the repository at this point in the history
  • Loading branch information
gkostin1966 committed Nov 9, 2023
1 parent 57fdc39 commit 2b5e9a8
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 46 deletions.
1 change: 0 additions & 1 deletion apache/client/include/lauth/authorizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 0 additions & 4 deletions apache/client/include/lauth/http_client.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef __LAUTH_HTTP_CLIENT_HPP__
#define __LAUTH_HTTP_CLIENT_HPP__

#include "lauth/request.hpp"

#include <string>

namespace mlibrary::lauth {
Expand All @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion apache/client/src/lauth/api_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
4 changes: 0 additions & 4 deletions apache/client/src/lauth/authorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
#include <string>

namespace mlibrary::lauth {
bool Authorizer::isPasswordOnly(std::string url) {
return false;
}

bool Authorizer::isAllowed(Request req) {
return client->isAllowed(req);
}
Expand Down
4 changes: 0 additions & 4 deletions apache/client/src/lauth/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
#include <httplib.h>

namespace mlibrary::lauth {
bool HttpClient::isAllowed(Request req) {
return req.user == "authorized";
}

std::string HttpClient::get(const std::string& path) {
httplib::Client client(baseUrl);

Expand Down
26 changes: 0 additions & 26 deletions apache/client/test/lauth/api_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ using namespace mlibrary::lauth;
TEST(ApiClient, allowed_by_mock_http_client) {
auto client = std::make_unique<MockHttpClient>();
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 {
Expand All @@ -28,7 +27,6 @@ TEST(ApiClient, allowed_by_mock_http_client) {
TEST(ApiClient, denied_by_mock_http_client) {
auto client = std::make_unique<MockHttpClient>();
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 {
Expand All @@ -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<MockHttpClient>();
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<MockHttpClient>();
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;
Expand Down
1 change: 0 additions & 1 deletion apache/client/test/lauth/mocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};

Expand Down
10 changes: 5 additions & 5 deletions apache/client/test/mock_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down

0 comments on commit 2b5e9a8

Please sign in to comment.