From 94c3df224697bdbe7f82828d853e96e5b894bae1 Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Fri, 10 Mar 2023 09:05:00 +0100 Subject: [PATCH] [test-only] add test to filter or (#5771) * add test to filter or * lint --- tests/TestHelpers/GraphHelper.php | 29 +++++++++++++++++++ .../features/apiGraph/getUser.feature | 20 +++++++++++++ .../features/bootstrap/GraphContext.php | 22 ++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index 16e8c6f1e..8ed3baf3b 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -1151,6 +1151,35 @@ class GraphHelper { ); } + /** + * @param string $baseUrl + * @param string $xRequestId + * @param string $user + * @param string $password + * @param string $firstGroup + * @param string $secondGroup + * + * @return ResponseInterface + * @throws GuzzleException + */ + public static function getUsersFromOneOrOtherGroup( + string $baseUrl, + string $xRequestId, + string $user, + string $password, + string $firstGroup, + string $secondGroup + ): ResponseInterface { + $url = self::getFullUrl($baseUrl, 'users' . '?$filter=memberOf/any(m:m/id ' . "eq '$firstGroup') " . "or memberOf/any(m:m/id eq '$secondGroup')"); + return HttpRequestHelper::get( + $url, + $xRequestId, + $user, + $password, + self::getRequestHeaders() + ); + } + /** * @param string $baseUrl * @param string $xRequestId diff --git a/tests/acceptance/features/apiGraph/getUser.feature b/tests/acceptance/features/apiGraph/getUser.feature index 5778a6949..d422cedff 100644 --- a/tests/acceptance/features/apiGraph/getUser.feature +++ b/tests/acceptance/features/apiGraph/getUser.feature @@ -135,6 +135,26 @@ Feature: get users | Alice Hansen | %uuid_v4% | alice@example.org | Alice | true | | Carol King | %uuid_v4% | carol@example.org | Carol | true | + @skipOnStable2.0 + Scenario: admin user gets all users of certain groups + Given user "Carol" has been created with default attributes and without skeleton files + And group "tea-lover" has been created + And group "coffee-lover" has been created + And group "wine-lover" has been created + And user "Alice" has been added to group "tea-lover" + And user "Brian" has been added to group "coffee-lover" + And user "Carol" has been added to group "wine-lover" + When the user "Alice" gets all users from that are members in the group "tea-lover" or the group "coffee-lover" using the Graph API + Then the HTTP status code should be "200" + And the API response should contain following users with the information: + | displayName | id | mail | onPremisesSamAccountName | accountEnabled | + | Alice Hansen | %uuid_v4% | alice@example.org | Alice | true | + | Brian Murphy | %uuid_v4% | brian@example.org | Brian | true | + But the API response should not contain following user with the information: + | displayName | id | mail | onPremisesSamAccountName | accountEnabled | + | Carol King | %uuid_v4% | carol@example.org | Carol | false | + + Scenario Outline: non admin user tries to get users of certain groups Given the administrator has given "Brian" the role "" using the settings api And group "tea-lover" has been created diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index 8275c468a..8f3b37606 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -1890,6 +1890,28 @@ class GraphContext implements Context { $this->featureContext->setResponse($response); } + /** + * @When the user :user gets all users from that are members in the group :firstGroup or the group :secondGroup using the Graph API + * + * @param string $user + * @param string $firstGroup + * @param string $secondGroup + * + * @return void + * @throws GuzzleException + */ + public function userGetsAllUsersOfFirstGroupOderSecondGroupUsingTheGraphApi(string $user, string $firstGroup, string $secondGroup) { + $response = GraphHelper::getUsersFromOneOrOtherGroup( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $user, + $this->featureContext->getPasswordForUser($user), + $firstGroup, + $secondGroup + ); + $this->featureContext->setResponse($response); + } + /** * Get roleId by role name *