diff options
author | Hilmar R <u02@u29lx193> | 2021-02-28 21:06:16 +0100 |
---|---|---|
committer | Hilmar R <u02@u29lx193> | 2021-03-01 18:48:11 +0100 |
commit | c26dede97f626b52b7bf8962ed55d1dbda86abe8 (patch) | |
tree | 3c8c9bc97aa09f7ce9afe9bf467cf87bbf2c7d0b /vendor/sabre/dav/tests/Sabre/DAV/Locks | |
parent | ea3390d626f85b7293a750958bfd1b5460958365 (diff) | |
download | volse-hubzilla-c26dede97f626b52b7bf8962ed55d1dbda86abe8.tar.gz volse-hubzilla-c26dede97f626b52b7bf8962ed55d1dbda86abe8.tar.bz2 volse-hubzilla-c26dede97f626b52b7bf8962ed55d1dbda86abe8.zip |
get dev
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/DAV/Locks')
6 files changed, 0 insertions, 1245 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/AbstractTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/AbstractTest.php deleted file mode 100644 index d1cd1799c..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/AbstractTest.php +++ /dev/null @@ -1,189 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Sabre\DAV\Locks\Backend; - -use Sabre\DAV; - -abstract class AbstractTest extends \PHPUnit\Framework\TestCase -{ - /** - * @abstract - * - * @return AbstractBackend - */ - abstract public function getBackend(); - - public function testSetup() - { - $backend = $this->getBackend(); - $this->assertInstanceOf('Sabre\\DAV\\Locks\\Backend\\AbstractBackend', $backend); - } - - /** - * @depends testSetup - */ - public function testGetLocks() - { - $backend = $this->getBackend(); - - $lock = new DAV\Locks\LockInfo(); - $lock->owner = 'Sinterklaas'; - $lock->timeout = 60; - $lock->created = time(); - $lock->token = 'MY-UNIQUE-TOKEN'; - $lock->uri = 'someuri'; - - $this->assertTrue($backend->lock('someuri', $lock)); - - $locks = $backend->getLocks('someuri', false); - - $this->assertEquals(1, count($locks)); - $this->assertEquals('Sinterklaas', $locks[0]->owner); - $this->assertEquals('someuri', $locks[0]->uri); - } - - /** - * @depends testGetLocks - */ - public function testGetLocksParent() - { - $backend = $this->getBackend(); - - $lock = new DAV\Locks\LockInfo(); - $lock->owner = 'Sinterklaas'; - $lock->timeout = 60; - $lock->created = time(); - $lock->depth = DAV\Server::DEPTH_INFINITY; - $lock->token = 'MY-UNIQUE-TOKEN'; - - $this->assertTrue($backend->lock('someuri', $lock)); - - $locks = $backend->getLocks('someuri/child', false); - - $this->assertEquals(1, count($locks)); - $this->assertEquals('Sinterklaas', $locks[0]->owner); - $this->assertEquals('someuri', $locks[0]->uri); - } - - /** - * @depends testGetLocks - */ - public function testGetLocksParentDepth0() - { - $backend = $this->getBackend(); - - $lock = new DAV\Locks\LockInfo(); - $lock->owner = 'Sinterklaas'; - $lock->timeout = 60; - $lock->created = time(); - $lock->depth = 0; - $lock->token = 'MY-UNIQUE-TOKEN'; - - $this->assertTrue($backend->lock('someuri', $lock)); - - $locks = $backend->getLocks('someuri/child', false); - - $this->assertEquals(0, count($locks)); - } - - public function testGetLocksChildren() - { - $backend = $this->getBackend(); - - $lock = new DAV\Locks\LockInfo(); - $lock->owner = 'Sinterklaas'; - $lock->timeout = 60; - $lock->created = time(); - $lock->depth = 0; - $lock->token = 'MY-UNIQUE-TOKEN'; - - $this->assertTrue($backend->lock('someuri/child', $lock)); - - $locks = $backend->getLocks('someuri/child', false); - $this->assertEquals(1, count($locks)); - - $locks = $backend->getLocks('someuri', false); - $this->assertEquals(0, count($locks)); - - $locks = $backend->getLocks('someuri', true); - $this->assertEquals(1, count($locks)); - } - - /** - * @depends testGetLocks - */ - public function testLockRefresh() - { - $backend = $this->getBackend(); - - $lock = new DAV\Locks\LockInfo(); - $lock->owner = 'Sinterklaas'; - $lock->timeout = 60; - $lock->created = time(); - $lock->token = 'MY-UNIQUE-TOKEN'; - - $this->assertTrue($backend->lock('someuri', $lock)); - /* Second time */ - - $lock->owner = 'Santa Clause'; - $this->assertTrue($backend->lock('someuri', $lock)); - - $locks = $backend->getLocks('someuri', false); - - $this->assertEquals(1, count($locks)); - - $this->assertEquals('Santa Clause', $locks[0]->owner); - $this->assertEquals('someuri', $locks[0]->uri); - } - - /** - * @depends testGetLocks - */ - public function testUnlock() - { - $backend = $this->getBackend(); - - $lock = new DAV\Locks\LockInfo(); - $lock->owner = 'Sinterklaas'; - $lock->timeout = 60; - $lock->created = time(); - $lock->token = 'MY-UNIQUE-TOKEN'; - - $this->assertTrue($backend->lock('someuri', $lock)); - - $locks = $backend->getLocks('someuri', false); - $this->assertEquals(1, count($locks)); - - $this->assertTrue($backend->unlock('someuri', $lock)); - - $locks = $backend->getLocks('someuri', false); - $this->assertEquals(0, count($locks)); - } - - /** - * @depends testUnlock - */ - public function testUnlockUnknownToken() - { - $backend = $this->getBackend(); - - $lock = new DAV\Locks\LockInfo(); - $lock->owner = 'Sinterklaas'; - $lock->timeout = 60; - $lock->created = time(); - $lock->token = 'MY-UNIQUE-TOKEN'; - - $this->assertTrue($backend->lock('someuri', $lock)); - - $locks = $backend->getLocks('someuri', false); - $this->assertEquals(1, count($locks)); - - $lock->token = 'SOME-OTHER-TOKEN'; - $this->assertFalse($backend->unlock('someuri', $lock)); - - $locks = $backend->getLocks('someuri', false); - $this->assertEquals(1, count($locks)); - } -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FileTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FileTest.php deleted file mode 100644 index 57a3255c7..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FileTest.php +++ /dev/null @@ -1,21 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Sabre\DAV\Locks\Backend; - -class FileTest extends AbstractTest -{ - public function getBackend() - { - \Sabre\TestUtil::clearTempDir(); - $backend = new File(SABRE_TEMPDIR.'/lockdb'); - - return $backend; - } - - public function teardown(): void - { - \Sabre\TestUtil::clearTempDir(); - } -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/PDOMySQLTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/PDOMySQLTest.php deleted file mode 100644 index 86ffc0bb3..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/PDOMySQLTest.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Sabre\DAV\Locks\Backend; - -class PDOMySQLTest extends PDOTest -{ - public $driver = 'mysql'; -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/PDOTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/PDOTest.php deleted file mode 100644 index f5ed98f50..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/PDOTest.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Sabre\DAV\Locks\Backend; - -abstract class PDOTest extends AbstractTest -{ - use \Sabre\DAV\DbTestHelperTrait; - - public function getBackend() - { - $this->dropTables('locks'); - $this->createSchema('locks'); - - $pdo = $this->getPDO(); - - return new PDO($pdo); - } -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/MSWordTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/MSWordTest.php deleted file mode 100644 index 02c3d39ba..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Locks/MSWordTest.php +++ /dev/null @@ -1,119 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Sabre\DAV\Locks; - -use Sabre\DAV; -use Sabre\HTTP; - -class MSWordTest extends \PHPUnit\Framework\TestCase -{ - public function teardown(): void - { - \Sabre\TestUtil::clearTempDir(); - } - - public function testLockEtc() - { - 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'); - $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((bool) $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((bool) $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); - } - - public 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('<D:lockinfo xmlns:D="DAV:"> - <D:lockscope> - <D:exclusive /> - </D:lockscope> - <D:locktype> - <D:write /> - </D:locktype> - <D:owner> - <D:href>PC-Vista\User</D:href> - </D:owner> -</D:lockinfo>'); - - return $request; - } - - public 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('<D:lockinfo xmlns:D="DAV:"> - <D:lockscope> - <D:exclusive /> - </D:lockscope> - <D:locktype> - <D:write /> - </D:locktype> - <D:owner> - <D:href>PC-Vista\User</D:href> - </D:owner> -</D:lockinfo>'); - - return $request; - } - - public function getPutRequest($lockToken) - { - $request = HTTP\Sapi::createFromServerArray([ - 'REQUEST_METHOD' => 'PUT', - 'REQUEST_URI' => '/Nouveau%20Microsoft%20Office%20Excel%20Worksheet.xlsx', - 'HTTP_IF' => 'If: ('.$lockToken.')', - ]); - $request->setBody('FAKE BODY'); - - return $request; - } -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php deleted file mode 100644 index 9279afb5a..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php +++ /dev/null @@ -1,886 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Sabre\DAV\Locks; - -use Sabre\DAV; -use Sabre\HTTP; - -class PluginTest extends DAV\AbstractServer -{ - /** - * @var Plugin - */ - protected $locksPlugin; - - public function setup(): void - { - parent::setUp(); - $locksBackend = new Backend\File(SABRE_TEMPDIR.'/locksdb'); - $locksPlugin = new Plugin($locksBackend); - $this->server->addPlugin($locksPlugin); - $this->locksPlugin = $locksPlugin; - } - - public function testGetInfo() - { - $this->assertArrayHasKey( - 'name', - $this->locksPlugin->getPluginInfo() - ); - } - - public function testGetFeatures() - { - $this->assertEquals([2], $this->locksPlugin->getFeatures()); - } - - public function testGetHTTPMethods() - { - $this->assertEquals(['LOCK', 'UNLOCK'], $this->locksPlugin->getHTTPMethods('')); - } - - public function testLockNoBody() - { - $request = new HTTP\Request('LOCK', '/test.txt'); - $this->server->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals([ - 'X-Sabre-Version' => [DAV\Version::VERSION], - 'Content-Type' => ['application/xml; charset=utf-8'], - ], - $this->response->getHeaders() - ); - - $this->assertEquals(400, $this->response->status); - } - - public function testLock() - { - $request = new HTTP\Request('LOCK', '/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->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); - - $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'); - - $elements = [ - '/d:prop', - '/d:prop/d:lockdiscovery', - '/d:prop/d:lockdiscovery/d:activelock', - '/d:prop/d:lockdiscovery/d:activelock/d:locktype', - '/d:prop/d:lockdiscovery/d:activelock/d:lockroot', - '/d:prop/d:lockdiscovery/d:activelock/d:lockroot/d:href', - '/d:prop/d:lockdiscovery/d:activelock/d:locktype/d:write', - '/d:prop/d:lockdiscovery/d:activelock/d:lockscope', - '/d:prop/d:lockdiscovery/d:activelock/d:lockscope/d:exclusive', - '/d:prop/d:lockdiscovery/d:activelock/d:depth', - '/d:prop/d:lockdiscovery/d:activelock/d:owner', - '/d:prop/d:lockdiscovery/d:activelock/d:timeout', - '/d:prop/d:lockdiscovery/d:activelock/d:locktoken', - '/d:prop/d:lockdiscovery/d:activelock/d:locktoken/d:href', - ]; - - foreach ($elements as $elem) { - $data = $xml->xpath($elem); - $this->assertEquals(1, count($data), 'We expected 1 match for the xpath expression "'.$elem.'". '.count($data).' were found. Full response body: '.$this->response->getBodyAsString()); - } - - $depth = $xml->xpath('/d:prop/d:lockdiscovery/d:activelock/d:depth'); - $this->assertEquals('infinity', (string) $depth[0]); - - $token = $xml->xpath('/d:prop/d:lockdiscovery/d:activelock/d:locktoken/d:href'); - $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 - */ - public function testDoubleLock() - { - $request = new HTTP\Request('LOCK', '/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->httpRequest = $request; - $this->server->exec(); - - $this->response = new HTTP\ResponseMock(); - $this->server->httpResponse = $this->response; - - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - - $this->assertEquals(423, $this->response->status, 'Full response: '.$this->response->getBodyAsString()); - } - - /** - * @depends testLock - */ - public function testLockRefresh() - { - $request = new HTTP\Request('LOCK', '/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->httpRequest = $request; - $this->server->exec(); - - $lockToken = $this->response->getHeader('Lock-Token'); - - $this->response = new HTTP\ResponseMock(); - $this->server->httpResponse = $this->response; - - $request = new HTTP\Request('LOCK', '/test.txt', ['If' => '('.$lockToken.')']); - $request->setBody(''); - - $this->server->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - - $this->assertEquals(200, $this->response->status, 'We received an incorrect status code. Full response body: '.$this->response->getBody()); - } - - /** - * @depends testLock - */ - public function testLockRefreshBadToken() - { - $request = new HTTP\Request('LOCK', '/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->httpRequest = $request; - $this->server->exec(); - - $lockToken = $this->response->getHeader('Lock-Token'); - - $this->response = new HTTP\ResponseMock(); - $this->server->httpResponse = $this->response; - - $request = new HTTP\Request('LOCK', '/test.txt', ['If' => '('.$lockToken.'foobar) (<opaquelocktoken:anotherbadtoken>)']); - $request->setBody(''); - - $this->server->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - - $this->assertEquals(423, $this->response->getStatus(), 'We received an incorrect status code. Full response body: '.$this->response->getBody()); - } - - /** - * @depends testLock - */ - public function testLockNoFile() - { - $request = new HTTP\Request('LOCK', '/notfound.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->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); - - $this->assertEquals(201, $this->response->status); - } - - /** - * @depends testLock - */ - public function testUnlockNoToken() - { - $request = new HTTP\Request('UNLOCK', '/test.txt'); - $this->server->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals([ - 'X-Sabre-Version' => [DAV\Version::VERSION], - 'Content-Type' => ['application/xml; charset=utf-8'], - ], - $this->response->getHeaders() - ); - - $this->assertEquals(400, $this->response->status); - } - - /** - * @depends testLock - */ - public function testUnlockBadToken() - { - $request = new HTTP\Request('UNLOCK', '/test.txt', ['Lock-Token' => '<opaquelocktoken:blablabla>']); - $this->server->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals([ - 'X-Sabre-Version' => [DAV\Version::VERSION], - 'Content-Type' => ['application/xml; charset=utf-8'], - ], - $this->response->getHeaders() - ); - - $this->assertEquals(409, $this->response->status, 'Got an incorrect status code. Full response body: '.$this->response->getBodyAsString()); - } - - /** - * @depends testLock - */ - public function testLockPutNoToken() - { - $request = new HTTP\Request('LOCK', '/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->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); - - $this->assertEquals(200, $this->response->status); - - $request = new HTTP\Request('PUT', '/test.txt'); - $request->setBody('newbody'); - $this->server->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); - - $this->assertEquals(423, $this->response->status); - } - - /** - * @depends testLock - */ - public function testUnlock() - { - $request = new HTTP\Request('LOCK', '/test.txt'); - $this->server->httpRequest = $request; - - $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->invokeMethod($request, $this->server->httpResponse); - $lockToken = $this->server->httpResponse->getHeader('Lock-Token'); - - $request = new HTTP\Request('UNLOCK', '/test.txt', ['Lock-Token' => $lockToken]); - $this->server->httpRequest = $request; - $this->server->httpResponse = new HTTP\ResponseMock(); - $this->server->invokeMethod($request, $this->server->httpResponse); - - $this->assertEquals(204, $this->server->httpResponse->status, 'Got an incorrect status code. Full response body: '.$this->response->getBodyAsString()); - $this->assertEquals([ - 'X-Sabre-Version' => [DAV\Version::VERSION], - 'Content-Length' => ['0'], - ], - $this->server->httpResponse->getHeaders() - ); - } - - /** - * @depends testLock - */ - public function testUnlockWindowsBug() - { - $request = new HTTP\Request('LOCK', '/test.txt'); - $this->server->httpRequest = $request; - - $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->invokeMethod($request, $this->server->httpResponse); - $lockToken = $this->server->httpResponse->getHeader('Lock-Token'); - - // See Issue 123 - $lockToken = trim($lockToken, '<>'); - - $request = new HTTP\Request('UNLOCK', '/test.txt', ['Lock-Token' => $lockToken]); - $this->server->httpRequest = $request; - $this->server->httpResponse = new HTTP\ResponseMock(); - $this->server->invokeMethod($request, $this->server->httpResponse); - - $this->assertEquals(204, $this->server->httpResponse->status, 'Got an incorrect status code. Full response body: '.$this->response->getBodyAsString()); - $this->assertEquals([ - 'X-Sabre-Version' => [DAV\Version::VERSION], - 'Content-Length' => ['0'], - ], - $this->server->httpResponse->getHeaders() - ); - } - - /** - * @depends testLock - */ - public function testLockRetainOwner() - { - $request = new HTTP\Request('LOCK', '/test.txt'); - $this->server->httpRequest = $request; - - $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>Evert</D:owner> -</D:lockinfo>'); - - $this->server->invokeMethod($request, $this->server->httpResponse); - $lockToken = $this->server->httpResponse->getHeader('Lock-Token'); - - $locks = $this->locksPlugin->getLocks('test.txt'); - $this->assertEquals(1, count($locks)); - $this->assertEquals('Evert', $locks[0]->owner); - } - - /** - * @depends testLock - */ - public function testLockPutBadToken() - { - $request = new HTTP\Request('LOCK', '/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->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); - - $this->assertEquals(200, $this->response->status); - - $request = new HTTP\Request('PUT', '/test.txt', [ - 'If' => '(<opaquelocktoken:token1>)', - ]); - $request->setBody('newbody'); - $this->server->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); - - // $this->assertEquals('412 Precondition failed',$this->response->status); - $this->assertEquals(423, $this->response->status); - } - - /** - * @depends testLock - */ - public function testLockDeleteParent() - { - $request = new HTTP\Request('LOCK', '/dir/child.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->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); - - $this->assertEquals(200, $this->response->status); - - $request = new HTTP\Request('DELETE', '/dir'); - $this->server->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals(423, $this->response->status); - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - } - - /** - * @depends testLock - */ - public function testLockDeleteSucceed() - { - $request = new HTTP\Request('LOCK', '/dir/child.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->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); - - $this->assertEquals(200, $this->response->status); - - $request = new HTTP\Request('DELETE', '/dir/child.txt', [ - 'If' => '('.$this->response->getHeader('Lock-Token').')', - ]); - $this->server->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals(204, $this->response->status); - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - } - - /** - * @depends testLock - */ - public function testLockCopyLockSource() - { - $request = new HTTP\Request('LOCK', '/dir/child.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->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); - - $this->assertEquals(200, $this->response->status); - - $request = new HTTP\Request('COPY', '/dir/child.txt', [ - 'Destination' => '/dir/child2.txt', - ]); - - $this->server->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals(201, $this->response->status, 'Copy must succeed if only the source is locked, but not the destination'); - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - } - - /** - * @depends testLock - */ - public function testLockCopyLockDestination() - { - $request = new HTTP\Request('LOCK', '/dir/child2.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->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); - - $this->assertEquals(201, $this->response->status); - - $request = new HTTP\Request('COPY', '/dir/child.txt', [ - 'Destination' => '/dir/child2.txt', - ]); - $this->server->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals(423, $this->response->status, 'Copy must succeed if only the source is locked, but not the destination'); - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - } - - /** - * @depends testLock - */ - public function testLockMoveLockSourceLocked() - { - $request = new HTTP\Request('LOCK', '/dir/child.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->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); - - $this->assertEquals(200, $this->response->status); - - $request = new HTTP\Request('MOVE', '/dir/child.txt', [ - 'Destination' => '/dir/child2.txt', - ]); - $this->server->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals(423, $this->response->status, 'Copy must succeed if only the source is locked, but not the destination'); - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - } - - /** - * @depends testLock - */ - public function testLockMoveLockSourceSucceed() - { - $request = new HTTP\Request('LOCK', '/dir/child.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->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); - - $this->assertEquals(200, $this->response->status); - - $request = new HTTP\Request('MOVE', '/dir/child.txt', [ - 'Destination' => '/dir/child2.txt', - 'If' => '('.$this->response->getHeader('Lock-Token').')', - ]); - $this->server->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals(201, $this->response->status, 'A valid lock-token was provided for the source, so this MOVE operation must succeed. Full response body: '.$this->response->getBodyAsString()); - } - - /** - * @depends testLock - */ - public function testLockMoveLockDestination() - { - $request = new HTTP\Request('LOCK', '/dir/child2.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->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); - - $this->assertEquals(201, $this->response->status); - - $request = new HTTP\Request('MOVE', '/dir/child.txt', [ - 'Destination' => '/dir/child2.txt', - ]); - $this->server->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals(423, $this->response->status, 'Copy must succeed if only the source is locked, but not the destination'); - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - } - - /** - * @depends testLock - */ - public function testLockMoveLockParent() - { - $request = new HTTP\Request('LOCK', '/dir', [ - 'Depth' => 'infinite', - ]); - $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->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); - - $this->assertEquals(200, $this->response->status); - - $request = new HTTP\Request('MOVE', '/dir/child.txt', [ - 'Destination' => '/dir/child2.txt', - 'If' => '</dir> ('.$this->response->getHeader('Lock-Token').')', - ]); - $this->server->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals(201, $this->response->status, 'We locked the parent of both the source and destination, but the move didn\'t succeed.'); - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - } - - /** - * @depends testLock - */ - public function testLockPutGoodToken() - { - $request = new HTTP\Request('LOCK', '/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->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); - - $this->assertEquals(200, $this->response->status); - - $request = new HTTP\Request('PUT', '/test.txt', [ - 'If' => '('.$this->response->getHeader('Lock-Token').')', - ]); - $request->setBody('newbody'); - $this->server->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); - - $this->assertEquals(204, $this->response->status); - } - - /** - * @depends testLock - */ - public function testLockPutUnrelatedToken() - { - $request = new HTTP\Request('LOCK', '/unrelated.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->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); - - $this->assertEquals(201, $this->response->getStatus()); - - $request = new HTTP\Request( - 'PUT', - '/test.txt', - ['If' => '</unrelated.txt> ('.$this->response->getHeader('Lock-Token').')'] - ); - $request->setBody('newbody'); - $this->server->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - $this->assertTrue(1 === preg_match('/^<opaquelocktoken:(.*)>$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); - - $this->assertEquals(204, $this->response->status); - } - - public function testPutWithIncorrectETag() - { - $request = new HTTP\Request('PUT', '/test.txt', [ - 'If' => '(["etag1"])', - ]); - $request->setBody('newbody'); - $this->server->httpRequest = $request; - $this->server->exec(); - $this->assertEquals(412, $this->response->status); - } - - /** - * @depends testPutWithIncorrectETag - */ - public function testPutWithCorrectETag() - { - // We need an ETag-enabled file node. - $tree = new DAV\Tree(new DAV\FSExt\Directory(SABRE_TEMPDIR)); - $this->server->tree = $tree; - - $filename = SABRE_TEMPDIR.'/test.txt'; - $etag = sha1( - fileinode($filename). - filesize($filename). - filemtime($filename) - ); - - $request = new HTTP\Request('PUT', '/test.txt', [ - 'If' => '(["'.$etag.'"])', - ]); - $request->setBody('newbody'); - - $this->server->httpRequest = $request; - $this->server->exec(); - $this->assertEquals(204, $this->response->status, 'Incorrect status received. Full response body:'.$this->response->getBodyAsString()); - } - - public function testDeleteWithETagOnCollection() - { - $request = new HTTP\Request('DELETE', '/dir', [ - 'If' => '(["etag1"])', - ]); - - $this->server->httpRequest = $request; - $this->server->exec(); - $this->assertEquals(412, $this->response->status); - } - - public function testGetTimeoutHeader() - { - $request = new HTTP\Request('LOCK', '/foo/bar', [ - 'Timeout' => 'second-100', - ]); - - $this->server->httpRequest = $request; - $this->assertEquals(100, $this->locksPlugin->getTimeoutHeader()); - } - - public function testGetTimeoutHeaderTwoItems() - { - $request = new HTTP\Request('LOCK', '/foo/bar', [ - 'Timeout' => 'second-5, infinite', - ]); - $this->server->httpRequest = $request; - $this->assertEquals(5, $this->locksPlugin->getTimeoutHeader()); - } - - public function testGetTimeoutHeaderInfinite() - { - $request = new HTTP\Request('LOCK', '/foo/bar', [ - 'Timeout' => 'infinite, second-5', - ]); - $this->server->httpRequest = $request; - $this->assertEquals(LockInfo::TIMEOUT_INFINITE, $this->locksPlugin->getTimeoutHeader()); - } - - public function testGetTimeoutHeaderInvalid() - { - $this->expectException('Sabre\DAV\Exception\BadRequest'); - $request = new HTTP\Request('GET', '/', ['Timeout' => 'yourmom']); - - $this->server->httpRequest = $request; - $this->locksPlugin->getTimeoutHeader(); - } -} |