Skip to content

Commit

Permalink
[tests-only] [full-ci] backporting the PR related to user addition to…
Browse files Browse the repository at this point in the history
… group to graphapi (#7545)

* backporting the PR

* [tests-only][full-ci] refactoring user addition to group to graphapi (#7360)

* changed user addition to group to graphapi

* addressing the review

* addressing review regarding nonexistent user

* addressing the review

* updated expected failures file

* changing code to make it pass in reva edge

* addressing review

* addressing review
  • Loading branch information
S-Panta authored Oct 31, 2023
1 parent 804d17c commit e68b98d
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 234 deletions.
8 changes: 4 additions & 4 deletions tests/acceptance/expected-failures-API-on-OCIS-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,10 @@ cannot share a folder with create permission

#### [Sharing folder and sub-folder with same user but different permission,the permission of sub-folder is not obeyed ](https://github.com/owncloud/ocis/issues/2440)

- [coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature:221](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature#L221)
- [coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature:351](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature#L351)
- [coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature:252](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature#L252)
- [coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature:382](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature#L382)
- [coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature:220](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature#L220)
- [coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature:350](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature#L350)
- [coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature:251](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature#L251)
- [coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature:381](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareReceivedInMultipleWays.feature#L381)

#### [Empty OCS response for a share create request using a disabled user](https://github.com/owncloud/ocis/issues/2212)

Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/features/apiGraph/addUserToGroup.feature
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ Feature: add users to group

Scenario: admin tries to add a nonexistent user to a group
Given group "groupA" has been created
When the administrator tries to add user "nonexistentuser" to group "groupA" using the provisioning API
Then the HTTP status code should be "405"
When the administrator tries to add nonexistent user to group "groupA" using the Graph API
Then the HTTP status code should be "404"


Scenario: admin tries to add user to a group without sending the group
Expand Down
85 changes: 40 additions & 45 deletions tests/acceptance/features/bootstrap/GraphContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ public function theUserCreatesNewUser(string $user, TableNode $table): void {

/**
* adds a user to a group
* NOTE: If you want to make a request with non-existing user or group,provide "nonexistent" as their name
*
* @param string $group
* @param string $user
Expand All @@ -772,8 +773,16 @@ public function theUserCreatesNewUser(string $user, TableNode $table): void {
*/
public function addUserToGroup(string $group, string $user, ?string $byUser = null): ResponseInterface {
$credentials = $this->getAdminOrUserCredentials($byUser);
$groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id");
$userId = $this->featureContext->getAttributeOfCreatedUser($user, "id");
if ($group === "nonexistent") {
$groupId = WebDavHelper::generateUUIDv4();
} else {
$groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id");
}
if ($user === "nonexistent") {
$userId = WebDavHelper::generateUUIDv4();
} else {
$userId = $this->featureContext->getAttributeOfCreatedUser($user, "id");
}
return GraphHelper::addUserToGroup(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
Expand All @@ -800,10 +809,8 @@ public function adminHasAddedUserToGroupUsingTheGraphApi(
string $group,
bool $checkResult = true
): void {
$result = $this->addUserToGroup($group, $user);
if ($checkResult && ($result->getStatusCode() !== 204)) {
$this->throwHttpException($result, "Could not add user '$user' to group '$group'.");
}
$response = $this->addUserToGroup($group, $user);
$this->featureContext->theHTTPStatusCodeShouldBe(204, '', $response);
}

/**
Expand All @@ -824,15 +831,14 @@ public function theAdministratorAddsTheFollowingUsersToTheFollowingGroupsUsingTh
}

/**
* @When the administrator tries to add user :user to group :group using the Graph API
* @When the administrator tries to add nonexistent user to group :group using the Graph API
*
* @param string $user
* @param string $group
*
* @return void
*/
public function theAdministratorTriesToAddUserToGroupUsingTheGraphAPI(string $user, string $group): void {
$this->featureContext->setResponse($this->addUserToGroup($group, $user));
public function theAdministratorTriesToAddNonExistentUserToGroupUsingTheGraphAPI(string $group): void {
$this->featureContext->setResponse($this->addUserToGroup($group, "nonexistent"));
}

/**
Expand All @@ -847,19 +853,7 @@ public function theAdministratorTriesToAddUserToGroupUsingTheGraphAPI(string $us
* @throws GuzzleException | Exception
*/
public function theAdministratorTriesToAddUserToNonExistentGroupUsingTheGraphAPI(string $user, ?string $byUser = null): void {
$credentials = $this->getAdminOrUserCredentials($byUser);
$groupId = WebDavHelper::generateUUIDv4();
$userId = $this->featureContext->getAttributeOfCreatedUser($user, "id");
$this->featureContext->setResponse(
GraphHelper::addUserToGroup(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$credentials['username'],
$credentials['password'],
$userId,
$groupId
)
);
$this->featureContext->setResponse($this->addUserToGroup("nonexistent", $user, $byUser));
}

/**
Expand Down Expand Up @@ -1423,25 +1417,21 @@ public function userTriesToGetOwnDriveInformation(string $user) {
* @param string $user
* @param array $userIds
* @param string $groupId
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function addMultipleUsersToGroup(string $user, array $userIds, string $groupId, TableNode $table): void {
public function addMultipleUsersToGroup(string $user, array $userIds, string $groupId): ResponseInterface {
$credentials = $this->getAdminOrUserCredentials($user);
$this->featureContext->verifyTableNodeColumns($table, ['username']);

$this->featureContext->setResponse(
GraphHelper::addUsersToGroup(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$credentials["username"],
$credentials["password"],
$groupId,
$userIds
)
return GraphHelper::addUsersToGroup(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$credentials["username"],
$credentials["password"],
$groupId,
$userIds
);
}

Expand All @@ -1462,7 +1452,9 @@ public function theAdministratorAddsTheFollowingUsersToAGroupInASingleRequestUsi
foreach ($table->getHash() as $row) {
$userIds[] = $this->featureContext->getAttributeOfCreatedUser($row['username'], "id");
}
$this->addMultipleUsersToGroup($user, $userIds, $groupId, $table);
$this->featureContext->verifyTableNodeColumns($table, ['username']);
$response = $this->addMultipleUsersToGroup($user, $userIds, $groupId);
$this->featureContext->setResponse($response);
}

/**
Expand Down Expand Up @@ -1552,7 +1544,9 @@ public function theAdministratorTriesToAddsTheFollowingUsersToANonExistingGroupA
foreach ($table->getHash() as $row) {
$userIds[] = $this->featureContext->getAttributeOfCreatedUser($row['username'], "id");
}
$this->addMultipleUsersToGroup($user, $userIds, $groupId, $table);
$this->featureContext->verifyTableNodeColumns($table, ['username']);
$response = $this->addMultipleUsersToGroup($user, $userIds, $groupId);
$this->featureContext->setResponse($response);
}

/**
Expand All @@ -1572,7 +1566,9 @@ public function theAdministratorTriesToAddTheFollowingNonExistingUsersToAGroupAt
foreach ($table->getHash() as $row) {
$userIds[] = WebDavHelper::generateUUIDv4();
}
$this->addMultipleUsersToGroup($user, $userIds, $groupId, $table);
$this->featureContext->verifyTableNodeColumns($table, ['username']);
$response = $this->addMultipleUsersToGroup($user, $userIds, $groupId);
$this->featureContext->setResponse($response);
}

/**
Expand All @@ -1594,7 +1590,9 @@ public function theAdministratorTriesToAddTheFollowingUsersToAGroupAtOnceUsingTh
$userId = $this->featureContext->getAttributeOfCreatedUser($row['username'], "id");
$userIds[] = $userId ?: WebDavHelper::generateUUIDv4();
}
$this->addMultipleUsersToGroup($user, $userIds, $groupId, $table);
$this->featureContext->verifyTableNodeColumns($table, ['username']);
$response = $this->addMultipleUsersToGroup($user, $userIds, $groupId);
$this->featureContext->setResponse($response);
}

/**
Expand Down Expand Up @@ -1987,12 +1985,9 @@ public function theAdministratorHasAddedTheFollowingUsersToAGroupAtOnceUsingTheG
foreach ($table->getHash() as $row) {
$userIds[] = $this->featureContext->getAttributeOfCreatedUser($row['username'], "id");
}
$this->addMultipleUsersToGroup($user, $userIds, $groupId, $table);
$response = $this->featureContext->getResponse();
if ($response->getStatusCode() !== 204) {
$this->throwHttpException($response, "Cannot add users to group '$group'");
}
$this->featureContext->emptyLastHTTPStatusCodesArray();
$this->featureContext->verifyTableNodeColumns($table, ['username']);
$response = $this->addMultipleUsersToGroup($user, $userIds, $groupId);
$this->featureContext->theHTTPStatusCodeShouldBe(204, '', $response);
}

/**
Expand Down
Loading

0 comments on commit e68b98d

Please sign in to comment.