mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-11 09:33:17 -04:00
Add tests to add user in a group at once (#5743)
This commit is contained in:
@@ -502,6 +502,41 @@ class GraphHelper {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string $adminUser
|
||||
* @param string $adminPassword
|
||||
* @param string $groupId
|
||||
* @param array $userIds
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function addUsersToGroup(
|
||||
string $baseUrl,
|
||||
string $xRequestId,
|
||||
string $adminUser,
|
||||
string $adminPassword,
|
||||
string $groupId,
|
||||
array $userIds
|
||||
): ResponseInterface {
|
||||
$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::sendRequest(
|
||||
$url,
|
||||
$xRequestId,
|
||||
'PATCH',
|
||||
$adminUser,
|
||||
$adminPassword,
|
||||
self::getRequestHeaders(),
|
||||
\json_encode($payload)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
@@ -678,7 +713,7 @@ class GraphHelper {
|
||||
$payload['mail'] = $email;
|
||||
}
|
||||
$payload['accountEnabled'] = $accountEnabled;
|
||||
|
||||
|
||||
return \json_encode($payload);
|
||||
}
|
||||
|
||||
|
||||
@@ -151,6 +151,60 @@ Feature: add users to group
|
||||
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"
|
||||
|
||||
|
||||
Scenario: adding a disabled user to a group
|
||||
Given these groups have been created:
|
||||
| groupname | comment |
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -956,6 +956,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
|
||||
*
|
||||
@@ -1609,6 +1631,117 @@ class GraphContext implements Context {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When user :user gets all applications using the Graph API
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user