Skip to content

Commit

Permalink
Merge pull request #2900 from owncloud/shareSpace
Browse files Browse the repository at this point in the history
[tests-only] ApiTest: share space
  • Loading branch information
phil-davis authored Dec 21, 2021
2 parents 30c0ffc + a8fc6ee commit 9483f53
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tests/acceptance/features/apiSpaces/changeSpaces.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Feature: Change data of space
Given user "Alice" has been created with default attributes and without skeleton files
And the administrator has given "Alice" the role "Admin" using the settings api

Scenario: Alice changes a name of the space via the Graph api, she expects a 204 code and checks that the space name has changed
Scenario: Alice changes a name of the space via the Graph api, she expects a 200 code and checks that the space name has changed
Given user "Alice" has created a space "Project Jupiter" of type "project" with quota "20"
When user "Alice" changes the name of the "Project Jupiter" space to "Project Death Star"
Then the HTTP status code should be "200"
Expand All @@ -22,7 +22,7 @@ Feature: Change data of space
| quota@@@total | 20 |
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |

Scenario: Alice increases quota of the space via the Graph api, she expects a 204 code and checks that the quota has changed
Scenario: Alice increases quota of the space via the Graph api, she expects a 200 code and checks that the quota has changed
Given user "Alice" has created a space "Project Earth" of type "project" with quota "20"
When user "Alice" changes the quota of the "Project Earth" space to "100"
Then the HTTP status code should be "200"
Expand Down
63 changes: 63 additions & 0 deletions tests/acceptance/features/apiSpaces/shareSpaces.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
@api @skipOnOcV10
Feature: Share spaces
As the owner of a space
I want to be able to add members to a space, and to remove access for them

Note - this feature is run in CI with ACCOUNTS_HASH_DIFFICULTY set to the default for production
See https://github.com/owncloud/ocis/issues/1542 and https://github.com/owncloud/ocis/pull/839

Background:
Given user "Alice" has been created with default attributes and without skeleton files
And user "Brian" has been created with default attributes and without skeleton files
And the administrator has given "Alice" the role "Admin" using the settings api


Scenario: Alice shares space to Brian, she expects a 200 response code
Given user "Alice" has created a space "Space to share" of type "project" with quota "10"
When user "Alice" shares a space "Space to share" to user "Brian"
Then the HTTP status code should be "200"


Scenario: Brian checks that a shared space is available
Given user "Alice" has created a space "Share space to Brian" of type "project" with quota "10"
And user "Alice" has shared a space "Share space to Brian" to user "Brian"
When user "Brian" lists all available spaces via the GraphApi
Then the json responded should contain a space "Share space to Brian" with these key and value pairs:
| key | value |
| driveType | share |
| id | %space_id% |
| name | Share space to Brian |
| quota@@@state | normal |
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |


Scenario: Brian can see files in shared space
Given user "Alice" has created a space "Share space with file" of type "project" with quota "10"
And user "Alice" has uploaded a file inside space "Share space with file" with content "Test" to "test.txt"
When user "Alice" has shared a space "Share space with file" to user "Brian"
Then for user "Brian" the space "Share space with file" should contain these entries:
| test.txt |


Scenario: Brian can see folder in shared space
Given user "Alice" has created a space "Share space with folder" of type "project" with quota "10"
And user "Alice" has created a folder "Folder Main" in space "Share space with folder"
When user "Alice" has shared a space "Share space with folder" to user "Brian"
Then for user "Brian" the space "Share space with folder" should contain these entries:
| Folder Main |


Scenario: When Alice unshares space, the space becomes unavailable to Brian
Given user "Alice" has created a space "Unshare space" of type "project" with quota "10"
And user "Alice" has shared a space "Unshare space" to user "Brian"
When user "Brian" lists all available spaces via the GraphApi
Then the json responded should contain a space "Unshare space" with these key and value pairs:
| key | value |
| driveType | share |
| id | %space_id% |
| name | Unshare space |
When user "Alice" unshares a space "Unshare space" to user "Brian"
Then the HTTP status code should be "200"
And user "Brian" lists all available spaces via the GraphApi
And the json responded should not contain a space "Unshare space"

134 changes: 134 additions & 0 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,20 @@ public function jsonRespondedShouldContain(
}
}

/**
* @Then /^the json responded should not contain a space "([^"]*)"$/
*
* @param string $spaceName
*
* @return void
* @throws Exception
*/
public function jsonRespondedShouldNotContain(
string $spaceName
): void {
Assert::assertEmpty($this->getSpaceByNameFromResponse($spaceName), "space $spaceName should not be available for a user");
}

/**
* @param string $shouldOrNot (not|)
* @param TableNode $expectedFiles
Expand Down Expand Up @@ -819,6 +833,44 @@ public function theUserCreatesAFolderUsingTheGraphApi(
);
}

/**
* @Given /^user "([^"]*)" has created a folder "([^"]*)" in space "([^"]*)"$/
*
* @param string $user
* @param string $folder
* @param string $spaceName
*
* @return void
*
* @throws GuzzleException
*/
public function theUserHasCreateAFolderUsingTheGraphApi(
string $user,
string $folder,
string $spaceName
): void {
$space = $this->getSpaceByName($user, $spaceName);

$baseUrl = $this->featureContext->getBaseUrl();
if (!str_ends_with($baseUrl, '/')) {
$baseUrl .= '/';
}
$fullUrl = $baseUrl . "dav/spaces/" . $space['id'] . '/' . $folder;

$this->featureContext->setResponse(
$this->sendCreateFolderRequest(
$fullUrl,
"MKCOL",
$user,
$this->featureContext->getPasswordForUser($user)
)
);
$this->featureContext->theHTTPStatusCodeShouldBe(
201,
"Expected response status code should be 201"
);
}

/**
* @When /^user "([^"]*)" creates a folder "([^"]*)" in space "([^"]*)" owned by the user "([^"]*)" using the WebDav Api$/
*
Expand Down Expand Up @@ -1108,4 +1160,86 @@ public function userHasUploadedFile(string $user, string $spaceName, string $fil

$this->featureContext->theHTTPStatusCodeShouldBeOr(201, 204);
}

/**
* @When /^user "([^"]*)" shares a space "([^"]*)" to user "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
* @param string $userRecipient
*
* @throws GuzzleException
*/
public function sendShareSpaceRequest(
string $user,
string $spaceName,
string $userRecipient
): ResponseInterface {
$space = $this->getSpaceByName($user, $spaceName);
$body = ["space_ref" => $space['id'], "shareType" => 7, "shareWith" => $userRecipient];

$baseUrl = $this->featureContext->getBaseUrl();
if (!str_ends_with($baseUrl, '/')) {
$baseUrl .= '/';
}
$fullUrl = $baseUrl . "ocs/v2.php/apps/files_sharing/api/v1/shares";

return HttpRequestHelper::post($fullUrl, "", $user, $this->featureContext->getPasswordForUser($user), [], $body);
}

/**
* @Given /^user "([^"]*)" has shared a space "([^"]*)" to user "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
* @param string $userRecipient
*
* @throws GuzzleException
*/
public function userHasSharedSpace(
string $user,
string $spaceName,
string $userRecipient
): ResponseInterface {
$space = $this->getSpaceByName($user, $spaceName);
$body = ["space_ref" => $space['id'], "shareType" => 7, "shareWith" => $userRecipient];

$baseUrl = $this->featureContext->getBaseUrl();
if (!str_ends_with($baseUrl, '/')) {
$baseUrl .= '/';
}
$fullUrl = $baseUrl . "ocs/v2.php/apps/files_sharing/api/v1/shares";

return HttpRequestHelper::post($fullUrl, "", $user, $this->featureContext->getPasswordForUser($user), [], $body);

$this->featureContext->theHTTPStatusCodeShouldBe(
200,
"Expected response status code should be 200"
);
$this->OCSContext->theOCSStatusCodeShouldBe(400, "Expected OCS response status code should be 200");
}

/**
* @When /^user "([^"]*)" unshares a space "([^"]*)" to user "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
* @param string $userRecipient
*
* @throws GuzzleException
*/
public function sendUnshareSpaceRequest(
string $user,
string $spaceName,
string $userRecipient
): ResponseInterface {
$space = $this->getSpaceByName($user, $spaceName);
$baseUrl = $this->featureContext->getBaseUrl();
if (!str_ends_with($baseUrl, '/')) {
$baseUrl .= '/';
}
$fullUrl = $baseUrl . "ocs/v2.php/apps/files_sharing/api/v1/shares/" . $space['id'] . "?shareWith=" . $userRecipient;

return HttpRequestHelper::delete($fullUrl, "", $user, $this->featureContext->getPasswordForUser($user));
}
}

0 comments on commit 9483f53

Please sign in to comment.