diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-02-26 18:27:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-26 18:27:54 +0100 |
commit | 4076c091951543289b310119e0f4e598143364be (patch) | |
tree | 8cddc8978618a625d633a0fad08cce8f1ef8b469 /apps/theming | |
parent | a60d7a8563f6f9e8047ac187e8f96f09f6dfa844 (diff) | |
parent | 8dcbea124ea91dc2a838ac16c0dc5e68dd384ab8 (diff) | |
download | nextcloud-server-4076c091951543289b310119e0f4e598143364be.tar.gz nextcloud-server-4076c091951543289b310119e0f4e598143364be.zip |
Merge pull request #8463 from kyrofa/bugfix/8462/theming_app_outside_root
theming: handle not being in the serverroot
Diffstat (limited to 'apps/theming')
-rw-r--r-- | apps/theming/lib/Controller/ThemingController.php | 13 | ||||
-rw-r--r-- | apps/theming/tests/Controller/ThemingControllerTest.php | 26 |
2 files changed, 34 insertions, 5 deletions
diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php index 4e9ce1b646e..e7865b90cf0 100644 --- a/apps/theming/lib/Controller/ThemingController.php +++ b/apps/theming/lib/Controller/ThemingController.php @@ -51,6 +51,7 @@ use OCP\IRequest; use OCA\Theming\Util; use OCP\ITempManager; use OCP\IURLGenerator; +use OCP\App\IAppManager; /** * Class ThemingController @@ -78,6 +79,8 @@ class ThemingController extends Controller { private $scssCacher; /** @var IURLGenerator */ private $urlGenerator; + /** @var IAppManager */ + private $appManager; /** * ThemingController constructor. @@ -93,6 +96,7 @@ class ThemingController extends Controller { * @param IAppData $appData * @param SCSSCacher $scssCacher * @param IURLGenerator $urlGenerator + * @param IAppManager $appManager */ public function __construct( $appName, @@ -105,7 +109,8 @@ class ThemingController extends Controller { ITempManager $tempManager, IAppData $appData, SCSSCacher $scssCacher, - IURLGenerator $urlGenerator + IURLGenerator $urlGenerator, + IAppManager $appManager ) { parent::__construct($appName, $request); @@ -118,6 +123,7 @@ class ThemingController extends Controller { $this->appData = $appData; $this->scssCacher = $scssCacher; $this->urlGenerator = $urlGenerator; + $this->appManager = $appManager; } /** @@ -409,12 +415,13 @@ class ThemingController extends Controller { * @return FileDisplayResponse|NotFoundResponse */ public function getStylesheet() { - $appPath = substr(\OC::$server->getAppManager()->getAppPath('theming'), strlen(\OC::$SERVERROOT) + 1); + $appPath = $this->appManager->getAppPath('theming'); + /* SCSSCacher is required here * We cannot rely on automatic caching done by \OC_Util::addStyle, * since we need to add the cacheBuster value to the url */ - $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, $appPath . '/css/theming.scss', 'theming'); + $cssCached = $this->scssCacher->process($appPath, 'css/theming.scss', 'theming'); if(!$cssCached) { return new NotFoundResponse(); } diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php index 54b842bc4e8..debc1b71e47 100644 --- a/apps/theming/tests/Controller/ThemingControllerTest.php +++ b/apps/theming/tests/Controller/ThemingControllerTest.php @@ -106,7 +106,8 @@ class ThemingControllerTest extends TestCase { $this->tempManager, $this->appData, $this->scssCacher, - $this->urlGenerator + $this->urlGenerator, + $this->appManager ); return parent::setUp(); @@ -798,7 +799,7 @@ class ThemingControllerTest extends TestCase { public function testGetStylesheet() { - + $this->appManager->expects($this->once())->method('getAppPath')->with('theming')->willReturn(\OC::$SERVERROOT . '/theming'); $file = $this->createMock(ISimpleFile::class); $file->expects($this->any())->method('getName')->willReturn('theming.css'); $file->expects($this->any())->method('getContent')->willReturn('compiled'); @@ -818,6 +819,7 @@ class ThemingControllerTest extends TestCase { } public function testGetStylesheetFails() { + $this->appManager->expects($this->once())->method('getAppPath')->with('theming')->willReturn(\OC::$SERVERROOT . '/theming'); $file = $this->createMock(ISimpleFile::class); $file->expects($this->any())->method('getName')->willReturn('theming.css'); $file->expects($this->any())->method('getContent')->willReturn('compiled'); @@ -829,6 +831,26 @@ class ThemingControllerTest extends TestCase { $this->assertEquals($response, $actual); } + public function testGetStylesheetOutsideServerroot() { + $this->appManager->expects($this->once())->method('getAppPath')->with('theming')->willReturn('/outside/serverroot/theming'); + $file = $this->createMock(ISimpleFile::class); + $file->expects($this->any())->method('getName')->willReturn('theming.css'); + $file->expects($this->any())->method('getContent')->willReturn('compiled'); + $this->scssCacher->expects($this->once())->method('process')->with('/outside/serverroot/theming', 'css/theming.scss', 'theming')->willReturn(true); + $this->scssCacher->expects($this->once())->method('getCachedCSS')->willReturn($file); + + $response = new Http\FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'text/css']); + $response->cacheFor(86400); + $expires = new \DateTime(); + $expires->setTimestamp($this->timeFactory->getTime()); + $expires->add(new \DateInterval('PT24H')); + $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); + $response->addHeader('Pragma', 'cache'); + + $actual = $this->themingController->getStylesheet(); + $this->assertEquals($response, $actual); + } + public function testGetJavascript() { $this->themingDefaults ->expects($this->at(0)) |