use built-in feed for integration test

This commit is contained in:
Andrew Dolgov 2025-09-02 21:55:03 +03:00
parent be3ee920b1
commit 36644365c8
No known key found for this signature in database
GPG Key ID: 1A56B4FA25D4AF2A
4 changed files with 37 additions and 10 deletions

View File

@ -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

View File

@ -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();

View File

@ -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']);
}

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:base="https://mfw.fakecake.org/testfeeds/" >
<title type="text">Atom:base testfeed</title>
<id>tag:fakecake.org,2021:minerva-feed</id>
<updated>2021-05-21T14:17:43+04:00</updated>
<entry>
<title>x-21may2020</title>
<link rel="alternate" type="text/html" href="clouds.png" />
<id>tag:fakecake.org,2021:minerva-2021-05-20</id>
<updated>2021-05-21T07:54:43+04:00</updated>
<published>2021-05-21T07:54:43+04:00</published>
<content type="html">...</content>
</entry>
</feed>