TYPO3 CMS  TYPO3_7-6
SimpleLockStrategyTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
25 {
30  {
32  new SimpleLockStrategy('999999999');
33  $this->assertTrue(is_dir(PATH_site . SimpleLockStrategy::FILE_LOCK_FOLDER));
34  }
35 
40  {
41  $lock = $this->getAccessibleMock(SimpleLockStrategy::class, ['dummy'], ['999999999']);
42  $this->assertSame(PATH_site . SimpleLockStrategy::FILE_LOCK_FOLDER . 'simple_' . md5('999999999'), $lock->_get('filePath'));
43  }
44 
48  public function acquireFixesPermissionsOnLockFile()
49  {
50  if (TYPO3_OS === 'WIN') {
51  $this->markTestSkipped('Test not available on Windows.');
52  }
53  // Use a very high id to be unique
55  $lock = $this->getAccessibleMock(SimpleLockStrategy::class, ['dummy'], ['999999999']);
56 
57  $pathOfLockFile = $lock->_get('filePath');
58 
59  $GLOBALS['TYPO3_CONF_VARS']['SYS']['fileCreateMask'] = '0777';
60 
61  // Acquire lock, get actual file permissions and clean up
62  $lock->acquire();
63  clearstatcache();
64  $resultFilePermissions = substr(decoct(fileperms($pathOfLockFile)), 2);
65  $lock->release();
66  $this->assertEquals($resultFilePermissions, '0777');
67  }
68 
72  public function releaseRemovesLockfileInTypo3TempLocks()
73  {
75  $lock = $this->getAccessibleMock(SimpleLockStrategy::class, ['dummy'], ['999999999']);
76 
77  $pathOfLockFile = $lock->_get('filePath');
78 
79  $lock->acquire();
80  $lock->release();
81 
82  $this->assertFalse(is_file($pathOfLockFile));
83  }
84 
88  public function invalidFileReferences()
89  {
90  return [
91  'not withing PATH_site' => ['/tmp/TYPO3-Lock-Test'],
92  'directory traversal' => [PATH_site . 'typo3temp/../typo3temp/locks/foo'],
93  'directory traversal 2' => [PATH_site . 'typo3temp/locks/../locks/foo'],
94  'within uploads' => [PATH_site . 'uploads/TYPO3-Lock-Test']
95  ];
96  }
97 
104  public function releaseDoesNotRemoveFilesNotWithinTypo3TempLocksDirectory($file)
105  {
106  if (TYPO3_OS === 'WIN') {
107  $this->markTestSkipped('releaseDoesNotRemoveFilesNotWithinTypo3TempLocksDirectory() test not available on Windows.');
108  }
109  // Create test file
110  touch($file);
111  if (!is_file($file)) {
112  $this->markTestIncomplete('releaseDoesNotRemoveFilesNotWithinTypo3TempLocksDirectory() skipped: Test file could not be created');
113  }
114  // Create instance, set lock file to invalid path
116  $lock = $this->getAccessibleMock(SimpleLockStrategy::class, ['dummy'], ['999999999']);
117  $lock->_set('filePath', $file);
118  $lock->_set('isAcquired', true);
119 
120  // Call release method
121  $lock->release();
122  // Check if file is still there and clean up
123  $fileExists = is_file($file);
124  if (is_file($file)) {
125  unlink($file);
126  }
127  $this->assertTrue($fileExists);
128  }
129 }
static rmdir($path, $removeNonEmpty=false)
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']