AuthMechanismTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2020-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Files_External\Tests\Auth;
  8. use OCA\Files_External\Lib\Auth\AuthMechanism;
  9. use OCA\Files_External\Lib\Backend\Backend;
  10. use OCA\Files_External\Lib\StorageConfig;
  11. class AuthMechanismTest extends \Test\TestCase {
  12. public function testJsonSerialization() {
  13. $mechanism = $this->getMockBuilder(AuthMechanism::class)
  14. ->setMethods(['jsonSerializeDefinition'])
  15. ->getMock();
  16. $mechanism->expects($this->once())
  17. ->method('jsonSerializeDefinition')
  18. ->willReturn(['foo' => 'bar']);
  19. $mechanism->setScheme('scheme');
  20. $json = $mechanism->jsonSerialize();
  21. $this->assertEquals('bar', $json['foo']);
  22. $this->assertEquals('scheme', $json['scheme']);
  23. }
  24. public function validateStorageProvider() {
  25. return [
  26. [true, 'scheme', true],
  27. [false, 'scheme', false],
  28. [true, 'foobar', true],
  29. [false, 'barfoo', true],
  30. ];
  31. }
  32. /**
  33. * @dataProvider validateStorageProvider
  34. */
  35. public function testValidateStorage($expectedSuccess, $scheme, $definitionSuccess) {
  36. $mechanism = $this->getMockBuilder(AuthMechanism::class)
  37. ->setMethods(['validateStorageDefinition'])
  38. ->getMock();
  39. $mechanism->expects($this->atMost(1))
  40. ->method('validateStorageDefinition')
  41. ->willReturn($definitionSuccess);
  42. $mechanism->setScheme($scheme);
  43. $backend = $this->getMockBuilder(Backend::class)
  44. ->disableOriginalConstructor()
  45. ->getMock();
  46. $backend->expects($this->once())
  47. ->method('getAuthSchemes')
  48. ->willReturn(['scheme' => true, 'foobar' => true]);
  49. $storageConfig = $this->getMockBuilder(StorageConfig::class)
  50. ->disableOriginalConstructor()
  51. ->getMock();
  52. $storageConfig->expects($this->once())
  53. ->method('getBackend')
  54. ->willReturn($backend);
  55. $this->assertEquals($expectedSuccess, $mechanism->validateStorage($storageConfig));
  56. }
  57. }