Merge pull request #5678 from owncloud/add-multiple-user-in-group

[full-ci][tests-only] Extend tests coverage for adding users in a group with single request
This commit is contained in:
Amrita authored and GitHub committed 2023-03-02 13:37:08 +05:45
commit 0c1006cad2
4 files changed
+198 -13

No files matched your search

+8 -10
View File
@@ -478,8 +478,7 @@ class GraphHelper {
* @param string $adminUser
* @param string $adminPassword
* @param string $groupId
* @param array $users expects users array with user ids
* [ [ 'id' => 'some_id' ], ]
* @param array $userIds
*
* @return ResponseInterface
* @throws GuzzleException
@@ -490,18 +489,17 @@ class GraphHelper {
string $adminUser,
string $adminPassword,
string $groupId,
array $users
array $userIds
): ResponseInterface {
$url = self::getFullUrl($baseUrl, 'groups/' . $groupId . '/users');
$payload = [
"members@odata.bind" => []
];
foreach ($users as $user) {
$payload[0][] = self::getFullUrl($baseUrl, 'users/' . $user["id"]);
$url = self::getFullUrl($baseUrl, 'groups/' . $groupId);
$payload = [ "members@odata.bind" => [] ];
foreach ($userIds as $userId) {
$payload["members@odata.bind"][] = self::getFullUrl($baseUrl, 'users/' . $userId);
}
return HttpRequestHelper::post(
return HttpRequestHelper::sendRequest(
$url,
$xRequestId,
'PATCH',
$adminUser,
$adminPassword,
self::getRequestHeaders(),
@@ -149,3 +149,57 @@ Feature: add users to group
Scenario: admin tries to add user to a group without sending the group
When the administrator tries to add user "Alice" to group "" using the Graph API
Then the HTTP status code should be "404"
Scenario: add multiple users to a group at once
Given the administrator has given "Alice" the role "Admin" using the settings api
And these users have been created with default attributes and without skeleton files:
| username |
| Brian |
| Carol |
And user "Alice" has created a group "grp1" using the Graph API
When the administrator "Alice" adds the following users to a group "grp1" at once using the Graph API
| username |
| Brian |
| Carol |
Then the HTTP status code should be "204"
And the following users should be listed in the following groups
| username | groupname |
| Brian | grp1 |
| Carol | grp1 |
Scenario: admin tries to add users to a non-existing group at once
Given the administrator has given "Alice" the role "Admin" using the settings api
And these users have been created with default attributes and without skeleton files:
| username |
| Brian |
| Carol |
When the administrator "Alice" tries to add the following users to a non-existing group at once using the Graph API
| username |
| Brian |
| Carol |
Then the HTTP status code should be "404"
Scenario: admin tries to add multiple non-existing users to a group at once
Given the administrator has given "Alice" the role "Admin" using the settings api
And user "Alice" has created a group "grp1" using the Graph API
When the administrator "Alice" tries to add the following non-existing users to a group "grp1" at once using the Graph API
| username |
| Brian |
| Carol |
Then the HTTP status code should be "404"
Scenario: admin tries to add non-existing and existing users to a group at once
Given the administrator has given "Alice" the role "Admin" using the settings api
And these users have been created with default attributes and without skeleton files:
| username |
| Brian |
And user "Alice" has created a group "grp1" using the Graph API
When the administrator "Alice" tries to add the following users to a group "grp1" at once using the Graph API
| username |
| Brian |
| Carol |
Then the HTTP status code should be "404"
@@ -26,17 +26,17 @@ Feature: create group
Scenario: admin user tries to create a group that already exists
Given group "mygroup" has been created
When user "Alice" tries to create a group "mygroup" using the Graph API
And the HTTP status code should be "400"
Then the HTTP status code should be "400"
And group "mygroup" should exist
Scenario: normal user tries to create a group
Given user "Brian" has been created with default attributes and without skeleton files
When user "Brian" tries to create a group "mygroup" using the Graph API
And the HTTP status code should be "401"
Then the HTTP status code should be "401"
And group "mygroup" should not exist
Scenario: admin user tries to create a group that is the empty string
When user "Alice" tries to create a group "" using the Graph API
Then the HTTP status code should be "400"
Then the HTTP status code should be "400"
@@ -890,6 +890,28 @@ class GraphContext implements Context {
}
}
/**
* @Given /^the administrator has created a group "([^"]*)" using the Graph API$/
* @Given user :user has created a group :group using the Graph API
*
* @param string $group
* @param ?string $user
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function userHasCreatedGroupUsingTheGraphApi(string $group, ?string $user = null): void {
$response = $this->createGroup($group, $user);
if ($response->getStatusCode() === 200) {
$groupId = $this->featureContext->getJsonDecodedResponse($response)["id"];
$this->featureContext->addGroupToCreatedGroupsList($group, true, true, $groupId);
} else {
$this->throwHttpException($response, "Could not create group '$group'.");
}
}
/**
* create group with provided data
*
@@ -1532,4 +1554,115 @@ class GraphContext implements Context {
throw new Error('Response is not an array or the array does not consist key "drive"');
}
}
/**
* add multiple users in a group at once
*
* @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 {
$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
)
);
}
/**
* @When /^the administrator "([^"]*)" adds the following users to a group "([^"]*)" at once using the Graph API$/
*
* @param string $user
* @param string $group
* @param TableNode $table
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function theAdministratorAddsTheFollowingUsersToAGroupInASingleRequestUsingTheGraphApi(string $user, string $group, TableNode $table): void {
$userIds = [];
$groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id");
foreach ($table->getHash() as $row) {
$userIds[] = $this->featureContext->getAttributeOfCreatedUser($row['username'], "id");
}
$this->addMultipleUsersToGroup($user, $userIds, $groupId, $table);
}
/**
* @When /^the administrator "([^"]*)" tries to add the following users to a non-existing group at once using the Graph API$/
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function theAdministratorTriesToAddsTheFollowingUsersToANonExistingGroupAtOnceUsingTheGraphApi(string $user, TableNode $table): void {
$userIds = [];
$groupId = WebDavHelper::generateUUIDv4();
foreach ($table->getHash() as $row) {
$userIds[] = $this->featureContext->getAttributeOfCreatedUser($row['username'], "id");
}
$this->addMultipleUsersToGroup($user, $userIds, $groupId, $table);
}
/**
* @When /^the administrator "([^"]*)" tries to add the following non-existing users to a group "([^"]*)" at once using the Graph API$/
*
* @param string $user
* @param string $group
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function theAdministratorTriesToAddTheFollowingNonExistingUsersToAGroupAtOnceUsingTheGraphApi(string $user, string $group, TableNode $table): void {
$userIds = [];
$groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id");
foreach ($table->getHash() as $row) {
$userIds[] = WebDavHelper::generateUUIDv4();
}
$this->addMultipleUsersToGroup($user, $userIds, $groupId, $table);
}
/**
* @When /^the administrator "([^"]*)" tries to add the following users to a group "([^"]*)" at once using the Graph API$/
*
* @param string $user
* @param string $group
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function theAdministratorTriesToAddTheFollowingUsersToAGroupAtOnceUsingTheGraphApi(string $user, string $group, TableNode $table): void {
$userIds = [];
$groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id");
foreach ($table->getHash() as $row) {
try {
$userIds[] = $this->featureContext->getAttributeOfCreatedUser($row['username'], "id");
} catch (Exception $e) {
$userIds[] = WebDavHelper::generateUUIDv4();
}
}
$this->addMultipleUsersToGroup($user, $userIds, $groupId, $table);
}
}