From 3cae6014bf6ac7b3cb998e1443341ff4fbf0a6af Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Wed, 8 Jan 2025 11:31:13 +0100 Subject: [PATCH] fix issue that port is removed Signed-off-by: Benjamin Brahmer --- CHANGELOG.md | 1 + lib/Config/FetcherConfig.php | 14 +++++++++++-- tests/Unit/Config/FetcherConfigTest.php | 27 +++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 851fd9902..819d29792 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ You can also check [on GitHub](https://github.com/nextcloud/news/releases), the - add explanations for the individual values in the feed information table ### Fixed +- fix proxy port removed if standard port for the protocol (#3027) # Releases diff --git a/lib/Config/FetcherConfig.php b/lib/Config/FetcherConfig.php index 0b52fb7a6..3bc09324a 100644 --- a/lib/Config/FetcherConfig.php +++ b/lib/Config/FetcherConfig.php @@ -125,11 +125,11 @@ public function __construct( $url->setUserinfo($auth[0], $auth[1]); } - $this->proxy = $url->getNormalizedURL(); + $this->proxy = $url->getURL(); $this->logger->debug( 'Proxy configuration finalized: {proxy}', - ['proxy' => $proxy] + ['proxy' => $this->proxy] ); return $this; @@ -198,4 +198,14 @@ public function getUserAgent(): string return 'NextCloud-News/' . $this->version; } + + /** + * Get the proxy configuration + * + * @return string|null + */ + public function getProxy(): ?string + { + return $this->proxy; + } } diff --git a/tests/Unit/Config/FetcherConfigTest.php b/tests/Unit/Config/FetcherConfigTest.php index 5b1075de4..9b3975d56 100644 --- a/tests/Unit/Config/FetcherConfigTest.php +++ b/tests/Unit/Config/FetcherConfigTest.php @@ -122,4 +122,31 @@ public function testGetUserAgentUnknownVersion() $response = $this->class->getUserAgent(); $this->assertEquals($expected, $response); } + + public function testProxyPortPreserved() + { + $this->config->expects($this->exactly(2)) + ->method('getValueInt') + ->willReturnMap([ + ['news', 'feedFetcherTimeout', 60, false, 60], + ['news', 'maxRedirects', 10, false, 10] + ]); + + $this->appmanager->expects($this->exactly(1)) + ->method('getAppVersion') + ->willReturn('1.0'); + + $this->sysconfig->expects($this->exactly(2)) + ->method('getSystemValue') + ->willReturnMap([ + ['proxy', null, 'http://192.168.178.1:80'], + ['proxyuserpwd', null , null] + ]); + + $this->class = new FetcherConfig($this->config, $this->sysconfig, $this->appmanager, $this->logger); + + $expected = 'http://192.168.178.1:80'; + $response = $this->class->getProxy(); + $this->assertEquals($expected, $response); + } }