diff --git a/interfaces/inner_api/common/include/config/white_list_checker.h b/interfaces/inner_api/common/include/config/white_list_checker.h index cf46908..d0c9bdc 100644 --- a/interfaces/inner_api/common/include/config/white_list_checker.h +++ b/interfaces/inner_api/common/include/config/white_list_checker.h @@ -1,28 +1,29 @@ /* -* Copyright (C) 2023 Huawei Device Co., Ltd. -* Licensed 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. -*/ + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed 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. + */ #ifndef APP_DOMAIN_VERIFY_WHITE_LIST_CHECKER_H #define APP_DOMAIN_VERIFY_WHITE_LIST_CHECKER_H #include #include "white_list_config_mgr.h" -namespace OHOS::AppDomainVerify{ +namespace OHOS::AppDomainVerify { -class WhiteListChecker : public WhiteListConfigMgr{ +class WhiteListChecker : public WhiteListConfigMgr { public: WhiteListChecker(); ~WhiteListChecker() override = default; bool IsInWhiteList(const std::string& url); + private: std::shared_ptr observer_; }; diff --git a/interfaces/inner_api/common/src/config/white_list_updater.cpp b/interfaces/inner_api/common/src/config/white_list_updater.cpp index 81a54aa..161b0ea 100644 --- a/interfaces/inner_api/common/src/config/white_list_updater.cpp +++ b/interfaces/inner_api/common/src/config/white_list_updater.cpp @@ -26,8 +26,8 @@ void WhiteListUpdater::UpdateWhiteList(std::unordered_set& whiteLis Load(); } std::unordered_set filtedWhiteList; - std::for_each(whiteList.begin(), whiteList.end(), [&filtedWhiteList](const std::string& element){ - if(UrlUtil::IsValidUrl(element)){ + std::for_each(whiteList.begin(), whiteList.end(), [&filtedWhiteList](const std::string& element) { + if (UrlUtil::IsValidUrl(element)) { filtedWhiteList.insert(element); } }); diff --git a/interfaces/inner_api/common/src/httpsession/app_domain_verify_task_mgr.cpp b/interfaces/inner_api/common/src/httpsession/app_domain_verify_task_mgr.cpp index eb09218..3f5e0f2 100644 --- a/interfaces/inner_api/common/src/httpsession/app_domain_verify_task_mgr.cpp +++ b/interfaces/inner_api/common/src/httpsession/app_domain_verify_task_mgr.cpp @@ -26,7 +26,7 @@ std::shared_ptr AppDomainVerifyTaskMgr::instance_ = null std::mutex AppDomainVerifyTaskMgr::mutex_; using namespace OHOS::NetStack::HttpClient; - +constexpr int MAX_CONCURRENCY = 10; std::shared_ptr AppDomainVerifyTaskMgr::GetInstance() { if (instance_ == nullptr) { @@ -62,7 +62,7 @@ bool AppDomainVerifyTaskMgr::Init() { APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MODULE_COMMON, "Init."); ffrt::queue_attr queueAttr{}; - queueAttr.max_concurrency(10); + queueAttr.max_concurrency(MAX_CONCURRENCY); queueAttr.qos(ffrt_qos_default); ffrtTaskQueue_ = std::make_shared("ffrt-queue", queueAttr); return false; diff --git a/interfaces/inner_api/verifier/include/i_verify_task.h b/interfaces/inner_api/verifier/include/i_verify_task.h index eb2fed3..ff8ccdd 100644 --- a/interfaces/inner_api/verifier/include/i_verify_task.h +++ b/interfaces/inner_api/verifier/include/i_verify_task.h @@ -22,15 +22,15 @@ namespace OHOS { namespace AppDomainVerify { -class IVerifyTask: public std::enable_shared_from_this{ +class IVerifyTask : public std::enable_shared_from_this { public: IVerifyTask() = default; virtual ~IVerifyTask() = default; - virtual void OnPostVerify(const std::string &uri, - const OHOS::NetStack::HttpClient::HttpClientResponse &response) = 0; + virtual void OnPostVerify( + const std::string& uri, const OHOS::NetStack::HttpClient::HttpClientResponse& response) = 0; virtual void OnSaveVerifyResult() = 0; - virtual bool OnPreRequest(OHOS::NetStack::HttpClient::HttpClientRequest &request, const std::string &uri) = 0; - virtual const std::unordered_map &GetUriVerifyMap() = 0; + virtual bool OnPreRequest(OHOS::NetStack::HttpClient::HttpClientRequest& request, const std::string& uri) = 0; + virtual const std::unordered_map& GetUriVerifyMap() = 0; virtual OHOS::AppDomainVerify::TaskType GetType() = 0; }; } diff --git a/test/unittest/common/httpsession_test/app_domain_verify_task_mgr_test.cpp b/test/unittest/common/httpsession_test/app_domain_verify_task_mgr_test.cpp index e2465e9..9131853 100644 --- a/test/unittest/common/httpsession_test/app_domain_verify_task_mgr_test.cpp +++ b/test/unittest/common/httpsession_test/app_domain_verify_task_mgr_test.cpp @@ -53,8 +53,10 @@ void AppDomainVerifyTaskMgrTest::TearDown(void) { } -void Sleep(){ - std::this_thread::sleep_for(std::chrono::milliseconds(10)); +#define SLEEP_TIME (10) +void Sleep() +{ + std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME)); } /** * @tc.name: AppDomainVerifyTaskMgrTest001 diff --git a/test/unittest/mock/include/http_client/http_client.h b/test/unittest/mock/include/http_client/http_client.h index f459cd5..96b5106 100644 --- a/test/unittest/mock/include/http_client/http_client.h +++ b/test/unittest/mock/include/http_client/http_client.h @@ -1,20 +1,19 @@ /* -* Copyright (c) 2023 Huawei Device Co., Ltd. -* Licensed 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. -*/ + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed 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. + */ #ifndef COMMUNICATIONNETSTACK_HTTP_CLIENT_H #define COMMUNICATIONNETSTACK_HTTP_CLIENT_H - #endif // COMMUNICATIONNETSTACK_HTTP_CLIENT_H diff --git a/test/unittest/mock/include/http_client/http_client_error.h b/test/unittest/mock/include/http_client/http_client_error.h index 25e7954..972c1f3 100644 --- a/test/unittest/mock/include/http_client/http_client_error.h +++ b/test/unittest/mock/include/http_client/http_client_error.h @@ -1,17 +1,17 @@ /* -* Copyright (C) 2022 Huawei Device Co., Ltd. -* Licensed 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. -*/ + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed 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. + */ #ifndef COMMUNICATIONNETSTACK_HTTP_CLIENT_ERROR_H #define COMMUNICATIONNETSTACK_HTTP_CLIENT_ERROR_H @@ -24,11 +24,13 @@ public: { } - int GetErrorCode() const{ + int GetErrorCode() const + { return errorCode_; }; - const std::string& GetErrorMessage() const{ + const std::string& GetErrorMessage() const + { return errorMsg_; }; diff --git a/test/unittest/mock/include/http_client/http_client_request.h b/test/unittest/mock/include/http_client/http_client_request.h index ab02540..23f6cfc 100644 --- a/test/unittest/mock/include/http_client/http_client_request.h +++ b/test/unittest/mock/include/http_client/http_client_request.h @@ -1,17 +1,17 @@ /* -* Copyright (C) 2022 Huawei Device Co., Ltd. -* Licensed 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. -*/ + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed 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. + */ #ifndef COMMUNICATIONNETSTACK_HTTP_CLIENT_REQUEST_H #define COMMUNICATIONNETSTACK_HTTP_CLIENT_REQUEST_H @@ -19,9 +19,8 @@ namespace OHOS::NetStack::HttpClient { class HttpClientRequest { public: - HttpClientRequest()= default; + HttpClientRequest() = default; }; } - #endif // COMMUNICATIONNETSTACK_HTTP_CLIENT_REQUEST_H diff --git a/test/unittest/mock/include/http_client/http_client_response.h b/test/unittest/mock/include/http_client/http_client_response.h index 213eec8..79e8d70 100644 --- a/test/unittest/mock/include/http_client/http_client_response.h +++ b/test/unittest/mock/include/http_client/http_client_response.h @@ -1,16 +1,16 @@ /* -* Copyright (C) 2022 Huawei Device Co., Ltd. -* Licensed 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. + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed 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. */ #ifndef COMMUNICATIONNETSTACK_HTTP_CLIENT_RESPONSE_H @@ -23,12 +23,14 @@ namespace HttpClient { using ResponseCode = int; class HttpClientResponse { public: - HttpClientResponse() : responseCode_(0) {}; - ResponseCode GetResponseCode() const{ + HttpClientResponse() : responseCode_(0){}; + ResponseCode GetResponseCode() const + { GTEST_LOG_(INFO) << "MOCK GetResponseCode"; return responseCode_; } - const std::string &GetResult() const{ + const std::string& GetResult() const + { GTEST_LOG_(INFO) << "MOCK GetResult"; return result_; } diff --git a/test/unittest/mock/include/http_client/http_client_task.h b/test/unittest/mock/include/http_client/http_client_task.h index f4b2908..406db5e 100644 --- a/test/unittest/mock/include/http_client/http_client_task.h +++ b/test/unittest/mock/include/http_client/http_client_task.h @@ -23,6 +23,7 @@ #include "http_client_response.h" namespace OHOS::NetStack::HttpClient { +#define DATA_BLOCK (10 * 1024) class HttpClientTask : public std::enable_shared_from_this { public: explicit HttpClientTask(const HttpClientRequest& request) @@ -46,14 +47,14 @@ public: if (receive_) { if (onDataReceive_) { uint8_t* fake; - onDataReceive_(request_, fake, 10 * 1024); - onDataReceive_(request_, fake, 10 * 1024); - onDataReceive_(request_, fake, 10 * 1024); + onDataReceive_(request_, fake, DATA_BLOCK); + onDataReceive_(request_, fake, DATA_BLOCK); + onDataReceive_(request_, fake, DATA_BLOCK); } } - if(cancel_){ - if(onCanceled_){ - onCanceled_(request_,response_); + if (cancel_) { + if (onCanceled_) { + onCanceled_(request_, response_); } } return true; @@ -96,7 +97,7 @@ public: { response_ = response; }; - static void MockStatus(bool success = true, bool failed = false, bool receive = false, bool cancel = false) + static void MockStatus(bool success = true, bool failed = false, bool receive = false, bool cancel = false) { success_ = success; failed_ = failed; @@ -104,7 +105,8 @@ public: cancel_ = cancel; } - static void MockResponse(HttpClientResponse& response){ + static void MockResponse(HttpClientResponse& response) + { response_ = response; } diff --git a/test/unittest/mock/include/mock_preferences.h b/test/unittest/mock/include/mock_preferences.h index 6eade7c..a5cf16c 100644 --- a/test/unittest/mock/include/mock_preferences.h +++ b/test/unittest/mock/include/mock_preferences.h @@ -56,7 +56,6 @@ public: } double GetDouble(const std::string& key, const double& defValue = {}) override { - return 0; } int64_t GetLong(const std::string& key, const int64_t& defValue = {}) override diff --git a/test/unittest/mock/include/mock_verify_http_task.h b/test/unittest/mock/include/mock_verify_http_task.h index 7a9656d..c421d72 100644 --- a/test/unittest/mock/include/mock_verify_http_task.h +++ b/test/unittest/mock/include/mock_verify_http_task.h @@ -34,10 +34,6 @@ public: const uint8_t* data, size_t length), (override)); }; - -class MocHttpClientTask:public HttpClientTask{ - -}; } } #endif // APP_DOMAIN_VERIFY_MOCK_VERIFY_HTTP_TASK_H