From 36644365c8622a249118ea72b50f0e468ea1e394 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 2 Sep 2025 21:55:03 +0300 Subject: [PATCH] use built-in feed for integration test --- .gitlab-ci.yml | 3 +++ classes/UrlHelper.php | 24 +++++++++++++++--------- tests/integration/ApiTest.php | 6 +++++- tests/integration/feed.xml | 14 ++++++++++++++ 4 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 tests/integration/feed.xml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cd4e62a03..b7cd4d44a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -98,6 +98,7 @@ phpunit-integration: FF_NETWORK_PER_BUILD: "true" APP_WEB_ROOT: /builds/shared-root APP_INSTALL_BASE_DIR: ${APP_WEB_ROOT} + APP_BASE: "/tt-rss" APP_FASTCGI_PASS: app:9000 # skip resolver AUTO_CREATE_USER: test AUTO_CREATE_USER_PASS: 'test' @@ -106,6 +107,7 @@ phpunit-integration: APP_URL: http://web-nginx/tt-rss API_URL: ${APP_URL}/api/ HEALTHCHECK_URL: ${APP_URL}/public.php?op=healthcheck + __URLHELPER_ALLOW_LOOPBACK: 'true' services: - &svc_db name: registry.fakecake.org/docker.io/postgres:15-alpine @@ -129,6 +131,7 @@ phpunit-integration: sleep 5 done script: + - cp tests/integration/feed.xml ${APP_WEB_ROOT}/${APP_BASE}/ - php84 vendor/bin/phpunit --group integration --do-not-cache-result --log-junit phpunit-report.xml --coverage-cobertura phpunit-coverage.xml --coverage-text --colors=never artifacts: when: always diff --git a/classes/UrlHelper.php b/classes/UrlHelper.php index f24e13671..7e793be46 100644 --- a/classes/UrlHelper.php +++ b/classes/UrlHelper.php @@ -293,12 +293,15 @@ class UrlHelper { return false; } - $url_host = parse_url($url, PHP_URL_HOST); - $ip_addr = gethostbyname($url_host); + // this skip is needed for integration tests, please don't enable in production + if (!getenv('__URLHELPER_ALLOW_LOOPBACK')) { + $url_host = parse_url($url, PHP_URL_HOST); + $ip_addr = gethostbyname($url_host); - if (!$ip_addr || str_starts_with($ip_addr, '127.')) { - self::$fetch_last_error = "URL hostname failed to resolve or resolved to a loopback address ($ip_addr)"; - return false; + if (!$ip_addr || str_starts_with($ip_addr, '127.')) { + self::$fetch_last_error = "URL hostname failed to resolve or resolved to a loopback address ($ip_addr)"; + return false; + } } $req_options = [ @@ -435,10 +438,13 @@ class UrlHelper { // @phpstan-ignore argument.type (prior validation ensures the host value exists) self::$fetch_effective_ip_addr = gethostbyname(parse_url(self::$fetch_effective_url, PHP_URL_HOST)); - if (!self::$fetch_effective_ip_addr || str_starts_with(self::$fetch_effective_ip_addr, '127.')) { - self::$fetch_last_error = 'URL hostname received after redirection failed to resolve or resolved to a loopback address (' . - self::$fetch_effective_ip_addr . ')'; - return false; + // this skip is needed for integration tests, please don't enable in production + if (!getenv('__URLHELPER_ALLOW_LOOPBACK')) { + if (!self::$fetch_effective_ip_addr || str_starts_with(self::$fetch_effective_ip_addr, '127.')) { + self::$fetch_last_error = 'URL hostname received after redirection failed to resolve or resolved to a loopback address (' . + self::$fetch_effective_ip_addr . ')'; + return false; + } } $body = (string) $response->getBody(); diff --git a/tests/integration/ApiTest.php b/tests/integration/ApiTest.php index d7b605b6e..5cf364217 100644 --- a/tests/integration/ApiTest.php +++ b/tests/integration/ApiTest.php @@ -4,10 +4,12 @@ use PHPUnit\Framework\TestCase; /** @group integration */ final class ApiTest extends TestCase { private string $api_url = ""; + private string $app_url = ""; private string $sid = ""; function __construct() { $this->api_url = getenv('API_URL'); + $this->app_url = getenv('APP_URL'); parent::__construct(); } @@ -73,9 +75,11 @@ final class ApiTest extends TestCase { } public function test_subscribeToFeed() : void { - $resp = $this->api(["op" => "subscribeToFeed", "feed_url" => "https://gitlab.tt-rss.org/tt-rss/tt-rss.atom"]); + $resp = $this->api(["op" => "subscribeToFeed", "feed_url" => $this->app_url . "/feed.xml"]); $this->common_assertions($resp); + print_r($resp); + $this->assertArrayHasKey("feed_id", $resp['content']['status']); } diff --git a/tests/integration/feed.xml b/tests/integration/feed.xml new file mode 100644 index 000000000..a705b0f79 --- /dev/null +++ b/tests/integration/feed.xml @@ -0,0 +1,14 @@ + + + Atom:base testfeed + tag:fakecake.org,2021:minerva-feed + 2021-05-21T14:17:43+04:00 + + x-21may2020 + + tag:fakecake.org,2021:minerva-2021-05-20 + 2021-05-21T07:54:43+04:00 + 2021-05-21T07:54:43+04:00 + ... + +