Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue that proxy port is removed if it matches the standard port #3027

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a1b2c3d4e5f6 nextcloud-news-app "docker-entrypoint.…" 2 hours ago Up 2 hours 0.0.0.0:8081->80/tcp nextcloud-news-app
```
To open a shell run

To open a shell as www-data which you need to run occ commands run:

Check failure on line 37 in docker/README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'occ'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'occ'?", "location": {"path": "docker/README.md", "range": {"start": {"line": 37, "column": 51}}}, "severity": "ERROR"}
``` bash
docker exec -u www-data -it nextcloud-news-app /bin/bash
```

To open a shell as root run
``` bash
docker exec -it nextcloud-news-app /bin/bash
```
Expand Down
40 changes: 37 additions & 3 deletions lib/Config/FetcherConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace OCA\News\Config;

use FeedIo\Adapter\ClientInterface;
use Psr\Log\LoggerInterface;
use \GuzzleHttp\Client;
use OCA\News\AppInfo\Application;
use OCA\News\Fetcher\Client\FeedIoClient;
Expand Down Expand Up @@ -72,15 +73,28 @@ class FetcherConfig
* @var int
*/
public const SLEEPY_DURATION = 86400;

/**
* Logger
* @var LoggerInterface
*/
private LoggerInterface $logger;

/**
* FetcherConfig constructor.
*
* @param IAppConfig $config App configuration
* @param IConfig $systemconfig System configuration
* @param IAppManager $appManager App manager
* @param LoggerInterface $logger Logger
*/
public function __construct(IAppConfig $config, IConfig $systemconfig, IAppManager $appManager)
{
public function __construct(
IAppConfig $config,
IConfig $systemconfig,
IAppManager $appManager,
LoggerInterface $logger
) {
$this->logger = $logger;
$this->version = $appManager->getAppVersion(Application::NAME);
$this->client_timeout = $config->getValueInt(
Application::NAME,
Expand All @@ -95,8 +109,13 @@ public function __construct(IAppConfig $config, IConfig $systemconfig, IAppManag

$proxy = $systemconfig->getSystemValue('proxy', null);
if (is_null($proxy)) {
$this->logger->debug('No proxy configuration found');
return $this;
}
$this->logger->debug(
'Proxy configuration found: {proxy}',
['proxy' => $proxy]
);

$url = new Net_URL2($proxy);

Expand All @@ -106,7 +125,12 @@ public function __construct(IAppConfig $config, IConfig $systemconfig, IAppManag
$url->setUserinfo($auth[0], $auth[1]);
}

$this->proxy = $url->getNormalizedURL();
$this->proxy = $url->getURL();

$this->logger->debug(
'Proxy configuration finalized: {proxy}',
['proxy' => $this->proxy]
);

return $this;
}
Expand Down Expand Up @@ -174,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;
}
}
42 changes: 39 additions & 3 deletions tests/Unit/Config/FetcherConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCP\App\IAppManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;

/**
* Class FetcherConfigTest
Expand All @@ -49,6 +50,9 @@ class FetcherConfigTest extends TestCase
/** @var FetcherConfig */
protected $class;

/** @var MockObject|LoggerInterface */
protected $logger;

protected function setUp(): void
{
$this->config = $this->getMockBuilder(IAppConfig::class)
Expand All @@ -62,14 +66,19 @@ protected function setUp(): void
$this->appmanager = $this->getMockBuilder(IAppManager::class)
->disableOriginalConstructor()
->getMock();

$this->logger = $this->getMockBuilder(LoggerInterface::class)
->disableOriginalConstructor()
->getMock();

}

/**
* Test a valid call will work
*/
public function testGetClient()
{
$this->class = new FetcherConfig($this->config, $this->sysconfig, $this->appmanager);
$this->class = new FetcherConfig($this->config, $this->sysconfig, $this->appmanager, $this->logger);

$this->assertInstanceOf(FeedIoClient::class, $this->class->getClient());
}
Expand All @@ -87,7 +96,7 @@ public function testGetUserAgent()
->method('getAppVersion')
->willReturn('123.45');

$this->class = new FetcherConfig($this->config, $this->sysconfig, $this->appmanager);
$this->class = new FetcherConfig($this->config, $this->sysconfig, $this->appmanager, $this->logger);

$expected = 'NextCloud-News/123.45';
$response = $this->class->getUserAgent();
Expand All @@ -107,10 +116,37 @@ public function testGetUserAgentUnknownVersion()
->method('getAppVersion')
->willReturn('1.0');

$this->class = new FetcherConfig($this->config, $this->sysconfig, $this->appmanager);
$this->class = new FetcherConfig($this->config, $this->sysconfig, $this->appmanager, $this->logger);

$expected = 'NextCloud-News/1.0';
$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);
}
}
Loading