-
-
Couldn't load subscription status.
- Fork 4.6k
fix: hide guests group when searching for principals #53369
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Testing; | ||
|
|
||
| use OCP\Group\Backend\ABackend; | ||
| use OCP\Group\Backend\IHideFromCollaborationBackend; | ||
|
|
||
| class HiddenGroupBackend extends ABackend implements IHideFromCollaborationBackend { | ||
| private string $groupName; | ||
|
|
||
| public function __construct( | ||
| string $groupName = 'hidden_group', | ||
| ) { | ||
| $this->groupName = $groupName; | ||
| } | ||
|
|
||
| public function inGroup($uid, $gid): bool { | ||
| return false; | ||
| } | ||
|
|
||
| public function getUserGroups($uid): array { | ||
| return []; | ||
| } | ||
|
|
||
| public function getGroups($search = '', $limit = -1, $offset = 0): array { | ||
| return $offset === 0 ? [$this->groupName] : []; | ||
| } | ||
|
|
||
| public function groupExists($gid): bool { | ||
| return $gid === $this->groupName; | ||
| } | ||
|
|
||
| public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0): array { | ||
| return []; | ||
| } | ||
|
|
||
| public function hideGroup(string $groupId): bool { | ||
| return true; | ||
| } | ||
| } |
This file contains hidden or 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
13 changes: 13 additions & 0 deletions
13
build/integration/dav_features/principal-property-search.feature
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| # SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
|
||
| Feature: principal-property-search | ||
| Background: | ||
| Given user "user0" exists | ||
| Given As an "admin" | ||
| Given invoking occ with "app:enable --force testing" | ||
|
|
||
| Scenario: Find a principal by a given displayname | ||
| When searching for a principal matching "user0" | ||
| Then The search HTTP status code should be "207" | ||
| And The search response should contain "<d:href>/remote.php/dav/principals/users/user0/</d:href>" | ||
140 changes: 140 additions & 0 deletions
140
build/integration/features/bootstrap/PrincipalPropertySearchContext.php
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| <?php | ||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| require __DIR__ . '/../../vendor/autoload.php'; | ||
|
|
||
| use Behat\Behat\Context\Context; | ||
| use GuzzleHttp\BodySummarizer; | ||
| use GuzzleHttp\Client; | ||
| use GuzzleHttp\HandlerStack; | ||
| use GuzzleHttp\Middleware; | ||
| use GuzzleHttp\Utils; | ||
| use Psr\Http\Message\ResponseInterface; | ||
|
|
||
| class PrincipalPropertySearchContext implements Context { | ||
| private string $baseUrl; | ||
| private Client $client; | ||
| private ResponseInterface $response; | ||
|
|
||
| public function __construct(string $baseUrl) { | ||
| $this->baseUrl = $baseUrl; | ||
|
|
||
| // in case of ci deployment we take the server url from the environment | ||
| $testServerUrl = getenv('TEST_SERVER_URL'); | ||
| if ($testServerUrl !== false) { | ||
| $this->baseUrl = substr($testServerUrl, 0, -5); | ||
| } | ||
| } | ||
|
|
||
| /** @BeforeScenario */ | ||
| public function setUpScenario(): void { | ||
| $this->client = $this->createGuzzleInstance(); | ||
| } | ||
|
|
||
| /** | ||
| * Create a Guzzle client with a higher truncateAt value to read full error responses. | ||
| */ | ||
| private function createGuzzleInstance(): Client { | ||
| $bodySummarizer = new BodySummarizer(2048); | ||
|
|
||
| $stack = new HandlerStack(Utils::chooseHandler()); | ||
| $stack->push(Middleware::httpErrors($bodySummarizer), 'http_errors'); | ||
| $stack->push(Middleware::redirect(), 'allow_redirects'); | ||
| $stack->push(Middleware::cookies(), 'cookies'); | ||
| $stack->push(Middleware::prepareBody(), 'prepare_body'); | ||
|
|
||
| return new Client(['handler' => $stack]); | ||
| } | ||
|
|
||
| /** | ||
| * @When searching for a principal matching :match | ||
| * @param string $match | ||
| * @throws \Exception | ||
| */ | ||
| public function principalPropertySearch(string $match) { | ||
| $davUrl = $this->baseUrl . '/remote.php/dav/'; | ||
| $user = 'admin'; | ||
| $password = 'admin'; | ||
|
|
||
| $this->response = $this->client->request( | ||
| 'REPORT', | ||
| $davUrl, | ||
| [ | ||
| 'body' => '<x0:principal-property-search xmlns:x0="DAV:" test="anyof"> | ||
| <x0:property-search> | ||
| <x0:prop> | ||
| <x0:displayname/> | ||
| <x2:email-address xmlns:x2="http://sabredav.org/ns"/> | ||
| </x0:prop> | ||
| <x0:match>' . $match . '</x0:match> | ||
| </x0:property-search> | ||
| <x0:prop> | ||
| <x0:displayname/> | ||
| <x1:calendar-user-type xmlns:x1="urn:ietf:params:xml:ns:caldav"/> | ||
| <x1:calendar-user-address-set xmlns:x1="urn:ietf:params:xml:ns:caldav"/> | ||
| <x0:principal-URL/> | ||
| <x0:alternate-URI-set/> | ||
| <x2:email-address xmlns:x2="http://sabredav.org/ns"/> | ||
| <x3:language xmlns:x3="http://nextcloud.com/ns"/> | ||
| <x1:calendar-home-set xmlns:x1="urn:ietf:params:xml:ns:caldav"/> | ||
| <x1:schedule-inbox-URL xmlns:x1="urn:ietf:params:xml:ns:caldav"/> | ||
| <x1:schedule-outbox-URL xmlns:x1="urn:ietf:params:xml:ns:caldav"/> | ||
| <x1:schedule-default-calendar-URL xmlns:x1="urn:ietf:params:xml:ns:caldav"/> | ||
| <x3:resource-type xmlns:x3="http://nextcloud.com/ns"/> | ||
| <x3:resource-vehicle-type xmlns:x3="http://nextcloud.com/ns"/> | ||
| <x3:resource-vehicle-make xmlns:x3="http://nextcloud.com/ns"/> | ||
| <x3:resource-vehicle-model xmlns:x3="http://nextcloud.com/ns"/> | ||
| <x3:resource-vehicle-is-electric xmlns:x3="http://nextcloud.com/ns"/> | ||
| <x3:resource-vehicle-range xmlns:x3="http://nextcloud.com/ns"/> | ||
| <x3:resource-vehicle-seating-capacity xmlns:x3="http://nextcloud.com/ns"/> | ||
| <x3:resource-contact-person xmlns:x3="http://nextcloud.com/ns"/> | ||
| <x3:resource-contact-person-vcard xmlns:x3="http://nextcloud.com/ns"/> | ||
| <x3:room-type xmlns:x3="http://nextcloud.com/ns"/> | ||
| <x3:room-seating-capacity xmlns:x3="http://nextcloud.com/ns"/> | ||
| <x3:room-building-address xmlns:x3="http://nextcloud.com/ns"/> | ||
| <x3:room-building-story xmlns:x3="http://nextcloud.com/ns"/> | ||
| <x3:room-building-room-number xmlns:x3="http://nextcloud.com/ns"/> | ||
| <x3:room-features xmlns:x3="http://nextcloud.com/ns"/> | ||
| </x0:prop> | ||
| <x0:apply-to-principal-collection-set/> | ||
| </x0:principal-property-search> | ||
| ', | ||
| 'auth' => [ | ||
| $user, | ||
| $password, | ||
| ], | ||
| 'headers' => [ | ||
| 'Content-Type' => 'application/xml; charset=UTF-8', | ||
| 'Depth' => '0', | ||
| ], | ||
| ] | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @Then The search HTTP status code should be :code | ||
| * @param string $code | ||
| * @throws \Exception | ||
| */ | ||
| public function theHttpStatusCodeShouldBe(string $code): void { | ||
| if ((int)$code !== $this->response->getStatusCode()) { | ||
| throw new \Exception('Expected ' . (int)$code . ' got ' . $this->response->getStatusCode()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @Then The search response should contain :needle | ||
| * @param string $needle | ||
| * @throws \Exception | ||
| */ | ||
| public function theResponseShouldContain(string $needle): void { | ||
| $body = $this->response->getBody()->getContents(); | ||
|
|
||
| if (str_contains($body, $needle) === false) { | ||
| throw new \Exception('Response does not contain "' . $needle . '"'); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
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.
I run into conflicts with other behat definitions and therefore use "the search ..." as prefix.