Repository navigation
fix: handle unreadable appdata cache without error #6196
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
+283
−9
Merged
Changes from all commits
Commits
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
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
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,100 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace Tests\Richdocuments\WOPI; | ||
|
|
||
| use Exception; | ||
| use OCA\Richdocuments\Service\DiscoveryService; | ||
| use OCA\Richdocuments\WOPI\Parser; | ||
| use PHPUnit\Framework\MockObject\MockObject; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Psr\Log\LoggerInterface; | ||
|
|
||
| class ParserTest extends TestCase { | ||
| private DiscoveryService&MockObject $discoveryService; | ||
| private LoggerInterface&MockObject $logger; | ||
|
|
||
| private Parser $parser; | ||
|
|
||
| protected function setUp(): void { | ||
| parent::setUp(); | ||
|
|
||
| $this->discoveryService = $this->createMock(DiscoveryService::class); | ||
| $this->logger = $this->createMock(LoggerInterface::class); | ||
|
|
||
| $this->parser = new Parser($this->discoveryService, $this->logger); | ||
| } | ||
|
|
||
| public function testGetUrlSrcValue(): void { | ||
| $discoveryXml = <<<END | ||
| <wopi-discovery> | ||
| <net-zone name="external-http"> | ||
| <app name="application/vnd.oasis.opendocument.text"> | ||
| <action name="edit" urlsrc="https://collabora\.example\.com/browser/abc/cool\.html?"/> | ||
| </app> | ||
| </net-zone> | ||
| </wopi-discovery> | ||
| END; | ||
|
|
||
| $this->discoveryService->method('get') | ||
| ->willReturn($discoveryXml); | ||
|
|
||
| $this->assertEquals( | ||
| 'https://collabora.example.com/browser/abc/cool.html?', | ||
| $this->parser->getUrlSrcValue('application/vnd.oasis.opendocument.text') | ||
| ); | ||
| } | ||
|
|
||
| public function testGetUrlSrcValueWithoutDiscoveryData(): void { | ||
| $this->discoveryService->method('get') | ||
| ->willReturn(null); | ||
|
|
||
| $this->expectException(Exception::class); | ||
| $this->expectExceptionMessage('No discovery data available'); | ||
|
|
||
| $this->parser->getUrlSrcValue('application/vnd.oasis.opendocument.text'); | ||
| } | ||
|
|
||
| public function testGetUrlSrcValueWithUnparseableDiscoveryData(): void { | ||
| $this->discoveryService->method('get') | ||
| ->willReturn('this is not xml'); | ||
|
|
||
| $useInternalErrors = libxml_use_internal_errors(true); | ||
|
|
||
| try { | ||
| $this->expectException(Exception::class); | ||
| $this->expectExceptionMessage('Could not parse WOPI discovery response'); | ||
|
|
||
| $this->parser->getUrlSrcValue('application/vnd.oasis.opendocument.text'); | ||
| } finally { | ||
| libxml_clear_errors(); | ||
| libxml_use_internal_errors($useInternalErrors); | ||
| } | ||
| } | ||
|
|
||
| public function testGetUrlSrcValueWithUnknownMimetype(): void { | ||
| $discoveryXml = <<<END | ||
| <wopi-discovery> | ||
| <net-zone name="external-http"> | ||
| <app name="application/vnd.oasis.opendocument.text"> | ||
| <action name="edit" urlsrc="https://collabora.example.com/browser/abc/cool.html?"/> | ||
| </app> | ||
| </net-zone> | ||
| </wopi-discovery> | ||
| END; | ||
|
|
||
| $this->discoveryService->method('get') | ||
| ->willReturn($discoveryXml); | ||
|
|
||
| $this->expectException(Exception::class); | ||
| $this->expectExceptionMessage('Could not find urlsrc for application/vnd.ms-excel'); | ||
|
|
||
| $this->parser->getUrlSrcValue('application/vnd.ms-excel'); | ||
| } | ||
| } |
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.
I was thinking about writing
nullto the cache here to prevent this triggering over and over again, but think this would then prevent quick recovery if the file is written again.May be worth to double check but not a blocker from my POV.
Uh oh!
There was an error while loading. Please reload this page.
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.
I think it's probably better to just keep it as the last state of the file, rather than delete it or write
nullto it