Skip to content

Commit

Permalink
Merge pull request #44625 from nextcloud/bugfix/44608/fix-remote-of-c…
Browse files Browse the repository at this point in the history
…loudid-being-with-protocol

fix(federation): ICloudId->getRemote() should contain the protocol
  • Loading branch information
nickvergessen committed Apr 2, 2024
2 parents 6bced38 + 575e7d8 commit 43204a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions lib/private/Federation/CloudIdManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ public function getCloudId(string $user, ?string $remote): ICloudId {
// 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);

Expand All @@ -191,7 +190,9 @@ public function getCloudId(string $user, ?string $remote): ICloudId {
} 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,
Expand Down
12 changes: 7 additions & 5 deletions tests/lib/Federation/CloudIdManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ public function getCloudIdProvider(): array {
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'],
];
}

Expand All @@ -143,7 +143,7 @@ public function getCloudIdProvider(): array {
* @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')
Expand All @@ -159,9 +159,11 @@ public function testGetCloudId(string $user, ?string $remote, string $id, ?strin
->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');
}
}

0 comments on commit 43204a0

Please sign in to comment.