Files
Sunshine/tests/unit/test_httpcommon.cpp
Cody Maness 64544e7960
Some checks failed
CI / GitHub Env Debug (push) Has been cancelled
CI / Setup Release (push) Has been cancelled
CI / Setup Flatpak Matrix (push) Has been cancelled
CI Docker / Check Dockerfiles (push) Has been cancelled
CodeQL / Get language matrix (push) Has been cancelled
localize / Update Localization (push) Has been cancelled
Build GH-Pages / prep (push) Has been cancelled
CI / Linux Flatpak (push) Has been cancelled
CI / Linux ${{ matrix.type }} (--appimage-build, 22.04, AppImage) (push) Has been cancelled
CI / Homebrew (${{ matrix.os_name }}-${{ matrix.os_version }}${{ matrix.release == true && ' (Release)' || '' }}) (macos, 13) (push) Has been cancelled
CI / Homebrew (${{ matrix.os_name }}-${{ matrix.os_version }}${{ matrix.release == true && ' (Release)' || '' }}) (macos, 14) (push) Has been cancelled
CI / Homebrew (${{ matrix.os_name }}-${{ matrix.os_version }}${{ matrix.release == true && ' (Release)' || '' }}) (ubuntu, latest) (push) Has been cancelled
CI / Homebrew (${{ matrix.os_name }}-${{ matrix.os_version }}${{ matrix.release == true && ' (Release)' || '' }}) (ubuntu, latest, true) (push) Has been cancelled
CI / Windows (push) Has been cancelled
CI Docker / Setup Release (push) Has been cancelled
CI Docker / Docker${{ matrix.tag }} (push) Has been cancelled
CodeQL / Analyze (${{ matrix.name }}) (push) Has been cancelled
Build GH-Pages / call-jekyll-build (push) Has been cancelled
fix(httpcommon): sonarqube warning cleanup (#3558)
Co-authored-by: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com>
2025-01-22 09:16:14 -05:00

74 lines
2.0 KiB
C++

/**
* @file tests/unit/test_httpcommon.cpp
* @brief Test src/httpcommon.*.
*/
// test imports
#include "../tests_common.h"
// lib imports
#include <curl/curl.h>
// local imports
#include <src/httpcommon.h>
struct UrlEscapeTest: testing::TestWithParam<std::tuple<std::string, std::string>> {};
TEST_P(UrlEscapeTest, Run) {
const auto &[input, expected] = GetParam();
ASSERT_EQ(http::url_escape(input), expected);
}
INSTANTIATE_TEST_SUITE_P(
UrlEscapeTests,
UrlEscapeTest,
testing::Values(
std::make_tuple("igdb_0123456789", "igdb_0123456789"),
std::make_tuple("../../../", "..%2F..%2F..%2F"),
std::make_tuple("..*\\", "..%2A%5C")
)
);
struct UrlGetHostTest: testing::TestWithParam<std::tuple<std::string, std::string>> {};
TEST_P(UrlGetHostTest, Run) {
const auto &[input, expected] = GetParam();
ASSERT_EQ(http::url_get_host(input), expected);
}
INSTANTIATE_TEST_SUITE_P(
UrlGetHostTests,
UrlGetHostTest,
testing::Values(
std::make_tuple("https://images.igdb.com/example.txt", "images.igdb.com"),
std::make_tuple("http://localhost:8080", "localhost"),
std::make_tuple("nonsense!!}{::", "")
)
);
struct DownloadFileTest: testing::TestWithParam<std::tuple<std::string, std::string>> {};
TEST_P(DownloadFileTest, Run) {
const auto &[url, filename] = GetParam();
const std::string test_dir = platf::appdata().string() + "/tests/";
std::string path = test_dir + filename;
ASSERT_TRUE(http::download_file(url, path, CURL_SSLVERSION_TLSv1_0));
}
#ifdef SUNSHINE_BUILD_FLATPAK
// requires running `npm run serve` prior to running the tests
constexpr const char *URL_1 = "http://0.0.0.0:3000/hello.txt";
constexpr const char *URL_2 = "http://0.0.0.0:3000/hello-redirect.txt";
#else
constexpr const char *URL_1 = "https://httpbin.org/base64/aGVsbG8h";
constexpr const char *URL_2 = "https://httpbin.org/redirect-to?url=/base64/aGVsbG8h";
#endif
INSTANTIATE_TEST_SUITE_P(
DownloadFileTests,
DownloadFileTest,
testing::Values(
std::make_tuple(URL_1, "hello.txt"),
std::make_tuple(URL_2, "hello-redirect.txt")
)
);