From 5a958dfb923cef4a1f3f918532f4c9c0fcab2c12 Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Wed, 14 Aug 2024 16:38:42 +0200 Subject: [PATCH 1/2] get federated users test --- docs/ocis/development/testing.md | 3 + tests/TestHelpers/GraphHelper.php | 50 +++ ...ected-failures-localAPI-on-OCIS-storage.md | 6 + .../apiOcm/searchFederationUsers.feature | 413 +++++++++++++++++- .../features/bootstrap/FeatureContext.php | 8 + .../features/bootstrap/GraphContext.php | 42 ++ 6 files changed, 516 insertions(+), 6 deletions(-) diff --git a/docs/ocis/development/testing.md b/docs/ocis/development/testing.md index 7955b9b2d..fe14492bd 100644 --- a/docs/ocis/development/testing.md +++ b/docs/ocis/development/testing.md @@ -559,6 +559,9 @@ PROXY_ENABLE_BASIC_AUTH=true \ OCIS_ENABLE_OCM=true \ OCM_OCM_PROVIDER_AUTHORIZER_PROVIDERS_FILE="${workspaceFolder}/tests/config/drone/providers.json" \ OCIS_ADD_RUN_SERVICES="ocm" \ +OCM_OCM_INVITE_MANAGER_INSECURE=true \ +OCM_OCM_SHARE_PROVIDER_INSECURE=true \ +OCM_OCM_STORAGE_PROVIDER_INSECURE=true \ ocis/bin/ocis server ``` diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index 9cb17d8f4..07998e209 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -2346,4 +2346,54 @@ class GraphHelper { $password ); } + + /** + * @param string $baseUrl + * @param string $xRequestId + * @param string $user + * @param string $password + * + * @return ResponseInterface + * @throws GuzzleException + */ + public static function getFederatedUsers( + string $baseUrl, + string $xRequestId, + string $user, + string $password + ): ResponseInterface { + $url = self::getFullUrl($baseUrl, "users?\$filter=userType eq 'Federated'"); + return HttpRequestHelper::get( + $url, + $xRequestId, + $user, + $password, + self::getRequestHeaders() + ); + } + + /** + * @param string $baseUrl + * @param string $xRequestId + * @param string $adminUser + * @param string $adminPassword + * + * @return ResponseInterface + * @throws GuzzleException + */ + public static function getAllUsers( + string $baseUrl, + string $xRequestId, + string $adminUser, + string $adminPassword, + ): ResponseInterface { + $url = self::getFullUrl($baseUrl, "users?\$filter=userType eq 'Federated' or userType eq 'Member'"); + return HttpRequestHelper::get( + $url, + $xRequestId, + $adminUser, + $adminPassword, + self::getRequestHeaders() + ); + } } diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index 45f6417e0..bf292758f 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -293,5 +293,11 @@ The expected failures in this file are from features in the owncloud/ocis repo. ### [OCM. user cannot see invite description and inviteUser email](https://github.com/owncloud/ocis/issues/9591) - [apiOcm/createInvitation.feature:63](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiOcm/createInvitation.feature#L63) + +### [OCM. admin cannot get federated users if he hasn't connection with them ](https://github.com/owncloud/ocis/issues/9829) + +tests/acceptance/features/apiOcm/searchFederationUsers.feature +- [apiOcm/searchFederationUsers.feature:434](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiOcm/searchFederationUsers.feature#L434) +- [apiOcm/searchFederationUsers.feature:611](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiOcm/searchFederationUsers.feature#L611) - 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/apiOcm/searchFederationUsers.feature b/tests/acceptance/features/apiOcm/searchFederationUsers.feature index fc46eb37c..bc6f6d7ba 100755 --- a/tests/acceptance/features/apiOcm/searchFederationUsers.feature +++ b/tests/acceptance/features/apiOcm/searchFederationUsers.feature @@ -36,7 +36,9 @@ Feature: search federation users "type": "object", "required": [ "displayName", - "id" + "id", + "userType", + "identities" ], "properties": { "displayName": { @@ -45,6 +47,31 @@ Feature: search federation users "id": { "type": "string", "pattern": "^%user_id_pattern%$" + }, + "userType": { + "type": "string", + "const": "Federated" + }, + "identities": { + "type": "array", + "minItems": 1, + "maxItems": 1, + "items": { + "type": "object", + "required": [ + "issuer", + "issuerAssignedId" + ], + "properties": { + "issuer": { + "const": "ocis-server" + }, + "issuerAssignedId": { + "type": "string", + "pattern": "^%identities_issuer_id_pattern%$" + } + } + } } } } @@ -71,7 +98,9 @@ Feature: search federation users "type": "object", "required": [ "displayName", - "id" + "id", + "userType", + "identities" ], "properties": { "displayName": { @@ -80,6 +109,31 @@ Feature: search federation users "id": { "type": "string", "pattern": "^%user_id_pattern%$" + }, + "userType": { + "type": "string", + "const": "Federated" + }, + "identities": { + "type": "array", + "minItems": 1, + "maxItems": 1, + "items": { + "type": "object", + "required": [ + "issuer", + "issuerAssignedId" + ], + "properties": { + "issuer": { + "const": "https://federation-ocis-server:10200" + }, + "issuerAssignedId": { + "type": "string", + "pattern": "^%identities_issuer_id_pattern%$" + } + } + } } } } @@ -112,7 +166,9 @@ Feature: search federation users "type": "object", "required": [ "displayName", - "id" + "id", + "userType", + "identities" ], "properties": { "displayName": { @@ -121,6 +177,31 @@ Feature: search federation users "id": { "type": "string", "pattern": "^%user_id_pattern%$" + }, + "userType": { + "type": "string", + "const": "Federated" + }, + "identities": { + "type": "array", + "minItems": 1, + "maxItems": 1, + "items": { + "type": "object", + "required": [ + "issuer", + "issuerAssignedId" + ], + "properties": { + "issuer": { + "const": "ocis-server" + }, + "issuerAssignedId": { + "type": "string", + "pattern": "^%identities_issuer_id_pattern%$" + } + } + } } } } @@ -147,7 +228,9 @@ Feature: search federation users "type": "object", "required": [ "displayName", - "id" + "id", + "userType", + "identities" ], "properties": { "displayName": { @@ -156,6 +239,31 @@ Feature: search federation users "id": { "type": "string", "pattern": "^%user_id_pattern%$" + }, + "userType": { + "type": "string", + "const": "Federated" + }, + "identities": { + "type": "array", + "minItems": 1, + "maxItems": 1, + "items": { + "type": "object", + "required": [ + "issuer", + "issuerAssignedId" + ], + "properties": { + "issuer": { + "const": "https://federation-ocis-server:10200" + }, + "issuerAssignedId": { + "type": "string", + "pattern": "^%identities_issuer_id_pattern%$" + } + } + } } } } @@ -165,7 +273,7 @@ Feature: search federation users """ - Scenario: sers search for federation users without federated connection + Scenario: users search for federation users without federated connection Given using server "LOCAL" And "Alice" has created the federation share invitation And using server "REMOTE" @@ -207,7 +315,6 @@ Feature: search federation users } } """ - And using server "REMOTE" Scenario: users search all federation users @@ -324,5 +431,299 @@ Feature: search federation users } """ + @issue-9829 + Scenario: admin gets federated users + Given using server "LOCAL" + And "Alice" has created the federation share invitation + And using server "REMOTE" + And "Brian" has accepted invitation + When the administrator gets federated users using the Graph API + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "value" + ], + "properties": { + "value": { + "type": "array", + "minItems": 1, + "maxItems": 1, + "items": { + "type": "object", + "required": [ + "displayName", + "id", + "mail", + "userType", + "identities" + ], + "properties": { + "displayName": { + "const": "Alice Hansen" + }, + "id": { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "const": "alice@example.org" + }, + "userType": { + "type": "string", + "const": "Federated" + }, + "identities": { + "type": "array", + "minItems": 1, + "maxItems": 1, + "items": { + "type": "object", + "required": [ + "issuer", + "issuerAssignedId" + ], + "properties": { + "issuer": { + "const": "ocis-server" + }, + "issuerAssignedId": { + "type": "string", + "pattern": "^%identities_issuer_id_pattern%$" + } + } + } + } + } + } + } + } + } + """ + And using server "LOCAL" + When the administrator gets federated users using the Graph API + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "value" + ], + "properties": { + "value": { + "type": "array", + "minItems": 1, + "maxItems": 1, + "items": { + "type": "object", + "required": [ + "displayName", + "id", + "mail", + "userType", + "identities" + ], + "properties": { + "displayName": { + "const": "Brian Murphy" + }, + "id": { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "const": "brian@example.org" + }, + "userType": { + "type": "string", + "const": "Federated" + }, + "identities": { + "type": "array", + "minItems": 1, + "maxItems": 1, + "items": { + "type": "object", + "required": [ + "issuer", + "issuerAssignedId" + ], + "properties": { + "issuer": { + "const": "https://federation-ocis-server:10200" + }, + "issuerAssignedId": { + "type": "string", + "pattern": "^%identities_issuer_id_pattern%$" + } + } + } + } + } + } + } + } + } + """ + + + Scenario: user without admin permissions cannot get federated users + Given using server "LOCAL" + And "Alice" has created the federation share invitation + And using server "REMOTE" + And "Brian" has accepted invitation + And using server "LOCAL" + When user "Carol" tries to get federated users using the Graph API + Then the HTTP status code should be "403" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "error" + ], + "properties": { + "error": { + "type": "object", + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "string", + "const": "accessDenied" + }, + "message": { + "type": "string", + "const": "search term too short" + } + } + } + } + } + """ + + @issue-9829 + Scenario: admin gets federated and member users + Given using server "LOCAL" + And "Alice" has created the federation share invitation + And using server "REMOTE" + And "Brian" has accepted invitation + And using server "LOCAL" + When the administrator gets federated and member users using the Graph API + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "value" + ], + "properties": { + "value": { + "type": "array", + "maxItems": 2, + "minItems": 2, + "uniqueItems": true, + "items": { + "oneOf": [ + { + "type": "object", + "required": [ + "accountEnabled", + "displayName", + "id", + "mail", + "onPremisesSamAccountName", + "surname", + "userType" + ], + "properties": { + "accountEnabled": { + "const": true + }, + "displayName": { + "const": "Carol King" + }, + "id": { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "const": "carol@example.org" + }, + "onPremisesSamAccountName": { + "const": "Carol" + }, + "surname": { + "const": "Carol" + }, + "userType": { + "type": "string", + "const": "Member" + } + } + }, + { + "type": "object", + "required": [ + "displayName", + "id", + "mail", + "userType", + "identities" + ], + "properties": { + "displayName": { + "const": "Brian Murphy" + }, + "id": { + "type": "string", + "pattern": "^%user_id_pattern%$" + }, + "mail": { + "type": "string", + "const": "brian@example.org" + }, + "userType": { + "type": "string", + "const": "Federated" + }, + "identities": { + "type": "array", + "minItems": 1, + "maxItems": 1, + "items": { + "type": "object", + "required": [ + "issuer", + "issuerAssignedId" + ], + "properties": { + "issuer": { + "const": "https://federation-ocis-server:10200" + }, + "issuerAssignedId": { + "type": "string", + "pattern": "^%identities_issuer_id_pattern%$" + } + } + } + } + } + } + ] + } + } + } + } + """ # TODO try to find federation users after deleting federated conection diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index e1fcbb8c1..8c89667cb 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -2309,6 +2309,14 @@ class FeatureContext extends BehatVariablesContext { "getUUIDv4Regex" ], "parameter" => [] + ], + [ + "code" => "%identities_issuer_id_pattern%", + "function" => [ + __NAMESPACE__ . '\TestHelpers\GraphHelper', + "getUUIDv4Regex" + ], + "parameter" => [] ] ]; if ($user !== null) { diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index 113c6857b..078f347ab 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -2838,4 +2838,46 @@ class GraphContext implements Context { ); $this->featureContext->setResponse($response); } + + /** + * @When the administrator gets federated users using the Graph API + * @When user :user tries to get federated users using the Graph API + * + * @param ?string $user + * + * @return void + */ + public function theUserGetsFederatedUsersUsingTheGraphApi(?string $user = null): void { + $credentials = $this->getAdminOrUserCredentials($user); + + $response = GraphHelper::getFederatedUsers( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $credentials['username'], + $credentials['password'] + ); + + $this->featureContext->setResponse($response); + } + + /** + * @When the administrator gets federated and member users using the Graph API + * @When user :user tries to get federated and member users using the Graph API + * + * @param ?string $user + * + * @return void + */ + public function theUserGetsAllUsersUsingTheGraphApi(?string $user = null): void { + $credentials = $this->getAdminOrUserCredentials($user); + + $response = GraphHelper::getAllUsers( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $credentials['username'], + $credentials['password'] + ); + + $this->featureContext->setResponse($response); + } } From 60eaef5f75c204b738a28c4cd31c2c84501ca9a4 Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Mon, 19 Aug 2024 11:11:17 +0200 Subject: [PATCH 2/2] fix --- ...ected-failures-localAPI-on-OCIS-storage.md | 4 ++-- .../features/apiOcm/createInvitation.feature | 4 ---- .../apiOcm/searchFederationUsers.feature | 20 ++----------------- .../acceptance/features/apiOcm/share.feature | 7 ++----- .../features/bootstrap/GraphContext.php | 4 ++-- 5 files changed, 8 insertions(+), 31 deletions(-) diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index bf292758f..d4e1cccba 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -297,7 +297,7 @@ The expected failures in this file are from features in the owncloud/ocis repo. ### [OCM. admin cannot get federated users if he hasn't connection with them ](https://github.com/owncloud/ocis/issues/9829) tests/acceptance/features/apiOcm/searchFederationUsers.feature -- [apiOcm/searchFederationUsers.feature:434](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiOcm/searchFederationUsers.feature#L434) -- [apiOcm/searchFederationUsers.feature:611](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiOcm/searchFederationUsers.feature#L611) +- [apiOcm/searchFederationUsers.feature:429](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiOcm/searchFederationUsers.feature#L429) +- [apiOcm/searchFederationUsers.feature:601](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiOcm/searchFederationUsers.feature#L601) - 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/apiOcm/createInvitation.feature b/tests/acceptance/features/apiOcm/createInvitation.feature index f2689d570..14ffb0181 100755 --- a/tests/acceptance/features/apiOcm/createInvitation.feature +++ b/tests/acceptance/features/apiOcm/createInvitation.feature @@ -84,11 +84,9 @@ Feature: create invitation "pattern": "^%fed_invitation_token_pattern%$" }, "description": { - "type": "string", "const": "a share invitation from Alice" }, "recipient": { - "type": "string", "const": "brian@example.com" } } @@ -117,11 +115,9 @@ Feature: create invitation "pattern": "^%fed_invitation_token_pattern%$" }, "description": { - "type": "string", "const": "a share invitation from Alice" }, "recipient": { - "type": "string", "const": "brian@example.com" } } diff --git a/tests/acceptance/features/apiOcm/searchFederationUsers.feature b/tests/acceptance/features/apiOcm/searchFederationUsers.feature index bc6f6d7ba..9eceb5d86 100755 --- a/tests/acceptance/features/apiOcm/searchFederationUsers.feature +++ b/tests/acceptance/features/apiOcm/searchFederationUsers.feature @@ -382,15 +382,12 @@ Feature: search federation users ], "properties": { "display_name": { - "type": "string", "const": "Alice Hansen" }, "idp": { - "type": "string", "const": "https://ocis-server:9200" }, "mail": { - "type": "string", "pattern": "alice@example.org" }, "user_id": { @@ -409,15 +406,12 @@ Feature: search federation users ], "properties": { "display_name": { - "type": "string", "const": "Carol King" }, "idp": { - "type": "string", "const": "https://ocis-server:9200" }, "mail": { - "type": "string", "pattern": "carol@example.org" }, "user_id": { @@ -469,11 +463,9 @@ Feature: search federation users "pattern": "^%user_id_pattern%$" }, "mail": { - "type": "string", "const": "alice@example.org" }, "userType": { - "type": "string", "const": "Federated" }, "identities": { @@ -536,11 +528,9 @@ Feature: search federation users "pattern": "^%user_id_pattern%$" }, "mail": { - "type": "string", "const": "brian@example.org" }, "userType": { - "type": "string", "const": "Federated" }, "identities": { @@ -596,11 +586,9 @@ Feature: search federation users ], "properties": { "code": { - "type": "string", "const": "accessDenied" }, "message": { - "type": "string", "const": "search term too short" } } @@ -610,13 +598,13 @@ Feature: search federation users """ @issue-9829 - Scenario: admin gets federated and member users + Scenario: admin gets federated and local users Given using server "LOCAL" And "Alice" has created the federation share invitation And using server "REMOTE" And "Brian" has accepted invitation And using server "LOCAL" - When the administrator gets federated and member users using the Graph API + When the administrator gets federated and local users using the Graph API Then the HTTP status code should be "200" And the JSON data of the response should match """ @@ -656,7 +644,6 @@ Feature: search federation users "pattern": "^%user_id_pattern%$" }, "mail": { - "type": "string", "const": "carol@example.org" }, "onPremisesSamAccountName": { @@ -666,7 +653,6 @@ Feature: search federation users "const": "Carol" }, "userType": { - "type": "string", "const": "Member" } } @@ -689,11 +675,9 @@ Feature: search federation users "pattern": "^%user_id_pattern%$" }, "mail": { - "type": "string", "const": "brian@example.org" }, "userType": { - "type": "string", "const": "Federated" }, "identities": { diff --git a/tests/acceptance/features/apiOcm/share.feature b/tests/acceptance/features/apiOcm/share.feature index 028f133ff..b117fa632 100755 --- a/tests/acceptance/features/apiOcm/share.feature +++ b/tests/acceptance/features/apiOcm/share.feature @@ -126,12 +126,10 @@ Feature: an user shares resources usin ScienceMesh application ], "properties": { "@UI.Hidden":{ - "type": "boolean", - "enum": [false] + "const": "false" }, "@client.synchronize":{ - "type": "boolean", - "enum": [true] + "const": "true" }, "createdBy": { "type": "object", @@ -144,7 +142,6 @@ Feature: an user shares resources usin ScienceMesh application "required": ["displayName", "id"], "properties": { "displayName": { - "type": "string", "const": "Brian Murphy" }, "id": { diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index 078f347ab..2fbb15445 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -2861,8 +2861,8 @@ class GraphContext implements Context { } /** - * @When the administrator gets federated and member users using the Graph API - * @When user :user tries to get federated and member users using the Graph API + * @When the administrator gets federated and local users using the Graph API + * @When user :user tries to get federated and local users using the Graph API * * @param ?string $user *