Honor "hide_version_public" setting in JSON response headers (#3394)

* Honor "hide_version_public" setting while setting JSON headers

* Fix PHPUnit tests to mock shouldExposeVersion() after refactoring

Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>
This commit is contained in:
Yağızhan Burak Yakarandadmdly authored and GitHub committed 2026-04-08 13:06:27 +03:00
1 parent e573a872c1
commit ef795ffcdb
4 files changed
+24 -41

No files matched your search

+3 -1
View File
@@ -331,7 +331,9 @@ class Client implements InjectionAwareInterface
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json; charset=utf-8');
header('X-FOSSBilling-Version: ' . \FOSSBilling\Version::VERSION);
if ($this->di['mod_service']('system')->shouldExposeVersion()) {
header('X-FOSSBilling-Version: ' . \FOSSBilling\Version::VERSION);
}
header('X-RateLimit-Span: ' . $this->_api_config['rate_span']);
header('X-RateLimit-Limit: ' . $this->_api_config['rate_limit']);
header('X-RateLimit-Remaining: ' . $this->_requests_left);
+3 -9
View File
@@ -28,15 +28,9 @@ class Guest extends \Api_Abstract
*/
public function version()
{
$hideVersionGuest = $this->getService()->getParamValue('hide_version_public');
// Only provide the FOSSBilling version if configured to do so or if the request is being made by an administrator.
if ($this->di['auth']->isAdminLoggedIn() || !$hideVersionGuest) {
return $this->getService()->getVersion();
}
// return an empty string
return '';
$service = $this->getService();
return $service->shouldExposeVersion() ? $service->getVersion() : '';
}
/**
+7
View File
@@ -1000,6 +1000,13 @@ class Service
return Version::VERSION;
}
public function shouldExposeVersion(): bool
{
$hideVersionPublic = $this->getParamValue('hide_version_public');
return $this->di['auth']->isAdminLoggedIn() || !$hideVersionPublic;
}
public function getPendingMessages()
{
$messages = $this->di['session']->get('pending_messages');
+11 -31
View File
@@ -26,19 +26,15 @@ final class GuestTest extends \BBTestCase
public function testVersionAdmin(): void
{
$authorizationMock = $this->getMockBuilder('\Box_Authorization')->disableOriginalConstructor()->getMock();
$authorizationMock->expects($this->atLeastOnce())
->method('isAdminLoggedIn')
->willReturn(true);
$di = $this->getDi();
$di['auth'] = $authorizationMock;
$serviceMock = $this->createMock(\Box\Mod\System\Service::class);
$serviceMock->expects($this->atLeastOnce())
->method('shouldExposeVersion')
->willReturn(true);
$serviceMock->expects($this->atLeastOnce())
->method('getVersion')
->willReturn(\FOSSBilling\Version::VERSION);
$di = $this->getDi();
$this->api->setDi($di);
$this->api->setService($serviceMock);
$result = $this->api->version();
@@ -49,23 +45,15 @@ final class GuestTest extends \BBTestCase
public function testVersionShowPublicOn(): void
{
$authorizationMock = $this->getMockBuilder('\Box_Authorization')->disableOriginalConstructor()->getMock();
$authorizationMock->expects($this->atLeastOnce())
->method('isAdminLoggedIn')
->willReturn(false);
$di = $this->getDi();
$di['auth'] = $authorizationMock;
$serviceMock = $this->createMock(\Box\Mod\System\Service::class);
$serviceMock->expects($this->atLeastOnce())
->method('shouldExposeVersion')
->willReturn(true);
$serviceMock->expects($this->atLeastOnce())
->method('getVersion')
->willReturn(\FOSSBilling\Version::VERSION);
$serviceMock->expects($this->atLeastOnce())
->method('getParamValue')
->with('hide_version_public')
->willReturn(0);
$di = $this->getDi();
$this->api->setDi($di);
$this->api->setService($serviceMock);
$result = $this->api->version();
@@ -76,20 +64,12 @@ final class GuestTest extends \BBTestCase
public function testVersionShowPublicOff(): void
{
$authorizationMock = $this->getMockBuilder('\Box_Authorization')->disableOriginalConstructor()->getMock();
$authorizationMock->expects($this->atLeastOnce())
->method('isAdminLoggedIn')
$serviceMock = $this->createMock(\Box\Mod\System\Service::class);
$serviceMock->expects($this->atLeastOnce())
->method('shouldExposeVersion')
->willReturn(false);
$di = $this->getDi();
$di['auth'] = $authorizationMock;
$serviceMock = $this->createMock(\Box\Mod\System\Service::class);
$serviceMock->expects($this->atLeastOnce())
->method('getParamValue')
->with('hide_version_public')
->willReturn(1);
$this->api->setDi($di);
$this->api->setService($serviceMock);
$result = $this->api->version();