diff --git a/src/helpers/webhelpers.cpp b/src/helpers/webhelpers.cpp index 5fc87f9..a2d8935 100644 --- a/src/helpers/webhelpers.cpp +++ b/src/helpers/webhelpers.cpp @@ -15,7 +15,11 @@ namespace Nickvision::Aura curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true); curl_easy_setopt(curl, CURLOPT_NOBODY, 1); curl_easy_setopt(curl, CURLOPT_HEADER, false); - CURLcode code = curl_easy_perform(curl); +#ifdef _WIN32 + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); +#endif + CURLcode code{ curl_easy_perform(curl) }; curl_easy_cleanup(curl); curl_global_cleanup(); return code == CURLE_OK; @@ -39,21 +43,25 @@ namespace Nickvision::Aura curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, [](char* ptr, size_t size, size_t nmemb, void* data) { - std::ofstream* stream{ (std::ofstream*)data }; + std::ofstream* stream{ reinterpret_cast(data) }; stream->write(ptr, size * nmemb); return size * nmemb; }); +#ifdef _WIN32 + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); +#endif if (progress) { curl_easy_setopt(curl, CURLOPT_NOPROGRESS, false); curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &progress); curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, [](void* data, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) { - CurlProgressFunction& func{ *((CurlProgressFunction*)data) }; + CurlProgressFunction& func{ *(reinterpret_cast(data)) }; return func(dltotal, dlnow, ultotal, ulnow); }); } - CURLcode code = curl_easy_perform(curl); + CURLcode code{ curl_easy_perform(curl) }; curl_easy_cleanup(curl); curl_global_cleanup(); return code == CURLE_OK; @@ -77,11 +85,15 @@ namespace Nickvision::Aura curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, [](char* ptr, size_t size, size_t nmemb, void* data) { - std::stringstream* stream{ (std::stringstream*)data }; + std::stringstream* stream{ reinterpret_cast(data) }; stream->write(ptr, size * nmemb); return size * nmemb; }); - CURLcode code = curl_easy_perform(curl); +#ifdef _WIN32 + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); +#endif + CURLcode code{ curl_easy_perform(curl) }; curl_easy_cleanup(curl); curl_slist_free_all(listHttpHeader); curl_global_cleanup(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cf41b77..843c8e9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,7 +4,8 @@ enable_testing() add_executable(${PROJECT_NAME} stringtests.cpp - versiontests.cpp) + versiontests.cpp + webtests.cpp) target_link_libraries(${PROJECT_NAME} PRIVATE libaura-static) find_package(GTest REQUIRED) diff --git a/tests/webtests.cpp b/tests/webtests.cpp new file mode 100644 index 0000000..0ad8bfd --- /dev/null +++ b/tests/webtests.cpp @@ -0,0 +1,19 @@ +#include +#include "helpers/webhelpers.h" + +using namespace Nickvision::Aura; + +TEST(WebTests, ValidWebsite1) +{ + EXPECT_TRUE(WebHelpers::isValidWebsite("https://example.com")); +} + +TEST(WebTests, ValidWebsite2) +{ + EXPECT_FALSE(WebHelpers::isValidWebsite("https://www.sdfjsdfj.com")); +} + +TEST(WebTests, DownloadFile1) +{ + EXPECT_TRUE(WebHelpers::downloadFile("https://www.w3.org/TR/2003/REC-PNG-20031110/iso_8859-1.txt", "test.txt")); +} \ No newline at end of file