-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30281 from owncloud/stable10-c41dda7205aa68f62ff8…
…a5ae3d780715b51f3edd [stable10] When executing the data-fingerprint command a log entry is…
- Loading branch information
Showing
3 changed files
with
78 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?php | ||
/** | ||
* @author Roeland Jago Douma <[email protected]> | ||
* @author Thomas Müller <[email protected]> | ||
* | ||
* @copyright Copyright (c) 2018, ownCloud GmbH | ||
* @license AGPL-3.0 | ||
|
@@ -22,22 +23,30 @@ | |
|
||
use OCP\AppFramework\Utility\ITimeFactory; | ||
use OCP\IConfig; | ||
use OCP\ILogger; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Helper\QuestionHelper; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Question\ConfirmationQuestion; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
|
||
class DataFingerprint extends Command { | ||
|
||
/** @var IConfig */ | ||
protected $config; | ||
private $config; | ||
/** @var ITimeFactory */ | ||
protected $timeFactory; | ||
private $timeFactory; | ||
/** @var ILogger */ | ||
private $logger; | ||
|
||
public function __construct(IConfig $config, | ||
ITimeFactory $timeFactory) { | ||
ITimeFactory $timeFactory, | ||
ILogger $logger ) { | ||
$this->config = $config; | ||
$this->timeFactory = $timeFactory; | ||
$this->logger = $logger; | ||
parent::__construct(); | ||
} | ||
|
||
|
@@ -48,6 +57,23 @@ protected function configure() { | |
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) { | ||
$this->config->setSystemValue('data-fingerprint', md5($this->timeFactory->getTime())); | ||
$io = new SymfonyStyle($input, $output); | ||
$warning = <<<EOD | ||
Setting the data fingerprint will notify desktop and mobile clients that a server backup has been restored. | ||
Users will be prompted to resolve any conflicts between newer and older file versions. | ||
Setting the data fingerprint has a large impact on all connected clients! | ||
Only perform this operation if you really know what you are doing. | ||
EOD; | ||
|
||
$io->warning($warning); | ||
if ($io->confirm('Do you want to set the data fingerprint?', false)) { | ||
$osUser = get_current_user(); | ||
$server = gethostname(); | ||
$fingerprint = md5($this->timeFactory->getTime()); | ||
$this->config->setSystemValue('data-fingerprint', $fingerprint); | ||
$this->logger->info("Data fingerprint was set by $osUser@$server to $fingerprint"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?php | ||
/** | ||
* @author Roeland Jago Douma <[email protected]> | ||
* @author Thomas Müller <[email protected]> | ||
* | ||
* @copyright Copyright (c) 2018, ownCloud GmbH | ||
* @license AGPL-3.0 | ||
|
@@ -24,41 +25,68 @@ | |
use OC\Core\Command\Maintenance\DataFingerprint; | ||
use OCP\AppFramework\Utility\ITimeFactory; | ||
use OCP\IConfig; | ||
use OCP\ILogger; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use Test\TestCase; | ||
|
||
class DataFingerprintTest extends TestCase { | ||
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $config; | ||
/** @var \PHPUnit_Framework_MockObject_MockObject */ | ||
protected $consoleInput; | ||
/** @var \PHPUnit_Framework_MockObject_MockObject */ | ||
protected $consoleOutput; | ||
/** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $timeFactory; | ||
|
||
/** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */ | ||
private $config; | ||
/** @var ITimeFactory | \PHPUnit_Framework_MockObject_MockObject */ | ||
private $timeFactory; | ||
/** @var ILogger | \PHPUnit_Framework_MockObject_MockObject */ | ||
private $logger; | ||
/** @var \Symfony\Component\Console\Command\Command */ | ||
protected $command; | ||
private $command; | ||
/** @var CommandTester */ | ||
private $commandTester; | ||
|
||
public function providesAnswers() { | ||
return [ | ||
'yes' => [true, 'yes'], | ||
'no' => [false, 'no'], | ||
]; | ||
} | ||
|
||
protected function setUp() { | ||
parent::setUp(); | ||
|
||
$this->config = $this->createMock('OCP\IConfig'); | ||
$this->timeFactory = $this->createMock('OCP\AppFramework\Utility\ITimeFactory'); | ||
$this->consoleInput = $this->createMock('Symfony\Component\Console\Input\InputInterface'); | ||
$this->consoleOutput = $this->createMock('Symfony\Component\Console\Output\OutputInterface'); | ||
$this->config = $this->createMock(IConfig::class); | ||
$this->timeFactory = $this->createMock(ITimeFactory::class); | ||
$this->logger = $this->createMock(ILogger::class); | ||
|
||
$this->command = new DataFingerprint($this->config, $this->timeFactory, $this->logger); | ||
$this->commandTester = new CommandTester($this->command); | ||
|
||
/** @var \OCP\IConfig $config */ | ||
$this->command = new DataFingerprint($this->config, $this->timeFactory); | ||
} | ||
|
||
public function testSetFingerPrint() { | ||
$this->timeFactory->expects($this->once()) | ||
/** | ||
* @dataProvider providesAnswers | ||
* @param $expectToLog | ||
* @param $answer | ||
*/ | ||
public function testSetFingerPrint($expectToLog, $answer) { | ||
$expects = $expectToLog ? $this->any() : $this->never(); | ||
$this->timeFactory->expects($expects) | ||
->method('getTime') | ||
->willReturn(42); | ||
$this->config->expects($this->once()) | ||
$this->config->expects($expects) | ||
->method('setSystemValue') | ||
->with('data-fingerprint', md5(42)); | ||
|
||
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); | ||
$osUser = get_current_user(); | ||
$server = gethostname(); | ||
|
||
$this->logger->expects($expects) | ||
->method('info') | ||
->with("Data fingerprint was set by $osUser@$server to a1d0c6e83f027327d8461063f4ac58a6"); | ||
|
||
$this->commandTester->setInputs([$answer]); | ||
$this->commandTester->execute([]); | ||
$output = $this->commandTester->getDisplay(); | ||
$this->assertContains("Do you want to set the data fingerprint?", $output); | ||
|
||
|
||
} | ||
} |