Merge "RequestContext: Load the request object for getRequest on first call"
[lhc/web/wiklou.git] / tests / phpunit / includes / media / XMPTest.php
index 798e492..6758e94 100644 (file)
@@ -62,6 +62,8 @@ class XMPTest extends MediaWikiTestCase {
                        array( 'gps', 'Handling of exif GPS parameters in XMP' ),
                );
 
+               $xmpFiles[] = array( 'doctype-included', 'XMP includes doctype' );
+
                foreach ( $xmpFiles as $file ) {
                        $xmp = file_get_contents( $xmpPath . $file[0] . '.xmp' );
                        // I'm not sure if this is the best way to handle getting the
@@ -170,4 +172,52 @@ class XMPTest extends MediaWikiTestCase {
 
                $this->assertEquals( $expected, $actual );
        }
+
+       /**
+        * Test for multi-section, hostile XML
+        * @covers checkParseSafety
+        */
+       public function testCheckParseSafety() {
+
+               // Test for detection
+               $xmpPath = __DIR__ . '/../../data/xmp/';
+               $file = fopen( $xmpPath . 'doctype-included.xmp', 'rb' );
+               $valid = false;
+               $reader = new XMPReader();
+               do {
+                       $chunk = fread( $file, 10 );
+                       $valid = $reader->parse( $chunk, feof( $file ) );
+               } while ( !feof( $file ) );
+               $this->assertFalse( $valid, 'Check that doctype is detected in fragmented XML' );
+               $this->assertEquals(
+                       array(),
+                       $reader->getResults(),
+                       'Check that doctype is detected in fragmented XML'
+               );
+               fclose( $file );
+               unset( $reader );
+
+               // Test for false positives
+               $file = fopen( $xmpPath . 'doctype-not-included.xmp', 'rb' );
+               $valid = false;
+               $reader = new XMPReader();
+               do {
+                       $chunk = fread( $file, 10 );
+                       $valid = $reader->parse( $chunk, feof( $file ) );
+               } while ( !feof( $file ) );
+               $this->assertTrue(
+                       $valid,
+                       'Check for false-positive detecting doctype in fragmented XML'
+               );
+               $this->assertEquals(
+                       array(
+                               'xmp-exif' => array(
+                                       'DigitalZoomRatio' => '0/10',
+                                       'Flash' => '9'
+                               )
+                       ),
+                       $reader->getResults(),
+                       'Check that doctype is detected in fragmented XML'
+               );
+       }
 }