mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-03-09 07:18:40 -05:00
[test-only] ApiTest. get users of members of several groups (#5575)
* get users with group filter * fix test
This commit is contained in:
@@ -1019,4 +1019,58 @@ class GraphHelper {
|
||||
self::getRequestHeaders()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $groupId
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function getUsersWithFilterMemberOf(
|
||||
string $baseUrl,
|
||||
string $xRequestId,
|
||||
string $user,
|
||||
string $password,
|
||||
string $groupId
|
||||
): ResponseInterface {
|
||||
$url = self::getFullUrl($baseUrl, 'users' . '?$filter=memberOf/any(m:m/id ' . "eq '$groupId')");
|
||||
return HttpRequestHelper::get(
|
||||
$url,
|
||||
$xRequestId,
|
||||
$user,
|
||||
$password,
|
||||
self::getRequestHeaders()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param array $groupIdArray
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function getUsersOfTwoGroups(
|
||||
string $baseUrl,
|
||||
string $xRequestId,
|
||||
string $user,
|
||||
string $password,
|
||||
array $groupIdArray
|
||||
): ResponseInterface {
|
||||
$url = self::getFullUrl($baseUrl, 'users' . '?$filter=memberOf/any(m:m/id ' . "eq '$groupIdArray[0]') " . "and memberOf/any(m:m/id eq '$groupIdArray[1]')");
|
||||
return HttpRequestHelper::get(
|
||||
$url,
|
||||
$xRequestId,
|
||||
$user,
|
||||
$password,
|
||||
self::getRequestHeaders()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ default:
|
||||
- WebDavPropertiesContext:
|
||||
- TUSContext:
|
||||
- SpacesTUSContext:
|
||||
- GraphContext:
|
||||
|
||||
apiSpacesShares:
|
||||
paths:
|
||||
@@ -75,6 +76,7 @@ default:
|
||||
- TUSContext:
|
||||
- SpacesTUSContext:
|
||||
- ArchiverContext:
|
||||
- GraphContext:
|
||||
|
||||
apiContract:
|
||||
paths:
|
||||
@@ -96,6 +98,7 @@ default:
|
||||
- WebDavPropertiesContext:
|
||||
- TUSContext:
|
||||
- SpacesTUSContext:
|
||||
- GraphContext:
|
||||
|
||||
apiArchiver:
|
||||
paths:
|
||||
@@ -115,6 +118,7 @@ default:
|
||||
- FavoritesContext:
|
||||
- TrashbinContext:
|
||||
- WebDavPropertiesContext:
|
||||
- GraphContext:
|
||||
|
||||
apiGraph:
|
||||
paths:
|
||||
@@ -152,6 +156,7 @@ default:
|
||||
- FilesVersionsContext:
|
||||
- OCSContext:
|
||||
- TrashbinContext:
|
||||
- GraphContext:
|
||||
|
||||
apiAsyncUpload:
|
||||
paths:
|
||||
@@ -167,6 +172,7 @@ default:
|
||||
- FilesVersionsContext:
|
||||
- OCSContext:
|
||||
- TrashbinContext:
|
||||
- GraphContext:
|
||||
|
||||
|
||||
extensions:
|
||||
|
||||
@@ -29,7 +29,7 @@ Feature: get users
|
||||
Scenario: admin user gets all users
|
||||
When user "Alice" gets all users using the Graph API
|
||||
Then the HTTP status code should be "200"
|
||||
And the API response should contain all users with the following information:
|
||||
And the API response should contain following users with the information:
|
||||
| displayName | id | mail | onPremisesSamAccountName |
|
||||
| Alice Hansen | %uuid_v4% | alice@example.org | Alice |
|
||||
| Brian Murphy | %uuid_v4% | brian@example.org | Brian |
|
||||
@@ -96,4 +96,30 @@ Feature: get users
|
||||
When the user "Carol" gets user "Brian" along with his group information using Graph API
|
||||
Then the HTTP status code should be "401"
|
||||
And the last response should be an unauthorized response
|
||||
|
||||
|
||||
|
||||
Scenario: admin user gets all users of certain groups
|
||||
Given user "Carol" has been created with default attributes and without skeleton files
|
||||
And group "tea-lover" has been created
|
||||
And group "coffee-lover" has been created
|
||||
And user "Alice" has been added to group "tea-lover"
|
||||
And user "Brian" has been added to group "tea-lover"
|
||||
And user "Brian" has been added to group "coffee-lover"
|
||||
When the user "Alice" gets all users of the group "tea-lover" using the Graph API
|
||||
Then the HTTP status code should be "200"
|
||||
And the API response should contain following users with the information:
|
||||
| displayName | id | mail | onPremisesSamAccountName |
|
||||
| Alice Hansen | %uuid_v4% | alice@example.org | Alice |
|
||||
| Brian Murphy | %uuid_v4% | brian@example.org | Brian |
|
||||
But the API response should not contain following user with the information:
|
||||
| displayName | id | mail | onPremisesSamAccountName |
|
||||
| Carol King | %uuid_v4% | carol@example.org | Carol |
|
||||
When the user "Alice" gets all users of two groups "tea-lover,coffee-lover" using the Graph API
|
||||
Then the HTTP status code should be "200"
|
||||
And the API response should contain following user with the information:
|
||||
| displayName | id | mail | onPremisesSamAccountName |
|
||||
| Brian Murphy | %uuid_v4% | brian@example.org | Brian |
|
||||
But the API response should not contain following users with the information:
|
||||
| displayName | id | mail | onPremisesSamAccountName |
|
||||
| Alice Hansen | %uuid_v4% | alice@example.org | Alice |
|
||||
| Carol King | %uuid_v4% | carol@example.org | Carol |
|
||||
|
||||
@@ -39,6 +39,7 @@ use TestHelpers\HttpRequestHelper;
|
||||
use TestHelpers\UploadHelper;
|
||||
use TestHelpers\OcisHelper;
|
||||
use Laminas\Ldap\Ldap;
|
||||
use TestHelpers\GraphHelper;
|
||||
use TestHelpers\WebDavHelper;
|
||||
|
||||
require_once 'bootstrap.php';
|
||||
@@ -3104,6 +3105,8 @@ class FeatureContext extends BehatVariablesContext {
|
||||
* "parameter" => []
|
||||
* ],
|
||||
* ]
|
||||
* @param string|null $group
|
||||
* @param string|null $userName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -3111,7 +3114,9 @@ class FeatureContext extends BehatVariablesContext {
|
||||
?string $value,
|
||||
?string $user = null,
|
||||
?array $functions = [],
|
||||
?array $additionalSubstitutions = []
|
||||
?array $additionalSubstitutions = [],
|
||||
?string $group = null,
|
||||
?string $userName = null
|
||||
): ?string {
|
||||
$substitutions = [
|
||||
[
|
||||
@@ -3249,6 +3254,18 @@ class FeatureContext extends BehatVariablesContext {
|
||||
"getLastPublicShareToken"
|
||||
],
|
||||
"parameter" => []
|
||||
],
|
||||
[
|
||||
"code" => "%user_id%",
|
||||
"function" =>
|
||||
[$this, "getUserIdByUserName"],
|
||||
"parameter" => [$userName]
|
||||
],
|
||||
[
|
||||
"code" => "%group_id%",
|
||||
"function" =>
|
||||
[$this, "getGroupIdByGroupName"],
|
||||
"parameter" => [$group]
|
||||
]
|
||||
];
|
||||
if ($user !== null) {
|
||||
@@ -3293,6 +3310,18 @@ class FeatureContext extends BehatVariablesContext {
|
||||
"getPersonalSpaceIdForUser",
|
||||
],
|
||||
"parameter" => [$user, true]
|
||||
],
|
||||
[
|
||||
"code" => "%user_id%",
|
||||
"function" =>
|
||||
[$this, "getUserIdByUserName"],
|
||||
"parameter" => [$userName]
|
||||
],
|
||||
[
|
||||
"code" => "%group_id%",
|
||||
"function" =>
|
||||
[$this, "getGroupIdByGroupName"],
|
||||
"parameter" => [$group]
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -4485,4 +4514,58 @@ class FeatureContext extends BehatVariablesContext {
|
||||
$this->getBaseUrl()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The method returns userId
|
||||
*
|
||||
* @param string $userName
|
||||
*
|
||||
* @return string
|
||||
* @throws Exception|GuzzleException
|
||||
*/
|
||||
public function getUserIdByUserName(string $userName): string {
|
||||
$response = GraphHelper::getUser(
|
||||
$this->getBaseUrl(),
|
||||
$this->getStepLineRef(),
|
||||
$this->getAdminUsername(),
|
||||
$this->getAdminPassword(),
|
||||
$userName
|
||||
);
|
||||
if ($response) {
|
||||
$data = \json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
|
||||
if (isset($data["id"])) {
|
||||
return $data["id"];
|
||||
} else {
|
||||
throw new Exception(__METHOD__ . " accounts-list is empty");
|
||||
}
|
||||
}
|
||||
throw new Exception(__METHOD__ . " user with name $userName not found");
|
||||
}
|
||||
|
||||
/**
|
||||
* The method returns groupId
|
||||
*
|
||||
* @param string $groupName
|
||||
*
|
||||
* @return string
|
||||
* @throws Exception|GuzzleException
|
||||
*/
|
||||
public function getGroupIdByGroupName(string $groupName): string {
|
||||
$response = GraphHelper::getGroup(
|
||||
$this->getBaseUrl(),
|
||||
$this->getStepLineRef(),
|
||||
$this->getAdminUsername(),
|
||||
$this->getAdminPassword(),
|
||||
$groupName
|
||||
);
|
||||
if ($response) {
|
||||
$data = $this->getJsonDecodedResponse($response);
|
||||
if (isset($data["id"])) {
|
||||
return $data["id"];
|
||||
} else {
|
||||
throw new Exception(__METHOD__ . " accounts-list is empty");
|
||||
}
|
||||
}
|
||||
throw new Exception(__METHOD__ . " Group with name $groupName not found");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,11 +28,6 @@ class GraphContext implements Context {
|
||||
*/
|
||||
private FeatureContext $featureContext;
|
||||
|
||||
/**
|
||||
* @var SpacesContext
|
||||
*/
|
||||
private SpacesContext $spacesContext;
|
||||
|
||||
/**
|
||||
* This will run before EVERY scenario.
|
||||
* It will set the properties for this object.
|
||||
@@ -1284,14 +1279,15 @@ class GraphContext implements Context {
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the API response should contain all users with the following information:
|
||||
* @Then /^the API response should (not|)\s?contain following (user|users) with the information:$/
|
||||
*
|
||||
* @param string $shouldOrNot (not|)
|
||||
* @param TableNode $table
|
||||
*
|
||||
* @throws Exception
|
||||
* @return void
|
||||
*/
|
||||
public function theApiResponseShouldContainAllUserWithFollowingInformation(TableNode $table): void {
|
||||
public function theApiResponseShouldContainAllUserWithFollowingInformation(string $shouldOrNot, TableNode $table): void {
|
||||
$values = $table->getHash();
|
||||
$apiResponse = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse())['value'];
|
||||
foreach ($values as $expectedValue) {
|
||||
@@ -1304,8 +1300,10 @@ class GraphContext implements Context {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
throw new Exception('User ' . $expectedValue["displayName"] . ' could not be found in the response.');
|
||||
if ($shouldOrNot === 'not') {
|
||||
Assert::assertFalse($found, $expectedValue["displayName"] . ' has been found in the response, but should not be.');
|
||||
} else {
|
||||
Assert::assertTrue($found, $expectedValue["displayName"] . ' could not be found in the response.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1520,4 +1518,49 @@ class GraphContext implements Context {
|
||||
Assert::assertTrue($foundRoleInResponse, "the response does not contain the role $row[0]");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @When the user :user gets all users of the group :group using the Graph API
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $group
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function userGetsAllUsersOfTheGroupUsingTheGraphApi(string $user, string $group) {
|
||||
$groupId = $this->featureContext->getGroupIdByGroupName($group);
|
||||
$response = GraphHelper::getUsersWithFilterMemberOf(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$groupId
|
||||
);
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When the user :user gets all users of two groups :groups using the Graph API
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $groups
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function userGetsAllUsersOfTwoGroupsUsingTheGraphApi(string $user, string $groups) {
|
||||
$groupsIdArray = [];
|
||||
foreach (explode(',', $groups) as $group) {
|
||||
array_push($groupsIdArray, $this->featureContext->getGroupIdByGroupName($group));
|
||||
}
|
||||
$response = GraphHelper::getUsersOfTwoGroups(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$groupsIdArray
|
||||
);
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,11 +69,17 @@ class SpacesContext implements Context {
|
||||
* @var ChecksumContext
|
||||
*/
|
||||
private ChecksumContext $checksumContext;
|
||||
|
||||
/**
|
||||
* @var FilesVersionsContext
|
||||
*/
|
||||
private FilesVersionsContext $filesVersionsContext;
|
||||
|
||||
/**
|
||||
* @var GraphContext
|
||||
*/
|
||||
private GraphContext $graphContext;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@@ -397,60 +403,6 @@ class SpacesContext implements Context {
|
||||
return $fileData["Etag"][0];
|
||||
}
|
||||
|
||||
/**
|
||||
* The method returns userId
|
||||
*
|
||||
* @param string $userName
|
||||
*
|
||||
* @return string
|
||||
* @throws Exception|GuzzleException
|
||||
*/
|
||||
public function getUserIdByUserName(string $userName): string {
|
||||
$response = GraphHelper::getUser(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword(),
|
||||
$userName
|
||||
);
|
||||
if ($response) {
|
||||
$data = \json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
|
||||
if (isset($data["id"])) {
|
||||
return $data["id"];
|
||||
} else {
|
||||
throw new Exception(__METHOD__ . " accounts-list is empty");
|
||||
}
|
||||
}
|
||||
throw new Exception(__METHOD__ . " user with name $userName not found");
|
||||
}
|
||||
|
||||
/**
|
||||
* The method returns groupId
|
||||
*
|
||||
* @param string $groupName
|
||||
*
|
||||
* @return string
|
||||
* @throws Exception|GuzzleException
|
||||
*/
|
||||
public function getGroupIdByGroupName(string $groupName): string {
|
||||
$response = GraphHelper::getGroup(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword(),
|
||||
$groupName
|
||||
);
|
||||
if ($response) {
|
||||
$data = $this->featureContext->getJsonDecodedResponse($response);
|
||||
if (isset($data["id"])) {
|
||||
return $data["id"];
|
||||
} else {
|
||||
throw new Exception(__METHOD__ . " accounts-list is empty");
|
||||
}
|
||||
}
|
||||
throw new Exception(__METHOD__ . " Group with name $groupName not found");
|
||||
}
|
||||
|
||||
/**
|
||||
* using method from core to set share data
|
||||
*
|
||||
@@ -485,6 +437,7 @@ class SpacesContext implements Context {
|
||||
$this->favoritesContext = $environment->getContext('FavoritesContext');
|
||||
$this->checksumContext = $environment->getContext('ChecksumContext');
|
||||
$this->filesVersionsContext = $environment->getContext('FilesVersionsContext');
|
||||
$this->graphContext = $environment->getContext('GraphContext');
|
||||
// Run the BeforeScenario function in OCSContext to set it up correctly
|
||||
$this->ocsContext->before($scope);
|
||||
$this->baseUrl = \trim($this->featureContext->getBaseUrl(), "/");
|
||||
@@ -990,12 +943,6 @@ class SpacesContext implements Context {
|
||||
[$this, "getSpaceIdByNameFromResponse"],
|
||||
"parameter" => [$spaceName]
|
||||
],
|
||||
[
|
||||
"code" => "%user_id%",
|
||||
"function" =>
|
||||
[$this, "getUserIdByUserName"],
|
||||
"parameter" => [$userName]
|
||||
],
|
||||
[
|
||||
"code" => "%file_id%",
|
||||
"function" =>
|
||||
@@ -1007,14 +954,10 @@ class SpacesContext implements Context {
|
||||
"function" =>
|
||||
[$this, "getETag"],
|
||||
"parameter" => [$userName, $spaceName, $fileName]
|
||||
],
|
||||
[
|
||||
"code" => "%group_id%",
|
||||
"function" =>
|
||||
[$this, "getGroupIdByGroupName"],
|
||||
"parameter" => [$groupName]
|
||||
]
|
||||
]
|
||||
],
|
||||
$groupName,
|
||||
$userName
|
||||
);
|
||||
$segments = explode("@@@", $row["key"]);
|
||||
// traverse down in the array
|
||||
@@ -1111,7 +1054,7 @@ class SpacesContext implements Context {
|
||||
);
|
||||
Assert::assertIsArray($spaceAsArray = $this->getSpaceByNameFromResponse($spaceName), "No space with name $spaceName found");
|
||||
$permissions = $spaceAsArray["root"]["permissions"];
|
||||
$userId = $this->getUserIdByUserName($grantedUser);
|
||||
$userId = $this->featureContext->getUserIdByUserName($grantedUser);
|
||||
|
||||
$userRole = "";
|
||||
foreach ($permissions as $permission) {
|
||||
@@ -3277,7 +3220,7 @@ class SpacesContext implements Context {
|
||||
"Expected response status code should be 200"
|
||||
);
|
||||
Assert::assertIsArray($spaceAsArray = $this->getSpaceByNameFromResponse($spaceName), "No space with name $spaceName found");
|
||||
$recipientType === 'user' ? $recipientId = $this->getUserIdByUserName($recipient) : $recipientId = $this->getGroupIdByGroupName($recipient);
|
||||
$recipientType === 'user' ? $recipientId = $this->featureContext->getUserIdByUserName($recipient) : $recipientId = $this->featureContext->getGroupIdByGroupName($recipient);
|
||||
$foundRoleInResponse = false;
|
||||
foreach ($spaceAsArray['root']['permissions'] as $permission) {
|
||||
if (isset($permission['grantedToIdentities'][0][$recipientType]) && $permission['roles'][0] === $role && $permission['grantedToIdentities'][0][$recipientType]['id'] === $recipientId) {
|
||||
|
||||
Reference in New Issue
Block a user