CloudIdManagerTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. namespace Test\Federation;
  22. use OC\Federation\CloudIdManager;
  23. use Test\TestCase;
  24. class CloudIdManagerTest extends TestCase {
  25. /** @var CloudIdManager */
  26. private $cloudIdManager;
  27. protected function setUp() {
  28. parent::setUp();
  29. $this->cloudIdManager = new CloudIdManager();
  30. }
  31. public function cloudIdProvider() {
  32. return [
  33. ['test@example.com', 'test', 'example.com', 'test@example.com'],
  34. ['test@example.com/cloud', 'test', 'example.com/cloud', 'test@example.com/cloud'],
  35. ['test@example.com/cloud/', 'test', 'example.com/cloud', 'test@example.com/cloud'],
  36. ['test@example.com/cloud/index.php', 'test', 'example.com/cloud', 'test@example.com/cloud'],
  37. ['test@example.com@example.com', 'test@example.com', 'example.com', 'test@example.com@example.com'],
  38. ];
  39. }
  40. /**
  41. * @dataProvider cloudIdProvider
  42. *
  43. * @param string $cloudId
  44. * @param string $user
  45. * @param string $remote
  46. */
  47. public function testResolveCloudId($cloudId, $user, $remote, $cleanId) {
  48. $cloudId = $this->cloudIdManager->resolveCloudId($cloudId);
  49. $this->assertEquals($user, $cloudId->getUser());
  50. $this->assertEquals($remote, $cloudId->getRemote());
  51. $this->assertEquals($cleanId, $cloudId->getId());
  52. }
  53. public function invalidCloudIdProvider() {
  54. return [
  55. ['example.com'],
  56. ['test:foo@example.com'],
  57. ['test/foo@example.com']
  58. ];
  59. }
  60. /**
  61. * @dataProvider invalidCloudIdProvider
  62. *
  63. * @param string $cloudId
  64. *
  65. * @expectedException \InvalidArgumentException
  66. */
  67. public function testInvalidCloudId($cloudId) {
  68. $this->cloudIdManager->resolveCloudId($cloudId);
  69. }
  70. public function getCloudIdProvider() {
  71. return [
  72. ['test', 'example.com', 'test@example.com'],
  73. ['test@example.com', 'example.com', 'test@example.com@example.com'],
  74. ];
  75. }
  76. /**
  77. * @dataProvider getCloudIdProvider
  78. *
  79. * @param string $user
  80. * @param string $remote
  81. * @param string $id
  82. */
  83. public function testGetCloudId($user, $remote, $id) {
  84. $cloudId = $this->cloudIdManager->getCloudId($user, $remote);
  85. $this->assertEquals($id, $cloudId->getId());
  86. }
  87. }