-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38448 from nextcloud/fix/carddav/no-sab-guest-users
fix(carddav): Don't show system address book cards to guests
- Loading branch information
Showing
2 changed files
with
84 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,46 @@ protected function setUp(): void { | |
); | ||
} | ||
|
||
public function testGetChildrenAsGuest(): void { | ||
$this->config->expects(self::exactly(3)) | ||
->method('getAppValue') | ||
->willReturnMap([ | ||
['core', 'shareapi_allow_share_dialog_user_enumeration', 'yes', 'yes'], | ||
['core', 'shareapi_restrict_user_enumeration_to_group', 'no', 'no'], | ||
['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'], | ||
]); | ||
$user = $this->createMock(IUser::class); | ||
$user->method('getUID')->willReturn('user'); | ||
$user->method('getBackendClassName')->willReturn('Guests'); | ||
$this->userSession->expects(self::once()) | ||
->method('getUser') | ||
->willReturn($user); | ||
$vcfWithScopes = <<<VCF | ||
BEGIN:VCARD | ||
VERSION:3.0 | ||
PRODID:-//Sabre//Sabre VObject 4.4.2//EN | ||
UID:admin | ||
FN;X-NC-SCOPE=v2-federated:admin | ||
N;X-NC-SCOPE=v2-federated:admin;;;; | ||
ADR;TYPE=OTHER;X-NC-SCOPE=v2-local:Testing test test test;;;;;; | ||
EMAIL;TYPE=OTHER;X-NC-SCOPE=v2-federated:[email protected] | ||
TEL;TYPE=OTHER;X-NC-SCOPE=v2-local:+435454454544 | ||
CLOUD:admin@http://localhost | ||
END:VCARD | ||
VCF; | ||
$originalCard = [ | ||
'carddata' => $vcfWithScopes, | ||
]; | ||
$this->cardDavBackend->expects(self::once()) | ||
->method('getCard') | ||
->with(123, 'Guests:user.vcf') | ||
->willReturn($originalCard); | ||
|
||
$children = $this->addressBook->getChildren(); | ||
|
||
self::assertCount(1, $children); | ||
} | ||
|
||
public function testGetFilteredChildForFederation(): void { | ||
$this->config->expects(self::exactly(3)) | ||
->method('getAppValue') | ||
|
@@ -172,6 +212,24 @@ public function testGetChildWithoutEnumeration(): void { | |
$this->addressBook->getChild("LDAP:user.vcf"); | ||
} | ||
|
||
public function testGetChildAsGuest(): void { | ||
$this->config->expects(self::exactly(3)) | ||
->method('getAppValue') | ||
->willReturnMap([ | ||
['core', 'shareapi_allow_share_dialog_user_enumeration', 'yes', 'yes'], | ||
['core', 'shareapi_restrict_user_enumeration_to_group', 'no', 'no'], | ||
['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'], | ||
]); | ||
$user = $this->createMock(IUser::class); | ||
$user->method('getBackendClassName')->willReturn('Guests'); | ||
$this->userSession->expects(self::once()) | ||
->method('getUser') | ||
->willReturn($user); | ||
$this->expectException(Forbidden::class); | ||
|
||
$this->addressBook->getChild("LDAP:user.vcf"); | ||
} | ||
|
||
public function testGetChildWithGroupEnumerationRestriction(): void { | ||
$this->config->expects(self::exactly(3)) | ||
->method('getAppValue') | ||
|
@@ -322,6 +380,26 @@ public function testGetMultipleChildrenWithGroupEnumerationRestriction(): void { | |
self::assertCount(2, $cards); | ||
} | ||
|
||
public function testGetMultipleChildrenAsGuest(): void { | ||
$this->config | ||
->method('getAppValue') | ||
->willReturnMap([ | ||
['core', 'shareapi_allow_share_dialog_user_enumeration', 'yes', 'yes'], | ||
['core', 'shareapi_restrict_user_enumeration_to_group', 'no', 'no'], | ||
['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'], | ||
]); | ||
$user = $this->createMock(IUser::class); | ||
$user->method('getUID')->willReturn('user'); | ||
$user->method('getBackendClassName')->willReturn('Guests'); | ||
$this->userSession->expects(self::once()) | ||
->method('getUser') | ||
->willReturn($user); | ||
|
||
$cards = $this->addressBook->getMultipleChildren(['Database:user1.vcf', 'LDAP:user2.vcf']); | ||
|
||
self::assertEmpty($cards); | ||
} | ||
|
||
public function testGetMultipleChildren(): void { | ||
$this->config | ||
->method('getAppValue') | ||
|