Skip to content

Commit

Permalink
Merge pull request #17784 from nextcloud/enh/disable-clear-site-data-…
Browse files Browse the repository at this point in the history
…via-config

Disable Clear-Site-Data for Chrom* (and Opera, Brave, etc)
  • Loading branch information
rullzer authored Dec 12, 2019
2 parents 815241f + 9378a6b commit 87104ce
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
8 changes: 6 additions & 2 deletions core/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@

namespace OC\Core\Controller;

use OC\AppFramework\Http\Request;
use OC\Authentication\Login\Chain;
use OC\Authentication\Login\LoginData;
use OC\Authentication\TwoFactorAuth\Manager;
use OC\Security\Bruteforce\Throttler;
use OC\User\Session;
use OC_App;
Expand Down Expand Up @@ -126,7 +126,11 @@ public function logout() {

$this->session->set('clearingExecutionContexts', '1');
$this->session->close();
$response->addHeader('Clear-Site-Data', '"cache", "storage"');

if (!$this->request->isUserAgent([Request::USER_AGENT_CHROME, Request::USER_AGENT_ANDROID_MOBILE_CHROME])) {
$response->addHeader('Clear-Site-Data', '"cache", "storage"');
}

return $response;
}

Expand Down
28 changes: 28 additions & 0 deletions tests/Core/Controller/LoginControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ public function testLogoutWithoutToken() {
->method('getCookie')
->with('nc_token')
->willReturn(null);
$this->request
->expects($this->once())
->method('isUserAgent')
->willReturn(false);
$this->config
->expects($this->never())
->method('deleteUserValue');
Expand All @@ -142,12 +146,36 @@ public function testLogoutWithoutToken() {
$this->assertEquals($expected, $this->loginController->logout());
}

public function testLogoutNoClearSiteData() {
$this->request
->expects($this->once())
->method('getCookie')
->with('nc_token')
->willReturn(null);
$this->request
->expects($this->once())
->method('isUserAgent')
->willReturn(true);
$this->urlGenerator
->expects($this->once())
->method('linkToRouteAbsolute')
->with('core.login.showLoginForm')
->willReturn('/login');

$expected = new RedirectResponse('/login');
$this->assertEquals($expected, $this->loginController->logout());
}

public function testLogoutWithToken() {
$this->request
->expects($this->once())
->method('getCookie')
->with('nc_token')
->willReturn('MyLoginToken');
$this->request
->expects($this->once())
->method('isUserAgent')
->willReturn(false);
$user = $this->createMock(IUser::class);
$user
->expects($this->once())
Expand Down

0 comments on commit 87104ce

Please sign in to comment.