added checks: who is owner, who has be granted

This commit is contained in:
Viktor Scharf
2022-02-10 20:21:22 +01:00
parent 21c7b10f98
commit 85714c113d
3 changed files with 102 additions and 14 deletions
@@ -205,6 +205,40 @@ class SpacesContext implements Context {
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();
if (isset(\json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR)["accounts"])) {
$accounts = \json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR)["accounts"];
}
}
foreach ($accounts as $account) {
if ($account["preferredName"] === $userName) {
return $account["id"];
}
}
throw new Exception(__METHOD__ . " user with name $userName not found");
}
/**
* @BeforeScenario
*
@@ -718,9 +752,10 @@ class SpacesContext implements Context {
}
/**
* @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
@@ -728,6 +763,7 @@ class SpacesContext implements Context {
*/
public function jsonRespondedShouldContain(
string $spaceName,
string $userName = '',
TableNode $table
): void {
$this->featureContext->verifyTableNodeColumns($table, ['key', 'value']);
@@ -745,7 +781,13 @@ class SpacesContext implements Context {
"function" =>
[$this, "getSpaceIdByNameFromResponse"],
"parameter" => [$spaceName]
]
],
[
"code" => "%user_id%",
"function" =>
[$this, "getUserIdByUserName"],
"parameter" => [$userName]
],
]
);
$segments = explode("@@@", $row["key"]);
@@ -1488,19 +1530,24 @@ class SpacesContext implements Context {
*
* @param string $user
* @param string $spaceName
* @param string $userWithManagerRigths
*
* @return void
* @throws GuzzleException
*/
public function sendRestoreSpaceRequest(
string $user,
string $spaceName
string $spaceName,
string $userWithManagerRigths = ''
): void {
if (!empty($userWithManagerRigths)) {
$space = $this->getSpaceByName($userWithManagerRigths, $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,
@@ -1514,6 +1561,22 @@ class SpacesContext implements Context {
);
}
/**
* @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 "([^"]*)"$/
*