Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApiTest. search entity from project space and shares jail #4054

Merged
merged 2 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .drone.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The test runner source for API tests
CORE_COMMITID=ca4294642f8391dd3f294e0bfd8277fa0ca478f5
CORE_COMMITID=7e9caa446346426de197b475e03be19dfe367a54
CORE_BRANCH=master

# The test runner source for UI tests
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ default:
- FilesVersionsContext:
- OCSContext:
- PublicWebDavContext:
- SearchContext:
- TrashbinContext:
- WebDavPropertiesContext:
- TusContext:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ The expected failures in this file are from features in the owncloud/ocis repo.
- [apiArchiver/downloadById.feature:134](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/downloadById.feature#L134)
- [apiArchiver/downloadById.feature:135](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiArchiver/downloadById.feature#L135)

### [Search by shares jail works incorrect](https://github.com/owncloud/ocis/issues/4014)
- [apiSpaces/search.feature:43](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/search.feature#L43)
54 changes: 54 additions & 0 deletions tests/acceptance/features/apiSpaces/search.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
@api @skipOnOcV10
Feature: Search
It is possible to search files in the shares jail and the project space

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 these users have been created with default attributes and without skeleton files:
| username |
| Alice |
| Brian |
And using new DAV path
And the administrator has given "Alice" the role "Admin" using the settings api
And user "Alice" has created a space "find data" with the default quota using the GraphApi
And user "Alice" has created a folder "folder/SubFolder1/subFOLDER2" in space "find data"
And user "Alice" has uploaded a file inside space "find data" with content "some content" to "folder/SubFolder1/subFOLDER2/insideTheFolder.txt"


Scenario: Alice can find data from the project space
When user "Alice" searches for "fol" using the WebDAV API
Then the HTTP status code should be "207"
And the search result should contain "4" entries
And the search result of user "Alice" should contain these entries:
| /folder |
| /folder/SubFolder1 |
| /folder/SubFolder1/subFOLDER2 |
| /folder/SubFolder1/subFOLDER2/insideTheFolder.txt |


Scenario: Alice can find data from the project space
When user "Alice" searches for "SUB" using the WebDAV API
Then the HTTP status code should be "207"
And the search result should contain "2" entries
And the search result of user "Alice" should contain these entries:
| /folder/SubFolder1 |
| /folder/SubFolder1/subFOLDER2 |
But the search result of user "Alice" should not contain these entries:
| /folder |
| /folder/SubFolder1/subFOLDER2/insideTheFolder.txt |


Scenario: Brian can find data from the shares jail
Given user "Alice" shares the following entity "folder" inside of space "find data" with user "Brian" with role "viewer"
And user "Brian" has accepted share "/folder" offered by user "Alice"
When user "Brian" searches for "folder" using the WebDAV API
Then the HTTP status code should be "207"
And the search result should contain "4" entries
And the search result of user "Brian" should contain these entries:
| /folder |
| /folder/SubFolder1 |
| /folder/SubFolder1/subFOLDER2 |
| /folder/SubFolder1/subFOLDER2/insideTheFolder.txt |

62 changes: 32 additions & 30 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,15 @@ public function getETag(string $user, string $spaceName, string $fileName): stri
* @throws Exception|GuzzleException
*/
public function getUserIdByUserName(string $userName): string {
$this->featureContext->setResponse(GraphHelper::getUser(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
$userName
));
$this->featureContext->setResponse(
GraphHelper::getUser(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
$userName
)
);
if ($this->featureContext->getResponse()) {
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
$response = \json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR);
Expand Down Expand Up @@ -369,21 +371,20 @@ public function setUpScenario(BeforeScenarioScope $scope): void {
*
* @throws Exception|GuzzleException
*/
public function cleanDataAfterTests(): void
{
public function cleanDataAfterTests(): void {
$this->deleteAllSpacesOfTheType('project');
}

/**
* The method first disables and then deletes spaces
*
* @param string $driveType
*
* @return void
*
* @throws Exception|GuzzleException
*/
public function deleteAllSpacesOfTheType(string $driveType): void
{
public function deleteAllSpacesOfTheType(string $driveType): void {
Comment on lines -385 to +387
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we run PHP lint here? this should have been caught by CI

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran make test-php-style-fix and got No fixable errors were found

$query = "\$filter=driveType eq $driveType";
$userAdmin = $this->featureContext->getAdminUsername();

Expand All @@ -401,7 +402,7 @@ public function deleteAllSpacesOfTheType(string $driveType): void

if (!empty($drives)) {
foreach ($drives as $value) {
if (!array_key_exists("deleted", $value["root"])) {
if (!\array_key_exists("deleted", $value["root"])) {
$this->sendDisableSpaceRequest($userAdmin, $value["name"]);
} else {
$this->sendDeleteSpaceRequest($userAdmin, $value["name"]);
Expand Down Expand Up @@ -744,13 +745,15 @@ public function theAdministratorGivesUserTheRole(string $user, string $role): vo
}
Assert::assertNotEmpty($roleToAssign, "The selected role $role could not be found");

$this->featureContext->setResponse(GraphHelper::getUser(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
$user
));
$this->featureContext->setResponse(
GraphHelper::getUser(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
$user
)
);
if ($this->featureContext->getResponse()) {
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
if (isset(\json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR)["id"])) {
Expand Down Expand Up @@ -2228,6 +2231,7 @@ public function userRestoresSpaceObjectsFromTrashRequest(

/**
* User downloads a preview of the file inside the project space
*
* @When /^user "([^"]*)" downloads the preview of "([^"]*)" of the space "([^"]*)" with width "([^"]*)" and height "([^"]*)" using the WebDAV API$/
*
* @param string $user
Expand Down Expand Up @@ -2273,7 +2277,7 @@ public function downloadPreview(
* @When /^user "([^"]*)" downloads the file "([^"]*)" of the space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $fileName
* @param string $fileName
* @param string $spaceName
*
* @throws GuzzleException
Expand All @@ -2282,7 +2286,7 @@ public function downloadFile(
string $user,
string $fileName,
string $spaceName
): void {
): void {
$space = $this->getSpaceByName($user, $spaceName);
$fullUrl = $this->baseUrl . $this->davSpacesUrl . $space['id'] . '/' . $fileName;

Expand All @@ -2303,7 +2307,7 @@ public function downloadFile(
* @When /^user "([^"]*)" downloads version of the file "([^"]*)" with the index "([^"]*)" of the space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $fileName
* @param string $fileName
* @param string $index
* @param string $spaceName
*
Expand All @@ -2314,14 +2318,14 @@ public function downloadVersionOfTheFile(
string $fileName,
string $index,
string $spaceName
): void {
): void {
$fileVersion = $this->listFileVersion($user, $fileName, $spaceName);
if (!isset($fileVersion[$index])) {
Assert::fail(
'could not find version of file "' . $fileName . '" with index "' . $index . '"'
);
}
$url = $this->baseUrl . $fileVersion[$index][0];
$url = $this->baseUrl . $fileVersion[$index][0];

$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
Expand All @@ -2337,12 +2341,11 @@ public function downloadVersionOfTheFile(
}

/**
* Method returns an array with url values from the propfind request
* Method returns an array with url values from the propfind request
* like: /remote.php/dav/meta/spaceUuid%fileUuid/v/fileUuid.REV.2022-05-17T10:39:49.672285951Z

*
*
* @param string $user
* @param string $fileName
* @param string $fileName
* @param string $spaceName
*
* @return array
Expand All @@ -2352,8 +2355,7 @@ public function listFileVersion(
string $user,
string $fileName,
string $spaceName
): array {

): array {
$fileId = $this->getFileId($user, $spaceName, $fileName);
$fullUrl = $this->baseUrl . '/remote.php/dav/meta/' . $fileId . '/v';

Expand Down
Loading