From 6ff9d6196f71965b7425d8cdd13426d408967b7d Mon Sep 17 00:00:00 2001 From: "sagargurung1001@gmail.com" Date: Tue, 29 Nov 2022 16:39:10 +0545 Subject: [PATCH] Added expected to failure file --- tests/TestHelpers/GraphHelper.php | 50 ++--- ...ected-failures-localAPI-on-OCIS-storage.md | 3 + .../features/apiGraph/getUser.feature | 31 ++- .../features/bootstrap/GraphContext.php | 202 ++++++++++-------- 4 files changed, 168 insertions(+), 118 deletions(-) diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index d2c49af5f5..f38023a429 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -242,31 +242,31 @@ class GraphHelper { ); } - /** - * @param string $baseUrl - * @param string $xRequestId - * @param string $adminUser - * @param string $adminPassword - * @param string $ofUser - * - * @return ResponseInterface - * @throws GuzzleException - */ - public static function getUserWithDriveInformation( - string $baseUrl, - string $xRequestId, - string $user, - string $userPassword, - string $ofUser - ): ResponseInterface { - $url = self::getFullUrl($baseUrl, 'users/'. $ofUser . '?%24select=&%24expand=drive'); - return HttpRequestHelper::get( - $url, - $xRequestId, - $user, - $userPassword, - ); - } + /** + * @param string $baseUrl + * @param string $xRequestId + * @param string $user + * @param string $userPassword + * @param string|null $ofUser + * + * @return ResponseInterface + * @throws GuzzleException + */ + public static function getUserWithDriveInformation( + string $baseUrl, + string $xRequestId, + string $user, + string $userPassword, + ?string $ofUser = null + ): ResponseInterface { + $url = self::getFullUrl($baseUrl, 'users/' . $ofUser . '?%24select=&%24expand=drive'); + return HttpRequestHelper::get( + $url, + $xRequestId, + $user, + $userPassword, + ); + } /** * @param string $baseUrl diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index b611ea8c9a..cdbbcc1865 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -78,3 +78,6 @@ The expected failures in this file are from features in the owncloud/ocis repo. #### [Requests with invalid credentials do not return CORS headers](https://github.com/owncloud/ocis/issues/5194) - [apiCors/cors.feature:67](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiCors/cors.feature#L67) - [apiCors/cors.feature:68](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiCors/cors.feature#L68) + +#### [A User can get information of another user with Graph API](https://github.com/owncloud/ocis/issues/5125) +- [apiGraph/getUser.feature:21](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L21) diff --git a/tests/acceptance/features/apiGraph/getUser.feature b/tests/acceptance/features/apiGraph/getUser.feature index dea0b77356..05df4502d9 100644 --- a/tests/acceptance/features/apiGraph/getUser.feature +++ b/tests/acceptance/features/apiGraph/getUser.feature @@ -51,12 +51,39 @@ Feature: get users And the last response should be an unauthorized response - Scenario: admin user tries to get drive data of another user + Scenario: admin user tries to get drive information of a user Given these users have been created with default attributes and without skeleton files: | username | | Brian | - When the user "Alice" tries to get information of user "Brian" along with his drive data using Graph API + When the user "Alice" tries to get user "Brian" along with his drive information using 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 | | Brian Murphy | %uuid_v4% | brian@example.org | Brian | +# And the drive information of user "Brian" should contain: +# | key | value | +# | driveType | personal | +# | driveAlias | personal/alice | +# | id | %space_id% | +# | name | Brian Murphy | +# | quota@@@state | normal | +# | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | + + + Scenario: normal user tries to get hid/her own drive information + Given these users have been created with default attributes and without skeleton files: + | username | + | Brian | + When the user "Brian" tries to get his drive information using 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 | + | Brian Murphy | %uuid_v4% | brian@example.org | Brian | +# And the drive information of user "Brian" should contain: +# | key | value | +# | driveType | personal | +# | driveAlias | personal/brian | +# | id | %space_id% | +# | name | Brian Murphy | +# | quota@@@state | normal | +# | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index 158f6dcfc4..2b2f251c64 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -1241,100 +1241,120 @@ class GraphContext implements Context { } } - /** - * @When user :user tries to get information of user :ofUser using Graph API - */ - public function userTriesToGetInformationOfUser($user, $ofUser) { - $credentials = $this->getAdminOrUserCredentials($user); - $response = GraphHelper::getUser( - $this->featureContext->getBaseUrl(), - $this->featureContext->getStepLineRef(), - $credentials['username'], - $credentials['password'], - $ofUser - ); - $this->featureContext->setResponse($response); - } + /** + * @When user :user tries to get information of user :ofUser using Graph API + * + * @param string $user + * @param string $ofUser + * + * @return void + */ + public function userTriesToGetInformationOfUser($user, $ofUser): void { + $credentials = $this->getAdminOrUserCredentials($user); + $response = GraphHelper::getUser( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $credentials['username'], + $credentials['password'], + $ofUser + ); + $this->featureContext->setResponse($response); + } + /** + * @When user :user tries to get all user using the Graph API + * + * @param string $user + * + * @return void + */ + public function userGetsAllUserUsingTheGraphApi(string $user) { + $credentials = $this->getAdminOrUserCredentials($user); + $response = GraphHelper::getUsers( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $credentials['username'], + $credentials['password'], + ); + $this->featureContext->setResponse($response); + } - /** - * @When user :user tries to get all user using the Graph API - * - * @param string $user - * - * @return void - */ - public function userGetsAllUserUsingTheGraphApi(string $user) { - $credentials = $this->getAdminOrUserCredentials($user); - $response = GraphHelper::getUsers( - $this->featureContext->getBaseUrl(), - $this->featureContext->getStepLineRef(), - $credentials['username'], - $credentials['password'], - ); - $this->featureContext->setResponse($response); - } + /** + * @Then the API response should contain all user with following information: + * + * @param TableNode $table + * + * @throws Exception + * @return void + */ + public function theApiResponseShouldContainAllUserWithFollowingInformation(TableNode $table): void { + $values = $table->getHash(); + $apiResponse = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse())['value']; + foreach ($values as $expectedValue) { + $found = false; + foreach ($apiResponse as $key => $actualResponseValue) { + if ($expectedValue["displayName"] === $actualResponseValue["displayName"]) { + $found = true; + $this->checkUserInformation($expectedValue, $actualResponseValue); + unset($apiResponse[$key]); + break; + } + } + if (!$found) { + throw new Exception('User ' . $expectedValue["displayName"] . ' could not be found in the response.'); + } + } + } - /** - * @Then the API response should contain all user with following information: - * - * @param TableNode $table - * - * @throws Exception - */ - public function theApiResponseShouldContainAllUserWithFollowingInformation(TableNode $table) { - $values = $table->getHash(); - $apiResponse = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse())['value']; - foreach ($values as $expectedValue) { - $found = false; - foreach ($apiResponse as $key => $actualResponseValue) { - if ($expectedValue["displayName"] === $actualResponseValue["displayName"]) { - $found = true; - $this->checkUserInformation($expectedValue, $actualResponseValue); - unset($apiResponse[$key]); - break; - } - } - if (!$found) { - throw new Exception('User ' . $expectedValue["displayName"] . ' could not be found in the response.'); - } - } - } + /** + * @param string $user + * @param string|null $ofUser + * + * @return ResponseInterface + * @throws JsonException + * @throws GuzzleException + */ + public function retrieveUserInformationAlongWithDriveUsingGraphApi( + string $user, + ?string $ofUser = null + ):ResponseInterface { + if ($ofUser === null) { + $ofUser = $user; + } + $credentials = $this->getAdminOrUserCredentials($user); + return GraphHelper::getUserWithDriveInformation( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $credentials["username"], + $credentials["password"], + $ofUser + ); + } - /** - * @param string $user - * @param string $ofUser - * - * @return ResponseInterface - * @throws JsonException - * @throws GuzzleException - */ - public function retrieveUserInformationAlongWithDriveUsingGraphApi( - string $user, - string $ofUser - ):ResponseInterface { - $credentials = $this->getAdminOrUserCredentials($user); - return GraphHelper::getUserWithDriveInformation( - $this->featureContext->getBaseUrl(), - $this->featureContext->getStepLineRef(), - $credentials["username"], - $credentials["password"], - $ofUser - ); - } + /** + * + * @When /^the user "([^"]*)" tries to get user "([^"]*)" along with (his|her) drive information using Graph API$/ + * + * @param string $user + * @param string $ofUser + * + * @return void + */ + public function userTriesToGetInformationOfUserAlongWithHisDriveData(string $user, $ofUser) { + $response = $this->retrieveUserInformationAlongWithDriveUsingGraphApi($user, $ofUser); + $this->featureContext->setResponse($response); + } - /** - * - * @When /^the user "([^"]*)" tries to get information of user "([^"]*)" along with (his|her) drive data using Graph API$/ - * - * @param string $user - * @param string $ofUser - * - * @return void - */ - public function userTriesToGetInformationOfUserAlongWithHisDriveData(string $user, string $ofUser) - { - $response = $this->retrieveUserInformationAlongWithDriveUsingGraphApi($user, $ofUser); - $this->featureContext->setResponse($response); - } + /** + * + * @When /^the user "([^"]*)" tries to get (his|her) drive information using Graph API$/ + * + * @param string $user + * + * @return void + */ + public function userTriesToGetOwnDriveInformation(string $user) { + $response = $this->retrieveUserInformationAlongWithDriveUsingGraphApi($user); + $this->featureContext->setResponse($response); + } }