Skip to content

Commit

Permalink
review addresses
Browse files Browse the repository at this point in the history
Signed-off-by: nabim777 <[email protected]>
  • Loading branch information
nabim777 committed Jan 3, 2025
1 parent 0ec975d commit d592bae
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* ownCloud
*
* @author Nabin Magar <[email protected]>
* @copyright Copyright (c) 2017 Nabin Magar [email protected]
* @copyright Copyright (c) 2025 Nabin Magar [email protected]
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License,
Expand All @@ -23,54 +23,17 @@
namespace TestHelpers;

use Carbon\Carbon;
use GuzzleHttp\Exception\GuzzleException;
use TusPhp\Exception\FileException;
use GuzzleHttp\Exception\ClientException;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Exception\GuzzleException;
use Symfony\Component\HttpFoundation\Response as HttpResponse;
use ReflectionException;
use TusPhp\Tus\Client;

/**
* A helper class where TUS is wrapped and done API requests
* A TUS client based on TusPhp\Tus\Client
*/

class TusClientWrapper extends Client {
public $client;

/**
* Constructor for the TusClientWrapper.
*
* @param string $baseUri
* @param array $options
*
* @throws ReflectionException
*/
public function __construct(string $baseUri, array $options = []) {
parent::__construct($baseUri, $options);
$this->client = new Client($baseUri, $options);
}

/**
* @param string $key
*
* @return self
*/
public function setKey(string $key): self {
$this->client->setKey($key);
return $this;
}

/**
* @param string $file
* @param string|null $name
*
* @return self
*/
public function file(string $file, string $name = null): self {
$this->client->file($file, $name);
return $this;
}
class TusClient extends Client {

/**
* @param string $key
Expand All @@ -82,15 +45,15 @@ public function file(string $file, string $name = null): self {
public function createUploadWithResponse(string $key, int $bytes = -1): ResponseInterface {
$bytes = $bytes < 0 ? $this->fileSize : $bytes;
$headers = $this->headers + [
'Upload-Length' => $this->client->fileSize,
'Upload-Length' => $this->fileSize,
'Upload-Key' => $key,
'Upload-Checksum' => $this->client->getUploadChecksumHeader(),
'Upload-Metadata' => $this->client->getUploadMetadataHeader(),
'Upload-Checksum' => $this->getUploadChecksumHeader(),
'Upload-Metadata' => $this->getUploadMetadataHeader(),
];

$data = '';
if ($bytes > 0) {
$data = $this->client->getData(0, $bytes);
$data = $this->getData(0, $bytes);

$headers += [
'Content-Type' => self::HEADER_CONTENT_TYPE,
Expand All @@ -103,7 +66,7 @@ public function createUploadWithResponse(string $key, int $bytes = -1): Response
}

try {
$response = $this->client->getClient()->post(
$response = $this->getClient()->post(
$this->apiPath,
[
'body' => $data,
Expand All @@ -123,7 +86,7 @@ public function createUploadWithResponse(string $key, int $bytes = -1): Response
$uploadLocation = current($response->getHeader('location'));

$this->getCache()->set(
$this->client->getKey(),
$this->getKey(),
[
'location' => $uploadLocation,
'expires_at' => Carbon::now()->addSeconds($this->getCache()->getTtl())->format($this->getCache()::RFC_7231),
Expand Down
12 changes: 6 additions & 6 deletions tests/acceptance/bootstrap/TUSContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
use TestHelpers\HttpRequestHelper;
use TestHelpers\WebDavHelper;
use TestHelpers\BehatHelper;
use TestHelpers\TusClientWrapper;
use TestHelpers\TusClient;

require_once 'bootstrap.php';

Expand Down Expand Up @@ -366,22 +366,22 @@ public function publicUploadFileUsingTus(
$token = $this->featureContext->getLastCreatedPublicShareToken();
}
$headers = [
'Authorization' => 'Basic ' . \base64_encode("public" . ':' . $password),
'Authorization' => 'Basic ' . \base64_encode("public:$password"),
];
$sourceFile = $this->featureContext->acceptanceTestsDirLocation() . $source;
$url = WebdavHelper::getDavPath(WebDavHelper::DAV_VERSION_SPACES, $token, "public-files");

$tusWrapper = new TusClientWrapper(
$tusClient = new TusClient(
$this->featureContext->getBaseUrl(),
[
'verify' => false,
'headers' => $headers
]
);

$tusWrapper->setApiPath($url);
$tusWrapper->setKey((string)rand())->file($sourceFile, $destination);
$response = $tusWrapper->file($sourceFile, $destination)->createUploadWithResponse("", 0);
$tusClient->setApiPath($url);
$tusClient->setKey((string)rand())->file($sourceFile, $destination);
$response = $tusClient->file($sourceFile, $destination)->createUploadWithResponse("", 0);
return $response;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/expected-failures-without-remotephp.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@
- [apiSpaces/uploadSpaces.feature:132](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpaces/uploadSpaces.feature#L132)
- [apiSpacesShares/shareSpacesViaLink.feature:61](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesShares/shareSpacesViaLink.feature#L61)
- [apiSpacesShares/shareUploadTUS.feature:407](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesShares/shareUploadTUS.feature#L407)
- [apiSpacesShares/shareUploadTUS.feature:423](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesShares/shareUploadTUS.feature#L423)
- [apiSpacesShares/shareUploadTUS.feature:441](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesShares/shareUploadTUS.feature#L441)
- [apiSpacesShares/shareUploadTUS.feature:424](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesShares/shareUploadTUS.feature#L424)
- [apiSpacesShares/shareUploadTUS.feature:443](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiSpacesShares/shareUploadTUS.feature#L443)
- [apiDepthInfinity/propfind.feature:74](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiDepthInfinity/propfind.feature#L74)
- [apiDepthInfinity/propfind.feature:124](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiDepthInfinity/propfind.feature#L124)
- [apiLocks/lockFiles.feature:490](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiLocks/lockFiles.feature#L490)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ Feature: upload resources on share using TUS protocol
| permissionsRole | createOnly |
| password | %public% |
When the public uploads file "filesForUpload/zerobyte.txt" to "textfile.txt" via TUS inside last link shared folder with password "%public%" using the WebDAV API
Then the HTTP status code should be "201"
And for user "Alice" folder "uploadFolder" of the space "Personal" should contain these files:
| textfile.txt |
And for user "Alice" folder "uploadFolder" of the space "Personal" should not contain these files:
Expand All @@ -431,6 +432,7 @@ Feature: upload resources on share using TUS protocol
| permissionsRole | createOnly |
| password | %public% |
When the public uploads file "filesForUpload/zerobyte.txt" to "textfile.txt" via TUS inside last link shared folder with password "%public%" using the WebDAV API
Then the HTTP status code should be "201"
And for user "Alice" folder "uploadFolder" of the space "Project" should contain these files:
| textfile.txt |
And for user "Alice" folder "uploadFolder" of the space "Project" should not contain these files:
Expand Down

0 comments on commit d592bae

Please sign in to comment.