コード例 #1
0
 public function testJsonSerialization()
 {
     $backend = $this->getMockBuilder('\\OCA\\Files_External\\Lib\\Backend\\Backend')->disableOriginalConstructor()->getMock();
     $parameter = $this->getMockBuilder('\\OCA\\Files_External\\Lib\\DefinitionParameter')->disableOriginalConstructor()->getMock();
     $parameter->expects($this->once())->method('getType')->willReturn(1);
     $backend->expects($this->once())->method('getParameters')->willReturn(['secure' => $parameter]);
     $backend->method('getIdentifier')->willReturn('storage::identifier');
     $authMech = $this->getMockBuilder('\\OCA\\Files_External\\Lib\\Auth\\AuthMechanism')->disableOriginalConstructor()->getMock();
     $authMech->method('getIdentifier')->willReturn('auth::identifier');
     $storageConfig = new StorageConfig(1);
     $storageConfig->setMountPoint('test');
     $storageConfig->setBackend($backend);
     $storageConfig->setAuthMechanism($authMech);
     $storageConfig->setBackendOptions(['user' => 'test', 'password' => 'password123', 'secure' => '1']);
     $storageConfig->setPriority(128);
     $storageConfig->setApplicableUsers(['user1', 'user2']);
     $storageConfig->setApplicableGroups(['group1', 'group2']);
     $storageConfig->setMountOptions(['preview' => false]);
     $json = $storageConfig->jsonSerialize();
     $this->assertSame(1, $json['id']);
     $this->assertSame('/test', $json['mountPoint']);
     $this->assertSame('storage::identifier', $json['backend']);
     $this->assertSame('auth::identifier', $json['authMechanism']);
     $this->assertSame('test', $json['backendOptions']['user']);
     $this->assertSame('password123', $json['backendOptions']['password']);
     $this->assertSame(true, $json['backendOptions']['secure']);
     $this->assertSame(128, $json['priority']);
     $this->assertSame(['user1', 'user2'], $json['applicableUsers']);
     $this->assertSame(['group1', 'group2'], $json['applicableGroups']);
     $this->assertSame(['preview' => false], $json['mountOptions']);
 }
コード例 #2
0
 /**
  * Copy legacy storage options into the given storage config object.
  *
  * @param StorageConfig $storageConfig storage config to populate
  * @param string $mountType mount type
  * @param string $applicable applicable user or group
  * @param array $storageOptions legacy storage options
  *
  * @return StorageConfig populated storage config
  */
 protected function populateStorageConfigWithLegacyOptions(&$storageConfig, $mountType, $applicable, $storageOptions)
 {
     $storageConfig->setBackendClass($storageOptions['class']);
     $storageConfig->setBackendOptions($storageOptions['options']);
     if (isset($storageOptions['mountOptions'])) {
         $storageConfig->setMountOptions($storageOptions['mountOptions']);
     }
     if (isset($storageOptions['priority'])) {
         $storageConfig->setPriority($storageOptions['priority']);
     }
     if ($mountType === \OC_Mount_Config::MOUNT_TYPE_USER) {
         $applicableUsers = $storageConfig->getApplicableUsers();
         if ($applicable !== 'all') {
             $applicableUsers[] = $applicable;
             $storageConfig->setApplicableUsers($applicableUsers);
         }
     } else {
         if ($mountType === \OC_Mount_Config::MOUNT_TYPE_GROUP) {
             $applicableGroups = $storageConfig->getApplicableGroups();
             $applicableGroups[] = $applicable;
             $storageConfig->setApplicableGroups($applicableGroups);
         }
     }
     return $storageConfig;
 }
コード例 #3
0
ファイル: commandtest.php プロジェクト: farukuzun/core-1
 /**
  * @param $id
  * @param $mountPoint
  * @param $backendClass
  * @param string $applicableIdentifier
  * @param array $config
  * @param array $options
  * @param array $users
  * @param array $groups
  * @return StorageConfig
  */
 protected function getMount($id, $mountPoint, $backendClass, $applicableIdentifier = 'password::password', $config = [], $options = [], $users = [], $groups = [])
 {
     $mount = new StorageConfig($id);
     $mount->setMountPoint($mountPoint);
     $mount->setBackendOptions($config);
     $mount->setMountOptions($options);
     $mount->setApplicableUsers($users);
     $mount->setApplicableGroups($groups);
     return $mount;
 }
コード例 #4
0
 /**
  * Copy legacy storage options into the given storage config object.
  *
  * @param StorageConfig $storageConfig storage config to populate
  * @param string $mountType mount type
  * @param string $applicable applicable user or group
  * @param array $storageOptions legacy storage options
  *
  * @return StorageConfig populated storage config
  */
 protected function populateStorageConfigWithLegacyOptions(&$storageConfig, $mountType, $applicable, $storageOptions)
 {
     $backend = $this->backendService->getBackend($storageOptions['backend']);
     if (!$backend) {
         throw new \UnexpectedValueException('Invalid backend ' . $storageOptions['backend']);
     }
     $storageConfig->setBackend($backend);
     if (isset($storageOptions['authMechanism']) && $storageOptions['authMechanism'] !== 'builtin::builtin') {
         $authMechanism = $this->backendService->getAuthMechanism($storageOptions['authMechanism']);
     } else {
         $authMechanism = $backend->getLegacyAuthMechanism($storageOptions);
         $storageOptions['authMechanism'] = 'null';
         // to make error handling easier
     }
     if (!$authMechanism) {
         throw new \UnexpectedValueException('Invalid authentication mechanism ' . $storageOptions['authMechanism']);
     }
     $storageConfig->setAuthMechanism($authMechanism);
     $storageConfig->setBackendOptions($storageOptions['options']);
     if (isset($storageOptions['mountOptions'])) {
         $storageConfig->setMountOptions($storageOptions['mountOptions']);
     }
     if (!isset($storageOptions['priority'])) {
         $storageOptions['priority'] = $backend->getPriority();
     }
     $storageConfig->setPriority($storageOptions['priority']);
     if ($mountType === \OC_Mount_Config::MOUNT_TYPE_USER) {
         $applicableUsers = $storageConfig->getApplicableUsers();
         if ($applicable !== 'all') {
             $applicableUsers[] = $applicable;
             $storageConfig->setApplicableUsers($applicableUsers);
         }
     } else {
         if ($mountType === \OC_Mount_Config::MOUNT_TYPE_GROUP) {
             $applicableGroups = $storageConfig->getApplicableGroups();
             $applicableGroups[] = $applicable;
             $storageConfig->setApplicableGroups($applicableGroups);
         }
     }
     return $storageConfig;
 }
コード例 #5
0
ファイル: storageconfigtest.php プロジェクト: samj1912/repo
 public function testJsonSerialization()
 {
     $storageConfig = new StorageConfig(1);
     $storageConfig->setMountPoint('test');
     $storageConfig->setBackendClass('\\OC\\Files\\Storage\\SMB');
     $storageConfig->setBackendOptions(['user' => 'test', 'password' => 'password123']);
     $storageConfig->setPriority(128);
     $storageConfig->setApplicableUsers(['user1', 'user2']);
     $storageConfig->setApplicableGroups(['group1', 'group2']);
     $storageConfig->setMountOptions(['preview' => false]);
     $json = $storageConfig->jsonSerialize();
     $this->assertEquals(1, $json['id']);
     $this->assertEquals('/test', $json['mountPoint']);
     $this->assertEquals('\\OC\\Files\\Storage\\SMB', $json['backendClass']);
     $this->assertEquals('test', $json['backendOptions']['user']);
     $this->assertEquals('password123', $json['backendOptions']['password']);
     $this->assertEquals(128, $json['priority']);
     $this->assertEquals(['user1', 'user2'], $json['applicableUsers']);
     $this->assertEquals(['group1', 'group2'], $json['applicableGroups']);
     $this->assertEquals(['preview' => false], $json['mountOptions']);
 }
コード例 #6
0
 /**
  * @dataProvider applicableStorageProvider
  */
 public function testGetStorageWithApplicable($applicableUsers, $applicableGroups, $isVisible)
 {
     $backend = $this->backendService->getBackend('identifier:\\OCA\\Files_External\\Lib\\Backend\\SMB');
     $authMechanism = $this->backendService->getAuthMechanism('identifier:\\Auth\\Mechanism');
     $storage = new StorageConfig();
     $storage->setMountPoint('mountpoint');
     $storage->setBackend($backend);
     $storage->setAuthMechanism($authMechanism);
     $storage->setBackendOptions(['password' => 'testPassword']);
     $storage->setApplicableUsers($applicableUsers);
     $storage->setApplicableGroups($applicableGroups);
     $newStorage = $this->globalStoragesService->addStorage($storage);
     $storages = $this->service->getAllStorages();
     if ($isVisible) {
         $this->assertEquals(1, count($storages));
         $retrievedStorage = $this->service->getStorage($newStorage->getId());
         $this->assertEquals('/mountpoint', $retrievedStorage->getMountPoint());
     } else {
         $this->assertEquals(0, count($storages));
     }
 }
コード例 #7
0
 /**
  * Update an external storage entry.
  *
  * @param int $id storage id
  * @param string $mountPoint storage mount point
  * @param string $backendClass backend class name
  * @param array $backendOptions backend-specific options
  * @param array $mountOptions mount-specific options
  * @param array $applicableUsers users for which to mount the storage
  * @param array $applicableGroups groups for which to mount the storage
  * @param int $priority priority
  *
  * @return DataResponse
  */
 public function update($id, $mountPoint, $backendClass, $backendOptions, $mountOptions, $applicableUsers, $applicableGroups, $priority)
 {
     $storage = new StorageConfig($id);
     $storage->setMountPoint($mountPoint);
     $storage->setBackendClass($backendClass);
     $storage->setBackendOptions($backendOptions);
     $storage->setMountOptions($mountOptions);
     $storage->setApplicableUsers($applicableUsers);
     $storage->setApplicableGroups($applicableGroups);
     $storage->setPriority($priority);
     $response = $this->validate($storage);
     if (!empty($response)) {
         return $response;
     }
     try {
         $storage = $this->service->updateStorage($storage);
     } catch (NotFoundException $e) {
         return new DataResponse(['message' => (string) $this->l10n->t('Storage with id "%i" not found', array($id))], Http::STATUS_NOT_FOUND);
     }
     $this->updateStorageStatus($storage);
     return new DataResponse($storage, Http::STATUS_OK);
 }
コード例 #8
0
 /**
  * Creates a StorageConfig instance based on array data
  *
  * @param array data
  *
  * @return StorageConfig storage config instance
  */
 protected function makeStorageConfig($data)
 {
     $storage = new StorageConfig();
     if (isset($data['id'])) {
         $storage->setId($data['id']);
     }
     $storage->setMountPoint($data['mountPoint']);
     $storage->setBackendClass($data['backendClass']);
     $storage->setBackendOptions($data['backendOptions']);
     if (isset($data['applicableUsers'])) {
         $storage->setApplicableUsers($data['applicableUsers']);
     }
     if (isset($data['applicableGroups'])) {
         $storage->setApplicableGroups($data['applicableGroups']);
     }
     if (isset($data['priority'])) {
         $storage->setPriority($data['priority']);
     }
     if (isset($data['mountOptions'])) {
         $storage->setMountOptions($data['mountOptions']);
     }
     return $storage;
 }
コード例 #9
0
ファイル: storagesservicetest.php プロジェクト: evanjt/core
 /**
  * Creates a StorageConfig instance based on array data
  *
  * @param array data
  *
  * @return StorageConfig storage config instance
  */
 protected function makeStorageConfig($data)
 {
     $storage = new StorageConfig();
     if (isset($data['id'])) {
         $storage->setId($data['id']);
     }
     $storage->setMountPoint($data['mountPoint']);
     if (!isset($data['backend'])) {
         // data providers are run before $this->backendService is initialised
         // so $data['backend'] can be specified directly
         $data['backend'] = $this->backendService->getBackend($data['backendIdentifier']);
     }
     if (!isset($data['backend'])) {
         throw new \Exception('oops, no backend');
     }
     if (!isset($data['authMechanism'])) {
         $data['authMechanism'] = $this->backendService->getAuthMechanism($data['authMechanismIdentifier']);
     }
     if (!isset($data['authMechanism'])) {
         throw new \Exception('oops, no auth mechanism');
     }
     $storage->setBackend($data['backend']);
     $storage->setAuthMechanism($data['authMechanism']);
     $storage->setBackendOptions($data['backendOptions']);
     if (isset($data['applicableUsers'])) {
         $storage->setApplicableUsers($data['applicableUsers']);
     }
     if (isset($data['applicableGroups'])) {
         $storage->setApplicableGroups($data['applicableGroups']);
     }
     if (isset($data['priority'])) {
         $storage->setPriority($data['priority']);
     }
     if (isset($data['mountOptions'])) {
         $storage->setMountOptions($data['mountOptions']);
     }
     return $storage;
 }
コード例 #10
0
ファイル: storagesservice.php プロジェクト: loulancn/core
 /**
  * Create a storage from its parameters
  *
  * @param string $mountPoint storage mount point
  * @param string $backendIdentifier backend identifier
  * @param string $authMechanismIdentifier authentication mechanism identifier
  * @param array $backendOptions backend-specific options
  * @param array|null $mountOptions mount-specific options
  * @param array|null $applicableUsers users for which to mount the storage
  * @param array|null $applicableGroups groups for which to mount the storage
  * @param int|null $priority priority
  *
  * @return StorageConfig
  */
 public function createStorage($mountPoint, $backendIdentifier, $authMechanismIdentifier, $backendOptions, $mountOptions = null, $applicableUsers = null, $applicableGroups = null, $priority = null)
 {
     $backend = $this->backendService->getBackend($backendIdentifier);
     if (!$backend) {
         throw new \InvalidArgumentException('Unable to get backend for ' . $backendIdentifier);
     }
     $authMechanism = $this->backendService->getAuthMechanism($authMechanismIdentifier);
     if (!$authMechanism) {
         throw new \InvalidArgumentException('Unable to get authentication mechanism for ' . $authMechanismIdentifier);
     }
     $newStorage = new StorageConfig();
     $newStorage->setMountPoint($mountPoint);
     $newStorage->setBackend($backend);
     $newStorage->setAuthMechanism($authMechanism);
     $newStorage->setBackendOptions($backendOptions);
     if (isset($mountOptions)) {
         $newStorage->setMountOptions($mountOptions);
     }
     if (isset($applicableUsers)) {
         $newStorage->setApplicableUsers($applicableUsers);
     }
     if (isset($applicableGroups)) {
         $newStorage->setApplicableGroups($applicableGroups);
     }
     if (isset($priority)) {
         $newStorage->setPriority($priority);
     }
     return $newStorage;
 }
コード例 #11
0
 /**
  * @dataProvider getUniqueStoragesProvider
  */
 public function testGetUniqueStorages($priority1, $applicableUsers1, $applicableGroups1, $priority2, $applicableUsers2, $applicableGroups2, $expectedPrecedence)
 {
     $backend = $this->backendService->getBackend('identifier:\\OCA\\Files_External\\Lib\\Backend\\SMB');
     $authMechanism = $this->backendService->getAuthMechanism('identifier:\\Auth\\Mechanism');
     $storage1 = new StorageConfig();
     $storage1->setMountPoint('mountpoint');
     $storage1->setBackend($backend);
     $storage1->setAuthMechanism($authMechanism);
     $storage1->setBackendOptions(['password' => 'testPassword']);
     $storage1->setPriority($priority1);
     $storage1->setApplicableUsers($applicableUsers1);
     $storage1->setApplicableGroups($applicableGroups1);
     $storage1 = $this->globalStoragesService->addStorage($storage1);
     $storage2 = new StorageConfig();
     $storage2->setMountPoint('mountpoint');
     $storage2->setBackend($backend);
     $storage2->setAuthMechanism($authMechanism);
     $storage2->setBackendOptions(['password' => 'testPassword']);
     $storage2->setPriority($priority2);
     $storage2->setApplicableUsers($applicableUsers2);
     $storage2->setApplicableGroups($applicableGroups2);
     $storage2 = $this->globalStoragesService->addStorage($storage2);
     $storages = $this->service->getUniqueStorages();
     $this->assertCount(1, $storages);
     if ($expectedPrecedence === 1) {
         $this->assertArrayHasKey($storage1->getID(), $storages);
     } elseif ($expectedPrecedence === 2) {
         $this->assertArrayHasKey($storage2->getID(), $storages);
     }
 }
コード例 #12
0
ファイル: userstoragesservice.php プロジェクト: kenwi/core
 /**
  * Update storage to the configuration
  *
  * @param StorageConfig $updatedStorage storage attributes
  *
  * @return StorageConfig storage config
  * @throws NotFoundException if the given storage does not exist in the config
  */
 public function updateStorage(StorageConfig $updatedStorage)
 {
     $updatedStorage->setApplicableUsers([$this->getUser()->getUID()]);
     return parent::updateStorage($updatedStorage);
 }
コード例 #13
0
 /**
  * @expectedException \OCA\Files_External\NotFoundException
  */
 public function testGetAdminStorage()
 {
     $backend = $this->backendService->getBackend('identifier:\\OCA\\Files_External\\Lib\\Backend\\SMB');
     $authMechanism = $this->backendService->getAuthMechanism('identifier:\\Auth\\Mechanism');
     $storage = new StorageConfig();
     $storage->setMountPoint('mountpoint');
     $storage->setBackend($backend);
     $storage->setAuthMechanism($authMechanism);
     $storage->setBackendOptions(['password' => 'testPassword']);
     $storage->setApplicableUsers([$this->userId]);
     $newStorage = $this->globalStoragesService->addStorage($storage);
     $this->assertInstanceOf('\\OCA\\Files_External\\Lib\\StorageConfig', $this->globalStoragesService->getStorage($newStorage->getId()));
     $this->service->getStorage($newStorage->getId());
 }
コード例 #14
0
ファイル: Create.php プロジェクト: rchicoli/owncloud-core
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $user = $input->getOption('user');
     $mountPoint = $input->getArgument('mount_point');
     $storageIdentifier = $input->getArgument('storage_backend');
     $authIdentifier = $input->getArgument('authentication_backend');
     $configInput = $input->getOption('config');
     $storageBackend = $this->backendService->getBackend($storageIdentifier);
     $authBackend = $this->backendService->getAuthMechanism($authIdentifier);
     if (!Filesystem::isValidPath($mountPoint)) {
         $output->writeln('<error>Invalid mountpoint "' . $mountPoint . '"</error>');
         return 1;
     }
     if (is_null($storageBackend)) {
         $output->writeln('<error>Storage backend with identifier "' . $storageIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
         return 404;
     }
     if (is_null($authBackend)) {
         $output->writeln('<error>Authentication backend with identifier "' . $authIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
         return 404;
     }
     $supportedSchemes = array_keys($storageBackend->getAuthSchemes());
     if (!in_array($authBackend->getScheme(), $supportedSchemes)) {
         $output->writeln('<error>Authentication backend "' . $authIdentifier . '" not valid for storage backend "' . $storageIdentifier . '" (see `occ files_external:backends storage ' . $storageIdentifier . '` for possible values)</error>');
         return 1;
     }
     $config = [];
     foreach ($configInput as $configOption) {
         if (!strpos($configOption, '=')) {
             $output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>');
             return 1;
         }
         list($key, $value) = explode('=', $configOption, 2);
         if (!$this->validateParam($key, $value, $storageBackend, $authBackend)) {
             $output->writeln('<error>Unknown configuration for backends "' . $key . '"</error>');
             return 1;
         }
         $config[$key] = $value;
     }
     $mount = new StorageConfig();
     $mount->setMountPoint($mountPoint);
     $mount->setBackend($storageBackend);
     $mount->setAuthMechanism($authBackend);
     $mount->setBackendOptions($config);
     if ($user) {
         if (!$this->userManager->userExists($user)) {
             $output->writeln('<error>User "' . $user . '" not found</error>');
             return 1;
         }
         $mount->setApplicableUsers([$user]);
     }
     if ($input->getOption('dry')) {
         $this->showMount($user, $mount, $input, $output);
     } else {
         $this->getStorageService($user)->addStorage($mount);
         if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) {
             $output->writeln('<info>Storage created with id ' . $mount->getId() . '</info>');
         } else {
             $output->writeln($mount->getId());
         }
     }
     return 0;
 }
コード例 #15
0
ファイル: Import.php プロジェクト: GitHubUser4234/core
 private function parseData(array $data)
 {
     $mount = new StorageConfig($data['mount_id']);
     $mount->setMountPoint($data['mount_point']);
     $mount->setBackend($this->getBackendByClass($data['storage']));
     $authBackend = $this->backendService->getAuthMechanism($data['authentication_type']);
     $mount->setAuthMechanism($authBackend);
     $mount->setBackendOptions($data['configuration']);
     $mount->setMountOptions($data['options']);
     $mount->setApplicableUsers(isset($data['applicable_users']) ? $data['applicable_users'] : []);
     $mount->setApplicableGroups(isset($data['applicable_groups']) ? $data['applicable_groups'] : []);
     return $mount;
 }