Skip to content
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
3 changes: 2 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,8 @@ private function downloadArchive(string $fromUrl, string $toLocation): bool {
}

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200 && $httpCode !== 206) {
$isFileUrl = parse_url($fromUrl, PHP_URL_SCHEME) === 'file';
if (!$isFileUrl && $httpCode !== 200 && $httpCode !== 206) {
fclose($fp);
unlink($toLocation);
$this->silentLog('[warn] fail to download archive from ' . $fromUrl . '. Error: ' . $httpCode . ' ' . curl_error($ch));
Expand Down
3 changes: 2 additions & 1 deletion lib/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,8 @@ private function downloadArchive(string $fromUrl, string $toLocation): bool {
}

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200 && $httpCode !== 206) {
$isFileUrl = parse_url($fromUrl, PHP_URL_SCHEME) === 'file';
if (!$isFileUrl && $httpCode !== 200 && $httpCode !== 206) {
fclose($fp);
unlink($toLocation);
$this->silentLog('[warn] fail to download archive from ' . $fromUrl . '. Error: ' . $httpCode . ' ' . curl_error($ch));
Expand Down
78 changes: 78 additions & 0 deletions tests/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,84 @@ public function theCliUpdaterIsRun() {
$this->CLIReturnCode = $returnCode;
}

/**
* @Given the archive for version :version is available locally
*/
public function theArchiveForVersionIsAvailableLocally(string $version): void {
if ($this->skipIt) {
return;
}

$filename = 'nextcloud-' . $version . '.zip';
if (!file_exists($this->tmpDownloadDir . $filename)) {
$fp = fopen($this->tmpDownloadDir . $filename, 'w+');
$url = $this->downloadURL . $filename;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_USERAGENT, 'Nextcloud Updater');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
if (curl_exec($ch) === false) {
throw new \Exception('Curl error: ' . curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200) {
throw new \Exception('Download failed for ' . $url . ' - HTTP code: ' . $httpCode);
}
curl_close($ch);
fclose($fp);
}
}

/**
* @When the CLI updater is run with local file URL for version :version and --no-verify successfully
*/
public function theCliUpdaterIsRunWithLocalFileUrlAndNoVerifySuccessfully(string $version): void {
if ($this->skipIt) {
return;
}

$this->runUpdaterWithLocalFileUrl($version, noVerify: true);

if ($this->CLIReturnCode !== 0) {
throw new Exception('updater failed' . PHP_EOL . implode(PHP_EOL, $this->CLIOutput));
}
}

/**
* @When the CLI updater is run with local file URL for version :version
*/
public function theCliUpdaterIsRunWithLocalFileUrl(string $version): void {
if ($this->skipIt) {
return;
}

$this->runUpdaterWithLocalFileUrl($version, noVerify: false);
}

private function runUpdaterWithLocalFileUrl(string $version, bool $noVerify): void {
$filename = 'nextcloud-' . $version . '.zip';
$fileUrl = 'file://' . $this->tmpDownloadDir . $filename;

if (!file_exists($this->buildDir . 'updater.phar')) {
throw new Exception('updater.phar not available - please build it in advance via "box build -c box.json"');
}

copy($this->buildDir . 'updater.phar', $this->serverDir . 'nextcloud/updater/updater');
chdir($this->serverDir . 'nextcloud/updater');
chmod($this->serverDir . 'nextcloud/updater/updater', 0755);

$args = '-n --url ' . escapeshellarg($fileUrl);
if ($noVerify) {
$args .= ' --no-verify';
}
exec('./updater ' . $args . ' 2>&1', $output, $returnCode);

// sleep to let the opcache do it's work and invalidate the status.php
sleep(5);
$this->CLIOutput = $output;
$this->CLIReturnCode = $returnCode;
}

/**
* @param $version
*/
Expand Down
18 changes: 18 additions & 0 deletions tests/features/cli.feature
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,21 @@ Feature: CLI updater
And the installed version should be 26.0.0
And maintenance mode should be off
And upgrade is not required

Scenario: Update via local file URL with --no-verify - 26.0.0 to 26.0.13
Given the current installed version is 26.0.0
And the archive for version 26.0.13 is available locally
When the CLI updater is run with local file URL for version 26.0.13 and --no-verify successfully
Then the installed version should be 26.0.1
And maintenance mode should be off
And upgrade is not required

Scenario: Update via local file URL without --no-verify fails - 26.0.0 to 26.0.13
Given the current installed version is 26.0.0
And the archive for version 26.0.13 is available locally
When the CLI updater is run with local file URL for version 26.0.13
Then the return code should not be 0
And the output should contain "You need to provide a signature with --signature or skip integrity check with --no-verify."
And the installed version should be 26.0.0
And maintenance mode should be off
And upgrade is not required
Binary file modified updater.phar
Binary file not shown.

This file was deleted.

80 changes: 0 additions & 80 deletions vendor/bamarni/composer-bin-plugin/.github/workflows/tests.yaml

This file was deleted.

61 changes: 0 additions & 61 deletions vendor/bamarni/composer-bin-plugin/.makefile/touch.sh

This file was deleted.

6 changes: 0 additions & 6 deletions vendor/bamarni/composer-bin-plugin/.phive/phars.xml

This file was deleted.

12 changes: 6 additions & 6 deletions vendor/bamarni/composer-bin-plugin/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
},
"require-dev": {
"ext-json": "*",
"composer/composer": "^2.0",
"composer/composer": "^2.2.26",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-phpunit": "^1.1",
"phpunit/phpunit": "^8.5 || ^9.5",
"phpstan/phpstan": "^1.8 || ^2.0",
"phpstan/phpstan-phpunit": "^1.1 || ^2.0",
"phpunit/phpunit": "^8.5 || ^9.6 || ^10.0",
"symfony/console": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0",
"symfony/finder": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0",
"symfony/process": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0"
Expand All @@ -38,9 +38,9 @@
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true,
"ergebnis/composer-normalize": true,
"infection/extension-installer": true
"infection/extension-installer": true,
"phpstan/extension-installer": true
},
"sort-packages": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;

use function count;
use function in_array;
use function sprintf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;

use function chdir;
use function count;
use function file_exists;
Expand All @@ -30,6 +31,7 @@
use function mkdir;
use function putenv;
use function sprintf;

use const GLOB_ONLYDIR;

/**
Expand Down Expand Up @@ -96,6 +98,7 @@ public function isProxyCommand(): bool
public function execute(InputInterface $input, OutputInterface $output): int
{
// Switch to requireComposer() once Composer 2.3 is set as the minimum
// @phpstan-ignore function.alreadyNarrowedType
$composer = method_exists($this, 'requireComposer')
? $this->requireComposer()
: $this->getComposer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Bamarni\Composer\Bin\Command;

use RuntimeException;

use function sprintf;

final class CouldNotCreateNamespaceDir extends RuntimeException
Expand Down
1 change: 1 addition & 0 deletions vendor/bamarni/composer-bin-plugin/src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Bamarni\Composer\Bin\Config;

use Composer\Composer;

use function array_key_exists;
use function array_merge;
use function function_exists;
Expand Down
Loading
Loading