1
0

S3Test.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Robin Appelman <robin@icewind.nl>
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. namespace Test\Files\ObjectStore;
  22. use Icewind\Streams\Wrapper;
  23. use OC\Files\ObjectStore\S3;
  24. class MultiPartUploadS3 extends S3 {
  25. function writeObject($urn, $stream) {
  26. $this->getConnection()->upload($this->bucket, $urn, $stream, 'private', [
  27. 'mup_threshold' => 1
  28. ]);
  29. }
  30. }
  31. class NonSeekableStream extends Wrapper {
  32. public static function wrap($source) {
  33. $context = stream_context_create(array(
  34. 'nonseek' => array(
  35. 'source' => $source
  36. )
  37. ));
  38. return Wrapper::wrapSource($source, $context, 'nonseek', self::class);
  39. }
  40. public function dir_opendir($path, $options) {
  41. return false;
  42. }
  43. public function stream_open($path, $mode, $options, &$opened_path) {
  44. $this->loadContext('nonseek');
  45. return true;
  46. }
  47. public function stream_seek($offset, $whence = SEEK_SET) {
  48. return false;
  49. }
  50. }
  51. /**
  52. * @group PRIMARY-s3
  53. */
  54. class S3Test extends ObjectStoreTest {
  55. protected function getInstance() {
  56. $config = \OC::$server->getConfig()->getSystemValue('objectstore');
  57. if (!is_array($config) || $config['class'] !== 'OC\\Files\\ObjectStore\\S3') {
  58. $this->markTestSkipped('objectstore not configured for s3');
  59. }
  60. return new S3($config['arguments']);
  61. }
  62. public function testUploadNonSeekable() {
  63. $config = \OC::$server->getConfig()->getSystemValue('objectstore');
  64. if (!is_array($config) || $config['class'] !== 'OC\\Files\\ObjectStore\\S3') {
  65. $this->markTestSkipped('objectstore not configured for s3');
  66. }
  67. $s3 = $this->getInstance();
  68. $s3->writeObject('multiparttest', NonSeekableStream::wrap(fopen(__FILE__, 'r')));
  69. $result = $s3->readObject('multiparttest');
  70. $this->assertEquals(file_get_contents(__FILE__), stream_get_contents($result));
  71. }
  72. }