Review Address

This commit is contained in:
sagargurung1001@gmail.com
2022-11-24 14:12:26 +05:45
parent 9813fe2841
commit 4124173a51
3 changed files with 73 additions and 78 deletions

View File

@@ -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
@@ -190,7 +200,7 @@ class GraphHelper {
* @return ResponseInterface
* @throws GuzzleException
*/
public static function getUserInformation(
public static function getOwnInformationAndGroupMemberships(
string $baseUrl,
string $xRequestId,
string $user,

View File

@@ -1,5 +1,5 @@
@api
Feature: get user own information
@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
@@ -9,14 +9,11 @@ Feature: get user own information
Scenario: user gets his/her own information with no group involvement
When the user "Alice" retrives her information using the Graph API
When the user "Alice" retrieves her information using the Graph API
Then the HTTP status code should be "200"
And the api response should contains the following information:
| displayName | Alice Hansen |
| id | %UUIDv4% |
| mail | alice@example.org |
| onPremisesSamAccountName | Alice |
| memberOf | |
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
@@ -24,13 +21,8 @@ Feature: get user own information
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 should contains the following information:
| displayName | Alice Hansen |
| id | %UUIDv4% |
| onPremisesSamAccountName | Alice |
| mail | alice@example.org |
| memberOf | tea-lover, 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 |

View File

@@ -201,20 +201,6 @@ class GraphContext implements Context {
}
}
/**
* This method check if the userUUIDv4 is in correct pattern or not
*
* @param string $userUUIDv4
*
* @return int
* @throws Exception
* @throws GuzzleException
*/
public function checkUUIDv4PatternForUserId(string $userUUIDv4): int {
$UUIDv4Regex = '/^[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($UUIDv4Regex, $userUUIDv4);
}
/**
* @param string $group
*
@@ -1024,7 +1010,7 @@ class GraphContext implements Context {
string $user
):ResponseInterface {
$credentials = $this->getAdminOrUserCredentials($user);
return GraphHelper::getUserInformation(
return GraphHelper::getOwnInformationAndGroupMemberships(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$credentials["username"],
@@ -1033,7 +1019,7 @@ class GraphContext implements Context {
}
/**
* @When /^the user "([^"]*)" retrives (:?her|his) information using the Graph API$/
* @When /^the user "([^"]*)" retrieves (her|his) information using the Graph API$/
*
* @param string $user
*
@@ -1048,55 +1034,62 @@ class GraphContext implements Context {
}
/**
* @Then /^the api response should contains the following information:$/
* @Then /^the user retrieve API response should contain the following information:$/
*
* @param TableNode $table
*
* @return void
* @throws GuzzleException
*/
public function theApiResponseForUserShouldContainsTheFollowingInformation(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);
public function theUserRetrieveApiResponseShouldContainTheFollowingInformation(TableNode $table): void {
$rows = $table->getHash();
$apiResponse = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse());
foreach ($rows as $row) {
$this->checkUserInformation($row, $apiResponse);
}
// check if the user_if from response is in format UUIDv4
$isUUIDv4 = $this->featureContext->substituteInLineCodes(
$rows['id'],
$this->featureContext->getCurrentUser(),
[],
[
[
"code" => "%UUIDv4%",
"function" =>
[$this, "checkUUIDv4PatternForUserId"],
"parameter" => [$apiResponse['id']]
],
]
);
Assert::assertEquals(
1,
$isUUIDv4,
__METHOD__ .
$apiResponse['id'] . ' ID is not in the format of UUIDv4'
);
}
// assertion for remaining key other than 'memberOf' and
foreach (array_keys($rows) as $keyName) {
if ($keyName !== 'memberOf' && $keyName !== 'id') {
Assert::assertEquals(
$rows[$keyName],
$apiResponse[$keyName],
__METHOD__ .
' Expected ' . $rows[$keyName] . ' but got ' . $apiResponse[$keyName]
);
/**
* @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;
}
}
}