2014-03-14 16:03:18 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
2016-05-19 10:38:52 +03:00
|
|
|
namespace Test;
|
|
|
|
|
2014-03-14 16:03:18 +04:00
|
|
|
/**
|
|
|
|
* Tests for server check functions
|
2015-11-25 18:58:54 +03:00
|
|
|
*
|
|
|
|
* @group DB
|
2014-03-14 16:03:18 +04:00
|
|
|
*/
|
2016-05-19 10:38:52 +03:00
|
|
|
class UtilCheckServerTest extends \Test\TestCase {
|
2014-03-14 16:03:18 +04:00
|
|
|
private $datadir;
|
|
|
|
|
2014-09-08 16:56:11 +04:00
|
|
|
/**
|
|
|
|
* @param array $systemOptions
|
2020-08-11 22:32:18 +03:00
|
|
|
* @return \OC\SystemConfig | \PHPUnit\Framework\MockObject\MockObject
|
2014-09-08 16:56:11 +04:00
|
|
|
*/
|
|
|
|
protected function getConfig($systemOptions) {
|
|
|
|
$systemOptions['datadirectory'] = $this->datadir;
|
2014-09-08 17:05:57 +04:00
|
|
|
$systemOptions['appstoreenabled'] = false; //it's likely that there is no app folder we can write in
|
2017-03-18 01:37:48 +03:00
|
|
|
$config = $this->getMockBuilder('\OC\SystemConfig')
|
2014-09-08 16:56:11 +04:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$config->expects($this->any())
|
2017-03-18 01:37:48 +03:00
|
|
|
->method('getValue')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function ($key, $default) use ($systemOptions) {
|
2014-09-08 16:56:11 +04:00
|
|
|
return isset($systemOptions[$key]) ? $systemOptions[$key] : $default;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2014-09-08 16:56:11 +04:00
|
|
|
return $config;
|
|
|
|
}
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2014-11-11 00:59:50 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2015-12-18 13:19:53 +03:00
|
|
|
$this->datadir = \OC::$server->getTempManager()->getTemporaryFolder();
|
2014-03-14 16:03:18 +04:00
|
|
|
|
|
|
|
file_put_contents($this->datadir . '/.ocdata', '');
|
2014-09-08 17:05:57 +04:00
|
|
|
\OC::$server->getSession()->set('checkServer_succeeded', false);
|
2014-03-14 16:03:18 +04:00
|
|
|
}
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function tearDown(): void {
|
2014-03-14 16:03:18 +04:00
|
|
|
// clean up
|
|
|
|
@unlink($this->datadir . '/.ocdata');
|
2014-11-11 00:59:50 +03:00
|
|
|
parent::tearDown();
|
2014-03-14 16:03:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that checkServer() returns no errors in the regular case.
|
|
|
|
*/
|
|
|
|
public function testCheckServer() {
|
2020-03-26 11:30:18 +03:00
|
|
|
$result = \OC_Util::checkServer($this->getConfig([
|
2014-09-08 16:56:11 +04:00
|
|
|
'installed' => true
|
2020-03-26 11:30:18 +03:00
|
|
|
]));
|
2014-03-14 16:03:18 +04:00
|
|
|
$this->assertEmpty($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that checkServer() does not check the data dir validity
|
|
|
|
* when the server is not installed yet (else the setup cannot
|
|
|
|
* be run...)
|
|
|
|
*/
|
|
|
|
public function testCheckServerSkipDataDirValidityOnSetup() {
|
|
|
|
// simulate old version that didn't have it
|
|
|
|
unlink($this->datadir . '/.ocdata');
|
|
|
|
|
|
|
|
// even though ".ocdata" is missing, the error isn't
|
|
|
|
// triggered to allow setup to run
|
2020-03-26 11:30:18 +03:00
|
|
|
$result = \OC_Util::checkServer($this->getConfig([
|
2014-09-08 16:56:11 +04:00
|
|
|
'installed' => false
|
2020-03-26 11:30:18 +03:00
|
|
|
]));
|
2014-03-14 16:03:18 +04:00
|
|
|
$this->assertEmpty($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that checkServer() does not check the data dir validity
|
|
|
|
* when an upgrade is required (else the upgrade cannot be
|
|
|
|
* performed...)
|
|
|
|
*/
|
|
|
|
public function testCheckServerSkipDataDirValidityOnUpgrade() {
|
|
|
|
// simulate old version that didn't have it
|
|
|
|
unlink($this->datadir . '/.ocdata');
|
|
|
|
|
|
|
|
$session = \OC::$server->getSession();
|
|
|
|
$oldCurrentVersion = $session->get('OC_Version');
|
|
|
|
|
|
|
|
// upgrade condition to simulate needUpgrade() === true
|
2020-03-26 11:30:18 +03:00
|
|
|
$session->set('OC_Version', [6, 0, 0, 2]);
|
2014-03-14 16:03:18 +04:00
|
|
|
|
|
|
|
// even though ".ocdata" is missing, the error isn't
|
|
|
|
// triggered to allow for upgrade
|
2020-03-26 11:30:18 +03:00
|
|
|
$result = \OC_Util::checkServer($this->getConfig([
|
2014-09-08 16:56:11 +04:00
|
|
|
'installed' => true,
|
|
|
|
'version' => '6.0.0.1'
|
2020-03-26 11:30:18 +03:00
|
|
|
]));
|
2014-03-14 16:03:18 +04:00
|
|
|
$this->assertEmpty($result);
|
|
|
|
|
|
|
|
// restore versions
|
|
|
|
$session->set('OC_Version', $oldCurrentVersion);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that checkDataDirectoryValidity returns no error
|
|
|
|
* when ".ocdata" is present.
|
|
|
|
*/
|
|
|
|
public function testCheckDataDirValidity() {
|
|
|
|
$result = \OC_Util::checkDataDirectoryValidity($this->datadir);
|
|
|
|
$this->assertEmpty($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-08 16:56:11 +04:00
|
|
|
* Test that checkDataDirectoryValidity and checkServer
|
2014-03-14 16:03:18 +04:00
|
|
|
* both return an error when ".ocdata" is missing.
|
|
|
|
*/
|
|
|
|
public function testCheckDataDirValidityWhenFileMissing() {
|
|
|
|
unlink($this->datadir . '/.ocdata');
|
|
|
|
$result = \OC_Util::checkDataDirectoryValidity($this->datadir);
|
|
|
|
$this->assertEquals(1, count($result));
|
|
|
|
|
2020-03-26 11:30:18 +03:00
|
|
|
$result = \OC_Util::checkServer($this->getConfig([
|
2014-09-08 16:56:11 +04:00
|
|
|
'installed' => true,
|
2015-12-18 17:26:54 +03:00
|
|
|
'version' => implode('.', \OCP\Util::getVersion())
|
2020-03-26 11:30:18 +03:00
|
|
|
]));
|
2014-09-08 16:56:11 +04:00
|
|
|
$this->assertCount(1, $result);
|
2014-03-14 16:03:18 +04:00
|
|
|
}
|
|
|
|
|
2014-09-08 17:05:57 +04:00
|
|
|
/**
|
|
|
|
* Tests that no error is given when the datadir is writable
|
|
|
|
*/
|
|
|
|
public function testDataDirWritable() {
|
2020-03-26 11:30:18 +03:00
|
|
|
$result = \OC_Util::checkServer($this->getConfig([
|
2014-09-08 17:05:57 +04:00
|
|
|
'installed' => true,
|
2015-12-18 17:26:54 +03:00
|
|
|
'version' => implode('.', \OCP\Util::getVersion())
|
2020-03-26 11:30:18 +03:00
|
|
|
]));
|
2014-09-08 17:05:57 +04:00
|
|
|
$this->assertEmpty($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests an error is given when the datadir is not writable
|
|
|
|
*/
|
|
|
|
public function testDataDirNotWritable() {
|
2016-06-07 17:20:07 +03:00
|
|
|
$this->markTestSkipped('TODO: Disable because fails on drone');
|
2014-11-05 18:47:27 +03:00
|
|
|
|
2014-09-08 17:05:57 +04:00
|
|
|
chmod($this->datadir, 0300);
|
2020-03-26 11:30:18 +03:00
|
|
|
$result = \OC_Util::checkServer($this->getConfig([
|
2014-09-08 17:05:57 +04:00
|
|
|
'installed' => true,
|
2015-12-18 17:26:54 +03:00
|
|
|
'version' => implode('.', \OCP\Util::getVersion())
|
2020-03-26 11:30:18 +03:00
|
|
|
]));
|
2014-09-08 17:05:57 +04:00
|
|
|
$this->assertCount(1, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests no error is given when the datadir is not writable during setup
|
|
|
|
*/
|
|
|
|
public function testDataDirNotWritableSetup() {
|
|
|
|
chmod($this->datadir, 0300);
|
2020-03-26 11:30:18 +03:00
|
|
|
$result = \OC_Util::checkServer($this->getConfig([
|
2014-09-08 17:05:57 +04:00
|
|
|
'installed' => false,
|
2015-12-18 17:26:54 +03:00
|
|
|
'version' => implode('.', \OCP\Util::getVersion())
|
2020-03-26 11:30:18 +03:00
|
|
|
]));
|
2014-09-08 17:05:57 +04:00
|
|
|
chmod($this->datadir, 0700); //needed for cleanup
|
|
|
|
$this->assertEmpty($result);
|
|
|
|
}
|
2014-03-14 16:03:18 +04:00
|
|
|
}
|