From 2675e739b20ecc3334e78db24e1933995b788ecd Mon Sep 17 00:00:00 2001 From: Prarup Gurung Date: Wed, 24 Jan 2024 14:34:06 +0545 Subject: [PATCH] Added test for sending share invitation to wrong objectId --- .../apiSharingNg/shareInvitations.feature | 50 +++++++++++++++++++ .../features/bootstrap/SharingNgContext.php | 23 +++++---- 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/tests/acceptance/features/apiSharingNg/shareInvitations.feature b/tests/acceptance/features/apiSharingNg/shareInvitations.feature index 368e34dd9f..a865b26a31 100644 --- a/tests/acceptance/features/apiSharingNg/shareInvitations.feature +++ b/tests/acceptance/features/apiSharingNg/shareInvitations.feature @@ -1192,3 +1192,53 @@ Feature: Send a sharing invitations | Viewer | folder | FolderToShare | | Editor | folder | FolderToShare | | Uploader | folder | FolderToShare | + + + Scenario Outline: send share invitation to wrong user id with different roles + Given user "Alice" has uploaded file with content "to share" to "/textfile1.txt" + And user "Alice" has created folder "FolderToShare" + When user "Alice" tries to send the following share invitation using the Graph API: + | resourceType | | + | resource | | + | space | Personal | + | shareeId | a4c0c83e-ae24-4870-93c3-fcaf2a2228f7 | + | shareType | user | + | permissionsRole | | + Then the HTTP status code should be "400" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "type": "object", + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "string", + "pattern": "generalException" + }, + "message": { + "type": "string", + "enum": [ + "itemNotFound: not found" + ] + } + } + } + } + } + """ + Examples: + | permissions-role | resource-type | path | + | Viewer | file | /textfile1.txt | + | File Editor | file | /textfile1.txt | + | Viewer | folder | FolderToShare | + | Editor | folder | FolderToShare | + | Uploader | folder | FolderToShare | diff --git a/tests/acceptance/features/bootstrap/SharingNgContext.php b/tests/acceptance/features/bootstrap/SharingNgContext.php index 7e16a7356f..09300c2a55 100644 --- a/tests/acceptance/features/bootstrap/SharingNgContext.php +++ b/tests/acceptance/features/bootstrap/SharingNgContext.php @@ -156,16 +156,20 @@ class SharingNgContext implements Context { : $this->spacesContext->getFileId($user, $rows['space'], $rows['resource']); } - $sharees = array_map('trim', explode(',', $rows['sharee'])); - $shareTypes = array_map('trim', explode(',', $rows['shareType'])); + if (\array_key_exists('shareeId', $rows)) { + $shareeIds[] = $rows['shareeId']; + $shareTypes[] = $rows['shareType']; + } else { + $sharees = array_map('trim', explode(',', $rows['sharee'])); + $shareTypes = array_map('trim', explode(',', $rows['shareType'])); - $shareeIds = []; - foreach ($sharees as $index => $sharee) { - $shareType = $shareTypes[$index]; - // for non-exiting group or user, generate random id - $shareeIds[] = (($shareType === 'user') - ? $this->featureContext->getAttributeOfCreatedUser($sharee, 'id') - : $this->featureContext->getAttributeOfCreatedGroup($sharee, 'id')) ?: WebDavHelper::generateUUIDv4(); + foreach ($sharees as $index => $sharee) { + $shareType = $shareTypes[$index]; + // for non-exiting group or user, generate random id + $shareeIds[] = (($shareType === 'user') + ? $this->featureContext->getAttributeOfCreatedUser($sharee, 'id') + : $this->featureContext->getAttributeOfCreatedGroup($sharee, 'id')) ?: WebDavHelper::generateUUIDv4(); + } } $permissionsRole = $rows['permissionsRole'] ?? null; @@ -208,6 +212,7 @@ class SharingNgContext implements Context { /** * @When /^user "([^"]*)" sends the following share invitation using the Graph API:$/ + * @When /^user "([^"]*)" tries to send the following share invitation using the Graph API:$/ * * @param string $user * @param TableNode $table