Skip to content

Commit

Permalink
fix: bring code to 2023 🤣
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 committed Nov 9, 2023
1 parent 9309a8d commit 4a9d4dc
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 55 deletions.
29 changes: 14 additions & 15 deletions lib/DAV/Locks/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<opaquelocktoken:', '', $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(['<opaquelocktoken:', '>'], '', $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.
Expand Down
78 changes: 38 additions & 40 deletions tests/Sabre/DAV/Locks/MSWord2016Test.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
<?php declare (strict_types=1);
<?php

declare(strict_types=1);

namespace Sabre\DAV\Locks;

use PHPUnit\Framework\TestCase;
use Sabre\DAV;
use Sabre\HTTP;

require_once 'Sabre/HTTP/ResponseMock.php';
require_once 'Sabre/TestUtil.php';

class MSWord2016 extends \PHPUnit_Framework_TestCase {

function tearDown() {

\Sabre\TestUtil::clearTempDir();

use Sabre\HTTP\Request;
use Sabre\TestUtil;

class MSWord2016Test extends TestCase
{
public function tearDown(): void
{
TestUtil::clearTempDir();
}

function testLockEtc() {

mkdir(SABRE_TEMPDIR . '/mstest');
$tree = new DAV\FS\Directory(SABRE_TEMPDIR . '/mstest');
public function testLockEtc(): void
{
mkdir(SABRE_TEMPDIR.'/mstest');
$tree = new DAV\FS\Directory(SABRE_TEMPDIR.'/mstest');

$server = new DAV\Server($tree);
$server->debugExceptions = true;
$locksBackend = new Backend\File(SABRE_TEMPDIR . '/locksdb');
$locksBackend = new Backend\File(SABRE_TEMPDIR.'/locksdb');
$locksPlugin = new Plugin($locksBackend);
$server->addPlugin($locksPlugin);

Expand All @@ -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);
Expand All @@ -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('<D:lockinfo xmlns:D="DAV:">
Expand All @@ -82,15 +82,15 @@ function getLockRequest() {
</D:lockinfo>');

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('<D:lockinfo xmlns:D="DAV:">
Expand All @@ -106,19 +106,17 @@ function getLockRequest2() {
</D:lockinfo>');

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;
}

}

0 comments on commit 4a9d4dc

Please sign in to comment.