From 0b02a6d123b2014705998c94ddf3d460948d3eac Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 10 May 2016 17:26:44 -0700 Subject: initial sabre upgrade (needs lots of work - to wit: authentication, redo the browser interface, and rework event export/import) --- .../sabre/dav/tests/Sabre/DAV/ServerRangeTest.php | 350 ++++++++++----------- 1 file changed, 169 insertions(+), 181 deletions(-) (limited to 'vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php') diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php index a06fcb0be..bafbef6e4 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php @@ -1,42 +1,62 @@ server->createFile('files/test.txt', 'Test contents'); - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=2-5', + $this->lastModified = HTTP\Util::toHTTPDate( + new DateTime('@' . $this->server->tree->getNodeForPath('files/test.txt')->getLastModified()) ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); + $stream = popen('echo "Test contents"', 'r'); + $streamingFile = new Mock\StreamingFile( + 'no-seeking.txt', + $stream + ); + $streamingFile->setSize(12); + $this->server->tree->getNodeForPath('files')->addNode($streamingFile); - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 4, - 'Content-Range' => 'bytes 2-5/13', - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')). '"', - ), - $this->response->headers - ); + } - $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status); - $this->assertEquals('st c', stream_get_contents($this->response->body)); + function testRange() { + + $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=2-5']); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [4], + 'Content-Range' => ['bytes 2-5/13'], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() + ); + $this->assertEquals(206, $response->getStatus()); + $this->assertEquals('st c', $response->getBodyAsString()); } @@ -45,28 +65,22 @@ class ServerRangeTest extends AbstractServer{ */ function testStartRange() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=2-', + $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=2-']); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [11], + 'Content-Range' => ['bytes 2-12/13'], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 11, - 'Content-Range' => 'bytes 2-12/13', - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status); - $this->assertEquals('st contents', stream_get_contents($this->response->body)); + $this->assertEquals(206, $response->getStatus()); + $this->assertEquals('st contents', $response->getBodyAsString()); } @@ -75,28 +89,22 @@ class ServerRangeTest extends AbstractServer{ */ function testEndRange() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=-8', + $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=-8']); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [8], + 'Content-Range' => ['bytes 5-12/13'], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 8, - 'Content-Range' => 'bytes 5-12/13', - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')). '"', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status); - $this->assertEquals('contents', stream_get_contents($this->response->body)); + $this->assertEquals(206, $response->getStatus()); + $this->assertEquals('contents', $response->getBodyAsString()); } @@ -105,17 +113,10 @@ class ServerRangeTest extends AbstractServer{ */ function testTooHighRange() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=100-200', - ); + $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=100-200']); + $response = $this->request($request); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals('HTTP/1.1 416 Requested Range Not Satisfiable',$this->response->status); + $this->assertEquals(416, $response->getStatus()); } @@ -124,151 +125,138 @@ class ServerRangeTest extends AbstractServer{ */ function testCrazyRange() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=8-4', - ); + $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=8-4']); + $response = $this->request($request); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); + $this->assertEquals(416, $response->getStatus()); - $this->assertEquals('HTTP/1.1 416 Requested Range Not Satisfiable',$this->response->status); + } + + function testNonSeekableStream() { + + $request = new HTTP\Request('GET', '/files/no-seeking.txt', ['Range' => 'bytes=2-5']); + $response = $this->request($request); + + $this->assertEquals(206, $response->getStatus(), $response); + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [4], + 'Content-Range' => ['bytes 2-5/12'], + // 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() + ); + + $this->assertEquals('st c', $response->getBodyAsString()); } /** * @depends testRange - * @covers \Sabre\DAV\Server::httpGet */ function testIfRangeEtag() { - $node = $this->server->tree->getNodeForPath('test.txt'); - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=2-5', - 'HTTP_IF_RANGE' => $node->getETag(), + $request = new HTTP\Request('GET', '/files/test.txt', [ + 'Range' => 'bytes=2-5', + 'If-Range' => '"' . md5('Test contents') . '"', + ]); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [4], + 'Content-Range' => ['bytes 2-5/13'], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 4, - 'Content-Range' => 'bytes 2-5/13', - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status); - $this->assertEquals('st c', stream_get_contents($this->response->body)); + $this->assertEquals(206, $response->getStatus()); + $this->assertEquals('st c', $response->getBodyAsString()); } /** - * @depends testRange - * @covers \Sabre\DAV\Server::httpGet + * @depends testIfRangeEtag */ function testIfRangeEtagIncorrect() { - $node = $this->server->tree->getNodeForPath('test.txt'); - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=2-5', - 'HTTP_IF_RANGE' => $node->getETag() . 'blabla', + $request = new HTTP\Request('GET', '/files/test.txt', [ + 'Range' => 'bytes=2-5', + 'If-Range' => '"foobar"', + ]); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [13], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); - $this->assertEquals('Test contents', stream_get_contents($this->response->body)); + $this->assertEquals(200, $response->getStatus()); + $this->assertEquals('Test contents', $response->getBodyAsString()); } /** - * @depends testRange - * @covers \Sabre\DAV\Server::httpGet + * @depends testIfRangeEtag */ function testIfRangeModificationDate() { - $node = $this->server->tree->getNodeForPath('test.txt'); - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=2-5', - 'HTTP_IF_RANGE' => 'tomorrow', + $request = new HTTP\Request('GET', '/files/test.txt', [ + 'Range' => 'bytes=2-5', + 'If-Range' => 'tomorrow', + ]); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [4], + 'Content-Range' => ['bytes 2-5/13'], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 4, - 'Content-Range' => 'bytes 2-5/13', - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status); - $this->assertEquals('st c', stream_get_contents($this->response->body)); + $this->assertEquals(206, $response->getStatus()); + $this->assertEquals('st c', $response->getBodyAsString()); } /** - * @depends testRange - * @covers \Sabre\DAV\Server::httpGet + * @depends testIfRangeModificationDate */ function testIfRangeModificationDateModified() { - $node = $this->server->tree->getNodeForPath('test.txt'); - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=2-5', - 'HTTP_IF_RANGE' => '-2 years', + $request = new HTTP\Request('GET', '/files/test.txt', [ + 'Range' => 'bytes=2-5', + 'If-Range' => '-2 years', + ]); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [13], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); - $this->assertEquals('Test contents', stream_get_contents($this->response->body)); + $this->assertEquals(200, $response->getStatus()); + $this->assertEquals('Test contents', $response->getBodyAsString()); } + } -- cgit v1.2.3