From a9af288036df63effa7aa164307a5ef0422387f6 Mon Sep 17 00:00:00 2001
From: Andreas Wolf <andreas.wolf@typo3.org>
Date: Sat, 1 Sep 2012 16:50:41 +0200
Subject: [PATCH] [BUGFIX] LocalDriver can be instantiated without basePath

The Local driver of FAL does not check if its configuration contains a
base path, leading to some hard-to-track errors when no path is given.

Resolves: #40505
Releases: 6.0
Change-Id: Id90a005f6cc9c167e3ab8df06a896cd078867e0a
Reviewed-on: http://review.typo3.org/14258
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
---
 typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php   | 6 +++++-
 .../core/Tests/Unit/Resource/Driver/LocalDriverTest.php     | 2 +-
 .../sysext/core/Tests/Unit/Resource/ResourceStorageTest.php | 5 +++++
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php b/typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
index bffb6df095a5..e90eabcca543 100644
--- a/typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
+++ b/typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
@@ -115,11 +115,15 @@ class LocalDriver extends \TYPO3\CMS\Core\Resource\Driver\AbstractDriver {
 	/**
 	 * Calculates the absolute path to this drivers storage location.
 	 *
-	 * @throws \RuntimeException
+	 * @throws \TYPO3\CMS\Core\Resource\Exception\InvalidConfigurationException
 	 * @param array $configuration
 	 * @return string
 	 */
 	protected function calculateBasePath(array $configuration) {
+		if (!array_key_exists('basePath', $configuration) || empty($configuration['basePath'])) {
+			throw new \TYPO3\CMS\Core\Resource\Exception\InvalidConfigurationException('Configuration must contain base path.', 1346510477);
+		}
+
 		if ($configuration['pathType'] === 'relative') {
 			$relativeBasePath = $configuration['basePath'];
 			$absoluteBasePath = PATH_site . $relativeBasePath;
diff --git a/typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php b/typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php
index fdfdd5c669be..4471ae11712f 100644
--- a/typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php
+++ b/typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php
@@ -131,7 +131,7 @@ class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase {
 	 */
 	public function rootLevelFolderIsCreatedWithCorrectArguments() {
 		$mockedMount = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
-		$fixture = $this->createDriverFixture(array(), $mockedMount);
+		$fixture = $this->createDriverFixture(array('basePath' => $this->getMountRootUrl()), $mockedMount);
 		$mockedFactory = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
 		$mockedFactory->expects($this->once())->method('createFolderObject')->with($this->equalTo($mockedMount), $this->equalTo('/'), $this->equalTo(''));
 		\TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', $mockedFactory);
diff --git a/typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php b/typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php
index fd46ff767cf5..d916fc9ec889 100644
--- a/typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php
+++ b/typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php
@@ -118,6 +118,11 @@ class ResourceStorageTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCa
 		if ($storageObject == NULL) {
 			$storageObject = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
 		}
+
+		if (!isset($driverConfiguration['basePath'])) {
+			$driverConfiguration['basePath'] = $this->getMountRootUrl();
+		}
+
 		if ($mockedDriverMethods === NULL) {
 			$driver = new \TYPO3\CMS\Core\Resource\Driver\LocalDriver($driverConfiguration);
 		} else {
-- 
GitLab