1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\DAV\Browser; 4*a1a3b679SAndreas Boehler 5*a1a3b679SAndreas Boehleruse Sabre\DAV; 6*a1a3b679SAndreas Boehleruse Sabre\HTTP; 7*a1a3b679SAndreas Boehler 8*a1a3b679SAndreas Boehlerrequire_once 'Sabre/DAV/AbstractServer.php'; 9*a1a3b679SAndreas Boehler 10*a1a3b679SAndreas Boehlerclass PluginTest extends DAV\AbstractServer{ 11*a1a3b679SAndreas Boehler 12*a1a3b679SAndreas Boehler protected $plugin; 13*a1a3b679SAndreas Boehler 14*a1a3b679SAndreas Boehler function setUp() { 15*a1a3b679SAndreas Boehler 16*a1a3b679SAndreas Boehler parent::setUp(); 17*a1a3b679SAndreas Boehler $this->server->addPlugin($this->plugin = new Plugin()); 18*a1a3b679SAndreas Boehler $this->server->tree->getNodeForPath('')->createDirectory('dir2'); 19*a1a3b679SAndreas Boehler 20*a1a3b679SAndreas Boehler } 21*a1a3b679SAndreas Boehler 22*a1a3b679SAndreas Boehler function testCollectionGet() { 23*a1a3b679SAndreas Boehler 24*a1a3b679SAndreas Boehler $request = new HTTP\Request('GET', '/dir'); 25*a1a3b679SAndreas Boehler $this->server->httpRequest = $request; 26*a1a3b679SAndreas Boehler $this->server->exec(); 27*a1a3b679SAndreas Boehler 28*a1a3b679SAndreas Boehler $this->assertEquals(200, $this->response->getStatus(), "Incorrect status received. Full response body: " . $this->response->getBodyAsString()); 29*a1a3b679SAndreas Boehler $this->assertEquals( 30*a1a3b679SAndreas Boehler [ 31*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [DAV\Version::VERSION], 32*a1a3b679SAndreas Boehler 'Content-Type' => ['text/html; charset=utf-8'], 33*a1a3b679SAndreas Boehler 'Content-Security-Policy' => ["img-src 'self'; style-src 'self';"] 34*a1a3b679SAndreas Boehler ], 35*a1a3b679SAndreas Boehler $this->response->getHeaders() 36*a1a3b679SAndreas Boehler ); 37*a1a3b679SAndreas Boehler 38*a1a3b679SAndreas Boehler $body = $this->response->getBodyAsString(); 39*a1a3b679SAndreas Boehler $this->assertTrue(strpos($body, '<title>dir') !== false, $body); 40*a1a3b679SAndreas Boehler $this->assertTrue(strpos($body, '<a href="/dir/child.txt">')!==false); 41*a1a3b679SAndreas Boehler 42*a1a3b679SAndreas Boehler } 43*a1a3b679SAndreas Boehler 44*a1a3b679SAndreas Boehler /** 45*a1a3b679SAndreas Boehler * Adding the If-None-Match should have 0 effect, but it threw an error. 46*a1a3b679SAndreas Boehler */ 47*a1a3b679SAndreas Boehler function testCollectionGetIfNoneMatch() { 48*a1a3b679SAndreas Boehler 49*a1a3b679SAndreas Boehler $request = new HTTP\Request('GET', '/dir'); 50*a1a3b679SAndreas Boehler $request->setHeader('If-None-Match', '"foo-bar"'); 51*a1a3b679SAndreas Boehler $this->server->httpRequest = $request; 52*a1a3b679SAndreas Boehler $this->server->exec(); 53*a1a3b679SAndreas Boehler 54*a1a3b679SAndreas Boehler $this->assertEquals(200, $this->response->getStatus(), "Incorrect status received. Full response body: " . $this->response->getBodyAsString()); 55*a1a3b679SAndreas Boehler $this->assertEquals( 56*a1a3b679SAndreas Boehler [ 57*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [DAV\Version::VERSION], 58*a1a3b679SAndreas Boehler 'Content-Type' => ['text/html; charset=utf-8'], 59*a1a3b679SAndreas Boehler 'Content-Security-Policy' => ["img-src 'self'; style-src 'self';"] 60*a1a3b679SAndreas Boehler ], 61*a1a3b679SAndreas Boehler $this->response->getHeaders() 62*a1a3b679SAndreas Boehler ); 63*a1a3b679SAndreas Boehler 64*a1a3b679SAndreas Boehler $body = $this->response->getBodyAsString(); 65*a1a3b679SAndreas Boehler $this->assertTrue(strpos($body, '<title>dir') !== false, $body); 66*a1a3b679SAndreas Boehler $this->assertTrue(strpos($body, '<a href="/dir/child.txt">')!==false); 67*a1a3b679SAndreas Boehler 68*a1a3b679SAndreas Boehler } 69*a1a3b679SAndreas Boehler function testCollectionGetRoot() { 70*a1a3b679SAndreas Boehler 71*a1a3b679SAndreas Boehler $request = new HTTP\Request('GET', '/'); 72*a1a3b679SAndreas Boehler $this->server->httpRequest = ($request); 73*a1a3b679SAndreas Boehler $this->server->exec(); 74*a1a3b679SAndreas Boehler 75*a1a3b679SAndreas Boehler $this->assertEquals(200, $this->response->status, "Incorrect status received. Full response body: " . $this->response->getBodyAsString()); 76*a1a3b679SAndreas Boehler $this->assertEquals( 77*a1a3b679SAndreas Boehler [ 78*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [DAV\Version::VERSION], 79*a1a3b679SAndreas Boehler 'Content-Type' => ['text/html; charset=utf-8'], 80*a1a3b679SAndreas Boehler 'Content-Security-Policy' => ["img-src 'self'; style-src 'self';"] 81*a1a3b679SAndreas Boehler ], 82*a1a3b679SAndreas Boehler $this->response->getHeaders() 83*a1a3b679SAndreas Boehler ); 84*a1a3b679SAndreas Boehler 85*a1a3b679SAndreas Boehler $body = $this->response->getBodyAsString(); 86*a1a3b679SAndreas Boehler $this->assertTrue(strpos($body, '<title>/') !== false, $body); 87*a1a3b679SAndreas Boehler $this->assertTrue(strpos($body, '<a href="/dir/">')!==false); 88*a1a3b679SAndreas Boehler $this->assertTrue(strpos($body, '<span class="btn disabled">')!==false); 89*a1a3b679SAndreas Boehler 90*a1a3b679SAndreas Boehler } 91*a1a3b679SAndreas Boehler 92*a1a3b679SAndreas Boehler function testGETPassthru() { 93*a1a3b679SAndreas Boehler 94*a1a3b679SAndreas Boehler $request = new HTTP\Request('GET', '/random'); 95*a1a3b679SAndreas Boehler $response = new HTTP\Response(); 96*a1a3b679SAndreas Boehler $this->assertNull( 97*a1a3b679SAndreas Boehler $this->plugin->httpGet($request, $response) 98*a1a3b679SAndreas Boehler ); 99*a1a3b679SAndreas Boehler 100*a1a3b679SAndreas Boehler } 101*a1a3b679SAndreas Boehler 102*a1a3b679SAndreas Boehler function testPostOtherContentType() { 103*a1a3b679SAndreas Boehler 104*a1a3b679SAndreas Boehler $request = new HTTP\Request('POST', '/', ['Content-Type' => 'text/xml']); 105*a1a3b679SAndreas Boehler $this->server->httpRequest = $request; 106*a1a3b679SAndreas Boehler $this->server->exec(); 107*a1a3b679SAndreas Boehler 108*a1a3b679SAndreas Boehler $this->assertEquals(501, $this->response->status); 109*a1a3b679SAndreas Boehler 110*a1a3b679SAndreas Boehler } 111*a1a3b679SAndreas Boehler 112*a1a3b679SAndreas Boehler function testPostNoSabreAction() { 113*a1a3b679SAndreas Boehler 114*a1a3b679SAndreas Boehler $request = new HTTP\Request('POST', '/', ['Content-Type' => 'application/x-www-form-urlencoded']); 115*a1a3b679SAndreas Boehler $request->setPostData([]); 116*a1a3b679SAndreas Boehler $this->server->httpRequest = $request; 117*a1a3b679SAndreas Boehler $this->server->exec(); 118*a1a3b679SAndreas Boehler 119*a1a3b679SAndreas Boehler $this->assertEquals(501, $this->response->status); 120*a1a3b679SAndreas Boehler 121*a1a3b679SAndreas Boehler } 122*a1a3b679SAndreas Boehler 123*a1a3b679SAndreas Boehler function testPostMkCol() { 124*a1a3b679SAndreas Boehler 125*a1a3b679SAndreas Boehler $serverVars = array( 126*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/', 127*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'POST', 128*a1a3b679SAndreas Boehler 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', 129*a1a3b679SAndreas Boehler ); 130*a1a3b679SAndreas Boehler $postVars = array( 131*a1a3b679SAndreas Boehler 'sabreAction' => 'mkcol', 132*a1a3b679SAndreas Boehler 'name' => 'new_collection', 133*a1a3b679SAndreas Boehler ); 134*a1a3b679SAndreas Boehler 135*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray($serverVars); 136*a1a3b679SAndreas Boehler $request->setPostData($postVars); 137*a1a3b679SAndreas Boehler $this->server->httpRequest = $request; 138*a1a3b679SAndreas Boehler $this->server->exec(); 139*a1a3b679SAndreas Boehler 140*a1a3b679SAndreas Boehler $this->assertEquals(302, $this->response->status); 141*a1a3b679SAndreas Boehler $this->assertEquals(array( 142*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [DAV\Version::VERSION], 143*a1a3b679SAndreas Boehler 'Location' => ['/'], 144*a1a3b679SAndreas Boehler ), $this->response->getHeaders()); 145*a1a3b679SAndreas Boehler 146*a1a3b679SAndreas Boehler $this->assertTrue(is_dir(SABRE_TEMPDIR . '/new_collection')); 147*a1a3b679SAndreas Boehler 148*a1a3b679SAndreas Boehler } 149*a1a3b679SAndreas Boehler 150*a1a3b679SAndreas Boehler function testGetAsset() { 151*a1a3b679SAndreas Boehler 152*a1a3b679SAndreas Boehler $request = new HTTP\Request('GET', '/?sabreAction=asset&assetName=favicon.ico'); 153*a1a3b679SAndreas Boehler $this->server->httpRequest = $request; 154*a1a3b679SAndreas Boehler $this->server->exec(); 155*a1a3b679SAndreas Boehler 156*a1a3b679SAndreas Boehler $this->assertEquals(200, $this->response->getStatus(), 'Error: ' . $this->response->body); 157*a1a3b679SAndreas Boehler $this->assertEquals([ 158*a1a3b679SAndreas Boehler 'X-Sabre-Version' => [DAV\Version::VERSION], 159*a1a3b679SAndreas Boehler 'Content-Type' => ['image/vnd.microsoft.icon'], 160*a1a3b679SAndreas Boehler 'Content-Length' => ['4286'], 161*a1a3b679SAndreas Boehler 'Cache-Control' => ['public, max-age=1209600'], 162*a1a3b679SAndreas Boehler 'Content-Security-Policy' => ["img-src 'self'; style-src 'self';"] 163*a1a3b679SAndreas Boehler ], $this->response->getHeaders()); 164*a1a3b679SAndreas Boehler 165*a1a3b679SAndreas Boehler } 166*a1a3b679SAndreas Boehler 167*a1a3b679SAndreas Boehler function testGetAsset404() { 168*a1a3b679SAndreas Boehler 169*a1a3b679SAndreas Boehler $request = new HTTP\Request('GET', '/?sabreAction=asset&assetName=flavicon.ico'); 170*a1a3b679SAndreas Boehler $this->server->httpRequest = $request; 171*a1a3b679SAndreas Boehler $this->server->exec(); 172*a1a3b679SAndreas Boehler 173*a1a3b679SAndreas Boehler $this->assertEquals(404, $this->response->getStatus(), 'Error: ' . $this->response->body); 174*a1a3b679SAndreas Boehler 175*a1a3b679SAndreas Boehler } 176*a1a3b679SAndreas Boehler 177*a1a3b679SAndreas Boehler function testGetAssetEscapeBasePath() { 178*a1a3b679SAndreas Boehler 179*a1a3b679SAndreas Boehler $request = new HTTP\Request('GET', '/?sabreAction=asset&assetName=./../assets/favicon.ico'); 180*a1a3b679SAndreas Boehler $this->server->httpRequest = $request; 181*a1a3b679SAndreas Boehler $this->server->exec(); 182*a1a3b679SAndreas Boehler 183*a1a3b679SAndreas Boehler $this->assertEquals(404, $this->response->getStatus(), 'Error: ' . $this->response->body); 184*a1a3b679SAndreas Boehler 185*a1a3b679SAndreas Boehler } 186*a1a3b679SAndreas Boehler} 187