[full-ci][tests-only] Check id file owner in response (#6627)

* check owner as spaceId in sharing response

* fix after review
This commit is contained in:
Viktor Scharf
2023-06-27 12:50:10 +02:00
committed by GitHub
parent 5524658f86
commit 753c8f2372
5 changed files with 118 additions and 61 deletions
@@ -162,6 +162,7 @@ class FeatureContext extends BehatVariablesContext {
public OCSContext $ocsContext;
public AuthContext $authContext;
public GraphContext $graphContext;
public SpacesContext $spacesContext;
public AppConfigurationContext $appConfigurationContext;
private array $initialTrustedServer;
@@ -3221,12 +3222,15 @@ class FeatureContext extends BehatVariablesContext {
$this->ocsContext = new OCSContext();
$this->authContext = new AuthContext();
$this->appConfigurationContext = new AppConfigurationContext();
$this->spacesContext = new SpacesContext();
$this->ocsContext->before($scope);
$this->authContext->setUpScenario($scope);
$this->appConfigurationContext->setUpScenario($scope);
$environment->registerContext($this->ocsContext);
$environment->registerContext($this->authContext);
$environment->registerContext($this->appConfigurationContext);
$this->spacesContext->setUpScenario($scope);
$environment->registerContext($this->spacesContext);
$scenarioLine = $scope->getScenario()->getLine();
$featureFile = $scope->getFeature()->getFile();
$suiteName = $scope->getSuite()->getName();
@@ -2777,6 +2777,69 @@ trait Sharing {
}
}
/**
* @Then the fields of the last response to user :user and space :space should include
*
* @param string $user
* @param string $space
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
public function checkFieldsOfSpaceSharingResponse(string $user, string $space, ?TableNode $body):void {
$this->verifyTableNodeColumnsCount($body, 2);
$bodyRows = $body->getRowsHash();
$userRelatedFieldNames = [
"owner",
"user",
"uid_owner",
"uid_file_owner",
"share_with",
"displayname_file_owner",
"displayname_owner",
"additional_info_owner",
"additional_info_file_owner",
"space_id"
];
$this->setLastPublicShareData($this->getResponseXml(null, __METHOD__));
foreach ($bodyRows as $field => $value) {
if (\in_array($field, $userRelatedFieldNames)) {
$value = $this->substituteInLineCodes(
$value,
$user,
[],
[
[
"code" => "%space_id%",
"function" =>
[$this->spacesContext, "getSpaceIdByName"],
"parameter" => [$user, $space]
],
],
null,
null
);
if ($field === "uid_file_owner") {
$value = (explode("$", $value))[1];
}
if ($field === "space_id") {
$exploadedSpaceId = explode("$", $value);
$value = $exploadedSpaceId[0] . "$" . $exploadedSpaceId[1] . "!" . $exploadedSpaceId[1];
}
}
$value = $this->getActualUsername($value);
$value = $this->replaceValuesFromTable($field, $value);
Assert::assertTrue(
$this->isFieldInResponse($field, $value, true, $this->getLastPublicShareData()->data[0]),
"$field doesn't have value '$value'"
);
}
}
/**
* @Then /^the fields of the last response (?:to|about) user "([^"]*)" sharing with (?:user|group) "([^"]*)" should include$/
*
@@ -204,6 +204,20 @@ class SpacesContext implements Context {
return $spaces[$spaceName];
}
/**
* The method finds available spaces to the user and returns the spaceId by spaceName
*
* @param string $user
* @param string $spaceName
*
* @return string
* @throws GuzzleException
*/
public function getSpaceIdByName(string $user, string $spaceName): string {
$space = $this->getSpaceByName($user, $spaceName);
return $space["id"];
}
/**
* This method sets space id by Space Name
* This is currently used to set space id from ocis in core so that we can reuse available resource (code) and avoid duplication
@@ -378,14 +392,20 @@ class SpacesContext implements Context {
public function setUpScenario(BeforeScenarioScope $scope): void {
// Get the environment
$environment = $scope->getEnvironment();
// register new context
$this->trashbinContext = new TrashbinContext();
$this->webDavPropertiesContext = new WebDavPropertiesContext();
$this->favoritesContext = new FavoritesContext();
$this->checksumContext = new ChecksumContext();
$this->filesVersionsContext = new FilesVersionsContext();
$environment->registerContext($this->trashbinContext);
$environment->registerContext($this->webDavPropertiesContext);
$environment->registerContext($this->favoritesContext);
$environment->registerContext($this->checksumContext);
$environment->registerContext($this->filesVersionsContext);
// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
$this->ocsContext = $environment->getContext('OCSContext');
$this->trashbinContext = $environment->getContext('TrashbinContext');
$this->webDavPropertiesContext = $environment->getContext('WebDavPropertiesContext');
$this->favoritesContext = $environment->getContext('FavoritesContext');
$this->checksumContext = $environment->getContext('ChecksumContext');
$this->filesVersionsContext = $environment->getContext('FilesVersionsContext');
// Run the BeforeScenario function in OCSContext to set it up correctly
$this->ocsContext->before($scope);
$this->baseUrl = \trim($this->featureContext->getBaseUrl(), "/");