diff --git a/src/Request.php b/src/Request.php index 1109c643..67cd093b 100755 --- a/src/Request.php +++ b/src/Request.php @@ -35,6 +35,10 @@ class Request { private $phpMinorVersion = '4'; /** @var int|null */ private $phpReleaseVersion = '0'; + /** @var int|null */ + private $category = null; + /** @var int|null */ + private $isSubscriber = null; /** * @param string $versionString @@ -137,6 +141,20 @@ public function getPHPReleaseVersion() { return $this->phpReleaseVersion; } + /** + * @return int|null + */ + public function getCategory() { + return $this->category; + } + + /** + * @return int|null + */ + public function isSubscriber() { + return $this->isSubscriber; + } + /** * @param string $versionString * @param array $server @@ -145,34 +163,13 @@ public function getPHPReleaseVersion() { private function readVersion($versionString, array $server) { $version = explode('x', $versionString); - if (count($version) === 9 || count($version) === 12) { - $this->majorVersion = (int)$version['0']; - $this->minorVersion = (int)$version['1']; - $this->maintenanceVersion = (int)$version['2']; - $this->revisionVersion = (int)$version['3']; - $this->installationMtime = (float)$version['4']; - $this->lastCheck = (int)$version['5']; - $this->channel = $version['6']; - $this->edition = $version['7']; - $this->build = explode(' ', substr(urldecode($version['8']), 0, strrpos(urldecode($version['8']), ' ')))[0]; - $this->remoteAddress = (isset($server['REMOTE_ADDR']) ? $server['REMOTE_ADDR'] : ''); - - # TODO remove this once there are no Nextcloud 11.0 betas out there - if ($this->majorVersion === 11 && - $this->minorVersion === 0 && - $this->maintenanceVersion === 0 && - in_array($this->revisionVersion, array(2, 4, 5)) && - $this->channel === '' - ) { - $this->channel = 'stable'; - } - - // starting with nextcloud 17 there is no production channel anymore - if ($this->channel === 'production') { - $this->channel = 'stable'; - } - - if(count($version) === 12) { + $this->remoteAddress = (isset($server['REMOTE_ADDR']) ? $server['REMOTE_ADDR'] : ''); + switch (count($version)) { + case 14: + $this->isSubscriber = (int) $version[13]; + $this->category = (int) $version[12]; + // no break + case 12: if($version['9'] !== '') { $this->phpMajorVersion = (int)$version['9']; } @@ -182,17 +179,32 @@ private function readVersion($versionString, array $server) { if($version['11'] !== '') { $this->phpReleaseVersion = (int)$version['11']; } - } - - // Nextcloud 11 at least runs on PHP 5.6 (so if there is PHP 5.4 and Nextcloud 11 detected we set it to PHP 5.6) - if ($this->majorVersion === 11 && - $this->phpMajorVersion === '5' && - $this->phpMinorVersion === '4') { + // no break + case 9: + $this->majorVersion = (int)$version['0']; + $this->minorVersion = (int)$version['1']; + $this->maintenanceVersion = (int)$version['2']; + $this->revisionVersion = (int)$version['3']; + $this->installationMtime = (float)$version['4']; + $this->lastCheck = (int)$version['5']; + $this->channel = $version['6']; + $this->edition = $version['7']; + $this->build = explode(' ', substr(urldecode($version['8']), 0, strrpos(urldecode($version['8']), ' ')))[0]; + // starting with nextcloud 17 there is no production channel anymore + if ($this->channel === 'production') { + $this->channel = 'stable'; + } + break; + default: + throw new UnsupportedReleaseException; + } - $this->phpMinorVersion = '6'; - } - } else { - throw new UnsupportedReleaseException; + // Nextcloud 11 at least runs on PHP 5.6 (so if there is PHP 5.4 and Nextcloud 11 detected we set it to PHP 5.6) + if ($this->majorVersion === 11 && + $this->phpMajorVersion === '5' && + $this->phpMinorVersion === '4' + ) { + $this->phpMinorVersion = '6'; } } } diff --git a/tests/integration/features/beta.feature b/tests/integration/features/beta.feature index f5939eae..5cd0808f 100644 --- a/tests/integration/features/beta.feature +++ b/tests/integration/features/beta.feature @@ -725,3 +725,26 @@ Feature: Testing the update scenario of beta releases AU45erykEtmF8RqZR5wTPBOc4kjrryTnKhuNsEPKtEjQlxpI5/PdV5fE+eegTGeh EGDLJyXxKje9pcfLoid0xQ== """ + + Scenario: Updating latest Nextcloud 26 on the beta channel with instance category + Given There is a release with channel "beta" + And The received version is "26.0.3.2" + And The received PHP version is "8.1.0" + And the installation mtime is "11" + And the instance category is 2 + And the instance has no subscription + When The request is sent + Then The response is non-empty + And Update to version "27.0.0.8" is available + And URL to download is "https://download.nextcloud.com/server/releases/nextcloud-27.0.0.zip" + And URL to documentation is "https://docs.nextcloud.com/server/27/admin_manual/maintenance/upgrade.html" + And EOL is set to "0" + And The signature is + """ + wUz0K6QLON0SXaz5wBzJ2XW7GeYTdqGP0iJmGaGvIGT3D2+ftmHY17nCTYKcr3I5 + hh/4FKfsUaoP2Ak37GR1KMLyli5hARZRApR5powznf504atImcY51LuMvXE9CgIN + yM1oJPehacjYsrJzjMizK4aTHepz+zVeWo8SlBiKXwB9Ntqhrt63mHnzMJb7B6vY + 6N7YkvKlPMCSk3ttIgIH04J+CMYZWzW0UVRn2NV2ID8e22+tiskWNVK6uvTszIX5 + AU45erykEtmF8RqZR5wTPBOc4kjrryTnKhuNsEPKtEjQlxpI5/PdV5fE+eegTGeh + EGDLJyXxKje9pcfLoid0xQ== + """ diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 8f0fe534..9b442e55 100755 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -31,6 +31,10 @@ class FeatureContext implements Context, SnippetAcceptingContext { private $phpMinorVersion = ''; /** @var string */ private $phpReleaseVersion = ''; + /** @var int */ + private $categoryId = ''; + /** @var bool */ + private $subscriptionRegistered = false; /** @var string */ private $result = ''; /** @var array */ @@ -83,6 +87,30 @@ public function theInstallationMtimeIs($time) { $this->installationMtime = $time; } + /** + * @Given the instance category is :categoryId + */ + public function theInstanceCategoryIs($categoryId) + { + $this->categoryId = $categoryId; + } + + /** + * @Given the instance has a subscription + */ + public function theInstanceHasASubscription() + { + $this->subscriptionRegistered = true; + } + + /** + * @Given the instance has no subscription + */ + public function theInstanceHasNoSubscription() + { + $this->subscriptionRegistered = false; + } + /** * Builds the version to sent * @@ -101,12 +129,17 @@ private function buildVersionToSend() { $this->build, ]; - if($this->phpMajorVersion !== '') { + if ($this->phpMajorVersion !== '') { $parameters[] = $this->phpMajorVersion; $parameters[] = $this->phpMinorVersion; $parameters[] = $this->phpReleaseVersion; } + if ($this->categoryId) { + $parameters[] = $this->categoryId; + $parameters[] = (int) $this->subscriptionRegistered; + } + return implode('x', $parameters); } diff --git a/tests/integration/features/stable.feature b/tests/integration/features/stable.feature index 8a8f9b97..929c6417 100644 --- a/tests/integration/features/stable.feature +++ b/tests/integration/features/stable.feature @@ -120,27 +120,6 @@ Feature: Testing the update scenario of stable releases vbaIJ8CiZnKdMBDAdXAVMA== """ - Scenario: Updating a non-staged outdated Nextcloud 11.0.0 beta on the empty channel - will use the stable channel then - Given There is a release with channel "" - And The received version is "11.0.0.2" - And the installation mtime is "20" - And The received PHP version is "5.6.0" - When The request is sent - Then The response is non-empty - And Update to version "12.0.13.2" is available - And URL to download is "https://download.nextcloud.com/server/releases/nextcloud-12.0.13.zip" - And URL to documentation is "https://docs.nextcloud.com/server/12/admin_manual/maintenance/upgrade.html" - And EOL is set to "1" - And The signature is - """ - jZbAdJ9cHzBcw7BatJoX7/0Nv9NdecbsR4wEnRBbWI/EmAQ09HoMmmC1xiY88ME5 - lvHlcEgF0sVTx6tdg4LvqAH2ze34LhzxgIu7mS1tAHIZ81elGhv66VuRv17QYVs1 - 7QQySikKMprI+mzdTjIf3rloc97lpm9ynQ+6vizwdxhZ0w5r4Gl85ni52MpeN1Zd - Sx/Z9LJ0bCIO9C+E6kyQvjI7Q7A+WpMF1SiQL2RJsLJERtV4BP8izVuZQ/hI9NDj - rdZAAiMKh8jB0atDNbxu24dWI2Ie7MvnzadL6Ax9+qIWUzlZIqX9yXgFVE2RsGVS - vbaIJ8CiZnKdMBDAdXAVMA== - """ - Scenario: Updating an outdated Nextcloud 13.0.0 on the stable channel Given There is a release with channel "stable" And The received version is "13.0.0.8" @@ -1021,3 +1000,25 @@ Feature: Testing the update scenario of stable releases AU45erykEtmF8RqZR5wTPBOc4kjrryTnKhuNsEPKtEjQlxpI5/PdV5fE+eegTGeh EGDLJyXxKje9pcfLoid0xQ== """ + Scenario: Updating Nextcloud 27 to latest 27 on the stable channel with categoryId + Given There is a release with channel "stable" + And The received version is "27.0.0.7" + And The received PHP version is "8.1.0" + And the installation mtime is "71" + And the instance category is 5 + And the instance has a subscription + When The request is sent + Then The response is non-empty + And Update to version "27.0.0.8" is available + And URL to download is "https://download.nextcloud.com/server/releases/nextcloud-27.0.0.zip" + And URL to documentation is "https://docs.nextcloud.com/server/27/admin_manual/maintenance/upgrade.html" + And EOL is set to "0" + And The signature is + """ + wUz0K6QLON0SXaz5wBzJ2XW7GeYTdqGP0iJmGaGvIGT3D2+ftmHY17nCTYKcr3I5 + hh/4FKfsUaoP2Ak37GR1KMLyli5hARZRApR5powznf504atImcY51LuMvXE9CgIN + yM1oJPehacjYsrJzjMizK4aTHepz+zVeWo8SlBiKXwB9Ntqhrt63mHnzMJb7B6vY + 6N7YkvKlPMCSk3ttIgIH04J+CMYZWzW0UVRn2NV2ID8e22+tiskWNVK6uvTszIX5 + AU45erykEtmF8RqZR5wTPBOc4kjrryTnKhuNsEPKtEjQlxpI5/PdV5fE+eegTGeh + EGDLJyXxKje9pcfLoid0xQ== + """ diff --git a/tests/unit/RequestTest.php b/tests/unit/RequestTest.php index d9ebb86e..ca9b771c 100755 --- a/tests/unit/RequestTest.php +++ b/tests/unit/RequestTest.php @@ -20,6 +20,11 @@ public function testRequest() { $this->assertSame('', $request->getEdition()); $this->assertSame('2015-10-19T18:44:30', $request->getBuild()); $this->assertSame('', $request->getRemoteAddress()); + $this->assertNull($request->getPHPMajorVersion()); + $this->assertNull($request->getPHPMinorVersion()); + $this->assertNull($request->getPHPReleaseVersion()); + $this->assertNull($request->getCategory()); + $this->assertNull($request->isSubscriber()); } public function testRequestPHP() { @@ -37,6 +42,27 @@ public function testRequestPHP() { $this->assertSame(5, $request->getPHPMajorVersion()); $this->assertSame(6, $request->getPHPMinorVersion()); $this->assertSame(36, $request->getPHPReleaseVersion()); + $this->assertNull($request->getCategory()); + $this->assertNull($request->isSubscriber()); + } + + public function testRequestWithCategory() { + $request = new Request('8x2x0x12x1448709225.0768x1448709281xtestingxx2015-10-19T18:44:30+00:00%208ee2009de36e01a9866404f07722892f84c16e3ex5x6x36x3x1', []); + $this->assertSame(8, $request->getMajorVersion()); + $this->assertSame(2, $request->getMinorVersion()); + $this->assertSame(0, $request->getMaintenanceVersion()); + $this->assertSame(12, $request->getRevisionVersion()); + $this->assertSame(1448709225.0768, $request->getInstallationMtime()); + $this->assertSame(1448709281, $request->getLastCheck()); + $this->assertSame('testing', $request->getChannel()); + $this->assertSame('', $request->getEdition()); + $this->assertSame('2015-10-19T18:44:30', $request->getBuild()); + $this->assertSame('', $request->getRemoteAddress()); + $this->assertSame(5, $request->getPHPMajorVersion()); + $this->assertSame(6, $request->getPHPMinorVersion()); + $this->assertSame(36, $request->getPHPReleaseVersion()); + $this->assertSame(3, $request->getCategory()); + $this->assertTrue($request->isSubscriber()); } /**