summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitlab-ci.yml3
-rw-r--r--classes/UrlHelper.php24
-rw-r--r--tests/integration/ApiTest.php6
-rw-r--r--tests/integration/feed.xml14
4 files changed, 37 insertions, 10 deletions
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 @@
+<?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>