Skip to content

Commit

Permalink
API client constructor needs URL
Browse files Browse the repository at this point in the history
  • Loading branch information
gkostin1966 committed Nov 9, 2023
1 parent 1b3d301 commit 4b5d541
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion apache/client/include/lauth/api_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace mlibrary::lauth {
class ApiClient {
public:
ApiClient() : client(std::make_unique<HttpClient>("http://localhost:9000")) {};
ApiClient(const std::string& url) : client(std::make_unique<HttpClient>(url)) {};
ApiClient(std::unique_ptr<HttpClient>&& client) : client(std::move(client)) {};
ApiClient(const ApiClient&) = delete;
ApiClient& operator=(const ApiClient&) = delete;
Expand Down
2 changes: 1 addition & 1 deletion apache/client/include/lauth/authorizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace mlibrary::lauth {
class Authorizer {
public:
Authorizer() : client(std::make_unique<ApiClient>()) {};
Authorizer(const std::string& url) : client(std::make_unique<ApiClient>(url)) {};
Authorizer(std::unique_ptr<ApiClient>&& client) : client(std::move(client)) {};
Authorizer(const Authorizer&) = delete;
Authorizer& operator=(const Authorizer&) = delete;
Expand Down
2 changes: 1 addition & 1 deletion apache/client/src/lauth/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace mlibrary::lauth {

auto res = client.Get(path);

return res->body;
return res ? res->body : "";
}
}

6 changes: 3 additions & 3 deletions apache/client/test/lauth/api_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ TEST(ApiClient, denied_by_mock_http_client) {
}

TEST(ApiClient, a_request_with_no_user_is_denied) {
ApiClient client;
ApiClient client("http://localhost:9000");
Request request;

bool result = client.isAllowed(request);
Expand All @@ -48,7 +48,7 @@ TEST(ApiClient, a_request_with_no_user_is_denied) {


TEST(ApiClient, a_request_with_authorized_user_is_allowed) {
ApiClient client;
ApiClient client("http://localhost:9000");
Request request;

request.user = "authorized";
Expand All @@ -57,7 +57,7 @@ TEST(ApiClient, a_request_with_authorized_user_is_allowed) {
}

TEST(ApiClient, a_request_with_unauthorized_user_is_denied) {
ApiClient client;
ApiClient client("http://localhost:9000");
Request request;

request.user = "unauthorized";
Expand Down
1 change: 1 addition & 0 deletions apache/client/test/lauth/mocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ using namespace mlibrary::lauth;

class MockApiClient : public ApiClient {
public:
MockApiClient() : ApiClient("http://localhost:9000") {};
MOCK_METHOD(bool, isAllowed, (Request), (override));
};

Expand Down
6 changes: 1 addition & 5 deletions apache/module/mod_lauth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,13 @@ static authz_status lauth_check_authorization(request_rec *r,
return AUTHZ_DENIED_NO_USER;
}

if (Authorizer().isPasswordOnly(r->uri) && !r->user) {
return AUTHZ_DENIED_NO_USER;
}

Request req {
.ip = r->useragent_ip ? std::string(r->useragent_ip) : "",
.uri = r->uri ? std::string(r->uri) : "",
.user = r->user ? std::string(r->user) : ""
};

return Authorizer().isAllowed(req) ? AUTHZ_GRANTED : AUTHZ_DENIED;
return Authorizer("http://api-mock:9000").isAllowed(req) ? AUTHZ_GRANTED : AUTHZ_DENIED;
}

static const authz_provider authz_lauth_provider =
Expand Down

0 comments on commit 4b5d541

Please sign in to comment.