diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index a81470095f..d2c49af5f5 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -242,6 +242,32 @@ 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 diff --git a/tests/acceptance/features/apiGraph/getUser.feature b/tests/acceptance/features/apiGraph/getUser.feature new file mode 100644 index 0000000000..dea0b77356 --- /dev/null +++ b/tests/acceptance/features/apiGraph/getUser.feature @@ -0,0 +1,62 @@ +@api @skipOnOcV10 +Feature: get users + As an admin + I want to be able to retrieve user information + So that I can see the information + + Background: + Given user "Alice" has been created with default attributes and without skeleton files + And the administrator has given "Alice" the role "Admin" using the settings api + + + Scenario: admin user tries get information of a user + Given user "Brian" has been created with default attributes and without skeleton files + When user "Alice" tries to get information of user "Brian" 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 | + + + Scenario: non-admin user tries get information of a user + Given user "Brian" has been created with default attributes and without skeleton files + When user "Brian" tries to get information of user "Alice" using Graph API + Then the HTTP status code should be "200" + And the last response should be an unauthorized response + + + Scenario: admin user tries get all user + Given these users have been created with default attributes and without skeleton files: + | username | + | Brian | + | Carol | + | David | + When user "Alice" tries to get all user using the Graph API + Then the HTTP status code should be "200" + And the API response should contain all user with following information: + | displayName | id | mail | onPremisesSamAccountName | + | Brian Murphy | %uuid_v4% | brian@example.org | Brian | + | David Lopez | %uuid_v4% | david@example.org | David | + | Carol King | %uuid_v4% | carol@example.org | Carol | + + + Scenario: non-admin user tries get all user + Given these users have been created with default attributes and without skeleton files: + | username | + | Brian | + | Carol | + | David | + When user "Brian" tries to get all user using the Graph API + Then the HTTP status code should be "401" + And the last response should be an unauthorized response + + + Scenario: admin user tries to get drive data of another 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 + 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 | diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index 0eb723b37f..158f6dcfc4 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -1240,4 +1240,101 @@ 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 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 + */ + 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 $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 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); + } }