adding tests for searching groups as a normal user (#8096)

This commit is contained in:
nirajacharya2
2024-01-17 12:52:37 +05:45
committed by GitHub
parent 7e18f96d87
commit 97f2c8d354
4 changed files with 184 additions and 14 deletions
+26
View File
@@ -554,6 +554,32 @@ class GraphHelper {
);
}
/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $user
* @param string $password
* @param string $searchTerm
*
* @return ResponseInterface
*/
public static function searchGroup(
string $baseUrl,
string $xRequestId,
string $user,
string $password,
string $searchTerm
): ResponseInterface {
$url = self::getFullUrl($baseUrl, "groups?\$search=$searchTerm");
return HttpRequestHelper::get(
$url,
$xRequestId,
$user,
$password,
self::getRequestHeaders()
);
}
/**
* @param string $baseUrl
* @param string $xRequestId
@@ -86,9 +86,9 @@ The expected failures in this file are from features in the owncloud/ocis repo.
#### [Normal user can get expanded members information of a group](https://github.com/owncloud/ocis/issues/5604)
- [apiGraph/getGroup.feature:381](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L381)
- [apiGraph/getGroup.feature:382](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L382)
- [apiGraph/getGroup.feature:383](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L383)
- [apiGraph/getGroup.feature:389](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L389)
- [apiGraph/getGroup.feature:390](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L390)
- [apiGraph/getGroup.feature:391](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L391)
#### [Same users can be added in a group multiple time](https://github.com/owncloud/ocis/issues/5702)
@@ -111,9 +111,9 @@ The expected failures in this file are from features in the owncloud/ocis repo.
- [apiGraph/editGroup.feature:35](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/editGroup.feature#L35)
- [apiGraph/editGroup.feature:34](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/editGroup.feature#L34)
- [apiGraph/editGroup.feature:36](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/editGroup.feature#L36)
- [apiGraph/getGroup.feature:103](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L103)
- [apiGraph/getGroup.feature:104](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L104)
- [apiGraph/getGroup.feature:105](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L105)
- [apiGraph/getGroup.feature:107](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L107)
- [apiGraph/getGroup.feature:108](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L108)
- [apiGraph/getGroup.feature:109](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L109)
- [apiGraph/removeUserFromGroup.feature:193](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/removeUserFromGroup.feature#L193)
- [apiGraph/removeUserFromGroup.feature:194](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/removeUserFromGroup.feature#L194)
- [apiGraph/removeUserFromGroup.feature:195](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/removeUserFromGroup.feature#L195)
@@ -42,8 +42,10 @@ Feature: get groups and their members
"message"
],
"properties": {
"type": "string",
"enum": ["Unauthorized"]
"message": {
"type": "string",
"enum": ["search term too short"]
}
}
}
}
@@ -91,8 +93,10 @@ Feature: get groups and their members
"message"
],
"properties": {
"type": "string",
"enum": ["Unauthorized"]
"message": {
"type": "string",
"enum": ["Unauthorized"]
}
}
}
}
@@ -255,8 +259,10 @@ Feature: get groups and their members
"message"
],
"properties": {
"type": "string",
"enum": ["Unauthorized"]
"message": {
"type": "string",
"enum": ["search term too short"]
}
}
}
}
@@ -369,8 +375,10 @@ Feature: get groups and their members
"message"
],
"properties": {
"type": "string",
"enum": ["Unauthorized"]
"message": {
"type": "string",
"enum": ["Unauthorized"]
}
}
}
}
@@ -444,3 +452,117 @@ Feature: get groups and their members
Scenario: admin user tries to get group information of non-existing group
When user "Alice" gets details of the group "non-existing" using the Graph API
Then the HTTP status code should be "404"
Scenario Outline: non-admin user search for a group by group name
Given these users have been created with default attributes and without skeleton files:
| username |
| Brian |
And group "tea-lover" has been created
When user "Brian" searches for group "<group>" using Graph API
Then the HTTP status code should be "200"
And the JSON data of the response should match
"""
{
"type": "object",
"required": [
"value"
],
"properties": {
"value": {
"type": "array",
"required": [
"displayName",
"id",
"groupTypes"
],
"properties": {
"displayName": {
"type": "string",
"enum": ["tea-lover"]
},
"id": {
"type": "string",
"pattern": "%group_id_pattern%"
},
"groupTypes": {
"type": "array",
"enum": []
}
}
}
}
}
"""
Examples:
| group |
| tea |
| %22tea-%22 |
Scenario: non-admin user tries to search for a group by group name with less than 3 characters
Given these users have been created with default attributes and without skeleton files:
| username |
| Brian |
And group "tea-lover" has been created
When user "Brian" tries to search for group "te" using Graph API
Then the HTTP status code should be "403"
And the JSON data of the response should match
"""
{
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "object",
"required": [
"message"
],
"properties": {
"message":{
"type": "string",
"enum": ["search term too short"]
}
}
}
}
}
"""
@issue-7990
Scenario Outline: non-admin user tries to search for a group by group name with invalid characters/token
Given these users have been created with default attributes and without skeleton files:
| username |
| Brian |
And group "<group>" has been created
When user "Brian" tries to search for group "<group>" using Graph API
Then the HTTP status code should be "400"
And the JSON data of the response should match
"""
{
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "object",
"required": [
"message"
],
"properties": {
"message": {
"type": "string",
"enum": ["Token '<token>' is invalid"]
}
}
}
}
}
"""
Examples:
| group | token |
| tea-lovers | -lovers |
| tea@lovers | @lovers |
@@ -1900,6 +1900,28 @@ class GraphContext implements Context {
);
}
/**
* @When user :user tries to search for group :searchTerm using Graph API
* @When user :user searches for group :searchTerm using Graph API
*
* @param string $user
* @param string $searchTerm
*
* @return void
*/
public function userSearchesForGroupUsingGraphApi($user, $searchTerm):void {
$credentials = $this->getAdminOrUserCredentials($user);
$this->featureContext->setResponse(
GraphHelper::searchGroup(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$credentials["username"],
$credentials["password"],
$searchTerm
)
);
}
/**
* @Then /^the JSON data of the response should (not )?contain the user "([^"]*)" in the item 'value'(?:, the user-details should match)?$/
* @Then /^the JSON data of the response should (not )?contain the group "([^"]*)" in the item 'value'(?:, the group-details should match)?$/