[tests-only][full-ci] Forwardport test for send wrong host for adding user in group (#5932)

* added test for admin trying to add user with wrong host

* added test for adding single user to a group with invalid hostname
This commit is contained in:
Prajwol Amatya
2023-03-27 15:47:55 +05:45
committed by GitHub
parent eefd1b82aa
commit 1e5bf171fe
3 changed files with 99 additions and 0 deletions
@@ -135,5 +135,9 @@ The expected failures in this file are from features in the owncloud/ocis repo.
#### [Try to add group to a group return 204](https://github.com/owncloud/ocis/issues/5793)
- [apiGraph/addUserToGroup.feature:244](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L244)
### [Users are added in a group with wrong host in host-part of user](https://github.com/owncloud/ocis/issues/5871)
- [apiGraph/addUserToGroup.feature:292](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L292)
- [apiGraph/addUserToGroup.feature:306](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L306)
Note: always have an empty line at the end of this file.
The bash script that processes this file requires that the last line has a newline on the end.
@@ -287,3 +287,27 @@ Feature: add users to group
| {'members@odata.bind': ['https://localhost:9200/graph/v1.0/users/%user_id%',,'https://localhost:9200/graph/v1.0/users/%user_id%']} |
| {'members@odata.bind'- ['https://localhost:9200/graph/v1.0/users/%user_id%','https://localhost:9200/graph/v1.0/users/%user_id%']} |
| {'members@odata.bind': ['https://localhost:9200/graph/v1.0/users/%user_id%'.'https://localhost:9200/graph/v1.0/users/%user_id%']} |
@issue-5871
Scenario: admin tries to add multiple users with wrong host
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 user "Alice" tries to add the following users to a group "grp1" at once with an invalid host using the Graph API
| username |
| Brian |
| Carol |
Then the HTTP status code should be "400"
@issue-5871
Scenario: admin tries to add single user with wrong host
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 user "Alice" tries to add user "Brian" to group "grp1" with an invalid host using the Graph API
Then the HTTP status code should be "400"
@@ -1759,6 +1759,77 @@ class GraphContext implements Context {
$this->addMultipleUsersToGroup($user, $userIds, $groupId, $table);
}
/**
* @When /^user "([^"]*)" tries to add the following users to a group "([^"]*)" at once with an invalid host using the Graph API$/
*
* @param string $user
* @param string $group
* @param TableNode $table
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function userTriesToAddTheFollowingUsersToAGroupAtOnceWithInvalidHostUsingTheGraphApi(string $user, string $group, TableNode $table): void {
$userIds = [];
$groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id");
$credentials = $this->getAdminOrUserCredentials($user);
$this->featureContext->verifyTableNodeColumns($table, ['username']);
foreach ($table->getHash() as $row) {
$userIds[] = $this->featureContext->getAttributeOfCreatedUser($row['username'], "id");
}
$payload = [ "members@odata.bind" => [] ];
foreach ($userIds as $userId) {
$payload["members@odata.bind"][] = GraphHelper::getFullUrl('https://invalid/', 'users/' . $userId);
}
$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
GraphHelper::getFullUrl($this->featureContext->getBaseUrl(), 'groups/' . $groupId),
$this->featureContext->getStepLineRef(),
'PATCH',
$credentials["username"],
$credentials["password"],
['Content-Type' => 'application/json'],
\json_encode($payload)
)
);
}
/**
* @When /^user "([^"]*)" tries to add user "([^"]*)" to group "([^"]*)" with an invalid host using the Graph API$/
*
* @param string $adminUser
* @param string $user
* @param string $group
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function userTriesToAddUserToGroupWithInvalidHostUsingTheGraphApi(string $adminUser, string $user, string $group): void {
$groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id");
$userId = $this->featureContext->getAttributeOfCreatedUser($user, "id");
$credentials = $this->getAdminOrUserCredentials($adminUser);
$body = [
"@odata.id" => GraphHelper::getFullUrl('https://invalid/', 'users/' . $userId)
];
$this->featureContext->setResponse(
HttpRequestHelper::post(
GraphHelper::getFullUrl($this->featureContext->getBaseUrl(), 'groups/' . $groupId . '/members/$ref'),
$this->featureContext->getStepLineRef(),
$credentials["username"],
$credentials["password"],
['Content-Type' => 'application/json'],
\json_encode($body)
)
);
}
/**
* @When /^the administrator "([^"]*)" tries to add the following users to a nonexistent group at once using the Graph API$/
*