mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-04-25 21:48:28 -05:00
Refactored and added test to get user information with GraphAPI
This commit is contained in:
@@ -181,6 +181,31 @@ class GraphHelper {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string $user
|
||||
* @param string $userPassword
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function getUserInformation(
|
||||
string $baseUrl,
|
||||
string $xRequestId,
|
||||
string $user,
|
||||
string $userPassword
|
||||
): ResponseInterface {
|
||||
$url = self::getFullUrl($baseUrl, 'me/?%24expand=memberOf');
|
||||
return HttpRequestHelper::get(
|
||||
$url,
|
||||
$xRequestId,
|
||||
$user,
|
||||
$userPassword,
|
||||
self::getRequestHeaders()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
|
||||
@@ -1,11 +1,36 @@
|
||||
@api
|
||||
Feature: get user information
|
||||
As an admin, subadmin or as myself
|
||||
I want to be able to retrieve user information
|
||||
So that I can see the information
|
||||
As user
|
||||
I want to be able to retrieve my own information
|
||||
So that I can see my information
|
||||
|
||||
Background:
|
||||
Given user "Alice" has been created with default attributes and without skeleton files
|
||||
|
||||
|
||||
Scenario: user gets his/her own information with no group involvement
|
||||
When the user "Alice" retrives her information using the Graph API
|
||||
Then the HTTP status code should be "200"
|
||||
And the api response for user "Alice" should contains the following information:
|
||||
| displayName | Alice Hansen |
|
||||
| id | %user_id% |
|
||||
| mail | alice@example.org |
|
||||
| onPremisesSamAccountName | Alice |
|
||||
| memberOf | |
|
||||
|
||||
|
||||
Scenario: user gets his/her own information with group involvement
|
||||
Given 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 "Alice" has been added to group "coffee-lover"
|
||||
When the user "Alice" retrives her information using the Graph API
|
||||
And the api response for user "Alice" should contains the following information:
|
||||
| displayName | Alice Hansen |
|
||||
| id | %user_id% |
|
||||
| onPremisesSamAccountName | Alice |
|
||||
| mail | alice@example.org |
|
||||
| memberOf | tea-lover, coffee-lover |
|
||||
|
||||
|
||||
|
||||
Scenario: admin gets an existing user
|
||||
Given these users have been created with default attributes and without skeleton files:
|
||||
| username | displayname |
|
||||
| brand-new-user | Brand New User |
|
||||
|
||||
@@ -649,7 +649,7 @@ class GraphContext implements Context {
|
||||
public function theAdministratorTriesToAddUserToGroupUsingTheGraphAPI(string $user, string $group): void {
|
||||
$this->featureContext->setResponse($this->addUserToGroup($group, $user));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @When user :user tries to add himself/herself to group :group using the Graph API
|
||||
*
|
||||
@@ -874,7 +874,7 @@ class GraphContext implements Context {
|
||||
$response = $this->userDeletesGroupWithGroupId($groupId, $user);
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Then the following users should be listed in the following groups
|
||||
*
|
||||
@@ -998,4 +998,82 @@ class GraphContext implements Context {
|
||||
}
|
||||
$this->featureContext->setResponse($this->removeUserFromGroup($groupId, $userId, $byUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $user
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws JsonException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function retrieveUserInformationUsingGraphApi(
|
||||
string $user
|
||||
):ResponseInterface {
|
||||
$credentials = $this->getAdminOrUserCredentials($user);
|
||||
return GraphHelper::getUserInformation(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$credentials["username"],
|
||||
$credentials["password"],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^the user "([^"]*)" retrives (:?her|his) information using the Graph API$/
|
||||
*
|
||||
* @param string $user
|
||||
*
|
||||
* @return void
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function userRetrievesHisorHerInformationOfUserUsingGraphApi(
|
||||
string $user
|
||||
):void {
|
||||
$response = $this->retrieveUserInformationUsingGraphApi($user);
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^the api response for user "([^"]*)" should contains the following information:$/
|
||||
*
|
||||
* @param string $user
|
||||
* @param TableNode $table
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function theApiResponseForUserShouldContainsTheFollowingInformation(string $user, TableNode $table): void {
|
||||
$rows = $table->getRowsHash();
|
||||
$apiResponse = \json_decode((string)$this->featureContext->getResponse()->getBody(), true, 512, JSON_THROW_ON_ERROR);
|
||||
// assertion of the user is member of groups
|
||||
if ($rows['memberOf']) {
|
||||
// collect memberOf from response
|
||||
$memberOfFromApiReponse = [];
|
||||
$memberOf = preg_split('/\s*,\s*/', trim($rows['memberOf']));
|
||||
foreach ($apiResponse['memberOf'] as $member) {
|
||||
$memberOfFromApiReponse[] = $member['displayName'];
|
||||
}
|
||||
Assert::assertEqualsCanonicalizing($memberOf, $memberOfFromApiReponse);
|
||||
}
|
||||
// get user_id for the given user
|
||||
$rows['id'] = $this->featureContext->substituteInLineCodes(
|
||||
$rows['id'],
|
||||
$this->featureContext->getCurrentUser(),
|
||||
[],
|
||||
[
|
||||
[
|
||||
"code" => "%user_id%",
|
||||
"function" =>
|
||||
[$this->spacesContext, "getUserIdByUserName"],
|
||||
"parameter" => [$user]
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
// assertion for remaining key other than 'memberOf'
|
||||
foreach (array_keys($rows) as $keyName) {
|
||||
if ($keyName !== 'memberOf') {
|
||||
Assert::assertEquals($rows[$keyName], $apiResponse[$keyName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user