From 8107e5c6ae9a7f9aca51d8dc8ca6ba0ac19b78f2 Mon Sep 17 00:00:00 2001 From: Jurgen de Jonge Date: Wed, 12 Jul 2017 14:24:03 +0200 Subject: [PATCH 1/3] Add check for Lock-Token in request header. Only check for Lock-Token is there are $mustLocks left. --- lib/DAV/Locks/Plugin.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/DAV/Locks/Plugin.php b/lib/DAV/Locks/Plugin.php index fd67aa2f0b..4e12f1f3bf 100644 --- a/lib/DAV/Locks/Plugin.php +++ b/lib/DAV/Locks/Plugin.php @@ -531,6 +531,21 @@ function validateTokens(RequestInterface $request, &$conditions) { } } + + //what if Lock-token is not in If header, but in Lock-Token header? + $lockToken = $request->getHeader('Lock-Token'); + + if($mustLocks && $lockToken) { + $lockToken = str_replace('', '', $lockToken); + foreach ($mustLocks as $jj => $mustLock) { + if ($mustLock->token == $lockToken) { + // We have a match! + // Removing this one from mustlocks + unset($mustLocks[$jj]); + } + } + } // If there's any locks left in the 'mustLocks' array, it means that // the resource was locked and we must block it. From 12217a99eec0619e33d6a7b3202412df10024744 Mon Sep 17 00:00:00 2001 From: Jurgen de Jonge Date: Wed, 12 Jul 2017 17:17:23 +0200 Subject: [PATCH 2/3] add Word2016 unit test. --- tests/Sabre/DAV/Locks/MSWord2016.php | 124 +++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 tests/Sabre/DAV/Locks/MSWord2016.php diff --git a/tests/Sabre/DAV/Locks/MSWord2016.php b/tests/Sabre/DAV/Locks/MSWord2016.php new file mode 100644 index 0000000000..d43c94219d --- /dev/null +++ b/tests/Sabre/DAV/Locks/MSWord2016.php @@ -0,0 +1,124 @@ +debugExceptions = true; + $locksBackend = new Backend\File(SABRE_TEMPDIR . '/locksdb'); + $locksPlugin = new Plugin($locksBackend); + $server->addPlugin($locksPlugin); + + $response1 = new HTTP\ResponseMock(); + + $server->httpRequest = $this->getLockRequest(); + $server->httpResponse = $response1; + $server->sapi = new HTTP\SapiMock(); + $server->exec(); + + $this->assertEquals(201, $server->httpResponse->getStatus(), 'Full response body:' . $response1->getBodyAsString()); + $this->assertTrue(!!$server->httpResponse->getHeaders('Lock-Token')); + $lockToken = $server->httpResponse->getHeader('Lock-Token'); + + //sleep(10); + + $response2 = new HTTP\ResponseMock(); + + $server->httpRequest = $this->getLockRequest2(); + $server->httpResponse = $response2; + $server->exec(); + + $this->assertEquals(201, $server->httpResponse->status); + $this->assertTrue(!!$server->httpResponse->getHeaders('Lock-Token')); + + //sleep(10); + + $response3 = new HTTP\ResponseMock(); + $server->httpRequest = $this->getPutRequest($lockToken); + $server->httpResponse = $response3; + $server->exec(); + + $this->assertEquals(204, $server->httpResponse->status); + + } + + function getLockRequest() { + + $request = HTTP\Sapi::createFromServerArray([ + 'REQUEST_METHOD' => 'LOCK', + 'HTTP_CONTENT_TYPE' => 'application/xml', + 'HTTP_TIMEOUT' => 'Second-3600', + 'REQUEST_URI' => '/Nouveau%20Microsoft%20Office%20Excel%20Worksheet.xlsx', + ]); + + $request->setBody(' + + + + + + + + PC-Vista\User + +'); + + return $request; + + } + function getLockRequest2() { + + $request = HTTP\Sapi::createFromServerArray([ + 'REQUEST_METHOD' => 'LOCK', + 'HTTP_CONTENT_TYPE' => 'application/xml', + 'HTTP_TIMEOUT' => 'Second-3600', + 'REQUEST_URI' => '/~$Nouveau%20Microsoft%20Office%20Excel%20Worksheet.xlsx', + ]); + + $request->setBody(' + + + + + + + + PC-Vista\User + +'); + + return $request; + + } + + function getPutRequest($lockToken) { + + $request = HTTP\Sapi::createFromServerArray([ + 'REQUEST_METHOD' => 'PUT', + 'REQUEST_URI' => '/Nouveau%20Microsoft%20Office%20Excel%20Worksheet.xlsx', + 'HTTP_LOCK_TOKEN' => $lockToken, + ]); + $request->setBody('FAKE BODY'); + return $request; + + } + +} From 02d240ec46a263c431c0a214bb74a9bca7c59a53 Mon Sep 17 00:00:00 2001 From: Jurgen de Jonge Date: Wed, 12 Jul 2017 17:40:31 +0200 Subject: [PATCH 3/3] Updated test filename --- tests/Sabre/DAV/Locks/{MSWord2016.php => MSWord2016Test.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/Sabre/DAV/Locks/{MSWord2016.php => MSWord2016Test.php} (100%) diff --git a/tests/Sabre/DAV/Locks/MSWord2016.php b/tests/Sabre/DAV/Locks/MSWord2016Test.php similarity index 100% rename from tests/Sabre/DAV/Locks/MSWord2016.php rename to tests/Sabre/DAV/Locks/MSWord2016Test.php