Repository navigation
fix(Themes): resolve URIs served outside the webroot in Element::fromUri() #245
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
Merged
ralflang
merged 2 commits into
horde:FRAMEWORK_6_0
from
pierrefardel:fix/cachecss-fromuri
Nov 2, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * Tests for Horde_Themes_Element::fromUri(). | ||
| * | ||
| * @category Horde | ||
| * @package Core | ||
| */ | ||
|
|
||
| namespace Horde\Core\Test\Unit\Themes; | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
| use PHPUnit\Framework\Attributes\CoversClass; | ||
| use Horde_Registry; | ||
| use Horde_Themes_Element; | ||
|
|
||
| #[CoversClass(Horde_Themes_Element::class)] | ||
| class ElementTest extends TestCase | ||
| { | ||
| private string $fileroot; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| $this->fileroot = realpath(sys_get_temp_dir()); | ||
| } | ||
|
|
||
| protected function tearDown(): void | ||
| { | ||
| unset($GLOBALS['registry']); | ||
| } | ||
|
|
||
| /** | ||
| * Installs a registry stub answering get() from a per-app array. | ||
| */ | ||
| private function setRegistry(array $applications): void | ||
| { | ||
| $registry = $this->createStub(Horde_Registry::class); | ||
| $registry->method('listAllApps')->willReturn(array_keys($applications)); | ||
| $registry->method('get')->willReturnCallback( | ||
| fn($parameter, $app = null) => $applications[$app][$parameter] | ||
| ?? $applications['horde'][$parameter] | ||
| ?? null | ||
| ); | ||
| $GLOBALS['registry'] = $registry; | ||
| } | ||
|
|
||
| /** | ||
| * Composer layout: themes are served outside of the Horde webroot. | ||
| */ | ||
| private function composerLayout(): array | ||
| { | ||
| return [ | ||
| 'horde' => [ | ||
| 'fileroot' => $this->fileroot, | ||
| 'webroot' => '/horde/', | ||
| 'jsfs' => '/var/www/horde/web/js/horde/', | ||
| 'jsuri' => '/js/horde', | ||
| 'staticfs' => '/var/www/horde/web/static/', | ||
| 'staticuri' => '/static/', | ||
| 'themesfs' => '/var/www/horde/web/themes/horde/', | ||
| 'themesuri' => '/themes/horde', | ||
| ], | ||
| 'imp' => [ | ||
| 'themesfs' => '/var/www/horde/web/themes/imp/', | ||
| 'themesuri' => '/themes/imp', | ||
| ], | ||
| ]; | ||
| } | ||
|
|
||
| public function testThemesUriOutsideWebroot(): void | ||
| { | ||
| $this->setRegistry($this->composerLayout()); | ||
|
|
||
| $ob = Horde_Themes_Element::fromUri('/themes/horde/mytheme/base.css'); | ||
|
|
||
| $this->assertSame('/var/www/horde/web/themes/horde/mytheme/base.css', $ob->fs); | ||
| $this->assertSame('/themes/horde/mytheme/base.css', $ob->uri); | ||
| } | ||
|
|
||
| public function testApplicationThemesUri(): void | ||
| { | ||
| $this->setRegistry($this->composerLayout()); | ||
|
|
||
| $ob = Horde_Themes_Element::fromUri('/themes/imp/mytheme/screen.css'); | ||
|
|
||
| $this->assertSame('/var/www/horde/web/themes/imp/mytheme/screen.css', $ob->fs); | ||
| } | ||
|
|
||
| public function testStaticUri(): void | ||
| { | ||
| $this->setRegistry($this->composerLayout()); | ||
|
|
||
| $ob = Horde_Themes_Element::fromUri('/static/abc.css'); | ||
|
|
||
| $this->assertSame('/var/www/horde/web/static/abc.css', $ob->fs); | ||
| } | ||
|
|
||
| public function testLongestPrefixWins(): void | ||
| { | ||
| $applications = $this->composerLayout(); | ||
| $applications['horde']['themesfs'] = '/srv/themes/'; | ||
| $applications['horde']['themesuri'] = '/themes'; | ||
| $this->setRegistry($applications); | ||
|
|
||
| $ob = Horde_Themes_Element::fromUri('/themes/imp/mytheme/screen.css'); | ||
|
|
||
| $this->assertSame('/var/www/horde/web/themes/imp/mytheme/screen.css', $ob->fs); | ||
| } | ||
|
|
||
| public function testPrefixMatchesWholePathSegment(): void | ||
| { | ||
| $this->setRegistry($this->composerLayout()); | ||
|
|
||
| $ob = Horde_Themes_Element::fromUri('/themes/horde-extra/base.css'); | ||
|
|
||
| $this->assertSame($this->fileroot . '/themes/horde-extra/base.css', $ob->fs); | ||
| } | ||
|
|
||
| public function testFallbackStripsWebrootWithTrailingSlash(): void | ||
| { | ||
| $this->setRegistry(['horde' => [ | ||
| 'fileroot' => $this->fileroot, | ||
| 'webroot' => '/horde/', | ||
| ]]); | ||
|
|
||
| $ob = Horde_Themes_Element::fromUri('/horde/themes/default/screen.css'); | ||
|
|
||
| $this->assertSame($this->fileroot . '/themes/default/screen.css', $ob->fs); | ||
| } | ||
|
|
||
| public function testFallbackStripsWebrootWithoutTrailingSlash(): void | ||
| { | ||
| $this->setRegistry(['horde' => [ | ||
| 'fileroot' => $this->fileroot, | ||
| 'webroot' => '/horde', | ||
| ]]); | ||
|
|
||
| $ob = Horde_Themes_Element::fromUri('/horde/themes/default/screen.css'); | ||
|
|
||
| $this->assertSame($this->fileroot . '/themes/default/screen.css', $ob->fs); | ||
| } | ||
|
|
||
| public function testFallbackWithRootWebroot(): void | ||
| { | ||
| $this->setRegistry(['horde' => [ | ||
| 'fileroot' => $this->fileroot, | ||
| 'webroot' => '/', | ||
| ]]); | ||
|
|
||
| $ob = Horde_Themes_Element::fromUri('/themes/default/screen.css'); | ||
|
|
||
| $this->assertSame($this->fileroot . '/themes/default/screen.css', $ob->fs); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks. Fixed in 82d35a6:
CompressTestnow stubslistAllApps(). I checked that no other test reachesfromUri()with a registry stub. PHPUnit is still not available in my environment, so the suite itself has not been run.