Skip to content

Commit

Permalink
Refactor get full url and headers with adding different scenarios for…
Browse files Browse the repository at this point in the history
… COPY request
  • Loading branch information
SagarGi committed Jul 11, 2022
1 parent 1e98c96 commit 7164b1a
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 22 deletions.
120 changes: 120 additions & 0 deletions tests/acceptance/features/apiSpaces/copySpaces.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Feature: copy file
| Alice |
| Brian |


Scenario Outline: Copying a file within a same space project with role manager and editor
Given the administrator has given "Alice" the role "Space Admin" using the settings api
And user "Alice" has created a space "Project" with the default quota using the GraphApi
Expand Down Expand Up @@ -68,6 +69,7 @@ Feature: copy file
| editor |
| viewer |


Scenario Outline: User copy a file from a space project with different role to a space project with editor role
Given the administrator has given "Brian" the role "Space Admin" using the settings api
And user "Brian" has created a space "Project1" with the default quota using the GraphApi
Expand Down Expand Up @@ -98,6 +100,7 @@ Feature: copy file
| editor |
| viewer |


Scenario Outline: User copy a file from space project with different role to shares jail with editor role
Given the administrator has given "Brian" the role "Space Admin" using the settings api
And user "Brian" has created a space "Project" with the default quota using the GraphApi
Expand Down Expand Up @@ -132,3 +135,120 @@ Feature: copy file
| manager |
| editor |
| viewer |


Scenario Outline: User copy a file from space personal to space project with different role role
Given the administrator has given "Brian" the role "Space Admin" using the settings api
And user "Brian" has created a space "Project" with the default quota using the GraphApi
And user "Brian" has shared a space "Project" to user "Alice" with role "<role>"
And user "Alice" has uploaded file with content "personal space content" to "/personal.txt"
When user "Alice" copies file "personal.txt" from space "Personal" to "personal.txt" inside space "Project" using the WebDAV API
Then the HTTP status code should be "201"
And for user "Alice" the content of the file "personal.txt" of the space "Project" should be "personal space content"
Examples:
| role |
| manager |
| editor |


Scenario: User copy a file from space personal to space project with different viewer role
Given the administrator has given "Brian" the role "Space Admin" using the settings api
And user "Brian" has created a space "Project" with the default quota using the GraphApi
And user "Brian" has shared a space "Project" to user "Alice" with role "viewer"
And user "Alice" has uploaded file with content "personal space content" to "/personal.txt"
When user "Alice" copies file "personal.txt" from space "Personal" to "personal.txt" inside space "Project" using the WebDAV API
Then the HTTP status code should be "403"


Scenario: User copy a file from space shares jail with role editor to space personal
Given the administrator has given "Brian" the role "Space Admin" using the settings api
And user "Brian" has created folder "/testshare"
And user "Brian" has uploaded file with content "testshare content" to "/testshare/testshare.txt"
And user "Brian" has shared folder "/testshare" with user "Alice" with permissions "31"
And user "Alice" has accepted share "/testshare" offered by user "Brian"
When user "Alice" copies file "/testshare/testshare.txt" from space "Shares Jail" to "testshare.txt" inside space "Personal" using the WebDAV API
Then the HTTP status code should be "201"
And the content of file "testshare.txt" for user "Alice" should be "testshare content"


Scenario: User copy a file from space shares jail with role viewer to space personal
Given the administrator has given "Brian" the role "Space Admin" using the settings api
And user "Brian" has created folder "/testshare"
And user "Brian" has uploaded file with content "testshare content" to "/testshare/testshare.txt"
And user "Brian" has shared folder "/testshare" with user "Alice" with permissions "17"
And user "Alice" has accepted share "/testshare" offered by user "Brian"
When user "Alice" copies file "/testshare/testshare.txt" from space "Shares Jail" to "testshare.txt" inside space "Personal" using the WebDAV API
Then the HTTP status code should be "403"


Scenario Outline: User copy a file from space shares jail with different role to space project with different role
Given the administrator has given "Brian" the role "Space Admin" using the settings api
And user "Brian" has created a space "Project" with the default quota using the GraphApi
And user "Brian" has shared a space "Project" to user "Alice" with role "<role>"
And user "Brian" has created folder "/testshare"
And user "Brian" has uploaded file with content "testshare content" to "/testshare/testshare.txt"
And user "Brian" has shared folder "/testshare" with user "Alice" with permissions "<permissions>"
And user "Alice" has accepted share "/testshare" offered by user "Brian"
When user "Alice" copies file "/testshare/testshare.txt" from space "Shares Jail" to "testshare.txt" inside space "Project" using the WebDAV API
Then the HTTP status code should be "201"
And for user "Alice" the content of the file "testshare.txt" of the space "Project" should be "testshare content"
Examples:
| role | permissions |
| manager | 31 |
| manager | 17 |
| editor | 31 |
| editor | 17 |


Scenario Outline: User copy a file from space shares jail with different role to space project with role viewer
Given the administrator has given "Brian" the role "Space Admin" using the settings api
And user "Brian" has created a space "Project" with the default quota using the GraphApi
And user "Brian" has shared a space "Project" to user "Alice" with role "viewer"
And user "Brian" has created folder "/testshare"
And user "Brian" has uploaded file with content "testshare content" to "/testshare/testshare.txt"
And user "Brian" has shared folder "/testshare" with user "Alice" with permissions "<permissions>"
And user "Alice" has accepted share "/testshare" offered by user "Brian"
When user "Alice" copies file "/testshare/testshare.txt" from space "Shares Jail" to "testshare.txt" inside space "Project" using the WebDAV API
Then the HTTP status code should be "403"
Examples:
| permissions |
| 31 |
| 17 |


Scenario Outline: User copy a file from space shares jail with different role to space shares jail with role editor
Given user "Brian" has created folder "/testshare1"
And user "Brian" has created folder "/testshare2"
And user "Brian" has uploaded file with content "testshare1 content" to "/testshare1/testshare1.txt"
And user "Brian" has shared folder "/testshare1" with user "Alice" with permissions "<permissions>"
And user "Brian" has shared folder "/testshare2" with user "Alice" with permissions "31"
And user "Alice" has accepted share "/testshare1" offered by user "Brian"
And user "Alice" has accepted share "/testshare2" offered by user "Brian"
When user "Alice" copies file "/testshare1/testshare1.txt" from space "Shares Jail" to "/testshare2/testshare1.txt" inside space "Shares Jail" using the WebDAV API
Then the HTTP status code should be "201"
And as "Alice" file "/Shares/testshare2/testshare1.txt" should exist
And as "Brian" file "/testshare2/testshare1.txt" should exist
And the content of file "/Shares/testshare2/testshare1.txt" for user "Alice" should be "testshare1 content"
And the content of file "/testshare2/testshare1.txt" for user "Brian" should be "testshare1 content"
Examples:
| permissions |
| 31 |
| 17 |


Scenario Outline: User copy a file from space shares jail with different role to space shares jail with role editor
Given user "Brian" has created folder "/testshare1"
And user "Brian" has created folder "/testshare2"
And user "Brian" has uploaded file with content "testshare1 content" to "/testshare1/testshare1.txt"
And user "Brian" has shared folder "/testshare1" with user "Alice" with permissions "<permissions>"
And user "Brian" has shared folder "/testshare2" with user "Alice" with permissions "17"
And user "Alice" has accepted share "/testshare1" offered by user "Brian"
And user "Alice" has accepted share "/testshare2" offered by user "Brian"
When user "Alice" copies file "/testshare1/testshare1.txt" from space "Shares Jail" to "/testshare2/testshare1.txt" inside space "Shares Jail" using the WebDAV API
Then the HTTP status code should be "403"
And as "Alice" file "/Shares/testshare2/testshare1.txt" should not exist
And as "Brian" file "/testshare2/testshare1.txt" should not exist
Examples:
| permissions |
| 31 |
| 17 |
70 changes: 48 additions & 22 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1745,6 +1745,7 @@ public function userCopiesFileUsingTheAPI(
* @param string $toSpaceName
*
* @return void
* @throws GuzzleException
*/
public function userCopiesFileFromAndToSpaceBetweenProjects(
string $user,
Expand All @@ -1753,28 +1754,8 @@ public function userCopiesFileFromAndToSpaceBetweenProjects(
string $fileDestination,
string $toSpaceName
):void {

// get headers
if($toSpaceName === "Personal"){
$headers['Destination'] = $this->destinationHeaderValueWithUserPersonalSpaceID(
$user,
$fileDestination,
);
} else {
$headers['Destination'] = $this->destinationHeaderValueWithSpaceName(
$user,
$fileDestination,
$toSpaceName
);
}

if($fromSpaceName === "Personal"){
$userPersonalSpaceID = $this->featureContext->getPersonalSpaceIdForUser($user, true);
$fullUrl = $this->baseUrl . "/dav/spaces/" . $userPersonalSpaceID . '/' . $fileSource;
}else {
$space = $this->getSpaceByName($user, $fromSpaceName);
$fullUrl = $this->baseUrl . "/dav/spaces/" . $space['id'] . '/' . $fileSource;
}
$headers['Destination'] = $this->getDestinationHeader($user, $fileDestination, $toSpaceName);
$fullUrl = $this->getFullUrlForSpaces($user, $fileSource, $fromSpaceName);
$this->copyFilesAndFoldersRequest($user, $fullUrl, $headers);
}

Expand All @@ -1794,6 +1775,51 @@ public function destinationHeaderValueWithSpaceName(string $user, string $fileDe
return \rtrim($fullUrl, '/') . '/' . \ltrim($fileDestination, '/');
}

/**
* get destination headers to copy or move file between spaces
*
* @param string $user
* @param string $fileDestination
* @param string $toSpaceName
*
* @return string
* @throws GuzzleException
*/
public function getDestinationHeader(string $user, string $fileDestination, string $toSpaceName):string {
if ($toSpaceName === "Personal") {
return $this->destinationHeaderValueWithUserPersonalSpaceID(
$user,
$fileDestination,
);
} else {
return $this->destinationHeaderValueWithSpaceName(
$user,
$fileDestination,
$toSpaceName
);
}
}

/**
* get fullurl to copy or move file between spaces
*
* @param string $user
* @param string $fileSource
* @param string $fromSpaceName
*
* @return string
* @throws GuzzleException
*/
public function getFullUrlForSpaces(string $user, string $fileSource, string $fromSpaceName):string {
if ($fromSpaceName === "Personal") {
$userPersonalSpaceID = $this->featureContext->getPersonalSpaceIdForUser($user, true);
return $this->baseUrl . "/dav/spaces/" . $userPersonalSpaceID . '/' . $fileSource;
} else {
$space = $this->getSpaceByName($user, $fromSpaceName);
return $this->baseUrl . "/dav/spaces/" . $space['id'] . '/' . $fileSource;
}
}

/**
* returns a url for destination with personal space id
*
Expand Down

0 comments on commit 7164b1a

Please sign in to comment.