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

Read instance category on update check #890

Merged
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
88 changes: 50 additions & 38 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it mean we rely on the client to provide reliable subscription information?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes,I implemented it here : nextcloud/server#39264
I didn't find any other way, but we can discuss it if you have some time :)

$this->category = (int) $version[12];
// no break
case 12:
if($version['9'] !== '') {
$this->phpMajorVersion = (int)$version['9'];
}
Expand All @@ -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';
}
}
}
23 changes: 23 additions & 0 deletions tests/integration/features/beta.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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==
"""
35 changes: 34 additions & 1 deletion tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
*
Expand All @@ -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);
}

Expand Down
43 changes: 22 additions & 21 deletions tests/integration/features/stable.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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==
"""
26 changes: 26 additions & 0 deletions tests/unit/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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());
}

/**
Expand Down