Skip to content

Commit

Permalink
Merge pull request #10149 from owncloud/enableOcmSharingTests
Browse files Browse the repository at this point in the history
[test-only] adjust ocm sharing tests
  • Loading branch information
ScharfViktor authored Sep 25, 2024
2 parents 6153653 + 99ecc5a commit 78095bc
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 43 deletions.
30 changes: 17 additions & 13 deletions tests/acceptance/bootstrap/GraphContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2538,15 +2538,16 @@ public function userSwitchesTheSystemLanguageUsingGraphApi(string $user, string
}

/**
* @When /^user "([^"]*)" lists the shares shared with (?:him|her)(| after clearing user cache) using the Graph API$/
* @When /^user "([^"]*)" lists the shares shared with (?:him|her)(| after clearing user cache)(| without retry) using the Graph API$/
*
* @param string $user
* @param string $cacheStepString
* @param string $retryOption
*
* @return void
* @throws GuzzleException
*/
public function userListsTheResourcesSharedWithThemUsingGraphApi(string $user, string $cacheStepString): void {
public function userListsTheResourcesSharedWithThemUsingGraphApi(string $user, string $cacheStepString, string $retryOption): void {
if ($cacheStepString !== '') {
// ENV (GRAPH_SPACES_GROUPS_CACHE_TTL | GRAPH_SPACES_USERS_CACHE_TTL) is set default to 60 sec
// which means 60 sec is required to clean up all the user|group cache once they are deleted
Expand All @@ -2559,6 +2560,7 @@ public function userListsTheResourcesSharedWithThemUsingGraphApi(string $user, s
// Sometimes listing shares might not return the updated shares list
// so try again until @client.synchronize is true for the max. number of retries (i.e. 10)
// and do not retry when the share is expected to be not synced
$retryEnabled = ($retryOption === '');
$tryAgain = false;
$retried = 0;
do {
Expand All @@ -2571,17 +2573,19 @@ public function userListsTheResourcesSharedWithThemUsingGraphApi(string $user, s

$jsonBody = $this->featureContext->getJsonDecodedResponseBodyContent($response);

foreach ($jsonBody->value as $share) {
$autoSync = $this->featureContext->getUserAutoSyncSetting($credentials['username']);
$tryAgain = !$share->{'@client.synchronize'} && $autoSync && $retried < HttpRequestHelper::numRetriesOnHttpTooEarly();

if ($tryAgain) {
$retried += 1;
echo "auto-sync share for user '$user' is enabled\n";
echo "but share '$share->name' was not auto-synced, retrying ($retried)...\n";
// wait 500ms and try again
\usleep(500 * 1000);
break;
if ($retryEnabled) {
foreach ($jsonBody->value as $share) {
$autoSync = $this->featureContext->getUserAutoSyncSetting($credentials['username']);
$tryAgain = !$share->{'@client.synchronize'} && $autoSync && $retried < HttpRequestHelper::numRetriesOnHttpTooEarly();

if ($tryAgain) {
$retried += 1;
echo "auto-sync share for user '$user' is enabled\n";
echo "but share '$share->name' was not auto-synced, retrying ($retried)...\n";
// wait 500ms and try again
\usleep(500 * 1000);
break;
}
}
}
} while ($tryAgain);
Expand Down
24 changes: 23 additions & 1 deletion tests/acceptance/bootstrap/SharingNgContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,15 @@ public function userTriesToListThePermissionsOfSpaceUsingPermissionsEndpointOfTh
* @param string $user
* @param array $shareInfo
* @param string|null $fileId
* @param bool $isFederated
*
* @return ResponseInterface
*
* @throws JsonException
* @throws GuzzleException
* @throws Exception
*/
public function sendShareInvitation(string $user, array $shareInfo, string $fileId = null): ResponseInterface {
public function sendShareInvitation(string $user, array $shareInfo, string $fileId = null, $isFederated = false): ResponseInterface {
if ($shareInfo['space'] === 'Personal' || $shareInfo['space'] === 'Shares') {
$space = $this->spacesContext->getSpaceByName($user, $shareInfo['space']);
} else {
Expand Down Expand Up @@ -282,6 +283,9 @@ public function sendShareInvitation(string $user, array $shareInfo, string $file
$shareeId = "";
if ($shareType === "user") {
$shareeId = $this->featureContext->getAttributeOfCreatedUser($sharee, 'id');
if ($isFederated) {
$shareeId = base64_encode($shareeId . $shareInfo['federatedServer']);
}
} elseif ($shareType === "group") {
$shareeId = $this->featureContext->getAttributeOfCreatedGroup($sharee, 'id');
}
Expand Down Expand Up @@ -426,6 +430,24 @@ public function userSendsTheFollowingResourceShareInvitationUsingTheGraphApi(str
);
}

/**
* @When /^user "([^"]*)" sends the following resource share invitation to federated user using the Graph API:$/
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function userSendsTheFollowingResourceShareInvitationTofederatedUserUsingTheGraphApi(string $user, TableNode $table): void {
$rows = $table->getRowsHash();
Assert::assertArrayHasKey("resource", $rows, "'resource' should be provided in the data-table while sharing a resource");
$this->featureContext->setResponse(
$this->sendShareInvitation($user, $rows, null, true)
);
}

/**
* @When /^user "([^"]*)" sends the following space share invitation using permissions endpoint of the Graph API:$/
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,6 @@ The expected failures in this file are from features in the owncloud/ocis repo.
- [apiSpacesDavOperation/moveByFileId.feature:492](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesDavOperation/moveByFileId.feature#L492)
- [apiSpacesDavOperation/moveByFileId.feature:493](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesDavOperation/moveByFileId.feature#L493)

#### [OCM. sharing issues](https://github.com/owncloud/ocis/issues/9534)

- [apiOcm/share.feature:12](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiOcm/share.feature#L12)
- [apiOcm/share.feature:91](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiOcm/share.feature#L91)

#### [OCM. admin cannot get federated users if he hasn't connection with them ](https://github.com/owncloud/ocis/issues/9829)

tests/acceptance/features/apiOcm/searchFederationUsers.feature
Expand Down
58 changes: 34 additions & 24 deletions tests/acceptance/features/apiOcm/share.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ Feature: an user shares resources usin ScienceMesh application
And "Brian" has accepted invitation
And using server "LOCAL"
And user "Alice" has created folder "folderToShare"
When user "Alice" sends the following resource share invitation using the Graph API:
| resource | folderToShare |
| space | Personal |
| sharee | Brian |
| shareType | user |
| permissionsRole | Viewer |
When user "Alice" sends the following resource share invitation to federated user using the Graph API:
| resource | folderToShare |
| space | Personal |
| sharee | Brian |
| shareType | user |
| permissionsRole | Viewer |
| federatedServer | @federation-ocis-server:10200 |
Then the HTTP status code should be "200"
When using server "REMOTE"
And user "Brian" lists the shares shared with him using the Graph API
And user "Brian" lists the shares shared with him without retry using the Graph API
Then the HTTP status code should be "200"
And the JSON data of the response should match
"""
Expand All @@ -47,13 +48,13 @@ Feature: an user shares resources usin ScienceMesh application
"name"
],
"properties": {
"@UI.Hidden":{
"@UI.Hidden": {
"type": "boolean",
"enum": [false]
},
"@client.synchronize":{
"@client.synchronize": {
"type": "boolean",
"enum": [true]
"enum": [false]
},
"createdBy": {
"type": "object",
Expand All @@ -63,15 +64,18 @@ Feature: an user shares resources usin ScienceMesh application
"properties": {
"user": {
"type": "object",
"required": ["displayName", "id"],
"required": [
"displayName",
"id"
],
"properties": {
"displayName": {
"type": "string",
"const": "Alice Hansen"
},
"id": {
"type": "string",
"pattern": "^%user_id_pattern%$"
"pattern": "^%federated_user_id_pattern%$"
}
}
}
Expand All @@ -94,12 +98,13 @@ Feature: an user shares resources usin ScienceMesh application
And using server "REMOTE"
And "Brian" has accepted invitation
And user "Brian" has created folder "folderToShare"
When user "Brian" sends the following resource share invitation using the Graph API:
| resource | folderToShare |
| space | Personal |
| sharee | Alice |
| shareType | user |
| permissionsRole | Viewer |
When user "Brian" sends the following resource share invitation to federated user using the Graph API:
| resource | folderToShare |
| space | Personal |
| sharee | Alice |
| shareType | user |
| permissionsRole | Viewer |
| federatedServer | @ocis-server:9200 |
Then the HTTP status code should be "200"
When using server "LOCAL"
And user "Alice" lists the shares shared with her using the Graph API
Expand All @@ -125,11 +130,13 @@ Feature: an user shares resources usin ScienceMesh application
"name"
],
"properties": {
"@UI.Hidden":{
"const": "false"
"@UI.Hidden": {
"type": "boolean",
"enum": [false]
},
"@client.synchronize":{
"const": "true"
"@client.synchronize": {
"type": "boolean",
"enum": [false]
},
"createdBy": {
"type": "object",
Expand All @@ -139,14 +146,17 @@ Feature: an user shares resources usin ScienceMesh application
"properties": {
"user": {
"type": "object",
"required": ["displayName", "id"],
"required": [
"displayName",
"id"
],
"properties": {
"displayName": {
"const": "Brian Murphy"
},
"id": {
"type": "string",
"pattern": "^%user_id_pattern%$"
"pattern": "^%federated_user_id_pattern%$"
}
}
}
Expand Down

0 comments on commit 78095bc

Please sign in to comment.