From 05e11ce17a23937f38593508f7f6f8feeef89213 Mon Sep 17 00:00:00 2001 From: Ilja Neumann Date: Tue, 14 Feb 2017 15:13:51 +0100 Subject: [PATCH] #26655 Webdav returns only one checksum (SHA1) --- apps/dav/lib/Connector/Sabre/File.php | 26 ++++++++++++++++--- apps/dav/lib/Connector/Sabre/FilesPlugin.php | 4 +-- .../Files/Storage/Wrapper/Checksum.php | 5 ---- tests/integration/features/checksums.feature | 16 ++++++------ .../features/webdav-related.feature | 2 +- 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index 3140d127c526..86f84a4a87de 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -600,12 +600,30 @@ private function convertToSabreException(\Exception $e) { throw new \Sabre\DAV\Exception($e->getMessage(), 0, $e); } + /** - * Get the checksum for this file - * + * Set $algo to get a specific checksum, leave null to get all checksums + * (space seperated) + * @param null $algo * @return string */ - public function getChecksum() { - return $this->info->getChecksum(); + public function getChecksum($algo = null) { + $allChecksums = $this->info->getChecksum(); + + if (!$algo) { + return $allChecksums; + } + + $checksums = explode(' ', $allChecksums); + $algo = strtoupper($algo); + + foreach ($checksums as $checksum) { + // starts with $algo + if (substr($checksum, 0, strlen($algo)) === $algo) { + return $checksum; + } + } + + return ''; } } diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index 6d9d65ce71bc..cbe7406cc2ff 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -252,7 +252,7 @@ function httpGet(RequestInterface $request, ResponseInterface $response) { if ($node instanceof \OCA\DAV\Connector\Sabre\File) { //Add OC-Checksum header /** @var $node File */ - $checksum = $node->getChecksum(); + $checksum = $node->getChecksum('sha1'); if ($checksum !== null && $checksum !== '') { $response->addHeader('OC-Checksum', $checksum); } @@ -340,7 +340,7 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) }); $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) { - $checksum = $node->getChecksum(); + $checksum = $node->getChecksum('SHA1'); if ($checksum === NULL || $checksum === '') { return null; } diff --git a/lib/private/Files/Storage/Wrapper/Checksum.php b/lib/private/Files/Storage/Wrapper/Checksum.php index 3b3c5ffa6e07..6aaf14b34fcd 100644 --- a/lib/private/Files/Storage/Wrapper/Checksum.php +++ b/lib/private/Files/Storage/Wrapper/Checksum.php @@ -87,15 +87,10 @@ public function getMetaData($path) { $parentMetaData = $this->getWrapperStorage()->getMetaData($path); $parentMetaData['checksum'] = rtrim($checksumString); - // Need to investigate more - - if (!isset($parentMetaData['mimetype'])) { $parentMetaData['mimetype'] = 'application/octet-stream'; } - - return $parentMetaData; } } \ No newline at end of file diff --git a/tests/integration/features/checksums.feature b/tests/integration/features/checksums.feature index 303fd43bba16..1a0739df7ee0 100644 --- a/tests/integration/features/checksums.feature +++ b/tests/integration/features/checksums.feature @@ -9,41 +9,41 @@ Feature: checksums Given user "user0" exists And user "user0" uploads file "data/textfile.txt" to "/myChecksumFile.txt" with checksum "MD5:d70b40f177b14b470d1756a3c12b963a" When user "user0" request the checksum of "/myChecksumFile.txt" via propfind - Then The webdav checksum should match "SHA1:3ee962b839762adb0ad8ba6023a4690be478de6f MD5:d70b40f177b14b470d1756a3c12b963a ADLER32:8ae90960" + Then The webdav checksum should match "SHA1:3ee962b839762adb0ad8ba6023a4690be478de6f" Scenario: Uploading a file with checksum should return the checksum in the download header Given user "user0" exists And user "user0" uploads file "data/textfile.txt" to "/myChecksumFile.txt" with checksum "MD5:d70b40f177b14b470d1756a3c12b963a" When user "user0" downloads the file "/myChecksumFile.txt" - Then The header checksum should match "SHA1:3ee962b839762adb0ad8ba6023a4690be478de6f MD5:d70b40f177b14b470d1756a3c12b963a ADLER32:8ae90960" + Then The header checksum should match "SHA1:3ee962b839762adb0ad8ba6023a4690be478de6f" Scenario: Moving a file with checksum should return the checksum in the propfind Given user "user0" exists And user "user0" uploads file "data/textfile.txt" to "/myChecksumFile.txt" with checksum "MD5:d70b40f177b14b470d1756a3c12b963a" When User "user0" moved file "/myChecksumFile.txt" to "/myMovedChecksumFile.txt" And user "user0" request the checksum of "/myMovedChecksumFile.txt" via propfind - Then The webdav checksum should match "SHA1:3ee962b839762adb0ad8ba6023a4690be478de6f MD5:d70b40f177b14b470d1756a3c12b963a ADLER32:8ae90960" + Then The webdav checksum should match "SHA1:3ee962b839762adb0ad8ba6023a4690be478de6f" Scenario: Moving file with checksum should return the checksum in the download header Given user "user0" exists And user "user0" uploads file "data/textfile.txt" to "/myChecksumFile.txt" with checksum "MD5:d70b40f177b14b470d1756a3c12b963a" When User "user0" moved file "/myChecksumFile.txt" to "/myMovedChecksumFile.txt" And user "user0" downloads the file "/myMovedChecksumFile.txt" - Then The header checksum should match "SHA1:3ee962b839762adb0ad8ba6023a4690be478de6f MD5:d70b40f177b14b470d1756a3c12b963a ADLER32:8ae90960" + Then The header checksum should match "SHA1:3ee962b839762adb0ad8ba6023a4690be478de6f" Scenario: Copying a file with checksum should return the checksum in the propfind Given user "user0" exists And user "user0" uploads file "data/textfile.txt" to "/myChecksumFile.txt" with checksum "MD5:d70b40f177b14b470d1756a3c12b963a" When User "user0" copied file "/myChecksumFile.txt" to "/myChecksumFileCopy.txt" And user "user0" request the checksum of "/myChecksumFileCopy.txt" via propfind - Then The webdav checksum should match "SHA1:3ee962b839762adb0ad8ba6023a4690be478de6f MD5:d70b40f177b14b470d1756a3c12b963a ADLER32:8ae90960" + Then The webdav checksum should match "SHA1:3ee962b839762adb0ad8ba6023a4690be478de6f" Scenario: Copying file with checksum should return the checksum in the download header Given user "user0" exists And user "user0" uploads file "data/textfile.txt" to "/myChecksumFile.txt" with checksum "MD5:d70b40f177b14b470d1756a3c12b963a" When User "user0" copied file "/myChecksumFile.txt" to "/myChecksumFileCopy.txt" And user "user0" downloads the file "/myChecksumFileCopy.txt" - Then The header checksum should match "SHA1:3ee962b839762adb0ad8ba6023a4690be478de6f MD5:d70b40f177b14b470d1756a3c12b963a ADLER32:8ae90960" + Then The header checksum should match "SHA1:3ee962b839762adb0ad8ba6023a4690be478de6f" Scenario: Uploading a chunked file with checksum should return the checksum in the propfind Given user "user0" exists @@ -51,7 +51,7 @@ Feature: checksums And user "user0" uploads chunk file "2" of "3" with "BBBBB" to "/myChecksumFile.txt" with checksum "MD5:45a72715acdd5019c5be30bdbb75233e" And user "user0" uploads chunk file "3" of "3" with "CCCCC" to "/myChecksumFile.txt" with checksum "MD5:45a72715acdd5019c5be30bdbb75233e" When user "user0" request the checksum of "/myChecksumFile.txt" via propfind - Then The webdav checksum should match "SHA1:acfa6b1565f9710d4d497c6035d5c069bd35a8e8 MD5:45a72715acdd5019c5be30bdbb75233e ADLER32:1ecd03df" + Then The webdav checksum should match "SHA1:acfa6b1565f9710d4d497c6035d5c069bd35a8e8" Scenario: Uploading a chunked file with checksum should return the checksum in the download header Given user "user0" exists @@ -59,4 +59,4 @@ Feature: checksums And user "user0" uploads chunk file "2" of "3" with "BBBBB" to "/myChecksumFile.txt" with checksum "MD5:45a72715acdd5019c5be30bdbb75233e" And user "user0" uploads chunk file "3" of "3" with "CCCCC" to "/myChecksumFile.txt" with checksum "MD5:45a72715acdd5019c5be30bdbb75233e" When user "user0" downloads the file "/myChecksumFile.txt" - Then The header checksum should match "SHA1:acfa6b1565f9710d4d497c6035d5c069bd35a8e8 MD5:45a72715acdd5019c5be30bdbb75233e ADLER32:1ecd03df" + Then The header checksum should match "SHA1:acfa6b1565f9710d4d497c6035d5c069bd35a8e8" diff --git a/tests/integration/features/webdav-related.feature b/tests/integration/features/webdav-related.feature index 2d7ba1fcd0aa..deb998fb06e7 100644 --- a/tests/integration/features/webdav-related.feature +++ b/tests/integration/features/webdav-related.feature @@ -425,7 +425,7 @@ Feature: webdav-related And user "user0" uploads file with checksum "SHA1:ce5582148c6f0c1282335b87df5ed4be4b781399" and content "Some Text" to "/chksumtst.txt" When Downloading file "/chksumtst.txt" as "user0" Then The following headers should be set - | OC-Checksum | SHA1:ce5582148c6f0c1282335b87df5ed4be4b781399 MD5:56e57920c3c8c727bfe7a5288cdf61c4 ADLER32:1048035a | + | OC-Checksum | SHA1:ce5582148c6f0c1282335b87df5ed4be4b781399 | Scenario: A disabled user cannot use webdav Given user "userToBeDisabled" exists