Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable12] theming: handle not being in the serverroot #8549

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions apps/theming/lib/Controller/ThemingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use OCA\Theming\Util;
use OCP\ITempManager;
use OCP\IURLGenerator;
use OCP\App\IAppManager;

/**
* Class ThemingController
Expand Down Expand Up @@ -75,6 +76,8 @@ class ThemingController extends Controller {
private $scssCacher;
/** @var IURLGenerator */
private $urlGenerator;
/** @var IAppManager */
private $appManager;

/**
* ThemingController constructor.
Expand All @@ -90,6 +93,7 @@ class ThemingController extends Controller {
* @param IAppData $appData
* @param SCSSCacher $scssCacher
* @param IURLGenerator $urlGenerator
* @param IAppManager $appManager
*/
public function __construct(
$appName,
Expand All @@ -102,7 +106,8 @@ public function __construct(
ITempManager $tempManager,
IAppData $appData,
SCSSCacher $scssCacher,
IURLGenerator $urlGenerator
IURLGenerator $urlGenerator,
IAppManager $appManager
) {
parent::__construct($appName, $request);

Expand All @@ -115,6 +120,7 @@ public function __construct(
$this->appData = $appData;
$this->scssCacher = $scssCacher;
$this->urlGenerator = $urlGenerator;
$this->appManager = $appManager;
}

/**
Expand Down Expand Up @@ -374,12 +380,13 @@ public function getLoginBackground() {
* @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();
}
Expand Down
26 changes: 24 additions & 2 deletions apps/theming/tests/Controller/ThemingControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public function setUp() {
$this->tempManager,
$this->appData,
$this->scssCacher,
$this->urlGenerator
$this->urlGenerator,
$this->appManager
);

return parent::setUp();
Expand Down Expand Up @@ -629,7 +630,7 @@ public function testGetLoginBackground() {


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');
Expand All @@ -649,6 +650,7 @@ public function testGetStylesheet() {
}

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');
Expand All @@ -660,6 +662,26 @@ public function testGetStylesheetFails() {
$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))
Expand Down