|
13 | 13 | use OC\Files\AppData\AppData; |
14 | 14 | use OC\Files\AppData\Factory; |
15 | 15 | use OCP\AppFramework\Utility\ITimeFactory; |
| 16 | +use OCP\Files\GenericFileException; |
16 | 17 | use OCP\Files\IAppData; |
17 | 18 | use OCP\Files\NotFoundException; |
18 | 19 | use OCP\Files\SimpleFS\ISimpleFile; |
@@ -684,4 +685,89 @@ public function testFetchAfterUpgradeNoETag(): void { |
684 | 685 | ]; |
685 | 686 | $this->assertSame($expected, $this->fetcher->get()); |
686 | 687 | } |
| 688 | + |
| 689 | + public function testGetWithUnreadableCacheFileRecreatesAndFetches(): void { |
| 690 | + $this->config |
| 691 | + ->method('getSystemValueString') |
| 692 | + ->willReturnCallback(function ($var, $default) { |
| 693 | + if ($var === 'appstoreurl') { |
| 694 | + return 'https://apps.nextcloud.com/api/v1'; |
| 695 | + } elseif ($var === 'version') { |
| 696 | + return '11.0.0.2'; |
| 697 | + } |
| 698 | + return $default; |
| 699 | + }); |
| 700 | + $this->config->method('getSystemValueBool') |
| 701 | + ->willReturn(true); |
| 702 | + |
| 703 | + $folder = $this->createMock(ISimpleFolder::class); |
| 704 | + $corruptedFile = $this->createMock(ISimpleFile::class); |
| 705 | + $freshFile = $this->createMock(ISimpleFile::class); |
| 706 | + $this->appData |
| 707 | + ->expects($this->once()) |
| 708 | + ->method('getFolder') |
| 709 | + ->with('/') |
| 710 | + ->willReturn($folder); |
| 711 | + $folder |
| 712 | + ->expects($this->once()) |
| 713 | + ->method('getFile') |
| 714 | + ->with($this->fileName) |
| 715 | + ->willReturn($corruptedFile); |
| 716 | + $corruptedFile |
| 717 | + ->expects($this->once()) |
| 718 | + ->method('getContent') |
| 719 | + ->willThrowException(new GenericFileException()); |
| 720 | + $corruptedFile |
| 721 | + ->expects($this->once()) |
| 722 | + ->method('delete'); |
| 723 | + $folder |
| 724 | + ->expects($this->once()) |
| 725 | + ->method('newFile') |
| 726 | + ->with($this->fileName) |
| 727 | + ->willReturn($freshFile); |
| 728 | + |
| 729 | + $client = $this->createMock(IClient::class); |
| 730 | + $this->clientService |
| 731 | + ->expects($this->once()) |
| 732 | + ->method('newClient') |
| 733 | + ->willReturn($client); |
| 734 | + $response = $this->createMock(IResponse::class); |
| 735 | + $client |
| 736 | + ->expects($this->once()) |
| 737 | + ->method('get') |
| 738 | + ->with($this->endpoint) |
| 739 | + ->willReturn($response); |
| 740 | + $response |
| 741 | + ->expects($this->once()) |
| 742 | + ->method('getBody') |
| 743 | + ->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]'); |
| 744 | + $response->method('getHeader') |
| 745 | + ->with($this->equalTo('ETag')) |
| 746 | + ->willReturn('"myETag"'); |
| 747 | + |
| 748 | + $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"myETag\""}'; |
| 749 | + $freshFile |
| 750 | + ->expects($this->once()) |
| 751 | + ->method('putContent') |
| 752 | + ->with($fileData); |
| 753 | + $freshFile |
| 754 | + ->expects($this->once()) |
| 755 | + ->method('getContent') |
| 756 | + ->willReturn($fileData); |
| 757 | + $this->timeFactory |
| 758 | + ->expects($this->once()) |
| 759 | + ->method('getTime') |
| 760 | + ->willReturn(1502); |
| 761 | + |
| 762 | + $expected = [ |
| 763 | + [ |
| 764 | + 'id' => 'MyNewApp', |
| 765 | + 'foo' => 'foo', |
| 766 | + ], |
| 767 | + [ |
| 768 | + 'id' => 'bar', |
| 769 | + ], |
| 770 | + ]; |
| 771 | + $this->assertSame($expected, $this->fetcher->get()); |
| 772 | + } |
687 | 773 | } |
0 commit comments