check that created user has only one personal space

This commit is contained in:
Viktor Scharf
2025-04-29 12:39:25 +02:00
parent a97f5e4c2e
commit 7bb95d057a
2 changed files with 89 additions and 0 deletions

View File

@@ -1985,8 +1985,29 @@ trait Provisioning {
if ($this->isTestingWithLdap()) {
$this->deleteLdapUsersAndGroups();
}
$assertionFailed = false;
$errorMessage = '';
// check that created users have only one personal space
try {
$this->setResponse(
$this->spacesContext->listAllAvailableSpaces("admin", "%24filter=driveType+eq+personal")
);
$this->spacesContext->jsonRespondedShouldContainOnlyOneSpace();
$this->spacesContext->jsonRespondedShouldNotContainSpaceWithoutName();
} catch (\Throwable $e) {
$assertionFailed = true;
$errorMessage = $e->getMessage();
echo "\n[WARNING] Space assertion failed: " . $errorMessage . "\n";
}
$this->cleanupDatabaseUsers();
$this->cleanupDatabaseGroups();
if ($assertionFailed) {
throw new \Exception("Space assertion failed:\n" . $errorMessage);
}
}
/**

View File

@@ -1087,6 +1087,74 @@ class SpacesContext implements Context {
);
}
/**
* @return void
* @throws Exception
*/
public function jsonRespondedShouldContainOnlyOneSpace(): void {
$response = $response ?? $this->featureContext->getResponse();
$decodedResponse = $this->featureContext->getJsonDecodedResponse($response);
$userAdmin = $this->featureContext->getAdminUsername();
$aliases = [];
foreach ($decodedResponse['value'] as $space) {
$alias = $space['driveAlias'];
if (isset($aliases[$alias])) {
GraphHelper::disableSpace(
$this->featureContext->getBaseUrl(),
$userAdmin,
$this->featureContext->getPasswordForUser($userAdmin),
$space["id"],
$this->featureContext->getStepLineRef()
);
GraphHelper::deleteSpace(
$this->featureContext->getBaseUrl(),
$userAdmin,
$this->featureContext->getPasswordForUser($userAdmin),
$space["id"],
$this->featureContext->getStepLineRef()
);
Assert::fail(
"Duplicate space found: '$alias'\nResponse:\n" . json_encode($decodedResponse, JSON_PRETTY_PRINT)
);
}
$aliases[$alias] = true;
}
}
/**
* @return void
* @throws Exception
*/
public function jsonRespondedShouldNotContainSpaceWithoutName(): void {
$response = $response ?? $this->featureContext->getResponse();
$decodedResponse = $this->featureContext->getJsonDecodedResponse($response);
$userAdmin = $this->featureContext->getAdminUsername();
foreach ($decodedResponse['value'] as $space) {
if ($space['name'] === "") {
GraphHelper::disableSpace(
$this->featureContext->getBaseUrl(),
$userAdmin,
$this->featureContext->getPasswordForUser($userAdmin),
$space["id"],
$this->featureContext->getStepLineRef()
);
GraphHelper::deleteSpace(
$this->featureContext->getBaseUrl(),
$userAdmin,
$this->featureContext->getPasswordForUser($userAdmin),
$space["id"],
$this->featureContext->getStepLineRef()
);
Assert::fail(
"Space without name found. \nResponse:\n" . json_encode($decodedResponse, JSON_PRETTY_PRINT)
);
}
}
}
/**
* @Then /^the user "([^"]*)" should (not |)have a space called "([^"]*)"$/
*