Skip to content

Commit 0ce4b4b

Browse files
authored
Merge pull request #52012 from nextcloud/fix-user-collaborators-returned-when-searching-for-mail-collaborators
Fix user collaborators returned when searching for mail collaborators
2 parents 8029dd6 + c40fcba commit 0ce4b4b

File tree

13 files changed

+1053
-109
lines changed

13 files changed

+1053
-109
lines changed

build/integration/collaboration_features/autocomplete.feature

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,88 @@ Feature: autocomplete
4141
Then get autocomplete for "autocomplete"
4242
| id | source |
4343

44+
Scenario: getting autocomplete from address book with enumeration
45+
Given As an "admin"
46+
And sending "PUT" to "/cloud/users/autocomplete" with
47+
| key | email |
48+
| value | autocomplete@example.com |
49+
And there is a contact in an addressbook
50+
When parameter "shareapi_restrict_user_enumeration_full_match" of app "core" is set to "no"
51+
Then get autocomplete for "auto"
52+
| id | source |
53+
| auto | users |
54+
| autocomplete | users |
55+
| autocomplete2 | users |
56+
Then get autocomplete for "example"
57+
| id | source |
58+
| autocomplete | users |
59+
Then get autocomplete for "[email protected]"
60+
| id | source |
61+
| autocomplete | users |
62+
When parameter "shareapi_restrict_user_enumeration_full_match" of app "core" is set to "yes"
63+
Then get autocomplete for "auto"
64+
| id | source |
65+
| auto | users |
66+
| autocomplete | users |
67+
| autocomplete2 | users |
68+
Then get autocomplete for "example"
69+
| id | source |
70+
| autocomplete | users |
71+
Then get autocomplete for "[email protected]"
72+
| id | source |
73+
| autocomplete | users |
74+
| autocomplete | users |
75+
76+
Scenario: getting autocomplete from address book without enumeration
77+
Given As an "admin"
78+
And sending "PUT" to "/cloud/users/autocomplete" with
79+
| key | email |
80+
| value | autocomplete@example.com |
81+
And there is a contact in an addressbook
82+
And parameter "shareapi_allow_share_dialog_user_enumeration" of app "core" is set to "no"
83+
When parameter "shareapi_restrict_user_enumeration_full_match" of app "core" is set to "no"
84+
Then get autocomplete for "auto"
85+
| id | source |
86+
Then get autocomplete for "example"
87+
| id | source |
88+
Then get autocomplete for "[email protected]"
89+
| id | source |
90+
When parameter "shareapi_restrict_user_enumeration_full_match" of app "core" is set to "yes"
91+
Then get autocomplete for "auto"
92+
| id | source |
93+
| auto | users |
94+
Then get autocomplete for "example"
95+
| id | source |
96+
Then get autocomplete for "[email protected]"
97+
| id | source |
98+
| autocomplete | users |
99+
| autocomplete | users |
100+
44101
Scenario: getting autocomplete emails from address book with enumeration
45102
Given As an "admin"
46103
And sending "PUT" to "/cloud/users/autocomplete" with
47104
| key | email |
48105
| value | autocomplete@example.com |
49106
And there is a contact in an addressbook
107+
When parameter "shareapi_restrict_user_enumeration_full_match" of app "core" is set to "no"
108+
Then get email autocomplete for "auto"
109+
| id | source |
50110
Then get email autocomplete for "example"
51111
| id | source |
52-
| autocomplete | users |
53112
| leon@example.com | emails |
54113
| user@example.com | emails |
114+
Then get email autocomplete for "[email protected]"
115+
| id | source |
116+
| autocomplete@example.com | emails |
117+
When parameter "shareapi_restrict_user_enumeration_full_match" of app "core" is set to "yes"
55118
Then get email autocomplete for "auto"
56119
| id | source |
57-
| autocomplete | users |
58120
Then get email autocomplete for "example"
59121
| id | source |
60-
| autocomplete | users |
61122
| leon@example.com | emails |
62123
| user@example.com | emails |
63124
Then get email autocomplete for "[email protected]"
64125
| id | source |
65-
| autocomplete | users |
66126

67127
Scenario: getting autocomplete emails from address book without enumeration
68128
Given As an "admin"
@@ -72,10 +132,15 @@ Feature: autocomplete
72132
And there is a contact in an addressbook
73133
And parameter "shareapi_allow_share_dialog_user_enumeration" of app "core" is set to "no"
74134
When parameter "shareapi_restrict_user_enumeration_full_match" of app "core" is set to "no"
135+
Then get email autocomplete for "auto"
136+
| id | source |
75137
Then get email autocomplete for "example"
76138
| id | source |
77139
| leon@example.com | emails |
78140
| user@example.com | emails |
141+
Then get email autocomplete for "[email protected]"
142+
| id | source |
143+
| autocomplete@example.com | emails |
79144
When parameter "shareapi_restrict_user_enumeration_full_match" of app "core" is set to "yes"
80145
Then get email autocomplete for "auto"
81146
| id | source |
@@ -85,7 +150,6 @@ Feature: autocomplete
85150
| user@example.com | emails |
86151
Then get email autocomplete for "[email protected]"
87152
| id | source |
88-
| autocomplete | users |
89153

90154
Scenario: getting autocomplete with limited enumeration by group
91155
Given As an "admin"

build/integration/features/bootstrap/Provisioning.php

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
trait Provisioning {
1717
use BasicStructure;
1818

19+
/** @var array */
20+
private $appsToEnableAfterScenario = [];
21+
22+
/** @var array */
23+
private $appsToDisableAfterScenario = [];
24+
1925
/** @var array */
2026
private $createdUsers = [];
2127

@@ -28,6 +34,19 @@ trait Provisioning {
2834
/** @var array */
2935
private $createdGroups = [];
3036

37+
/** @AfterScenario */
38+
public function restoreAppsEnabledStateAfterScenario() {
39+
$this->asAn('admin');
40+
41+
foreach ($this->appsToEnableAfterScenario as $app) {
42+
$this->sendingTo('POST', '/cloud/apps/' . $app);
43+
}
44+
45+
foreach ($this->appsToDisableAfterScenario as $app) {
46+
$this->sendingTo('DELETE', '/cloud/apps/' . $app);
47+
}
48+
}
49+
3150
/**
3251
* @Given /^user "([^"]*)" exists$/
3352
* @param string $user
@@ -803,13 +822,23 @@ public function getArrayOfSubadminsResponded($resp) {
803822
return $extractedElementsArray;
804823
}
805824

806-
807825
/**
808-
* @Given /^app "([^"]*)" is disabled$/
826+
* @Given /^app "([^"]*)" enabled state will be restored once the scenario finishes$/
809827
* @param string $app
810828
*/
811-
public function appIsDisabled($app) {
812-
$fullUrl = $this->baseUrl . 'v2.php/cloud/apps?filter=disabled';
829+
public function appEnabledStateWillBeRestoredOnceTheScenarioFinishes($app) {
830+
if (in_array($app, $this->getAppsWithFilter('enabled'))) {
831+
$this->appsToEnableAfterScenario[] = $app;
832+
} elseif (in_array($app, $this->getAppsWithFilter('disabled'))) {
833+
$this->appsToDisableAfterScenario[] = $app;
834+
}
835+
836+
// Apps that were not installed before the scenario will not be
837+
// disabled nor uninstalled after the scenario.
838+
}
839+
840+
private function getAppsWithFilter($filter) {
841+
$fullUrl = $this->baseUrl . 'v2.php/cloud/apps?filter=' . $filter;
813842
$client = new Client();
814843
$options = [];
815844
if ($this->currentUser === 'admin') {
@@ -820,7 +849,15 @@ public function appIsDisabled($app) {
820849
];
821850

822851
$this->response = $client->get($fullUrl, $options);
823-
$respondedArray = $this->getArrayOfAppsResponded($this->response);
852+
return $this->getArrayOfAppsResponded($this->response);
853+
}
854+
855+
/**
856+
* @Given /^app "([^"]*)" is disabled$/
857+
* @param string $app
858+
*/
859+
public function appIsDisabled($app) {
860+
$respondedArray = $this->getAppsWithFilter('disabled');
824861
Assert::assertContains($app, $respondedArray);
825862
Assert::assertEquals(200, $this->response->getStatusCode());
826863
}
@@ -830,18 +867,7 @@ public function appIsDisabled($app) {
830867
* @param string $app
831868
*/
832869
public function appIsEnabled($app) {
833-
$fullUrl = $this->baseUrl . 'v2.php/cloud/apps?filter=enabled';
834-
$client = new Client();
835-
$options = [];
836-
if ($this->currentUser === 'admin') {
837-
$options['auth'] = $this->adminUser;
838-
}
839-
$options['headers'] = [
840-
'OCS-APIREQUEST' => 'true',
841-
];
842-
843-
$this->response = $client->get($fullUrl, $options);
844-
$respondedArray = $this->getArrayOfAppsResponded($this->response);
870+
$respondedArray = $this->getAppsWithFilter('enabled');
845871
Assert::assertContains($app, $respondedArray);
846872
Assert::assertEquals(200, $this->response->getStatusCode());
847873
}
@@ -854,18 +880,7 @@ public function appIsEnabled($app) {
854880
* @param string $app
855881
*/
856882
public function appIsNotEnabled($app) {
857-
$fullUrl = $this->baseUrl . 'v2.php/cloud/apps?filter=enabled';
858-
$client = new Client();
859-
$options = [];
860-
if ($this->currentUser === 'admin') {
861-
$options['auth'] = $this->adminUser;
862-
}
863-
$options['headers'] = [
864-
'OCS-APIREQUEST' => 'true',
865-
];
866-
867-
$this->response = $client->get($fullUrl, $options);
868-
$respondedArray = $this->getArrayOfAppsResponded($this->response);
883+
$respondedArray = $this->getAppsWithFilter('enabled');
869884
Assert::assertNotContains($app, $respondedArray);
870885
Assert::assertEquals(200, $this->response->getStatusCode());
871886
}

build/integration/features/bootstrap/Sharing.php

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,13 @@ public function whenGettingShareesFor($body) {
697697
if ($body instanceof TableNode) {
698698
$parameters = [];
699699
foreach ($body->getRowsHash() as $key => $value) {
700-
$parameters[] = $key . '=' . $value;
700+
if ($key === 'shareTypes') {
701+
foreach (explode(' ', $value) as $shareType) {
702+
$parameters[] = 'shareType[]=' . $shareType;
703+
}
704+
} else {
705+
$parameters[] = $key . '=' . $value;
706+
}
701707
}
702708
if (!empty($parameters)) {
703709
$url .= '?' . implode('&', $parameters);
@@ -732,9 +738,46 @@ public function getArrayOfShareesResponded(ResponseInterface $response, $shareeT
732738
$shareeType = substr($shareeType, 6);
733739
}
734740

741+
// "simplexml_load_string" creates a SimpleXMLElement object for each
742+
// XML element with child elements. In turn, each child is indexed by
743+
// its tag in the SimpleXMLElement object. However, when there are
744+
// several child XML elements with the same tag, an array with all the
745+
// children with the same tag is indexed instead. Therefore, when the
746+
// XML contains
747+
// <XXX>
748+
// <element>
749+
// <label>...</label>
750+
// <value>...</value>
751+
// </element>
752+
// </XXX>
753+
// the "$elements[$shareeType]" variable contains an "element" key which
754+
// in turn contains "label" and "value" keys, but when the XML contains
755+
// <XXX>
756+
// <element>
757+
// <label>...</label>
758+
// <value>...</value>
759+
// </element>
760+
// <element>
761+
// <label>...</label>
762+
// <value>...</value>
763+
// </element>
764+
// </XXX>
765+
// the "$elements[$shareeType]" variable contains an "element" key which
766+
// in turn contains "0" and "1" keys, and in turn each one contains
767+
// "label" and "value" keys.
768+
if (array_key_exists('element', $elements[$shareeType]) && is_int(array_keys($elements[$shareeType]['element'])[0])) {
769+
$elements[$shareeType] = $elements[$shareeType]['element'];
770+
}
771+
735772
$sharees = [];
736773
foreach ($elements[$shareeType] as $element) {
737-
$sharees[] = [$element['label'], $element['value']['shareType'], $element['value']['shareWith']];
774+
$sharee = [$element['label'], $element['value']['shareType'], $element['value']['shareWith']];
775+
776+
if (array_key_exists('shareWithDisplayNameUnique', $element)) {
777+
$sharee[] = $element['shareWithDisplayNameUnique'];
778+
}
779+
780+
$sharees[] = $sharee;
738781
}
739782
return $sharees;
740783
}

build/integration/openldap_features/openldap-uid-username.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,5 @@ Feature: LDAP
161161
And the HTTP status code should be "200"
162162
And "exact users" sharees returned is empty
163163
And "users" sharees returned are
164-
| Elisa | 0 | elisa |
164+
| Elisa | 0 | elisa | elisa@nextcloud.ci |
165165
And "exact groups" sharees returned is empty

0 commit comments

Comments
 (0)