github-actions[bot] commented on code in PR #17753:
URL: https://github.com/apache/doris/pull/17753#discussion_r1133905616


##########
be/test/http/http_auth_test.cpp:
##########
@@ -0,0 +1,88 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gtest/gtest.h>
+
+#include "common/config.h"
+#include "http/ev_http_server.h"
+#include "http/http_channel.h"
+#include "http/http_handler.h"
+#include "http/http_handler_with_auth.h"
+#include "http/http_request.h"
+
+namespace doris {
+
+class HttpAuthTestHandler : public HttpHandlerWithAuth {
+public:
+    HttpAuthTestHandler(ExecEnv* exec_env) : HttpHandlerWithAuth(exec_env) {}
+
+    virtual ~HttpAuthTestHandler() {}
+
+    void handle(HttpRequest* req) override {}
+
+private:
+    bool on_privilege(const HttpRequest& req, TCheckAuthRequest& auth_request) 
override {
+        return !req.param("table").empty();
+    };
+};
+
+static ExecEnv env;
+static HttpAuthTestHandler s_auth_handler = HttpAuthTestHandler(&env);
+
+class HttpAuthTest : public testing::Test {};
+
+TEST_F(HttpAuthTest, disable_auth) {
+    EXPECT_FALSE(config::enable_auth);
+
+    auto evhttp_req = evhttp_request_new(nullptr, nullptr);
+    HttpRequest req(evhttp_req);
+    EXPECT_EQ(s_auth_handler.on_header(&req), 0);
+    evhttp_request_free(evhttp_req);
+}
+
+TEST_F(HttpAuthTest, enable_auth) {
+    config::enable_auth = true;
+
+    // 1. empty auth info
+    {
+        auto evhttp_req = evhttp_request_new(nullptr, nullptr);
+        HttpRequest req1(evhttp_req);
+        EXPECT_EQ(s_auth_handler.on_header(&req1), -1);
+    }
+
+    // 2. empty param
+    {
+        auto evhttp_req = evhttp_request_new(nullptr, nullptr);
+        HttpRequest req2(evhttp_req);
+        auto auth = encode_basic_auth("doris", "passwd");
+        req2._headers.emplace(HttpHeaders::AUTHORIZATION, auth);
+        EXPECT_EQ(s_auth_handler.on_header(&req2), -1);
+    }
+
+    // 3. OK
+    {
+        auto evhttp_req = evhttp_request_new(nullptr, nullptr);
+        HttpRequest req3(evhttp_req);
+        auto auth = encode_basic_auth("doris", "passwd");

Review Comment:
   warning: use of undeclared identifier 'encode_basic_auth' 
[clang-diagnostic-error]
   ```cpp
           auto auth = encode_basic_auth("doris", "passwd");
                       ^
   ```
   



##########
be/test/http/http_auth_test.cpp:
##########
@@ -0,0 +1,88 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gtest/gtest.h>
+
+#include "common/config.h"
+#include "http/ev_http_server.h"
+#include "http/http_channel.h"
+#include "http/http_handler.h"
+#include "http/http_handler_with_auth.h"
+#include "http/http_request.h"
+
+namespace doris {
+
+class HttpAuthTestHandler : public HttpHandlerWithAuth {
+public:
+    HttpAuthTestHandler(ExecEnv* exec_env) : HttpHandlerWithAuth(exec_env) {}
+
+    virtual ~HttpAuthTestHandler() {}
+
+    void handle(HttpRequest* req) override {}
+
+private:
+    bool on_privilege(const HttpRequest& req, TCheckAuthRequest& auth_request) 
override {
+        return !req.param("table").empty();
+    };
+};
+
+static ExecEnv env;
+static HttpAuthTestHandler s_auth_handler = HttpAuthTestHandler(&env);
+
+class HttpAuthTest : public testing::Test {};
+
+TEST_F(HttpAuthTest, disable_auth) {
+    EXPECT_FALSE(config::enable_auth);
+
+    auto evhttp_req = evhttp_request_new(nullptr, nullptr);
+    HttpRequest req(evhttp_req);
+    EXPECT_EQ(s_auth_handler.on_header(&req), 0);
+    evhttp_request_free(evhttp_req);
+}
+
+TEST_F(HttpAuthTest, enable_auth) {
+    config::enable_auth = true;
+
+    // 1. empty auth info
+    {
+        auto evhttp_req = evhttp_request_new(nullptr, nullptr);
+        HttpRequest req1(evhttp_req);
+        EXPECT_EQ(s_auth_handler.on_header(&req1), -1);
+    }
+
+    // 2. empty param
+    {
+        auto evhttp_req = evhttp_request_new(nullptr, nullptr);
+        HttpRequest req2(evhttp_req);
+        auto auth = encode_basic_auth("doris", "passwd");

Review Comment:
   warning: use of undeclared identifier 'encode_basic_auth' 
[clang-diagnostic-error]
   ```cpp
           auto auth = encode_basic_auth("doris", "passwd");
                       ^
   ```
   



##########
be/test/http/http_auth_test.cpp:
##########
@@ -0,0 +1,88 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gtest/gtest.h>
+
+#include "common/config.h"
+#include "http/ev_http_server.h"
+#include "http/http_channel.h"
+#include "http/http_handler.h"
+#include "http/http_handler_with_auth.h"
+#include "http/http_request.h"
+
+namespace doris {
+
+class HttpAuthTestHandler : public HttpHandlerWithAuth {
+public:
+    HttpAuthTestHandler(ExecEnv* exec_env) : HttpHandlerWithAuth(exec_env) {}
+
+    virtual ~HttpAuthTestHandler() {}
+
+    void handle(HttpRequest* req) override {}
+
+private:
+    bool on_privilege(const HttpRequest& req, TCheckAuthRequest& auth_request) 
override {
+        return !req.param("table").empty();
+    };
+};
+
+static ExecEnv env;
+static HttpAuthTestHandler s_auth_handler = HttpAuthTestHandler(&env);
+
+class HttpAuthTest : public testing::Test {};
+
+TEST_F(HttpAuthTest, disable_auth) {
+    EXPECT_FALSE(config::enable_auth);
+
+    auto evhttp_req = evhttp_request_new(nullptr, nullptr);
+    HttpRequest req(evhttp_req);
+    EXPECT_EQ(s_auth_handler.on_header(&req), 0);
+    evhttp_request_free(evhttp_req);
+}
+
+TEST_F(HttpAuthTest, enable_auth) {
+    config::enable_auth = true;
+
+    // 1. empty auth info
+    {
+        auto evhttp_req = evhttp_request_new(nullptr, nullptr);
+        HttpRequest req1(evhttp_req);
+        EXPECT_EQ(s_auth_handler.on_header(&req1), -1);
+    }
+
+    // 2. empty param
+    {
+        auto evhttp_req = evhttp_request_new(nullptr, nullptr);
+        HttpRequest req2(evhttp_req);
+        auto auth = encode_basic_auth("doris", "passwd");
+        req2._headers.emplace(HttpHeaders::AUTHORIZATION, auth);
+        EXPECT_EQ(s_auth_handler.on_header(&req2), -1);
+    }
+
+    // 3. OK
+    {
+        auto evhttp_req = evhttp_request_new(nullptr, nullptr);
+        HttpRequest req3(evhttp_req);
+        auto auth = encode_basic_auth("doris", "passwd");
+        req3._headers.emplace(HttpHeaders::AUTHORIZATION, auth);

Review Comment:
   warning: '_headers' is a private member of 'doris::HttpRequest' 
[clang-diagnostic-error]
   ```cpp
           req3._headers.emplace(HttpHeaders::AUTHORIZATION, auth);
                ^
   ```
   **be/src/http/http_request.h:90:** declared private here
   ```cpp
       StringCaseUnorderedMap<std::string> _headers;
                                           ^
   ```
   



##########
be/test/olap/tablet_test.cpp:
##########
@@ -272,7 +270,7 @@ TEST_F(TestTablet, pad_rowset) {
     ASSERT_FALSE(_tablet->capture_rs_readers(version, &readers).ok());
     readers.clear();
 
-    PadRowsetAction action;
+    PadRowsetAction action(nullptr);
     action._pad_rowset(_tablet, version);

Review Comment:
   warning: '_pad_rowset' is a private member of 'doris::PadRowsetAction' 
[clang-diagnostic-error]
   ```cpp
       action._pad_rowset(_tablet, version);
              ^
   ```
   **be/src/http/action/pad_rowset_action.h:49:** declared private here
   ```cpp
       Status _pad_rowset(TabletSharedPtr tablet, const Version& version);
              ^
   ```
   



##########
be/test/http/http_auth_test.cpp:
##########
@@ -0,0 +1,88 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gtest/gtest.h>
+
+#include "common/config.h"
+#include "http/ev_http_server.h"
+#include "http/http_channel.h"
+#include "http/http_handler.h"
+#include "http/http_handler_with_auth.h"
+#include "http/http_request.h"
+
+namespace doris {
+
+class HttpAuthTestHandler : public HttpHandlerWithAuth {
+public:
+    HttpAuthTestHandler(ExecEnv* exec_env) : HttpHandlerWithAuth(exec_env) {}
+
+    virtual ~HttpAuthTestHandler() {}
+
+    void handle(HttpRequest* req) override {}
+
+private:
+    bool on_privilege(const HttpRequest& req, TCheckAuthRequest& auth_request) 
override {
+        return !req.param("table").empty();
+    };
+};
+
+static ExecEnv env;
+static HttpAuthTestHandler s_auth_handler = HttpAuthTestHandler(&env);
+
+class HttpAuthTest : public testing::Test {};
+
+TEST_F(HttpAuthTest, disable_auth) {
+    EXPECT_FALSE(config::enable_auth);
+
+    auto evhttp_req = evhttp_request_new(nullptr, nullptr);
+    HttpRequest req(evhttp_req);
+    EXPECT_EQ(s_auth_handler.on_header(&req), 0);
+    evhttp_request_free(evhttp_req);
+}
+
+TEST_F(HttpAuthTest, enable_auth) {
+    config::enable_auth = true;
+
+    // 1. empty auth info
+    {
+        auto evhttp_req = evhttp_request_new(nullptr, nullptr);
+        HttpRequest req1(evhttp_req);
+        EXPECT_EQ(s_auth_handler.on_header(&req1), -1);
+    }
+
+    // 2. empty param
+    {
+        auto evhttp_req = evhttp_request_new(nullptr, nullptr);
+        HttpRequest req2(evhttp_req);
+        auto auth = encode_basic_auth("doris", "passwd");
+        req2._headers.emplace(HttpHeaders::AUTHORIZATION, auth);

Review Comment:
   warning: '_headers' is a private member of 'doris::HttpRequest' 
[clang-diagnostic-error]
   ```cpp
           req2._headers.emplace(HttpHeaders::AUTHORIZATION, auth);
                ^
   ```
   **be/src/http/http_request.h:90:** declared private here
   ```cpp
       StringCaseUnorderedMap<std::string> _headers;
                                           ^
   ```
   



##########
be/test/http/http_auth_test.cpp:
##########
@@ -0,0 +1,88 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gtest/gtest.h>
+
+#include "common/config.h"
+#include "http/ev_http_server.h"
+#include "http/http_channel.h"
+#include "http/http_handler.h"
+#include "http/http_handler_with_auth.h"
+#include "http/http_request.h"
+
+namespace doris {
+
+class HttpAuthTestHandler : public HttpHandlerWithAuth {
+public:
+    HttpAuthTestHandler(ExecEnv* exec_env) : HttpHandlerWithAuth(exec_env) {}
+
+    virtual ~HttpAuthTestHandler() {}
+
+    void handle(HttpRequest* req) override {}
+
+private:
+    bool on_privilege(const HttpRequest& req, TCheckAuthRequest& auth_request) 
override {
+        return !req.param("table").empty();
+    };
+};
+
+static ExecEnv env;
+static HttpAuthTestHandler s_auth_handler = HttpAuthTestHandler(&env);
+
+class HttpAuthTest : public testing::Test {};
+
+TEST_F(HttpAuthTest, disable_auth) {
+    EXPECT_FALSE(config::enable_auth);
+
+    auto evhttp_req = evhttp_request_new(nullptr, nullptr);
+    HttpRequest req(evhttp_req);
+    EXPECT_EQ(s_auth_handler.on_header(&req), 0);
+    evhttp_request_free(evhttp_req);
+}
+
+TEST_F(HttpAuthTest, enable_auth) {
+    config::enable_auth = true;
+
+    // 1. empty auth info
+    {
+        auto evhttp_req = evhttp_request_new(nullptr, nullptr);
+        HttpRequest req1(evhttp_req);
+        EXPECT_EQ(s_auth_handler.on_header(&req1), -1);
+    }
+
+    // 2. empty param
+    {
+        auto evhttp_req = evhttp_request_new(nullptr, nullptr);
+        HttpRequest req2(evhttp_req);
+        auto auth = encode_basic_auth("doris", "passwd");
+        req2._headers.emplace(HttpHeaders::AUTHORIZATION, auth);
+        EXPECT_EQ(s_auth_handler.on_header(&req2), -1);
+    }
+
+    // 3. OK
+    {
+        auto evhttp_req = evhttp_request_new(nullptr, nullptr);
+        HttpRequest req3(evhttp_req);
+        auto auth = encode_basic_auth("doris", "passwd");
+        req3._headers.emplace(HttpHeaders::AUTHORIZATION, auth);
+        req3._params.emplace("table", "T");

Review Comment:
   warning: '_params' is a private member of 'doris::HttpRequest' 
[clang-diagnostic-error]
   ```cpp
           req3._params.emplace("table", "T");
                ^
   ```
   **be/src/http/http_request.h:91:** declared private here
   ```cpp
       std::map<std::string, std::string> _params;
                                          ^
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to