diff options
-rw-r--r-- | core/Controller/NavigationController.php | 23 | ||||
-rw-r--r-- | tests/Core/Controller/NavigationControllerTest.php | 6 |
2 files changed, 22 insertions, 7 deletions
diff --git a/core/Controller/NavigationController.php b/core/Controller/NavigationController.php index b178cb97cd5..2397fb3c7b4 100644 --- a/core/Controller/NavigationController.php +++ b/core/Controller/NavigationController.php @@ -56,12 +56,12 @@ class NavigationController extends OCSController { $navigation = $this->rewriteToAbsoluteUrls($navigation); } - $etag = md5(json_encode($navigation)); + $etag = $this->generateETag($navigation); if ($this->request->getHeader('If-None-Match') === $etag) { return new DataResponse([], Http::STATUS_NOT_MODIFIED); } $response = new DataResponse($navigation); - $response->setEtag($etag); + $response->setETag($etag); return $response; } @@ -77,16 +77,31 @@ class NavigationController extends OCSController { if ($absolute) { $navigation = $this->rewriteToAbsoluteUrls($navigation); } - $etag = md5(json_encode($navigation)); + $etag = $this->generateETag($navigation); if ($this->request->getHeader('If-None-Match') === $etag) { return new DataResponse([], Http::STATUS_NOT_MODIFIED); } $response = new DataResponse($navigation); - $response->setEtag($etag); + $response->setETag($etag); return $response; } /** + * Generate an ETag for a list of navigation entries + * + * @param array $navigation + * @return string + */ + private function generateETag(array $navigation): string { + foreach ($navigation as &$nav) { + if ($nav['id'] === 'logout') { + $nav['href'] = 'logout'; + } + } + return md5(json_encode($navigation)); + } + + /** * Rewrite href attribute of navigation entries to an absolute URL * * @param array $navigation diff --git a/tests/Core/Controller/NavigationControllerTest.php b/tests/Core/Controller/NavigationControllerTest.php index ef4720604fb..a33ddf7dd23 100644 --- a/tests/Core/Controller/NavigationControllerTest.php +++ b/tests/Core/Controller/NavigationControllerTest.php @@ -132,7 +132,7 @@ class NavigationControllerTest extends TestCase { $this->request->expects($this->once()) ->method('getHeader') ->with('If-None-Match') - ->willReturn(md5(json_encode($navigation))); + ->willReturn(md5(json_encode(['files']))); $this->navigationManager->expects($this->once()) ->method('getAll') ->with('link') @@ -143,11 +143,11 @@ class NavigationControllerTest extends TestCase { } public function testGetSettingsNavigationEtagMatch() { - $navigation = [ ['id' => 'files', 'href' => '/index.php/apps/files', 'icon' => 'icon' ] ]; + $navigation = [ ['id' => 'logout', 'href' => '/index.php/apps/files', 'icon' => 'icon' ] ]; $this->request->expects($this->once()) ->method('getHeader') ->with('If-None-Match') - ->willReturn(md5(json_encode($navigation))); + ->willReturn(md5(json_encode([ ['id' => 'logout', 'href' => 'logout', 'icon' => 'icon' ] ]))); $this->navigationManager->expects($this->once()) ->method('getAll') ->with('settings') |