]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(federation): ICloudId->getRemote() should contain the protocol 44626/head
authorJoas Schilling <coding@schilljs.com>
Tue, 2 Apr 2024 15:55:16 +0000 (17:55 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Tue, 2 Apr 2024 15:59:24 +0000 (15:59 +0000)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/Federation/CloudIdManager.php
tests/lib/Federation/CloudIdManagerTest.php

index 70431ce2289b9c3cab6b2e5b51b6ebfe09a25477..86b5ed621ba2229cb8def61ecbbe4dcc949800b5 100644 (file)
@@ -174,7 +174,6 @@ class CloudIdManager implements ICloudIdManager {
                // note that for remote id's we don't strip the protocol for the remote we use to construct the CloudId
                // this way if a user has an explicit non-https cloud id this will be preserved
                // we do still use the version without protocol for looking up the display name
-               $remote = $this->removeProtocolFromUrl($remote, true);
                $remote = $this->fixRemoteURL($remote);
                $host = $this->removeProtocolFromUrl($remote);
 
@@ -191,7 +190,9 @@ class CloudIdManager implements ICloudIdManager {
                } else {
                        $displayName = $this->getDisplayNameFromContact($user . '@' . $host);
                }
-               $id = $user . '@' . $remote;
+
+               // For the visible cloudID we only strip away https
+               $id = $user . '@' . $this->removeProtocolFromUrl($remote, true);
 
                $data = [
                        'id' => $id,
index 748d292e977c5d2d5f7e2b3784d3001af2668e01..a144dbb780007a9f4732fe9110af495d3fdf497c 100644 (file)
@@ -128,11 +128,11 @@ class CloudIdManagerTest extends TestCase {
                return [
                        ['test', 'example.com', 'test@example.com'],
                        ['test', 'http://example.com', 'test@http://example.com', 'test@example.com'],
-                       ['test', null, 'test@http://example.com', 'test@example.com', 'http://example.com'],
+                       ['test', null, 'test@http://example.com', 'test@example.com', 'http://example.com', 'http://example.com'],
                        ['test@example.com', 'example.com', 'test@example.com@example.com'],
                        ['test@example.com', 'https://example.com', 'test@example.com@example.com'],
-                       ['test@example.com', null, 'test@example.com@example.com'],
-                       ['test@example.com', 'https://example.com/index.php/s/shareToken', 'test@example.com@example.com'],
+                       ['test@example.com', null, 'test@example.com@example.com', null, 'https://example.com', 'https://example.com'],
+                       ['test@example.com', 'https://example.com/index.php/s/shareToken', 'test@example.com@example.com', null, 'https://example.com', 'https://example.com'],
                ];
        }
 
@@ -143,7 +143,7 @@ class CloudIdManagerTest extends TestCase {
         * @param null|string $remote
         * @param string $id
         */
-       public function testGetCloudId(string $user, ?string $remote, string $id, ?string $searchCloudId = null, ?string $localHost = 'https://example.com'): void {
+       public function testGetCloudId(string $user, ?string $remote, string $id, ?string $searchCloudId = null, ?string $localHost = 'https://example.com', ?string $expectedRemoteId = null): void {
                if ($remote !== null) {
                        $this->contactsManager->expects($this->any())
                                ->method('search')
@@ -159,9 +159,11 @@ class CloudIdManagerTest extends TestCase {
                                ->method('getAbsoluteUrl')
                                ->willReturn($localHost);
                }
+               $expectedRemoteId ??= $remote;
 
                $cloudId = $this->cloudIdManager->getCloudId($user, $remote);
 
-               $this->assertEquals($id, $cloudId->getId());
+               $this->assertEquals($id, $cloudId->getId(), 'Cloud ID');
+               $this->assertEquals($expectedRemoteId, $cloudId->getRemote(), 'Remote URL');
        }
 }