Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
saw-jan marked this conversation as resolved.
Show resolved Hide resolved
$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");
}
S-Panta marked this conversation as resolved.
Show resolved Hide resolved
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