From 4a9d4dc2c0c02e342a9404f438ca413dc203ce36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= <1005065+DeepDiver1975@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:14:12 +0100 Subject: [PATCH] fix: bring code to 2023 :rofl: --- lib/DAV/Locks/Plugin.php | 29 +++++---- tests/Sabre/DAV/Locks/MSWord2016Test.php | 78 ++++++++++++------------ 2 files changed, 52 insertions(+), 55 deletions(-) diff --git a/lib/DAV/Locks/Plugin.php b/lib/DAV/Locks/Plugin.php index e2d0b0cc1b..747d124da9 100644 --- a/lib/DAV/Locks/Plugin.php +++ b/lib/DAV/Locks/Plugin.php @@ -497,21 +497,20 @@ public function validateTokens(RequestInterface $request, &$conditions) // really unknown. } } - - //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]); - } - } - } + + //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. diff --git a/tests/Sabre/DAV/Locks/MSWord2016Test.php b/tests/Sabre/DAV/Locks/MSWord2016Test.php index d43c94219d..9bb3c09fb6 100644 --- a/tests/Sabre/DAV/Locks/MSWord2016Test.php +++ b/tests/Sabre/DAV/Locks/MSWord2016Test.php @@ -1,29 +1,30 @@ -debugExceptions = true; - $locksBackend = new Backend\File(SABRE_TEMPDIR . '/locksdb'); + $locksBackend = new Backend\File(SABRE_TEMPDIR.'/locksdb'); $locksPlugin = new Plugin($locksBackend); $server->addPlugin($locksPlugin); @@ -32,10 +33,10 @@ function testLockEtc() { $server->httpRequest = $this->getLockRequest(); $server->httpResponse = $response1; $server->sapi = new HTTP\SapiMock(); - $server->exec(); + $server->start(); - $this->assertEquals(201, $server->httpResponse->getStatus(), 'Full response body:' . $response1->getBodyAsString()); - $this->assertTrue(!!$server->httpResponse->getHeaders('Lock-Token')); + $this->assertEquals(201, $server->httpResponse->getStatus(), 'Full response body:'.$response1->getBodyAsString()); + $this->assertTrue((bool) $server->httpResponse->getHeader('Lock-Token')); $lockToken = $server->httpResponse->getHeader('Lock-Token'); //sleep(10); @@ -44,29 +45,28 @@ function testLockEtc() { $server->httpRequest = $this->getLockRequest2(); $server->httpResponse = $response2; - $server->exec(); + $server->start(); $this->assertEquals(201, $server->httpResponse->status); - $this->assertTrue(!!$server->httpResponse->getHeaders('Lock-Token')); + $this->assertTrue((bool) $server->httpResponse->getHeader('Lock-Token')); //sleep(10); $response3 = new HTTP\ResponseMock(); $server->httpRequest = $this->getPutRequest($lockToken); $server->httpResponse = $response3; - $server->exec(); + $server->start(); $this->assertEquals(204, $server->httpResponse->status); - } - function getLockRequest() { - + public function getLockRequest(): Request + { $request = HTTP\Sapi::createFromServerArray([ - 'REQUEST_METHOD' => 'LOCK', + 'REQUEST_METHOD' => 'LOCK', 'HTTP_CONTENT_TYPE' => 'application/xml', - 'HTTP_TIMEOUT' => 'Second-3600', - 'REQUEST_URI' => '/Nouveau%20Microsoft%20Office%20Excel%20Worksheet.xlsx', + 'HTTP_TIMEOUT' => 'Second-3600', + 'REQUEST_URI' => '/Nouveau%20Microsoft%20Office%20Excel%20Worksheet.xlsx', ]); $request->setBody(' @@ -82,15 +82,15 @@ function getLockRequest() { '); return $request; - } - function getLockRequest2() { + public function getLockRequest2(): Request + { $request = HTTP\Sapi::createFromServerArray([ - 'REQUEST_METHOD' => 'LOCK', + 'REQUEST_METHOD' => 'LOCK', 'HTTP_CONTENT_TYPE' => 'application/xml', - 'HTTP_TIMEOUT' => 'Second-3600', - 'REQUEST_URI' => '/~$Nouveau%20Microsoft%20Office%20Excel%20Worksheet.xlsx', + 'HTTP_TIMEOUT' => 'Second-3600', + 'REQUEST_URI' => '/~$Nouveau%20Microsoft%20Office%20Excel%20Worksheet.xlsx', ]); $request->setBody(' @@ -106,19 +106,17 @@ function getLockRequest2() { '); return $request; - } - function getPutRequest($lockToken) { - + public function getPutRequest($lockToken): Request + { $request = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'PUT', - 'REQUEST_URI' => '/Nouveau%20Microsoft%20Office%20Excel%20Worksheet.xlsx', - 'HTTP_LOCK_TOKEN' => $lockToken, + 'REQUEST_URI' => '/Nouveau%20Microsoft%20Office%20Excel%20Worksheet.xlsx', + 'HTTP_LOCK_TOKEN' => $lockToken, ]); $request->setBody('FAKE BODY'); - return $request; + return $request; } - }