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'));
 }
Example #2
0
 public function __construct($options)
 {
     $this->memcacheFactory = \OC::$server->getMemCacheFactory();
     $this->httpClient = \OC::$server->getHTTPClientService();
     $discoveryManager = new DiscoveryManager($this->memcacheFactory, \OC::$server->getHTTPClientService());
     $this->manager = $options['manager'];
     $this->certificateManager = $options['certificateManager'];
     $this->remote = $options['remote'];
     $this->remoteUser = $options['owner'];
     list($protocol, $remote) = explode('://', $this->remote);
     if (strpos($remote, '/')) {
         list($host, $root) = explode('/', $remote, 2);
     } else {
         $host = $remote;
         $root = '';
     }
     $secure = $protocol === 'https';
     $root = rtrim($root, '/') . $discoveryManager->getWebDavEndpoint($this->remote);
     $this->mountPoint = $options['mountpoint'];
     $this->token = $options['token'];
     parent::__construct(array('secure' => $secure, 'host' => $host, 'root' => $root, 'user' => $options['token'], 'password' => (string) $options['password']));
 }