[tests-only] [full-ci] backporting the PR related to user addition to 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
This commit is contained in:
Sabin Panta
2023-10-31 12:15:57 +05:45
committed by GitHub
parent 804d17c501
commit e68b98d288
6 changed files with 69 additions and 234 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -762,6 +762,7 @@ class GraphContext implements Context {
/**
* 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
@@ -772,8 +773,16 @@ class GraphContext implements Context {
*/
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(),
@@ -800,10 +809,8 @@ class GraphContext implements Context {
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);
}
/**
@@ -824,15 +831,14 @@ class GraphContext implements Context {
}
/**
* @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"));
}
/**
@@ -847,19 +853,7 @@ class GraphContext implements Context {
* @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));
}
/**
@@ -1423,25 +1417,21 @@ class GraphContext implements Context {
* @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
);
}
@@ -1462,7 +1452,9 @@ class GraphContext implements Context {
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);
}
/**
@@ -1552,7 +1544,9 @@ class GraphContext implements Context {
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);
}
/**
@@ -1572,7 +1566,9 @@ class GraphContext implements Context {
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);
}
/**
@@ -1594,7 +1590,9 @@ class GraphContext implements Context {
$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);
}
/**
@@ -1987,12 +1985,9 @@ class GraphContext implements Context {
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);
}
/**

View File

@@ -2966,82 +2966,8 @@ trait Provisioning {
* @throws Exception
*/
public function adminAddsUserToGroupUsingTheProvisioningApi(string $user, string $group):void {
$this->addUserToGroup($user, $group, "api");
}
/**
* @When the administrator adds the following users to the following groups using the provisioning API
*
* @param TableNode $table
*
* @return void
* @throws Exception
*/
public function theAdministratorAddsUserToTheFollowingGroupsUsingTheProvisioningApi(TableNode $table):void {
$this->verifyTableNodeColumns($table, ["username", "groupname"], ["comment"]);
$rows = $table->getHash();
foreach ($rows as $row) {
$this->adminAddsUserToGroupUsingTheProvisioningApi($row["username"], $row["groupname"]);
}
}
/**
* @When user :user tries to add user :otherUser to group :group using the provisioning API
*
* @param string $user
* @param string $otherUser
* @param string $group
*
* @return void
* @throws Exception
*/
public function userTriesToAddUserToGroupUsingTheProvisioningApi(string $user, string $otherUser, string $group):void {
$actualUser = $this->getActualUsername($user);
$actualPassword = $this->getUserPassword($actualUser);
$actualOtherUser = $this->getActualUsername($otherUser);
$result = UserHelper::addUserToGroup(
$this->getBaseUrl(),
$actualOtherUser,
$group,
$actualUser,
$actualPassword,
$this->getStepLineRef(),
$this->ocsApiVersion
);
$this->response = $result;
}
/**
* @When user :user tries to add himself to group :group using the provisioning API
*
* @param string $user
* @param string $group
*
* @return void
* @throws Exception
*/
public function userTriesToAddHimselfToGroupUsingTheProvisioningApi(string $user, string $group):void {
$this->userTriesToAddUserToGroupUsingTheProvisioningApi($user, $user, $group);
}
/**
* @When the administrator tries to add user :user to group :group using the provisioning API
*
* @param string $user
* @param string $group
*
* @return void
* @throws Exception
*/
public function theAdministratorTriesToAddUserToGroupUsingTheProvisioningApi(
string $user,
string $group
):void {
$this->userTriesToAddUserToGroupUsingTheProvisioningApi(
$this->getAdminUsername(),
$user,
$group
);
$response = $this->graphContext->addUserToGroup($group, $user);
$this->setResponse($response);
}
/**
@@ -3055,7 +2981,21 @@ trait Provisioning {
*/
public function userHasBeenAddedToGroup(string $user, string $group):void {
$user = $this->getActualUsername($user);
$this->addUserToGroup($user, $group, null, true);
if ($this->isTestingWithLdap()) {
try {
$this->addUserToLdapGroup(
$user,
$group
);
} catch (LdapException $exception) {
throw new Exception(
"User $user cannot be added to $group Error: $exception"
);
}
} else {
$response = $this->graphContext->addUserToGroup($group, $user);
$this->theHTTPStatusCodeShouldBe(204, '', $response);
}
}
/**
@@ -3073,105 +3013,6 @@ trait Provisioning {
}
}
/**
* @Given /^user "([^"]*)" has been added to database backend group "([^"]*)"$/
*
* @param string $user
* @param string $group
*
* @return void
* @throws Exception
*/
public function userHasBeenAddedToDatabaseBackendGroup(string $user, string $group):void {
$this->addUserToGroup($user, $group, 'api', true);
}
/**
* @param string $user
* @param string $group
* @param string|null $method how to add the user to the group api|occ
* @param bool $checkResult if true, then check the status of the operation. default false.
* for given step checkResult is expected to be set as true
* for when step checkResult is expected to be set as false
*
* @return void
* @throws Exception
*/
public function addUserToGroup(string $user, string $group, ?string $method = null, bool $checkResult = false):void {
$user = $this->getActualUsername($user);
if ($method === null
&& $this->isTestingWithLdap()
&& !$this->isLocalAdminGroup($group)
) {
//guess yourself
$method = "ldap";
} elseif ($method === null && OcisHelper::isTestingWithGraphApi()) {
$method = "graph";
} elseif ($method === null) {
$method = "api";
}
$method = \trim(\strtolower($method));
switch ($method) {
case "api":
$result = UserHelper::addUserToGroup(
$this->getBaseUrl(),
$user,
$group,
$this->getAdminUsername(),
$this->getAdminPassword(),
$this->getStepLineRef(),
$this->ocsApiVersion
);
if ($checkResult && ($result->getStatusCode() !== 200)) {
throw new Exception(
"could not add user to group. "
. $result->getStatusCode() . " " . $result->getBody()
);
}
$this->response = $result;
if (!$checkResult) {
// for when step only
$this->pushToLastStatusCodesArrays();
}
break;
case "ldap":
try {
$this->addUserToLdapGroup(
$user,
$group
);
} catch (LdapException $exception) {
throw new Exception(
"User $user cannot be added to $group Error: $exception"
);
};
break;
case "graph":
$this->graphContext->adminHasAddedUserToGroupUsingTheGraphApi(
$user,
$group
);
break;
default:
throw new InvalidArgumentException(
"Invalid method to add a user to a group"
);
}
}
/**
* @Given the administrator has been added to group :group
*
* @param string $group
*
* @return void
* @throws Exception
*/
public function theAdministratorHasBeenAddedToGroup(string $group):void {
$admin = $this->getAdminUsername();
$this->addUserToGroup($admin, $group, null, true);
}
/**
* @param string $group
* @param bool $shouldExist - true if the group should exist

View File

@@ -160,7 +160,7 @@ Feature: share resources where the sharee receives the share in multiple ways
| 1 | 100 |
| 2 | 200 |
@skipOnGraph
@skipOnReva
Scenario Outline: share with a group and then add a user to that group that already has a file with the shared name
Given using OCS API version "<ocs_api_version>"
And user "Carol" has been created with default attributes and without skeleton files
@@ -176,16 +176,15 @@ Feature: share resources where the sharee receives the share in multiple ways
| shareWith | grp1 |
And user "Brian" has accepted share "/lorem.txt" offered by user "Alice"
When the administrator adds user "Carol" to group "grp1" using the provisioning API
Then the OCS status code should be "<ocs_status_code>"
And the HTTP status code should be "200"
Then the HTTP status code should be "204"
And user "Carol" should be able to accept pending share "/lorem.txt" offered by user "Alice"
And the content of file "Shares/lorem.txt" for user "Brian" should be "Shared content"
And the content of file "lorem.txt" for user "Carol" should be "My content"
And the content of file "Shares/lorem.txt" for user "Carol" should be "Shared content"
Examples:
| ocs_api_version | ocs_status_code |
| 1 | 100 |
| 2 | 200 |
| ocs_api_version |
| 1 |
| 2 |
@issue-2440
Scenario: sharing parent folder to user with all permissions and its child folder to group with read permission then check create operation

View File

@@ -466,7 +466,7 @@ Feature: sharing
| 1 | 100 |
| 2 | 200 |
@skipOnGraph
@skipOnReva
Scenario Outline: share with a group and then add a user to that group
Given using OCS API version "<ocs_api_version>"
And these users have been created with default attributes and without skeleton files: