aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJulius Knorr <jus@bitgrid.net>2024-09-17 22:38:44 +0200
committerJulius Knorr <jus@bitgrid.net>2024-09-20 14:53:34 +0200
commit606241caebda2e01702c0d08adbc35ace8d01f13 (patch)
treeda9cc49d1079724a9192f89415c594b97db93aa9 /tests
parent7ff911665e7507a800e05fe9cd80e0304cd11dbc (diff)
downloadnextcloud-server-606241caebda2e01702c0d08adbc35ace8d01f13.tar.gz
nextcloud-server-606241caebda2e01702c0d08adbc35ace8d01f13.zip
chore(legacy): Introduce public version ct plass and drop version methods from OC_Utilclean/version-ocp
Signed-off-by: Julius Knorr <jus@bitgrid.net>
Diffstat (limited to 'tests')
-rw-r--r--tests/Core/Controller/OCSControllerTest.php28
-rw-r--r--tests/lib/IntegrityCheck/CheckerTest.php44
-rw-r--r--tests/lib/IntegrityCheck/Helpers/EnvironmentHelperTest.php4
-rw-r--r--tests/lib/PublicNamespace/UtilTest.php30
-rw-r--r--tests/lib/Updater/VersionCheckTest.php23
-rw-r--r--tests/lib/UpdaterTest.php25
-rw-r--r--tests/lib/UtilTest.php10
7 files changed, 64 insertions, 100 deletions
diff --git a/tests/Core/Controller/OCSControllerTest.php b/tests/Core/Controller/OCSControllerTest.php
index 6fc5f54b8ef..142a15e2308 100644
--- a/tests/Core/Controller/OCSControllerTest.php
+++ b/tests/Core/Controller/OCSControllerTest.php
@@ -15,6 +15,7 @@ use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
+use OCP\ServerVersion;
use Test\TestCase;
class OCSControllerTest extends TestCase {
@@ -28,6 +29,8 @@ class OCSControllerTest extends TestCase {
private $userManager;
/** @var Manager|\PHPUnit\Framework\MockObject\MockObject */
private $keyManager;
+ /** @var ServerVersion|\PHPUnit\Framework\MockObject\MockObject */
+ private $serverVersion;
/** @var OCSController */
private $controller;
@@ -39,6 +42,7 @@ class OCSControllerTest extends TestCase {
$this->userSession = $this->createMock(IUserSession::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->keyManager = $this->createMock(Manager::class);
+ $serverVersion = \OCP\Server::get(ServerVersion::class);
$this->controller = new OCSController(
'core',
@@ -46,7 +50,8 @@ class OCSControllerTest extends TestCase {
$this->capabilitiesManager,
$this->userSession,
$this->userManager,
- $this->keyManager
+ $this->keyManager,
+ $serverVersion
);
}
@@ -72,14 +77,15 @@ class OCSControllerTest extends TestCase {
$this->userSession->expects($this->once())
->method('isLoggedIn')
->willReturn(true);
- [$major, $minor, $micro] = \OCP\Util::getVersion();
+
+ $serverVersion = \OCP\Server::get(ServerVersion::class);
$result = [];
$result['version'] = [
- 'major' => $major,
- 'minor' => $minor,
- 'micro' => $micro,
- 'string' => \OC_Util::getVersionString(),
+ 'major' => $serverVersion->getMajorVersion(),
+ 'minor' => $serverVersion->getMinorVersion(),
+ 'micro' => $serverVersion->getPatchVersion(),
+ 'string' => $serverVersion->getVersionString(),
'edition' => '',
'extendedSupport' => false
];
@@ -105,14 +111,14 @@ class OCSControllerTest extends TestCase {
$this->userSession->expects($this->once())
->method('isLoggedIn')
->willReturn(false);
- [$major, $minor, $micro] = \OCP\Util::getVersion();
+ $serverVersion = \OCP\Server::get(ServerVersion::class);
$result = [];
$result['version'] = [
- 'major' => $major,
- 'minor' => $minor,
- 'micro' => $micro,
- 'string' => \OC_Util::getVersionString(),
+ 'major' => $serverVersion->getMajorVersion(),
+ 'minor' => $serverVersion->getMinorVersion(),
+ 'micro' => $serverVersion->getPatchVersion(),
+ 'string' => $serverVersion->getVersionString(),
'edition' => '',
'extendedSupport' => false
];
diff --git a/tests/lib/IntegrityCheck/CheckerTest.php b/tests/lib/IntegrityCheck/CheckerTest.php
index 6b6da1cc30c..5858a01203f 100644
--- a/tests/lib/IntegrityCheck/CheckerTest.php
+++ b/tests/lib/IntegrityCheck/CheckerTest.php
@@ -17,11 +17,14 @@ use OCP\App\IAppManager;
use OCP\IAppConfig;
use OCP\ICacheFactory;
use OCP\IConfig;
+use OCP\ServerVersion;
use phpseclib\Crypt\RSA;
use phpseclib\File\X509;
use Test\TestCase;
class CheckerTest extends TestCase {
+ /** @var ServerVersion|\PHPUnit\Framework\MockObject\MockObject */
+ private $serverVersion;
/** @var EnvironmentHelper|\PHPUnit\Framework\MockObject\MockObject */
private $environmentHelper;
/** @var AppLocator|\PHPUnit\Framework\MockObject\MockObject */
@@ -43,6 +46,7 @@ class CheckerTest extends TestCase {
protected function setUp(): void {
parent::setUp();
+ $this->serverVersion = $this->createMock(ServerVersion::class);
$this->environmentHelper = $this->createMock(EnvironmentHelper::class);
$this->fileAccessHelper = $this->createMock(FileAccessHelper::class);
$this->appLocator = $this->createMock(AppLocator::class);
@@ -62,6 +66,7 @@ class CheckerTest extends TestCase {
->willReturn(new NullCache());
$this->checker = new Checker(
+ $this->serverVersion,
$this->environmentHelper,
$this->fileAccessHelper,
$this->appLocator,
@@ -149,7 +154,7 @@ class CheckerTest extends TestCase {
}
public function testVerifyAppSignatureWithoutSignatureData(): void {
- $this->environmentHelper
+ $this->serverVersion
->expects($this->once())
->method('getChannel')
->willReturn('stable');
@@ -169,7 +174,7 @@ class CheckerTest extends TestCase {
}
public function testVerifyAppSignatureWithValidSignatureData(): void {
- $this->environmentHelper
+ $this->serverVersion
->expects($this->once())
->method('getChannel')
->willReturn('stable');
@@ -208,7 +213,7 @@ class CheckerTest extends TestCase {
}
public function testVerifyAppSignatureWithTamperedSignatureData(): void {
- $this->environmentHelper
+ $this->serverVersion
->expects($this->once())
->method('getChannel')
->willReturn('stable');
@@ -253,7 +258,7 @@ class CheckerTest extends TestCase {
}
public function testVerifyAppSignatureWithTamperedFiles(): void {
- $this->environmentHelper
+ $this->serverVersion
->expects($this->once())
->method('getChannel')
->willReturn('stable');
@@ -314,7 +319,7 @@ class CheckerTest extends TestCase {
}
public function testVerifyAppSignatureWithTamperedFilesAndAlternatePath(): void {
- $this->environmentHelper
+ $this->serverVersion
->expects($this->once())
->method('getChannel')
->willReturn('stable');
@@ -374,7 +379,7 @@ class CheckerTest extends TestCase {
}
public function testVerifyAppWithDifferentScope(): void {
- $this->environmentHelper
+ $this->serverVersion
->expects($this->once())
->method('getChannel')
->willReturn('stable');
@@ -418,7 +423,7 @@ class CheckerTest extends TestCase {
}
public function testVerifyAppWithDifferentScopeAndAlwaysTrustedCore(): void {
- $this->environmentHelper
+ $this->serverVersion
->expects($this->once())
->method('getChannel')
->willReturn('stable');
@@ -639,7 +644,7 @@ class CheckerTest extends TestCase {
}
public function testVerifyCoreSignatureWithoutSignatureData(): void {
- $this->environmentHelper
+ $this->serverVersion
->expects($this->once())
->method('getChannel')
->willReturn('stable');
@@ -659,7 +664,7 @@ class CheckerTest extends TestCase {
}
public function testVerifyCoreSignatureWithValidSignatureData(): void {
- $this->environmentHelper
+ $this->serverVersion
->expects($this->once())
->method('getChannel')
->willReturn('stable');
@@ -696,7 +701,7 @@ class CheckerTest extends TestCase {
}
public function testVerifyCoreSignatureWithValidModifiedHtaccessSignatureData(): void {
- $this->environmentHelper
+ $this->serverVersion
->expects($this->once())
->method('getChannel')
->willReturn('stable');
@@ -759,7 +764,7 @@ class CheckerTest extends TestCase {
// occ integrity:sign-core --privateKey=./tests/data/integritycheck/core.key --certificate=./tests/data/integritycheck/core.crt --path=./tests/data/integritycheck/mimetypeListModified
self::assertEquals($newFile, file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/mimetypeListModified/core/js/mimetypelist.js'));
- $this->environmentHelper
+ $this->serverVersion
->expects($this->once())
->method('getChannel')
->willReturn('stable');
@@ -786,7 +791,7 @@ class CheckerTest extends TestCase {
}
public function testVerifyCoreSignatureWithValidSignatureDataAndNotAlphabeticOrder(): void {
- $this->environmentHelper
+ $this->serverVersion
->expects($this->once())
->method('getChannel')
->willReturn('stable');
@@ -823,7 +828,7 @@ class CheckerTest extends TestCase {
}
public function testVerifyCoreSignatureWithTamperedSignatureData(): void {
- $this->environmentHelper
+ $this->serverVersion
->expects($this->once())
->method('getChannel')
->willReturn('stable');
@@ -866,7 +871,7 @@ class CheckerTest extends TestCase {
}
public function testVerifyCoreSignatureWithTamperedFiles(): void {
- $this->environmentHelper
+ $this->serverVersion
->expects($this->once())
->method('getChannel')
->willReturn('stable');
@@ -924,7 +929,7 @@ class CheckerTest extends TestCase {
}
public function testVerifyCoreWithInvalidCertificate(): void {
- $this->environmentHelper
+ $this->serverVersion
->expects($this->once())
->method('getChannel')
->willReturn('stable');
@@ -967,7 +972,7 @@ class CheckerTest extends TestCase {
}
public function testVerifyCoreWithDifferentScope(): void {
- $this->environmentHelper
+ $this->serverVersion
->expects($this->once())
->method('getChannel')
->willReturn('stable');
@@ -1012,6 +1017,7 @@ class CheckerTest extends TestCase {
public function testRunInstanceVerification(): void {
$this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
->setConstructorArgs([
+ $this->serverVersion,
$this->environmentHelper,
$this->fileAccessHelper,
$this->appLocator,
@@ -1090,7 +1096,7 @@ class CheckerTest extends TestCase {
}
public function testVerifyAppSignatureWithoutSignatureDataAndCodeCheckerDisabled(): void {
- $this->environmentHelper
+ $this->serverVersion
->expects($this->once())
->method('getChannel')
->willReturn('stable');
@@ -1120,7 +1126,7 @@ class CheckerTest extends TestCase {
* @dataProvider channelDataProvider
*/
public function testIsCodeCheckEnforced($channel, $isCodeSigningEnforced): void {
- $this->environmentHelper
+ $this->serverVersion
->expects($this->once())
->method('getChannel')
->willReturn($channel);
@@ -1138,7 +1144,7 @@ class CheckerTest extends TestCase {
* @dataProvider channelDataProvider
*/
public function testIsCodeCheckEnforcedWithDisabledConfigSwitch($channel): void {
- $this->environmentHelper
+ $this->serverVersion
->expects($this->once())
->method('getChannel')
->willReturn($channel);
diff --git a/tests/lib/IntegrityCheck/Helpers/EnvironmentHelperTest.php b/tests/lib/IntegrityCheck/Helpers/EnvironmentHelperTest.php
index b8280d9816a..379eb178b06 100644
--- a/tests/lib/IntegrityCheck/Helpers/EnvironmentHelperTest.php
+++ b/tests/lib/IntegrityCheck/Helpers/EnvironmentHelperTest.php
@@ -22,8 +22,4 @@ class EnvironmentHelperTest extends TestCase {
public function testGetServerRoot(): void {
$this->assertSame(\OC::$SERVERROOT, $this->environmentHelper->getServerRoot());
}
-
- public function testGetChannel(): void {
- $this->assertSame(\OC_Util::getChannel(), $this->environmentHelper->getChannel());
- }
}
diff --git a/tests/lib/PublicNamespace/UtilTest.php b/tests/lib/PublicNamespace/UtilTest.php
deleted file mode 100644
index 4fa31bd902a..00000000000
--- a/tests/lib/PublicNamespace/UtilTest.php
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-/**
- * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
- * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-
-namespace Test\PublicNamespace;
-
-class UtilTest extends \Test\TestCase {
- /**
- * @dataProvider channelProvider
- *
- * @param string $channel
- */
- public function testOverrideChannel($channel): void {
- \OCP\Util::setChannel($channel);
- $actual = \OCP\Util::getChannel($channel);
- $this->assertEquals($channel, $actual);
- }
-
- public function channelProvider() {
- return [
- ['daily'],
- ['beta'],
- ['stable'],
- ['production']
- ];
- }
-}
diff --git a/tests/lib/Updater/VersionCheckTest.php b/tests/lib/Updater/VersionCheckTest.php
index 94347265427..51d1625ea4d 100644
--- a/tests/lib/Updater/VersionCheckTest.php
+++ b/tests/lib/Updater/VersionCheckTest.php
@@ -12,11 +12,13 @@ use OCP\Http\Client\IClientService;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IUserManager;
+use OCP\ServerVersion;
use OCP\Support\Subscription\IRegistry;
-use OCP\Util;
use Psr\Log\LoggerInterface;
class VersionCheckTest extends \Test\TestCase {
+ /** @var ServerVersion|\PHPUnit\Framework\MockObject\MockObject */
+ private $serverVersion;
/** @var IConfig| \PHPUnit\Framework\MockObject\MockObject */
private $config;
/** @var IAppConfig| \PHPUnit\Framework\MockObject\MockObject */
@@ -30,15 +32,12 @@ class VersionCheckTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
- $this->config = $this->getMockBuilder(IConfig::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->appConfig = $this->getMockBuilder(IAppConfig::class)
- ->disableOriginalConstructor()
- ->getMock();
- $clientService = $this->getMockBuilder(IClientService::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $this->serverVersion = $this->createMock(ServerVersion::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
+ $clientService = $this->createMock(IClientService::class);
+
+ $this->serverVersion->method('getChannel')->willReturn('git');
$this->registry = $this->createMock(IRegistry::class);
$this->registry
@@ -48,6 +47,7 @@ class VersionCheckTest extends \Test\TestCase {
$this->updater = $this->getMockBuilder(VersionCheck::class)
->setMethods(['getUrlContent'])
->setConstructorArgs([
+ $this->serverVersion,
$clientService,
$this->config,
$this->appConfig,
@@ -63,7 +63,8 @@ class VersionCheckTest extends \Test\TestCase {
* @return string
*/
private function buildUpdateUrl($baseUrl) {
- return $baseUrl . '?version=' . implode('x', Util::getVersion()) . 'xinstalledatx' . time() . 'x' . \OC_Util::getChannel() . 'xxx' . PHP_MAJOR_VERSION . 'x' . PHP_MINOR_VERSION . 'x' . PHP_RELEASE_VERSION . 'x0x0';
+ $serverVersion = \OCP\Server::get(ServerVersion::class);
+ return $baseUrl . '?version=' . implode('x', $serverVersion->getVersion()) . 'xinstalledatx' . time() . 'x' . $serverVersion->getChannel() . 'xxx' . PHP_MAJOR_VERSION . 'x' . PHP_MINOR_VERSION . 'x' . PHP_RELEASE_VERSION . 'x0x0';
}
public function testCheckInCache(): void {
diff --git a/tests/lib/UpdaterTest.php b/tests/lib/UpdaterTest.php
index da48e581fbc..81babee7029 100644
--- a/tests/lib/UpdaterTest.php
+++ b/tests/lib/UpdaterTest.php
@@ -12,10 +12,13 @@ use OC\IntegrityCheck\Checker;
use OC\Updater;
use OCP\IAppConfig;
use OCP\IConfig;
+use OCP\ServerVersion;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
class UpdaterTest extends TestCase {
+ /** @var ServerVersion|MockObject */
+ private $serverVersion;
/** @var IConfig|MockObject */
private $config;
/** @var IAppConfig|MockObject */
@@ -31,23 +34,15 @@ class UpdaterTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->config = $this->getMockBuilder(IConfig::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->appConfig = $this->getMockBuilder(IAppConfig::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->logger = $this->getMockBuilder(LoggerInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->checker = $this->getMockBuilder(Checker::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->installer = $this->getMockBuilder(Installer::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $this->serverVersion = $this->createMock(ServerVersion::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
+ $this->checker = $this->createMock(Checker::class);
+ $this->installer = $this->createMock(Installer::class);
$this->updater = new Updater(
+ $this->serverVersion,
$this->config,
$this->appConfig,
$this->checker,
diff --git a/tests/lib/UtilTest.php b/tests/lib/UtilTest.php
index 064b73d0b7e..c1dea8d5423 100644
--- a/tests/lib/UtilTest.php
+++ b/tests/lib/UtilTest.php
@@ -24,16 +24,6 @@ class UtilTest extends \Test\TestCase {
}
}
- public function testGetVersionString(): void {
- $version = \OC_Util::getVersionString();
- $this->assertTrue(is_string($version));
- }
-
- public function testGetEditionString(): void {
- $edition = \OC_Util::getEditionString();
- $this->assertTrue(is_string($edition));
- }
-
public function testSanitizeHTML(): void {
$badArray = [
'While it is unusual to pass an array',