Fixed bug #17490: After introducing the locking in #17289 no CSRF token will ever...
[Packages/TYPO3.CMS.git] / tests / t3lib / t3lib_divTest.php
index 7779bcd..f3fec1a 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2009-2010 Ingo Renner <ingo@typo3.org>
+*  (c) 2009-2011 Ingo Renner <ingo@typo3.org>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -766,6 +766,40 @@ class t3lib_divTest extends tx_phpunit_testcase {
                $this->assertEquals('/', $result[strlen($result) - 1]);
        }
 
+       /**
+        * @return array
+        */
+       public static function hostnameAndPortDataProvider() {
+               return array(
+                       'localhost ipv4 without port' => array('127.0.0.1', '127.0.0.1', ''),
+                       'localhost ipv4 with port' => array('127.0.0.1:81', '127.0.0.1', '81'),
+                       'localhost ipv6 without port' => array('[::1]', '[::1]', ''),
+                       'localhost ipv6 with port' => array('[::1]:81', '[::1]', '81'),
+                       'ipv6 without port' => array('[2001:DB8::1]', '[2001:DB8::1]', ''),
+                       'ipv6 with port' => array('[2001:DB8::1]:81', '[2001:DB8::1]', '81'),
+                       'hostname without port' => array('lolli.did.this', 'lolli.did.this', ''),
+                       'hostname with port' => array('lolli.did.this:42', 'lolli.did.this', '42'),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider hostnameAndPortDataProvider
+        */
+       public function getIndpEnvTypo3HostOnlyParsesHostnamesAndIpAdresses($httpHost, $expectedIp) {
+               $_SERVER['HTTP_HOST'] = $httpHost;
+               $this->assertEquals($expectedIp, t3lib_div::getIndpEnv('TYPO3_HOST_ONLY'));
+       }
+
+       /**
+        * @test
+        * @dataProvider hostnameAndPortDataProvider
+        */
+       public function getIndpEnvTypo3PortParsesHostnamesAndIpAdresses($httpHost, $dummy, $expectedPort) {
+               $_SERVER['HTTP_HOST'] = $httpHost;
+               $this->assertEquals($expectedPort, t3lib_div::getIndpEnv('TYPO3_PORT'));
+       }
+
 
        //////////////////////////////////
        // Tests concerning underscoredToUpperCamelCase
@@ -1606,6 +1640,32 @@ class t3lib_divTest extends tx_phpunit_testcase {
        /**
         * @test
         */
+       public function fixPermissionsCorrectlySetsGroup() {
+               if (TYPO3_OS == 'WIN') {
+                       $this->markTestSkipped('fixPermissionsCorrectlySetsGroupOwnerOfFile() tests not available on Windows');
+               }
+               if (!function_exists('posix_getegid')) {
+                       $this->markTestSkipped('Function posix_getegid() not available, fixPermissionsCorrectlySetsGroupOwnerOfFile() tests skipped');
+               }
+
+                       // Create and prepare test file
+               $filename = PATH_site . 'typo3temp/' . uniqid('test_');
+               t3lib_div::writeFileToTypo3tempDir($filename, '42');
+
+                       // Set target group and run method
+               $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid();
+               $fixPermissionsResult = t3lib_div::fixPermissions($filename);
+
+               clearstatcache();
+               $resultFileGroup = filegroup($filename);
+               unlink($filename);
+
+               $this->assertEquals($resultFileGroup, posix_getegid());
+       }
+
+       /**
+        * @test
+        */
        public function fixPermissionsCorrectlySetsPermissionsToFile() {
                if (TYPO3_OS == 'WIN') {
                        $this->markTestSkipped('fixPermissions() tests not available on Windows');
@@ -1618,19 +1678,16 @@ class t3lib_divTest extends tx_phpunit_testcase {
 
                        // Set target permissions and run method
                $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660';
-               $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid();
                $fixPermissionsResult = t3lib_div::fixPermissions($filename);
 
                        // Get actual permissions and clean up
                clearstatcache();
                $resultFilePermissions = substr(decoct(fileperms($filename)), 2);
-               $resultFileGroup = filegroup($filename);
                unlink($filename);
 
                        // Test if everything was ok
                $this->assertTrue($fixPermissionsResult);
                $this->assertEquals($resultFilePermissions, '0660');
-               $this->assertEquals($resultFileGroup, posix_getegid());
        }
 
        /**
@@ -1648,19 +1705,16 @@ class t3lib_divTest extends tx_phpunit_testcase {
 
                        // Set target permissions and run method
                $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660';
-               $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid();
                $fixPermissionsResult = t3lib_div::fixPermissions($filename);
 
                        // Get actual permissions and clean up
                clearstatcache();
                $resultFilePermissions = substr(decoct(fileperms($filename)), 2);
-               $resultFileGroup = filegroup($filename);
                unlink($filename);
 
                        // Test if everything was ok
                $this->assertTrue($fixPermissionsResult);
                $this->assertEquals($resultFilePermissions, '0660');
-               $this->assertEquals($resultFileGroup, posix_getegid());
        }
 
        /**
@@ -1678,19 +1732,16 @@ class t3lib_divTest extends tx_phpunit_testcase {
 
                        // Set target permissions and run method
                $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0770';
-               $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid();
                $fixPermissionsResult = t3lib_div::fixPermissions($directory . '/');
 
                        // Get actual permissions and clean up
                clearstatcache();
                $resultDirectoryPermissions = substr(decoct(fileperms($directory)), 1);
-               $resultDirectoryGroup = filegroup($directory);
                t3lib_div::rmdir($directory);
 
                        // Test if everything was ok
                $this->assertTrue($fixPermissionsResult);
                $this->assertEquals($resultDirectoryPermissions, '0770');
-               $this->assertEquals($resultDirectoryGroup, posix_getegid());
        }
 
        /**
@@ -1708,19 +1759,16 @@ class t3lib_divTest extends tx_phpunit_testcase {
 
                        // Set target permissions and run method
                $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0770';
-               $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid();
                $fixPermissionsResult = t3lib_div::fixPermissions($directory);
 
                        // Get actual permissions and clean up
                clearstatcache();
                $resultDirectoryPermissions = substr(decoct(fileperms($directory)), 1);
-               $resultDirectoryGroup = filegroup($directory);
                t3lib_div::rmdir($directory);
 
                        // Test if everything was ok
                $this->assertTrue($fixPermissionsResult);
                $this->assertEquals($resultDirectoryPermissions, '0770');
-               $this->assertEquals($resultDirectoryGroup, posix_getegid());
        }
 
        /**
@@ -1754,25 +1802,17 @@ class t3lib_divTest extends tx_phpunit_testcase {
                        // Set target permissions and run method
                $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660';
                $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0770';
-               $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid();
                $fixPermissionsResult = t3lib_div::fixPermissions($baseDirectory, TRUE);
 
                        // Get actual permissions
                clearstatcache();
                $resultBaseDirectoryPermissions = substr(decoct(fileperms($baseDirectory)), 1);
-               $resultBaseDirectoryGroup = filegroup($baseDirectory);
                $resultBaseFilePermissions = substr(decoct(fileperms($baseDirectory . '/file')), 2);
-               $resultBaseFileGroup = filegroup($baseDirectory . '/file');
                $resultFooDirectoryPermissions = substr(decoct(fileperms($baseDirectory . '/foo')), 1);
-               $resultFooDirectoryGroup = filegroup($baseDirectory . '/foo');
                $resultFooFilePermissions = substr(decoct(fileperms($baseDirectory . '/foo/file')), 2);
-               $resultFooFileGroup = filegroup($baseDirectory . '/foo/file');
                $resultBarDirectoryPermissions = substr(decoct(fileperms($baseDirectory . '/.bar')), 1);
-               $resultBarDirectoryGroup = filegroup($baseDirectory . '/.bar');
                $resultBarFilePermissions = substr(decoct(fileperms($baseDirectory . '/.bar/.file')), 2);
-               $resultBarFileGroup = filegroup($baseDirectory . '/.bar/.file');
                $resultBarFile2Permissions = substr(decoct(fileperms($baseDirectory . '/.bar/..file2')), 2);
-               $resultBarFile2Group = filegroup($baseDirectory . '/.bar/..file2');
 
                        // Clean up
                unlink($baseDirectory . '/file');
@@ -1786,19 +1826,12 @@ class t3lib_divTest extends tx_phpunit_testcase {
                        // Test if everything was ok
                $this->assertTrue($fixPermissionsResult);
                $this->assertEquals($resultBaseDirectoryPermissions, '0770');
-               $this->assertEquals($resultBaseDirectoryGroup, posix_getegid());
                $this->assertEquals($resultBaseFilePermissions, '0660');
-               $this->assertEquals($resultBaseFileGroup, posix_getegid());
                $this->assertEquals($resultFooDirectoryPermissions, '0770');
-               $this->assertEquals($resultFooDirectoryGroup, posix_getegid());
                $this->assertEquals($resultFooFilePermissions, '0660');
-               $this->assertEquals($resultFooFileGroup, posix_getegid());
                $this->assertEquals($resultBarDirectoryPermissions, '0770');
-               $this->assertEquals($resultBarDirectoryGroup, posix_getegid());
                $this->assertEquals($resultBarFilePermissions, '0660');
-               $this->assertEquals($resultBarFileGroup, posix_getegid());
                $this->assertEquals($resultBarFile2Permissions, '0660');
-               $this->assertEquals($resultBarFile2Group, posix_getegid());
        }
 
        /**
@@ -1825,7 +1858,32 @@ class t3lib_divTest extends tx_phpunit_testcase {
 
                        // Test if everything was ok
                $this->assertFalse($fixPermissionsResult);
-               $this->assertEquals($resultFilePermissions, '0742');
+       }
+
+       /**
+        * @test
+        */
+       public function fixPermissionsSetsPermissionsWithRelativeFileReference() {
+               if (TYPO3_OS == 'WIN') {
+                       $this->markTestSkipped('fixPermissions() tests not available on Windows');
+               }
+
+               $filename = 'typo3temp/' . uniqid('test_');
+               t3lib_div::writeFileToTypo3tempDir(PATH_site . $filename, '42');
+               chmod($filename, 0742);
+
+                       // Set target permissions and run method
+               $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660';
+               $fixPermissionsResult = t3lib_div::fixPermissions($filename);
+
+                       // Get actual permissions and clean up
+               clearstatcache();
+               $resultFilePermissions = substr(decoct(fileperms(PATH_site . $filename)), 2);
+               unlink(PATH_site . $filename);
+
+                       // Test if everything was ok
+               $this->assertTrue($fixPermissionsResult);
+               $this->assertEquals($resultFilePermissions, '0660');
        }