public function testScheduleBackupPreconditionsNok()
 {
     $this->backupServiceMock->expects($this->never())->method('executeBackup');
     $this->statusContainerMock->expects($this->once())->method('getOverallStatus')->will($this->returnValue(\OCA\EasyBackup\StatusContainer::ERROR));
     $this->backupServiceMock->expects($this->once())->method('createStatusInformation')->will($this->returnValue($this->statusContainerMock));
     $this->responseFactoryMock->expects($this->once())->method('createJSONBadRequestResponse');
     $this->cut->scheduleBackup();
 }
 public function testIsAllOkError()
 {
     $this->cut->addStatus('test1', \OCA\EasyBackup\StatusContainer::OK, 'loc_test1');
     $this->cut->addStatus('test2', \OCA\EasyBackup\StatusContainer::WARN, 'loc_test2');
     $this->cut->addStatus('test3', \OCA\EasyBackup\StatusContainer::ERROR, 'loc_test3');
     $retVal = $this->cut->getOverallStatus();
     $this->assertEquals(\OCA\EasyBackup\StatusContainer::ERROR, $retVal);
 }
 public function testUploadSshKeyOk()
 {
     $keyFileName = __DIR__ . '/../resource/private_key.txt';
     $uploadedFileName = '/tmp/test_keyfile';
     $this->requestMock->expects($this->once())->method('getUploadedFile')->with($this->equalTo('easybackup_sshKeyFile'))->will($this->returnValue(array('tmp_name' => $keyFileName)));
     $this->configServiceMock->expects($this->once())->method('getPrivateKeyFilename')->will($this->returnValue($uploadedFileName));
     $this->configServiceMock->expects($this->once())->method('getPublicKey')->will($this->returnValue('***MockKey***'));
     $this->backupServiceMock->expects($this->once())->method('validatePrivateSshKey')->will($this->returnValue(true));
     $statusContainer = new StatusContainer();
     $statusContainer->addStatus('privateKeyPresent', StatusContainer::OK, '');
     $this->backupServiceMock->expects($this->any())->method('createStatusInformation')->will($this->returnValue($statusContainer));
     $this->responseFactoryMock->expects($this->exactly(2))->method('createTemplateResponse')->will($this->returnValue($this->templateResponseMock));
     $this->responseFactoryMock->expects($this->at(0))->method('createTemplateResponse')->with($this->equalTo('easybackup'), $this->equalTo('preconditions.inc'), $this->equalTo(array('statusContainer' => $statusContainer)))->will($this->returnValue($this->templateResponseMock));
     $this->responseFactoryMock->expects($this->at(1))->method('createTemplateResponse')->with($this->equalTo('easybackup'), $this->equalTo('publickey.inc'), $this->equalTo(array('statusContainer' => $statusContainer, 'publicKey' => '***MockKey***')))->will($this->returnValue($this->templateResponseMock));
     $this->responseFactoryMock->expects($this->once())->method('createJSONSuccessResponse')->with($this->equalTo(array('preconditionsHtml' => null, 'publicKeyHtml' => null)));
     $this->cut->uploadSshKey();
     $this->assertEquals(file_get_contents($keyFileName), file_get_contents($uploadedFileName));
     $stat = stat($uploadedFileName);
     $this->assertEquals("0600", sprintf("%o", $stat['mode'] & 0777));
     // Only the read/write bit for the owner are set (-rw-------)
     unlink($uploadedFileName);
 }
 /**
  *
  * @return \OCA\EasyBackup\StatusContainer
  */
 public function createStatusInformation()
 {
     $statusContainer = new StatusContainer();
     $statusContainer->addStatus('safeMode', $this->checkSafeModeNotEnabled() ? StatusContainer::OK : StatusContainer::ERROR, $this->trans->t('safe mode may not be enabled'));
     $statusContainer->addStatus('rsyncPresent', $this->checkRsyncPresent() ? StatusContainer::OK : StatusContainer::ERROR, $this->trans->t('rsync must be present in execution path'));
     $statusContainer->addStatus('rsyncExecutable', $this->checkRsyncExecutable() ? StatusContainer::OK : StatusContainer::ERROR, $this->trans->t('rsync binary needs to be executable'));
     // $statusContainer->addStatus('mysqldumpPresent', $this->checkMysqldumpPresent() ? StatusContainer::OK : StatusContainer::WARN, $this->trans->t('mysqldump binary is present in execution path'));
     // $statusContainer->addStatus('mysqldumpExecutable', $this->checkMysqldumpExecutable() ? StatusContainer::OK : StatusContainer::WARN, $this->trans->t('mysqldump binary may be executed'));
     $statusContainer->addStatus('osIsLinux', php_uname('s') == 'Linux' ? StatusContainer::OK : StatusContainer::ERROR, $this->trans->t('operating system must be Linux'));
     $statusContainer->addStatus('cronAvailable', $this->configService->isCronEnabled() ? StatusContainer::OK : StatusContainer::WARN, $this->trans->t('scheduled tasks should be executed via CRON'));
     $statusContainer->addStatus('privateKeyPresent', file_exists($this->configService->getPrivateKeyFilename()) ? StatusContainer::OK : StatusContainer::ERROR, $this->trans->t('private key for backup authentication'));
     $statusContainer->addStatus('hostNameValid', $this->isHostUserNameValid() ? StatusContainer::OK : StatusContainer::ERROR, $this->trans->t('host user name validation'));
     return $statusContainer;
 }
 public function testIndexConfigurationOkBackupOk()
 {
     $statusContainer = new StatusContainer();
     $statusContainer->addStatus('mockStatus', StatusContainer::OK, '');
     $this->backupServiceMock->expects($this->once())->method('createStatusInformation')->will($this->returnValue($statusContainer));
     $this->backupServiceMock->expects($this->atLeastOnce())->method('isLastBackupSuccessful')->will($this->returnValue(true));
     $this->containerMock->expects($this->once())->method('isAdminUser')->will($this->returnValue(true));
     $this->responseFactoryMock->expects($this->once())->method('createTemplateResponse')->with($this->equalTo('easybackup'), $this->equalTo('index'), $this->callback(function ($params) {
         return $params['subTemplate'] == 'restore.inc';
     }));
     $retVal = $this->cut->index();
 }