Skip to content

Commit

Permalink
Validation for new storage key location
Browse files Browse the repository at this point in the history
Extra validation required if the new storage
key location is being provided to the command.
When is_dir returns null it wasn't captured by
the command. And hence the command was executed
successfully. This change would help to prevent
such scenario. If is_dir returns null throw exception.

Signed-off-by: Sujith H <[email protected]>
  • Loading branch information
sharidas committed Jan 22, 2018
1 parent 1dc2232 commit d32f47d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion core/Command/Encryption/ChangeKeyStorageRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ protected function moveAllKeys($oldRoot, $newRoot, OutputInterface $output) {
* @throws \Exception
*/
protected function prepareNewRoot($newRoot) {
if ($this->rootView->is_dir($newRoot) === false) {
$validateNewRootDir = $this->rootView->is_dir($newRoot);
if (($validateNewRootDir === false) or ($validateNewRootDir === null)) {
throw new \Exception("New root folder doesn't exist. Please create the folder or check the permissions and try again.");
}

Expand Down
21 changes: 20 additions & 1 deletion tests/Core/Command/Encryption/ChangeKeyStorageRootTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,29 @@ public function testPrepareNewRootException($dirExists, $couldCreateFile) {
public function dataTestPrepareNewRootException() {
return [
[true, false],
[false, true]
[false, true],
[null, true]
];
}

public function nulldir() {
return [
[null]
];
}

/**
* @dataProvider nulldir
* @expectedException \Exception
* @expectedExceptionMessage New root folder doesn't exist. Please create the folder or check the permissions and try again.
* @param $dirExists
*/
public function testPrepareNewRootExceptionForNullDir($dirExists) {
$this->view->expects($this->once())->method('is_dir')->with('../../newRoot')
->willReturn($dirExists);
$this->invokePrivate($this->changeKeyStorageRoot, 'prepareNewRoot', ['../../newRoot']);
}

/**
* @dataProvider dataTestMoveSystemKeys
*
Expand Down

0 comments on commit d32f47d

Please sign in to comment.