From: <ja...@us...> - 2007-03-14 01:46:28
|
Revision: 15996 http://svn.sourceforge.net/gallery/?rev=15996&view=rev Author: jablko Date: 2007-03-13 18:46:09 -0700 (Tue, 13 Mar 2007) Log Message: ----------- Branch at r15715 to bring 2.3 changes up-to-date. Should be unstable for about a week. Modified Paths: -------------- branches/DEV_2_3/gallery2/modules/webdav/ItemAddWebDav.inc branches/DEV_2_3/gallery2/modules/webdav/MANIFEST branches/DEV_2_3/gallery2/modules/webdav/WebDav.inc branches/DEV_2_3/gallery2/modules/webdav/classes/WebDavHelper.class branches/DEV_2_3/gallery2/modules/webdav/lib/HTTP/WebDAV/Server.php branches/DEV_2_3/gallery2/modules/webdav/module.inc branches/DEV_2_3/gallery2/modules/webdav/templates/WebDavMount.tpl branches/DEV_2_3/gallery2/modules/webdav/templates/WebDavSiteAdmin.tpl branches/DEV_2_3/gallery2/modules/webdav/test/phpunit/WebDavHelperTest.class branches/DEV_2_3/gallery2/modules/webdav/test/phpunit/WebDavModuleTest.class branches/DEV_2_3/gallery2/modules/webdav/test/phpunit/WebDavTest.class Removed Paths: ------------- branches/DEV_2_3/gallery2/modules/webdav/test/phpunit/WebDavControllerTest.class Modified: branches/DEV_2_3/gallery2/modules/webdav/ItemAddWebDav.inc =================================================================== --- branches/DEV_2_3/gallery2/modules/webdav/ItemAddWebDav.inc 2007-03-14 00:30:57 UTC (rev 15995) +++ branches/DEV_2_3/gallery2/modules/webdav/ItemAddWebDav.inc 2007-03-14 01:46:09 UTC (rev 15996) @@ -120,10 +120,8 @@ } } - $originalPath = GalleryUtilities::getRequestVariables('originalPath'); - $title = empty($originalPath) ? basename($path) : basename($originalPath); list ($ret, $newItem) = GalleryCoreApi::addItemToAlbum($tmpFile, basename($path), - $title, '', '', $mimeType, $item->getId()); + basename($path), '', '', $mimeType, $item->getId()); @$platform->unlink($tmpFile); if ($ret) { return array($ret, null, null); Modified: branches/DEV_2_3/gallery2/modules/webdav/MANIFEST =================================================================== --- branches/DEV_2_3/gallery2/modules/webdav/MANIFEST 2007-03-14 00:30:57 UTC (rev 15995) +++ branches/DEV_2_3/gallery2/modules/webdav/MANIFEST 2007-03-14 01:46:09 UTC (rev 15996) @@ -2,56 +2,52 @@ # File crc32 crc32(crlf) size size(crlf) or R File modules/webdav/Callbacks.inc 2358814663 3453825565 1439 1486 modules/webdav/DownloadDavMount.inc 926099365 1573674116 2786 2878 -modules/webdav/ItemAddWebDav.inc 1635114911 3200595044 7104 7341 -modules/webdav/WebDav.inc 296137277 2916812957 7614 7841 +modules/webdav/ItemAddWebDav.inc 804268224 2096187695 6964 7199 +modules/webdav/WebDav.inc 1859713481 1182911663 6143 6339 modules/webdav/WebDavMount.inc 1838621692 2805740046 1587 1636 modules/webdav/WebDavSiteAdmin.inc 553960122 2291144207 1698 1752 -modules/webdav/WebDavWorks.inc 2574696807 3621906002 1308 1352 modules/webdav/classes/GNUmakefile 1995366819 843025639 51 52 modules/webdav/classes/GalleryStorage/GNUmakefile 1465776782 2009162633 61 62 modules/webdav/classes/GalleryStorage/schema.tpl 3361478170 1381064364 2241 2323 modules/webdav/classes/Maps.inc 3097969041 2458683522 580 584 modules/webdav/classes/Maps.xml 389449069 1930493512 1049 1087 -modules/webdav/classes/WebDavHelper.class 1329646022 650662872 58191 60137 +modules/webdav/classes/WebDavHelper.class 1895625006 3506079620 55597 57481 modules/webdav/classes/WebDavRewriteHelper.class 107529024 2731722737 2434 2512 -modules/webdav/data/options/.htaccess 1142116337 350654909 1316 1345 -modules/webdav/lib/HTTP/WebDAV/Server.php 2461613593 933395689 74761 77305 +modules/webdav/data/options/.htaccess 1719099191 2742727123 1328 1357 +modules/webdav/lib/HTTP/WebDAV/Server.php 1402151775 2169634766 74485 77019 modules/webdav/lib/HTTP/WebDAV/Tools/_parse_lockinfo.php 11587171 140948099 6213 6442 modules/webdav/lib/HTTP/WebDAV/Tools/_parse_propfind.php 2397186960 1499307163 4574 4737 modules/webdav/lib/HTTP/WebDAV/Tools/_parse_proppatch.php 3422974363 1239742415 5688 5904 -modules/webdav/locale/cs/LC_MESSAGES/modules_webdav.mo 1095572198 1095572198 1214 1214 -modules/webdav/locale/de/LC_MESSAGES/modules_webdav.mo 4129039548 4129039548 9485 9485 -modules/webdav/locale/en_GB/LC_MESSAGES/modules_webdav.mo 654394346 654394346 453 453 -modules/webdav/locale/es/LC_MESSAGES/modules_webdav.mo 2043826315 2043826315 7806 7806 -modules/webdav/locale/fi/LC_MESSAGES/modules_webdav.mo 2570798301 2570798301 513 513 -modules/webdav/locale/fr/LC_MESSAGES/modules_webdav.mo 3584929929 3584929929 9951 9951 -modules/webdav/locale/it/LC_MESSAGES/modules_webdav.mo 3951034313 3951034313 9203 9203 -modules/webdav/locale/no/LC_MESSAGES/modules_webdav.mo 2473627305 2473627305 9161 9161 -modules/webdav/locale/pl/LC_MESSAGES/modules_webdav.mo 1351046872 1351046872 9502 9502 -modules/webdav/locale/sv/LC_MESSAGES/modules_webdav.mo 4049719577 4049719577 8890 8890 -modules/webdav/locale/zh_TW/LC_MESSAGES/modules_webdav.mo 3350359092 3350359092 8314 8314 -modules/webdav/module.inc 547239974 678537786 11095 11470 +modules/webdav/locale/cs/LC_MESSAGES/modules_webdav.mo 408565810 408565810 1214 1214 +modules/webdav/locale/de/LC_MESSAGES/modules_webdav.mo 1677803683 1677803683 1266 1266 +modules/webdav/locale/es/LC_MESSAGES/modules_webdav.mo 1590331011 1590331011 1170 1170 +modules/webdav/locale/fi/LC_MESSAGES/modules_webdav.mo 266031501 266031501 513 513 +modules/webdav/locale/fr/LC_MESSAGES/modules_webdav.mo 3030742211 3030742211 2223 2223 +modules/webdav/locale/it/LC_MESSAGES/modules_webdav.mo 2369786090 2369786090 8400 8400 +modules/webdav/locale/no/LC_MESSAGES/modules_webdav.mo 1588936859 1588936859 8314 8314 +modules/webdav/locale/pl/LC_MESSAGES/modules_webdav.mo 1033178615 1033178615 8658 8658 +modules/webdav/locale/sv/LC_MESSAGES/modules_webdav.mo 1863776046 1863776046 8068 8068 +modules/webdav/locale/zh_TW/LC_MESSAGES/modules_webdav.mo 1388296440 1388296440 1086 1086 +modules/webdav/module.inc 2204349489 2448567963 10580 10937 modules/webdav/po/GNUmakefile 1866879166 2808215985 98 103 -modules/webdav/po/cs.po 4002103185 3953130318 7255 7485 -modules/webdav/po/de.po 81315669 4051799517 11455 11724 -modules/webdav/po/en_GB.po 3310272189 3714926523 9762 10005 -modules/webdav/po/es.po 2758181795 110428928 11290 11558 -modules/webdav/po/fi.po 2793476087 2271178349 6202 6411 -modules/webdav/po/fr.po 3615135923 1113962556 11111 11365 -modules/webdav/po/it.po 628726326 1049957802 10336 10582 -modules/webdav/po/no.po 4281180005 3882833530 10410 10658 -modules/webdav/po/pl.po 3526258286 411814876 10710 10960 -modules/webdav/po/strings.raw 1636664032 2040123002 4443 4497 -modules/webdav/po/sv.po 3121131090 2072241148 10080 10324 -modules/webdav/po/zh_TW.po 377692492 4265811174 9954 10200 +modules/webdav/po/cs.po 623459642 2969429411 6747 6959 +modules/webdav/po/de.po 116337256 1691138182 6843 7054 +modules/webdav/po/es.po 473124587 2583291442 6619 6829 +modules/webdav/po/fi.po 1225929799 173816261 5747 5941 +modules/webdav/po/fr.po 1425785468 2544049610 6391 6586 +modules/webdav/po/it.po 2554605733 1022102804 9534 9763 +modules/webdav/po/no.po 3357659926 3776440567 9561 9791 +modules/webdav/po/pl.po 2131304220 3606266951 9842 10074 +modules/webdav/po/strings.raw 1625944072 1104263242 4028 4076 +modules/webdav/po/sv.po 2998556492 1033853026 9232 9458 +modules/webdav/po/zh_TW.po 3298333249 2578053000 6430 6636 modules/webdav/templates/ItemAddWebDav.tpl 1353965866 1079974098 387 396 -modules/webdav/templates/WebDavMount.tpl 2057727104 3263326614 1678 1719 -modules/webdav/templates/WebDavSiteAdmin.tpl 1888656763 3892656047 8485 8626 +modules/webdav/templates/WebDavMount.tpl 3999565063 2881432302 1677 1717 +modules/webdav/templates/WebDavSiteAdmin.tpl 2166503115 1989436278 7468 7590 modules/webdav/templates/blocks/WebDavUrl.tpl 2356653701 4082093646 430 440 modules/webdav/templates/blocks/blocks.inc 740358944 826543430 102 107 -modules/webdav/test/phpunit/WebDavControllerTest.class 1936323244 2189887960 2716 2794 -modules/webdav/test/phpunit/WebDavHelperTest.class 528043975 2532886763 22894 23598 -modules/webdav/test/phpunit/WebDavModuleTest.class 4260492541 1060355023 10533 10879 +modules/webdav/test/phpunit/WebDavHelperTest.class 1367533433 1503960819 18568 19139 +modules/webdav/test/phpunit/WebDavModuleTest.class 2266502664 3189239604 8675 8968 modules/webdav/test/phpunit/WebDavRewriteHelperTest.class 1374179425 2225051594 4834 4993 -modules/webdav/test/phpunit/WebDavTest.class 2870995331 3304953649 36046 37302 +modules/webdav/test/phpunit/WebDavTest.class 1382803309 3558694978 33512 34703 R modules/webdav/classes/WebDavActivatePluginEventListener.class Modified: branches/DEV_2_3/gallery2/modules/webdav/WebDav.inc =================================================================== --- branches/DEV_2_3/gallery2/modules/webdav/WebDav.inc 2007-03-14 00:30:57 UTC (rev 15995) +++ branches/DEV_2_3/gallery2/modules/webdav/WebDav.inc 2007-03-14 01:46:09 UTC (rev 15996) @@ -49,26 +49,6 @@ } /* - * Windows Web Folders does not respect HTTP auth requests in PUT responses, so the user - * will not be prompted to login. To work around this, request HTTP auth in all responses - * to anonymous Windows Web Folders requests. Consequently anonymous users can't connect to - * WebDAV with Windows Web Folders. - */ - $userAgent = GalleryUtilities::getServerVar('HTTP_USER_AGENT'); - if (strpos($userAgent, 'Microsoft Data Access Internet Publishing Provider DAV') !== false - || strpos($userAgent, 'Microsoft-WebDAV-MiniRedir') !== false) { - list ($ret, $isAnonymous) = GalleryCoreApi::isAnonymousUser(); - if ($ret) { - return array($ret, null); - } - if ($isAnonymous) { - return array(GalleryCoreApi::error(ERROR_PERMISSION_DENIED, __FILE__, __LINE__, - 'WebDAV: Anonymous request by MS Windows Webfolders WebDAV client detected.' - . ' Usability workaround: Require auth on all requests.'), null); - } - } - - /* * GalleryCoreApi::addItemToAlbum normalizes path components but * GalleryCoreApi::fetchItemIdByPath does not. This is a problem for WebDAV because GET * following a successful PUT at the same URL should succeed. @@ -81,32 +61,20 @@ * This condition may be relaxed in future if it's a problem. */ $path = GalleryUtilities::getRequestVariables('path'); - /** - * @todo Refactor towards a cleaner approach, e.g. using a map for public paths. - */ - GalleryUtilities::putRequestVariable('originalPath', $path); $pathComponent = basename($path); - - /* Special case to suppress Mac '._' files. Ignore request but return success. */ - if (!strncmp($pathComponent, '._', 2)) { - WebDavServer::setResponseStatus('200 OK'); - $handle = WebDavServer::openRequestBody(); - while (!feof($handle)) { - fgets($handle); + if (!$platform->isLegalPathComponent($pathComponent)) { + /* Special case to suppress Mac '._' files. Ignore request but return success. */ + if (!strncmp($pathComponent, '._', 2)) { + WebDavServer::setResponseStatus('200 OK'); + return array(GalleryCoreApi::error(ERROR_BAD_PATH), null); } + + WebDavServer::setResponseStatus('403 Forbidden'); return array(GalleryCoreApi::error(ERROR_BAD_PATH), null); } - /* Silently legalize path component */ - $pathComponents = preg_split('/\//', $path, -1, PREG_SPLIT_NO_EMPTY); - foreach ($pathComponents as $key => $pathComponent) { - $pathComponents[$key] = $platform->legalizePathComponent($pathComponent); - } - $path = implode('/', $pathComponents); - GalleryUtilities::putRequestVariable('path', $path); - $requestMethod = GalleryUtilities::strToLower( - GalleryUtilities::getServerVar('REQUEST_METHOD')); + GalleryUtilities::getServerVar('REQUEST_METHOD')); if ($requestMethod == 'get' || $requestMethod == 'head') { if (empty($path)) { list ($ret, $itemId) = GalleryCoreApi::getDefaultAlbumId(); @@ -137,33 +105,40 @@ 'status' => array(), 'error' => array())); } else if ($requestMethod == 'put') { - list ($ret, $parentId) = WebDavHelper::getParentItemIdByPath($path); - if ($ret) { - if ($ret->getErrorCode() & ERROR_MISSING_OBJECT) { - /* - * A PUT that would result in the creation of a resource without an - * appropriately scoped parent collection MUST fail with a 409 - * (Conflict). - */ - WebDavServer::setResponseStatus('409 Conflict'); + $parentPath = dirname($path); + + /* dirname('foo') is '.' */ + if ($parentPath == '.') { + list ($ret, $parentId) = GalleryCoreApi::getDefaultAlbumId(); + if ($ret) { + return array($ret, null); } + } else { + list ($ret, $parentId) = GalleryCoreApi::fetchItemIdByPath($parentPath); + if ($ret) { + if ($ret->getErrorCode() & ERROR_MISSING_OBJECT) { + /* + * A PUT that would result in the creation of a resource without an + * appropriately scoped parent collection MUST fail with a 409 + * (Conflict). + */ + WebDavServer::setResponseStatus('409 Conflict'); + } - return array($ret, null); - } + return array($ret, null); + } - /* Until there's a better way to delegate to ItemAdd */ - GalleryUtilities::putRequestVariable('itemId', $parentId); - GalleryUtilities::putRequestVariable('addPlugin', 'ItemAddWebDav'); - /* Let the ItemAddPlugin handle the replacement for the auth-token check */ - list ($ret, $data) = ItemAddController::handleRequest($form); - if ($ret) { - return array($ret, null); - } + /* Until there's a better way to delegate to ItemAdd */ + GalleryUtilities::putRequestVariable('itemId', $parentId); + GalleryUtilities::putRequestVariable('addPlugin', 'ItemAddWebDav'); + /* Let the ItemAddPlugin handle the replacement for the auth-token check */ + list ($ret, $data) = ItemAddController::handleRequest($form); + if ($ret) { + return array($ret, null); + } - /* - * Don't send HTTP redirects or HTML status/error back to DAV clients since we - * have already set our status code. Fall through to the standard empty return. - */ + return array(null, $data); + } } return array(null, array('delegate' => array('view' => 'webdav.WebDav'), @@ -206,13 +181,7 @@ $requestMethod = GalleryUtilities::strToLower( GalleryUtilities::getServerVar('REQUEST_METHOD')); if (!in_array($requestMethod, array('options', 'propfind', 'proppatch', 'mkcol', 'delete', - 'move', 'lock', 'unlock'))) { - - /* If we just completed a PUT request and got delegated here, just silently return */ - if ($requestMethod == 'put') { - return null; - } - + 'move', 'lock', 'unlock'))) { return GalleryCoreApi::error(ERROR_UNIMPLEMENTED); } Modified: branches/DEV_2_3/gallery2/modules/webdav/classes/WebDavHelper.class =================================================================== --- branches/DEV_2_3/gallery2/modules/webdav/classes/WebDavHelper.class 2007-03-14 00:30:57 UTC (rev 15995) +++ branches/DEV_2_3/gallery2/modules/webdav/classes/WebDavHelper.class 2007-03-14 01:46:09 UTC (rev 15996) @@ -30,7 +30,6 @@ define('WEBDAV_STATUS_ALTERNATIVE_URL_HEADERS', 0x00000080); define('WEBDAV_STATUS_BAD_REWRITE_PARSER', 0x00000100); define('WEBDAV_STATUS_OPTIONS_RULE_DISABLED', 0x00000200); -define('WEBDAV_STATUS_HTTPAUTH_AUTH_PLUGINS_DISABLED', 0x00000400); define('WEBDAV_STATUS_ERROR_UNKNOWN', 0x80000000); /* Gallery property namespace - RFC2518 18 */ @@ -75,7 +74,7 @@ if ($ret) { return array($ret, null); } - if (!isset($rewriteApi)) { + if (empty($rewriteApi)) { return array(GalleryCoreApi::error(ERROR_CONFIGURATION_REQUIRED), null); } @@ -105,7 +104,8 @@ /* Already checked one cause: URL rewrite module disabled. Check other causes. */ if (!WebDavHelper::checkDavHeaders($urlGenerator->generateUrl( array('href' => 'modules/webdav/data/options/'), - array('forceFullUrl' => true, + array('forceDirect' => true, + 'forceFullUrl' => true, 'htmlEntities' => false)))) { $code |= WEBDAV_STATUS_ALTERNATIVE_URL_HEADERS; } @@ -146,30 +146,13 @@ */ if (empty($moduleStatus['httpauth']['active'])) { $code |= WEBDAV_STATUS_HTTPAUTH_MODULE_DISABLED; - } else { - /* Ensure HTTP auth is enabled */ - list ($ret, $httpAuthInterface) = - GalleryCoreApi::newFactoryInstance('HttpAuthInterface_1_0'); - if ($ret) { - return array($ret, null); - } - if (isset($httpAuthInterface)) { - list ($ret, $httpAuthPluginEnabled, $serverAuthPluginEnabled) = - $httpAuthInterface->getConfiguration(); - if ($ret) { - return array($ret, null); - } - if (!$httpAuthPluginEnabled && !$serverAuthPluginEnabled) { - $code |= WEBDAV_STATUS_HTTPAUTH_AUTH_PLUGINS_DISABLED; - } - } } /* * Check that Gallery handles WebDAV request methods. Check it after checking for missing * DAV headers causes so we can show the error unknown warning if no causes are found. */ - foreach (array('PROPFIND', 'PROPPATCH', 'MKCOL', 'DELETE', 'PUT', 'MOVE', 'LOCK', 'UNLOCK') + foreach (array('PROPFIND', 'PROPPATCH', 'MKCOL', 'MOVE', 'LOCK', 'UNLOCK') as $requestMethod) { if (!WebDavHelper::checkRequestMethod($requestMethod)) { if ($gallery->getDebug()) { @@ -203,7 +186,7 @@ list ($status, $headers, $body) = GalleryCoreApi::requestWebPage($urlGenerator->generateUrl( array('view' => 'webdav.WebDavWorks'), array('forceFullUrl' => true, - 'htmlEntities' => false)), $requestMethod, array('Content-length' => 0)); + 'htmlEntities' => false)), $requestMethod); if (!preg_match('/^HTTP\/[0-9]\.[0-9] 200/', $status)) { return false; @@ -294,34 +277,6 @@ } /** - * Returns the id of item that corresponds to the parent of the given path. - * The item at the given path doesn't have to exist, but its parent is expected to exist. - * - * @param string $path, e.g. /foo/bar - * @return array object GalleryStatus a status code, - * int the id of the parent item - */ - function getParentItemIdByPath($path) { - $parentPath = dirname($path); - - /* dirname('foo') is '.' and \ for dirname ('/foo') on Windows */ - if (in_array($parentPath, array('.', '\\'))) { - list ($ret, $parentId) = - GalleryCoreApi::getPluginParameter('module', 'core', 'id.rootAlbum'); - if ($ret) { - return array($ret, null); - } - } else { - list ($ret, $parentId) = GalleryCoreApi::fetchItemIdByPath($parentPath); - if ($ret) { - return array($ret, null); - } - } - - return array(null, (int)$parentId); - } - - /** * Get singleton WebDAV server library instance. * * If it didn't need path and baseUrl, we could eliminate and call library methods staticly. @@ -670,7 +625,7 @@ $files[] = $file; if ($depth <= 0) { - return null; + return; } list ($ret, $childIds) = GalleryCoreApi::fetchChildItemIds($item); @@ -679,7 +634,7 @@ } if (empty($childIds)) { - return null; + return; } list ($ret, $childItems) = GalleryCoreApi::loadEntitiesById($childIds); @@ -699,8 +654,6 @@ return $ret; } } - - return null; } /** @@ -815,8 +768,6 @@ if ($ret) { return $ret; } - - return null; } /** @@ -976,17 +927,28 @@ } $pathComponent = basename($path); + $parentPath = dirname($path); - list ($ret, $parentId) = WebDavHelper::getParentItemIdByPath($path); - if ($ret) { - if ($ret->getErrorCode() & ERROR_MISSING_OBJECT) { - /* - * 409 (Conflict) - A resource cannot be created at the destination until one or - * more intermediate collections have been created. - */ - WebDavServer::setResponseStatus('409 Conflict'); + /* dirname('foo') is '.' */ + if ($parentPath == '.') { + list ($ret, $parentId) = GalleryCoreApi::getPluginParameter('module', 'core', + 'id.rootAlbum'); + if ($ret) { + return $ret; } - return $ret; + } else { + list ($ret, $parentId) = GalleryCoreApi::fetchItemIdByPath($parentPath); + if ($ret) { + if ($ret->getErrorCode() & ERROR_MISSING_OBJECT) { + /* + * 409 (Conflict) - A resource cannot be created at the destination until one or + * more intermediate collections have been created. + */ + WebDavServer::setResponseStatus('409 Conflict'); + } + + return $ret; + } } list ($ret, $error) = WebDavHelper::mkcolValidateHelper($parentId, $pathComponent); @@ -1005,9 +967,7 @@ return GalleryCoreApi::error(ERROR_PERMISSION_DENIED); } - $originalPath = GalleryUtilities::getRequestVariables('originalPath'); - $title = empty($originalPath) ? $pathComponent : basename($originalPath); - $ret = WebDavHelper::mkcolHelper($parentId, $pathComponent, $title, '', '', ''); + $ret = WebDavHelper::mkcolHelper($parentId, $pathComponent, $pathComponent, '', '', ''); if ($ret) { if ($ret->getErrorCode() & ERROR_ILLEGAL_CHILD) { @@ -1394,28 +1354,37 @@ return GalleryCoreApi::error(ERROR_BAD_PARAMETER); } - list ($ret, $newParentId) = WebDavHelper::getParentItemIdByPath($newPath); - if ($ret) { - if ($ret->getErrorCode() & ERROR_MISSING_OBJECT) { - /* - * 409 (Conflict) - A resource cannot be created at the destination until - * one or more intermediate collections have been created. - */ - WebDavServer::setResponseStatus('409 Conflict'); - } - return $ret; - } - - list ($ret, $newParent) = GalleryCoreApi::loadEntitiesById($newParentId); - if ($ret) { - return $ret; - } - $pathComponent = basename($path); $newPathComponent = basename($newPath); - $oldParentId = $item->getParentId(); - if ($oldParentId != $newParentId) { + $parentPath = dirname($path); + $newParentPath = dirname($newPath); + if ($newParentPath != $parentPath) { + + /* dirname('foo') is '.' */ + if ($newParentPath == '.') { + $newParentId = $rootId; + } else { + list ($ret, $newParentId) = GalleryCoreApi::fetchItemIdByPath($newParentPath); + if ($ret) { + if ($ret->getErrorCode() & ERROR_MISSING_OBJECT) { + + /* + * 409 (Conflict) - A resource cannot be created at the destination until + * one or more intermediate collections have been created. + */ + WebDavServer::setResponseStatus('409 Conflict'); + } + + return $ret; + } + } + + list ($ret, $newParent) = GalleryCoreApi::loadEntitiesById($newParentId); + if ($ret) { + return $ret; + } + list ($ret, $error) = WebDavHelper::moveValidateHelper($item, $newParent); if ($ret) { return $ret; @@ -1453,7 +1422,7 @@ } } - if ($oldParentId != $newParentId) { + if ($newParentPath != $parentPath) { /* * Read lock both parent hierarchies * TODO Optimize this @@ -1463,6 +1432,7 @@ return $ret; } + $oldParentId = $item->getParentId(); list ($ret, $lockIds[]) = GalleryCoreApi::acquireReadLockParents($oldParentId); if ($ret) { GalleryCoreApi::releaseLocks($lockIds); @@ -1500,7 +1470,7 @@ } } - if ($newParentId != $oldParentId) { + if ($newParentPath != $parentPath) { /* Do the move */ $ret = $item->move($newParentId); if ($ret) { @@ -1525,7 +1495,7 @@ return $ret; } - if ($newParentId != $oldParentId) { + if ($newParentPath != $parentPath) { if (GalleryUtilities::isA($item, 'GalleryDataItem')) { /* Update for derivative preferences of new parent */ $ret = GalleryCoreApi::addExistingItemToAlbum($item, $newParentId); @@ -1543,7 +1513,7 @@ } /* Fix thumbnail integrity */ - if ($newParentId != $oldParentId) { + if ($newParentPath != $parentPath) { /* What do we do if we weren't successful? No thumbnail, I guess. */ list ($ret, $success) = GalleryCoreApi::guaranteeAlbumHasThumbnail($oldParentId); if ($ret) { Modified: branches/DEV_2_3/gallery2/modules/webdav/lib/HTTP/WebDAV/Server.php =================================================================== --- branches/DEV_2_3/gallery2/modules/webdav/lib/HTTP/WebDAV/Server.php 2007-03-14 00:30:57 UTC (rev 15995) +++ branches/DEV_2_3/gallery2/modules/webdav/lib/HTTP/WebDAV/Server.php 2007-03-14 01:46:09 UTC (rev 15996) @@ -1213,11 +1213,6 @@ $options['content_language'] = $value; break; - case 'HTTP_CONTENT_LENGTH': - - // defined on IIS and has the same value as CONTENT_LENGTH - break; - case 'HTTP_CONTENT_LOCATION': // RFC2616 14.14 // meaning of the Content-Location header in PUT or POST @@ -1254,11 +1249,6 @@ echo 'The service does not support content MD5 checksum verification'; return; - case 'HTTP_CONTENT_TYPE': - - // defined on IIS and has the same value as CONTENT_TYPE - break; - default: // any other unknown Content-* headers Modified: branches/DEV_2_3/gallery2/modules/webdav/module.inc =================================================================== --- branches/DEV_2_3/gallery2/modules/webdav/module.inc 2007-03-14 00:30:57 UTC (rev 15995) +++ branches/DEV_2_3/gallery2/modules/webdav/module.inc 2007-03-14 01:46:09 UTC (rev 15996) @@ -31,7 +31,7 @@ $this->setId('webdav'); $this->setName($gallery->i18n('WebDAV')); - $this->setVersion('0.7.3'); /* Update upgrade() too! */ + $this->setVersion('0.7.2'); /* Update upgrade() too! */ $this->setDescription($gallery->i18n('Mount Gallery on your desktop.')); $this->setGroup('interfaces', $gallery->i18n('Remote Interfaces')); $this->setCallbacks('getItemLinks|getSiteAdminViews|registerEventListeners'); @@ -131,8 +131,6 @@ /* Add whitelist for external interface */ case '0.7.1': /* Rename WebDavMount to DownloadDavMount */ - case '0.7.2': - /* Add HttpAuth check through interface */ case 'end of upgrade path': break; @@ -251,7 +249,7 @@ } return $rules; } - if (!isset($rewriteApi)) { + if (empty($rewriteApi)) { return $rules; } @@ -317,22 +315,6 @@ return array(null, null); case 'Gallery::Error': - $data = $event->getData(); - if (($data['error']->getErrorCode() & ERROR_PERMISSION_DENIED)) { - /* Prompt for authentication */ - list ($ret, $httpAuthInterface) = - GalleryCoreApi::newFactoryInstance('HttpAuthInterface_1_0'); - if ($ret) { - return array($ret, null); - } - if (isset($httpAuthInterface)) { - $ret = $httpAuthInterface->requestAuthentication(); - if ($ret) { - return array($ret, null); - } - } - } - /* Suppress generating HTML error pages for WebDAV clients */ return array(null, array('suppressBody' => true)); } @@ -349,7 +331,7 @@ if ($ret) { return $ret; } - if (!isset($rewriteApi)) { + if (empty($rewriteApi)) { return GalleryCoreApi::error(ERROR_CONFIGURATION_REQUIRED); } Modified: branches/DEV_2_3/gallery2/modules/webdav/templates/WebDavMount.tpl =================================================================== --- branches/DEV_2_3/gallery2/modules/webdav/templates/WebDavMount.tpl 2007-03-14 00:30:57 UTC (rev 15995) +++ branches/DEV_2_3/gallery2/modules/webdav/templates/WebDavMount.tpl 2007-03-14 01:46:09 UTC (rev 15996) @@ -38,4 +38,4 @@ {if $isView} </div> {/if} -{/if} +{/if} \ No newline at end of file Modified: branches/DEV_2_3/gallery2/modules/webdav/templates/WebDavSiteAdmin.tpl =================================================================== --- branches/DEV_2_3/gallery2/modules/webdav/templates/WebDavSiteAdmin.tpl 2007-03-14 00:30:57 UTC (rev 15995) +++ branches/DEV_2_3/gallery2/modules/webdav/templates/WebDavSiteAdmin.tpl 2007-03-14 01:46:09 UTC (rev 15996) @@ -51,15 +51,6 @@ {g->text text="You can connect with WebDAV anonymously, but you can't do anything which requires you to login because the HTTP auth module is disabled. You should activate the HTTP auth module in the %sSite Admin Plugins option%s. Troubleshooting documentation is in the %sGallery Codex%s." arg1="<a href=\"$adminPluginsUrl\">" arg2="</a>" arg3="<a href=\"http://codex.gallery2.org/index.php/Gallery2:Modules:webdav:admin\">" arg4="</a>"} </p> </div> -{elseif $WebDavSiteAdmin.code & WEBDAV_STATUS_HTTPAUTH_AUTH_PLUGINS_DISABLED} - <div class="gbBlock"> - <h3 class="giWarning"> {g->text text="HTTP auth plugin disabled"} </h3> - - <p class="giDescription"> - {g->text text="You can connect with WebDAV anonymously, but you can't do anything which requires you to login because neither HTTP authentication nor server authentication are enabled in the HTTP auth module. You should activate HTTP authentication in the settings of the HTTP auth module."} - </p> - </div> - {/if} {if $WebDavSiteAdmin.code & WEBDAV_STATUS_CONNECT_RULE_DISABLED} Deleted: branches/DEV_2_3/gallery2/modules/webdav/test/phpunit/WebDavControllerTest.class =================================================================== --- branches/DEV_2_3/gallery2/modules/webdav/test/phpunit/WebDavControllerTest.class 2007-03-14 00:30:57 UTC (rev 15995) +++ branches/DEV_2_3/gallery2/modules/webdav/test/phpunit/WebDavControllerTest.class 2007-03-14 01:46:09 UTC (rev 15996) @@ -1,78 +0,0 @@ -<?php -/* - * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2007 Bharat Mediratta - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. - */ - -GalleryCoreApi::requireOnce('modules/webdav/classes/WebDavHelper.class'); - -/** - * WebDAV Controller tests. - * @package WebDav - * @subpackage PHPUnit - * @author Andy Staudacher <ast@gmx> - * @version $Revision$ - */ -class WebDavControllerTest extends GalleryControllerTestCase { - function WebDavControllerTest($methodName) { - $this->GalleryControllerTestCase($methodName, 'webdav.WebDav'); - } - - function testRequireAuthForAllRequestsByWindowsWebfolders() { - /* See bug 1645834 */ - $this->_becomeGuestUser(); - - foreach (array('Microsoft Data Access Internet Publishing Provider DAV foo bar', - 'Microsoft-WebDAV-MiniRedir/5.1.2600') as $userAgent) { - $_SERVER['HTTP_USER_AGENT'] = $userAgent; - - foreach (array('options', 'propfind', 'proppatch', 'mkcol', 'delete', - 'move', 'lock', 'unlock', 'put', 'get', 'head') as $requestMethod) { - $_SERVER['REQUEST_METHOD'] = $requestMethod; - - $results = $this->handleRequest(ERROR_PERMISSION_DENIED); - $this->assertEquals(null, $results, - "User-Agent: $userAgent, Request-Method: $requestMethod"); - } - } - } - - function testNoAuthRequestForLoggedInUsersForRequestsByWindowsWebfolders() { - $_SERVER['REQUEST_METHOD'] = 'propfind'; - $_SERVER['HTTP_USER_AGENT'] = - 'Microsoft Data Access Internet Publishing Provider DAV foo bar'; - - $results = $this->handleRequest(); - $this->assertEquals(array('delegate' => array('view' => 'webdav.WebDav'), - 'status' => array(), - 'error' => array()), - $results); - } - - function testNoAuthRequiredForOtherClients() { - $_SERVER['REQUEST_METHOD'] = 'propfind'; - $_SERVER['HTTP_USER_AGENT'] = 'SOME USER AGENT STRING'; - $this->_becomeGuestUser(); - - $results = $this->handleRequest(); - $this->assertEquals(array('delegate' => array('view' => 'webdav.WebDav'), - 'status' => array(), - 'error' => array()), - $results); - } -} -?> Modified: branches/DEV_2_3/gallery2/modules/webdav/test/phpunit/WebDavHelperTest.class =================================================================== --- branches/DEV_2_3/gallery2/modules/webdav/test/phpunit/WebDavHelperTest.class 2007-03-14 00:30:57 UTC (rev 15995) +++ branches/DEV_2_3/gallery2/modules/webdav/test/phpunit/WebDavHelperTest.class 2007-03-14 01:46:09 UTC (rev 15996) @@ -41,7 +41,6 @@ $this->_urlGenerator = new GalleryUrlGenerator(); $ret = $this->_urlGenerator->init('http://example.com/gallery2/main.php'); if ($ret) { - print $ret->getAsHtml(); return $this->failWithStatus($ret); } $gallery->setUrlGenerator($this->_urlGenerator); @@ -66,12 +65,6 @@ 'RewriteApi', 'WebDavHelperTestRewriteApi', 'WebDavHelperTestRewriteApi', 'modules/webdav/test/phpunit/WebDavHelperTest.class', 'test'); - $this->_registerFactoryImplementationForTest( - 'HttpAuthInterface_1_0', 'WebDavHelperTestHttpAuthInterface', - 'WebDavHelperTestHttpAuthInterface', - 'modules/webdav/test/phpunit/WebDavHelperTest.class', 'test'); - WebDavHelperTestHttpAuthInterface::_getConfiguration(true); - /* Define requests */ $this->_optionsRequest = implode("\r\n", array( 'OPTIONS ' . $this->_urlGenerator->generateUrl( @@ -138,7 +131,7 @@ $this->_platform = new WebDavHelperTestPlatform(); $this->_requests = array(); - foreach (array('PROPFIND', 'PROPPATCH', 'MKCOL', 'DELETE', 'PUT', 'MOVE', 'LOCK', 'UNLOCK') + foreach (array('PROPFIND', 'PROPPATCH', 'MKCOL', 'MOVE', 'LOCK', 'UNLOCK') as $requestMethod) { $this->_requests[$requestMethod] = implode("\r\n", array( $requestMethod . ' ' . $this->_urlGenerator->generateUrl( @@ -146,7 +139,6 @@ array('forceServerRelativeUrl' => true, 'htmlEntities' => false)) . ' HTTP/1.0', 'Host: ' . $this->_urlGenerator->getHostName(), - 'Content-length: 0', /* IIS requires a Content-length at least for PUT requests */ '', '')); @@ -172,7 +164,7 @@ return $this->failWithStatus($ret); } - $this->assertEquals(0, $code, 'error code'); + $this->assert(!$code); } function testCheckConfigurationNoXmlParser() { @@ -210,17 +202,6 @@ $this->assertEquals(WEBDAV_STATUS_HTTPAUTH_MODULE_DISABLED, $code); } - function testCheckConfigurationHttpAuthPluginDisabled() { - WebDavHelperTestHttpAuthInterface::_getConfiguration(false); - /* Even when the httpauth module is active, none of its auth plugins could be active. */ - list ($ret, $code) = WebDavHelper::checkConfiguration(); - if ($ret) { - return $this->failWithStatus($ret); - } - - $this->assertEquals(WEBDAV_STATUS_HTTPAUTH_AUTH_PLUGINS_DISABLED, $code, 'error code'); - } - function testCheckConfigurationRewriteModuleDisabled() { $moduleStatus = array('httpauth' => array('active' => true)); GalleryDataCache::put('GalleryPluginHelper::fetchPluginList(module)', $moduleStatus); @@ -557,51 +538,6 @@ $this->assertEquals($expected, $link); } - - function testGetParentItemIdByPathDefaultForNoParent() { - list ($ret, $parentId) = WebDavHelper::getParentItemIdByPath('foo'); - if ($ret) { - return $this->failWithStatus($ret); - } - - $this->assertEquals($this->_getRootId(), $parentId); - } - - function testGetParentItemIdByPathForTopLevelItems() { - list ($ret, $parentId) = WebDavHelper::getParentItemIdByPath('/foo'); - if ($ret) { - return $this->failWithStatus($ret); - } - - $this->assertEquals($this->_getRootId(), $parentId); - } - - function testGetParentItemIdByPathForNonExistentPath() { - list ($ret, $album) = $this->_createRandomAlbum($this->_getRootId()); - if ($ret) { - return $this->failWithStatus($ret); - } - $this->_markForCleanup($album); - - list ($ret, $parentId) = WebDavHelper::getParentItemIdByPath( - '/' . $album->getPathComponent() . '/foo'); - if ($ret) { - return $this->failWithStatus($ret); - } - - $this->assertEquals($album->getId(), $parentId); - } - - function testGetParentItemIdByPathForMissingParent() { - list ($ret, $parentId) = WebDavHelper::getParentItemIdByPath('/test_' . rand() . '/foo'); - if ($ret && $ret->getErrorCode() & ERROR_MISSING_OBJECT) { - /* As expected */ - } else if ($ret) { - return $this->failWithStatus($ret); - } else { - $this->fail('should have failed with ERROR_MISSING_OBJECT'); - } - } } class WebDavHelperTestPhpVm extends GalleryPhpVm { @@ -687,18 +623,4 @@ return true; } } - -class WebDavHelperTestHttpAuthInterface /* extends HttpAuthInterface_1_0 */ { - function _getConfiguration($initPluginsEnabled=null) { - static $pluginsEnabled; - if (isset($initPluginsEnabled)) { - $pluginsEnabled = $initPluginsEnabled; - } - return array(null, $pluginsEnabled, $pluginsEnabled, false); - } - - function getConfiguration() { - return WebDavHelperTestHttpAuthInterface::_getConfiguration(); - } -} ?> Modified: branches/DEV_2_3/gallery2/modules/webdav/test/phpunit/WebDavModuleTest.class =================================================================== --- branches/DEV_2_3/gallery2/modules/webdav/test/phpunit/WebDavModuleTest.class 2007-03-14 00:30:57 UTC (rev 15995) +++ branches/DEV_2_3/gallery2/modules/webdav/test/phpunit/WebDavModuleTest.class 2007-03-14 01:46:09 UTC (rev 15996) @@ -39,7 +39,6 @@ $urlGenerator = new GalleryUrlGenerator(); $ret = $urlGenerator->init('http://example.com/gallery2/main.php'); if ($ret) { - print $ret->getAsHtml(); return $this->failWithStatus($ret); } $gallery->setUrlGenerator($urlGenerator); @@ -47,7 +46,6 @@ /* Create test items */ list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId()); if ($ret) { - print $ret->getAsHtml(); return $this->failWithStatus($ret); } $this->_markForCleanup($this->_album); @@ -55,20 +53,17 @@ list ($ret, $this->_item) = $this->_createRandomDataItem($this->_album->getId(), 'test/file'); if ($ret) { - print $ret->getAsHtml(); return $this->failWithStatus($ret); } list ($ret, $this->_subAlbum) = $this->_createRandomAlbum($this->_album->getId()); if ($ret) { - print $ret->getAsHtml(); return $this->failWithStatus($ret); } /* Load WebDAV module */ list ($ret, $this->_module) = GalleryCoreApi::loadPlugin('module', 'webdav'); if ($ret) { - print $ret->getAsHtml(); return $this->failWithStatus($ret); } @@ -81,16 +76,9 @@ 'RewriteApi', 'WebDavModuleTestRewriteApi', 'WebDavModuleTestRewriteApi', 'modules/webdav/test/phpunit/WebDavModuleTest.class', 'test'); if ($ret) { - print $ret->getAsHtml(); return $this->failWithStatus($ret); } - $this->_registerFactoryImplementationForTest( - 'HttpAuthInterface_1_0', 'WebDavModuleTestHttpAuthInterface', - 'WebDavModuleTestHttpAuthInterface', - 'modules/webdav/test/phpunit/WebDavModuleTest.class', 'test'); - WebDavModuleTestHttpAuthInterface::_requestAuthenticationCalls('reset'); - /* Define OPTIONS request */ $this->_optionsRequest = implode("\r\n", array( 'OPTIONS ' . $urlGenerator->generateUrl( @@ -211,8 +199,6 @@ } function testHandleEventError() { - GalleryUtilities::removeRequestVariable('controller'); - GalleryUtilities::putRequestVariable('view', 'webdav.WebDav'); $this->_registerTestEventListener('Gallery::Error', $this->_module); $error = GalleryCoreApi::error(GALLERY_ERROR); @@ -224,29 +210,7 @@ } $this->assertEquals(array(array('suppressBody' => 1)), $results); - $this->assertEquals(0, - WebDavModuleTestHttpAuthInterface::_requestAuthenticationCalls('read'), - 'httpauth should only be called for ERROR_PERMISSION_DENIED'); } - - function testHandleEventErrorPermissionDenied() { - GalleryUtilities::removeRequestVariable('controller'); - GalleryUtilities::putRequestVariable('view', 'webdav.WebDav'); - $this->_registerTestEventListener('Gallery::Error', $this->_module); - - $error = GalleryCoreApi::error(ERROR_PERMISSION_DENIED); - $event = GalleryCoreApi::newEvent('Gallery::Error'); - $event->setData(array('error' => $error)); - list ($ret, $results) = GalleryCoreApi::postEvent($event); - if ($ret) { - return $this->failWithStatus($ret); - } - - $this->assertEquals(array(array('suppressBody' => 1)), $results); - $this->assertEquals(1, - WebDavModuleTestHttpAuthInterface::_requestAuthenticationCalls('read'), - 'httpauth has not been called'); - } } class WebDavModuleTestRewriteApi { @@ -325,22 +289,4 @@ return true; } } - -class WebDavModuleTestHttpAuthInterface /* extends HttpAuthInterface_1_0 */ { - function _requestAuthenticationCalls($mode=false) { - static $calls = 0; - if ($mode == 'reset') { - $calls = 0; - } else if ($mode == 'read') { - return $calls; - } else { - $calls++; - } - } - - function requestAuthentication() { - WebDavModuleTestHttpAuthInterface::_requestAuthenticationCalls(); - return null; - } -} ?> Modified: branches/DEV_2_3/gallery2/modules/webdav/test/phpunit/WebDavTest.class =================================================================== --- branches/DEV_2_3/gallery2/modules/webdav/test/phpunit/WebDavTest.class 2007-03-14 00:30:57 UTC (rev 15995) +++ branches/DEV_2_3/gallery2/modules/webdav/test/phpunit/WebDavTest.class 2007-03-14 01:46:09 UTC (rev 15996) @@ -61,7 +61,6 @@ /* Create test items */ list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId()); if ($ret) { - print $ret->getAsHtml(); return $this->failWithStatus($ret); } $this->_markForCleanup($this->_album); @@ -69,13 +68,11 @@ list ($ret, $this->_item) = $this->_createRandomDataItem($this->_album->getId(), 'test/file'); if ($ret) { - print $ret->getAsHtml(); return $this->failWithStatus($ret); } list ($ret, $this->_subAlbum) = $this->_createRandomAlbum($this->_album->getId()); if ($ret) { - print $ret->getAsHtml(); return $this->failWithStatus($ret); } @@ -86,7 +83,6 @@ $storage =& $gallery->getStorage(); $ret = $storage->checkPoint(); if ($ret) { - print $ret->getAsHtml(); return $this->failWithStatus($ret); } @@ -97,7 +93,6 @@ list ($ret, $this->_urlGenerator) = GalleryCoreApi::newFactoryInstance('GalleryUrlGenerator'); if ($ret) { - print $ret->getAsHtml(); return $this->failWithStatus($ret); } if (!isset($this->_urlGenerator)) { @@ -107,7 +102,6 @@ $ret = $this->_urlGenerator->init('http://example.com/gallery2/main.php'); if ($ret) { - print $ret->getAsHtml(); return $this->failWithStatus($ret); } $gallery->setUrlGenerator($this->_urlGenerator); @@ -405,13 +399,6 @@ $_SERVER['CONTENT_LENGTH'] = $fileSize; $_SERVER['CONTENT_TYPE'] = 'foo/bar'; - /* - * Regression: Ensure that HTTP_CONTENT_LENGTH and HTTP_CONTENT_TYPE are ignored. - * These variables are defined on IIS + mod_php. - */ - $_SERVER['HTTP_CONTENT_LENGTH'] = $_SERVER['CONTENT_LENGTH']; - $_SERVER['HTTP_CONTENT_TYPE'] = $_SERVER['CONTENT_TYPE']; - $this->_platform->_streams['php://input'] = $this->_platform->fopen($filePath, 'rb'); /* Perform the request and verify that we succeeded */ @@ -916,32 +903,19 @@ $this->assertEquals('', $output); } - /** - * Illegal path components will be silently legalized, but treated consistently - * so if you PUT an illegal path, a subsequent GET of the same path will refer to - * the same item. - */ - function testPutAndGetIllegalPathComponent() { + function testIllegalPathComponent() { /* Use valid inputs */ $_SERVER['REQUEST_METHOD'] = 'PUT'; - list ($ret, $albumPath) = $this->_album->fetchLogicalPath(); + list ($ret, $path) = $this->_album->fetchLogicalPath(); if ($ret) { return $this->failWithStatus($ret); } - $filePath = dirname(__FILE__) . '/../../../core/test/data/test1.gif'; - $fileSize = $this->_platform->filesize($filePath); - - $pathComponent = 'The!Quick$Brown#Fox.gif'; - $path = $albumPath . $pathComponent; + $pathComponent = 'The!Quick$Brown#Fox'; + $path .= $pathComponent; GalleryUtilities::putRequestVariable('path', $path); - $_SERVER['CONTENT_LENGTH'] = $fileSize; - $_SERVER['CONTENT_TYPE'] = 'foo/bar'; - - $this->_platform->_streams['php://input'] = $this->_platform->fopen($filePath, 'rb'); - /* Perform the request and verify that we succeeded */ ob_start(); list ($ret, $g2Data) = _GalleryMain(); @@ -950,12 +924,16 @@ } $output = ob_get_contents(); ob_end_clean(); - if ($ret) { + if ($ret && !($ret->getErrorCode() & ERROR_BAD_PATH)) { return $this->failWithStatus($ret); } - $this->assertEquals('HTTP/1.0 201 Created', $this->_headers['status']); + $this->assertEquals(GALLERY_ERROR | ERROR_BAD_PATH, $ret->getErrorCode()); + $this->assertEquals(array('status' => 'HTTP/1.0 403 Forbidden'), $this->_headers); + + $this->assertEquals('', $output); + $this->_headers = array(); /* Use valid inputs */ @@ -969,31 +947,15 @@ } $output = ob_get_contents(); ob_end_clean(); - if ($ret) { + if ($ret && !($ret->getErrorCode() & ERROR_BAD_PATH)) { return $this->failWithStatus($ret); } - $this->assertEquals(file_get_contents($filePath), $output); + $this->assertEquals(GALLERY_ERROR | ERROR_BAD_PATH, $ret->getErrorCode()); - /* Verify that the item has the right title, name, etc. */ - $legalPathComponent = $this->_platform->legalizePathComponent($pathComponent); - list ($ret, $newItemId) = - GalleryCoreApi::fetchItemIdByPath($albumPath . $legalPathComponent); - if ($ret) { - return $this->failWithStatus($ret); - } + $this->assertEquals(array('status' => 'HTTP/1.0 403 Forbidden'), $this->_headers); - list ($ret, $newItem) = GalleryCoreApi::loadEntitiesById($newItemId); - if ($ret) { - return $this->failWithStatus($ret); - } - - $this->assertEquals($pathComponent, $newItem->getTitle(), 'title'); - $this->assertEquals($legalPathComponent, $newItem->getPathComponent(), 'path component'); - $this->assertEquals('', $newItem->getSummary(), 'summary'); - $this->assertEquals('', $newItem->getDescription(), 'description'); - $this->assertEquals('image/gif', $newItem->getMimeType(), 'mime-type'); - $this->assertEquals($fileSize, $newItem->getSize(), 'size'); + $this->assertEquals('', $output); } function testIllegalDestination() { @@ -1062,7 +1024,6 @@ } $output = ob_get_contents(); ob_end_clean(); - if ($ret && !($ret->getErrorCode() & ERROR_BAD_PATH)) { return $this->failWithStatus($ret); } @@ -1106,17 +1067,10 @@ return $this->failWithStatus($ret); } - $filePath = dirname(__FILE__) . '/../../../core/test/data/test1.gif'; - $fileSize = $this->_platform->filesize($filePath); - $pathComponent = '.DS_Store'; $path .= $pathComponent; GalleryUtilities::putRequestVariable('path', $path); - $_SERVER['CONTENT_LENGTH'] = $fileSize; - $_SERVER['CONTENT_TYPE'] = 'foo/bar'; - $this->_platform->_streams['php://input'] = $this->_platform->fopen($filePath, 'rb'); - /* Perform the request and verify that we succeeded */ ob_start(); list ($ret, $g2Data) = _GalleryMain(); @@ -1129,53 +1083,34 @@ return $this->failWithStatus($ret); } - $this->assertEquals('HTTP/1.0 201 Created', $this->_headers['status']); - } + $this->assertEquals(GALLERY_ERROR | ERROR_BAD_PATH, $ret->getErrorCode()); - function testMkcolIllegalPathComponent() { - /* Use valid inputs */ - $_SERVER['REQUEST_METHOD'] = 'MKCOL'; + $this->assertEquals(array('status' => 'HTTP/1.0 403 Forbidden'), $this->_headers); - list ($ret, $albumPath) = $this->_album->fetchLogicalPath(); - if ($ret) { - return $this->failWithStatus($ret); - } + $this->assertEquals('', $output); - $pathComponent = 'The!Quick$Brown#Fox'; - $path = $albumPath . $pathComponent; - GalleryUtilities::putRequestVariable('path', $path); + $this->_headers = array(); + /* Use valid inputs */ + $_SERVER['REQUEST_METHOD'] = 'GET'; + /* Perform the request and verify that we succeeded */ ob_start(); list ($ret, $g2Data) = _GalleryMain(); + if ($ret) { + _GalleryMain_errorHandler($ret, $g2Data); + } $output = ob_get_contents(); ob_end_clean(); - if ($ret) { + if ($ret && !($ret->getErrorCode() & ERROR_BAD_PATH)) { return $this->failWithStatus($ret); } - $this->assertEquals(array('status' => 'HTTP/1.0 201 Created'), - $this->_headers); + $this->assertEquals(GALLERY_ERROR | ERROR_BAD_PATH, $ret->getErrorCode()); - $this->assertEquals('', $output); + $this->assertEquals(array('status' => 'HTTP/1.0 403 Forbidden'), $this->_headers); - $legalPathComponent = $this->_platform->legalizePathComponent($pathComponent); - list ($ret, $newAlbumId) = - GalleryCoreApi::fetchItemIdByPath($albumPath . $legalPathComponent); - if ($ret) { - return $this->failWithStatus($ret); - } - - list ($ret, $newAlbum) = GalleryCoreApi::loadEntitiesById($newAlbumId); - if ($ret) { - return $this->failWithStatus($ret); - } - - $this->assertEquals($pathComponent, $newAlbum->getTitle(), 'title'); - $this->assertEquals($legalPathComponent, $newAlbum->getPathComponent(), 'path component'); - $this->assertEquals('', $newAlbum->getSummary(), 'summary'); - $this->assertEquals('', $newAlbum->getDescription(), 'description'); - $this->assertEquals('', $newAlbum->getKeywords(), 'keywords'); + $this->assertEquals('', $output); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |