diff --git a/cpp-httplib-0.92-test-offline.patch b/cpp-httplib-0.92-test-offline.patch new file mode 100644 index 0000000..0008ad8 --- /dev/null +++ b/cpp-httplib-0.92-test-offline.patch @@ -0,0 +1,139 @@ +From 217e469f4786abb6b14a89e559117e45f92aa7eb Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= +Date: Sat, 21 Aug 2021 16:47:22 +0200 +Subject: [PATCH] Support offline unit tests only + +Some environments provide no network connectivity. Allow simple way to +skip tests requiring working internet connection. Just defining +-DOFFLINE would omit tests failing without connection. +--- + test/Makefile | 3 ++- + test/test.cc | 14 ++++++++++++++ + 2 files changed, 16 insertions(+), 1 deletion(-) + +diff --git a/test/Makefile b/test/Makefile +index c653ca1..c4c6230 100644 +--- a/test/Makefile ++++ b/test/Makefile +@@ -1,5 +1,6 @@ + #CXX = clang++ +-CXXFLAGS = -g -std=c++11 -I.. -I. -Wall -Wextra -Wtype-limits -Wconversion #-fsanitize=address ++#OFFLINE=-DOFFLINE # Uncoment to run only localhost tests ++CXXFLAGS = -g -std=c++11 -I.. -I. -Wall -Wextra -Wtype-limits -Wconversion $(OFFLINE) #-fsanitize=address + + OPENSSL_DIR = /usr/local/opt/openssl@1.1 + OPENSSL_SUPPORT = -DCPPHTTPLIB_OPENSSL_SUPPORT -I$(OPENSSL_DIR)/include -L$(OPENSSL_DIR)/lib -lssl -lcrypto +diff --git a/test/test.cc b/test/test.cc +index f9077fa..0851f12 100644 +--- a/test/test.cc ++++ b/test/test.cc +@@ -354,6 +354,7 @@ TEST(BufferStreamTest, read) { + EXPECT_EQ(0, strm.read(buf, 1)); + } + ++#ifndef OFFLINE + TEST(ChunkedEncodingTest, FromHTTPWatch) { + auto host = "www.httpwatch.com"; + +@@ -495,6 +496,7 @@ TEST(RangeTest, FromHTTPBin) { + EXPECT_EQ(416, res->status); + } + } ++#endif + + TEST(ConnectionErrorTest, InvalidHost) { + auto host = "-abcde.com"; +@@ -578,6 +580,7 @@ TEST(ConnectionErrorTest, Timeout) { + EXPECT_TRUE(res.error() == Error::Connection); + } + ++#ifndef OFFLINE + TEST(CancelTest, NoCancel) { + auto host = "httpbin.org"; + +@@ -850,6 +853,7 @@ TEST(UrlWithSpace, Redirect) { + } + + #endif ++#endif /* OFFLINE */ + + TEST(RedirectToDifferentPort, Redirect) { + Server svr8080; +@@ -3852,6 +3856,7 @@ TEST(GetWithParametersTest, GetWithParameters2) { + ASSERT_FALSE(svr.is_running()); + } + ++#ifndef OFFLINE + TEST(ClientDefaultHeadersTest, DefaultHeaders) { + Client cli("httpbin.org"); + cli.set_default_headers({make_range_header({{1, 10}})}); +@@ -3871,6 +3876,7 @@ TEST(ClientDefaultHeadersTest, DefaultHeaders) { + EXPECT_EQ(206, res->status); + } + } ++#endif + + TEST(ServerDefaultHeadersTest, DefaultHeaders) { + Server svr; +@@ -4076,6 +4082,7 @@ TEST_F(PayloadMaxLengthTest, ExceedLimit) { + } + + #ifdef CPPHTTPLIB_OPENSSL_SUPPORT ++#ifndef OFFLINE + TEST(SSLClientTest, UpdateCAStore) { + httplib::SSLClient httplib_client("www.google.com"); + auto ca_store_1 = X509_STORE_new(); +@@ -4119,6 +4126,7 @@ TEST(SSLClientTest, ServerCertificateVerification3) { + ASSERT_TRUE(res); + ASSERT_EQ(301, res->status); + } ++#endif + + TEST(SSLClientTest, ServerCertificateVerification4) { + SSLServer svr(SERVER_CERT2_FILE, SERVER_PRIVATE_KEY_FILE); +@@ -4145,6 +4153,7 @@ TEST(SSLClientTest, ServerCertificateVerification4) { + t.join(); + } + ++#ifndef OFFLINE + TEST(SSLClientTest, WildcardHostNameMatch) { + SSLClient cli("www.youtube.com"); + +@@ -4156,6 +4165,7 @@ TEST(SSLClientTest, WildcardHostNameMatch) { + ASSERT_TRUE(res); + ASSERT_EQ(200, res->status); + } ++#endif + + TEST(SSLClientServerTest, ClientCertPresent) { + SSLServer svr(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE, CLIENT_CA_CERT_FILE, +@@ -4390,6 +4400,7 @@ TEST(NoScheme, SimpleInterface) { + ASSERT_TRUE(cli.is_valid()); + } + ++#ifndef OFFLINE + TEST(SendAPI, SimpleInterface) { + Client cli("http://yahoo.com"); + +@@ -4401,8 +4412,10 @@ TEST(SendAPI, SimpleInterface) { + ASSERT_TRUE(res); + EXPECT_EQ(301, res->status); + } ++#endif + + #ifdef CPPHTTPLIB_OPENSSL_SUPPORT ++#ifndef OFFLINE + TEST(YahooRedirectTest2, SimpleInterface) { + Client cli("http://yahoo.com"); + +@@ -4504,6 +4517,7 @@ TEST(HttpsToHttpRedirectTest3, SimpleInterface) { + ASSERT_TRUE(res); + EXPECT_EQ(200, res->status); + } ++#endif /* OFFLINE */ + + TEST(HttpToHttpsRedirectTest, CertFile) { + Server svr; +-- +2.31.1 + diff --git a/cpp-httplib.spec b/cpp-httplib.spec index 1d59211..161e17d 100644 --- a/cpp-httplib.spec +++ b/cpp-httplib.spec @@ -1,8 +1,7 @@ %global forgeurl0 https://github.com/yhirose/cpp-httplib %undefine __cmake_in_source_build -# TODO: tests don't work offline in mock -%bcond_with tests +%bcond_without tests # Compiled version in shared library. # Does not have any so-version, therefore not default %bcond_with compile @@ -22,6 +21,9 @@ License: MIT URL: https://github.com/yhirose/cpp-httplib Source0: %forgesource +# https://github.com/yhirose/cpp-httplib/pull/1026 +Patch1: cpp-httplib-0.92-test-offline.patch + BuildRequires: redhat-rpm-config BuildRequires: gcc-c++ BuildRequires: cmake @@ -30,6 +32,7 @@ BuildRequires: zlib-devel BuildRequires: brotli-devel %if %{with tests} BuildRequires: make openssl +BuildRequires: gtest-devel %endif %description @@ -57,7 +60,7 @@ If you are looking for a 'non-blocking' library, this is not the one that you wa Development files only. %prep -%forgeautosetup +%forgeautosetup -p1 %build @@ -76,7 +79,7 @@ Development files only. %check %if %{with tests} cd test -make +make OFFLINE=-DOFFLINE %endif