Skip to content

Commit b7f45ac

Browse files
committed
test(updater): add tests to new error handling in getUpdateServerResponse
Signed-off-by: Josh Richards <josh.t.richards@gmail.com>
1 parent 0e7f76f commit b7f45ac

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

tests/features/bootstrap/FeatureContext.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function theCliUpdaterIsRun() {
204204
copy($this->buildDir . 'updater.phar', $this->serverDir . 'nextcloud/updater/updater');
205205
chdir($this->serverDir . 'nextcloud/updater');
206206
chmod($this->serverDir . 'nextcloud/updater/updater', 0755);
207-
exec('./updater -n', $output, $returnCode);
207+
exec('./updater -n 2>&1', $output, $returnCode);
208208

209209
// sleep to let the opcache do it's work and invalidate the status.php
210210
sleep(5);
@@ -564,4 +564,54 @@ public function thereIsAConfigForASecondaryAppsDirectoryCalled($name) {
564564
public function phpIsAtLeastInVersion($version) {
565565
$this->skipIt = in_array(version_compare($version, PHP_VERSION, '<'), [0, false], true);
566566
}
567+
568+
/**
569+
* @Given the update server returns HTTP status :statusCode
570+
*/
571+
public function theUpdateServerReturnsHttpStatus(int $statusCode) {
572+
if ($this->skipIt) {
573+
return;
574+
}
575+
576+
$this->runUpdateServer();
577+
578+
$content = '<?php http_response_code(' . $statusCode . '); echo "Server Error";';
579+
file_put_contents($this->updateServerDir . 'index.php', $content);
580+
}
581+
582+
/**
583+
* @Given the update server returns invalid XML
584+
*/
585+
public function theUpdateServerReturnsInvalidXml() {
586+
if ($this->skipIt) {
587+
return;
588+
}
589+
590+
$this->runUpdateServer();
591+
592+
$content = '<?php header("Content-Type: application/xml"); echo "this is not valid xml <><><";';
593+
file_put_contents($this->updateServerDir . 'index.php', $content);
594+
}
595+
596+
/**
597+
* @Given the update server is unreachable
598+
*/
599+
public function theUpdateServerIsUnreachable() {
600+
if ($this->skipIt) {
601+
return;
602+
}
603+
604+
// Point updater.server.url at a port with nothing listening
605+
$configFile = $this->serverDir . 'nextcloud/config/config.php';
606+
$content = file_get_contents($configFile);
607+
$content = preg_replace(
608+
'!\$CONFIG\s*=\s*array\s*\(!',
609+
"\$CONFIG = array(\n 'updater.server.url' => 'http://localhost:8871/',",
610+
$content
611+
);
612+
file_put_contents($configFile, $content);
613+
614+
// Intentionally do NOT start any server on port 8871
615+
}
567616
}
617+

tests/features/cli.feature

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,33 @@ Feature: CLI updater
8484
And the installed version should be 26.0.0
8585
And maintenance mode should be off
8686
And upgrade is not required
87+
88+
Scenario: Update server returns HTTP 500 - 26.0.0
89+
Given the current installed version is 26.0.0
90+
And the update server returns HTTP status 500
91+
When the CLI updater is run
92+
Then the return code should not be 0
93+
And the output should contain "Update server returned unexpected HTTP status 500"
94+
And the installed version should be 26.0.0
95+
And maintenance mode should be off
96+
And upgrade is not required
97+
98+
Scenario: Update server returns invalid XML - 26.0.0
99+
Given the current installed version is 26.0.0
100+
And the update server returns invalid XML
101+
When the CLI updater is run
102+
Then the return code should not be 0
103+
And the output should contain "Could not parse updater server XML response"
104+
And the installed version should be 26.0.0
105+
And maintenance mode should be off
106+
And upgrade is not required
107+
108+
Scenario: Update server is unreachable - 26.0.0
109+
Given the current installed version is 26.0.0
110+
And the update server is unreachable
111+
When the CLI updater is run
112+
Then the return code should not be 0
113+
And the output should contain "Could not do request to updater server"
114+
And the installed version should be 26.0.0
115+
And maintenance mode should be off
116+
And upgrade is not required

0 commit comments

Comments
 (0)