function testExpand()
    {
        $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', 'HTTP_DEPTH' => '1'));
        $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
    <D:prop>
        <C:calendar-data>
            <C:expand start="20120205T230000Z" end="20120212T225959Z"/>
        </C:calendar-data>
        <D:getetag/>
    </D:prop>
    <C:filter>
        <C:comp-filter name="VCALENDAR">
            <C:comp-filter name="VEVENT">
                <C:time-range start="20120205T230000Z" end="20120212T225959Z"/>
            </C:comp-filter>
        </C:comp-filter>
    </C:filter>
</C:calendar-query>');
        $response = $this->request($request);
        // Everts super awesome xml parser.
        $body = substr($response->body, $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13);
        $body = str_replace('&#13;', '', $body);
        $vObject = Sabre_VObject_Reader::read($body);
        // We only expect 3 events
        $this->assertEquals(3, count($vObject->VEVENT), 'We got 6 events instead of 3. Output: ' . $body);
        // TZID should be gone
        $this->assertFalse(isset($vObject->VEVENT->DTSTART['TZID']));
    }
    function testCorrect()
    {
        $xml = '<?xml version="1.0"?>
<d:principal-search-property-set xmlns:d="DAV:"/>';
        $serverVars = array('REQUEST_METHOD' => 'REPORT', 'HTTP_DEPTH' => '0', 'REQUEST_URI' => '/principals');
        $request = new Sabre_HTTP_Request($serverVars);
        $request->setBody($xml);
        $server = $this->getServer();
        $server->httpRequest = $request;
        $server->exec();
        $this->assertEquals('HTTP/1.1 200 Ok', $server->httpResponse->status, $server->httpResponse->body);
        $this->assertEquals(array('Content-Type' => 'application/xml; charset=utf-8'), $server->httpResponse->headers);
        $check = array('/d:principal-search-property-set', '/d:principal-search-property-set/d:principal-search-property', '/d:principal-search-property-set/d:principal-search-property/d:prop', '/d:principal-search-property-set/d:principal-search-property/d:prop/d:displayname', '/d:principal-search-property-set/d:principal-search-property/d:description');
        $xml = simplexml_load_string($server->httpResponse->body);
        $xml->registerXPathNamespace('d', 'DAV:');
        foreach ($check as $v1 => $v2) {
            $xpath = is_int($v1) ? $v2 : $v1;
            $result = $xml->xpath($xpath);
            $count = 1;
            if (!is_int($v1)) {
                $count = $v2;
            }
            $this->assertEquals($count, count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result) . '. Full response body: ' . $server->httpResponse->body);
        }
    }
    function testQueryTimerange()
    {
        $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', 'HTTP_DEPTH' => '1'));
        $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
    <D:prop>
        <C:calendar-data>
            <C:expand start="20120226T230000Z" end="20120228T225959Z"/>
        </C:calendar-data>
        <D:getetag/>
    </D:prop>
    <C:filter>
        <C:comp-filter name="VCALENDAR">
            <C:comp-filter name="VEVENT">
                <C:time-range start="20120226T230000Z" end="20120228T225959Z"/>
            </C:comp-filter>
        </C:comp-filter>
    </C:filter>
</C:calendar-query>');
        $response = $this->request($request);
        if (strpos($response->body, 'BEGIN:VCALENDAR') === false) {
            $this->fail('Got no events instead of 1. Output: ' . $response->body);
        }
        // Everts super awesome xml parser.
        $body = substr($response->body, $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13);
        $body = str_replace('&#13;', '', $body);
        $vObject = VObject\Reader::read($body);
        // We expect 1 event
        $this->assertEquals(1, count($vObject->VEVENT), 'We got 0 events instead of 1. Output: ' . $body);
    }
    function testIssue205()
    {
        $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', 'HTTP_DEPTH' => '1'));
        $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
    <D:prop>
        <C:calendar-data>
            <C:expand start="20120325T220000Z" end="20120401T215959Z"/>
        </C:calendar-data>
        <D:getetag/>
    </D:prop>
    <C:filter>
        <C:comp-filter name="VCALENDAR">
            <C:comp-filter name="VEVENT">
                <C:comp-filter name="VALARM">
                    <C:time-range start="20120325T220000Z" end="20120401T215959Z"/>
                </C:comp-filter>
            </C:comp-filter>
        </C:comp-filter>
    </C:filter>
</C:calendar-query>');
        $response = $this->request($request);
        $this->assertFalse(strpos($response->body, '<s:exception>Exception</s:exception>'), 'Exception occurred: ' . $response->body);
        $this->assertFalse(strpos($response->body, 'Unknown or bad format'), 'DateTime unknown format Exception: ' . $response->body);
        // Everts super awesome xml parser.
        $body = substr($response->body, $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13);
        $body = str_replace('&#13;', '', $body);
        $vObject = VObject\Reader::read($body);
        $this->assertEquals(1, count($vObject->VEVENT));
    }
    /**
     * @depends testSimple
     */
    function testExpand()
    {
        $xml = '<?xml version="1.0"?>
<d:expand-property xmlns:d="DAV:">
  <d:property name="current-user-principal">
      <d:property name="displayname" />
  </d:property>
</d:expand-property>';
        $serverVars = array('REQUEST_METHOD' => 'REPORT', 'HTTP_DEPTH' => '0', 'REQUEST_URI' => '/');
        $request = new Sabre_HTTP_Request($serverVars);
        $request->setBody($xml);
        $server = $this->getServer();
        $server->httpRequest = $request;
        $server->exec();
        $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status);
        $this->assertEquals(array('Content-Type' => 'application/xml; charset=utf-8'), $server->httpResponse->headers);
        $check = array('/d:multistatus', '/d:multistatus/d:response' => 1, '/d:multistatus/d:response/d:href' => 1, '/d:multistatus/d:response/d:propstat' => 1, '/d:multistatus/d:response/d:propstat/d:prop' => 1, '/d:multistatus/d:response/d:propstat/d:prop/d:current-user-principal' => 1, '/d:multistatus/d:response/d:propstat/d:prop/d:current-user-principal/d:response' => 1, '/d:multistatus/d:response/d:propstat/d:prop/d:current-user-principal/d:response/d:href' => 1, '/d:multistatus/d:response/d:propstat/d:prop/d:current-user-principal/d:response/d:propstat' => 1, '/d:multistatus/d:response/d:propstat/d:prop/d:current-user-principal/d:response/d:propstat/d:prop' => 1, '/d:multistatus/d:response/d:propstat/d:prop/d:current-user-principal/d:response/d:propstat/d:prop/d:displayname' => 1);
        $xml = simplexml_load_string($server->httpResponse->body);
        $xml->registerXPathNamespace('d', 'DAV:');
        foreach ($check as $v1 => $v2) {
            $xpath = is_int($v1) ? $v2 : $v1;
            $result = $xml->xpath($xpath);
            $count = 1;
            if (!is_int($v1)) {
                $count = $v2;
            }
            $this->assertEquals($count, count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result));
        }
    }
 public function sendPROPFIND($body)
 {
     $serverVars = array('REQUEST_URI' => '/', 'REQUEST_METHOD' => 'PROPFIND', 'HTTP_DEPTH' => '0');
     $request = new Sabre_HTTP_Request($serverVars);
     $request->setBody($body);
     $this->server->httpRequest = $request;
     $this->server->exec();
 }
Example #7
0
 function testGetAbsoluteUri()
 {
     $s = array('HTTP_HOST' => 'sabredav.org', 'REQUEST_URI' => '/foo');
     $r = new Sabre_HTTP_Request($s);
     $this->assertEquals('http://sabredav.org/foo', $r->getAbsoluteUri());
     $s = array('HTTP_HOST' => 'sabredav.org', 'REQUEST_URI' => '/foo', 'HTTPS' => 'on');
     $r = new Sabre_HTTP_Request($s);
     $this->assertEquals('https://sabredav.org/foo', $r->getAbsoluteUri());
 }
Example #8
0
 function testGetQueryString()
 {
     $s = array('QUERY_STRING' => 'bla');
     $r = new Sabre_HTTP_Request($s);
     $this->assertEquals('bla', $r->getQueryString());
     $s = array();
     $r = new Sabre_HTTP_Request($s);
     $this->assertEquals('', $r->getQueryString());
 }
 public function testPatchSuccess()
 {
     $this->node->put('00000000');
     $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'PATCH', 'REQUEST_URI' => '/partial', 'HTTP_X_UPDATE_RANGE' => 'bytes=3-5', 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate', 'HTTP_CONTENT_LENGTH' => 3));
     $request->setBody('111');
     $response = $this->request($request);
     $this->assertEquals('HTTP/1.1 204 No Content', $response->status, 'Full response body:' . $response->body);
     $this->assertEquals('00111000', $this->node->get());
 }
 function testCollectionGet()
 {
     $serverVars = array('REQUEST_URI' => '/', 'REQUEST_METHOD' => 'GET');
     $request = new Sabre_HTTP_Request($serverVars);
     $request->setBody('');
     $this->server->httpRequest = $request;
     $this->server->exec();
     $this->assertEquals(array('Content-Type' => 'application/xml; charset=utf-8', 'DAV' => '1, 3, extended-mkcol'), $this->response->headers);
     $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status, 'Incorrect status response received. Full response body: ' . $this->response->body);
 }
 function testUpdateFileParsableBody()
 {
     $this->calBackend->createCalendarObject('calendar1', 'blabla.ics', 'foo');
     $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics'));
     $request->setBody("BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n");
     $response = $this->request($request);
     $this->assertEquals('HTTP/1.1 204 No Content', $response->status);
     $expected = array('uri' => 'blabla.ics', 'calendardata' => "BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n", 'calendarid' => 'calendar1');
     $this->assertEquals($expected, $this->calBackend->getCalendarObject('calendar1', 'blabla.ics'));
 }
 function testUpdateFileParsableBody()
 {
     $this->cardBackend->createCard('addressbook1', 'blabla.vcf', 'foo');
     $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf'));
     $body = "BEGIN:VCARD\r\nUID:foo\r\nEND:VCARD\r\n";
     $request->setBody($body);
     $response = $this->request($request);
     $this->assertEquals('HTTP/1.1 204 No Content', $response->status);
     $expected = array('uri' => 'blabla.vcf', 'carddata' => $body);
     $this->assertEquals($expected, $this->cardBackend->getCard('addressbook1', 'blabla.vcf'));
 }
 function testPutFail()
 {
     $serverVars = array('REQUEST_URI' => '/testput.txt', 'REQUEST_METHOD' => 'PUT', 'HTTP_X_EXPECTED_ENTITY_LENGTH' => '20');
     $request = new Sabre_HTTP_Request($serverVars);
     $request->setBody('');
     $this->server->httpRequest = $request;
     $this->server->exec();
     $this->assertEquals('HTTP/1.1 403 Forbidden', $this->response->status);
     $this->assertEquals(array('Content-Type' => 'application/xml; charset=utf-8'), $this->response->headers);
     $this->assertFalse(file_exists(SABRE_TEMPDIR . '/testput.txt'));
 }
 function testPutUpdate()
 {
     $serverVars = array('REQUEST_URI' => '/test.txt', 'REQUEST_METHOD' => 'PUT');
     $request = new Sabre_HTTP_Request($serverVars);
     $request->setBody('Testing updated file');
     $this->server->httpRequest = $request;
     $this->server->exec();
     $this->assertEquals('0', $this->response->headers['Content-Length']);
     $this->assertEquals('HTTP/1.1 204 No Content', $this->response->status);
     $this->assertEquals('', $this->response->body);
     $this->assertEquals('Testing updated file', file_get_contents($this->tempDir . '/test.txt'));
 }
Example #15
0
 function testReportPassThrough()
 {
     $fakeServer = new Sabre_DAV_Server(new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleDirectory('bla')));
     $plugin = new Sabre_DAV_Auth_Plugin(new Sabre_DAV_Auth_MockBackend(), 'realm');
     $fakeServer->addPlugin($plugin);
     $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/'));
     $request->setBody('<?xml version="1.0"?><s:somereport xmlns:s="http://www.rooftopsolutions.nl/NS/example" />');
     $fakeServer->httpRequest = $request;
     $fakeServer->httpResponse = new Sabre_HTTP_ResponseMock();
     $fakeServer->exec();
     $this->assertEquals('HTTP/1.1 501 Not Implemented', $fakeServer->httpResponse->status);
 }
Example #16
0
 public function testDigestAuthInt()
 {
     $this->auth->setQOP(Sabre_HTTP_DigestAuth::QOP_AUTHINT | Sabre_HTTP_DigestAuth::QOP_AUTH);
     list($nonce, $opaque) = $this->getServerTokens(Sabre_HTTP_DigestAuth::QOP_AUTHINT | Sabre_HTTP_DigestAuth::QOP_AUTH);
     $username = '******';
     $password = 12345;
     $nc = '00003';
     $cnonce = uniqid();
     $digestHash = md5(md5($username . ':' . self::REALM . ':' . $password) . ':' . $nonce . ':' . $nc . ':' . $cnonce . ':' . 'auth-int:' . md5('POST' . ':' . '/' . ':' . md5('body')));
     $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'POST', 'PHP_AUTH_DIGEST' => 'username="******", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth-int,nc=' . $nc . ',cnonce="' . $cnonce . '"'));
     $request->setBody('body');
     $this->auth->setHTTPRequest($request);
     $this->auth->init();
     $this->assertTrue($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . $password)), 'Authentication is deemed invalid through validateA1');
 }
    function testIssue203()
    {
        $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', 'HTTP_DEPTH' => '1'));
        $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
    <D:prop>
        <C:calendar-data>
            <C:expand start="20120325T220000Z" end="20120401T215959Z"/>
        </C:calendar-data>
        <D:getetag/>
    </D:prop>
    <C:filter>
        <C:comp-filter name="VCALENDAR">
            <C:comp-filter name="VEVENT">
                <C:time-range start="20120325T220000Z" end="20120401T215959Z"/>
            </C:comp-filter>
        </C:comp-filter>
    </C:filter>
</C:calendar-query>');
        $response = $this->request($request);
        // Everts super awesome xml parser.
        $body = substr($response->body, $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13);
        $body = str_replace('&#13;', '', $body);
        $vObject = VObject\Reader::read($body);
        $this->assertEquals(2, count($vObject->VEVENT));
        $expectedEvents = array(array('DTSTART' => '20120326T135200Z', 'DTEND' => '20120326T145200Z', 'SUMMARY' => 'original summary'), array('DTSTART' => '20120328T135200Z', 'DTEND' => '20120328T145200Z', 'SUMMARY' => 'overwritten summary', 'RECURRENCE-ID' => '20120327T135200Z'));
        // try to match agains $expectedEvents array
        foreach ($expectedEvents as $expectedEvent) {
            $matching = false;
            foreach ($vObject->VEVENT as $vevent) {
                /** @var $vevent Sabre\VObject\Component\VEvent */
                foreach ($vevent->children as $child) {
                    /** @var $child Sabre\VObject\Property */
                    if (isset($expectedEvent[$child->name])) {
                        if ($expectedEvent[$child->name] != $child->value) {
                            continue 2;
                        }
                    }
                }
                $matching = true;
                break;
            }
            $this->assertTrue($matching, 'Did not find the following event in the response: ' . var_export($expectedEvent, true));
        }
    }
Example #18
0
 /**
  * @depends testTreeMove
  * @depends testCopyMoveInfo
  */
 function testEverything()
 {
     // Request object
     $serverVars = array('REQUEST_METHOD' => 'MOVE', 'REQUEST_URI' => '/webdav/foo', 'HTTP_DESTINATION' => 'http://dev2.tribalos.com/webdav/%C3%A0fo%C3%B3', 'HTTP_OVERWRITE' => 'F');
     $request = new Sabre_HTTP_Request($serverVars);
     $request->setBody('');
     $response = new Sabre_HTTP_ResponseMock();
     // Server setup
     mkdir(SABRE_TEMPDIR . '/issue33');
     $dir = new Sabre_DAV_FS_Directory(SABRE_TEMPDIR . '/issue33');
     $dir->createDirectory('foo');
     $tree = new Sabre_DAV_ObjectTree($dir);
     $server = new Sabre_DAV_Server($tree);
     $server->setBaseUri('/webdav/');
     $server->httpRequest = $request;
     $server->httpResponse = $response;
     $server->exec();
     $this->assertTrue(file_exists(SABRE_TEMPDIR . '/issue33/' . urldecode('%C3%A0fo%C3%B3')));
 }
    function testMultiGet()
    {
        $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/addressbooks/user1/book1'));
        $request->setBody('<?xml version="1.0"?>
<c:addressbook-multiget xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
    <d:prop>
      <d:getetag />
      <c:address-data />
    </d:prop>
    <d:href>/addressbooks/user1/book1/card1</d:href>
</c:addressbook-multiget>');
        $response = new Sabre_HTTP_ResponseMock();
        $this->server->httpRequest = $request;
        $this->server->httpResponse = $response;
        $this->server->exec();
        $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body);
        // using the client for parsing
        $client = new Sabre_DAV_Client(array('baseUri' => '/'));
        $result = $client->parseMultiStatus($response->body);
        $this->assertEquals(array('/addressbooks/user1/book1/card1' => array(200 => array('{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD"))), $result);
    }
    function testExpandRecurringByDayEvent()
    {
        $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', 'HTTP_DEPTH' => '1'));
        $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
    <D:prop>
        <C:calendar-data>
            <C:expand start="20120210T230000Z" end="20120217T225959Z"/>
        </C:calendar-data>
        <D:getetag/>
    </D:prop>
    <C:filter>
        <C:comp-filter name="VCALENDAR">
            <C:comp-filter name="VEVENT">
                <C:time-range start="20120210T230000Z" end="20120217T225959Z"/>
            </C:comp-filter>
        </C:comp-filter>
    </C:filter>
</C:calendar-query>');
        $response = $this->request($request);
        // Everts super awesome xml parser.
        $body = substr($response->body, $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13);
        $body = str_replace('&#13;', '', $body);
        $vObject = Sabre_VObject_Reader::read($body);
        $this->assertEquals(2, count($vObject->VEVENT));
        // check if DTSTARTs and DTENDs are correct
        foreach ($vObject->VEVENT as $vevent) {
            /** @var $vevent Sabre_VObject_Component_VEvent */
            foreach ($vevent->children as $child) {
                /** @var $child Sabre_VObject_Property */
                if ($child->name == 'DTSTART') {
                    // DTSTART has to be one of two valid values
                    $this->assertContains($child->value, array('20120214T171500Z', '20120216T171500Z'), 'DTSTART is not a valid value: ' . $child->value);
                } elseif ($child->name == 'DTEND') {
                    // DTEND has to be one of two valid values
                    $this->assertContains($child->value, array('20120214T181500Z', '20120216T181500Z'), 'DTEND is not a valid value: ' . $child->value);
                }
            }
        }
    }
    function testIssue228()
    {
        $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', 'HTTP_DEPTH' => '1'));
        $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
  <D:prop>
    <C:calendar-data>
  <C:expand start="20120730T095609Z"
            end="20120813T095609Z"/>
</C:calendar-data>
    <D:getetag/>
  </D:prop>
  <C:filter>
    <C:comp-filter name="VCALENDAR">
      <C:comp-filter name="VEVENT">
        <C:time-range start="20120730T095609Z" end="20120813T095609Z"/>
      </C:comp-filter>
    </C:comp-filter>
  </C:filter>
</C:calendar-query>');
        $response = $this->request($request);
        // We must check if absolutely nothing was returned from this query.
        $this->assertFalse(strpos($response->body, 'BEGIN:VCALENDAR'));
    }
    function testIssue220()
    {
        $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', 'HTTP_DEPTH' => '1'));
        $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
    <D:prop>
        <C:calendar-data/>
        <D:getetag/>
    </D:prop>
    <C:filter>
        <C:comp-filter name="VCALENDAR">
            <C:comp-filter name="VEVENT">
                <C:comp-filter name="VALARM">
                    <C:time-range start="20120607T161646Z" end="20120612T161646Z"/>
                </C:comp-filter>
            </C:comp-filter>
        </C:comp-filter>
    </C:filter>
</C:calendar-query>');
        $response = $this->request($request);
        $this->assertFalse(strpos($response->body, '<s:exception>PHPUnit_Framework_Error_Warning</s:exception>'), 'Error Warning occurred: ' . $response->body);
        $this->assertFalse(strpos($response->body, 'Invalid argument supplied for foreach()'), 'Invalid argument supplied for foreach(): ' . $response->body);
        $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status);
    }
    function testIssue211()
    {
        $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', 'HTTP_DEPTH' => '1'));
        $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
    <D:prop>
        <C:calendar-data/>
        <D:getetag/>
    </D:prop>
    <C:filter>
        <C:comp-filter name="VCALENDAR">
            <C:comp-filter name="VEVENT">
                <C:comp-filter name="VALARM">
                    <C:time-range start="20120426T220000Z" end="20120427T215959Z"/>
                </C:comp-filter>
            </C:comp-filter>
        </C:comp-filter>
    </C:filter>
</C:calendar-query>');
        $response = $this->request($request);
        // if this assert is reached, the endless loop is gone
        // There should be no matching events
        $this->assertFalse(strpos('BEGIN:VEVENT', $response->body));
    }
Example #24
0
 /**
  * (non-PHPdoc)
  * @see Sabre_DAV_Collection::getChild()
  */
 public function getChild($_name)
 {
     $modelName = $this->_application->name . '_Model_' . $this->_model;
     if ($_name instanceof $modelName) {
         $object = $_name;
     } else {
         $filterClass = $this->_application->name . '_Model_' . $this->_model . 'Filter';
         $filter = new $filterClass(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_container->getId()), array('condition' => 'OR', 'filters' => array(array('field' => 'id', 'operator' => 'equals', 'value' => $this->_getIdFromName($_name)), array('field' => 'uid', 'operator' => 'equals', 'value' => $this->_getIdFromName($_name))))));
         $object = $this->_getController()->search($filter, null, false, false, 'sync')->getFirstRecord();
         if ($object == null) {
             throw new Sabre_DAV_Exception_FileNotFound('Object not found');
         }
     }
     $httpRequest = new Sabre_HTTP_Request();
     // lie about existance of event of request is a PUT request from an ATTENDEE for an already existing event
     // to prevent ugly (and not helpful) error messages on the client
     if (isset($_SERVER['REQUEST_METHOD']) && $httpRequest->getMethod() == 'PUT' && $httpRequest->getHeader('If-None-Match') === '*') {
         if ($object->organizer != Tinebase_Core::getUser()->contact_id && Calendar_Model_Attender::getOwnAttender($object->attendee) !== null) {
             throw new Sabre_DAV_Exception_FileNotFound('Object not found');
         }
     }
     $objectClass = $this->_application->name . '_Frontend_WebDAV_' . $this->_model;
     return new $objectClass($this->_container, $object);
 }
 /**
  * Returns information about Copy and Move requests
  * 
  * This function is created to help getting information about the source and the destination for the 
  * WebDAV MOVE and COPY HTTP request. It also validates a lot of information and throws proper exceptions 
  * 
  * The returned value is an array with the following keys:
  *   * source - Source path
  *   * destination - Destination path
  *   * destinationExists - Wether or not the destination is an existing url (and should therefore be overwritten)
  *
  * @return array 
  */
 protected function getCopyAndMoveInfo()
 {
     $source = $this->getRequestUri();
     // Collecting the relevant HTTP headers
     if (!$this->httpRequest->getHeader('Destination')) {
         throw new Sabre_DAV_Exception_BadRequest('The destination header was not supplied');
     }
     $destination = $this->calculateUri($this->httpRequest->getHeader('Destination'));
     $overwrite = $this->httpRequest->getHeader('Overwrite');
     if (!$overwrite) {
         $overwrite = 'T';
     }
     if (strtoupper($overwrite) == 'T') {
         $overwrite = true;
     } elseif (strtoupper($overwrite) == 'F') {
         $overwrite = false;
     } else {
         throw new Sabre_DAV_Exception_BadRequest('The HTTP Overwrite header should be either T or F');
     }
     $destinationUri = dirname($destination);
     if ($destinationUri == '.') {
         $destinationUri = '';
     }
     // Collection information on relevant existing nodes
     $sourceNode = $this->tree->getNodeForPath($source);
     try {
         $destinationParent = $this->tree->getNodeForPath($destinationUri);
         if (!$destinationParent instanceof Sabre_DAV_IDirectory) {
             throw new Sabre_DAV_Exception_UnsupportedMediaType('The destination node is not a collection');
         }
     } catch (Sabre_DAV_Exception_FileNotFound $e) {
         // If the destination parent node is not found, we throw a 409
         throw new Sabre_DAV_Exception_Conflict('The destination node is not found');
     }
     try {
         $destinationNode = $this->tree->getNodeForPath($destination);
         // If this succeeded, it means the destination already exists
         // we'll need to throw precondition failed in case overwrite is false
         if (!$overwrite) {
             throw new Sabre_DAV_Exception_PreconditionFailed('The destination node already exists, and the overwrite header is set to false');
         }
     } catch (Sabre_DAV_Exception_FileNotFound $e) {
         // Destination didn't exist, we're all good
         $destinationNode = false;
     }
     // These are the three relevant properties we need to return
     return array('source' => $source, 'destination' => $destination, 'destinationExists' => $destinationNode == true, 'destinationNode' => $destinationNode);
 }
Example #26
0
 /**
  * @depends testCalendarMultiGetReport
  */
 function testCalendarMultiGetReportEndBeforeStart()
 {
     $body = '<?xml version="1.0"?>' . '<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' . '<d:prop>' . '  <c:calendar-data>' . '     <c:expand start="20200101T000000Z" end="20110101T000000Z" />' . '  </c:calendar-data>' . '  <d:getetag />' . '</d:prop>' . '<d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>' . '</c:calendar-multiget>';
     $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/calendars/user1', 'HTTP_DEPTH' => '1'));
     $request->setBody($body);
     $this->server->httpRequest = $request;
     $this->server->exec();
     $this->assertEquals('HTTP/1.1 400 Bad request', $this->response->status, 'Invalid HTTP status received. Full response body: ' . $this->response->body);
 }
Example #27
0
 /**
  * Sets the contents of the HTTP request body
  *
  * This method can either accept a string, or a readable stream resource.
  *
  * If the setAsDefaultInputStream is set to true, it means for this run of the
  * script the supplied body will be used instead of php://input.
  *
  * @param mixed $body
  * @param bool $setAsDefaultInputStream
  * @return void
  */
 public function setBody($body, $setAsDefaultInputStream = false)
 {
     if (is_resource($body)) {
         $this->body = $body;
     } else {
         $stream = fopen('php://temp', 'r+');
         fputs($stream, $body);
         rewind($stream);
         // String is assumed
         $this->body = $stream;
     }
     if ($setAsDefaultInputStream) {
         self::$defaultInputStream = $this->body;
     }
 }
Example #28
0
 /**
  * This method checks the main HTTP preconditions.
  *
  * Currently these are:
  *   * If-Match
  *   * If-None-Match
  *   * If-Modified-Since
  *   * If-Unmodified-Since
  *
  * The method will return true if all preconditions are met
  * The method will return false, or throw an exception if preconditions
  * failed. If false is returned the operation should be aborted, and
  * the appropriate HTTP response headers are already set.
  *
  * Normally this method will throw 412 Precondition Failed for failures
  * related to If-None-Match, If-Match and If-Unmodified Since. It will
  * set the status to 304 Not Modified for If-Modified_since.
  *
  * If the $handleAsGET argument is set to true, it will also return 304
  * Not Modified for failure of the If-None-Match precondition. This is the
  * desired behaviour for HTTP GET and HTTP HEAD requests.
  *
  * @param bool $handleAsGET
  * @return bool
  */
 public function checkPreconditions($handleAsGET = false)
 {
     $uri = $this->getRequestUri();
     $node = null;
     $lastMod = null;
     $etag = null;
     if ($ifMatch = $this->httpRequest->getHeader('If-Match')) {
         // If-Match contains an entity tag. Only if the entity-tag
         // matches we are allowed to make the request succeed.
         // If the entity-tag is '*' we are only allowed to make the
         // request succeed if a resource exists at that url.
         try {
             $node = $this->tree->getNodeForPath($uri);
         } catch (Sabre_DAV_Exception_NotFound $e) {
             throw new Sabre_DAV_Exception_PreconditionFailed('An If-Match header was specified and the resource did not exist', 'If-Match');
         }
         // Only need to check entity tags if they are not *
         if ($ifMatch !== '*') {
             // There can be multiple etags
             $ifMatch = explode(',', $ifMatch);
             $haveMatch = false;
             foreach ($ifMatch as $ifMatchItem) {
                 // Stripping any extra spaces
                 $ifMatchItem = trim($ifMatchItem, ' ');
                 $etag = $node->getETag();
                 if ($etag === $ifMatchItem) {
                     $haveMatch = true;
                 }
             }
             if (!$haveMatch) {
                 throw new Sabre_DAV_Exception_PreconditionFailed('An If-Match header was specified, but none of the specified the ETags matched.', 'If-Match');
             }
         }
     }
     if ($ifNoneMatch = $this->httpRequest->getHeader('If-None-Match')) {
         // The If-None-Match header contains an etag.
         // Only if the ETag does not match the current ETag, the request will succeed
         // The header can also contain *, in which case the request
         // will only succeed if the entity does not exist at all.
         $nodeExists = true;
         if (!$node) {
             try {
                 $node = $this->tree->getNodeForPath($uri);
             } catch (Sabre_DAV_Exception_NotFound $e) {
                 $nodeExists = false;
             }
         }
         if ($nodeExists) {
             $haveMatch = false;
             if ($ifNoneMatch === '*') {
                 $haveMatch = true;
             } else {
                 // There might be multiple etags
                 $ifNoneMatch = explode(',', $ifNoneMatch);
                 $etag = $node->getETag();
                 foreach ($ifNoneMatch as $ifNoneMatchItem) {
                     // Stripping any extra spaces
                     $ifNoneMatchItem = trim($ifNoneMatchItem, ' ');
                     if ($etag === $ifNoneMatchItem) {
                         $haveMatch = true;
                     }
                 }
             }
             if ($haveMatch) {
                 if ($handleAsGET) {
                     $this->httpResponse->sendStatus(304);
                     return false;
                 } else {
                     throw new Sabre_DAV_Exception_PreconditionFailed('An If-None-Match header was specified, but the ETag matched (or * was specified).', 'If-None-Match');
                 }
             }
         }
     }
     if (!$ifNoneMatch && ($ifModifiedSince = $this->httpRequest->getHeader('If-Modified-Since'))) {
         // The If-Modified-Since header contains a date. We
         // will only return the entity if it has been changed since
         // that date. If it hasn't been changed, we return a 304
         // header
         // Note that this header only has to be checked if there was no If-None-Match header
         // as per the HTTP spec.
         $date = Sabre_HTTP_Util::parseHTTPDate($ifModifiedSince);
         if ($date) {
             if (is_null($node)) {
                 $node = $this->tree->getNodeForPath($uri);
             }
             $lastMod = $node->getLastModified();
             if ($lastMod) {
                 $lastMod = new DateTime('@' . $lastMod);
                 if ($lastMod <= $date) {
                     $this->httpResponse->sendStatus(304);
                     $this->httpResponse->setHeader('Last-Modified', Sabre_HTTP_Util::toHTTPDate($lastMod));
                     return false;
                 }
             }
         }
     }
     if ($ifUnmodifiedSince = $this->httpRequest->getHeader('If-Unmodified-Since')) {
         // The If-Unmodified-Since will allow allow the request if the
         // entity has not changed since the specified date.
         $date = Sabre_HTTP_Util::parseHTTPDate($ifUnmodifiedSince);
         // We must only check the date if it's valid
         if ($date) {
             if (is_null($node)) {
                 $node = $this->tree->getNodeForPath($uri);
             }
             $lastMod = $node->getLastModified();
             if ($lastMod) {
                 $lastMod = new DateTime('@' . $lastMod);
                 if ($lastMod > $date) {
                     throw new Sabre_DAV_Exception_PreconditionFailed('An If-Unmodified-Since header was specified, but the entity has been changed since the specified date.', 'If-Unmodified-Since');
                 }
             }
         }
     }
     return true;
 }
 function testPutPropfind()
 {
     // mimicking an OS/X resource fork
     $serverVars = array('REQUEST_URI' => '/._testput.txt', 'REQUEST_METHOD' => 'PUT');
     $request = new Sabre_HTTP_Request($serverVars);
     $request->setBody('Testing new file');
     $this->server->httpRequest = $request;
     $this->server->exec();
     $this->assertEquals('', $this->response->body);
     $this->assertEquals('HTTP/1.1 201 Created', $this->response->status);
     $this->assertEquals(array('X-Sabre-Temp' => 'true'), $this->response->headers);
     $serverVars = array('REQUEST_URI' => '/._testput.txt', 'REQUEST_METHOD' => 'PROPFIND');
     $request = new Sabre_HTTP_Request($serverVars);
     $request->setBody('');
     $this->server->httpRequest = $request;
     $this->server->exec();
     $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status, 'Incorrect status code returned. Body: ' . $this->response->body);
     $this->assertEquals(array('X-Sabre-Temp' => 'true', 'Content-Type' => 'application/xml; charset=utf-8'), $this->response->headers);
     $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\\')DAV:(\"|\\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body);
     $xml = simplexml_load_string($body);
     $xml->registerXPathNamespace('d', 'urn:DAV');
     list($data) = $xml->xpath('/d:multistatus/d:response/d:href');
     $this->assertEquals('/._testput.txt', (string) $data, 'href element should have been /._testput.txt');
     $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:resourcetype');
     $this->assertEquals(1, count($data));
 }
Example #30
0
    /**
     * @depends testMKCOLSuccess
     * @depends testMKCOLAlreadyExists
     */
    function testMKCOLAndProps()
    {
        $serverVars = array('REQUEST_URI' => '/testcol', 'REQUEST_METHOD' => 'MKCOL', 'HTTP_CONTENT_TYPE' => 'application/xml');
        $request = new Sabre_HTTP_Request($serverVars);
        $request->setBody('<?xml version="1.0"?>
<mkcol xmlns="DAV:">
  <set>
    <prop>
        <resourcetype><collection /></resourcetype>
        <displayname>my new collection</displayname>
    </prop>
  </set>
</mkcol>');
        $this->server->httpRequest = $request;
        $this->server->exec();
        $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status, 'Wrong statuscode received. Full response body: ' . $this->response->body);
        $this->assertEquals(array('Content-Type' => 'application/xml; charset=utf-8'), $this->response->headers);
    }