From 451f288ae318eea8a2b76d3e0e9d909cb3f13215 Mon Sep 17 00:00:00 2001 From: amrita Date: Thu, 29 Aug 2024 12:29:39 +0545 Subject: [PATCH 1/2] add tests for fake office --- tests/acceptance/bootstrap/CliContext.php | 1 - .../bootstrap/CollaborationContext.php | 94 ++++++++++++ tests/acceptance/config/behat.yml | 2 + .../apiCollaboration/checkFileInfo.feature | 142 ++++++++++++++++++ 4 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 tests/acceptance/bootstrap/CollaborationContext.php create mode 100644 tests/acceptance/features/apiCollaboration/checkFileInfo.feature diff --git a/tests/acceptance/bootstrap/CliContext.php b/tests/acceptance/bootstrap/CliContext.php index 10dff4b1f9..155cdbfc4d 100644 --- a/tests/acceptance/bootstrap/CliContext.php +++ b/tests/acceptance/bootstrap/CliContext.php @@ -23,7 +23,6 @@ use Behat\Behat\Hook\Scope\BeforeScenarioScope; use Behat\Behat\Context\Context; use PHPUnit\Framework\Assert; -use Psr\Http\Message\ResponseInterface; use TestHelpers\CliHelper; use TestHelpers\OcisConfigHelper; diff --git a/tests/acceptance/bootstrap/CollaborationContext.php b/tests/acceptance/bootstrap/CollaborationContext.php new file mode 100644 index 0000000000..d14d3039e2 --- /dev/null +++ b/tests/acceptance/bootstrap/CollaborationContext.php @@ -0,0 +1,94 @@ + + * @copyright Copyright (c) 2024 Amrita Shrestha + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, + * as published by the Free Software Foundation; + * either version 3 of the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * + */ + +use Behat\Behat\Context\Context; +use Behat\Behat\Hook\Scope\BeforeScenarioScope; +use GuzzleHttp\Exception\GuzzleException; +use TestHelpers\HttpRequestHelper; + +require_once 'bootstrap.php'; +/** + * steps needed to re-configure oCIS server + */ +class CollaborationContext implements Context { + private FeatureContext $featureContext; + private SpacesContext $spacesContext; + + /** + * This will run before EVERY scenario. + * It will set the properties for this object. + * + * @BeforeScenario + * + * @param BeforeScenarioScope $scope + * + * @return void + */ + public function before(BeforeScenarioScope $scope): void { + // Get the environment + $environment = $scope->getEnvironment(); + // Get all the contexts you need in this context from here + $this->featureContext = $environment->getContext('FeatureContext'); + $this->spacesContext = $environment->getContext('SpacesContext'); + } + + /** + * @When user :user request information of file :file on space :space for :app + * + * @param $user + * @param $file + * @param $space + * @param $app + * + * @return void + * + * @throws GuzzleException + * @throws JsonException + */ + public function userRequestInformationOfFileOnSpaceFor($user, $file, $space, $app) : void { + $fileId = $this->spacesContext->getFileId($user, $space, $file); + $response = \json_decode( + HttpRequestHelper::post( + $this->featureContext->getBaseUrl() . "/app/open?app_name=$app&file_id=$fileId", + $this->featureContext->getStepLineRef(), + $this->featureContext->getActualUsername($user), + $this->featureContext->getPasswordForUser($user), + ['Content-Type' => 'application/json'] + )->getBody()->getContents() + ); + + $accessToken = $response->form_parameters->access_token; + + // Extract the WOPISrc from the app_url + $parsedUrl = parse_url($response->app_url); + parse_str($parsedUrl['query'], $queryParams); + $wopiSrc = $queryParams['WOPISrc']; + + $this->featureContext->setResponse( + HttpRequestHelper::get( + $wopiSrc . "?access_token=$accessToken", + $this->featureContext->getStepLineRef() + ) + ); + } + +} diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index 9e288e323d..3ff29e1b54 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -407,6 +407,8 @@ default: contexts: - FeatureContext: *common_feature_context_params - SharingNgContext: + - CollaborationContext: + cliCommands: paths: diff --git a/tests/acceptance/features/apiCollaboration/checkFileInfo.feature b/tests/acceptance/features/apiCollaboration/checkFileInfo.feature new file mode 100644 index 0000000000..0790bd83c0 --- /dev/null +++ b/tests/acceptance/features/apiCollaboration/checkFileInfo.feature @@ -0,0 +1,142 @@ +Feature: check file info on wopi + As a user + I want to request file information on wopi server + So that I can make sure that the response contains all the relevant values + + Background: + Given user "Alice" has been created with default attributes and without skeleton files + + + Scenario: check file info for fake office + Given user "Alice" has uploaded file with content "hello world" to "/textfile0.txt" + When user "Alice" request information of file "textfile0.txt" on space "Personal" for "FakeOffice" + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "BaseFileName", + "OwnerId", + "Size", + "UserId", + "Version", + "SupportsCobalt", + "SupportsContainers", + "SupportsDeleteFile", + "SupportsEcosystem", + "SupportsExtendedLockLength", + "SupportsFolders", + "SupportsGetLock", + "SupportsLocks", + "SupportsRename", + "SupportsUpdate", + "SupportsUserInfo", + "UserFriendlyName", + "ReadOnly", + "RestrictedWebViewOnly", + "UserCanAttend", + "UserCanNotWriteRelative", + "UserCanPresent", + "UserCanRename", + "UserCanWrite", + "AllowAdditionalMicrosoftServices", + "AllowExternalMarketplace", + "DisablePrint", + "DisableTranslation", + "BreadcrumbDocName" + ], + "properties": { + "BaseFileName": { + "const": "textfile0.txt" + }, + "OwnerId": { + "type": "string", + "pattern": "^[0-9a-fA-F]{32,}$" + }, + "Size": { + "const": 11 + }, + "UserId": { + "type": "string", + "pattern": "^[0-9a-fA-F]{32,}$" + }, + "Version": { + "type": "string", + "pattern": "^\\d{10,12}\\.\\d+$" + }, + "SupportsCobalt": { + "const": false + }, + "SupportsContainers": { + "const": false + }, + "SupportsDeleteFile": { + "const": true + }, + "SupportsEcosystem": { + "const": false + }, + "SupportsExtendedLockLength": { + "const": true + }, + "SupportsFolders": { + "const": false + }, + "SupportsGetLock": { + "const": true + }, + "SupportsLocks": { + "const": true + }, + "SupportsRename": { + "const": true + }, + "SupportsUpdate": { + "const": true + }, + "SupportsUserInfo": { + "const": false + }, + "UserFriendlyName": { + "const": "Alice Hansen" + }, + "ReadOnly": { + "const": false + }, + "RestrictedWebViewOnly": { + "const": false + }, + "UserCanAttend": { + "const": false + }, + "UserCanNotWriteRelative": { + "const": false + }, + "UserCanPresent": { + "const": false + }, + "UserCanRename": { + "const": true + }, + "UserCanWrite": { + "const": true + }, + "AllowAdditionalMicrosoftServices": { + "const": false + }, + "AllowExternalMarketplace": { + "const": false + }, + "DisablePrint": { + "const": false + }, + "DisableTranslation": { + "const": false + }, + "BreadcrumbDocName": { + "const": "textfile0.txt" + } + } + } + """ From e444070563b35ab22cdc4f6c702014523deb7a83 Mon Sep 17 00:00:00 2001 From: amrita Date: Fri, 30 Aug 2024 09:46:02 +0545 Subject: [PATCH 2/2] review addressed --- .../bootstrap/CollaborationContext.php | 14 ++++++-------- .../apiCollaboration/checkFileInfo.feature | 17 +++++++---------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/tests/acceptance/bootstrap/CollaborationContext.php b/tests/acceptance/bootstrap/CollaborationContext.php index d14d3039e2..8f7e30e6aa 100644 --- a/tests/acceptance/bootstrap/CollaborationContext.php +++ b/tests/acceptance/bootstrap/CollaborationContext.php @@ -25,7 +25,6 @@ use Behat\Behat\Hook\Scope\BeforeScenarioScope; use GuzzleHttp\Exception\GuzzleException; use TestHelpers\HttpRequestHelper; -require_once 'bootstrap.php'; /** * steps needed to re-configure oCIS server */ @@ -52,19 +51,19 @@ class CollaborationContext implements Context { } /** - * @When user :user request information of file :file on space :space for :app + * @When user :user checks the information of file :file of space :space using office :app * - * @param $user - * @param $file - * @param $space - * @param $app + * @param string $user + * @param string $file + * @param string $space + * @param string $app * * @return void * * @throws GuzzleException * @throws JsonException */ - public function userRequestInformationOfFileOnSpaceFor($user, $file, $space, $app) : void { + public function userChecksTheInformationOfFileOfSpaceUsingOffice(string $user, string $file, string $space, string $app): void { $fileId = $this->spacesContext->getFileId($user, $space, $file); $response = \json_decode( HttpRequestHelper::post( @@ -90,5 +89,4 @@ class CollaborationContext implements Context { ) ); } - } diff --git a/tests/acceptance/features/apiCollaboration/checkFileInfo.feature b/tests/acceptance/features/apiCollaboration/checkFileInfo.feature index 0790bd83c0..80da892d1c 100644 --- a/tests/acceptance/features/apiCollaboration/checkFileInfo.feature +++ b/tests/acceptance/features/apiCollaboration/checkFileInfo.feature @@ -1,15 +1,15 @@ -Feature: check file info on wopi +Feature: check file info with different wopi apps As a user I want to request file information on wopi server - So that I can make sure that the response contains all the relevant values + So that I can get all the information of a file Background: Given user "Alice" has been created with default attributes and without skeleton files - Scenario: check file info for fake office + Scenario: check file info with fake office Given user "Alice" has uploaded file with content "hello world" to "/textfile0.txt" - When user "Alice" request information of file "textfile0.txt" on space "Personal" for "FakeOffice" + When user "Alice" checks the information of file "textfile0.txt" of space "Personal" using office "FakeOffice" Then the HTTP status code should be "200" And the JSON data of the response should match """ @@ -51,19 +51,16 @@ Feature: check file info on wopi "const": "textfile0.txt" }, "OwnerId": { - "type": "string", - "pattern": "^[0-9a-fA-F]{32,}$" + "type": "string" }, "Size": { "const": 11 }, "UserId": { - "type": "string", - "pattern": "^[0-9a-fA-F]{32,}$" + "type": "string" }, "Version": { - "type": "string", - "pattern": "^\\d{10,12}\\.\\d+$" + "type": "string" }, "SupportsCobalt": { "const": false