From b52597d6d1399fc9a8860f8ad31a1d5bb8d21d0d Mon Sep 17 00:00:00 2001 From: Sagar Gurung <46086950+SagarGi@users.noreply.github.com> Date: Wed, 5 Apr 2023 14:05:34 +0545 Subject: [PATCH] [tests-only][full-ci]Json assertion apigraph `master` branch (#5989) * Json assertion for api graph suite * Review Address --- ...ected-failures-localAPI-on-OCIS-storage.md | 104 +- .../features/apiGraph/addUserToGroup.feature | 44 +- .../features/apiGraph/editUser.feature | 324 ++++++- .../features/apiGraph/getGroup.feature | 282 +++++- .../features/apiGraph/getUser.feature | 899 ++++++++++++++++-- .../apiGraph/getUserOwnInformation.feature | 85 +- .../apiGraph/removeUserFromGroup.feature | 22 +- .../features/bootstrap/FeatureContext.php | 8 + .../features/bootstrap/GraphContext.php | 272 +----- 9 files changed, 1614 insertions(+), 426 deletions(-) diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index ed335cdf4e..826e427348 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -85,52 +85,52 @@ The expected failures in this file are from features in the owncloud/ocis repo. - [apiSpacesShares/publicLinkDownload.feature:30](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesShares/publicLinkDownload.feature#L30) #### [A User can get information of another user with Graph API](https://github.com/owncloud/ocis/issues/5125) -- [apiGraph/getUser.feature:31](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L31) -- [apiGraph/getUser.feature:32](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L32) -- [apiGraph/getUser.feature:33](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L33) -- [apiGraph/getUser.feature:34](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L34) -- [apiGraph/getUser.feature:35](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L35) -- [apiGraph/getUser.feature:36](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L36) -- [apiGraph/getUser.feature:37](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L37) -- [apiGraph/getUser.feature:38](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L38) -- [apiGraph/getUser.feature:39](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L39) -- [apiGraph/getUser.feature:40](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L40) -- [apiGraph/getUser.feature:41](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L41) -- [apiGraph/getUser.feature:42](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L42) -- [apiGraph/getUser.feature:144](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L144) -- [apiGraph/getUser.feature:145](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L145) -- [apiGraph/getUser.feature:146](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L146) -- [apiGraph/getUser.feature:147](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L147) -- [apiGraph/getUser.feature:148](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L148) -- [apiGraph/getUser.feature:149](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L149) -- [apiGraph/getUser.feature:150](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L150) -- [apiGraph/getUser.feature:151](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L151) -- [apiGraph/getUser.feature:152](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L152) -- [apiGraph/getUser.feature:153](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L153) -- [apiGraph/getUser.feature:154](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L154) -- [apiGraph/getUser.feature:155](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L155) +- [apiGraph/getUser.feature:83](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L83) +- [apiGraph/getUser.feature:84](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L84) +- [apiGraph/getUser.feature:85](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L85) +- [apiGraph/getUser.feature:86](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L86) +- [apiGraph/getUser.feature:87](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L87) +- [apiGraph/getUser.feature:88](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L88) +- [apiGraph/getUser.feature:89](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L89) +- [apiGraph/getUser.feature:90](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L90) +- [apiGraph/getUser.feature:91](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L91) +- [apiGraph/getUser.feature:92](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L92) +- [apiGraph/getUser.feature:93](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L93) +- [apiGraph/getUser.feature:94](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L94) +- [apiGraph/getUser.feature:607](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L607) +- [apiGraph/getUser.feature:608](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L608) +- [apiGraph/getUser.feature:609](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L609) +- [apiGraph/getUser.feature:610](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L610) +- [apiGraph/getUser.feature:611](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L611) +- [apiGraph/getUser.feature:612](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L612) +- [apiGraph/getUser.feature:613](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L613) +- [apiGraph/getUser.feature:614](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L614) +- [apiGraph/getUser.feature:615](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L615) +- [apiGraph/getUser.feature:616](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L616) +- [apiGraph/getUser.feature:617](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L617) +- [apiGraph/getUser.feature:618](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L618) #### [Sharing to a group with an expiration date does not work #5442](https://github.com/owncloud/ocis/issues/5442) - [apiSpacesShares/shareSubItemOfSpace.feature:105](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesShares/shareSubItemOfSpace.feature#L105) #### [Normal user can get expanded members information of a group](https://github.com/owncloud/ocis/issues/5604) -- [apiGraph/getGroup.feature:130](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L130) -- [apiGraph/getGroup.feature:131](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L131) -- [apiGraph/getGroup.feature:132](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L132) +- [apiGraph/getGroup.feature:382](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L382) +- [apiGraph/getGroup.feature:383](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L383) +- [apiGraph/getGroup.feature:384](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L384) #### [Changing user with an uppercase name gives 404 error](https://github.com/owncloud/ocis/issues/5763) -- [apiGraph/editUser.feature:41](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/editUser.feature#L41) +- [apiGraph/editUser.feature:65](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/editUser.feature#L65) #### [Same users can be added in a group multiple time](https://github.com/owncloud/ocis/issues/5702) -- [apiGraph/addUserToGroup.feature:246](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L246) +- [apiGraph/addUserToGroup.feature:286](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L286) #### [API requests from an unauthorized user should return 403](https://github.com/owncloud/ocis/issues/5938) -- [apiGraph/addUserToGroup.feature:131](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L131) -- [apiGraph/addUserToGroup.feature:132](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L132) -- [apiGraph/addUserToGroup.feature:133](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L133) -- [apiGraph/addUserToGroup.feature:145](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L145) -- [apiGraph/addUserToGroup.feature:146](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L146) -- [apiGraph/addUserToGroup.feature:147](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L147) +- [apiGraph/addUserToGroup.feature:151](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L151) +- [apiGraph/addUserToGroup.feature:152](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L152) +- [apiGraph/addUserToGroup.feature:153](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L153) +- [apiGraph/addUserToGroup.feature:185](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L185) +- [apiGraph/addUserToGroup.feature:186](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L186) +- [apiGraph/addUserToGroup.feature:187](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L187) - [apiGraph/createGroup.feature:41](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/createGroup.feature#L41) - [apiGraph/createGroup.feature:42](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/createGroup.feature#L42) - [apiGraph/createGroup.feature:43](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/createGroup.feature#L43) @@ -140,35 +140,35 @@ The expected failures in this file are from features in the owncloud/ocis repo. - [apiGraph/editGroup.feature:35](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/editGroup.feature#L35) - [apiGraph/editGroup.feature:36](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/editGroup.feature#L36) - [apiGraph/editGroup.feature:37](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/editGroup.feature#L37) -- [apiGraph/getGroup.feature:35](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L35) -- [apiGraph/getGroup.feature:36](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L36) -- [apiGraph/getGroup.feature:37](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L37) -- [apiGraph/getGroup.feature:64](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L64) -- [apiGraph/getGroup.feature:65](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L65) -- [apiGraph/getGroup.feature:66](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L66) -- [apiGraph/getGroup.feature:102](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L102) -- [apiGraph/getGroup.feature:103](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L103) +- [apiGraph/getGroup.feature:55](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L55) +- [apiGraph/getGroup.feature:56](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L56) +- [apiGraph/getGroup.feature:57](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L57) - [apiGraph/getGroup.feature:104](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L104) -- [apiGraph/removeUserFromGroup.feature:172](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/removeUserFromGroup.feature#L172) -- [apiGraph/removeUserFromGroup.feature:173](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/removeUserFromGroup.feature#L173) -- [apiGraph/removeUserFromGroup.feature:174](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/removeUserFromGroup.feature#L174) +- [apiGraph/getGroup.feature:105](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L105) +- [apiGraph/getGroup.feature:106](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L106) +- [apiGraph/getGroup.feature:268](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L268) +- [apiGraph/getGroup.feature:269](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L269) +- [apiGraph/getGroup.feature:270](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L270) +- [apiGraph/removeUserFromGroup.feature:192](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/removeUserFromGroup.feature#L192) +- [apiGraph/removeUserFromGroup.feature:193](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/removeUserFromGroup.feature#L193) +- [apiGraph/removeUserFromGroup.feature:194](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/removeUserFromGroup.feature#L194) - [apiSpaces/createSpace.feature:18](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/createSpace.feature#L18) - [apiSpaces/createSpace.feature:19](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/createSpace.feature#L19) #### [API requests for a non-existent resources should return 404](https://github.com/owncloud/ocis/issues/5939) -- [apiGraph/addUserToGroup.feature:162](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L162) -- [apiGraph/addUserToGroup.feature:163](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L163) -- [apiGraph/addUserToGroup.feature:164](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L164) +- [apiGraph/addUserToGroup.feature:202](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L202) +- [apiGraph/addUserToGroup.feature:203](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L203) +- [apiGraph/addUserToGroup.feature:204](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L204) ### [Users are added in a group with wrong host in host-part of user](https://github.com/owncloud/ocis/issues/5871) -- [apiGraph/addUserToGroup.feature:316](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L316) -- [apiGraph/addUserToGroup.feature:330](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L330) +- [apiGraph/addUserToGroup.feature:356](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L356) +- [apiGraph/addUserToGroup.feature:370](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L370) #### [Admin user can't restore other user spaces](https://github.com/owncloud/ocis/issues/5872) - [apiSpaces/restoreSpaces.feature:94](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/restoreSpaces.feature#L94) ### [Adding the same user as multiple members in a single request results in listing the same user twice in the group](https://github.com/owncloud/ocis/issues/5855) -- [apiGraph/addUserToGroup.feature:367](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L367) +- [apiGraph/addUserToGroup.feature:407](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/addUserToGroup.feature#L407) Note: always have an empty line at the end of this file. The bash script that processes this file requires that the last line has a newline on the end. diff --git a/tests/acceptance/features/apiGraph/addUserToGroup.feature b/tests/acceptance/features/apiGraph/addUserToGroup.feature index aefef6311f..afdfb4a94c 100644 --- a/tests/acceptance/features/apiGraph/addUserToGroup.feature +++ b/tests/acceptance/features/apiGraph/addUserToGroup.feature @@ -125,7 +125,27 @@ Feature: add users to group And group "groupA" has been created When user "Alice" tries to add himself to group "groupA" using the Graph API Then the HTTP status code should be "403" - And the last response should be an unauthorized response + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "type": "string", + "enum": ["Unauthorized"] + } + } + } + } + """ Examples: | role | | Space Admin | @@ -139,7 +159,27 @@ Feature: add users to group And group "groupA" has been created When user "Alice" tries to add user "Brian" to group "groupA" using the Graph API Then the HTTP status code should be "403" - And the last response should be an unauthorized response + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "type": "string", + "enum": ["Unauthorized"] + } + } + } + } + """ Examples: | role | | Space Admin | diff --git a/tests/acceptance/features/apiGraph/editUser.feature b/tests/acceptance/features/apiGraph/editUser.feature index 6901e5bb03..2d54e6cb3c 100644 --- a/tests/acceptance/features/apiGraph/editUser.feature +++ b/tests/acceptance/features/apiGraph/editUser.feature @@ -17,9 +17,21 @@ Feature: edit user Scenario Outline: the admin user can edit another user's email When the user "Alice" changes the email of user "Brian" to "" using the Graph API Then the HTTP status code should be "" - And the user "Brian" should have information with these key and value pairs: - | key | value | - | mail | | + And the user information of "Brian" should match this JSON schema + """ + { + "type": "object", + "required": [ + "mail" + ], + "properties": { + "mail": { + "type": "string", + "enum": [""] + } + } + } + """ Examples: | action description | newEmail | code | emailAsResult | | change to a valid email | newemail@example.com | 200 | newemail@example.com | @@ -33,15 +45,27 @@ Feature: edit user Given user "Carol" has been created with default attributes and without skeleton files When the user "Alice" changes the user name of user "Carol" to "" using the Graph API Then the HTTP status code should be "" - And the user "" should have information with these key and value pairs: - | key | value | - | onPremisesSamAccountName | | + And the user information of "" should match this JSON schema + """ + { + "type": "object", + "required": [ + "onPremisesSamAccountName" + ], + "properties": { + "type": "string", + "onPremisesSamAccountName": { + "enum": [""] + } + } + } + """ Examples: - | action description | userName | code | userNameAsResult | - | change to a valid user name | Lionel | 200 | Lionel | - | user name characters | *:!;_+-& | 200 | *:!;_+-& | - | change to existing user name | Brian | 409 | Brian | - | empty user name | | 200 | Brian | + | action description | userName | code | newUserName | + | change to a valid user name | Lionel | 200 | Lionel | + | user name characters | *:!;_+-& | 200 | *:!;_+-& | + | change to existing user name | Brian | 409 | Brian | + | empty user name | | 200 | Brian | @skipOnStable2.0 Scenario: the admin user changes the name of a user to the name of an existing disabled user @@ -53,9 +77,21 @@ Feature: edit user And the user "Alice" has disabled user "Brian" using the Graph API When the user "Alice" changes the user name of user "sam" to "Brian" using the Graph API Then the HTTP status code should be "409" - And the user "sam" should have information with these key and value pairs: - | key | value | - | onPremisesSamAccountName | sam | + And the user information of "sam" should match this JSON schema + """ + { + "type": "object", + "required": [ + "onPremisesSamAccountName" + ], + "properties": { + "onPremisesSamAccountName": { + "type": "string", + "enum": ["sam"] + } + } + } + """ @skipOnStable2.0 Scenario: the admin user changes the name of a user to the name of a previously deleted user @@ -67,18 +103,42 @@ Feature: edit user And the user "Alice" has deleted a user "sam" using the Graph API When the user "Alice" changes the user name of user "Brian" to "sam" using the Graph API Then the HTTP status code should be "200" - And the user "sam" should have information with these key and value pairs: - | key | value | - | onPremisesSamAccountName | sam | + And the user information of "sam" should match this JSON schema + """ + { + "type": "object", + "required": [ + "onPremisesSamAccountName" + ], + "properties": { + "onPremisesSamAccountName": { + "type": "string", + "enum": ["sam"] + } + } + } + """ Scenario Outline: a normal user should not be able to change their email address Given the administrator has given "Brian" the role "" using the settings api When the user "Brian" tries to change the email of user "Brian" to "newemail@example.com" using the Graph API Then the HTTP status code should be "401" - And the user "Brian" should have information with these key and value pairs: - | key | value | - | mail | brian@example.com | + And the user information of "Brian" should match this JSON schema + """ + { + "type": "object", + "required": [ + "mail" + ], + "properties": { + "mail": { + "type": "string", + "enum": ["brian@example.com"] + } + } + } + """ Examples: | role | | Space Admin | @@ -96,9 +156,21 @@ Feature: edit user And the administrator has given "Carol" the role "" using the settings api When the user "Brian" tries to change the email of user "Carol" to "newemail@example.com" using the Graph API Then the HTTP status code should be "401" - And the user "Carol" should have information with these key and value pairs: - | key | value | - | mail | carol@example.com | + And the user information of "Carol" should match this JSON schema + """ + { + "type": "object", + "required": [ + "mail" + ], + "properties": { + "mail": { + "type": "string", + "enum": ["carol@example.com"] + } + } + } + """ Examples: | userRole | role | | Space Admin | Space Admin | @@ -118,9 +190,21 @@ Feature: edit user Scenario Outline: the admin user can edit another user display name When the user "Alice" changes the display name of user "Brian" to "" using the Graph API Then the HTTP status code should be "200" - And the user "Brian" should have information with these key and value pairs: - | key | value | - | displayName | | + And the user information of "Brian" should match this JSON schema + """ + { + "type": "object", + "required": [ + "displayName" + ], + "properties": { + "displayName": { + "type": "string", + "enum": [""] + } + } + } + """ Examples: | action description | newDisplayName | code | displayNameAsResult | | change to a display name | Olaf Scholz | 200 | Olaf Scholz | @@ -133,9 +217,21 @@ Feature: edit user Given the administrator has given "Brian" the role "" using the settings api When the user "Brian" tries to change the display name of user "Brian" to "Brian Murphy" using the Graph API Then the HTTP status code should be "401" - And the user "Alice" should have information with these key and value pairs: - | key | value | - | displayName | Alice Hansen | + And the user information of "Alice" should match this JSON schema + """ + { + "type": "object", + "required": [ + "displayName" + ], + "properties": { + "displayName": { + "type": "string", + "enum": ["Alice Hansen"] + } + } + } + """ Examples: | role | | Space Admin | @@ -153,9 +249,21 @@ Feature: edit user And the administrator has given "Carol" the role "" using the settings api When the user "Brian" tries to change the display name of user "Carol" to "Alice Hansen" using the Graph API Then the HTTP status code should be "401" - And the user "Carol" should have information with these key and value pairs: - | key | value | - | displayName | Carol King | + And the user information of "Carol" should match this JSON schema + """ + { + "type": "object", + "required": [ + "displayName" + ], + "properties": { + "displayName": { + "type": "string", + "enum": ["Carol King"] + } + } + } + """ Examples: | userRole | role | | Space Admin | Space Admin | @@ -213,9 +321,41 @@ Feature: edit user Then the HTTP status code should be "200" When user "Alice" gets 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 | accountEnabled | - | Brian Murphy | %uuid_v4% | brian@example.com | Brian | false | + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "displayName", + "id", + "mail", + "onPremisesSamAccountName", + "accountEnabled" + ], + "properties": { + "displayName": { + "type": "string", + "enum": ["Brian Murphy"] + }, + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["brian@example.com"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Brian"] + }, + "accountEnabled": { + "type": "boolean", + "enum": [false] + } + } + } + """ @skipOnStable2.0 Scenario Outline: a normal user should not be able to disable another user @@ -225,9 +365,41 @@ Feature: edit user Then the HTTP status code should be "401" When user "Alice" gets information of user "Carol" 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 | accountEnabled | - | Carol King | %uuid_v4% | carol@example.org | Carol | true | + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "displayName", + "id", + "mail", + "onPremisesSamAccountName", + "accountEnabled" + ], + "properties": { + "displayName": { + "type": "string", + "enum": ["Carol King"] + }, + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["carol@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Carol"] + }, + "accountEnabled": { + "type": "boolean", + "enum": [true] + } + } + } + """ Examples: | role | | Space Admin | @@ -241,9 +413,41 @@ Feature: edit user Then the HTTP status code should be "200" When user "Alice" gets 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 | accountEnabled | - | Brian Murphy | %uuid_v4% | brian@example.com | Brian | true | + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "displayName", + "id", + "mail", + "onPremisesSamAccountName", + "accountEnabled" + ], + "properties": { + "displayName": { + "type": "string", + "enum": ["Brian Murphy"] + }, + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["brian@example.com"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Brian"] + }, + "accountEnabled": { + "type": "boolean", + "enum": [true] + } + } + } + """ @skipOnStable2.0 Scenario Outline: a normal user should not be able to enable another user @@ -254,9 +458,41 @@ Feature: edit user Then the HTTP status code should be "401" When user "Alice" gets information of user "Carol" 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 | accountEnabled | - | Carol King | %uuid_v4% | carol@example.org | Carol | false | + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "displayName", + "id", + "mail", + "onPremisesSamAccountName", + "accountEnabled" + ], + "properties": { + "displayName": { + "type": "string", + "enum": ["Carol King"] + }, + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["carol@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Carol"] + }, + "accountEnabled": { + "type": "boolean", + "enum": [false] + } + } + } + """ Examples: | role | | Space Admin | diff --git a/tests/acceptance/features/apiGraph/getGroup.feature b/tests/acceptance/features/apiGraph/getGroup.feature index 63a73e6e89..a6f4b3d007 100644 --- a/tests/acceptance/features/apiGraph/getGroup.feature +++ b/tests/acceptance/features/apiGraph/getGroup.feature @@ -29,7 +29,27 @@ Feature: get groups and their members And group "h2o-lover" has been created When user "Brian" gets all the groups using the Graph API Then the HTTP status code should be "403" - And the last response should be an unauthorized response + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "type": "string", + "enum": ["Unauthorized"] + } + } + } + } + """ Examples: | role | | Space Admin | @@ -58,7 +78,27 @@ Feature: get groups and their members And group "tea-lover" has been created When user "Brian" gets all the members of group "tea-lover" using the Graph API Then the HTTP status code should be "403" - And the last response should be an unauthorized response + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "type": "string", + "enum": ["Unauthorized"] + } + } + } + } + """ Examples: | role | | Space Admin | @@ -78,13 +118,119 @@ Feature: get groups and their members And user "Carol" has been added to group "tea-lover" When user "Alice" retrieves all groups along with their members using the Graph API Then the HTTP status code should be "200" - And the group 'coffee-lover' should have the following member information - | displayName | id | mail | onPremisesSamAccountName | - | Brian Murphy | %uuid_v4% | brian@example.org | Brian | - And the group 'tea-lover' should have the following member information - | displayName | id | mail | onPremisesSamAccountName | - | Alice Hansen | %uuid_v4% | alice@example.org | Alice | - | Carol King | %uuid_v4% | carol@example.org | Carol | + And the JSON data of the response should contain the group "coffee-lover" in the item 'value', the group-details should match + """ + { + "type": "object", + "required": [ + "members" + ], + "properties": { + "members": { + "type": "array", + "items": [ + { + "type": "object", + "required": [ + "displayName", + "id", + "mail", + "onPremisesSamAccountName" + ], + "properties": { + "displayName": { + "type": "string", + "enum": ["Brian Murphy"] + }, + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["brian@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Brian"] + } + } + } + ] + } + } + } + """ + And the JSON data of the response should contain the group "tea-lover" in the item 'value', the group-details should match + """ + { + "type": "object", + "required": [ + "members" + ], + "properties": { + "members": { + "type": "array", + "items": [ + { + "type": "object", + "required": [ + "displayName", + "id", + "mail", + "onPremisesSamAccountName" + ], + "properties": { + "displayName": { + "type": "string", + "enum": ["Alice Hansen"] + }, + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["alice@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Alice"] + } + } + }, + { + "type": "object", + "required": [ + "displayName", + "id", + "mail", + "onPremisesSamAccountName" + ], + "properties": { + "displayName": { + "type": "string", + "enum": ["Carol King"] + }, + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["carol@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Carol"] + } + } + } + ] + } + } + } + """ @issue-5938 Scenario Outline: user other than the admin shouldn't get all groups along with its member's information @@ -96,7 +242,27 @@ Feature: get groups and their members And user "Brian" has been added to group "coffee-lover" When user "Brian" retrieves all groups along with their members using the Graph API Then the HTTP status code should be "403" - And the last response should be an unauthorized response + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "type": "string", + "enum": ["Unauthorized"] + } + } + } + } + """ Examples: | role | | Space Admin | @@ -110,10 +276,76 @@ Feature: get groups and their members And user "Alice" has been added to group "tea-lover" And user "Brian" has been added to group "tea-lover" When user "Alice" gets all the members information of group "tea-lover" using the Graph API - And the group 'tea-lover' should have the following member information - | displayName | id | mail | onPremisesSamAccountName | - | Alice Hansen | %uuid_v4% | alice@example.org | Alice | - | Brian Murphy | %uuid_v4% | brian@example.org | Brian | + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "members" + ], + "properties": { + "members": { + "type": "array", + "items": [ + { + "type": "object", + "required": [ + "displayName", + "id", + "mail", + "onPremisesSamAccountName" + ], + "properties": { + "displayName": { + "type": "string", + "enum": ["Alice Hansen"] + }, + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["alice@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Alice"] + } + } + }, + { + "type": "object", + "required": [ + "displayName", + "id", + "mail", + "onPremisesSamAccountName" + ], + "properties": { + "displayName": { + "type": "string", + "enum": ["Brian Murphy"] + }, + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["brian@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Brian"] + } + } + } + ] + } + } + } + """ @issue-5604 Scenario Outline: user other than the admin gets a group along with its member's information @@ -124,7 +356,27 @@ Feature: get groups and their members And user "Brian" has been added to group "tea-lover" When user "Brian" gets all the members information of group "tea-lover" using the Graph API Then the HTTP status code should be "403" - And the last response should be an unauthorized response + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "type": "string", + "enum": ["Unauthorized"] + } + } + } + } + """ Examples: | role | | Space Admin | diff --git a/tests/acceptance/features/apiGraph/getUser.feature b/tests/acceptance/features/apiGraph/getUser.feature index 44bfe00cc3..aba8bb6582 100644 --- a/tests/acceptance/features/apiGraph/getUser.feature +++ b/tests/acceptance/features/apiGraph/getUser.feature @@ -15,9 +15,41 @@ Feature: get users Given the administrator has given "Alice" the role "Admin" using the settings api When user "Alice" gets 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 | accountEnabled | - | Brian Murphy | %uuid_v4% | brian@example.org | Brian | true | + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "displayName", + "id", + "mail", + "onPremisesSamAccountName", + "accountEnabled" + ], + "properties": { + "displayName": { + "type": "string", + "enum": ["Brian Murphy"] + }, + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["brian@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Brian"] + }, + "accountEnabled": { + "type": "boolean", + "enum": [true] + } + } + } + """ @issue-5125 Scenario Outline: non-admin user tries to get the information of a user @@ -25,7 +57,27 @@ Feature: get users And the administrator has given "Brian" the role "" using the settings api When user "Brian" tries to get information of user "Alice" using Graph API Then the HTTP status code should be "401" - And the last response should be an unauthorized response + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "type": "string", + "enum": ["Unauthorized"] + } + } + } + } + """ Examples: | userRole | role | | Space Admin | Space Admin | @@ -46,10 +98,66 @@ Feature: get users Given the administrator has given "Alice" the role "Admin" using the settings api When user "Alice" gets all users 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 | + And the JSON data of the response should contain the user "Alice Hansen" in the item 'value', the user-details should match + """ + { + "type": "object", + "required": [ + "id", + "mail", + "onPremisesSamAccountName", + "accountEnabled" + ], + "properties": { + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["alice@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Alice"] + }, + "accountEnabled": { + "type": "boolean", + "enum": [true] + } + } + } + """ + And the JSON data of the response should contain the user "Brian Murphy" in the item 'value', the user-details should match + """ + { + "type": "object", + "required": [ + "id", + "mail", + "onPremisesSamAccountName", + "accountEnabled" + ], + "properties": { + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["brian@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Brian"] + }, + "accountEnabled": { + "type": "boolean", + "enum": [true] + } + } + } + """ @skipOnStable2.0 Scenario: admin user gets all users include disabled users @@ -57,17 +165,93 @@ Feature: get users And the user "Alice" has disabled user "Brian" using the Graph API When user "Alice" gets all users 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 | false | + And the JSON data of the response should contain the user "Alice Hansen" in the item 'value', the user-details should match + """ + { + "type": "object", + "required": [ + "id", + "mail", + "onPremisesSamAccountName", + "accountEnabled" + ], + "properties": { + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["alice@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Alice"] + }, + "accountEnabled": { + "type": "boolean", + "enum": [true] + } + } + } + """ + And the JSON data of the response should contain the user "Brian Murphy" in the item 'value', the user-details should match + """ + { + "type": "object", + "required": [ + "id", + "mail", + "onPremisesSamAccountName", + "accountEnabled" + ], + "properties": { + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["brian@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Brian"] + }, + "accountEnabled": { + "type": "boolean", + "enum": [false] + } + } + } + """ Scenario Outline: non-admin user tries to get all users Given the administrator has given "Alice" the role "" using the settings api When user "Brian" tries to get all users using the Graph API Then the HTTP status code should be "401" - And the last response should be an unauthorized response + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "type": "string", + "enum": ["Unauthorized"] + } + } + } + } + """ Examples: | userRole | | Space Admin | @@ -79,38 +263,246 @@ Feature: get users Given the administrator has given "Alice" the role "Admin" using the settings api When the user "Alice" gets 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 | accountEnabled | - | Brian Murphy | %uuid_v4% | brian@example.org | Brian | true | - And the user retrieve API response should contain the following drive information: - | driveType | personal | - | driveAlias | personal/brian | - | id | %space_id% | - | name | Brian Murphy | - | owner@@@user@@@id | %user_id% | - | quota@@@state | normal | - | root@@@id | %space_id% | - | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | - | webUrl | %base_url%/f/%space_id% | + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "displayName", + "id", + "mail", + "onPremisesSamAccountName", + "drive", + "accountEnabled" + ], + "properties": { + "displayName": { + "type": "string", + "enum": ["Brian Murphy"] + }, + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["brian@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Brian"] + }, + "accountEnabled": { + "type": "boolean", + "enum": [true] + }, + "drive": { + "type": "object", + "required": [ + "driveAlias", + "id", + "name", + "owner", + "quota", + "root", + "webUrl" + ], + "properties": { + "driveType" : { + "type": "string", + "enum": ["personal"] + }, + "driveAlias" : { + "type": "string", + "enum": ["personal/brian"] + }, + "id" : { + "type": "string", + "pattern": "^%space_id_pattern%$" + }, + "name": { + "type": "string", + "enum": ["Brian Murphy"] + }, + "owner": { + "type": "object", + "required": [ + "user" + ], + "properties": { + "user": "string", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "string", + "enum": ["%user_id_pattern%"] + } + } + } + }, + "quota": { + "type": "object", + "required": [ + "state" + ], + "properties": { + "state": { + "type": "string", + "enum": ["normal"] + } + } + }, + "root": { + "type": "object", + "required": [ + "id", + "webDavUrl" + ], + "properties": { + "state": { + "type": "string", + "enum": ["normal"] + }, + "webDavUrl": { + "type": "string", + "pattern": "^%base_url%/dav/spaces/%space_id_pattern%$" + } + } + }, + "webUrl": { + "type": "string", + "pattern": "^%base_url%/f/%space_id_pattern%$" + } + } + } + } + } + """ @skipOnStable2.0 Scenario Outline: non-admin user gets his/her own drive information Given the administrator has given "Brian" the role "" using the settings api When the user "Brian" gets 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 | accountEnabled | - | Brian Murphy | %uuid_v4% | brian@example.org | Brian | true | - And the user retrieve API response should contain the following drive information: - | driveType | personal | - | driveAlias | personal/brian | - | id | %space_id% | - | name | Brian Murphy | - | owner@@@user@@@id | %user_id% | - | quota@@@state | normal | - | root@@@id | %space_id% | - | root@@@webDavUrl | %base_url%/dav/spaces/%space_id% | - | webUrl | %base_url%/f/%space_id% | + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "displayName", + "id", + "mail", + "onPremisesSamAccountName", + "drive", + "accountEnabled" + ], + "properties": { + "displayName": { + "type": "string", + "enum": ["Brian Murphy"] + }, + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["brian@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Brian"] + }, + "accountEnabled": { + "type": "boolean", + "enum": [true] + }, + "drive": { + "type": "object", + "required": [ + "driveAlias", + "id", + "name", + "owner", + "quota", + "root", + "webUrl" + ], + "properties": { + "driveType" : { + "type": "string", + "enum": ["personal"] + }, + "driveAlias" : { + "type": "string", + "enum": ["personal/brian"] + }, + "id" : { + "type": "string", + "pattern": "^%space_id_pattern%$" + }, + "name": { + "type": "string", + "enum": ["Brian Murphy"] + }, + "owner": { + "type": "object", + "required": [ + "user" + ], + "properties": { + "user": "string", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "string", + "enum": ["%user_id_pattern%"] + } + } + } + }, + "quota": { + "type": "object", + "required": [ + "state" + ], + "properties": { + "state": { + "type": "string", + "enum": ["normal"] + } + } + }, + "root": { + "type": "object", + "required": [ + "id", + "webDavUrl" + ], + "properties": { + "state": { + "type": "string", + "enum": ["normal"] + }, + "webDavUrl": { + "type": "string", + "pattern": "^%base_url%/dav/spaces/%space_id_pattern%$" + } + } + }, + "webUrl": { + "type": "string", + "pattern": "^%base_url%/f/%space_id_pattern%$" + } + } + } + } + } + """ Examples: | userRole | | Space Admin | @@ -126,9 +518,60 @@ Feature: get users And user "Brian" has been added to group "coffee-lover" When the user "Alice" gets user "Brian" along with his group 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 | accountEnabled | memberOf | - | Brian Murphy | %uuid_v4% | brian@example.org | Brian | true | tea-lover, coffee-lover | + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "id", + "mail", + "onPremisesSamAccountName" + ], + "properties": { + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["brian@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Brian"] + }, + "memberOf": { + "type": "array", + "items": [ + { + "type": "object", + "required": [ + "displayName" + ], + "properties": { + "displayName": { + "type": "string", + "enum": ["tea-lover"] + } + } + }, + { + "type": "object", + "required": [ + "displayName" + ], + "properties": { + "displayName": { + "type": "string", + "enum": ["coffee-lover"] + } + } + } + ] + } + } + } + """ @issue-5125 Scenario Outline: non-admin user tries to get the group information of a user @@ -138,7 +581,27 @@ Feature: get users And user "Brian" has been added to group "coffee-lover" When the user "Alice" gets user "Brian" along with his group information using Graph API Then the HTTP status code should be "401" - And the last response should be an unauthorized response + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "type": "string", + "enum": ["Unauthorized"] + } + } + } + } + """ Examples: | userRole | role | | Space Admin | Space Admin | @@ -166,22 +629,127 @@ Feature: get users And user "Brian" has been added to group "coffee-lover" When the user "Alice" gets all users of the group "tea-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 | + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "value" + ], + "properties": { + "value": { + "type": "array", + "items": [ + { + "type": "object", + "required": [ + "id", + "mail", + "onPremisesSamAccountName", + "accountEnabled" + ], + "properties": { + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["alice@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Alice"] + }, + "accountEnabled": { + "type": "boolean", + "enum": [true] + } + } + }, + { + "type": "object", + "required": [ + "id", + "mail", + "onPremisesSamAccountName", + "accountEnabled" + ], + "properties": { + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["brian@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Brian"] + }, + "accountEnabled": { + "type": "boolean", + "enum": [true] + } + } + } + ], + "additionalItems": false + } + } + } + """ + And the JSON data of the response should not contain the user "Carol King" in the item 'value' When the user "Alice" gets all users of two groups "tea-lover,coffee-lover" using the Graph API Then the HTTP status code should be "200" - And the API response should contain following user with the information: - | displayName | id | mail | onPremisesSamAccountName | accountEnabled | - | Brian Murphy | %uuid_v4% | brian@example.org | Brian | true | - But the API response should not contain following users with the information: - | displayName | id | mail | onPremisesSamAccountName | accountEnabled | - | Alice Hansen | %uuid_v4% | alice@example.org | Alice | true | - | Carol King | %uuid_v4% | carol@example.org | Carol | true | + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "value" + ], + "properties": { + "value": { + "type": "array", + "items": [ + { + "type": "object", + "required": [ + "id", + "mail", + "onPremisesSamAccountName", + "accountEnabled" + ], + "properties": { + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["brian@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Brian"] + }, + "accountEnabled": { + "type": "boolean", + "enum": [true] + } + } + } + ], + "additionalItems": false + } + } + } + """ + And the JSON data of the response should not contain the user "Carol King" in the item 'value' + And the JSON data of the response should not contain the user "Alice Hansen" in the item 'value' + @skipOnStable2.0 Scenario: admin user gets all users of certain groups @@ -195,13 +763,67 @@ Feature: get users 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 | + And the JSON data of the response should contain the user "Alice Hansen" in the item 'value', the user-details should match + """ + { + "type": "object", + "required": [ + "id", + "mail", + "onPremisesSamAccountName", + "accountEnabled" + ], + "properties": { + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["alice@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Alice"] + }, + "accountEnabled": { + "type": "boolean", + "enum": [true] + } + } + } + """ + And the JSON data of the response should contain the user "Brian Murphy" in the item 'value', the user-details should match + """ + { + "type": "object", + "required": [ + "id", + "mail", + "onPremisesSamAccountName", + "accountEnabled" + ], + "properties": { + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["brian@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Brian"] + }, + "accountEnabled": { + "type": "boolean", + "enum": [true] + } + } + } + """ + But the JSON data of the response should not contain the user "Carol King" in the item 'value' @skipOnStable2.0 Scenario Outline: non admin user tries to get users of certain groups @@ -211,7 +833,27 @@ Feature: get users And user "Alice" has been added to group "tea-lover" When the user "Brian" gets all users of the group "tea-lover" using the Graph API Then the HTTP status code should be "401" - And the last response should be an unauthorized response + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "type": "string", + "enum": ["Unauthorized"] + } + } + } + } + """ Examples: | role | | Space Admin | @@ -228,28 +870,127 @@ Feature: get users And user "Brian" has been added to group "tea-lover" When the user "Alice" gets all users with role "Space Admin" 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 | - | Brian Murphy | %uuid_v4% | brian@example.org | Brian | true | - | Carol King | %uuid_v4% | carol@example.org | Carol | true | - But the API response should not contain following user with the information: - | displayName | id | mail | onPremisesSamAccountName | - | Alice Hansen | %uuid_v4% | alice@example.org | Alice | + And the JSON data of the response should contain the user "Brian Murphy" in the item 'value', the user-details should match + """ + { + "type": "object", + "required": [ + "id", + "mail", + "onPremisesSamAccountName", + "accountEnabled" + ], + "properties": { + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["brian@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Brian"] + }, + "accountEnabled": { + "type": "boolean", + "enum": [true] + } + } + } + """ + And the JSON data of the response should contain the user "Carol King" in the item 'value', the user-details should match + """ + { + "type": "object", + "required": [ + "id", + "mail", + "onPremisesSamAccountName", + "accountEnabled" + ], + "properties": { + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["carol@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Carol"] + }, + "accountEnabled": { + "type": "boolean", + "enum": [true] + } + } + } + """ + But the JSON data of the response should not contain the user "Alice Hansen" in the item 'value' When the user "Alice" gets all users with role "Space Admin" and member of the group "tea-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 | - | 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 | true | + And the JSON data of the response should contain the user "Brian Murphy" in the item 'value', the user-details should match + """ + { + "type": "object", + "required": [ + "id", + "mail", + "onPremisesSamAccountName", + "accountEnabled" + ], + "properties": { + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["brian@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Brian"] + }, + "accountEnabled": { + "type": "boolean", + "enum": [true] + } + } + } + """ + But the JSON data of the response should not contain the user "Carol King" in the item 'value' @skipOnStable2.0 Scenario Outline: non-admin user tries to get users with a certain role Given the administrator has given "Alice" the role "" using the settings api When the user "Alice" gets all users with role "" using the Graph API Then the HTTP status code should be "401" - And the last response should be an unauthorized response + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "type": "string", + "enum": ["Unauthorized"] + } + } + } + } + """ Examples: | userRole | role | | Space Admin | Space Admin | diff --git a/tests/acceptance/features/apiGraph/getUserOwnInformation.feature b/tests/acceptance/features/apiGraph/getUserOwnInformation.feature index bafeb3bc0d..9ae09e4bbf 100644 --- a/tests/acceptance/features/apiGraph/getUserOwnInformation.feature +++ b/tests/acceptance/features/apiGraph/getUserOwnInformation.feature @@ -11,9 +11,31 @@ Feature: get user's own information 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 | + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "id", + "mail", + "onPremisesSamAccountName" + ], + "properties": { + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["alice@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Alice"] + } + } + } + """ Scenario: user gets his/her own information with group involvement @@ -23,6 +45,57 @@ Feature: get user's own information 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 | + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "id", + "mail", + "onPremisesSamAccountName" + ], + "properties": { + "id" : { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "enum": ["alice@example.org"] + }, + "onPremisesSamAccountName": { + "type": "string", + "enum": ["Alice"] + }, + "memberOf": { + "type": "array", + "items": [ + { + "type": "object", + "required": [ + "displayName" + ], + "properties": { + "displayName": { + "type": "string", + "enum": ["tea-lover"] + } + } + }, + { + "type": "object", + "required": [ + "displayName" + ], + "properties": { + "displayName": { + "type": "string", + "enum": ["coffee-lover"] + } + } + } + ] + } + } + } + """ diff --git a/tests/acceptance/features/apiGraph/removeUserFromGroup.feature b/tests/acceptance/features/apiGraph/removeUserFromGroup.feature index d6324b92f7..a1ed037f95 100644 --- a/tests/acceptance/features/apiGraph/removeUserFromGroup.feature +++ b/tests/acceptance/features/apiGraph/removeUserFromGroup.feature @@ -165,7 +165,27 @@ Feature: remove a user from a group And user "Brian" has been added to group "grp1" When user "Alice" tries to remove user "Brian" from group "grp1" using the Graph API Then the HTTP status code should be "403" - And the last response should be an unauthorized response + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "type": "string", + "enum": ["Unauthorized"] + } + } + } + } + """ And user "Brian" should belong to group "grp1" Examples: | role | diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index a47f807737..9c2ad3dc54 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -3143,6 +3143,14 @@ class FeatureContext extends BehatVariablesContext { ], "parameter" => [] ], + [ + "code" => "%user_id_pattern%", + "function" => [ + __NAMESPACE__ . '\TestHelpers\GraphHelper', + "getUUIDv4Regex" + ], + "parameter" => [] + ], [ "code" => "%user_id%", "function" => [ diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index efe666e713..c902742616 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -10,8 +10,10 @@ declare(strict_types=1); use Behat\Behat\Context\Context; use Behat\Behat\Hook\Scope\BeforeScenarioScope; +use Behat\Gherkin\Node\PyStringNode; use Behat\Gherkin\Node\TableNode; use GuzzleHttp\Exception\GuzzleException; +use Helmich\JsonAssert\JsonAssertions; use Psr\Http\Message\ResponseInterface; use TestHelpers\GraphHelper; use TestHelpers\WebDavHelper; @@ -198,28 +200,19 @@ class GraphContext implements Context { } /** - * @Then /^the user "([^"]*)" should have information with these key and value pairs:$/ + * @Then /^the user information of "([^"]*)" should match this JSON schema$/ * * @param string $user - * @param TableNode $table + * @param PyStringNode $schemaString * * @return void * @throws Exception * @throws GuzzleException * @throws JsonException */ - public function theUserShouldHaveInformationWithTheseKeyAndValuePairs(string $user, TableNode $table): void { - $rows = $table->getHash(); + public function theUserInformationShouldMatchTheJSON(string $user, PyStringNode $schemaString): void { $this->adminHasRetrievedUserUsingTheGraphApi($user); - foreach ($rows as $row) { - $key = $row['key']; - $expectedValue = $row['value']; - $responseValue = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse())[$key]; - Assert::assertEquals( - $expectedValue, - $responseValue - ); - } + $this->featureContext->theDataOfTheResponseShouldMatch($schemaString); } /** @@ -1187,62 +1180,6 @@ class GraphContext implements Context { $this->featureContext->setResponse($this->listSingleOrAllGroupsAlongWithAllMemberInformation($user, $group)); } - /** - * @Then the group :group should have the following member information - * - * @param string $group - * @param TableNode $table - * - * @return void - * @throws GuzzleException - */ - public function theGroupShouldHaveTheFollowingMemberInformation(string $group, TableNode $table): void { - $response = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse()); - $rows = $table->getHash(); - $currentMemberIndex = 0; - if (isset($response['value'])) { - $response = $response['value']; - $groupFoundInResponse = false; - foreach ($response as $value) { - if ($value['displayName'] === $group) { - $groupFoundInResponse = true; - foreach ($rows as $row) { - $this->checkUserInformation($row, $value['members'][$currentMemberIndex]); - $currentMemberIndex++; - } - break; - } - } - if (!$groupFoundInResponse) { - throw new Error( - 'Group ' . $group . " could not be found in the response." - ); - } - } else { - foreach ($rows as $row) { - $this->checkUserInformation($row, $response['members'][$currentMemberIndex]); - $currentMemberIndex++; - } - } - } - - /** - * @Then the last response should be an unauthorized response - * - * @return void - */ - public function theLastResponseShouldBeUnauthorizedReponse(): void { - $response = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse()); - $errorText = $response['error']['message']; - - Assert::assertEquals( - 'Unauthorized', - $errorText, - __METHOD__ - . "\nExpected unauthorized message but got '" . $errorText . "'" - ); - } - /** * @When user :user deletes group :group using the Graph API * @When the administrator deletes group :group using the Graph API @@ -1443,69 +1380,6 @@ class GraphContext implements Context { $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::assertTrue(GraphHelper::isUUIDv4($actualValue['id']), __METHOD__ . ' Expected user_id to have UUIDv4 pattern but found: ' . $actualValue['id']); - break; - case "accountEnabled": - if ($expectedValue[$keyName] === 'true') { - Assert::assertTrue($actualValue[$keyName], ' Expected ' . $keyName . ' is not true '); - } else { - Assert::assertFalse($actualValue[$keyName], ' Expected ' . $keyName . ' is not false '); - } - break; - default: - Assert::assertEquals( - $expectedValue[$keyName], - $actualValue[$keyName], - __METHOD__ . - ' Expected ' . $keyName . ' to have value ' . $expectedValue[$keyName] - . ' but got ' . $actualValue[$keyName] - ); - break; - } - } - } - /** * @When user :byUser tries to get information of user :user using Graph API * @When user :byUser gets information of user :user using Graph API @@ -1548,36 +1422,6 @@ class GraphContext implements Context { $this->featureContext->setResponse($response); } - /** - * @Then /^the API response should (not|)\s?contain following (user|users) with the information:$/ - * - * @param string $shouldOrNot (not|) - * @param TableNode $table - * - * @throws Exception - * @return void - */ - public function theApiResponseShouldContainAllUserWithFollowingInformation(string $shouldOrNot, 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 ($shouldOrNot === 'not') { - Assert::assertFalse($found, $expectedValue["displayName"] . ' has been found in the response, but should not be.'); - } else { - Assert::assertTrue($found, $expectedValue["displayName"] . ' could not be found in the response.'); - } - } - } - /** * @param string $byUser * @param string|null $user @@ -1663,71 +1507,6 @@ class GraphContext implements Context { $this->featureContext->setResponse($response); } - /** - * @param array $driveInformation - * - * @return string - */ - public static function getSpaceIdFromActualDriveinformation(array $driveInformation): string { - return $driveInformation['id']; - } - - /** - * check if single drive information is correct - * - * @param array $expectedDriveInformation - * @param array $actualDriveInformation - * - * @return void - */ - public function checkUserDriveInformation(array $expectedDriveInformation, array $actualDriveInformation):void { - foreach (array_keys($expectedDriveInformation) as $keyName) { - $actualKeyValue = GraphHelper::separateAndGetValueForKey($keyName, $actualDriveInformation); - switch ($expectedDriveInformation[$keyName]) { - case '%user_id%': - Assert::assertTrue(GraphHelper::isUUIDv4($actualKeyValue), __METHOD__ . ' Expected user_id to have UUIDv4 pattern but found: ' . $actualKeyValue); - break; - case '%space_id%': - Assert::assertTrue(GraphHelper::isSpaceId($actualKeyValue), __METHOD__ . ' Expected space_id to have a UUIDv4:UUIDv4 pattern but found: ' . $actualKeyValue); - break; - default: - $expectedDriveInformation[$keyName] = $this->featureContext->substituteInLineCodes( - $expectedDriveInformation[$keyName], - $this->featureContext->getCurrentUser(), - [], - [ - [ - // the actual space_id is substituted from the actual drive information rather than making an API request and substituting - "code" => "%space_id%", - "function" => - [$this, "getSpaceIdFromActualDriveinformation"], - "parameter" => [$actualDriveInformation] - ], - ] - ); - Assert::assertEquals($expectedDriveInformation[$keyName], $actualKeyValue); - } - } - } - - /** - * @param TableNode $table - * - * @Then the user retrieve API response should contain the following drive information: - * - * @return void - */ - public function theResponseShouldContainTheFollowingDriveInformation(TableNode $table): void { - $expectedDriveInformation = $table->getRowsHash(); - // array of user drive information (Personal Drive Information Only) - $actualDriveInformation = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse()); - if (\is_array($actualDriveInformation) && \array_key_exists('drive', $actualDriveInformation)) { - $this->checkUserDriveInformation($expectedDriveInformation, $actualDriveInformation['drive']); - } else { - throw new Error('Response is not an array or the array does not consist key "drive"'); - } - } - /** * add multiple users in a group at once * @@ -2228,6 +2007,45 @@ class GraphContext implements Context { ); } + /** + * @Then /^the JSON data of the response should (not )?contain the user "([^"]*)" in the item 'value'(?:, the user-details should match)?$/ + * @Then /^the JSON data of the response should (not )?contain the group "([^"]*)" in the item 'value'(?:, the group-details should match)?$/ + * + * @param string $shouldOrNot (not| ) + * @param string $userOrGroup + * @param PyStringNode|null $schemaString + * + * @return void + * @throws Exception + */ + public function theJsonDataResponseShouldOrNotContainUserOrGroupAndMatch( + string $shouldOrNot, + string $userOrGroup, + ?PyStringNode $schemaString = null + ): void { + $responseBody = $this->featureContext->getJsonDecodedResponseBodyContent()->value; + $userOrGroupFound = false; + foreach ($responseBody as $value) { + if (isset($value->displayName) && $value->displayName === $userOrGroup) { + $responseBody = $value; + $userOrGroupFound = true; + break; + } + } + $shouldContain = \trim($shouldOrNot) !== 'not'; + if (!$shouldContain && !$userOrGroupFound) { + return; + } + Assert::assertFalse( + !$shouldContain && $userOrGroupFound, + 'Response contains user or group "' . $userOrGroup . '" but should not have.' + ); + JsonAssertions::assertJsonDocumentMatchesSchema( + $responseBody, + $this->featureContext->getJSONSchema($schemaString) + ); + } + /** * @Given /^the administrator "([^"]*)" has added the following users to a group "([^"]*)" at once using the Graph API$/ *