aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/HTTP
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-10-21 15:46:31 -0700
committerfriendica <info@friendica.com>2013-10-21 15:46:31 -0700
commitb35122f7a6ad42756c35bb60ba1f06c3dcd45c77 (patch)
treeccdf373ce6475d264778523259cc32899b732fe7 /vendor/sabre/dav/tests/Sabre/HTTP
parente3504df514d306cfe6b83e44a11f550664564af4 (diff)
downloadvolse-hubzilla-b35122f7a6ad42756c35bb60ba1f06c3dcd45c77.tar.gz
volse-hubzilla-b35122f7a6ad42756c35bb60ba1f06c3dcd45c77.tar.bz2
volse-hubzilla-b35122f7a6ad42756c35bb60ba1f06c3dcd45c77.zip
add sabre (1.8.x) via composer in the !@#$ place it wants to be
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/HTTP')
-rw-r--r--vendor/sabre/dav/tests/Sabre/HTTP/AWSAuthTest.php242
-rw-r--r--vendor/sabre/dav/tests/Sabre/HTTP/BasicAuthTest.php132
-rw-r--r--vendor/sabre/dav/tests/Sabre/HTTP/DigestAuthTest.php228
-rw-r--r--vendor/sabre/dav/tests/Sabre/HTTP/RequestTest.php150
-rw-r--r--vendor/sabre/dav/tests/Sabre/HTTP/ResponseMock.php29
-rw-r--r--vendor/sabre/dav/tests/Sabre/HTTP/ResponseTest.php70
-rw-r--r--vendor/sabre/dav/tests/Sabre/HTTP/UtilTest.php78
-rw-r--r--vendor/sabre/dav/tests/Sabre/HTTP/VersionTest.php17
8 files changed, 946 insertions, 0 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/HTTP/AWSAuthTest.php b/vendor/sabre/dav/tests/Sabre/HTTP/AWSAuthTest.php
new file mode 100644
index 000000000..569ec2e7d
--- /dev/null
+++ b/vendor/sabre/dav/tests/Sabre/HTTP/AWSAuthTest.php
@@ -0,0 +1,242 @@
+<?php
+
+namespace Sabre\HTTP;
+
+require_once 'Sabre/HTTP/ResponseMock.php';
+
+class AWSAuthTest extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @var Sabre\HTTP\ResponseMock
+ */
+ private $response;
+ /**
+ * @var Sabre\HTTP\AWSAuth
+ */
+ private $auth;
+
+ const REALM = 'SabreDAV unittest';
+
+ public function setUp() {
+
+ $this->response = new ResponseMock();
+ $this->auth = new AWSAuth();
+ $this->auth->setRealm(self::REALM);
+ $this->auth->setHTTPResponse($this->response);
+
+ }
+
+ public function testNoHeader() {
+
+ $request = new Request(array(
+ 'REQUEST_METHOD' => 'GET',
+ ));
+
+ $this->auth->setHTTPRequest($request);
+
+ $result = $this->auth->init();
+
+ $this->assertFalse($result,'No AWS Authorization header was supplied, so we should have gotten false');
+ $this->assertEquals(AWSAuth::ERR_NOAWSHEADER,$this->auth->errorCode);
+
+ }
+
+ public function testIncorrectContentMD5() {
+
+ $accessKey = 'accessKey';
+ $secretKey = 'secretKey';
+
+ $request = new Request(array(
+ 'REQUEST_METHOD' => 'GET',
+ 'HTTP_AUTHORIZATION' => "AWS $accessKey:sig",
+ 'HTTP_CONTENT_MD5' => 'garbage',
+ 'REQUEST_URI' => '/',
+ ));
+
+ $this->auth->setHTTPRequest($request);
+ $this->auth->init();
+ $result = $this->auth->validate($secretKey);
+
+ $this->assertFalse($result);
+ $this->assertEquals(AWSAuth::ERR_MD5CHECKSUMWRONG,$this->auth->errorCode);
+
+ }
+
+ public function testNoDate() {
+
+ $accessKey = 'accessKey';
+ $secretKey = 'secretKey';
+ $content = 'thisisthebody';
+ $contentMD5 = base64_encode(md5($content,true));
+
+
+ $request = new Request(array(
+ 'REQUEST_METHOD' => 'POST',
+ 'HTTP_AUTHORIZATION' => "AWS $accessKey:sig",
+ 'HTTP_CONTENT_MD5' => $contentMD5,
+ ));
+
+ $request->setBody($content);
+
+ $this->auth->setHTTPRequest($request);
+ $this->auth->init();
+ $result = $this->auth->validate($secretKey);
+
+ $this->assertFalse($result);
+ $this->assertEquals(AWSAuth::ERR_INVALIDDATEFORMAT,$this->auth->errorCode);
+
+ }
+
+ public function testFutureDate() {
+
+ $accessKey = 'accessKey';
+ $secretKey = 'secretKey';
+ $content = 'thisisthebody';
+ $contentMD5 = base64_encode(md5($content,true));
+
+ $date = new \DateTime('@' . (time() + (60*20)));
+ $date->setTimeZone(new \DateTimeZone('GMT'));
+ $date = $date->format('D, d M Y H:i:s \\G\\M\\T');
+
+ $request = new Request(array(
+ 'REQUEST_METHOD' => 'POST',
+ 'HTTP_AUTHORIZATION' => "AWS $accessKey:sig",
+ 'HTTP_CONTENT_MD5' => $contentMD5,
+ 'HTTP_DATE' => $date,
+ ));
+
+ $request->setBody($content);
+
+ $this->auth->setHTTPRequest($request);
+ $this->auth->init();
+ $result = $this->auth->validate($secretKey);
+
+ $this->assertFalse($result);
+ $this->assertEquals(AWSAuth::ERR_REQUESTTIMESKEWED,$this->auth->errorCode);
+
+ }
+
+ public function testPastDate() {
+
+ $accessKey = 'accessKey';
+ $secretKey = 'secretKey';
+ $content = 'thisisthebody';
+ $contentMD5 = base64_encode(md5($content,true));
+
+ $date = new \DateTime('@' . (time() - (60*20)));
+ $date->setTimeZone(new \DateTimeZone('GMT'));
+ $date = $date->format('D, d M Y H:i:s \\G\\M\\T');
+
+ $request = new Request(array(
+ 'REQUEST_METHOD' => 'POST',
+ 'HTTP_AUTHORIZATION' => "AWS $accessKey:sig",
+ 'HTTP_CONTENT_MD5' => $contentMD5,
+ 'HTTP_X_AMZ_DATE' => $date,
+ ));
+
+ $request->setBody($content);
+
+ $this->auth->setHTTPRequest($request);
+ $this->auth->init();
+ $result = $this->auth->validate($secretKey);
+
+ $this->assertFalse($result);
+ $this->assertEquals(AWSAuth::ERR_REQUESTTIMESKEWED,$this->auth->errorCode);
+
+ }
+
+ public function testIncorrectSignature() {
+
+ $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');
+
+ $request = new Request(array(
+ 'REQUEST_METHOD' => 'POST',
+ 'HTTP_AUTHORIZATION' => "AWS $accessKey:sig",
+ 'HTTP_CONTENT_MD5' => $contentMD5,
+ 'HTTP_X_AMZ_DATE' => $date,
+ 'REQUEST_URI' => '/',
+ ));
+
+ $request->setBody($content);
+
+ $this->auth->setHTTPRequest($request);
+ $this->auth->init();
+ $result = $this->auth->validate($secretKey);
+
+ $this->assertFalse($result);
+ $this->assertEquals(AWSAuth::ERR_INVALIDSIGNATURE,$this->auth->errorCode);
+
+ }
+
+ 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 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());
+
+ }
+
+ public function test401() {
+
+ $this->auth->requireLogin();
+ $test = preg_match('/^AWS$/',$this->response->headers['WWW-Authenticate'],$matches);
+ $this->assertTrue($test==true,'The WWW-Authenticate response didn\'t match our pattern');
+
+ }
+
+ /**
+ * Generates an HMAC-SHA1 signature
+ *
+ * @param string $key
+ * @param string $message
+ * @return string
+ */
+ private function hmacsha1($key, $message) {
+
+ $blocksize=64;
+ if (strlen($key)>$blocksize)
+ $key=pack('H*', sha1($key));
+ $key=str_pad($key,$blocksize,chr(0x00));
+ $ipad=str_repeat(chr(0x36),$blocksize);
+ $opad=str_repeat(chr(0x5c),$blocksize);
+ $hmac = pack('H*',sha1(($key^$opad).pack('H*',sha1(($key^$ipad).$message))));
+ return $hmac;
+
+ }
+
+}
diff --git a/vendor/sabre/dav/tests/Sabre/HTTP/BasicAuthTest.php b/vendor/sabre/dav/tests/Sabre/HTTP/BasicAuthTest.php
new file mode 100644
index 000000000..77c5c7179
--- /dev/null
+++ b/vendor/sabre/dav/tests/Sabre/HTTP/BasicAuthTest.php
@@ -0,0 +1,132 @@
+<?php
+
+namespace Sabre\HTTP;
+
+require_once 'Sabre/HTTP/ResponseMock.php';
+
+class BasicAuthTest extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @var Sabre\HTTP\ResponseMock
+ */
+ private $response;
+ /**
+ * @var Sabre\HTTP\BasicAuth
+ */
+ private $basicAuth;
+
+ function setUp() {
+
+ $this->response = new ResponseMock();
+ $this->basicAuth = new BasicAuth();
+ $this->basicAuth->setHTTPResponse($this->response);
+
+ }
+
+ function testGetUserPassApache() {
+
+ $server = array(
+ 'PHP_AUTH_USER' => 'admin',
+ 'PHP_AUTH_PW' => '1234',
+ );
+
+ $request = new Request($server);
+ $this->basicAuth->setHTTPRequest($request);
+
+ $userPass = $this->basicAuth->getUserPass();
+
+ $this->assertEquals(
+ array('admin','1234'),
+ $userPass,
+ 'We did not get the username and password we expected'
+ );
+
+ }
+
+ function testGetUserPassIIS() {
+
+ $server = array(
+ 'HTTP_AUTHORIZATION' => 'Basic ' . base64_encode('admin:1234'),
+ );
+
+ $request = new Request($server);
+ $this->basicAuth->setHTTPRequest($request);
+
+ $userPass = $this->basicAuth->getUserPass();
+
+ $this->assertEquals(
+ array('admin','1234'),
+ $userPass,
+ 'We did not get the username and password we expected'
+ );
+
+ }
+
+ function testGetUserPassWithColon() {
+
+ $server = array(
+ 'HTTP_AUTHORIZATION' => 'Basic ' . base64_encode('admin:1234:5678'),
+ );
+
+ $request = new Request($server);
+ $this->basicAuth->setHTTPRequest($request);
+
+ $userPass = $this->basicAuth->getUserPass();
+
+ $this->assertEquals(
+ array('admin','1234:5678'),
+ $userPass,
+ 'We did not get the username and password we expected'
+ );
+
+ }
+
+ function testGetUserPassApacheEdgeCase() {
+
+ $server = array(
+ 'REDIRECT_HTTP_AUTHORIZATION' => 'Basic ' . base64_encode('admin:1234'),
+ );
+
+ $request = new Request($server);
+ $this->basicAuth->setHTTPRequest($request);
+
+ $userPass = $this->basicAuth->getUserPass();
+
+ $this->assertEquals(
+ array('admin','1234'),
+ $userPass,
+ 'We did not get the username and password we expected'
+ );
+
+ }
+
+ function testGetUserPassNothing() {
+
+ $this->assertEquals(
+ false,
+ $this->basicAuth->getUserPass()
+ );
+
+ }
+
+ function testRequireLogin() {
+
+ $this->basicAuth->requireLogin();
+ $this->assertEquals('SabreDAV',$this->basicAuth->getRealm());
+ $this->assertEquals(
+ 'HTTP/1.1 401 Unauthorized',
+ $this->response->status,
+ 'We expected a 401 status to be set'
+ );
+
+ $this->assertEquals(
+ 'Basic realm="SabreDAV"',
+ $this->response->headers['WWW-Authenticate'],
+ 'The WWW-Autenticate header was not set!'
+ );
+
+
+
+ }
+
+}
diff --git a/vendor/sabre/dav/tests/Sabre/HTTP/DigestAuthTest.php b/vendor/sabre/dav/tests/Sabre/HTTP/DigestAuthTest.php
new file mode 100644
index 000000000..576a00d4a
--- /dev/null
+++ b/vendor/sabre/dav/tests/Sabre/HTTP/DigestAuthTest.php
@@ -0,0 +1,228 @@
+<?php
+
+namespace Sabre\HTTP;
+
+require_once 'Sabre/HTTP/ResponseMock.php';
+
+class DigestAuthTest extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @var Sabre\HTTP\ResponseMock
+ */
+ private $response;
+ /**
+ * @var Sabre\HTTP\DigestAuth
+ */
+ private $auth;
+
+ const REALM = 'SabreDAV unittest';
+
+ public function setUp() {
+
+ $this->response = new ResponseMock();
+ $this->auth = new DigestAuth();
+ $this->auth->setRealm(self::REALM);
+ $this->auth->setHTTPResponse($this->response);
+
+ }
+
+ public function testDigest() {
+
+ list($nonce,$opaque) = $this->getServerTokens();
+
+ $username = 'admin';
+ $password = 12345;
+ $nc = '00002';
+ $cnonce = uniqid();
+
+ $digestHash = md5(
+ md5($username . ':' . self::REALM . ':' . $password) . ':' .
+ $nonce . ':' .
+ $nc . ':' .
+ $cnonce . ':' .
+ 'auth:' .
+ md5('GET' . ':' . '/')
+ );
+
+ $request = new Request(array(
+ 'REQUEST_METHOD' => 'GET',
+ 'PHP_AUTH_DIGEST' => 'username="'.$username.'", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth,nc='.$nc.',cnonce="' . $cnonce . '"',
+ ));
+
+ $this->auth->setHTTPRequest($request);
+ $this->auth->init();
+
+ $this->assertEquals($username,$this->auth->getUserName());
+ $this->assertEquals(self::REALM,$this->auth->getRealm());
+ $this->assertTrue($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . $password)),'Authentication is deemed invalid through validateA1');
+ $this->assertTrue($this->auth->validatePassword($password),'Authentication is deemed invalid through validatePassword');
+
+ }
+
+ public function testDigestCGIFormat() {
+
+ list($nonce,$opaque) = $this->getServerTokens();
+
+ $username = 'admin';
+ $password = 12345;
+ $nc = '00002';
+ $cnonce = uniqid();
+
+ $digestHash = md5(
+ md5($username . ':' . self::REALM . ':' . $password) . ':' .
+ $nonce . ':' .
+ $nc . ':' .
+ $cnonce . ':' .
+ 'auth:' .
+ md5('GET' . ':' . '/')
+ );
+
+ $request = new Request(array(
+ 'REQUEST_METHOD' => 'GET',
+ 'HTTP_AUTHORIZATION' => 'Digest username="'.$username.'", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth,nc='.$nc.',cnonce="' . $cnonce . '"',
+ ));
+
+ $this->auth->setHTTPRequest($request);
+ $this->auth->init();
+
+ $this->assertTrue($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . $password)),'Authentication is deemed invalid through validateA1');
+ $this->assertTrue($this->auth->validatePassword($password),'Authentication is deemed invalid through validatePassword');
+
+ }
+
+ public function testDigestApacheEdgeCase() {
+
+ list($nonce,$opaque) = $this->getServerTokens();
+
+ $username = 'admin';
+ $password = 12345;
+ $nc = '00002';
+ $cnonce = uniqid();
+
+ $digestHash = md5(
+ md5($username . ':' . self::REALM . ':' . $password) . ':' .
+ $nonce . ':' .
+ $nc . ':' .
+ $cnonce . ':' .
+ 'auth:' .
+ md5('GET' . ':' . '/')
+ );
+
+ $request = new Request(array(
+ 'REQUEST_METHOD' => 'GET',
+ 'REDIRECT_HTTP_AUTHORIZATION' => 'Digest username="'.$username.'", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth,nc='.$nc.',cnonce="' . $cnonce . '"',
+ ));
+
+ $this->auth->setHTTPRequest($request);
+ $this->auth->init();
+
+ $this->assertTrue($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . $password)),'Authentication is deemed invalid through validateA1');
+ $this->assertTrue($this->auth->validatePassword($password),'Authentication is deemed invalid through validatePassword');
+
+ }
+
+ public function testInvalidDigest() {
+
+ list($nonce,$opaque) = $this->getServerTokens();
+
+ $username = 'admin';
+ $password = 12345;
+ $nc = '00002';
+ $cnonce = uniqid();
+
+ $digestHash = md5(
+ md5($username . ':' . self::REALM . ':' . $password) . ':' .
+ $nonce . ':' .
+ $nc . ':' .
+ $cnonce . ':' .
+ 'auth:' .
+ md5('GET' . ':' . '/')
+ );
+
+ $request = new Request(array(
+ 'REQUEST_METHOD' => 'GET',
+ 'PHP_AUTH_DIGEST' => 'username="'.$username.'", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth,nc='.$nc.',cnonce="' . $cnonce . '"',
+ ));
+
+ $this->auth->setHTTPRequest($request);
+ $this->auth->init();
+
+ $this->assertFalse($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . ($password . 'randomness'))),'Authentication is deemed invalid through validateA1');
+
+ }
+
+ public function testInvalidDigest2() {
+
+ $request = new Request(array(
+ 'REQUEST_METHOD' => 'GET',
+ 'HTTP_AUTHORIZATION' => 'basic blablabla',
+ ));
+
+ $this->auth->setHTTPRequest($request);
+ $this->auth->init();
+
+ $this->assertFalse($this->auth->validateA1(md5('user:realm:password')));
+
+ }
+
+
+ public function testDigestAuthInt() {
+
+ $this->auth->setQOP(DigestAuth::QOP_AUTHINT | DigestAuth::QOP_AUTH);
+ list($nonce,$opaque) = $this->getServerTokens(DigestAuth::QOP_AUTHINT| DigestAuth::QOP_AUTH);
+
+ $username = 'admin';
+ $password = 12345;
+ $nc = '00003';
+ $cnonce = uniqid();
+
+ $digestHash = md5(
+ md5($username . ':' . self::REALM . ':' . $password) . ':' .
+ $nonce . ':' .
+ $nc . ':' .
+ $cnonce . ':' .
+ 'auth-int:' .
+ md5('POST' . ':' . '/' . ':' . md5('body'))
+ );
+
+ $request = new Request(array(
+ 'REQUEST_METHOD' => 'POST',
+ 'PHP_AUTH_DIGEST' => 'username="'.$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');
+
+ }
+
+ private function getServerTokens($qop = DigestAuth::QOP_AUTH) {
+
+ $this->auth->requireLogin();
+
+ switch($qop) {
+ case DigestAuth::QOP_AUTH : $qopstr='auth'; break;
+ case DigestAuth::QOP_AUTHINT : $qopstr='auth-int'; break;
+ default : $qopstr='auth,auth-int'; break;
+ }
+
+ $test = preg_match('/Digest realm="'.self::REALM.'",qop="'.$qopstr.'",nonce="([0-9a-f]*)",opaque="([0-9a-f]*)"/',
+ $this->response->headers['WWW-Authenticate'],$matches);
+
+ $this->assertTrue($test==true,'The WWW-Authenticate response didn\'t match our pattern. We received: ' . $this->response->headers['WWW-Authenticate']);
+
+ $nonce = $matches[1];
+ $opaque = $matches[2];
+
+ // Reset our environment
+ $this->setUp();
+ $this->auth->setQOP($qop);
+
+ return array($nonce,$opaque);
+
+ }
+
+}
diff --git a/vendor/sabre/dav/tests/Sabre/HTTP/RequestTest.php b/vendor/sabre/dav/tests/Sabre/HTTP/RequestTest.php
new file mode 100644
index 000000000..c52ce351d
--- /dev/null
+++ b/vendor/sabre/dav/tests/Sabre/HTTP/RequestTest.php
@@ -0,0 +1,150 @@
+<?php
+
+namespace Sabre\HTTP;
+
+/**
+ * @covers Sabre\HTTP\Request
+ */
+class RequestTest extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @var Sabre\HTTP\Request
+ */
+ private $request;
+
+ function setUp() {
+
+ $server = array(
+ 'HTTP_HOST' => 'www.example.org',
+ 'REQUEST_METHOD' => 'PUT',
+ 'REQUEST_URI' => '/testuri/',
+ 'CONTENT_TYPE' => 'text/xml',
+ );
+
+ $this->request = new Request($server);
+
+ }
+
+ function testGetHeader() {
+
+ $this->assertEquals('www.example.org', $this->request->getHeader('Host'));
+ $this->assertEquals('text/xml', $this->request->getHeader('Content-Type'));
+
+ }
+
+ function testGetNonExistantHeader() {
+
+ $this->assertNull($this->request->getHeader('doesntexist'));
+ $this->assertNull($this->request->getHeader('Content-Length'));
+
+ }
+
+ function testGetHeaders() {
+
+ $expected = array(
+ 'host' => 'www.example.org',
+ 'content-type' => 'text/xml',
+ );
+
+ $this->assertEquals($expected, $this->request->getHeaders());
+
+ }
+
+ function testGetMethod() {
+
+ $this->assertEquals('PUT', $this->request->getMethod(), 'It seems as if we didn\'t get a valid HTTP Request method back');
+
+ }
+
+ function testGetUri() {
+
+ $this->assertEquals('/testuri/', $this->request->getUri(), 'We got an invalid uri back');
+
+ }
+
+ function testSetGetBody() {
+
+ $h = fopen('php://memory','r+');
+ fwrite($h,'testing');
+ rewind($h);
+ $this->request->setBody($h);
+ $this->assertEquals('testing',$this->request->getBody(true),'We didn\'t get our testbody back');
+
+ }
+
+ 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');
+
+ }
+
+
+ function testDefaultInputStream() {
+
+ $h = fopen('php://memory','r+');
+ fwrite($h,'testing');
+ rewind($h);
+
+ $previousValue = Request::$defaultInputStream;
+ Request::$defaultInputStream = $h;
+
+ $this->assertEquals('testing',$this->request->getBody(true),'We didn\'t get our testbody back');
+ Request::$defaultInputStream = $previousValue;
+
+ }
+
+ function testGetAbsoluteUri() {
+
+ $s = array(
+ 'HTTP_HOST' => 'sabredav.org',
+ 'REQUEST_URI' => '/foo'
+ );
+
+ $r = new Request($s);
+
+ $this->assertEquals('http://sabredav.org/foo', $r->getAbsoluteUri());
+
+ $s = array(
+ 'HTTP_HOST' => 'sabredav.org',
+ 'REQUEST_URI' => '/foo',
+ 'HTTPS' => 'on',
+ );
+
+ $r = new Request($s);
+
+ $this->assertEquals('https://sabredav.org/foo', $r->getAbsoluteUri());
+
+ }
+
+ function testGetQueryString() {
+
+ $s = array(
+ 'QUERY_STRING' => 'bla',
+ );
+
+ $r = new Request($s);
+ $this->assertEquals('bla', $r->getQueryString());
+
+ $s = array();
+
+ $r = new Request($s);
+ $this->assertEquals('', $r->getQueryString());
+
+ }
+
+ function testGetPostVars() {
+
+ $post = array(
+ 'bla' => 'foo',
+ );
+ $r = new Request(array(),$post);
+ $this->assertEquals($post, $r->getPostVars('bla'));
+
+ }
+
+
+}
diff --git a/vendor/sabre/dav/tests/Sabre/HTTP/ResponseMock.php b/vendor/sabre/dav/tests/Sabre/HTTP/ResponseMock.php
new file mode 100644
index 000000000..16c034099
--- /dev/null
+++ b/vendor/sabre/dav/tests/Sabre/HTTP/ResponseMock.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Sabre\HTTP;
+
+class ResponseMock extends Response {
+
+ public $headers = array();
+ public $status = '';
+ public $body = '';
+
+ function setHeader($name,$value,$overwrite = true) {
+
+ $this->headers[$name] = $value;
+
+ }
+
+ function sendStatus($code) {
+
+ $this->status = $this->getStatusMessage($code, $this->defaultHttpVersion);
+
+ }
+
+ function sendBody($body) {
+
+ $this->body = $body;
+
+ }
+
+}
diff --git a/vendor/sabre/dav/tests/Sabre/HTTP/ResponseTest.php b/vendor/sabre/dav/tests/Sabre/HTTP/ResponseTest.php
new file mode 100644
index 000000000..f5302c993
--- /dev/null
+++ b/vendor/sabre/dav/tests/Sabre/HTTP/ResponseTest.php
@@ -0,0 +1,70 @@
+<?php
+
+namespace Sabre\HTTP;
+
+require_once 'Sabre/HTTP/ResponseMock.php';
+
+class ResponseTest extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @var Sabre\HTTP\ResponseMock
+ */
+ private $response;
+
+ function setUp() {
+
+ $this->response = new ResponseMock();
+
+ }
+
+ function testGetStatusMessage() {
+
+ $msg = $this->response->getStatusMessage(200);
+ $this->assertEquals('HTTP/1.1 200 OK',$msg);
+
+ }
+
+ function testSetHeader() {
+
+ $this->response->setHeader('Content-Type','text/html');
+ $this->assertEquals('text/html', $this->response->headers['Content-Type']);
+
+
+ }
+ function testSetHeaders() {
+
+ $this->response->setHeaders(array('Content-Type'=>'text/html'));
+ $this->assertEquals('text/html', $this->response->headers['Content-Type']);
+
+
+ }
+
+ function testSendStatus() {
+
+ $this->response->sendStatus(404);
+ $this->assertEquals('HTTP/1.1 404 Not Found', $this->response->status);
+
+ }
+
+ function testSendBody() {
+
+ ob_start();
+ $response = new Response();
+ $response->sendBody('hello');
+ $this->assertEquals('hello',ob_get_clean());
+
+ }
+
+ function testSendBodyStream() {
+
+ ob_start();
+ $stream = fopen('php://memory','r+');
+ fwrite($stream,'hello');
+ rewind($stream);
+ $response = new Response();
+ $response->sendBody($stream);
+ $this->assertEquals('hello',ob_get_clean());
+
+ }
+
+}
diff --git a/vendor/sabre/dav/tests/Sabre/HTTP/UtilTest.php b/vendor/sabre/dav/tests/Sabre/HTTP/UtilTest.php
new file mode 100644
index 000000000..47a7b98bd
--- /dev/null
+++ b/vendor/sabre/dav/tests/Sabre/HTTP/UtilTest.php
@@ -0,0 +1,78 @@
+<?php
+
+namespace Sabre\HTTP;
+
+class UtilTest extends \PHPUnit_Framework_TestCase {
+
+ function testParseHTTPDate() {
+
+ $times = array(
+ 'Wed, 13 Oct 2010 10:26:00 GMT',
+ 'Wednesday, 13-Oct-10 10:26:00 GMT',
+ 'Wed Oct 13 10:26:00 2010',
+ );
+
+ $expected = 1286965560;
+
+ foreach($times as $time) {
+ $result = Util::parseHTTPDate($time);
+ $this->assertEquals($expected, $result->format('U'));
+ }
+
+ $result = Util::parseHTTPDate('Wed Oct 6 10:26:00 2010');
+ $this->assertEquals(1286360760, $result->format('U'));
+
+ }
+
+ function testParseHTTPDateFail() {
+
+ $times = array(
+ //random string
+ 'NOW',
+ // not-GMT timezone
+ 'Wednesday, 13-Oct-10 10:26:00 UTC',
+ // No space before the 6
+ 'Wed Oct 6 10:26:00 2010',
+ );
+
+ foreach($times as $time) {
+ $this->assertFalse(Util::parseHTTPDate($time), 'We used the string: ' . $time);
+ }
+
+ }
+
+ function testTimezones() {
+
+ $default = date_default_timezone_get();
+ date_default_timezone_set('Europe/Amsterdam');
+
+ $this->testParseHTTPDate();
+
+ date_default_timezone_set($default);
+
+ }
+
+ function testToHTTPDate() {
+
+ $dt = new \DateTime('2011-12-10 12:00:00 +0200');
+
+ $this->assertEquals(
+ 'Sat, 10 Dec 2011 10:00:00 GMT',
+ Util::toHTTPDate($dt)
+ );
+
+ }
+
+ function testStrtotimeFail() {
+
+ // Strtotime may return -1 when the date cannot be parsed.
+ // We are simulating this situation by testing a date that actually
+ // results in -1. (because I have found no other way to break this
+ // code)
+
+ $time = 'Wed, 13 Oct 1960 10:26:00 GMT';
+
+ $this->assertNull(Util::parseHTTPDate($time));
+
+ }
+}
diff --git a/vendor/sabre/dav/tests/Sabre/HTTP/VersionTest.php b/vendor/sabre/dav/tests/Sabre/HTTP/VersionTest.php
new file mode 100644
index 000000000..c7094b3bc
--- /dev/null
+++ b/vendor/sabre/dav/tests/Sabre/HTTP/VersionTest.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace Sabre\HTTP;
+
+class VersionTest extends \PHPUnit_Framework_TestCase {
+
+ function testString() {
+
+ $v = Version::VERSION;
+ $this->assertEquals(-1, version_compare('1.0.0',$v));
+
+ $s = Version::STABILITY;
+ $this->assertTrue($s == 'alpha' || $s == 'beta' || $s =='stable');
+
+ }
+
+}