-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
respect shareapi_allow_share_dialog_user_enumeration in Principal backend for Sabre/DAV #18120
Merged
skjnldsv
merged 1 commit into
master
from
bugfix/11087/dav_principal_backend_respect_sharing_settings
Dec 3, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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 |
---|---|---|
|
@@ -65,21 +65,26 @@ class PrincipalTest extends TestCase { | |
/** @var ProxyMapper | \PHPUnit_Framework_MockObject_MockObject */ | ||
private $proxyMapper; | ||
|
||
/** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */ | ||
private $config; | ||
|
||
protected function setUp(): void { | ||
$this->userManager = $this->createMock(IUserManager::class); | ||
$this->groupManager = $this->createMock(IGroupManager::class); | ||
$this->shareManager = $this->createMock(IManager::class); | ||
$this->userSession = $this->createMock(IUserSession::class); | ||
$this->appManager = $this->createMock(IAppManager::class); | ||
$this->proxyMapper = $this->createMock(ProxyMapper::class); | ||
$this->config = $this->createMock(IConfig::class); | ||
|
||
$this->connector = new \OCA\DAV\Connector\Sabre\Principal( | ||
$this->userManager, | ||
$this->groupManager, | ||
$this->shareManager, | ||
$this->userSession, | ||
$this->appManager, | ||
$this->proxyMapper | ||
$this->proxyMapper, | ||
$this->config | ||
); | ||
parent::setUp(); | ||
} | ||
|
@@ -209,7 +214,7 @@ public function testGetGroupMemberSet() { | |
$this->assertSame([], $response); | ||
} | ||
|
||
|
||
public function testGetGroupMemberSetEmpty() { | ||
$this->expectException(\Sabre\DAV\Exception::class); | ||
$this->expectExceptionMessage('Principal not found'); | ||
|
@@ -334,7 +339,7 @@ public function testGetGroupMembership() { | |
$this->assertSame($expectedResponse, $response); | ||
} | ||
|
||
|
||
public function testGetGroupMembershipEmpty() { | ||
$this->expectException(\Sabre\DAV\Exception::class); | ||
$this->expectExceptionMessage('Principal not found'); | ||
|
@@ -348,7 +353,7 @@ public function testGetGroupMembershipEmpty() { | |
$this->connector->getGroupMembership('principals/users/foo'); | ||
} | ||
|
||
|
||
public function testSetGroupMembership() { | ||
$this->expectException(\Sabre\DAV\Exception::class); | ||
$this->expectExceptionMessage('Setting members of the group is not supported yet'); | ||
|
@@ -403,11 +408,6 @@ public function testSetGroupMembershipProxy() { | |
$this->connector->setGroupMemberSet('principals/users/foo/calendar-proxy-write', ['principals/users/bar']); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
public function testUpdatePrincipal() { | ||
$this->assertSame(0, $this->connector->updatePrincipal('foo', new PropPatch(array()))); | ||
} | ||
|
@@ -430,6 +430,11 @@ public function testSearchPrincipals($sharingEnabled, $groupsOnly, $test, $resul | |
->will($this->returnValue($sharingEnabled)); | ||
|
||
if ($sharingEnabled) { | ||
$this->config->expects($this->once()) | ||
->method('getAppValue') | ||
->with('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') | ||
->willReturn('yes'); | ||
|
||
$this->shareManager->expects($this->once()) | ||
->method('shareWithGroupMembersOnly') | ||
->will($this->returnValue($groupsOnly)); | ||
|
@@ -446,6 +451,8 @@ public function testSearchPrincipals($sharingEnabled, $groupsOnly, $test, $resul | |
->will($this->returnValue(['group1', 'group2', 'group5'])); | ||
} | ||
} else { | ||
$this->config->expects($this->never()) | ||
->method('getAppValue'); | ||
$this->shareManager->expects($this->never()) | ||
->method('shareWithGroupMembersOnly'); | ||
$this->groupManager->expects($this->never()) | ||
|
@@ -518,6 +525,11 @@ public function testSearchPrincipalByCalendarUserAddressSet() { | |
->method('shareAPIEnabled') | ||
->will($this->returnValue(true)); | ||
|
||
$this->config->expects($this->exactly(2)) | ||
->method('getAppValue') | ||
->with('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') | ||
->willReturn('yes'); | ||
|
||
$this->shareManager->expects($this->exactly(2)) | ||
->method('shareWithGroupMembersOnly') | ||
->will($this->returnValue(false)); | ||
|
@@ -539,6 +551,78 @@ public function testSearchPrincipalByCalendarUserAddressSet() { | |
['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => '[email protected]'])); | ||
} | ||
|
||
public function testSearchPrincipalWithEnumerationDisabledDisplayname() { | ||
$this->shareManager->expects($this->once()) | ||
->method('shareAPIEnabled') | ||
->will($this->returnValue(true)); | ||
|
||
$this->config->expects($this->once()) | ||
->method('getAppValue') | ||
->with('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') | ||
->willReturn('no'); | ||
|
||
$this->shareManager->expects($this->once()) | ||
->method('shareWithGroupMembersOnly') | ||
->will($this->returnValue(false)); | ||
|
||
$user2 = $this->createMock(IUser::class); | ||
$user2->method('getUID')->will($this->returnValue('user2')); | ||
$user2->method('getDisplayName')->will($this->returnValue('User 2')); | ||
$user2->method('getEMailAddress')->will($this->returnValue('[email protected]')); | ||
$user3 = $this->createMock(IUser::class); | ||
$user3->method('getUID')->will($this->returnValue('user3')); | ||
$user2->method('getDisplayName')->will($this->returnValue('User 22')); | ||
$user2->method('getEMailAddress')->will($this->returnValue('[email protected]')); | ||
$user4 = $this->createMock(IUser::class); | ||
$user4->method('getUID')->will($this->returnValue('user4')); | ||
$user2->method('getDisplayName')->will($this->returnValue('User 222')); | ||
$user2->method('getEMailAddress')->will($this->returnValue('[email protected]')); | ||
|
||
$this->userManager->expects($this->at(0)) | ||
->method('searchDisplayName') | ||
->with('User 2') | ||
->will($this->returnValue([$user2, $user3, $user4])); | ||
|
||
$this->assertEquals(['principals/users/user2'], $this->connector->searchPrincipals('principals/users', | ||
['{DAV:}displayname' => 'User 2'])); | ||
} | ||
|
||
public function testSearchPrincipalWithEnumerationDisabledEmail() { | ||
$this->shareManager->expects($this->once()) | ||
->method('shareAPIEnabled') | ||
->will($this->returnValue(true)); | ||
|
||
$this->config->expects($this->once()) | ||
->method('getAppValue') | ||
->with('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') | ||
->willReturn('no'); | ||
|
||
$this->shareManager->expects($this->once()) | ||
->method('shareWithGroupMembersOnly') | ||
->will($this->returnValue(false)); | ||
|
||
$user2 = $this->createMock(IUser::class); | ||
$user2->method('getUID')->will($this->returnValue('user2')); | ||
$user2->method('getDisplayName')->will($this->returnValue('User 2')); | ||
$user2->method('getEMailAddress')->will($this->returnValue('[email protected]')); | ||
$user3 = $this->createMock(IUser::class); | ||
$user3->method('getUID')->will($this->returnValue('user3')); | ||
$user2->method('getDisplayName')->will($this->returnValue('User 22')); | ||
$user2->method('getEMailAddress')->will($this->returnValue('[email protected]')); | ||
$user4 = $this->createMock(IUser::class); | ||
$user4->method('getUID')->will($this->returnValue('user4')); | ||
$user2->method('getDisplayName')->will($this->returnValue('User 222')); | ||
$user2->method('getEMailAddress')->will($this->returnValue('[email protected]')); | ||
|
||
$this->userManager->expects($this->at(0)) | ||
->method('getByEmail') | ||
->with('[email protected]') | ||
->will($this->returnValue([$user2, $user3, $user4])); | ||
|
||
$this->assertEquals(['principals/users/user2'], $this->connector->searchPrincipals('principals/users', | ||
['{http://sabredav.org/ns}email-address' => '[email protected]'])); | ||
} | ||
|
||
public function testFindByUriSharingApiDisabled() { | ||
$this->shareManager->expects($this->once()) | ||
->method('shareApiEnabled') | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GroupPrincipalBackend doesn't even take a fourth parameter: (Also not on
/stable(15|16|17)/
)https://github.com/nextcloud/server/blob/master/apps/dav/lib/DAV/GroupPrincipalBackend.php#L55
Not sure why it was there in the first place.