summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2017-02-09 14:54:32 +0100
committerGitHub <noreply@github.com>2017-02-09 14:54:32 +0100
commitbf88060a98ce397768d4afa7935b80751e4533f8 (patch)
tree6baaf10832fa68999eea01ab3df5241fdd3ece0a /tests/lib
parent4a5a3681d921adad8c4cb5bb29180514446ea2b9 (diff)
parent0d8d658b7e3885d92103a6e6248b37863f9acf1b (diff)
downloadnextcloud-server-bf88060a98ce397768d4afa7935b80751e4533f8.tar.gz
nextcloud-server-bf88060a98ce397768d4afa7935b80751e4533f8.zip
Merge pull request #3297 from nextcloud/cloud-id-resolve
Add a single public api for resolving a cloud id to a user and remote and back
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/Federation/CloudIdManagerTest.php99
-rw-r--r--tests/lib/Federation/CloudIdTest.php46
2 files changed, 145 insertions, 0 deletions
diff --git a/tests/lib/Federation/CloudIdManagerTest.php b/tests/lib/Federation/CloudIdManagerTest.php
new file mode 100644
index 00000000000..fe673588bba
--- /dev/null
+++ b/tests/lib/Federation/CloudIdManagerTest.php
@@ -0,0 +1,99 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\Federation;
+
+use OC\Federation\CloudIdManager;
+use Test\TestCase;
+
+class CloudIdManagerTest extends TestCase {
+ /** @var CloudIdManager */
+ private $cloudIdManager;
+
+ protected function setUp() {
+ parent::setUp();
+ $this->cloudIdManager = new CloudIdManager();
+ }
+
+ public function cloudIdProvider() {
+ return [
+ ['test@example.com', 'test', 'example.com', 'test@example.com'],
+ ['test@example.com/cloud', 'test', 'example.com/cloud', 'test@example.com/cloud'],
+ ['test@example.com/cloud/', 'test', 'example.com/cloud', 'test@example.com/cloud'],
+ ['test@example.com/cloud/index.php', 'test', 'example.com/cloud', 'test@example.com/cloud'],
+ ['test@example.com@example.com', 'test@example.com', 'example.com', 'test@example.com@example.com'],
+ ];
+ }
+
+ /**
+ * @dataProvider cloudIdProvider
+ *
+ * @param string $cloudId
+ * @param string $user
+ * @param string $remote
+ */
+ public function testResolveCloudId($cloudId, $user, $remote, $cleanId) {
+ $cloudId = $this->cloudIdManager->resolveCloudId($cloudId);
+
+ $this->assertEquals($user, $cloudId->getUser());
+ $this->assertEquals($remote, $cloudId->getRemote());
+ $this->assertEquals($cleanId, $cloudId->getId());
+ }
+
+ public function invalidCloudIdProvider() {
+ return [
+ ['example.com'],
+ ['test:foo@example.com'],
+ ['test/foo@example.com']
+ ];
+ }
+
+ /**
+ * @dataProvider invalidCloudIdProvider
+ *
+ * @param string $cloudId
+ *
+ * @expectedException \InvalidArgumentException
+ */
+ public function testInvalidCloudId($cloudId) {
+ $this->cloudIdManager->resolveCloudId($cloudId);
+ }
+
+ public function getCloudIdProvider() {
+ return [
+ ['test', 'example.com', 'test@example.com'],
+ ['test@example.com', 'example.com', 'test@example.com@example.com'],
+ ];
+ }
+
+ /**
+ * @dataProvider getCloudIdProvider
+ *
+ * @param string $user
+ * @param string $remote
+ * @param string $id
+ */
+ public function testGetCloudId($user, $remote, $id) {
+ $cloudId = $this->cloudIdManager->getCloudId($user, $remote);
+
+ $this->assertEquals($id, $cloudId->getId());
+ }
+}
diff --git a/tests/lib/Federation/CloudIdTest.php b/tests/lib/Federation/CloudIdTest.php
new file mode 100644
index 00000000000..7a6e841fb34
--- /dev/null
+++ b/tests/lib/Federation/CloudIdTest.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\Federation;
+
+use OC\Federation\CloudId;
+use Test\TestCase;
+
+class CloudIdTest extends TestCase {
+ public function testGetDisplayCloudIdProvider() {
+ return [
+ ['test@example.com', 'test@example.com'],
+ ['test@http://example.com', 'test@example.com'],
+ ['test@https://example.com', 'test@example.com'],
+ ];
+ }
+
+ /**
+ * @dataProvider testGetDisplayCloudIdProvider
+ *
+ * @param string $id
+ * @param string $display
+ */
+ public function testGetDisplayCloudId($id, $display) {
+ $cloudId = new CloudId($id, '', '');
+ $this->assertEquals($display, $cloudId->getDisplayId());
+ }
+}