Merge pull request #5084 from owncloud/infoAboutUserGraphTest
[tests-only][full-ci]Added test to get user information with GraphAPI
This commit is contained in:
3 files changed
+160
-2
No files matched your search
@@ -26,6 +26,16 @@ class GraphHelper {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
*
|
||||
* @return int (1 = true | 0 = false)
|
||||
*/
|
||||
public static function isUUIDv4(string $id): int {
|
||||
$regex = '/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i';
|
||||
return preg_match($regex, $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $path
|
||||
@@ -181,6 +191,31 @@ class GraphHelper {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string $user
|
||||
* @param string $userPassword
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function getOwnInformationAndGroupMemberships(
|
||||
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
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
@api @skipOnOcV10
|
||||
Feature: get user's own 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" retrieves her information using the Graph API
|
||||
Then the HTTP status code should be "200"
|
||||
And the user retrieve API response should contain the following information:
|
||||
| displayName | id | mail | onPremisesSamAccountName |
|
||||
| Alice Hansen | %uuid_v4% | alice@example.org | Alice |
|
||||
|
||||
|
||||
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" retrieves her information using the Graph API
|
||||
Then the HTTP status code should be "200"
|
||||
And the user retrieve API response should contain the following information:
|
||||
| displayName | id | mail | onPremisesSamAccountName | memberOf |
|
||||
| Alice Hansen | %uuid_v4% | alice@example.org | Alice | tea-lover, coffee-lover |
|
||||
@@ -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,99 @@ 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::getOwnInformationAndGroupMemberships(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$credentials["username"],
|
||||
$credentials["password"],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^the user "([^"]*)" retrieves (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 user retrieve API response should contain the following information:$/
|
||||
*
|
||||
* @param TableNode $table
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function theUserRetrieveApiResponseShouldContainTheFollowingInformation(TableNode $table): void {
|
||||
$rows = $table->getHash();
|
||||
$apiResponse = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse());
|
||||
foreach ($rows as $row) {
|
||||
$this->checkUserInformation($row, $apiResponse);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $expectedValue
|
||||
* @param array $actualValue
|
||||
*
|
||||
* @throws GuzzleException
|
||||
* @return void
|
||||
*/
|
||||
public function checkUserInformation(array $expectedValue, array $actualValue):void {
|
||||
foreach (array_keys($expectedValue) as $keyName) {
|
||||
switch ($keyName) {
|
||||
case "memberOf":
|
||||
$memberOfFromApiReponse = [];
|
||||
$memberOf = preg_split('/\s*,\s*/', trim($expectedValue['memberOf']));
|
||||
foreach ($actualValue['memberOf'] as $member) {
|
||||
$memberOfFromApiReponse[] = $member['displayName'];
|
||||
}
|
||||
Assert::assertEqualsCanonicalizing($memberOf, $memberOfFromApiReponse);
|
||||
break;
|
||||
case "id":
|
||||
if ($expectedValue[$keyName] !== '%uuid_v4%') {
|
||||
throw new Error(
|
||||
'Only UUIDv4 patterned user id can be checked' . ' but got '
|
||||
. trim($expectedValue[$keyName], '%')
|
||||
);
|
||||
}
|
||||
Assert::assertEquals(
|
||||
1,
|
||||
GraphHelper::isUUIDv4($actualValue['id']),
|
||||
__METHOD__ .
|
||||
' Expected user_id to have UUIDv4 pattern but found: ' . $actualValue['id']
|
||||
);
|
||||
break;
|
||||
default:
|
||||
Assert::assertEquals(
|
||||
$expectedValue[$keyName],
|
||||
$actualValue[$keyName],
|
||||
__METHOD__ .
|
||||
' Expected ' . $keyName . 'to have value' . $expectedValue[$keyName]
|
||||
. ' but got ' . $actualValue[$keyName]
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user