public function testListCategoriesNotCachedWithAppStore()
 {
     $expected = [['id' => 0, 'ident' => 'enabled', 'displayName' => 'Enabled'], ['id' => 1, 'ident' => 'disabled', 'displayName' => 'Not enabled'], ['id' => 0, 'ident' => 'tools', 'displayName' => 'Tools'], ['id' => 1, 'ident' => 'games', 'displayName' => 'Games'], ['id' => 2, 'ident' => 'productivity', 'displayName' => 'Productivity'], ['id' => 3, 'ident' => 'multimedia', 'displayName' => 'Multimedia']];
     $this->cache->expects($this->once())->method('get')->with('listCategories')->will($this->returnValue(null));
     $this->cache->expects($this->once())->method('set')->with('listCategories', $expected, 3600);
     $this->ocsClient->expects($this->once())->method('isAppStoreEnabled')->will($this->returnValue(true));
     $this->ocsClient->expects($this->once())->method('getCategories')->will($this->returnValue(['ownCloud Tools', 'Games', 'ownCloud Productivity', 'Multimedia']));
     $this->assertSame($expected, $this->appSettingsController->listCategories());
 }
	public function testListCategoriesNotCachedWithAppStore() {
		$expected = [
			[
				'id' => 0,
				'displayName' => 'Enabled',
			],
			[
				'id' => 1,
				'displayName' => 'Not enabled',
			],
			[
				'id' => 0,
				'displayName' => 'Tools',
			],
			[
				'id' => 1,
				'displayName' => 'Awesome Games',
			],
			[
				'id' => 2,
				'displayName' => 'PIM',
			],
			[
				'id' => 3,
				'displayName' => 'Papershop',
			],
		];

		$this->cache
			->expects($this->once())
			->method('get')
			->with('listCategories')
			->will($this->returnValue(null));
		$this->cache
			->expects($this->once())
			->method('set')
			->with('listCategories', $expected, 3600);

		$this->ocsClient
			->expects($this->once())
			->method('isAppStoreEnabled')
			->will($this->returnValue(true));
		$this->ocsClient
			->expects($this->once())
			->method('getCategories')
			->will($this->returnValue(
				[
					'ownCloud Tools',
					'Awesome Games',
					'ownCloud PIM',
					'Papershop',
				]
			));

		$this->assertSame($expected, $this->appSettingsController->listCategories());
	}
 public function testWithMaliciousEndpointCached()
 {
     $response = $this->getMock('\\OCP\\Http\\Client\\IResponse');
     $response->expects($this->once())->method('getStatusCode')->willReturn(200);
     $response->expects($this->once())->method('getBody')->willReturn('{"version":2,"services":{"PRIVATE_DATA":{"version":1,"endpoints":{"store":"\\/ocs\\/v2.php\\/privatedata\\/setattribute","read":"\\/ocs\\/v2.php\\/privatedata\\/getattribute","delete":"\\/ocs\\/v2.php\\/privatedata\\/deleteattribute"}},"SHARING":{"version":1,"endpoints":{"share":"\\/ocs\\/v2.php\\/apps\\/files_sharing\\/api\\/v1\\/shares"}},"FEDERATED_SHARING":{"version":1,"endpoints":{"share":"\\/ocs\\/v2.php\\/cl@oud\\/MyCustomShareEndpoint","webdav":"\\/public.php\\/MyC:ustomEndpoint\\/"}},"ACTIVITY":{"version":1,"endpoints":{"list":"\\/ocs\\/v2.php\\/cloud\\/activity"}},"PROVISIONING":{"version":1,"endpoints":{"user":"******","groups":"\\/ocs\\/v2.php\\/cloud\\/groups","apps":"\\/ocs\\/v2.php\\/cloud\\/apps"}}}}');
     $this->client->expects($this->once())->method('get')->with('https://myhost.com/ocs-provider/', [])->willReturn($response);
     $this->cache->expects($this->at(0))->method('get')->with('https://myhost.com')->willReturn(null);
     $this->cache->expects($this->at(1))->method('set')->with('https://myhost.com', '{"webdav":"\\/public.php\\/webdav","share":"\\/ocs\\/v1.php\\/cloud\\/shares"}');
     $this->cache->expects($this->at(2))->method('get')->with('https://myhost.com')->willReturn('{"webdav":"\\/public.php\\/webdav","share":"\\/ocs\\/v1.php\\/cloud\\/shares"}');
     $this->assertSame('/public.php/webdav', $this->discoveryManager->getWebDavEndpoint('https://myhost.com'));
     $this->assertSame('/ocs/v1.php/cloud/shares', $this->discoveryManager->getShareEndpoint('https://myhost.com'));
 }
Ejemplo n.º 4
0
 protected function expectClearCache()
 {
     $this->cache->expects($this->once())->method('clear')->with('listApps');
 }