[Pkg-owncloud-commits] [php-sabredav] 134/163: Tests passing.
David Prévot
taffit at moszumanska.debian.org
Tue May 20 18:55:02 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag upstream/2.0.0_beta1
in repository php-sabredav.
commit 0e8c43ee0f2b2394d25deb22dfd17404c6a1547e
Author: Evert Pot <me at evertpot.com>
Date: Tue May 13 16:21:27 2014 -0400
Tests passing.
---
lib/DAV/Browser/Plugin.php | 68 +++++++++-------------------------
tests/Sabre/DAV/Browser/PluginTest.php | 59 +++++++++++++++++++++++++----
2 files changed, 69 insertions(+), 58 deletions(-)
diff --git a/lib/DAV/Browser/Plugin.php b/lib/DAV/Browser/Plugin.php
index b4404c3..d1c05b8 100644
--- a/lib/DAV/Browser/Plugin.php
+++ b/lib/DAV/Browser/Plugin.php
@@ -24,34 +24,6 @@ use
class Plugin extends DAV\ServerPlugin {
/**
- * List of default icons for nodes.
- *
- * This is an array with class / interface names as keys, and asset names
- * as values.
- *
- * The evaluation order is reversed. The last item in the list gets
- * precendence.
- *
- * @var array
- */
- public $iconMap = array(
- 'Sabre\\DAV\\INode' => 'icons/other',
- 'Sabre\\DAV\\IFile' => 'icons/file',
- 'Sabre\\DAV\\ICollection' => 'icons/collection',
- 'Sabre\\DAVACL\\IPrincipal' => 'icons/principal',
- 'Sabre\\CalDAV\\ICalendar' => 'icons/calendar',
- 'Sabre\\CardDAV\\IAddressBook' => 'icons/addressbook',
- 'Sabre\\CardDAV\\ICard' => 'icons/card',
- );
-
- /**
- * The file extension used for all icons
- *
- * @var string
- */
- public $iconExtension = '.png';
-
- /**
* reference to server class
*
* @var Sabre\DAV\Server
@@ -167,7 +139,10 @@ class Plugin extends DAV\ServerPlugin {
$this->server->createDirectory($uri . '/' . $folderName);
}
break;
+
+ // @codeCoverageIgnoreStart
case 'put' :
+
if ($_FILES) $file = current($_FILES);
else break;
@@ -182,6 +157,7 @@ class Plugin extends DAV\ServerPlugin {
$this->server->createFile($uri . '/' . $newName, fopen($file['tmp_name'],'r'));
}
break;
+ // @codeCoverageIgnoreEnd
}
@@ -230,7 +206,7 @@ class Plugin extends DAV\ServerPlugin {
<!DOCTYPE html>
<html>
<head>
- <title>$vars[path] / - sabre/dav $version</title>
+ <title>$vars[path]/ - sabre/dav $version</title>
<link rel="shortcut icon" href="$vars[favicon]" type="image/vnd.microsoft.icon" />
<link rel="stylesheet" href="$vars[style]" type="text/css" />
<link rel="stylesheet" href="$vars[iconstyle]" type="text/css" />
@@ -414,10 +390,10 @@ HTML;
$path = $assetDir . $assetName;
// Making sure people aren't trying to escape from the base path.
- if (strpos(realpath($path), realpath($assetDir)) === 0) {
+ if (strpos(realpath($path), realpath($assetDir)) === 0 && file_exists($path)) {
return $path;
}
- throw new DAV\Exception\Forbidden('Path does not exist, or escaping from the base path was detected');
+ throw new DAV\Exception\NotFound('Path does not exist, or escaping from the base path was detected');
}
/**
@@ -429,28 +405,18 @@ HTML;
protected function serveAsset($assetName) {
$assetPath = $this->getLocalAssetPath($assetName);
- if (!file_exists($assetPath)) {
- throw new DAV\Exception\NotFound('Could not find an asset with this name');
- }
- // Rudimentary mime type detection
- switch(strtolower(substr($assetPath,strpos($assetPath,'.')+1))) {
-
- case 'ico' :
- $mime = 'image/vnd.microsoft.icon';
- break;
- case 'png' :
- $mime = 'image/png';
- break;
-
- case 'css' :
- $mime = 'text/css';
- break;
-
- default:
- $mime = 'application/octet-stream';
- break;
+ // Rudimentary mime type detection
+ $mime = 'application/octet-stream';
+ $map = [
+ 'ico' => 'image/vnd.microsoft.icon',
+ 'png' => 'image/png',
+ 'css' => 'text/css',
+ ];
+ $ext = substr($assetName, strrpos($assetName, '.')+1);
+ if (isset($map[$ext])) {
+ $mime = $map[$ext];
}
$this->server->httpResponse->setHeader('Content-Type', $mime);
diff --git a/tests/Sabre/DAV/Browser/PluginTest.php b/tests/Sabre/DAV/Browser/PluginTest.php
index d5419c0..7bc918a 100644
--- a/tests/Sabre/DAV/Browser/PluginTest.php
+++ b/tests/Sabre/DAV/Browser/PluginTest.php
@@ -9,10 +9,12 @@ require_once 'Sabre/DAV/AbstractServer.php';
class PluginTest extends DAV\AbstractServer{
+ protected $plugin;
+
function setUp() {
parent::setUp();
- $this->server->addPlugin(new Plugin());
+ $this->server->addPlugin($this->plugin = new Plugin());
}
@@ -35,15 +37,14 @@ class PluginTest extends DAV\AbstractServer{
$this->response->headers
);
- $this->assertTrue(strpos($this->response->body, 'Index for dir/') !== false);
- $this->assertTrue(strpos($this->response->body, '<a href="/dir/child.txt"><img src="/?sabreAction=asset&assetName=icons%2Ffile.png" alt="" width="24" />')!==false);
+ $this->assertTrue(strpos($this->response->body, '<title>dir/') !== false);
+ $this->assertTrue(strpos($this->response->body, '<a href="/dir/child.txt">')!==false);
}
-
- function testNotFound() {
+ function testCollectionGetRoot() {
$serverVars = array(
- 'REQUEST_URI' => '/random',
+ 'REQUEST_URI' => '/',
'REQUEST_METHOD' => 'GET',
);
@@ -51,7 +52,27 @@ class PluginTest extends DAV\AbstractServer{
$this->server->httpRequest = ($request);
$this->server->exec();
- $this->assertEquals(404, $this->response->status);
+ $this->assertEquals(200, $this->response->status, "Incorrect status received. Full response body: " . $this->response->getBodyAsString());
+ $this->assertEquals(array(
+ 'Content-Type' => 'text/html; charset=utf-8',
+ 'Content-Security-Policy' => "img-src 'self'; style-src 'unsafe-inline';"
+ ),
+ $this->response->headers
+ );
+
+ $this->assertTrue(strpos($this->response->body, '<title>/') !== false);
+ $this->assertTrue(strpos($this->response->body, '<a href="/dir/">')!==false);
+ $this->assertTrue(strpos($this->response->body, '<span class="btn disabled">')!==false);
+
+ }
+
+ function testGETPassthru() {
+
+ $request = new HTTP\Request('GET', '/random');
+ $response = new HTTP\Response();
+ $this->assertNull(
+ $this->plugin->httpGet($request, $response)
+ );
}
@@ -113,4 +134,28 @@ class PluginTest extends DAV\AbstractServer{
}
+ function testGetAsset() {
+
+ $request = new HTTP\Request('GET', '/?sabreAction=asset&assetName=favicon.ico');
+ $this->server->httpRequest = $request;
+ $this->server->exec();
+
+ $this->assertEquals(200, $this->response->getStatus(), 'Error: ' . $this->response->body);
+ $this->assertEquals([
+ 'Content-Type' => 'image/vnd.microsoft.icon',
+ 'Content-Length' => '4286',
+ 'Cache-Control' => 'public, max-age=1209600',
+ ], $this->response->getHeaders());
+
+ }
+
+ function testGetAsset404() {
+
+ $request = new HTTP\Request('GET', '/?sabreAction=asset&assetName=flavicon.ico');
+ $this->server->httpRequest = $request;
+ $this->server->exec();
+
+ $this->assertEquals(404, $this->response->getStatus(), 'Error: ' . $this->response->body);
+
+ }
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git
More information about the Pkg-owncloud-commits
mailing list