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. Checking owner and permissions #3151

Merged
merged 2 commits into from
Feb 11, 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
17 changes: 16 additions & 1 deletion tests/acceptance/features/apiSpaces/restoreSpaces.feature
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,19 @@ Feature: Restoring space
Then for user "Brian" the space "create data in restored space" should contain these entries:
| test.txt |
| mainFolder |



Scenario: User with viewer permissions cannot restore space
Given user "Alice" has created a space "viewer restores space" of type "project" with quota "10"
And user "Alice" has shared a space "viewer restores space" to user "Brian" with role "viewer"
And user "Alice" has disabled a space "viewer restores space"
When user "Brian" restores a disabled space "viewer restores space" without manager rights
Then the HTTP status code should be "404"


Scenario: User with editor permissions cannot restore space
Given user "Alice" has created a space "editor restores space" of type "project" with quota "10"
And user "Alice" has shared a space "editor restores space" to user "Brian" with role "editor"
And user "Alice" has disabled a space "editor restores space"
When user "Brian" restores a disabled space "editor restores space" without manager rights
Then the HTTP status code should be "404"
24 changes: 17 additions & 7 deletions tests/acceptance/features/apiSpaces/shareSpaces.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Feature: Share spaces
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 user "Bob" has been created with default attributes and without skeleton files
And the administrator has given "Alice" the role "Admin" using the settings api


Expand All @@ -32,13 +33,22 @@ Feature: Share spaces
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" with role "viewer"
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 | project |
| id | %space_id% |
| name | Share space to Brian |
| quota@@@state | normal |
| root@@@webDavUrl | %base_url%/dav/spaces/%space_id% |
Then the json responded should contain a space "Share space to Brian" owned by "Alice" with these key and value pairs:
| key | value |
| driveType | project |
| id | %space_id% |
| name | Share space to Brian |
| owner@@@user@@@id | %user_id% |


Scenario: A user can see who has been granted access
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" with role "viewer"
When user "Alice" lists all available spaces via the GraphApi
Then the json responded should contain a space "Share space to Brian" granted to "Brian" with these key and value pairs:
| key | value |
| root@@@permissions@@@1@@@grantedTo@@@0@@@user@@@id | %user_id% |
| root@@@permissions@@@1@@@roles@@@0 | viewer |


Scenario: A user can see a file in a received shared space
Expand Down
78 changes: 72 additions & 6 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,43 @@ public function getSpaceByName(string $user, string $spaceName): array {
return $spaces[$spaceName];
}

/**
* The method returns userId
*
* @param string $userName
*
* @return string
*/
public function getUserIdByUserName(string $userName): string {

$fullUrl = $this->baseUrl . "/api/v0/accounts/accounts-list";
$this->featureContext->setResponse(
HttpRequestHelper::post(
$fullUrl,
"",
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
[],
"{}"
)
);
if ($this->featureContext->getResponse()) {
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
$response = \json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR);
if (isset($response["accounts"])) {
$accounts = $response["accounts"];
} else {
throw new Exception(__METHOD__ . " accounts-list is empty");
}
}
foreach ($accounts as $account) {
if ($account["preferredName"] === $userName) {
return $account["id"];
}
}
throw new Exception(__METHOD__ . " user with name $userName not found");
}

/**
* @BeforeScenario
*
Expand Down Expand Up @@ -718,16 +755,18 @@ public function folderOfTheSpaceShouldContainEntries(
}

/**
* @Then /^the json responded should contain a space "([^"]*)" with these key and value pairs:$/
*
* @Then /^the json responded should contain a space "([^"]*)" (?:|(?:owned by|granted to) "([^"]*)" )with these key and value pairs:$/
*
* @param string $spaceName
* @param string $userName
* @param TableNode $table
*
* @return void
* @throws Exception
*/
public function jsonRespondedShouldContain(
string $spaceName,
string $userName = '',
TableNode $table
): void {
$this->featureContext->verifyTableNodeColumns($table, ['key', 'value']);
Expand All @@ -745,7 +784,13 @@ public function jsonRespondedShouldContain(
"function" =>
[$this, "getSpaceIdByNameFromResponse"],
"parameter" => [$spaceName]
]
],
[
"code" => "%user_id%",
"function" =>
[$this, "getUserIdByUserName"],
"parameter" => [$userName]
],
]
);
$segments = explode("@@@", $row["key"]);
Expand Down Expand Up @@ -1488,19 +1533,24 @@ public function sendDeleteSpaceRequest(
*
* @param string $user
* @param string $spaceName
* @param string $userWithManagerRights
*
* @return void
* @throws GuzzleException
*/
public function sendRestoreSpaceRequest(
string $user,
string $spaceName
string $spaceName,
string $userWithManagerRights = ''
): void {
if (!empty($userWithManagerRights)) {
$space = $this->getSpaceByName($userWithManagerRights, $spaceName);
} else {
$space = $this->getSpaceByName($user, $spaceName);
}
$header = ["restore" => true];
$body = '{}';
$space = $this->getSpaceByName($user, $spaceName);
$fullUrl = $this->baseUrl . "/graph/v1.0/drives/" . $space["id"];

$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
$fullUrl,
Expand All @@ -1514,6 +1564,22 @@ public function sendRestoreSpaceRequest(
);
}

/**
* @When /^user "([^"]*)" restores a disabled space "([^"]*)" without manager rights$/
*
* @param string $user
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
public function sendRestoreSpaceWithoutRightsRequest(
string $user,
string $spaceName
): void {
$this->sendRestoreSpaceRequest($user, $spaceName, $this->featureContext->getAdminUsername());
}

/**
* @When /^user "([^"]*)" has restored a disabled space "([^"]*)"$/
*
Expand Down