public function testGetStoragesAuthMechanismNotVisible()
 {
     $backend = $this->backendService->getBackend('identifier:\\OCA\\Files_External\\Lib\\Backend\\SMB');
     $backend->method('isVisibleFor')->with($this->service->getVisibilityType())->willReturn(true);
     $authMechanism = $this->backendService->getAuthMechanism('identifier:\\Auth\\Mechanism');
     $authMechanism->expects($this->once())->method('isVisibleFor')->with($this->service->getVisibilityType())->willReturn(false);
     $storage = new StorageConfig(255);
     $storage->setMountPoint('mountpoint');
     $storage->setBackend($backend);
     $storage->setAuthMechanism($authMechanism);
     $storage->setBackendOptions(['password' => 'testPassword']);
     $newStorage = $this->service->addStorage($storage);
     $this->assertCount(1, $this->service->getAllStorages());
     $this->assertEmpty($this->service->getStorages());
 }
 /**
  * Validate storage config
  *
  * @param StorageConfig $storage storage config
  *
  * @return DataResponse|null returns response in case of validation error
  */
 protected function validate(StorageConfig $storage)
 {
     $mountPoint = $storage->getMountPoint();
     if ($mountPoint === '' || $mountPoint === '/') {
         return new DataResponse(array('message' => (string) $this->l10n->t('Invalid mount point')), Http::STATUS_UNPROCESSABLE_ENTITY);
     }
     if ($storage->getBackendOption('objectstore')) {
         // objectstore must not be sent from client side
         return new DataResponse(array('message' => (string) $this->l10n->t('Objectstore forbidden')), Http::STATUS_UNPROCESSABLE_ENTITY);
     }
     /** @var Backend */
     $backend = $storage->getBackend();
     /** @var AuthMechanism */
     $authMechanism = $storage->getAuthMechanism();
     if ($backend->checkDependencies()) {
         // invalid backend
         return new DataResponse(array('message' => (string) $this->l10n->t('Invalid storage backend "%s"', [$backend->getIdentifier()])), Http::STATUS_UNPROCESSABLE_ENTITY);
     }
     if (!$backend->isVisibleFor($this->service->getVisibilityType())) {
         // not permitted to use backend
         return new DataResponse(array('message' => (string) $this->l10n->t('Not permitted to use backend "%s"', [$backend->getIdentifier()])), Http::STATUS_UNPROCESSABLE_ENTITY);
     }
     if (!$authMechanism->isVisibleFor($this->service->getVisibilityType())) {
         // not permitted to use auth mechanism
         return new DataResponse(array('message' => (string) $this->l10n->t('Not permitted to use authentication mechanism "%s"', [$authMechanism->getIdentifier()])), Http::STATUS_UNPROCESSABLE_ENTITY);
     }
     if (!$backend->validateStorage($storage)) {
         // unsatisfied parameters
         return new DataResponse(array('message' => (string) $this->l10n->t('Unsatisfied backend parameters')), Http::STATUS_UNPROCESSABLE_ENTITY);
     }
     if (!$authMechanism->validateStorage($storage)) {
         // unsatisfied parameters
         return new DataResponse(['message' => (string) $this->l10n->t('Unsatisfied authentication mechanism parameters')], Http::STATUS_UNPROCESSABLE_ENTITY);
     }
     return null;
 }