[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/aphront/sink/__tests__/ -> AphrontHTTPSinkTestCase.php (source)

   1  <?php
   2  
   3  final class AphrontHTTPSinkTestCase extends PhabricatorTestCase {
   4  
   5    public function testHTTPSinkBasics() {
   6      $sink = new AphrontIsolatedHTTPSink();
   7      $sink->writeHTTPStatus(200);
   8      $sink->writeHeaders(array(array('X-Test', 'test')));
   9      $sink->writeData('test');
  10  
  11      $this->assertEqual(200, $sink->getEmittedHTTPStatus());
  12      $this->assertEqual(
  13        array(array('X-Test', 'test')),
  14        $sink->getEmittedHeaders());
  15      $this->assertEqual('test', $sink->getEmittedData());
  16    }
  17  
  18    public function testHTTPSinkStatusCode() {
  19      $input = $this->tryTestCaseMap(
  20        array(
  21          200     => true,
  22          '201'   => true,
  23          1       => false,
  24          1000    => false,
  25          'apple' => false,
  26          ''      => false,
  27        ),
  28        array($this, 'tryHTTPSinkStatusCode'));
  29    }
  30  
  31    protected function tryHTTPSinkStatusCode($input) {
  32      $sink = new AphrontIsolatedHTTPSink();
  33      $sink->writeHTTPStatus($input);
  34    }
  35  
  36    public function testHTTPSinkResponseSplitting() {
  37      $input = $this->tryTestCaseMap(
  38        array(
  39          'test'      => true,
  40          "test\nx"   => false,
  41          "test\rx"   => false,
  42          "test\0x"   => false,
  43        ),
  44        array($this, 'tryHTTPSinkResponseSplitting'));
  45    }
  46  
  47    protected function tryHTTPSinkResponseSplitting($input) {
  48      $sink = new AphrontIsolatedHTTPSink();
  49      $sink->writeHeaders(array(array('X-Test', $input)));
  50    }
  51  
  52    public function testHTTPHeaderNames() {
  53      $input = $this->tryTestCaseMap(
  54        array(
  55          'test'  => true,
  56          'test:' => false,
  57        ),
  58        array($this, 'tryHTTPHeaderNames'));
  59    }
  60  
  61    protected function tryHTTPHeaderNames($input) {
  62      $sink = new AphrontIsolatedHTTPSink();
  63      $sink->writeHeaders(array(array($input, 'value')));
  64    }
  65  
  66    public function testJSONContentSniff() {
  67      $response = id(new AphrontJSONResponse())
  68        ->setContent(
  69          array(
  70            'x' => '<iframe>',
  71          ));
  72      $sink = new AphrontIsolatedHTTPSink();
  73      $sink->writeResponse($response);
  74  
  75      $this->assertEqual(
  76        'for (;;);{"x":"\u003ciframe\u003e"}',
  77        $sink->getEmittedData(),
  78        'JSONResponse should prevent content-sniffing attacks.');
  79    }
  80  
  81  
  82  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1