mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #56921 from nextcloud/fix-caching-routes-by-users-with-an-active-session
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
Integration sqlite / changes (push) Waiting to run
Integration sqlite / integration-sqlite (master, 8.4, main, --tags ~@large files_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, capabilities_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, collaboration_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, comments_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, dav_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, federation_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, file_conversions) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, files_reminders) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, filesdrop_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, ldap_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, openldap_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, openldap_numerical_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, remoteapi_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, routing_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, setup_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, sharees_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, sharing_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, theming_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, videoverification_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite-summary (push) Blocked by required conditions
Psalm static code analysis / static-code-analysis (push) Waiting to run
Psalm static code analysis / static-code-analysis-security (push) Waiting to run
Psalm static code analysis / static-code-analysis-ocp (push) Waiting to run
Psalm static code analysis / static-code-analysis-ncu (push) Waiting to run
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
Integration sqlite / changes (push) Waiting to run
Integration sqlite / integration-sqlite (master, 8.4, main, --tags ~@large files_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, capabilities_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, collaboration_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, comments_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, dav_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, federation_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, file_conversions) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, files_reminders) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, filesdrop_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, ldap_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, openldap_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, openldap_numerical_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, remoteapi_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, routing_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, setup_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, sharees_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, sharing_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, theming_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, videoverification_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite-summary (push) Blocked by required conditions
Psalm static code analysis / static-code-analysis (push) Waiting to run
Psalm static code analysis / static-code-analysis-security (push) Waiting to run
Psalm static code analysis / static-code-analysis-ocp (push) Waiting to run
Psalm static code analysis / static-code-analysis-ncu (push) Waiting to run
This commit is contained in:
commit
db530d1eae
9 changed files with 110 additions and 2 deletions
|
|
@ -63,5 +63,10 @@ return [
|
|||
'type' => null
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'Routes#getRoutesInRoutesPhp',
|
||||
'url' => '/api/v1/routes/routesphp/{app}',
|
||||
'verb' => 'GET',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
|
|
|||
7
apps/testing/clean_apcu_cache.php
Normal file
7
apps/testing/clean_apcu_cache.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
apcu_clear_cache();
|
||||
|
|
@ -12,6 +12,7 @@ return array(
|
|||
'OCA\\Testing\\Controller\\ConfigController' => $baseDir . '/../lib/Controller/ConfigController.php',
|
||||
'OCA\\Testing\\Controller\\LockingController' => $baseDir . '/../lib/Controller/LockingController.php',
|
||||
'OCA\\Testing\\Controller\\RateLimitTestController' => $baseDir . '/../lib/Controller/RateLimitTestController.php',
|
||||
'OCA\\Testing\\Controller\\RoutesController' => $baseDir . '/../lib/Controller/RoutesController.php',
|
||||
'OCA\\Testing\\Conversion\\ConversionProvider' => $baseDir . '/../lib/Conversion/ConversionProvider.php',
|
||||
'OCA\\Testing\\HiddenGroupBackend' => $baseDir . '/../lib/HiddenGroupBackend.php',
|
||||
'OCA\\Testing\\Listener\\GetDeclarativeSettingsValueListener' => $baseDir . '/../lib/Listener/GetDeclarativeSettingsValueListener.php',
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ class ComposerStaticInitTesting
|
|||
'OCA\\Testing\\Controller\\ConfigController' => __DIR__ . '/..' . '/../lib/Controller/ConfigController.php',
|
||||
'OCA\\Testing\\Controller\\LockingController' => __DIR__ . '/..' . '/../lib/Controller/LockingController.php',
|
||||
'OCA\\Testing\\Controller\\RateLimitTestController' => __DIR__ . '/..' . '/../lib/Controller/RateLimitTestController.php',
|
||||
'OCA\\Testing\\Controller\\RoutesController' => __DIR__ . '/..' . '/../lib/Controller/RoutesController.php',
|
||||
'OCA\\Testing\\Conversion\\ConversionProvider' => __DIR__ . '/..' . '/../lib/Conversion/ConversionProvider.php',
|
||||
'OCA\\Testing\\HiddenGroupBackend' => __DIR__ . '/..' . '/../lib/HiddenGroupBackend.php',
|
||||
'OCA\\Testing\\Listener\\GetDeclarativeSettingsValueListener' => __DIR__ . '/..' . '/../lib/Listener/GetDeclarativeSettingsValueListener.php',
|
||||
|
|
|
|||
42
apps/testing/lib/Controller/RoutesController.php
Normal file
42
apps/testing/lib/Controller/RoutesController.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
namespace OCA\Testing\Controller;
|
||||
|
||||
use OCP\App\AppPathNotFoundException;
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\OCSController;
|
||||
use OCP\IRequest;
|
||||
|
||||
class RoutesController extends OCSController {
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
private IAppManager $appManager,
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
}
|
||||
|
||||
public function getRoutesInRoutesPhp(string $app): DataResponse {
|
||||
try {
|
||||
$appPath = $this->appManager->getAppPath($app);
|
||||
} catch (AppPathNotFoundException) {
|
||||
return new DataResponse([], Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
$file = $appPath . '/appinfo/routes.php';
|
||||
if (!file_exists($file)) {
|
||||
return new DataResponse();
|
||||
}
|
||||
|
||||
$routes = include $file;
|
||||
|
||||
return new DataResponse($routes);
|
||||
}
|
||||
}
|
||||
|
|
@ -827,6 +827,9 @@ trait Provisioning {
|
|||
* @param string $app
|
||||
*/
|
||||
public function appEnabledStateWillBeRestoredOnceTheScenarioFinishes($app) {
|
||||
$previousUser = $this->currentUser;
|
||||
$this->currentUser = 'admin';
|
||||
|
||||
if (in_array($app, $this->getAppsWithFilter('enabled'))) {
|
||||
$this->appsToEnableAfterScenario[] = $app;
|
||||
} elseif (in_array($app, $this->getAppsWithFilter('disabled'))) {
|
||||
|
|
@ -835,6 +838,8 @@ trait Provisioning {
|
|||
|
||||
// Apps that were not installed before the scenario will not be
|
||||
// disabled nor uninstalled after the scenario.
|
||||
|
||||
$this->currentUser = $previousUser;
|
||||
}
|
||||
|
||||
private function getAppsWithFilter($filter) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
use Behat\Behat\Context\Context;
|
||||
use Behat\Behat\Context\SnippetAcceptingContext;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
require __DIR__ . '/autoload.php';
|
||||
|
||||
|
|
@ -16,4 +17,26 @@ class RoutingContext implements Context, SnippetAcceptingContext {
|
|||
|
||||
protected function resetAppConfigs(): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* @AfterScenario
|
||||
*/
|
||||
public function deleteMemcacheSetting(): void {
|
||||
$this->invokingTheCommand('config:system:delete memcache.local');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given /^route "([^"]*)" of app "([^"]*)" is defined in routes.php$/
|
||||
*/
|
||||
public function routeOfAppIsDefinedInRoutesPhP(string $route, string $app): void {
|
||||
$previousUser = $this->currentUser;
|
||||
$this->currentUser = 'admin';
|
||||
|
||||
$this->sendingTo('GET', "/apps/testing/api/v1/routes/routesphp/{$app}");
|
||||
$this->theHTTPStatusCodeShouldBe('200');
|
||||
|
||||
Assert::assertStringContainsString($route, $this->response->getBody()->getContents());
|
||||
|
||||
$this->currentUser = $previousUser;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,3 +50,22 @@ Feature: appmanagement
|
|||
Given As an "admin"
|
||||
And sending "DELETE" to "/cloud/apps/weather_status"
|
||||
And app "weather_status" is disabled
|
||||
|
||||
Scenario: Cache routes from routes.php with a user in a group without some apps enabled
|
||||
Given invoking occ with "config:system:set memcache.local --value \OC\Memcache\APCu"
|
||||
And the command was successful
|
||||
And route "api/v1/location" of app "weather_status" is defined in routes.php
|
||||
And app "weather_status" enabled state will be restored once the scenario finishes
|
||||
And invoking occ with "app:enable weather_status --groups group1"
|
||||
And the command was successful
|
||||
When Logging in using web as "user2"
|
||||
And sending "GET" with exact url to "/apps/testing/clean_apcu_cache.php"
|
||||
And Sending a "GET" to "/index.php/apps/files" with requesttoken
|
||||
And the HTTP status code should be "200"
|
||||
Then As an "user2"
|
||||
And sending "GET" to "/apps/weather_status/api/v1/location"
|
||||
And the HTTP status code should be "412"
|
||||
And As an "user1"
|
||||
And sending "GET" to "/apps/weather_status/api/v1/location"
|
||||
And the OCS status code should be "200"
|
||||
And the HTTP status code should be "200"
|
||||
|
|
|
|||
|
|
@ -74,12 +74,17 @@ class CachingRouter extends Router {
|
|||
* @return array
|
||||
*/
|
||||
public function findMatchingRoute(string $url): array {
|
||||
return parent::findMatchingRoute($url);
|
||||
|
||||
$this->eventLogger->start('cacheroute:match', 'Match route');
|
||||
$key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . '#rootCollection';
|
||||
$cachedRoutes = $this->cache->get($key);
|
||||
if (!$cachedRoutes) {
|
||||
// Ensure that all apps are loaded, as for users with an active
|
||||
// session only the apps that are enabled for that user might have
|
||||
// been loaded.
|
||||
$enabledApps = $this->appManager->getEnabledApps();
|
||||
foreach ($enabledApps as $app) {
|
||||
$this->appManager->loadApp($app);
|
||||
}
|
||||
parent::loadRoutes();
|
||||
$cachedRoutes = $this->serializeRouteCollection($this->root);
|
||||
$this->cache->set($key, $cachedRoutes, ($this->config->getSystemValueBool('debug') ? 3 : 3600));
|
||||
|
|
|
|||
Loading…
Reference in a new issue