Пример #1
0
 function testSetGetBodyStream()
 {
     $h = fopen('php://memory', 'r+');
     fwrite($h, 'testing');
     rewind($h);
     $this->request->setBody($h);
     $this->assertEquals('testing', stream_get_contents($this->request->getBody()), 'We didn\'t get our testbody back');
 }
Пример #2
0
    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));
    }
    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']));
    }
Пример #4
0
    /**
     * @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));
        }
    }
    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);
    }
Пример #7
0
 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();
 }
Пример #8
0
 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());
 }
Пример #9
0
 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 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->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'));
 }
Пример #13
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);
 }
Пример #14
0
 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'));
 }
Пример #15
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');
 }
Пример #16
0
    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));
        }
    }
Пример #17
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')));
 }
Пример #18
0
    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);
                }
            }
        }
    }
Пример #20
0
    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'));
    }
Пример #21
0
    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);
    }
Пример #22
0
    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));
    }
Пример #23
0
    function testproppatchMinimalError()
    {
        $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'PROPPATCH', 'REQUEST_URI' => '/', 'HTTP_PREFER' => 'return-minimal'));
        $request->setBody(<<<BLA
<?xml version="1.0"?>
<d:proppatch xmlns:d="DAV:">
    <d:set>
        <d:prop>
            <d:something>nope!</d:something>
        </d:prop>
    </d:set>
</d:proppatch>
BLA
);
        $response = $this->request($request);
        $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status);
        $this->assertTrue(strpos($response->body, 'something') !== false);
        $this->assertTrue(strpos($response->body, 'HTTP/1.1 403 Forbidden') !== false);
    }
Пример #24
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);
 }
Пример #25
0
    function testUnknownXmlDoc()
    {
        $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/calendars/user1/cal2', 'CONTENT_TYPE' => 'text/xml'));
        $xml = '<?xml version="1.0"?>
<cs:foo-bar xmlns:cs="' . Sabre_CalDAV_Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />';
        $request->setBody($xml);
        $response = $this->request($request);
        $this->assertEquals('HTTP/1.1 501 Not Implemented', $response->status, $response->body);
    }
 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));
 }
Пример #27
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);
    }
Пример #28
0
 function testSuccessCancel()
 {
     $req = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/calendars/user1/outbox', 'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org', 'HTTP_RECIPIENT' => 'mailto:user2@example.org', 'HTTP_CONTENT_TYPE' => 'text/calendar'));
     $body = array('BEGIN:VCALENDAR', 'METHOD:CANCEL', 'BEGIN:VEVENT', 'SUMMARY:An invitation', 'END:VEVENT', 'END:VCALENDAR');
     $req->setBody(implode("\r\n", $body));
     $handler = new Sabre_CalDAV_Schedule_IMip_Mock('*****@*****.**');
     $this->caldavPlugin->setIMIPhandler($handler);
     $this->assertHTTPStatus(200, $req);
     $this->assertEquals(array(array('to' => '*****@*****.**', 'subject' => 'Cancelled event: An invitation', 'body' => implode("\r\n", $body) . "\r\n", 'headers' => array('Reply-To: user1.sabredav@sabredav.org', 'From: server@example.org', 'Content-Type: text/calendar; method=CANCEL; charset=utf-8', 'X-Sabre-Version: ' . Sabre_DAV_Version::VERSION . '-' . Sabre_DAV_Version::STABILITY))), $handler->getSentEmails());
 }
Пример #29
0
    /**
     * @depends testParsePropPatchRequest
     * @depends testUpdateProperties
     * @covers Sabre_DAV_Server::httpPropPatch
     */
    public function testPropPatch()
    {
        $serverVars = array('REQUEST_URI' => '/', 'REQUEST_METHOD' => 'PROPPATCH');
        $body = '<?xml version="1.0"?>
<d:propertyupdate xmlns:d="DAV:" xmlns:s="http://www.rooftopsolutions.nl/testnamespace">
  <d:set><d:prop><s:someprop>somevalue</s:someprop></d:prop></d:set>
</d:propertyupdate>';
        $request = new Sabre_HTTP_Request($serverVars);
        $request->setBody($body);
        $this->server->httpRequest = $request;
        $this->server->exec();
        $this->assertEquals(array('Content-Type' => 'application/xml; charset=utf-8', 'Vary' => 'Brief,Prefer'), $this->response->headers);
        $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status, 'We got the wrong status. Full XML response: ' . $this->response->body);
        $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\\')DAV:(\"|\\')/", "xmlns\\1=\"DAV:\"", $this->response->body);
        $xml = simplexml_load_string($body);
        $xml->registerXPathNamespace('d', 'DAV:');
        $xml->registerXPathNamespace('bla', 'http://www.rooftopsolutions.nl/testnamespace');
        $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop');
        $this->assertEquals(1, count($data), 'We expected one \'d:prop\' element. Response body: ' . $body);
        $data = $xml->xpath('//bla:someprop');
        $this->assertEquals(1, count($data), 'We expected one \'s:someprop\' element. Response body: ' . $body);
        $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status');
        $this->assertEquals(1, count($data), 'We expected one \'s:status\' element. Response body: ' . $body);
        $this->assertEquals('HTTP/1.1 200 OK', (string) $data[0]);
    }
Пример #30
0
 public function testValidRequest()
 {
     $accessKey = 'accessKey';
     $secretKey = 'secretKey';
     $content = 'thisisthebody';
     $contentMD5 = base64_encode(md5($content, true));
     $date = new DateTime('now');
     $date->setTimeZone(new DateTimeZone('GMT'));
     $date = $date->format('D, d M Y H:i:s \\G\\M\\T');
     $sig = base64_encode($this->hmacsha1($secretKey, "POST\n{$contentMD5}\n\n{$date}\nx-amz-date:{$date}\n/evert"));
     $request = new Sabre_HTTP_Request(array('REQUEST_METHOD' => 'POST', 'HTTP_AUTHORIZATION' => "AWS {$accessKey}:{$sig}", 'HTTP_CONTENT_MD5' => $contentMD5, 'HTTP_X_AMZ_DATE' => $date, 'REQUEST_URI' => '/evert'));
     $request->setBody($content);
     $this->auth->setHTTPRequest($request);
     $this->auth->init();
     $result = $this->auth->validate($secretKey);
     $this->assertTrue($result, 'Signature did not validate, got errorcode ' . $this->auth->errorCode);
     $this->assertEquals($accessKey, $this->auth->getAccessKey());
 }