Commit 6361660f authored by Benni Mack's avatar Benni Mack Committed by Susanne Moog
Browse files

[FEATURE] Use dynamic path for typo3temp/var/

All TYPO3 Core areas where typo3temp/var/ was directly used,
the new Environment::getVarPath() API is now used.

When running via composer or setting the environment
variable "TYPO3_PATH_APP", the folder is $projectRootPath . /var
otherwise "typo3temp/var/" as before.

Additional changes to the default naming scheme
- Cache folders are now named lower-case (Cache/Code becomes
cache/code). 
- Install tool session files are stored within "var/session" instead of
"var/InstallToolSessions".
- Extension Manager files are now within "var/extensionmanager"
in a lower-cased variant
- log files are now placed into "var/log" instead of "var/logs"
- lock files are now placed into "var/lock" instead of "var/locks"

Resolves: #84545
Releases: master
Change-Id: Ifa57413cd212243387532ffb3435cfca361a582b
Reviewed-on: https://review.typo3.org/56413


Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: Susanne Moog's avatarSusanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog's avatarSusanne Moog <susanne.moog@typo3.org>
parent 084a75e4
......@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Cache\Backend;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Service\OpcodeCacheService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
......@@ -76,13 +77,13 @@ class SimpleFileBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBackend im
parent::setCache($cache);
if (empty($this->temporaryCacheDirectory)) {
// If no cache directory was given with cacheDirectory
// configuration option, set it to a path below typo3temp/var/
$temporaryCacheDirectory = PATH_site . 'typo3temp/var/';
// configuration option, set it to a path below var/ folder
$temporaryCacheDirectory = Environment::getVarPath() . '/';
} else {
$temporaryCacheDirectory = $this->temporaryCacheDirectory;
}
$codeOrData = $cache instanceof \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend ? 'Code' : 'Data';
$finalCacheDirectory = $temporaryCacheDirectory . 'Cache/' . $codeOrData . '/' . $this->cacheIdentifier . '/';
$codeOrData = $cache instanceof \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend ? 'code' : 'data';
$finalCacheDirectory = $temporaryCacheDirectory . 'cache/' . $codeOrData . '/' . $this->cacheIdentifier . '/';
if (!is_dir($finalCacheDirectory)) {
$this->createFinalCacheDirectory($finalCacheDirectory);
}
......
......@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Charset;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -643,7 +644,7 @@ class CharsetConverter implements SingletonInterface
if ($charset && GeneralUtility::validPathStr($charsetConvTableFile) && @is_file($charsetConvTableFile)) {
// Cache file for charsets:
// Caching brought parsing time for gb2312 down from 2400 ms to 150 ms. For other charsets we are talking 11 ms down to zero.
$cacheFile = GeneralUtility::getFileAbsFileName('typo3temp/var/charset/charset_' . $charset . '.tbl');
$cacheFile = Environment::getVarPath() . '/charset/charset_' . $charset . '.tbl';
if ($cacheFile && @is_file($cacheFile)) {
$this->parsedCharsets[$charset] = unserialize(file_get_contents($cacheFile));
} else {
......@@ -702,8 +703,8 @@ class CharsetConverter implements SingletonInterface
public function initUnicodeData($mode = null)
{
// Cache files
$cacheFileCase = GeneralUtility::getFileAbsFileName('typo3temp/var/charset/cscase_utf-8.tbl');
$cacheFileASCII = GeneralUtility::getFileAbsFileName('typo3temp/var/charset/csascii_utf-8.tbl');
$cacheFileCase = Environment::getVarPath() . '/charset/cscase_utf-8.tbl';
$cacheFileASCII = Environment::getVarPath() . '/charset/csascii_utf-8.tbl';
// Only process if the tables are not yet loaded
switch ($mode) {
case 'case':
......@@ -943,7 +944,7 @@ class CharsetConverter implements SingletonInterface
return 1;
}
// Use cached version if possible
$cacheFile = GeneralUtility::getFileAbsFileName('typo3temp/var/charset/cscase_' . $charset . '.tbl');
$cacheFile = Environment::getVarPath() . '/charset/cscase_' . $charset . '.tbl';
if ($cacheFile && @is_file($cacheFile)) {
$this->caseFolding[$charset] = unserialize(file_get_contents($cacheFile));
return 2;
......@@ -1005,7 +1006,7 @@ class CharsetConverter implements SingletonInterface
return 1;
}
// Use cached version if possible
$cacheFile = GeneralUtility::getFileAbsFileName('typo3temp/var/charset/csascii_' . $charset . '.tbl');
$cacheFile = Environment::getVarPath() . '/charset/csascii_' . $charset . '.tbl';
if ($cacheFile && @is_file($cacheFile)) {
$this->toASCII[$charset] = unserialize(file_get_contents($cacheFile));
return 2;
......
......@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Core\Imaging;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Charset\CharsetConverter;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\CommandUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
......@@ -1922,8 +1923,8 @@ class GraphicalFunctions
*/
public function randomName()
{
GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/var/transient/');
return PATH_site . 'typo3temp/var/transient/' . md5(uniqid('', true));
GeneralUtility::mkdir_deep(Environment::getVarPath() . '/transient/');
return Environment::getVarPath() . '/transient/' . md5(uniqid('', true));
}
/**
......
......@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Locking;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Locking\Exception\LockAcquireException;
use TYPO3\CMS\Core\Locking\Exception\LockAcquireWouldBlockException;
use TYPO3\CMS\Core\Locking\Exception\LockCreateException;
......@@ -24,7 +25,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
*/
class FileLockStrategy implements LockingStrategyInterface
{
const FILE_LOCK_FOLDER = 'typo3temp/var/locks/';
const FILE_LOCK_FOLDER = 'lock/';
/**
* @var resource File pointer if using flock method
......@@ -50,9 +51,9 @@ class FileLockStrategy implements LockingStrategyInterface
/*
* Tests if the directory for simple locks is available.
* If not, the directory will be created. The lock path is usually
* below typo3temp/var, typo3temp/var itself should exist already
* below typo3temp/var, typo3temp/var itself should exist already (or root-path/var/ respectively)
*/
$path = PATH_site . self::FILE_LOCK_FOLDER;
$path = Environment::getVarPath() . '/' . self::FILE_LOCK_FOLDER;
if (!is_dir($path)) {
// Not using mkdir_deep on purpose here, if typo3temp itself
// does not exist, this issue should be solved on a different
......
......@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Locking;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Locking\Exception\LockAcquireException;
use TYPO3\CMS\Core\Locking\Exception\LockCreateException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -23,7 +24,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
*/
class SemaphoreLockStrategy implements LockingStrategyInterface
{
const FILE_LOCK_FOLDER = 'typo3temp/var/locks/';
const FILE_LOCK_FOLDER = 'lock/';
/**
* @var mixed Identifier used for this lock
......@@ -51,7 +52,7 @@ class SemaphoreLockStrategy implements LockingStrategyInterface
*/
public function __construct($subject)
{
$path = PATH_site . self::FILE_LOCK_FOLDER;
$path = Environment::getVarPath() . '/' . self::FILE_LOCK_FOLDER;
if (!is_dir($path)) {
// Not using mkdir_deep on purpose here, if typo3temp/var itself
// does not exist, this issue should be solved on a different
......
......@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Locking;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Locking\Exception\LockAcquireWouldBlockException;
use TYPO3\CMS\Core\Locking\Exception\LockCreateException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -23,7 +24,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
*/
class SimpleLockStrategy implements LockingStrategyInterface
{
const FILE_LOCK_FOLDER = 'typo3temp/var/locks/';
const FILE_LOCK_FOLDER = 'lock/';
/**
* @var string File path used for this lock
......@@ -53,8 +54,8 @@ class SimpleLockStrategy implements LockingStrategyInterface
{
// Tests if the directory for simple locks is available.
// If not, the directory will be created. The lock path is usually
// below typo3temp/var, typo3temp/var itself should exist already
$path = PATH_site . self::FILE_LOCK_FOLDER;
// below typo3temp/var, typo3temp/var itself should exist already (or getProjectPath . /var/ respectively)
$path = Environment::getVarPath() . '/' . self::FILE_LOCK_FOLDER;
if (!is_dir($path)) {
// Not using mkdir_deep on purpose here, if typo3temp/var itself
// does not exist, this issue should be solved on a different
......@@ -102,7 +103,7 @@ class SimpleLockStrategy implements LockingStrategyInterface
$success = true;
if (
GeneralUtility::isAllowedAbsPath($this->filePath)
&& GeneralUtility::isFirstPartOfStr($this->filePath, PATH_site . self::FILE_LOCK_FOLDER)
&& GeneralUtility::isFirstPartOfStr($this->filePath, Environment::getVarPath() . '/' . self::FILE_LOCK_FOLDER)
) {
if (@unlink($this->filePath) === false) {
$success = false;
......
......@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Log\Writer;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Log\Exception\InvalidLogWriterConfigurationException;
use TYPO3\CMS\Core\Log\LogLevel;
use TYPO3\CMS\Core\Log\LogRecord;
......@@ -37,7 +38,7 @@ class FileWriter extends AbstractWriter
*
* @var string
*/
protected $defaultLogFileTemplate = 'typo3temp/var/logs/typo3_%s.log';
protected $defaultLogFileTemplate = '/log/typo3_%s.log';
/**
* Log file handle storage
......@@ -232,6 +233,6 @@ class FileWriter extends AbstractWriter
*/
protected function getDefaultLogFileName()
{
return sprintf($this->defaultLogFileTemplate, substr(GeneralUtility::hmac($this->defaultLogFileTemplate, 'defaultLogFile'), 0, 10));
return Environment::getVarPath() . sprintf($this->defaultLogFileTemplate, substr(GeneralUtility::hmac($this->defaultLogFileTemplate, 'defaultLogFile'), 0, 10));
}
}
......@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Resource\OnlineMedia\Helpers;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Resource\DuplicationBehavior;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\Folder;
......@@ -118,7 +119,7 @@ abstract class AbstractOnlineMediaHelper implements OnlineMediaHelperInterface
*/
protected function getTempFolderPath()
{
$path = PATH_site . 'typo3temp/var/transient/';
$path = Environment::getVarPath() . '/transient/';
if (!is_dir($path)) {
GeneralUtility::mkdir_deep($path);
}
......
......@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Resource\OnlineMedia\Processing;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Imaging\GraphicalFunctions;
use TYPO3\CMS\Core\Resource\Driver\DriverInterface;
use TYPO3\CMS\Core\Resource\File;
......@@ -77,7 +78,7 @@ class PreviewProcessing
if (empty($temporaryFileName) || !file_exists($temporaryFileName)) {
return;
}
$temporaryFileNameForResizedThumb = uniqid(PATH_site . 'typo3temp/var/transient/online_media_' . $file->getHashedIdentifier()) . '.jpg';
$temporaryFileNameForResizedThumb = uniqid(Environment::getVarPath() . '/transient/online_media_' . $file->getHashedIdentifier()) . '.jpg';
$configuration = $processedFile->getProcessingConfiguration();
switch ($taskType) {
case ProcessedFile::CONTEXT_IMAGEPREVIEW:
......
......@@ -19,6 +19,7 @@ use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use TYPO3\CMS\Core\Core\ApplicationContext;
use TYPO3\CMS\Core\Core\ClassLoadingInformation;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Http\RequestFactory;
use TYPO3\CMS\Core\Log\LogLevel;
use TYPO3\CMS\Core\Log\LogManager;
......@@ -3076,7 +3077,7 @@ class GeneralUtility
} elseif (!static::isAbsPath($filename)) {
// is relative. Prepended with PATH_site
$filename = PATH_site . $filename;
} elseif (!static::isFirstPartOfStr($filename, PATH_site)) {
} elseif (!static::isFirstPartOfStr($filename, Environment::getProjectPath())) {
// absolute, but set to blank if not allowed
$filename = '';
}
......@@ -3125,7 +3126,7 @@ class GeneralUtility
{
$lockRootPath = $GLOBALS['TYPO3_CONF_VARS']['BE']['lockRootPath'];
return static::isAbsPath($path) && static::validPathStr($path)
&& (static::isFirstPartOfStr($path, PATH_site)
&& (static::isFirstPartOfStr($path, Environment::getProjectPath())
|| $lockRootPath && static::isFirstPartOfStr($path, $lockRootPath));
}
......@@ -3243,7 +3244,7 @@ class GeneralUtility
}
/**
* Will move an uploaded file (normally in "/tmp/xxxxx") to a temporary filename in PATH_site."typo3temp/" from where TYPO3 can use it.
* Will move an uploaded file (normally in "/tmp/xxxxx") to a temporary filename in Environment::getProjectPath() . "var/" from where TYPO3 can use it.
* Use this function to move uploaded files to where you can work on them.
* REMEMBER to use \TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile() afterwards - otherwise temp-files will build up! They are NOT automatically deleted in PATH_site."typo3temp/"!
*
......@@ -3275,7 +3276,10 @@ class GeneralUtility
$uploadedTempFileName = self::fixWindowsFilePath($uploadedTempFileName);
if (
self::validPathStr($uploadedTempFileName)
&& self::isFirstPartOfStr($uploadedTempFileName, PATH_site . 'typo3temp/')
&& (
self::isFirstPartOfStr($uploadedTempFileName, PATH_site . 'typo3temp/')
|| self::isFirstPartOfStr($uploadedTempFileName, Environment::getVarPath() . '/')
)
&& @is_file($uploadedTempFileName)
) {
if (unlink($uploadedTempFileName)) {
......@@ -3297,7 +3301,7 @@ class GeneralUtility
*/
public static function tempnam($filePrefix, $fileSuffix = '')
{
$temporaryPath = PATH_site . 'typo3temp/var/transient/';
$temporaryPath = Environment::getVarPath() . '/transient/';
if (!is_dir($temporaryPath)) {
self::mkdir_deep($temporaryPath);
}
......
......@@ -21,7 +21,8 @@ As runtime reflection has been removed completely, along with it several reflect
analyzed doc blocks, have been removed as well. These are no longer necessary.
The `extbase_reflection` cache is no longer plugin based and will no longer be stored in the database
in the first place. Serialized ClassSchema instances will be stored in `typo3temp/var/Cache`.
in the first place. Serialized ClassSchema instances will be stored in `typo3temp/var/cache` or `var/cache` for
composer-based installations.
The following classes for internal use only and have been removed:
......
......@@ -49,6 +49,7 @@ Impact
analyzed doc blocks, have been removed as well. These are no longer necessary.
* The `extbase_reflection` cache is no longer plugin based and will no longer be stored in the
database in the first place. Serialized `ClassSchema` instances will be stored in `typo3temp/var/Cache`.
database in the first place. Serialized `ClassSchema` instances will be stored in `typo3temp/var/cache` or
`var/cache/` for composer-based installations.
.. index:: PHP-API, ext:extbase
.. include:: ../../Includes.txt
==============================================================================
Feature: #84545 - Allow temporary files to be stored outside the document root
==============================================================================
See :issue:`84545`
Description
===========
The environment variable called `TYPO3_PATH_APP`, which was previously introduced with the Environment
API, is now used to allow to store data outside of the document root.
All regular composer-based installations now benefit from this functionality directly, as data which was
previously stored and hard-coded within :file:`typo3temp/var/` is now stored within the project roots' folder
:file:`var/`.
For non-composer installations, it is possible to set the environment variable to a folder usually one level
upwards than the regular web root. This increases security for any TYPO3 installation as files are not
publicly accessible (for example via web browser) anymore.
A typical example:
- `TYPO3_PATH_APP` is set to :file:`/var/www/my-project`.
- The web folder is then set to `TYPO3_PATH_ROOT` :file:`/var/www/my-project/public`.
Non-public files are then put to
- :file:`/var/www/my-project/var/session` (like Install Tool Session files)
- :file:`/var/www/my-project/var/cache` (Caching Framework data)
- :file:`/var/www/my-project/var/lock` (Files related to locking)
- :file:`/var/www/my-project/var/log` (Files related to logging)
- :file:`/var/www/my-project/var/extensionmanager` (Files related to extension manager data)
- :file:`/var/www/my-project/var/transient` (Files related to import/export, core updater, FAL)
If the option is not set, the :file:`typo3temp/var/` folder is still used, but with some minor differences
regarding the naming scheme of the folders.
Impact
======
For installations having the environment variable set, the folder is now not within :file:`typo3temp/var/` anymore
but outside of the document root in a folder called :file:`var/`.
For installations without this setting in use, there are minor differences in the folder structure:
- :file:`typo3temp/var/cache` is now used instead of :file:`typo3temp/var/Cache`
- :file:`typo3temp/var/log` is now used instead of :file:`typo3temp/var/log`
- :file:`typo3temp/var/lock` is now used instead of :file:`typo3temp/var/locks`
- :file:`typo3temp/var/session` is now used instead of :file:`typo3temp/var/InstallToolSessions`
- :file:`typo3temp/var/extensionmanager` is now used instead of :file:`typo3temp/var/ExtensionManager`
Although it is a most common understanding in the TYPO3 world that `typo3temp/` can be removed at any time,
it is considered bad practice to remove the whole folder. Only folders relevant for the current development
changes should selectively be removed.
.. index:: CLI, PHP-API
......@@ -172,7 +172,7 @@ class FileBackendTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
$backend->setCacheDirectory('vfs://Foo/');
$backend->setCache($mockCache);
$this->assertEquals('vfs://Foo/Cache/Data/SomeCache/', $backend->getCacheDirectory());
$this->assertEquals('vfs://Foo/cache/data/SomeCache/', $backend->getCacheDirectory());
}
/**
......@@ -190,7 +190,7 @@ class FileBackendTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
$backend->setCacheDirectory('vfs://Foo/');
$backend->setCache($mockCache);
$this->assertEquals('vfs://Foo/Cache/Code/SomeCache/', $backend->getCacheDirectory());
$this->assertEquals('vfs://Foo/cache/code/SomeCache/', $backend->getCacheDirectory());
}
/**
......@@ -223,7 +223,7 @@ class FileBackendTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
$data = 'some data' . microtime();
$entryIdentifier = 'BackendFileTest';
$pathAndFilename = 'vfs://Foo/Cache/Data/UnitTestCache/' . $entryIdentifier;
$pathAndFilename = 'vfs://Foo/cache/data/UnitTestCache/' . $entryIdentifier;
$backend = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class)
->setMethods(['dummy'])
......@@ -261,7 +261,7 @@ class FileBackendTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
$backend->set($entryIdentifier, $data1, [], 500);
$backend->set($entryIdentifier, $data2, [], 200);
$pathAndFilename = 'vfs://Foo/Cache/Data/UnitTestCache/' . $entryIdentifier;
$pathAndFilename = 'vfs://Foo/cache/data/UnitTestCache/' . $entryIdentifier;
$this->assertFileExists($pathAndFilename);
$retrievedData = file_get_contents($pathAndFilename, null, null, 0, strlen($data2));
$this->assertEquals($data2, $retrievedData);
......@@ -287,7 +287,7 @@ class FileBackendTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
$backend->set($entryIdentifier, $data, ['Tag1', 'Tag2']);
$pathAndFilename = 'vfs://Foo/Cache/Data/UnitTestCache/' . $entryIdentifier;
$pathAndFilename = 'vfs://Foo/cache/data/UnitTestCache/' . $entryIdentifier;
$this->assertFileExists($pathAndFilename);
$retrievedData = file_get_contents(
$pathAndFilename,
......@@ -373,7 +373,7 @@ class FileBackendTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
->setMethods(['isCacheFileExpired'])
->disableOriginalConstructor()
->getMock();
$backend->expects($this->once())->method('isCacheFileExpired')->with('vfs://Foo/Cache/Data/UnitTestCache/ExpiredEntry')->will($this->returnValue(true));
$backend->expects($this->once())->method('isCacheFileExpired')->with('vfs://Foo/cache/data/UnitTestCache/ExpiredEntry')->will($this->returnValue(true));
$backend->setCacheDirectory('vfs://Foo/');
$backend->setCache($mockCache);
......@@ -475,7 +475,7 @@ class FileBackendTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
$data = 'some data' . microtime();
$entryIdentifier = 'BackendFileTest';
$pathAndFilename = 'vfs://Foo/Cache/Data/UnitTestCache/' . $entryIdentifier;
$pathAndFilename = 'vfs://Foo/cache/data/UnitTestCache/' . $entryIdentifier;
$backend = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\Backend\FileBackend::class)
->setMethods(['dummy'])
......@@ -736,13 +736,13 @@ class FileBackendTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
$backend->set('BackendFileTest1', $data);
$backend->set('BackendFileTest2', $data);
$this->assertFileExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest1');
$this->assertFileExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest2');
$this->assertFileExists('vfs://Foo/cache/data/UnitTestCache/BackendFileTest1');
$this->assertFileExists('vfs://Foo/cache/data/UnitTestCache/BackendFileTest2');
$backend->flush();
$this->assertFileNotExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest1');
$this->assertFileNotExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest2');
$this->assertFileNotExists('vfs://Foo/cache/data/UnitTestCache/BackendFileTest1');
$this->assertFileNotExists('vfs://Foo/cache/data/UnitTestCache/BackendFileTest2');
}
/**
......@@ -761,7 +761,7 @@ class FileBackendTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
$backend->setCache($mockCache);
$backend->flush();
$this->assertFileExists('vfs://Foo/Cache/Data/UnitTestCache/');
$this->assertFileExists('vfs://Foo/cache/data/UnitTestCache/');
}
/**
......@@ -802,12 +802,12 @@ class FileBackendTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
$backend->set('BackendFileTest1', $data);
$backend->set('BackendFileTest2', $data);
$this->assertFileExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest1');
$this->assertFileExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest2');
$this->assertFileExists('vfs://Foo/cache/data/UnitTestCache/BackendFileTest1');
$this->assertFileExists('vfs://Foo/cache/data/UnitTestCache/BackendFileTest2');
$backend->collectGarbage();
$this->assertFileNotExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest1');
$this->assertFileExists('vfs://Foo/Cache/Data/UnitTestCache/BackendFileTest2');
$this->assertFileNotExists('vfs://Foo/cache/data/UnitTestCache/BackendFileTest1');
$this->assertFileExists('vfs://Foo/cache/data/UnitTestCache/BackendFileTest2');
}
/**
......
......@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Locking;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Locking\FileLockStrategy;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -27,9 +28,9 @@ class FileLockStrategyTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCas
*/
public function constructorCreatesLockDirectoryIfNotExisting()
{
GeneralUtility::rmdir(PATH_site . FileLockStrategy::FILE_LOCK_FOLDER, true);
GeneralUtility::rmdir(Environment::getVarPath() . '/' . FileLockStrategy::FILE_LOCK_FOLDER, true);
new FileLockStrategy('999999999');
$this->assertTrue(is_dir(PATH_site . FileLockStrategy::FILE_LOCK_FOLDER));
$this->assertTrue(is_dir(Environment::getVarPath() . '/' . FileLockStrategy::FILE_LOCK_FOLDER));
}
/**
......@@ -38,6 +39,6 @@ class FileLockStrategyTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCas
public function constructorSetsFilePathToExpectedValue()
{
$lock = $this->getAccessibleMock(FileLockStrategy::class, ['dummy'], ['999999999']);
$this->assertSame(PATH_site . FileLockStrategy::FILE_LOCK_FOLDER . 'flock_' . md5('999999999'), $lock->_get('filePath'));
$this->assertSame(Environment::getVarPath() . '/' . FileLockStrategy::FILE_LOCK_FOLDER . 'flock_' . md5('999999999'), $lock->_get('filePath'));
}
}
......@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Core\Tests\Unit\Locking;
* The TYPO3 project - inspiring people to share!
*/
use PHPUnit\Framework\SkippedTestError;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Locking\SimpleLockStrategy;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -27,9 +29,9 @@ class SimpleLockStrategyTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestC
*/
public function constructorCreatesLockDirectoryIfNotExisting()
{
GeneralUtility::rmdir(PATH_site . SimpleLockStrategy::FILE_LOCK_FOLDER, true);
GeneralUtility::rmdir(Environment::getVarPath() . '/' . SimpleLockStrategy::FILE_LOCK_FOLDER, true);
new SimpleLockStrategy('999999999');
$this->assertTrue(is_dir(PATH_site . SimpleLockStrategy::FILE_LOCK_FOLDER));
$this->assertTrue(is_dir(Environment::getVarPath() . '/' . SimpleLockStrategy::FILE_LOCK_FOLDER));
}
/**
......@@ -38,7 +40,7 @@ class SimpleLockStrategyTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestC
public function constructorSetsResourceToPathWithIdIfUsingSimpleLocking()
{
$lock = $this->getAccessibleMock(SimpleLockStrategy::class, ['dummy'], ['999999999']);
$this->assertSame(PATH_site . SimpleLockStrategy::FILE_LOCK_FOLDER . 'simple_' . md5('999999999'), $lock->_get('filePath'));
$this->assertSame(Environment::getVarPath() . '/' . SimpleLockStrategy::FILE_LOCK_FOLDER . 'simple_' . md5('999999999'), $lock->_get('filePath'));
}
/**
......@@ -88,9 +90,9 @@ class SimpleLockStrategyTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestC
{
return [
'not within PATH_site' => [tempnam(sys_get_temp_dir(), 'foo')],
'directory traversal' => [PATH_site . 'typo3temp/../typo3temp/var/locks/foo'],
'directory traversal 2' => [PATH_site . 'typo3temp/var/locks/../../var/locks/foo'],
'within uploads' => [PATH_site . 'uploads/TYPO3-Lock-Test']
'directory traversal' => [Environment::getVarPath() . '/../var/lock/foo'],
'directory traversal 2' => [Environment::getVarPath() . '/lock/../../var/lock/foo'],
'within uploads' => [Environment::getPublicPath() . '/uploads/TYPO3-Lock-Test']
];
}
......@@ -98,7 +100,7 @@ class SimpleLockStrategyTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestC
* @test
* @dataProvider invalidFileReferences
* @param string $file
* @throws \PHPUnit_Framework_SkippedTestError
* @throws SkippedTestError
*/
public function releaseDoesNotRemoveFilesNotWithinTypo3TempLocksDirectory($file)
{
......
......@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Mail;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Mail\MemorySpool;
use TYPO3\CMS\Core\Mail\TransportFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -90,7 +91,7 @@ class TransportFactoryTest extends UnitTestCase
'defaultMailFromAddress' => '',
'defaultMailFromName' => '',
'transport_spool_type' => 'memory',
'transport_spool_filepath' => 'typo3temp/var/messages/',
'transport_spool_filepath' => Environment::getVarPath() . '/messages/',
];
// Register fixture class
......@@ -121,7 +122,7 @@ class TransportFactoryTest extends UnitTestCase
'defaultMailFromAddress' => '',
'defaultMailFromName' => '',
'transport_spool_type' => 'TYPO3\\CMS\\Core\\Tests\\Unit\\Mail\\Fixtures\\FakeValidSpoolFixture',