more ocm tests

This commit is contained in:
Viktor Scharf
2024-07-08 07:59:52 +02:00
parent 4b05f35d52
commit 97bce8edd4
11 changed files with 640 additions and 38 deletions
@@ -2250,6 +2250,14 @@ class FeatureContext extends BehatVariablesContext {
"getTusResourceLocation"
],
"parameter" => []
],
[
"code" => "%fed_invitation_token_pattern%",
"function" => [
__NAMESPACE__ . '\TestHelpers\GraphHelper',
"getUUIDv4Regex"
],
"parameter" => []
]
];
if ($user !== null) {
@@ -22,11 +22,12 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\OcisHelper;
use TestHelpers\OcmHelper;
/**
* Acceptance test steps related to testing sharing ng features
* Acceptance test steps related to testing federation share(ocm) features
*/
class OcmContext implements Context {
private FeatureContext $featureContext;
@@ -53,17 +54,40 @@ class OcmContext implements Context {
}
/**
* @When :user generates invitation
* @When :user generates invitation with email :email and description :description
* @return string
*/
public function getOcisDomain(): string {
return $this->extractDomain(\getenv('TEST_SERVER_URL'));
}
/**
* @return string
*/
public function getFedOcisDomain(): string {
return $this->extractDomain(\getenv('TEST_SERVER_FED_URL'));
}
/**
* @param string $url
*
* @return string
*/
public function extractDomain($url): string {
if (!$url) {
return "localhost";
}
return parse_url($url)["host"];
}
/**
* @param string $user
* @param string $email
* @param string $description
*
* @return void
* @return ResponseInterface
* @throws GuzzleException
*/
public function userGeneratesInvitation(string $user, $email = null, $description = null): void {
public function createInvitation(string $user, $email = null, $description = null): ResponseInterface {
$response = OcmHelper::createInvitation(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
@@ -72,26 +96,84 @@ class OcmContext implements Context {
$email,
$description
);
$this->featureContext->setResponse($response);
$this->invitationToken = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse())['token'];
$responseData = \json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
if (isset($responseData["token"])) {
$this->invitationToken = $responseData["token"];
} else {
throw new Exception(__METHOD__ . " response doesn't contain token");
}
return $response;
}
/**
* @When :user accepts invitation
* @When :user creates the federation share invitation
* @When :user creates the federation share invitation with email :email and description :description
*
* @param string $user
* @param string $email
* @param string $description
*
* @return void
* @throws GuzzleException
*/
public function userCreatesTheFederationShareInvitation(string $user, $email = null, $description = null): void {
$this->featureContext->setResponse($this->createInvitation($user, $email, $description));
}
/**
* @Given :user has created the federation share invitation
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function userAcceptsInvitation(string $user): void {
$response = OcmHelper::acceptInvitation(
public function userHasCreatedTheFederationShareInvitation(string $user): void {
$response = $this->createInvitation($user);
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
}
/**
* @param string $user
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function acceptInvitation(string $user): ResponseInterface {
$providerDomain = ($this->featureContext->getCurrentServer() === "LOCAL") ? $this->getFedOcisDomain() : $this->getOcisDomain();
return OcmHelper::acceptInvitation(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
$this->invitationToken
$this->invitationToken,
$providerDomain
);
$this->featureContext->setResponse($response);
}
/**
* @When :user accepts the last federation share invitation
* @When :user tries to accept the last federation share invitation
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function userAcceptsTheLastFederationShareInvitation(string $user): void {
$this->featureContext->setResponse($this->acceptInvitation($user));
}
/**
* @Given :user has accepted invitation
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function userHasAcceptedTheLastFederationShareInvitation(string $user): void {
$response = $this->acceptInvitation($user);
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
}
}
@@ -83,6 +83,13 @@ trait Provisioning {
return $this->createdUsers;
}
/**
* @return array
*/
public function getAllCreatedUsers():array {
return array_merge($this->createdUsers, $this->createdRemoteUsers);
}
/**
* @return boolean
*/
@@ -107,8 +114,9 @@ trait Provisioning {
*/
public function getUserDisplayName(string $username):string {
$normalizedUsername = $this->normalizeUsername($username);
if (isset($this->createdUsers[$normalizedUsername]['displayname'])) {
$displayName = (string) $this->createdUsers[$normalizedUsername]['displayname'];
$users = $this->getAllCreatedUsers();
if (isset($users[$normalizedUsername]['displayname'])) {
$displayName = (string) $users[$normalizedUsername]['displayname'];
if ($displayName !== '') {
return $displayName;
}
@@ -124,7 +132,7 @@ trait Provisioning {
* @throws Exception
*/
public function getAttributeOfCreatedUser(string $user, string $attribute) {
$usersList = $this->getCreatedUsers();
$usersList = $this->getAllCreatedUsers();
$normalizedUsername = $this->normalizeUsername($user);
if (\array_key_exists($normalizedUsername, $usersList)) {
if (\array_key_exists($attribute, $usersList[$normalizedUsername])) {
@@ -1118,6 +1126,7 @@ trait Provisioning {
// See comment above about the LOCAL case. The logic is the same for the remote case.
if ($shouldExist || !\array_key_exists($normalizedUsername, $this->createdRemoteUsers)) {
$this->createdRemoteUsers[$normalizedUsername] = $userData;
$this->createdUsers[$normalizedUsername] = $userData;
}
}
}