Exemplo n.º 1
0
 public function testLogoutWithToken()
 {
     $this->request->expects($this->once())->method('getCookie')->with('oc_token')->willReturn('MyLoginToken');
     $user = $this->getMock('\\OCP\\IUser');
     $user->expects($this->once())->method('getUID')->willReturn('JohnDoe');
     $this->userSession->expects($this->once())->method('getUser')->willReturn($user);
     $this->config->expects($this->once())->method('deleteUserValue')->with('JohnDoe', 'login_token', 'MyLoginToken');
     $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute')->with('core.login.showLoginForm')->willReturn('/login');
     $expected = new RedirectResponse('/login');
     $this->assertEquals($expected, $this->loginController->logout());
 }
Exemplo n.º 2
0
 public function testRestoreTrashedNote()
 {
     $file = "some-not-existing-test-file.txt";
     $timestamp = time();
     $this->request->expects($this->at(0))->method("getParam")->with("file_name")->willReturn("/Notes/{$file}");
     $this->request->expects($this->at(1))->method("getParam")->with("timestamp")->willReturn($timestamp);
     $result = $this->controller->restoreTrashedNote();
     $this->assertArrayHasKey("result", $result);
     $this->assertArrayHasKey("path", $result);
     $this->assertArrayHasKey("filename", $result);
     $this->assertFalse($result["result"]);
     $this->assertEquals($result["path"], "//{$file}.d{$timestamp}");
     $this->assertEquals($result["filename"], $file);
 }
Exemplo n.º 3
0
 protected function mockRSSToken($requestToken, $userToken, $users)
 {
     if ($requestToken !== null) {
         $this->request->expects($this->any())->method('getParam')->with('token', '')->willReturn($requestToken);
     }
     $this->config->expects($this->any())->method('getUsersForUserValue')->with('activity', 'rsstoken', $userToken)->willReturn($users);
 }
Exemplo n.º 4
0
 /**
  * @dataProvider dataLoadingJSAndCSS
  * @param string $scriptName
  * @param string $pathInfo
  * @param IUser|null $user
  * @param bool $scriptsAdded
  */
 public function testLoadingJSAndCSS($scriptName, $pathInfo, $user, $scriptsAdded)
 {
     $this->request->expects($this->any())->method('getScriptName')->willReturn($scriptName);
     $this->request->expects($this->any())->method('getPathInfo')->willReturn($pathInfo);
     $this->session->expects($this->once())->method('getUser')->willReturn($user);
     \OC_Util::$scripts = [];
     \OC_Util::$styles = [];
     include __DIR__ . '/../../appinfo/app.php';
     if ($scriptsAdded) {
         $this->assertNotEmpty(\OC_Util::$scripts);
         $this->assertNotEmpty(\OC_Util::$styles);
     } else {
         $this->assertEmpty(\OC_Util::$scripts);
         $this->assertEmpty(\OC_Util::$styles);
     }
 }
Exemplo n.º 5
0
 public function testAddPersonalRootCertificateInvalidCertificate()
 {
     $uploadedFile = ['tmp_name' => __DIR__ . '/../../data/certificates/badCertificate.crt', 'name' => 'badCertificate.crt'];
     $this->request->expects($this->once())->method('getUploadedFile')->with('rootcert_import')->will($this->returnValue($uploadedFile));
     $this->certificateManager->expects($this->once())->method('addCertificate')->with(file_get_contents($uploadedFile['tmp_name'], 'badCertificate.crt'))->will($this->throwException(new \Exception()));
     $expected = new DataResponse('An error occurred.', Http::STATUS_UNPROCESSABLE_ENTITY);
     $this->assertEquals($expected, $this->certificateController->addPersonalRootCertificate());
 }
Exemplo n.º 6
0
 public function testIndexWithRegularBrowser()
 {
     $this->request->expects($this->once())->method('isUserAgent')->with(['/MSIE 8.0/'])->will($this->returnValue(false));
     $this->viewController->expects($this->once())->method('getStorageInfo')->will($this->returnValue(['relative' => 123, 'owner' => 'MyName', 'ownerDisplayName' => 'MyDisplayName']));
     $this->config->expects($this->any())->method('getAppValue')->will($this->returnArgument(2));
     $nav = new Template('files', 'appnavigation');
     $nav->assign('navigationItems', [0 => ['id' => 'files', 'appname' => 'files', 'script' => 'list.php', 'order' => 0, 'name' => new \OC_L10N_String(new \OC_L10N('files'), 'All files', []), 'active' => false, 'icon' => ''], 1 => ['id' => 'favorites', 'appname' => 'files', 'script' => 'simplelist.php', 'order' => 5, 'name' => null, 'active' => false, 'icon' => ''], 2 => ['id' => 'sharingin', 'appname' => 'files_sharing', 'script' => 'list.php', 'order' => 10, 'name' => new \OC_L10N_String(new \OC_L10N('files_sharing'), 'Shared with you', []), 'active' => false, 'icon' => ''], 3 => ['id' => 'sharingout', 'appname' => 'files_sharing', 'script' => 'list.php', 'order' => 15, 'name' => new \OC_L10N_String(new \OC_L10N('files_sharing'), 'Shared with others', []), 'active' => false, 'icon' => ''], 4 => ['id' => 'sharinglinks', 'appname' => 'files_sharing', 'script' => 'list.php', 'order' => 20, 'name' => new \OC_L10N_String(new \OC_L10N('files_sharing'), 'Shared by link', []), 'active' => false, 'icon' => ''], 5 => ['id' => 'trashbin', 'appname' => 'files_trashbin', 'script' => 'list.php', 'order' => 50, 'name' => new \OC_L10N_String(new \OC_L10N('files_trashbin'), 'Deleted files', []), 'active' => false, 'icon' => '']]);
     $expected = new Http\TemplateResponse('files', 'index', ['usedSpacePercent' => 123, 'owner' => 'MyName', 'ownerDisplayName' => 'MyDisplayName', 'isPublic' => false, 'mailNotificationEnabled' => 'no', 'mailPublicNotificationEnabled' => 'no', 'allowShareWithLink' => 'yes', 'appNavigation' => $nav, 'appContents' => [0 => ['id' => 'files', 'content' => null], 1 => ['id' => 'favorites', 'content' => null], 2 => ['id' => 'sharingin', 'content' => null], 3 => ['id' => 'sharingout', 'content' => null], 4 => ['id' => 'sharinglinks', 'content' => null], 5 => ['id' => 'trashbin', 'content' => null]]]);
     $this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView'));
 }
Exemplo n.º 7
0
 /**
  * @dataProvider dataGenerateHeaders
  *
  * @param string $sort
  * @param int $limit
  * @param string $objectType
  * @param int $objectId
  * @param string $format
  * @param array $headersIn
  * @param bool $hasMoreActivities
  * @param array $expected
  */
 public function testGenerateHeaders($sort, $limit, $objectType, $objectId, $format, array $headersIn, $hasMoreActivities, array $expected)
 {
     $this->invokePrivate($this->controller, 'sort', [$sort]);
     $this->invokePrivate($this->controller, 'limit', [$limit]);
     $this->invokePrivate($this->controller, 'objectType', [$objectType]);
     $this->invokePrivate($this->controller, 'objectId', [$objectId]);
     $this->request->expects($this->any())->method('getParam')->with('format')->willReturn($format);
     $headers = $this->invokePrivate($this->controller, 'generateHeaders', [$headersIn, $hasMoreActivities]);
     $this->assertEquals($expected, $headers);
 }
Exemplo n.º 8
0
 /**
  * @dataProvider dataGetGroups
  */
 public function testGetGroups($search, $limit, $offset)
 {
     $this->request->expects($this->exactly(3))->method('getParam')->will($this->returnValueMap([['search', '', $search], ['limit', null, $limit], ['offset', null, $offset]]));
     $groups = [$this->createGroup('group1'), $this->createGroup('group2')];
     $search = $search === null ? '' : $search;
     $this->groupManager->expects($this->once())->method('search')->with($search, $limit, $offset)->willReturn($groups);
     $result = $this->api->getGroups([]);
     $this->assertInstanceOf('OC_OCS_Result', $result);
     $this->assertTrue($result->succeeded());
     $this->assertEquals(['group1', 'group2'], $result->getData()['groups']);
 }
Exemplo n.º 9
0
 /**
  * @dataProvider dataSetLanguageFromRequest
  *
  * @param string|null $app
  * @param string $header
  * @param string|null $requestLanguage
  * @param string[] $availableLanguages
  * @param string $expected
  * @param string $expectedLang
  */
 public function testSetLanguageFromRequest($app, $header, $requestLanguage, array $availableLanguages, $expected, $expectedLang)
 {
     $factory = $this->getFactory(['findAvailableLanguages']);
     $factory->expects($this->once())->method('findAvailableLanguages')->with($app)->willReturn($availableLanguages);
     $this->request->expects($this->once())->method('getHeader')->with('ACCEPT_LANGUAGE')->willReturn($header);
     if ($requestLanguage !== null) {
         $this->invokePrivate($factory, 'requestLanguage', [$requestLanguage]);
     }
     $this->assertSame($expected, $factory->setLanguageFromRequest($app), 'Asserting returned language');
     $this->assertSame($expectedLang, $this->invokePrivate($factory, 'requestLanguage'), 'Asserting stored language');
 }
Exemplo n.º 10
0
Arquivo: auth.php Projeto: gvde/core
 public function testAuthenticateAlreadyLoggedInWithCsrfTokenForGet()
 {
     $request = $this->getMockBuilder('Sabre\\HTTP\\RequestInterface')->disableOriginalConstructor()->getMock();
     $response = $this->getMockBuilder('Sabre\\HTTP\\ResponseInterface')->disableOriginalConstructor()->getMock();
     $this->userSession->expects($this->exactly(2))->method('isLoggedIn')->will($this->returnValue(true));
     $this->session->expects($this->exactly(2))->method('get')->with('AUTHENTICATED_TO_DAV_BACKEND')->will($this->returnValue(null));
     $user = $this->getMockBuilder('\\OCP\\IUser')->disableOriginalConstructor()->getMock();
     $user->expects($this->exactly(2))->method('getUID')->will($this->returnValue('MyWrongDavUser'));
     $this->userSession->expects($this->exactly(2))->method('getUser')->will($this->returnValue($user));
     $this->request->expects($this->once())->method('passesCSRFCheck')->willReturn(true);
     $response = $this->auth->check($request, $response);
     $this->assertEquals([true, 'principals/users/MyWrongDavUser'], $response);
 }
Exemplo n.º 11
0
 public function testIndexWithRegularBrowser()
 {
     $this->request->expects($this->once())->method('isUserAgent')->with(['/MSIE 8.0/'])->will($this->returnValue(false));
     $this->viewController->expects($this->once())->method('getStorageInfo')->will($this->returnValue(['relative' => 123, 'owner' => 'MyName', 'ownerDisplayName' => 'MyDisplayName']));
     $this->config->expects($this->exactly(3))->method('getUserValue')->will($this->returnValueMap([[$this->user->getUID(), 'files', 'file_sorting', 'name', 'name'], [$this->user->getUID(), 'files', 'file_sorting_direction', 'asc', 'asc'], [$this->user->getUID(), 'files', 'show_hidden', false, false]]));
     $this->config->expects($this->any())->method('getAppValue')->will($this->returnArgument(2));
     $nav = new Template('files', 'appnavigation');
     $nav->assign('navigationItems', [['id' => 'files', 'appname' => 'files', 'script' => 'list.php', 'order' => 0, 'name' => new \OC_L10N_String(new \OC_L10N('files'), 'All files', []), 'active' => false, 'icon' => ''], ['id' => 'favorites', 'appname' => 'files', 'script' => 'simplelist.php', 'order' => 5, 'name' => null, 'active' => false, 'icon' => ''], ['id' => 'sharingin', 'appname' => 'files_sharing', 'script' => 'list.php', 'order' => 10, 'name' => new \OC_L10N_String(new \OC_L10N('files_sharing'), 'Shared with you', []), 'active' => false, 'icon' => ''], ['id' => 'sharingout', 'appname' => 'files_sharing', 'script' => 'list.php', 'order' => 15, 'name' => new \OC_L10N_String(new \OC_L10N('files_sharing'), 'Shared with others', []), 'active' => false, 'icon' => ''], ['id' => 'sharinglinks', 'appname' => 'files_sharing', 'script' => 'list.php', 'order' => 20, 'name' => new \OC_L10N_String(new \OC_L10N('files_sharing'), 'Shared by link', []), 'active' => false, 'icon' => ''], ['id' => 'systemtagsfilter', 'appname' => 'systemtags', 'script' => 'list.php', 'order' => 25, 'name' => new \OC_L10N_String(new \OC_L10N('systemtags'), 'Tags', []), 'active' => false, 'icon' => ''], ['id' => 'trashbin', 'appname' => 'files_trashbin', 'script' => 'list.php', 'order' => 50, 'name' => new \OC_L10N_String(new \OC_L10N('files_trashbin'), 'Deleted files', []), 'active' => false, 'icon' => '']]);
     $expected = new Http\TemplateResponse('files', 'index', ['usedSpacePercent' => 123, 'owner' => 'MyName', 'ownerDisplayName' => 'MyDisplayName', 'isPublic' => false, 'defaultFileSorting' => 'name', 'defaultFileSortingDirection' => 'asc', 'showHiddenFiles' => false, 'mailNotificationEnabled' => 'no', 'mailPublicNotificationEnabled' => 'no', 'allowShareWithLink' => 'yes', 'appNavigation' => $nav, 'appContents' => [['id' => 'files', 'content' => null], ['id' => 'favorites', 'content' => null], ['id' => 'sharingin', 'content' => null], ['id' => 'sharingout', 'content' => null], ['id' => 'sharinglinks', 'content' => null], ['id' => 'systemtagsfilter', 'content' => null], ['id' => 'trashbin', 'content' => null]]]);
     $policy = new Http\ContentSecurityPolicy();
     $policy->addAllowedFrameDomain('\'self\'');
     $expected->setContentSecurityPolicy($policy);
     $this->assertEquals($expected, $this->viewController->index('MyDir', 'MyView'));
 }
Exemplo n.º 12
0
 public function testAuthenticateNoBasicAuthenticateHeadersProvidedWithAjaxButUserIsStillLoggedIn()
 {
     /** @var \Sabre\HTTP\RequestInterface $httpRequest */
     $httpRequest = $this->getMockBuilder('\\Sabre\\HTTP\\RequestInterface')->disableOriginalConstructor()->getMock();
     /** @var \Sabre\HTTP\ResponseInterface $httpResponse */
     $httpResponse = $this->getMockBuilder('\\Sabre\\HTTP\\ResponseInterface')->disableOriginalConstructor()->getMock();
     /** @var IUser */
     $user = $this->getMock('OCP\\IUser');
     $user->method('getUID')->willReturn('MyTestUser');
     $this->userSession->expects($this->any())->method('isLoggedIn')->will($this->returnValue(true));
     $this->userSession->expects($this->any())->method('getUser')->willReturn($user);
     $this->session->expects($this->atLeastOnce())->method('get')->with('AUTHENTICATED_TO_DAV_BACKEND')->will($this->returnValue('MyTestUser'));
     $this->request->expects($this->once())->method('getMethod')->willReturn('GET');
     $httpRequest->expects($this->atLeastOnce())->method('getHeader')->with('Authorization')->will($this->returnValue(null));
     $this->assertEquals([true, 'principals/users/MyTestUser'], $this->auth->check($httpRequest, $httpResponse));
 }
Exemplo n.º 13
0
 /**
  * @dataProvider showData
  *
  * @param string $acceptHeader
  * @param string $expectedHeader
  */
 public function testShowNoToken($acceptHeader, $expectedHeader)
 {
     $this->manager->expects($this->any())->method('getCurrentUserId')->willThrowException(new \UnexpectedValueException());
     if ($acceptHeader !== null) {
         $this->request->expects($this->any())->method('getHeader')->willReturn($acceptHeader);
     }
     $templateResponse = $this->controller->show();
     $this->assertTrue($templateResponse instanceof TemplateResponse, 'Asserting type of return is \\OCP\\AppFramework\\Http\\TemplateResponse');
     $headers = $templateResponse->getHeaders();
     $this->assertArrayHasKey('Content-Type', $headers);
     $this->assertEquals($expectedHeader, $headers['Content-Type']);
     $renderedResponse = $templateResponse->render();
     $this->assertNotEmpty($renderedResponse);
     $l = Util::getL10N('activity');
     $description = (string) $l->t('Your feed URL is invalid');
     $this->assertContains($description, $renderedResponse);
 }
Exemplo n.º 14
0
 public function testCheck()
 {
     $this->config->expects($this->at(0))->method('getSystemValue')->with('has_internet_connection', true)->will($this->returnValue(true));
     $this->config->expects($this->at(1))->method('getSystemValue')->with('memcache.local', null)->will($this->returnValue('SomeProvider'));
     $this->config->expects($this->at(2))->method('getSystemValue')->with('trusted_proxies', [])->willReturn(['1.2.3.4']);
     $this->request->expects($this->once())->method('getRemoteAddress')->willReturn('4.3.2.1');
     $client = $this->getMockBuilder('\\OCP\\Http\\Client\\IClient')->disableOriginalConstructor()->getMock();
     $client->expects($this->at(0))->method('get')->with('https://www.owncloud.org/', []);
     $client->expects($this->at(1))->method('get')->with('http://www.owncloud.org/', [])->will($this->throwException(new \Exception()));
     $this->clientService->expects($this->once())->method('newClient')->will($this->returnValue($client));
     $this->util->expects($this->once())->method('isHtaccessWorking')->will($this->returnValue(true));
     $this->urlGenerator->expects($this->at(0))->method('linkToDocs')->with('admin-performance')->willReturn('http://doc.owncloud.org/server/go.php?to=admin-performance');
     $this->urlGenerator->expects($this->at(1))->method('linkToDocs')->with('admin-security')->willReturn('https://doc.owncloud.org/server/8.1/admin_manual/configuration_server/hardening.html');
     self::$version_compare = -1;
     $this->urlGenerator->expects($this->at(2))->method('linkToDocs')->with('admin-reverse-proxy')->willReturn('reverse-proxy-doc-link');
     $expected = new DataResponse(['serverHasInternetConnection' => false, 'dataDirectoryProtected' => true, 'isMemcacheConfigured' => true, 'memcacheDocs' => 'http://doc.owncloud.org/server/go.php?to=admin-performance', 'isUrandomAvailable' => self::invokePrivate($this->checkSetupController, 'isUrandomAvailable'), 'securityDocs' => 'https://doc.owncloud.org/server/8.1/admin_manual/configuration_server/hardening.html', 'isUsedTlsLibOutdated' => '', 'phpSupported' => ['eol' => true, 'version' => PHP_VERSION], 'forwardedForHeadersWorking' => true, 'reverseProxyDocs' => 'reverse-proxy-doc-link']);
     $this->assertEquals($expected, $this->checkSetupController->check());
 }
Exemplo n.º 15
0
 /**
  * @dataProvider dataIsV2
  *
  * @param string $scriptName
  * @param bool $expected
  */
 public function testIsV2($scriptName, $expected)
 {
     $this->request->expects($this->once())->method('getScriptName')->willReturn($scriptName);
     $this->assertEquals($expected, $this->invokePrivate($this->sharees, 'isV2'));
 }
 /**
  * Mocks IRequest->getParam('token')
  */
 private function mockGetTokenParam($token)
 {
     $this->request->expects($this->any())->method('getParam')->with('token')->willReturn($token);
 }
Exemplo n.º 17
0
 /**
  * Needs to be called at least once by testDownloadWithWrongId() or the tests will fail
  *
  * @param $key
  * @param $value
  */
 private function mockCookieGet($key, $value)
 {
     $this->request->expects($this->once())->method('getCookie')->with($key)->willReturn($value);
 }