1 /* 2 * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 17 #include <cstring> 18 #include "gtest/gtest.h" 19 20 #ifdef GTEST_API_ 21 #define private public 22 #endif 23 24 #include "http_exec.h" 25 #include "http_async_work.h" 26 #include "netstack_log.h" 27 #include "constant.h" 28 #include "secure_char.h" 29 #include "curl/curl.h" 30 31 using namespace OHOS::NetStack; 32 using namespace OHOS::NetStack::Http; 33 34 class HttpExecTest : public testing::Test { 35 public: SetUpTestCase()36 static void SetUpTestCase() {} 37 TearDownTestCase()38 static void TearDownTestCase() {} 39 SetUp()40 virtual void SetUp() {} 41 TearDown()42 virtual void TearDown() {} 43 }; 44 45 namespace { 46 using namespace std; 47 using namespace testing::ext; 48 49 50 HWTEST_F(HttpExecTest, SetOption001, TestSize.Level1) 51 { 52 auto handle = curl_easy_init(); 53 54 napi_env env = nullptr; 55 EventManager manager; 56 OHOS::NetStack::Http::RequestContext context(env, &manager); 57 58 EXPECT_TRUE(HttpExec::SetOption(handle, &context, context.GetCurlHeaderList())); 59 } 60 61 HWTEST_F(HttpExecTest, SetServerSSLCertOption001, TestSize.Level1) 62 { 63 auto handle = curl_easy_init(); 64 65 napi_env env = nullptr; 66 EventManager manager; 67 OHOS::NetStack::Http::RequestContext context(env, &manager); 68 69 EXPECT_TRUE(HttpExec::SetServerSSLCertOption(handle, &context)); 70 } 71 72 } // namespace