Skip to content

Commit 603d61e

Browse files
authored
Merge pull request #11336 from owncloud/test/enable-disable-share-sync
[tests-only][full-ci] add API test to enable share sync after disabling
2 parents 688e956 + d790d87 commit 603d61e

File tree

5 files changed

+109
-25
lines changed

5 files changed

+109
-25
lines changed

tests/acceptance/TestHelpers/GraphHelper.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,6 @@ public static function hideOrUnhideShare(
20092009
* @param string $user
20102010
* @param string $password
20112011
* @param string $itemId
2012-
* @param string $shareSpaceId
20132012
*
20142013
* @return ResponseInterface
20152014
* @throws GuzzleException
@@ -2019,14 +2018,13 @@ public static function enableShareSync(
20192018
string $user,
20202019
string $password,
20212020
string $itemId,
2022-
string $shareSpaceId,
20232021
): ResponseInterface {
20242022
$body = [
20252023
"remoteItem" => [
20262024
"id" => $itemId,
20272025
],
20282026
];
2029-
$url = self::getBetaFullUrl($baseUrl, "drives/$shareSpaceId/root/children");
2027+
$url = self::getBetaFullUrl($baseUrl, "drives/" . GraphHelper::SHARES_SPACE_ID . "/root/children");
20302028
return HttpRequestHelper::post(
20312029
$url,
20322030
$user,

tests/acceptance/bootstrap/SettingsContext.php

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
class SettingsContext implements Context {
2828
private FeatureContext $featureContext;
29-
private string $settingsUrl = '/api/v0/settings/';
29+
private array $autoAcceptSharesSettingIds = [];
3030

3131
/**
3232
* This will run before EVERY scenario.
@@ -45,6 +45,29 @@ public function before(BeforeScenarioScope $scope): void {
4545
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
4646
}
4747

48+
/**
49+
* @param string $user
50+
*
51+
* @return string
52+
*/
53+
public function getAutoAcceptShareSettingId(string $user): string {
54+
if (!empty($this->autoAcceptSharesSettingIds) && \array_key_exists($user, $this->autoAcceptSharesSettingIds)) {
55+
return $this->autoAcceptSharesSettingIds[$user];
56+
57+
}
58+
return '';
59+
}
60+
61+
/**
62+
* @param string $user
63+
* @param string $id
64+
*
65+
* @return void
66+
*/
67+
public function setAutoAcceptShareSettingId(string $user, string $id): void {
68+
$this->autoAcceptSharesSettingIds[$user] = $id;
69+
}
70+
4871
/**
4972
* @param string $user
5073
*
@@ -487,27 +510,38 @@ public function userSwitchesTheSystemLanguageUsingTheSettingsApi(string $user, s
487510
* @throws Exception
488511
*/
489512
public function toggleAutoAcceptSharesSetting(string $user, bool $status): ResponseInterface {
490-
$body = json_encode(
491-
[
492-
"value" => [
493-
"account_uuid" => "me",
494-
"bundleId" => SettingsHelper::getBundleId(),
495-
"settingId" => SettingsHelper::getSettingIdUsingEventName("Auto Accept Shares"),
496-
"resource" => [
497-
"type" => "TYPE_USER",
498-
],
499-
"boolValue" => $status,
513+
$body = [
514+
"value" => [
515+
"account_uuid" => "me",
516+
"bundleId" => SettingsHelper::getBundleId(),
517+
"settingId" => SettingsHelper::getSettingIdUsingEventName("Auto Accept Shares"),
518+
"resource" => [
519+
"type" => "TYPE_USER",
500520
],
521+
"boolValue" => $status,
501522
],
502-
JSON_THROW_ON_ERROR,
503-
);
523+
];
524+
$autoAcceptSharesSettingId = $this->getAutoAcceptShareSettingId($user);
525+
if ($autoAcceptSharesSettingId) {
526+
// use existing id if available
527+
$body["value"]["id"] = $autoAcceptSharesSettingId;
528+
}
529+
$body = json_encode($body, JSON_THROW_ON_ERROR);
504530

505-
return SettingsHelper::updateSettings(
531+
$response = SettingsHelper::updateSettings(
506532
$this->featureContext->getBaseUrl(),
507533
$user,
508534
$this->featureContext->getPasswordForUser($user),
509535
$body,
510536
);
537+
if (!$autoAcceptSharesSettingId && $response->getStatusCode() === 201) {
538+
// save id for future use
539+
// updating the setting without id will create a new setting entry
540+
$data = $this->featureContext->getJsonDecodedResponseBodyContent($response);
541+
$this->setAutoAcceptShareSettingId($user, $data->value->value->id);
542+
}
543+
$response->getBody()->rewind();
544+
return $response;
511545
}
512546

513547
/**

tests/acceptance/bootstrap/SharingNgContext.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,13 +1512,11 @@ public function userEnablesSyncOfShareUsingTheGraphApi(
15121512
): void {
15131513
$share = ltrim($share, '/');
15141514
$itemId = $this->spacesContext->getResourceId($offeredBy, $space, $share);
1515-
$shareSpaceId = GraphHelper::SHARES_SPACE_ID;
15161515
$response = GraphHelper::enableShareSync(
15171516
$this->featureContext->getBaseUrl(),
15181517
$this->featureContext->getActualUsername($user),
15191518
$this->featureContext->getPasswordForUser($user),
15201519
$itemId,
1521-
$shareSpaceId,
15221520
);
15231521
$this->featureContext->setResponse($response);
15241522
}
@@ -1542,7 +1540,6 @@ public function userEnablesSyncOfFederatedShareUsingTheGraphApi(
15421540
$this->featureContext->getActualUsername($user),
15431541
$this->featureContext->getPasswordForUser($user),
15441542
$remoteItemId,
1545-
GraphHelper::SHARES_SPACE_ID,
15461543
);
15471544
$this->featureContext->setResponse($response);
15481545
}
@@ -1560,15 +1557,13 @@ public function userEnablesSyncOfFederatedShareUsingTheGraphApi(
15601557
* @throws Exception|GuzzleException
15611558
*/
15621559
public function userTriesToEnableShareSyncOfResourceUsingTheGraphApi(string $user, string $resource): void {
1563-
$shareSpaceId = GraphHelper::SHARES_SPACE_ID;
15641560
$itemId = ($resource === 'nonexistent') ? WebDavHelper::generateUUIDv4() : $resource;
15651561

15661562
$response = GraphHelper::enableShareSync(
15671563
$this->featureContext->getBaseUrl(),
15681564
$this->featureContext->getActualUsername($user),
15691565
$this->featureContext->getPasswordForUser($user),
15701566
$itemId,
1571-
$shareSpaceId,
15721567
);
15731568
$this->featureContext->setResponse($response);
15741569
}

tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ The expected failures in this file are from features in the owncloud/ocis repo.
2121

2222
#### [Settings service user can list other peoples assignments](https://github.com/owncloud/ocis/issues/5032)
2323

24-
- [apiSettings/settings.feature:125](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSettings/settings.feature#L125)
25-
- [apiSettings/settings.feature:126](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSettings/settings.feature#L126)
26-
- [apiSettings/settings.feature:127](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSettings/settings.feature#L127)
24+
- [apiSettings/settings.feature:182](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSettings/settings.feature#L182)
25+
- [apiSettings/settings.feature:183](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSettings/settings.feature#L183)
26+
- [apiSettings/settings.feature:184](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSettings/settings.feature#L184)
2727

2828
#### [A User can get information of another user with Graph API](https://github.com/owncloud/ocis/issues/5125)
2929

tests/acceptance/features/apiSettings/settings.feature

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,63 @@ Feature: settings api
6666
| permissionsRole | Viewer |
6767
Then user "Brian" should have sync disabled for share "textfile.txt"
6868

69+
@issue-11335
70+
Scenario: enable auto-sync-shares after disabling it
71+
Given user "Alice" has uploaded file with content "lorem epsum" to "textfile.txt"
72+
And user "Brian" has disabled the auto-sync share
73+
When user "Brian" enables the auto-sync share using the settings API
74+
Then the HTTP status code should be "201"
75+
And the JSON data of the response should match
76+
"""
77+
{
78+
"type": "object",
79+
"required": ["value"],
80+
"properties": {
81+
"value" : {
82+
"type": "object",
83+
"required": ["identifier","value"],
84+
"properties": {
85+
"identifier": {
86+
"type": "object",
87+
"required": ["extension", "bundle", "setting"],
88+
"properties": {
89+
"extension": { "const": "ocis-accounts" },
90+
"bundle": { "const": "profile" },
91+
"setting": { "const": "auto-accept-shares" }
92+
}
93+
},
94+
"value": {
95+
"type": "object",
96+
"required": ["id", "bundleId", "settingId", "accountUuid", "resource", "boolValue"],
97+
"properties": {
98+
"id": { "pattern": "^%user_id_pattern%$" },
99+
"bundleId": { "pattern": "^%user_id_pattern%$" },
100+
"settingId": { "pattern": "^%user_id_pattern%$" },
101+
"accountUuid": { "pattern": "^%user_id_pattern%$" },
102+
"resource": {
103+
"type": "object",
104+
"required": ["type"],
105+
"properties": {
106+
"type": { "const": "TYPE_USER" }
107+
}
108+
},
109+
"boolValue": { "const": true }
110+
}
111+
}
112+
}
113+
}
114+
}
115+
}
116+
"""
117+
And for user "Brian" setting "auto-accept-shares" should have value "true"
118+
Given user "Alice" has sent the following resource share invitation:
119+
| resource | textfile.txt |
120+
| space | Personal |
121+
| sharee | Brian |
122+
| shareType | user |
123+
| permissionsRole | Viewer |
124+
Then user "Brian" should have sync enabled for share "textfile.txt"
125+
69126

70127
Scenario: assign role to user
71128
When user "Admin" assigns the role "Admin" to user "Alice" using the settings API

0 commit comments

Comments
 (0)