Skip to content

Commit

Permalink
Merge pull request #1273 from sabre-io/bugfix/add-missing-context-uri…
Browse files Browse the repository at this point in the history
…-in-lock-responses

The baseUri was missing when generating the lock responses. This was …
  • Loading branch information
DeepDiver1975 authored May 29, 2020
2 parents 30e42f4 + 3a5d87d commit 22dbd3f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/DAV/Locks/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ protected function generateLockResponse(LockInfo $lockInfo)
{
return $this->server->xml->write('{DAV:}prop', [
'{DAV:}lockdiscovery' => new DAV\Xml\Property\LockDiscovery([$lockInfo]),
]);
], $this->server->getBaseUri());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Sabre/DAV/AbstractServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class AbstractServer extends \PHPUnit\Framework\TestCase
protected $response;
protected $request;
/**
* @var Sabre\DAV\Server
* @var \Sabre\DAV\Server
*/
protected $server;
protected $tempDir = SABRE_TEMPDIR;
Expand Down
26 changes: 26 additions & 0 deletions tests/Sabre/DAV/Locks/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,32 @@ public function testLock()
$this->assertEquals($this->response->getHeader('Lock-Token'), '<'.(string) $token[0].'>', 'Token in response body didn\'t match token in response header.');
}

public function testLockWithContext()
{
$request = new HTTP\Request('LOCK', '/baseuri/test.txt');
$request->setBody('<?xml version="1.0"?>
<D:lockinfo xmlns:D="DAV:">
<D:lockscope><D:exclusive/></D:lockscope>
<D:locktype><D:write/></D:locktype>
<D:owner>
<D:href>http://example.org/~ejw/contact.html</D:href>
</D:owner>
</D:lockinfo>');

$this->server->setBaseUri('baseuri');
$this->server->httpRequest = $request;
$this->server->exec();

$this->assertEquals(200, $this->response->status, 'Got an incorrect status back. Response body: '.$this->response->getBodyAsString());

$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", 'xmlns\\1="urn:DAV"', $this->response->getBodyAsString());
$xml = simplexml_load_string($body);
$xml->registerXPathNamespace('d', 'urn:DAV');

$lockRoot = $xml->xpath('/d:prop/d:lockdiscovery/d:activelock/d:lockroot/d:href');
$this->assertEquals('baseuri/test.txt', (string) $lockRoot[0]);
}

/**
* @depends testLock
*/
Expand Down

0 comments on commit 22dbd3f

Please sign in to comment.