mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-07 12:50:21 -06:00
Merge pull request #10055 from owncloud/add-bug-coverage-for-wopi
This commit is contained in:
67
tests/acceptance/TestHelpers/CollaborationHelper.php
Normal file
67
tests/acceptance/TestHelpers/CollaborationHelper.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* ownCloud
|
||||
*
|
||||
* @author Amrita Shrestha <amrita@jankaritech.com>
|
||||
* @copyright Copyright (c) 2024 Amrita Shrestha amrita@jankaritech.com
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace TestHelpers;
|
||||
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* A helper class for managing wopi requests
|
||||
*/
|
||||
class CollaborationHelper {
|
||||
|
||||
/**
|
||||
* @param string $fileId
|
||||
* @param string $app
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string|null $viewMode
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function sendPOSTRequestToAppOpen(
|
||||
string $fileId,
|
||||
string $app,
|
||||
string $username,
|
||||
string $password,
|
||||
string $baseUrl,
|
||||
string $xRequestId,
|
||||
?string $viewMode = null,
|
||||
): ResponseInterface {
|
||||
$url = $baseUrl . "/app/open?app_name=$app&file_id=$fileId";
|
||||
if ($viewMode) {
|
||||
$url .= "&view_mode=$viewMode";
|
||||
}
|
||||
|
||||
return HttpRequestHelper::post(
|
||||
$url,
|
||||
$xRequestId,
|
||||
$username,
|
||||
$password,
|
||||
['Content-Type' => 'application/json']
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,20 @@
|
||||
*
|
||||
* @author Prajwol Amatya <prajwol@jankaritech.com>
|
||||
* @copyright Copyright (c) 2023 Prajwol Amatya prajwol@jankaritech.com
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace TestHelpers;
|
||||
|
||||
@@ -4,6 +4,20 @@
|
||||
*
|
||||
* @author Kiran Parajuli <kiran@jankaritech.com>
|
||||
* @copyright Copyright (c) 2022 Kiran Parajuli kiran@jankaritech.com
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace TestHelpers;
|
||||
|
||||
@@ -4,6 +4,20 @@
|
||||
*
|
||||
* @author Viktor Scharf <scharf.vi@gmail.com>
|
||||
* @copyright Copyright (c) 2024 Viktor Scharf <scharf.vi@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace TestHelpers;
|
||||
@@ -23,7 +37,7 @@ class OcmHelper {
|
||||
'Content-Type' => 'application/json',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $path
|
||||
|
||||
@@ -24,6 +24,8 @@ use Behat\Behat\Context\Context;
|
||||
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use TestHelpers\HttpRequestHelper;
|
||||
use TestHelpers\WebDavHelper;
|
||||
use TestHelpers\CollaborationHelper;
|
||||
|
||||
/**
|
||||
* steps needed to re-configure oCIS server
|
||||
@@ -66,19 +68,15 @@ class CollaborationContext implements Context {
|
||||
*/
|
||||
public function userChecksTheInformationOfFileOfSpaceUsingOffice(string $user, string $file, string $space, string $app, string $viewMode = null): void {
|
||||
$fileId = $this->spacesContext->getFileId($user, $space, $file);
|
||||
$url = $this->featureContext->getBaseUrl() . "/app/open?app_name=$app&file_id=$fileId";
|
||||
|
||||
if ($viewMode) {
|
||||
$url .= "&view_mode=$viewMode";
|
||||
}
|
||||
|
||||
$response = \json_decode(
|
||||
HttpRequestHelper::post(
|
||||
$url,
|
||||
$this->featureContext->getStepLineRef(),
|
||||
CollaborationHelper::sendPOSTRequestToAppOpen(
|
||||
$fileId,
|
||||
$app,
|
||||
$this->featureContext->getActualUsername($user),
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
['Content-Type' => 'application/json']
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$viewMode
|
||||
)->getBody()->getContents()
|
||||
);
|
||||
|
||||
@@ -119,4 +117,46 @@ class CollaborationContext implements Context {
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When user :user tries to check the information of file :file of space :space using office :app with invalid file-id
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $file
|
||||
* @param string $space
|
||||
* @param string $app
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws GuzzleException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function userTriesToCheckTheInformationOfFileOfSpaceUsingOfficeWithInvalidFileId(string $user, string $file, string $space, string $app): void {
|
||||
$response = \json_decode(
|
||||
CollaborationHelper::sendPOSTRequestToAppOpen(
|
||||
$this->spacesContext->getFileId($user, $space, $file),
|
||||
$app,
|
||||
$this->featureContext->getActualUsername($user),
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef()
|
||||
)->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'];
|
||||
$position = strpos($wopiSrc, '/files/') + \strlen('/files/');
|
||||
|
||||
// Extract the base URL up to and including '/files/'
|
||||
$fullUrl = substr($wopiSrc, 0, $position) . WebDavHelper::generateUUIDv4();
|
||||
$this->featureContext->setResponse(
|
||||
HttpRequestHelper::get(
|
||||
$fullUrl . "?access_token=$accessToken",
|
||||
$this->featureContext->getStepLineRef()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -588,3 +588,14 @@ Feature: check file info with different wopi apps
|
||||
| view | true | false | false |
|
||||
| read | false | false | false |
|
||||
| write | false | true | true |
|
||||
|
||||
|
||||
Scenario Outline: try to get file info using invalid file id with office suites
|
||||
Given user "Alice" has uploaded file with content "hello world" to "/textfile0.txt"
|
||||
When user "Alice" tries to check the information of file "textfile0.txt" of space "Personal" using office "<office-suites>" with invalid file-id
|
||||
Then the HTTP status code should be "401"
|
||||
Examples:
|
||||
| office-suites |
|
||||
| Collabora |
|
||||
| FakeOffice |
|
||||
| OnlyOffice |
|
||||
|
||||
Reference in New Issue
Block a user