From 3caebc3b2b79af6ee347bfbbb5efd23e916860ba Mon Sep 17 00:00:00 2001 From: Saw-jan Date: Fri, 29 May 2026 15:01:02 +0545 Subject: [PATCH 1/2] refactor: organize app constants in Application Signed-off-by: Saw-jan --- lib/AppInfo/Application.php | 16 ++- lib/Controller/ConfigController.php | 16 +-- .../LoadAdditionalScriptsListener.php | 2 +- lib/Listener/OpenProjectReferenceListener.php | 2 +- .../Version2900Date20250718065820.php | 2 +- lib/Service/OpenProjectAPIService.php | 41 +++--- lib/Service/SettingsService.php | 19 +-- lib/Settings/Admin.php | 10 +- lib/TokenEventFactory.php | 2 +- tests/lib/Controller/ConfigControllerTest.php | 120 +++++++++--------- .../OpenProjectAPIControllerTest.php | 30 ++--- .../Controller/OpenProjectControllerTest.php | 2 +- tests/lib/Listener/LoadSidebarScriptTest.php | 4 +- .../lib/Service/OpenProjectAPIServiceTest.php | 80 ++++++------ tests/lib/Service/SettingsServiceTest.php | 36 +++--- tests/lib/Settings/AdminTest.php | 6 +- tests/lib/Settings/PersonalTest.php | 4 +- tests/lib/TokenEventFactoryTest.php | 4 +- 18 files changed, 197 insertions(+), 199 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index bdcacb317..8fe60968f 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -58,7 +58,17 @@ class Application extends App implements IBootstrap { public const APP_ID = 'integration_openproject'; public const OPEN_PROJECT_ENTITIES_NAME = 'OpenProject'; public const OPENPROJECT_ALL_GROUP_NAME = 'OpenProjectNoAutomaticProjectFolders'; - public const OPENPROJECT_API_SCOPES = ['api_v3']; + public const OPENPROJECT_API_SCOPES = ['api_v3']; + + public const AUTH_METHOD_OAUTH = 'oauth2'; + public const AUTH_METHOD_OIDC = 'oidc'; + public const NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE = "nextcloud_hub"; + public const NEXTCLOUD_HUB_OIDC_PROVIDER_LABEL = "Nextcloud Hub"; + public const EXTERNAL_OIDC_PROVIDER_TYPE = "external"; + + public const MIN_SUPPORTED_USER_OIDC_APP_VERSION = '7.2.0'; + public const MIN_SUPPORTED_OIDC_APP_VERSION = '1.14.1'; + public const MIN_SUPPORTED_GROUPFOLDERS_APP_VERSION = '1.0.0'; // default app name private const DEFAULT_APP_NAMES = [ @@ -154,8 +164,8 @@ public function registerNavigation(IUserSession $userSession): void { $userId, self::APP_ID, 'navigation_enabled', - $this->config->getAppValue(Application::APP_ID, 'default_enable_navigation', '0')) === '1') { - $openprojectUrl = $this->config->getAppValue(Application::APP_ID, 'openproject_instance_url', ''); + $this->config->getAppValue(self::APP_ID, 'default_enable_navigation', '0')) === '1') { + $openprojectUrl = $this->config->getAppValue(self::APP_ID, 'openproject_instance_url', ''); if ($openprojectUrl !== '') { $container->get(INavigationManager::class)->add(function () use ($container, $openprojectUrl) { $urlGenerator = $container->get(IURLGenerator::class); diff --git a/lib/Controller/ConfigController.php b/lib/Controller/ConfigController.php index 8d924bdf3..862a1d795 100755 --- a/lib/Controller/ConfigController.php +++ b/lib/Controller/ConfigController.php @@ -221,13 +221,13 @@ private function setIntegrationConfig(array $values): array { // determine if the full reset is done when configuration is already with "oauth2" $runningFullResetWithOAuth2Auth = ( $runningFullReset && - $oldAuthMethod === OpenProjectAPIService::AUTH_METHOD_OAUTH + $oldAuthMethod === Application::AUTH_METHOD_OAUTH ); // determine if the full reset is done when configuration is already with "oidc" $runningFullResetWithOIDCAuth = ( $runningFullReset && - $oldAuthMethod === OpenProjectAPIService::AUTH_METHOD_OIDC + $oldAuthMethod === Application::AUTH_METHOD_OIDC ); if ( (key_exists('openproject_client_id', $values) && key_exists('openproject_client_secret', $values)) @@ -379,13 +379,13 @@ private function setIntegrationConfig(array $values): array { // when switching from "oauth2" to "oidc" authorization method if (key_exists('authorization_method', $values) && - $values['authorization_method'] === OpenProjectAPIService::AUTH_METHOD_OIDC && $runningOauth2Reset) { + $values['authorization_method'] === Application::AUTH_METHOD_OIDC && $runningOauth2Reset) { $this->resetOauth2Configs(); } // when switching from "oidc" to "oauth2" authorization method if (key_exists('authorization_method', $values) && - $values['authorization_method'] === OpenProjectAPIService::AUTH_METHOD_OAUTH && $runningOIDCReset) { + $values['authorization_method'] === Application::AUTH_METHOD_OAUTH && $runningOIDCReset) { $this->resetOIDCConfigs(); } @@ -637,15 +637,15 @@ public function setUpIntegration(?array $values): DataResponse { // NOTE: this is for compatibility with older versions of the app // when the authorization_method is not provided, set default to "oauth2" if (\is_array($values) && !\array_key_exists('authorization_method', $values)) { - $values['authorization_method'] = OpenProjectAPIService::AUTH_METHOD_OAUTH; + $values['authorization_method'] = Application::AUTH_METHOD_OAUTH; } // For nextcloud_hub setup, set OIDC provider to Nextcloud Hub if not provided if ( - $values['authorization_method'] === OpenProjectAPIService::AUTH_METHOD_OIDC - && $values['sso_provider_type'] === SettingsService::NEXTCLOUDHUB_OIDC_PROVIDER_TYPE + $values['authorization_method'] === Application::AUTH_METHOD_OIDC + && $values['sso_provider_type'] === Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE && (!\array_key_exists('oidc_provider', $values) || !$values['oidc_provider']) ) { - $values['oidc_provider'] = SettingsService::NEXTCLOUDHUB_OIDC_PROVIDER_LABEL; + $values['oidc_provider'] = Application::NEXTCLOUD_HUB_OIDC_PROVIDER_LABEL; } // check all required settings diff --git a/lib/Listener/LoadAdditionalScriptsListener.php b/lib/Listener/LoadAdditionalScriptsListener.php index 20109d9b6..5ee1a6385 100644 --- a/lib/Listener/LoadAdditionalScriptsListener.php +++ b/lib/Listener/LoadAdditionalScriptsListener.php @@ -43,7 +43,7 @@ public function handle(Event $event): void { // then we need to hide the oidc based connection for the user // so this check is required if ( - $this->config->getAppValue(Application::APP_ID, 'authorization_method', '') === OpenProjectAPIService::AUTH_METHOD_OIDC && + $this->config->getAppValue(Application::APP_ID, 'authorization_method', '') === Application::AUTH_METHOD_OIDC && !$this->openProjectAPIService->getAccessToken($this->userId) ) { return; diff --git a/lib/Listener/OpenProjectReferenceListener.php b/lib/Listener/OpenProjectReferenceListener.php index b1dd02c86..9ab497c7f 100644 --- a/lib/Listener/OpenProjectReferenceListener.php +++ b/lib/Listener/OpenProjectReferenceListener.php @@ -51,7 +51,7 @@ public function handle(Event $event): void { // then we need to hide the oidc based connection for the user // so this check is required if ( - $this->config->getAppValue(Application::APP_ID, 'authorization_method', '') === OpenProjectAPIService::AUTH_METHOD_OIDC && + $this->config->getAppValue(Application::APP_ID, 'authorization_method', '') === Application::AUTH_METHOD_OIDC && !$this->openProjectAPIService->getAccessToken($this->userId) ) { return; diff --git a/lib/Migration/Version2900Date20250718065820.php b/lib/Migration/Version2900Date20250718065820.php index 3f4a92b36..c81848bff 100644 --- a/lib/Migration/Version2900Date20250718065820.php +++ b/lib/Migration/Version2900Date20250718065820.php @@ -39,7 +39,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt !(empty($opClientId) || empty($opClientSecret) || empty($ncClientId)); if (!$authenticationMethod && $hasCompleteOAuthSetup) { - $this->config->setAppValue(Application::APP_ID, 'authorization_method', OpenProjectAPIService::AUTH_METHOD_OAUTH); + $this->config->setAppValue(Application::APP_ID, 'authorization_method', Application::AUTH_METHOD_OAUTH); } return null; diff --git a/lib/Service/OpenProjectAPIService.php b/lib/Service/OpenProjectAPIService.php index 966730703..e76e73cf1 100644 --- a/lib/Service/OpenProjectAPIService.php +++ b/lib/Service/OpenProjectAPIService.php @@ -65,13 +65,6 @@ define('CACHE_TTL', 3600); class OpenProjectAPIService { - public const AUTH_METHOD_OAUTH = 'oauth2'; - public const AUTH_METHOD_OIDC = 'oidc'; - public const MIN_SUPPORTED_USER_OIDC_APP_VERSION = '7.2.0'; - public const MIN_SUPPORTED_OIDC_APP_VERSION = '1.14.1'; - public const MIN_SUPPORTED_GROUPFOLDERS_APP_VERSION = '1.0.0'; - public const NEXTCLOUD_HUB_PROVIDER = "nextcloud_hub"; - // 1 hour expiration public const DEFAULT_ACCESS_TOKEN_EXPIRATION = 3600; @@ -925,7 +918,7 @@ public static function isAdminConfigOkForOauth2(IConfig $config):bool { $authMethod = $config->getAppValue(Application::APP_ID, 'authorization_method'); // NOTE: For backwards compability, check the auth method only if provided // version: 2.8 -> 2.9 - if ($authMethod && $authMethod !== self::AUTH_METHOD_OAUTH) { + if ($authMethod && $authMethod !== Application::AUTH_METHOD_OAUTH) { return false; } @@ -947,7 +940,7 @@ public static function isAdminConfigOkForOIDCAuth(IConfig $config):bool { } $authMethod = $config->getAppValue(Application::APP_ID, 'authorization_method'); - if ($authMethod !== self::AUTH_METHOD_OIDC) { + if ($authMethod !== Application::AUTH_METHOD_OIDC) { return false; } @@ -961,17 +954,17 @@ public static function isAdminConfigOkForOIDCAuth(IConfig $config):bool { } // check for nextcloud_hub sso - if ($ssoProviderType === SettingsService::NEXTCLOUDHUB_OIDC_PROVIDER_TYPE) { + if ($ssoProviderType === Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE) { return !empty($targetAudienceClientId); } // check for external sso without token exchange - if ($ssoProviderType === SettingsService::EXTERNAL_OIDC_PROVIDER_TYPE && $tokenExchange === false) { + if ($ssoProviderType === Application::EXTERNAL_OIDC_PROVIDER_TYPE && $tokenExchange === false) { return true; } // check for external sso with token exchange - if ($ssoProviderType === SettingsService::EXTERNAL_OIDC_PROVIDER_TYPE && $tokenExchange === true) { + if ($ssoProviderType === Application::EXTERNAL_OIDC_PROVIDER_TYPE && $tokenExchange === true) { return !empty($targetAudienceClientId); } @@ -986,11 +979,11 @@ public static function isAdminConfigOkForOIDCAuth(IConfig $config):bool { public static function isAdminConfigOk(IConfig $config): bool { $authMethod = $config->getAppValue(Application::APP_ID, 'authorization_method'); - if ($authMethod === self::AUTH_METHOD_OAUTH) { + if ($authMethod === Application::AUTH_METHOD_OAUTH) { return self::isAdminConfigOkForOauth2($config); } - if ($authMethod === self::AUTH_METHOD_OIDC) { + if ($authMethod === Application::AUTH_METHOD_OIDC) { return self::isAdminConfigOkForOIDCAuth($config); } @@ -1206,7 +1199,7 @@ public function isGroupfoldersAppSupported(): bool { $appVersion = $this->appManager->getAppVersion('groupfolders'); return ( $this->isGroupfoldersAppEnabled() && - version_compare($appVersion, self::MIN_SUPPORTED_GROUPFOLDERS_APP_VERSION) >= 0 + version_compare($appVersion, Application::MIN_SUPPORTED_GROUPFOLDERS_APP_VERSION) >= 0 ); } @@ -1664,7 +1657,7 @@ public function getOpenProjectConfiguration(string $userId): array { */ public function getOIDCToken(string $userId): string { $authorizationMethod = $this->config->getAppValue(Application::APP_ID, 'authorization_method'); - if ($authorizationMethod !== SettingsService::AUTH_METHOD_OIDC) { + if ($authorizationMethod !== Application::AUTH_METHOD_OIDC) { return ''; } if (!$this->isUserOIDCAppInstalledAndEnabled()) { @@ -1689,7 +1682,7 @@ public function getOIDCToken(string $userId): string { } $SSOProviderType = $this->config->getAppValue(Application::APP_ID, 'sso_provider_type'); - if ($SSOProviderType === self::NEXTCLOUD_HUB_PROVIDER) { + if ($SSOProviderType === Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE) { $oidcClientId = $this->config->getAppValue(Application::APP_ID, 'targeted_audience_client_id'); $clientTokenType = ''; try { @@ -1747,7 +1740,7 @@ public function getAccessToken(?string $userId): string { $authMethod = $this->config->getAppValue(Application::APP_ID, 'authorization_method'); if ($token && !$this->isAccessTokenExpired($userId)) { - if ($authMethod === SettingsService::AUTH_METHOD_OIDC) { + if ($authMethod === Application::AUTH_METHOD_OIDC) { $this->initUserInfo($userId, $token); } return $token; @@ -1756,7 +1749,7 @@ public function getAccessToken(?string $userId): string { if ($token) { $this->logger->debug('Token has expired.', ['app' => $this->appName]); $this->logger->debug('Refreshing access token.', ['app' => $this->appName]); - if ($authMethod === SettingsService::AUTH_METHOD_OIDC) { + if ($authMethod === Application::AUTH_METHOD_OIDC) { $this->config->deleteUserValue($userId, Application::APP_ID, 'user_name'); $this->config->deleteUserValue($userId, Application::APP_ID, 'user_id'); } @@ -1764,7 +1757,7 @@ public function getAccessToken(?string $userId): string { // For OAuth2 setup, only try to refresh the expired token. // Token exchange needs to be initiated from the UI. - if ($authMethod === SettingsService::AUTH_METHOD_OAUTH && $token) { + if ($authMethod === Application::AUTH_METHOD_OAUTH && $token) { $refreshToken = $this->config->getUserValue($userId, Application::APP_ID, 'refresh_token'); $clientID = $this->config->getAppValue(Application::APP_ID, 'openproject_client_id'); $clientSecret = $this->config->getAppValue(Application::APP_ID, 'openproject_client_secret'); @@ -1784,7 +1777,7 @@ public function getAccessToken(?string $userId): string { return ''; } return $result['access_token']; - } elseif ($authMethod === SettingsService::AUTH_METHOD_OIDC) { + } elseif ($authMethod === Application::AUTH_METHOD_OIDC) { $token = $this->getOIDCToken($userId); if ($token) { $this->initUserInfo($userId, $token); @@ -1855,7 +1848,7 @@ class_exists('\OCA\UserOIDC\Event\ExchangedTokenRequestedEvent') && class_exists('\OCA\UserOIDC\Event\ExternalTokenRequestedEvent') && class_exists('\OCA\UserOIDC\Event\InternalTokenRequestedEvent') && class_exists('\OCA\UserOIDC\User\Backend') && - version_compare($userOidcVersion, self::MIN_SUPPORTED_USER_OIDC_APP_VERSION) >= 0 + version_compare($userOidcVersion, Application::MIN_SUPPORTED_USER_OIDC_APP_VERSION) >= 0 ); } @@ -1867,7 +1860,7 @@ public function isOIDCAppSupported(): bool { $appVersion = $this->appManager->getAppVersion('oidc'); return ( $this->isOIDCAppEnabled() && - version_compare($appVersion, self::MIN_SUPPORTED_OIDC_APP_VERSION) >= 0 + version_compare($appVersion, Application::MIN_SUPPORTED_OIDC_APP_VERSION) >= 0 ); } @@ -1876,7 +1869,7 @@ public function isOIDCAppSupported(): bool { */ public function isOIDCUser(): bool { $SSOProviderType = $this->config->getAppValue(Application::APP_ID, 'sso_provider_type'); - if ($SSOProviderType === self::NEXTCLOUD_HUB_PROVIDER) { + if ($SSOProviderType === Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE) { return true; } diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php index e62ddf26e..0754a108f 100644 --- a/lib/Service/SettingsService.php +++ b/lib/Service/SettingsService.php @@ -15,16 +15,11 @@ use OCP\Security\ISecureRandom; class SettingsService { - public const AUTH_METHOD_OAUTH = 'oauth2'; - public const AUTH_METHOD_OIDC = 'oidc'; - public const NEXTCLOUDHUB_OIDC_PROVIDER_TYPE = "nextcloud_hub"; - public const EXTERNAL_OIDC_PROVIDER_TYPE = "external"; - public const NEXTCLOUDHUB_OIDC_PROVIDER_LABEL = "Nextcloud Hub"; // => private const GENERAL_ADMIN_SETTINGS = [ // general settings 'openproject_instance_url' => 'string', - 'authorization_method' => [self::AUTH_METHOD_OAUTH, self::AUTH_METHOD_OIDC], + 'authorization_method' => [Application::AUTH_METHOD_OAUTH, Application::AUTH_METHOD_OIDC], 'default_enable_navigation' => 'boolean', 'default_enable_unified_search' => 'boolean', // groupfolders settings @@ -36,7 +31,7 @@ class SettingsService { 'openproject_client_secret' => 'string', ]; private const OIDC_ADMIN_SETTINGS = [ - 'sso_provider_type' => [self::NEXTCLOUDHUB_OIDC_PROVIDER_TYPE, self::EXTERNAL_OIDC_PROVIDER_TYPE], + 'sso_provider_type' => [Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE, Application::EXTERNAL_OIDC_PROVIDER_TYPE], 'oidc_provider' => 'string', 'targeted_audience_client_id' => 'string', 'token_exchange' => 'boolean', @@ -111,26 +106,26 @@ public function validateAdminSettingsForm(?array $values, bool $completeSetup = throw new InvalidArgumentException("'authorization_method' setting is missing"); } $authMethod = $values['authorization_method']; - if (!\in_array($authMethod, [self::AUTH_METHOD_OAUTH, self::AUTH_METHOD_OIDC])) { + if (!\in_array($authMethod, [Application::AUTH_METHOD_OAUTH, Application::AUTH_METHOD_OIDC])) { throw new InvalidArgumentException('Invalid authorization method'); } - if ($authMethod === self::AUTH_METHOD_OAUTH) { + if ($authMethod === Application::AUTH_METHOD_OAUTH) { $settings = $this->getCompleteOAuthSettings(); } else { $settings = $this->getCompleteOIDCSettings(); if (!\array_key_exists('sso_provider_type', $values)) { throw new InvalidArgumentException( "Incomplete settings: 'sso_provider_type' is required with '" - . self::AUTH_METHOD_OIDC + . Application::AUTH_METHOD_OIDC . "' method" ); } - if ($values['sso_provider_type'] === self::NEXTCLOUDHUB_OIDC_PROVIDER_TYPE) { + if ($values['sso_provider_type'] === Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE) { // for 'nextcloud_hub' type // 'oidc_provider' and 'token_exchange' settings are not required $settingsToSkip[] = 'oidc_provider'; $settingsToSkip[] = 'token_exchange'; - } elseif ($values['sso_provider_type'] === self::EXTERNAL_OIDC_PROVIDER_TYPE) { + } elseif ($values['sso_provider_type'] === Application::EXTERNAL_OIDC_PROVIDER_TYPE) { if (!\array_key_exists('token_exchange', $values)) { throw new InvalidArgumentException( "Incomplete settings: 'token_exchange' is required with external provider" diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index 55913ed11..aec0fec12 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -72,7 +72,7 @@ public function getForm(): TemplateResponse { // and there is existing complete Oauth2 setup $authenticationMethod = $this->config->getAppValue(Application::APP_ID, 'authorization_method', ''); if (!$authenticationMethod && OpenProjectAPIService::isAdminConfigOkForOauth2($this->config)) { - $authenticationMethod = OpenProjectAPIService::AUTH_METHOD_OAUTH; + $authenticationMethod = Application::AUTH_METHOD_OAUTH; $this->config->setAppValue(Application::APP_ID, 'authorization_method', $authenticationMethod); } @@ -111,25 +111,25 @@ public function getForm(): TemplateResponse { 'oidc_providers' => $this->openProjectAPIService->getRegisteredOidcProviders(), 'user_oidc_enabled' => $this->openProjectAPIService->isUserOIDCAppInstalledAndEnabled(), 'user_oidc_supported' => $this->openProjectAPIService->isUserOIDCAppSupported(), - 'user_oidc_minimum_version' => OpenProjectAPIService::MIN_SUPPORTED_USER_OIDC_APP_VERSION, + 'user_oidc_minimum_version' => Application::MIN_SUPPORTED_USER_OIDC_APP_VERSION, 'apps' => [ 'oidc' => [ 'name' => $this->openProjectAPIService->getAppsName('oidc'), 'enabled' => $this->openProjectAPIService->isOIDCAppEnabled(), 'supported' => $this->openProjectAPIService->isOIDCAppSupported(), - 'minimum_version' => OpenProjectAPIService::MIN_SUPPORTED_OIDC_APP_VERSION, + 'minimum_version' => Application::MIN_SUPPORTED_OIDC_APP_VERSION, ], 'user_oidc' => [ 'name' => $this->openProjectAPIService->getAppsName('user_oidc'), 'enabled' => $this->openProjectAPIService->isUserOIDCAppInstalledAndEnabled(), 'supported' => $this->openProjectAPIService->isUserOIDCAppSupported(), - 'minimum_version' => OpenProjectAPIService::MIN_SUPPORTED_USER_OIDC_APP_VERSION, + 'minimum_version' => Application::MIN_SUPPORTED_USER_OIDC_APP_VERSION, ], 'groupfolders' => [ 'name' => $this->openProjectAPIService->getAppsName('groupfolders'), 'enabled' => $this->openProjectAPIService->isGroupfoldersAppEnabled(), 'supported' => $this->openProjectAPIService->isGroupfoldersAppSupported(), - 'minimum_version' => OpenProjectAPIService::MIN_SUPPORTED_GROUPFOLDERS_APP_VERSION, + 'minimum_version' => Application::MIN_SUPPORTED_GROUPFOLDERS_APP_VERSION, ], ], ]; diff --git a/lib/TokenEventFactory.php b/lib/TokenEventFactory.php index d98b89946..b22d38380 100644 --- a/lib/TokenEventFactory.php +++ b/lib/TokenEventFactory.php @@ -33,7 +33,7 @@ public function getEvent(): InternalTokenEvent|ExternalTokenEvent|ExchangedToken // If the SSO provider is Nextcloud Hub, // get token from internal IDP (oidc) - if ($SSOProviderType === OpenProjectAPIService::NEXTCLOUD_HUB_PROVIDER) { + if ($SSOProviderType === Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE) { return new InternalTokenEvent($targetAudience, Application::OPENPROJECT_API_SCOPES, $targetAudience); } diff --git a/tests/lib/Controller/ConfigControllerTest.php b/tests/lib/Controller/ConfigControllerTest.php index 851418f1c..565607201 100644 --- a/tests/lib/Controller/ConfigControllerTest.php +++ b/tests/lib/Controller/ConfigControllerTest.php @@ -486,7 +486,7 @@ public function setAdminConfigStatusDataProviderForOauth2() { return [ [ [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => '$client_id', 'openproject_client_secret' => '$client_secret', 'openproject_instance_url' => 'http://openproject.com', @@ -495,7 +495,7 @@ public function setAdminConfigStatusDataProviderForOauth2() { ], [ [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => '', 'openproject_client_secret' => '$client_secret', 'openproject_instance_url' => 'http://openproject.com', @@ -529,7 +529,7 @@ public function testSetAdminConfigForDifferentAdminConfigStatusForOauth2($credsT ->method('getAppValue') ->willReturnMap([ [Application::APP_ID, 'openproject_instance_url', '', $credsToUpdate['openproject_instance_url']], - [Application::APP_ID, 'authorization_method', '', OpenProjectAPIService::AUTH_METHOD_OAUTH], + [Application::APP_ID, 'authorization_method', '', Application::AUTH_METHOD_OAUTH], [Application::APP_ID, 'openproject_client_id', '', $credsToUpdate['openproject_client_id']], [Application::APP_ID, 'openproject_client_secret', '', $credsToUpdate['openproject_client_secret']], [Application::APP_ID, 'nc_oauth_client_id', '', '123'], @@ -565,7 +565,7 @@ public function setAdminConfigStatusDataProviderForOIDC() { return [ [ [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => 'test-oidc-provider', 'targeted_audience_client_id' => 'test-client', 'openproject_instance_url' => 'http://openproject.com' @@ -574,7 +574,7 @@ public function setAdminConfigStatusDataProviderForOIDC() { ], [ [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => '', 'targeted_audience_client_id' => 'test-client', 'openproject_instance_url' => 'http://openproject.com' @@ -583,7 +583,7 @@ public function setAdminConfigStatusDataProviderForOIDC() { ], [ [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => '', 'targeted_audience_client_id' => '', 'openproject_instance_url' => 'http://openproject.com' @@ -592,7 +592,7 @@ public function setAdminConfigStatusDataProviderForOIDC() { ], [ [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => 'test-oidc-provider', 'targeted_audience_client_id' => '', 'openproject_instance_url' => 'http://openproject.com' @@ -626,9 +626,9 @@ public function testSetAdminConfigForDifferentAdminConfigStatusForOIDC($credsToU ->method('getAppValue') ->willReturnMap([ [Application::APP_ID, 'openproject_instance_url', '', $credsToUpdate['openproject_instance_url']], - [Application::APP_ID, 'authorization_method', '', OpenProjectAPIService::AUTH_METHOD_OIDC], + [Application::APP_ID, 'authorization_method', '', Application::AUTH_METHOD_OIDC], [Application::APP_ID, 'oidc_provider', '', $credsToUpdate['oidc_provider']], - [Application::APP_ID, 'sso_provider_type', '', SettingsService::NEXTCLOUDHUB_OIDC_PROVIDER_TYPE], + [Application::APP_ID, 'sso_provider_type', '', Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE], [Application::APP_ID, 'targeted_audience_client_id', '', $credsToUpdate['targeted_audience_client_id']], [Application::APP_ID, 'oPOAuthTokenRevokeStatus', '', ''], ]); @@ -663,13 +663,13 @@ public function setAdminConfigClearUserDataChangeNCOauthClientDataProvider() { return [ [ // everything changes so delete user values and change the oAuth Client [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => 'old-openproject_client_id', 'openproject_client_secret' => 'old-openproject_client_secret', 'openproject_instance_url' => 'http://old-openproject.com', ], [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => 'openproject_client_id', 'openproject_client_secret' => 'openproject_client_secret', 'openproject_instance_url' => 'http://openproject.com', @@ -679,13 +679,13 @@ public function setAdminConfigClearUserDataChangeNCOauthClientDataProvider() { ], [ // only client id changes so delete user values but don't change the oAuth Client [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => 'old-openproject_client_id', 'openproject_client_secret' => 'openproject_client_secret', 'openproject_instance_url' => 'http://openproject.com', ], [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => 'openproject_client_id', 'openproject_client_secret' => 'openproject_client_secret', 'openproject_instance_url' => 'http://openproject.com', @@ -695,13 +695,13 @@ public function setAdminConfigClearUserDataChangeNCOauthClientDataProvider() { ], [ // only client secret changes so delete user values but don't change the oAuth Client [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => 'openproject_client_id', 'openproject_client_secret' => 'old-openproject_client_secret', 'openproject_instance_url' => 'http://openproject.com', ], [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => 'openproject_client_id', 'openproject_client_secret' => 'openproject_client_secret', 'openproject_instance_url' => 'http://openproject.com', @@ -711,13 +711,13 @@ public function setAdminConfigClearUserDataChangeNCOauthClientDataProvider() { ], [ //only the openproject_instance_url changes so don't delete the user values but change the oAuth Client [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => 'openproject_client_id', 'openproject_client_secret' => 'openproject_client_secret', 'openproject_instance_url' => 'http://old-openproject.com', ], [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => 'openproject_client_id', 'openproject_client_secret' => 'openproject_client_secret', 'openproject_instance_url' => 'http://openproject.com', @@ -727,7 +727,7 @@ public function setAdminConfigClearUserDataChangeNCOauthClientDataProvider() { ], [ //everything cleared [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => 'openproject_client_id', 'openproject_client_secret' => 'openproject_client_secret', 'openproject_instance_url' => 'http://old-openproject.com', @@ -743,7 +743,7 @@ public function setAdminConfigClearUserDataChangeNCOauthClientDataProvider() { ], [ //everything cleared with empty strings [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => 'openproject_client_id', 'openproject_client_secret' => 'openproject_client_secret', 'openproject_instance_url' => 'http://old-openproject.com', @@ -928,7 +928,7 @@ public function oPOAuthTokenRevokeDataProvider() { return [ [ 'oldConfig' => [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => 'op_client', 'openproject_client_secret' => 'op_client_secret', 'nc_oauth_client_id' => 'nc_client', @@ -946,13 +946,13 @@ public function oPOAuthTokenRevokeDataProvider() { ], [ 'oldConfig' => [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => 'op_client', 'openproject_client_secret' => 'op_client_secret', 'nc_oauth_client_id' => 'nc_client', ], 'newConfig' => [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => 'client_id_changed', 'openproject_client_secret' => 'client_secret_changed', 'openproject_instance_url' => 'http://localhost:3000', @@ -1113,7 +1113,7 @@ public function oPOAuthTokenRevokeErrorDataProvider() { */ public function testOPOAuthTokenRevokeErrors($errorCode, $exception, $errMessage) { $oldAdminConfig = [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => 'some_old_client_id', 'openproject_client_secret' => 'some_old_client_secret', 'openproject_instance_url' => 'http://localhost:3000', @@ -1160,7 +1160,7 @@ public function testOPOAuthTokenRevokeErrors($errorCode, $exception, $errMessage $oldAdminConfig['openproject_client_secret'], '', $errorCode, - OpenProjectAPIService::AUTH_METHOD_OAUTH, + Application::AUTH_METHOD_OAUTH, $newAdminConfig['openproject_instance_url'], false, $newAdminConfig['openproject_client_id'], @@ -1247,7 +1247,7 @@ public function testOPOAuthTokenRevokeErrors($errorCode, $exception, $errMessage */ public function testOPOAuthTokenRevokeDoesNotOccurIfNoOPOAuthClientHasChanged() { $oldAdminConfig = [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => 'some_old_client_id', 'openproject_client_secret' => 'some_old_client_secret', 'openproject_instance_url' => 'http://localhost:3000', @@ -1330,7 +1330,7 @@ public function testSetupIntegrationProjectFoldersSetUp():void { ->method('getAppValue') ->willReturnMap([ [Application::APP_ID, 'openproject_instance_url', '', 'http://localhost:3000'], - [Application::APP_ID, 'authorization_method', '', OpenProjectAPIService::AUTH_METHOD_OAUTH], + [Application::APP_ID, 'authorization_method', '', Application::AUTH_METHOD_OAUTH], [Application::APP_ID, 'openproject_client_id', '', 'some_cilent_id'], [Application::APP_ID, 'openproject_client_secret', '', 'some_cilent_secret'], ]); @@ -1361,7 +1361,7 @@ public function testSetupIntegrationProjectFoldersSetUp():void { $configController = new ConfigController(...$constructArgs); $result = $configController->setAdminConfig([ - "authorization_method" => OpenProjectAPIService::AUTH_METHOD_OAUTH, + "authorization_method" => Application::AUTH_METHOD_OAUTH, "setup_project_folder" => true, "setup_app_password" => true ]); @@ -1428,13 +1428,13 @@ public function setAdminConfigForOIDCAuthSettingProvider() { return [ [ // set info if the authorization settings are changed [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => 'old-oidc_provider', 'targeted_audience_client_id' => 'old-targeted_audience_client_id', 'openproject_instance_url' => 'http://old-openproject.com', ], [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => 'oidc_provider', 'targeted_audience_client_id' => 'targeted_audience_client_id', 'openproject_instance_url' => 'http://openproject.com', @@ -1444,13 +1444,13 @@ public function setAdminConfigForOIDCAuthSettingProvider() { ], [ // set info even if only 'targeted_audience_client_id' authorization settings are changed [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => 'old-oidc_provider', 'targeted_audience_client_id' => 'old-targeted_audience_client_id', 'openproject_instance_url' => 'http://old-openproject.com', ], [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => 'old_oidc_provider', 'targeted_audience_client_id' => 'new_targeted_audience_client_id', 'openproject_instance_url' => 'http://openproject.com', @@ -1460,13 +1460,13 @@ public function setAdminConfigForOIDCAuthSettingProvider() { ], [ // setinfo even if only 'oidc_provider' authorization settings are changed [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => 'old-oidc_provider', 'targeted_audience_client_id' => 'old-targeted_audience_client_id', 'openproject_instance_url' => 'http://old-openproject.com', ], [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => 'new_oidc_provider', 'targeted_audience_client_id' => 'old-targeted_audience_client_id', 'openproject_instance_url' => 'http://openproject.com', @@ -1474,13 +1474,13 @@ public function setAdminConfigForOIDCAuthSettingProvider() { ], [ // set if authorization settings are empty string [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => 'old-oidc_provider', 'targeted_audience_client_id' => 'old-targeted_audience_client_id', 'openproject_instance_url' => 'http://old-openproject.com', ], [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => '', 'targeted_audience_client_id' => '', 'openproject_instance_url' => 'http://openproject.com', @@ -1488,13 +1488,13 @@ public function setAdminConfigForOIDCAuthSettingProvider() { ], [ // set if authorization settings are null [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => 'old-oidc_provider', 'targeted_audience_client_id' => 'old-targeted_audience_client_id', 'openproject_instance_url' => 'http://old-openproject.com', ], [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => null, 'targeted_audience_client_id' => null, 'openproject_instance_url' => 'http://openproject.com', @@ -1541,7 +1541,7 @@ public function testSetAdminConfigOIDCAuthSetting( $oldCreds['targeted_audience_client_id'], '123', '', - OpenProjectAPIService::AUTH_METHOD_OAUTH, + Application::AUTH_METHOD_OAUTH, $credsToUpdate['oidc_provider'], $credsToUpdate['targeted_audience_client_id'], $credsToUpdate['openproject_instance_url'] @@ -1572,13 +1572,13 @@ public function setAdminConfigForOAuth2AlreadyConfiguredDataProvider() { return [ [ // when switching from oauth2 to oidc, userdata gets deleted along with the nc client information [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => 'old-openproject_client_id', 'openproject_client_secret' => 'old-openproject_client_secret', 'openproject_instance_url' => 'http://old-openproject.com', ], [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'openproject_client_id' => '', 'openproject_client_secret' => '', 'openproject_instance_url' => 'http://old-openproject.com', @@ -1586,7 +1586,7 @@ public function setAdminConfigForOAuth2AlreadyConfiguredDataProvider() { ], [ // when resetting with OAUTH2 already configured, userdata gets deleted along with the nc client information [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => 'old-openproject_client_id', 'openproject_client_secret' => 'old-openproject_client_secret', 'openproject_instance_url' => 'http://old-openproject.com', @@ -1640,7 +1640,7 @@ public function testSetAdminConfigForOAuth2AlreadyConfigured( '123', '123', '', - OpenProjectAPIService::AUTH_METHOD_OAUTH, + Application::AUTH_METHOD_OAUTH, $credsToUpdate['openproject_client_id'], $credsToUpdate['openproject_client_secret'], $credsToUpdate['openproject_instance_url'] @@ -1692,13 +1692,13 @@ public function setAdminConfigForOIDCAlreadyConfigured() { return [ [ // when switching from oidc to oauth2, just the user information get deleted 'oldConfig' => [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => 'old-oidc_provider', 'targeted_audience_client_id' => 'old-targeted_audience_client_id', 'openproject_instance_url' => 'http://old-openproject.com', ], 'newConfig' => [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'oidc_provider' => '', 'targeted_audience_client_id' => '', 'openproject_instance_url' => 'http://old-openproject.com', @@ -1706,7 +1706,7 @@ public function setAdminConfigForOIDCAlreadyConfigured() { ], [ 'oldConfig' => [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => 'old-oidc_provider', 'targeted_audience_client_id' => 'old-targeted_audience_client_id', 'openproject_instance_url' => 'http://old-openproject.com', @@ -1821,52 +1821,52 @@ public function integrationDefaultSettingsProvider() { ...$defaultSettings, 'openproject_client_id' => 'test', 'openproject_client_secret' => 'test', - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, ], ], "complete oidc: NC Hub without 'oidc_provider'" => [ 'settings' => [ ...$defaultSettings, - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, - 'sso_provider_type' => SettingsService::NEXTCLOUDHUB_OIDC_PROVIDER_TYPE, + 'authorization_method' => Application::AUTH_METHOD_OIDC, + 'sso_provider_type' => Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE, 'targeted_audience_client_id' => 'test', ], 'expectedSettings' => [ ...$defaultSettings, - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, - 'sso_provider_type' => SettingsService::NEXTCLOUDHUB_OIDC_PROVIDER_TYPE, + 'authorization_method' => Application::AUTH_METHOD_OIDC, + 'sso_provider_type' => Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE, 'targeted_audience_client_id' => 'test', - 'oidc_provider' => SettingsService::NEXTCLOUDHUB_OIDC_PROVIDER_LABEL, + 'oidc_provider' => Application::NEXTCLOUD_HUB_OIDC_PROVIDER_LABEL, ], ], "complete oidc: NC Hub with empty 'oidc_provider'" => [ 'settings' => [ ...$defaultSettings, - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, - 'sso_provider_type' => SettingsService::NEXTCLOUDHUB_OIDC_PROVIDER_TYPE, + 'authorization_method' => Application::AUTH_METHOD_OIDC, + 'sso_provider_type' => Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE, 'targeted_audience_client_id' => 'test', 'oidc_provider' => '', ], 'expectedSettings' => [ ...$defaultSettings, - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, - 'sso_provider_type' => SettingsService::NEXTCLOUDHUB_OIDC_PROVIDER_TYPE, + 'authorization_method' => Application::AUTH_METHOD_OIDC, + 'sso_provider_type' => Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE, 'targeted_audience_client_id' => 'test', - 'oidc_provider' => SettingsService::NEXTCLOUDHUB_OIDC_PROVIDER_LABEL, + 'oidc_provider' => Application::NEXTCLOUD_HUB_OIDC_PROVIDER_LABEL, ], ], "complete oidc: NC Hub with 'oidc_provider'" => [ 'settings' => [ ...$defaultSettings, - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, - 'sso_provider_type' => SettingsService::NEXTCLOUDHUB_OIDC_PROVIDER_TYPE, + 'authorization_method' => Application::AUTH_METHOD_OIDC, + 'sso_provider_type' => Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE, 'targeted_audience_client_id' => 'test', 'oidc_provider' => 'test', ], 'expectedSettings' => [ ...$defaultSettings, - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, - 'sso_provider_type' => SettingsService::NEXTCLOUDHUB_OIDC_PROVIDER_TYPE, + 'authorization_method' => Application::AUTH_METHOD_OIDC, + 'sso_provider_type' => Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE, 'targeted_audience_client_id' => 'test', 'oidc_provider' => 'test', ], diff --git a/tests/lib/Controller/OpenProjectAPIControllerTest.php b/tests/lib/Controller/OpenProjectAPIControllerTest.php index 0cd8ce349..8a0d7868b 100644 --- a/tests/lib/Controller/OpenProjectAPIControllerTest.php +++ b/tests/lib/Controller/OpenProjectAPIControllerTest.php @@ -38,8 +38,8 @@ class OpenProjectAPIControllerTest extends TestCase { */ public function getAuthorizationMethodDataProvider() { return [ - [OpenProjectAPIService::AUTH_METHOD_OAUTH], - [OpenProjectAPIService::AUTH_METHOD_OIDC] + [Application::AUTH_METHOD_OAUTH], + [Application::AUTH_METHOD_OIDC] ]; } @@ -51,7 +51,7 @@ public function getAuthorizationMethodDataProvider() { * @return IConfig */ public function getConfigMock(string $authorizationMethod = '', $authToken = null, $opUrl = null): IConfig { - if ($authorizationMethod === OpenProjectAPIService::AUTH_METHOD_OAUTH) { + if ($authorizationMethod === Application::AUTH_METHOD_OAUTH) { $token = $authToken ?? '123'; } else { $token = ''; @@ -279,12 +279,12 @@ public function testGetOpenProjectAvatarNoType(string $authorizationMethod) { */ public function searchWorkPackagesDataProvider() { return [ - [OpenProjectAPIService::AUTH_METHOD_OAUTH, 'test', null, [['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]]], - [OpenProjectAPIService::AUTH_METHOD_OAUTH, 'test', 9090, [['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]]], - [OpenProjectAPIService::AUTH_METHOD_OAUTH, null, 9090, [['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]]], - [OpenProjectAPIService::AUTH_METHOD_OIDC, 'test', null, [['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]]], - [OpenProjectAPIService::AUTH_METHOD_OIDC, 'test', 9090, [['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]]], - [OpenProjectAPIService::AUTH_METHOD_OIDC, null, 9090, [['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]]] + [Application::AUTH_METHOD_OAUTH, 'test', null, [['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]]], + [Application::AUTH_METHOD_OAUTH, 'test', 9090, [['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]]], + [Application::AUTH_METHOD_OAUTH, null, 9090, [['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]]], + [Application::AUTH_METHOD_OIDC, 'test', null, [['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]]], + [Application::AUTH_METHOD_OIDC, 'test', 9090, [['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]]], + [Application::AUTH_METHOD_OIDC, null, 9090, [['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4], ['id' => 5]]] ]; } @@ -1081,37 +1081,37 @@ public function testLinkWorkPackageToFileForInvalidDataError(string $authorizati public function exceptionDataProvider(): array { return [ [ - OpenProjectAPIService::AUTH_METHOD_OAUTH, + Application::AUTH_METHOD_OAUTH, new OpenprojectErrorException('Precondition failed', 412), 412, 'Precondition failed' ], [ - OpenProjectAPIService::AUTH_METHOD_OAUTH, + Application::AUTH_METHOD_OAUTH, new OpenprojectResponseException('Malformed response'), 500, 'Malformed response' ], [ - OpenProjectAPIService::AUTH_METHOD_OAUTH, + Application::AUTH_METHOD_OAUTH, new Exception("Internal server error"), 500, 'Internal server error' ], [ - OpenProjectAPIService::AUTH_METHOD_OIDC, + Application::AUTH_METHOD_OIDC, new OpenprojectErrorException('Precondition failed', 412), 412, 'Precondition failed' ], [ - OpenProjectAPIService::AUTH_METHOD_OIDC, + Application::AUTH_METHOD_OIDC, new OpenprojectResponseException('Malformed response'), 500, 'Malformed response' ], [ - OpenProjectAPIService::AUTH_METHOD_OIDC, + Application::AUTH_METHOD_OIDC, new Exception("Internal server error"), 500, 'Internal server error' diff --git a/tests/lib/Controller/OpenProjectControllerTest.php b/tests/lib/Controller/OpenProjectControllerTest.php index cc6eff1b4..d77e2f582 100644 --- a/tests/lib/Controller/OpenProjectControllerTest.php +++ b/tests/lib/Controller/OpenProjectControllerTest.php @@ -285,7 +285,7 @@ public function testGetOpenProjectOauthURLWithStateAndPKCE(): void { $configMock ->method('getAppValue') ->willReturnMap([ - [Application::APP_ID, 'authorization_method', '', OpenProjectAPIService::AUTH_METHOD_OAUTH], + [Application::APP_ID, 'authorization_method', '', Application::AUTH_METHOD_OAUTH], [Application::APP_ID, 'openproject_instance_url', '', 'http://openproject.org'], [Application::APP_ID, 'openproject_client_id', '', 'myClientID'], [Application::APP_ID, 'openproject_client_secret', '', 'myClientSecret'], diff --git a/tests/lib/Listener/LoadSidebarScriptTest.php b/tests/lib/Listener/LoadSidebarScriptTest.php index 6ab2afbd0..10bd32d1c 100644 --- a/tests/lib/Listener/LoadSidebarScriptTest.php +++ b/tests/lib/Listener/LoadSidebarScriptTest.php @@ -47,11 +47,11 @@ protected function setUp(): void { public function dataTestHandle(): array { return [ [ - 'authMethod' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authMethod' => Application::AUTH_METHOD_OAUTH, 'openprojectUrl' => 'http://local.test', ], [ - 'authMethod' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authMethod' => Application::AUTH_METHOD_OIDC, 'openprojectUrl' => 'http://local.test', ], [ diff --git a/tests/lib/Service/OpenProjectAPIServiceTest.php b/tests/lib/Service/OpenProjectAPIServiceTest.php index d9c501a30..58805bc5b 100644 --- a/tests/lib/Service/OpenProjectAPIServiceTest.php +++ b/tests/lib/Service/OpenProjectAPIServiceTest.php @@ -582,7 +582,7 @@ class OpenProjectAPIServiceTest extends TestCase { */ public function getAppValues(array $withValues = []): array { $defaultValues = [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => $this->clientId, 'openproject_client_secret' => $this->clientSecret, 'openproject_instance_url' => $this->pactMockServerConfig->getBaseUri()->__toString(), @@ -777,11 +777,11 @@ private function getOpenProjectAPIService( $this->defaultConfigMock ->method('getAppValue') ->willReturnMap($this->getAppValues([ - 'authorization_method' => $authMethod ?? OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => $authMethod ?? Application::AUTH_METHOD_OAUTH, ])); $tokenExpiryTime = $oAuth2OrOidcToken === 'expired' ? 0 : time() + 7200; - if ($authMethod === OpenProjectAPIService::AUTH_METHOD_OIDC) { + if ($authMethod === Application::AUTH_METHOD_OIDC) { $this->defaultConfigMock ->method('getUserValue') ->willReturnMap([ @@ -800,7 +800,7 @@ private function getOpenProjectAPIService( [$userId, 'integration_openproject', 'token','new-Token'], ]); } - if ($authMethod === OpenProjectAPIService::AUTH_METHOD_OIDC) { + if ($authMethod === Application::AUTH_METHOD_OIDC) { $tokenMock = $this->getMockBuilder(Token::class)->disableOriginalConstructor()->getMock(); $exchangeTokenMock->method('getEvent')->willReturn($exchangedTokenRequestedEventMock); $exchangedTokenRequestedEventMock->method('getToken')->willReturn($tokenMock); @@ -1025,8 +1025,8 @@ public function testSearchWorkPackageRequestProblem() { */ public function getAuthorizationMethodDataProvider() { return [ - [OpenProjectAPIService::AUTH_METHOD_OAUTH], - [OpenProjectAPIService::AUTH_METHOD_OIDC] + [Application::AUTH_METHOD_OAUTH], + [Application::AUTH_METHOD_OIDC] ]; } @@ -1167,7 +1167,7 @@ public function testRequestUsingOAuthToken(string $authorizationMethod) { */ public function getAuthorizationMethodForOauth2DataProvider() { return [ - [OpenProjectAPIService::AUTH_METHOD_OAUTH] + [Application::AUTH_METHOD_OAUTH] ]; } @@ -1877,7 +1877,7 @@ public function testGetNodeNotFoundException($expectedReturn) { $storageMock = $this->getMockBuilder('\OCP\Files\IRootFolder')->getMock(); $storageMock->method('getUserFolder')->willReturn($folderMock); // here authorization method is of no use, just putting 'oauth2' since its the default - $service = $this->getOpenProjectAPIService(OpenProjectAPIService::AUTH_METHOD_OAUTH, $storageMock); + $service = $this->getOpenProjectAPIService(Application::AUTH_METHOD_OAUTH, $storageMock); $this->expectException(NotFoundException::class); $service->getNode('me', 1234); } @@ -1900,7 +1900,7 @@ public function getNodeDataProvider() { public function testGetNode($nodeClassName) { $storageMock = $this->getStorageMock($nodeClassName); // here authorization method is of no use, just putting 'oauth2' since its the default - $service = $this->getOpenProjectAPIService(OpenProjectAPIService::AUTH_METHOD_OAUTH, $storageMock); + $service = $this->getOpenProjectAPIService(Application::AUTH_METHOD_OAUTH, $storageMock); $result = $service->getNode('me', 1234); $this->assertTrue($result instanceof \OCP\Files\Node); } @@ -3298,7 +3298,7 @@ public function adminConfigStatusProviderForOauth(): array { ], [ 'config' => [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'openproject_client_id' => 'clientID', 'openproject_client_secret' => 'clientSecret', 'fresh_project_folder_setup', true, @@ -3316,7 +3316,7 @@ public function adminConfigStatusProviderForOauth(): array { ], [ 'config' => [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => 'clientID', 'openproject_client_secret' => 'clientSecret', 'fresh_project_folder_setup', false, @@ -3361,7 +3361,7 @@ public function adminConfigStatusProviderForOIDC(): array { [ 'config' => [ 'openproject_instance_url' => '', - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => '', 'targeted_audience_client_id' => '', 'sso_provider_type' => '', @@ -3372,7 +3372,7 @@ public function adminConfigStatusProviderForOIDC(): array { ], [ 'config' => [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => 'Keycloak', 'targeted_audience_client_id' => '', 'sso_provider_type' => '', @@ -3383,7 +3383,7 @@ public function adminConfigStatusProviderForOIDC(): array { ], [ 'config' => [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => '', 'targeted_audience_client_id' => 'targetClientID', 'sso_provider_type' => 'external', @@ -3394,7 +3394,7 @@ public function adminConfigStatusProviderForOIDC(): array { ], [ 'config' => [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'oidc_provider' => 'Keycloak', 'targeted_audience_client_id' => 'targetClientID', 'sso_provider_type' => 'external', @@ -3405,7 +3405,7 @@ public function adminConfigStatusProviderForOIDC(): array { ], [ 'config' => [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => 'oidcProvider', 'targeted_audience_client_id' => '', 'sso_provider_type' => 'external', @@ -3416,7 +3416,7 @@ public function adminConfigStatusProviderForOIDC(): array { ], [ 'config' => [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => 'oidcProvider', 'targeted_audience_client_id' => 'targetClientID', 'sso_provider_type' => '', @@ -3428,7 +3428,7 @@ public function adminConfigStatusProviderForOIDC(): array { [ 'config' => [ 'openproject_instance_url' => '', - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => 'oidcProvider', 'targeted_audience_client_id' => 'targetClientID', 'sso_provider_type' => '', @@ -3439,7 +3439,7 @@ public function adminConfigStatusProviderForOIDC(): array { ], [ 'config' => [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => 'oidcProvider', 'targeted_audience_client_id' => 'targetClientID', 'sso_provider_type' => 'external', @@ -3450,7 +3450,7 @@ public function adminConfigStatusProviderForOIDC(): array { ], [ 'config' => [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => 'oidcProvider', 'targeted_audience_client_id' => '', 'sso_provider_type' => 'external', @@ -3461,7 +3461,7 @@ public function adminConfigStatusProviderForOIDC(): array { ], [ 'config' => [ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, + 'authorization_method' => Application::AUTH_METHOD_OIDC, 'oidc_provider' => 'NC Provider', 'targeted_audience_client_id' => 'test-client', 'sso_provider_type' => 'nextcloud_hub', @@ -3497,7 +3497,7 @@ public function adminConfigOkDataProvider(): array { [ 'config' => [ 'openproject_instance_url' => 'http://op.local', - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH, + 'authorization_method' => Application::AUTH_METHOD_OAUTH, 'openproject_client_id' => 'clientID', 'openproject_client_secret' => 'clientSecret', 'fresh_project_folder_setup' => false, @@ -3508,8 +3508,8 @@ public function adminConfigOkDataProvider(): array { [ 'config' => [ 'openproject_instance_url' => 'http://op.local', - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC, - 'sso_provider_type' => OpenProjectAPIService::NEXTCLOUD_HUB_PROVIDER, + 'authorization_method' => Application::AUTH_METHOD_OIDC, + 'sso_provider_type' => Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE, 'oidc_provider' => 'Nextcloud', 'targeted_audience_client_id' => 'openproject', 'fresh_project_folder_setup' => false, @@ -4568,7 +4568,7 @@ public function testGetOIDCTokenSuccess(): void { $configMock ->method('getAppValue') ->willReturnMap($this->getAppValues([ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OIDC + 'authorization_method' => Application::AUTH_METHOD_OIDC ])); $calls = []; $configMock @@ -4608,7 +4608,7 @@ public function testGetOIDCTokenReturnsNullIfNotOIDC(): void { $configMock ->method('getAppValue') ->willReturnMap($this->getAppValues([ - 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH + 'authorization_method' => Application::AUTH_METHOD_OAUTH ])); $service = $this->getOpenProjectAPIServiceMock( [], @@ -4702,7 +4702,7 @@ public function testGetOIDCTokenClientTokenType(): void { $configMock->method('getAppValue') ->willReturnMap($this->getAppValues([ 'targeted_audience_client_id' => 'testclient', - 'sso_provider_type' => OpenProjectAPIService::NEXTCLOUD_HUB_PROVIDER, + 'sso_provider_type' => Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE, ])); $iManagerMock = $this->getMockBuilder(IManager::class)->getMock(); $iAppManagerMock = $this->getMockBuilder(IAppManager::class)->getMock(); @@ -4741,7 +4741,7 @@ public function getAccessTokenDataProvider(): array { 'userId is null' => [ 'token' => 'test_token', 'expired' => false, - 'authMethod' => SettingsService::AUTH_METHOD_OAUTH, + 'authMethod' => Application::AUTH_METHOD_OAUTH, 'tokenRefreshFailed' => false, 'expected' => '', 'userId' => null, @@ -4749,7 +4749,7 @@ public function getAccessTokenDataProvider(): array { 'has expired oauth token' => [ 'token' => 'test_token', 'expired' => true, - 'authMethod' => SettingsService::AUTH_METHOD_OAUTH, + 'authMethod' => Application::AUTH_METHOD_OAUTH, 'tokenRefreshFailed' => false, 'expected' => 'new_token', 'userId' => 'testUser', @@ -4757,7 +4757,7 @@ public function getAccessTokenDataProvider(): array { 'has expired oauth token and refresh fails' => [ 'token' => 'test_token', 'expired' => true, - 'authMethod' => SettingsService::AUTH_METHOD_OAUTH, + 'authMethod' => Application::AUTH_METHOD_OAUTH, 'tokenRefreshFailed' => true, 'expected' => null, 'userId' => 'testUser', @@ -4765,7 +4765,7 @@ public function getAccessTokenDataProvider(): array { 'has oidc token' => [ 'token' => 'test_token', 'expired' => false, - 'authMethod' => SettingsService::AUTH_METHOD_OIDC, + 'authMethod' => Application::AUTH_METHOD_OIDC, 'tokenRefreshFailed' => false, 'expected' => 'test_token', 'userId' => 'testUser', @@ -4773,7 +4773,7 @@ public function getAccessTokenDataProvider(): array { 'has expired oidc token' => [ 'token' => 'test_token', 'expired' => true, - 'authMethod' => SettingsService::AUTH_METHOD_OIDC, + 'authMethod' => Application::AUTH_METHOD_OIDC, 'tokenRefreshFailed' => false, 'expected' => 'new_token', 'userId' => 'testUser', @@ -4825,7 +4825,7 @@ public function testGetAccessToken( ->willReturn($expired); } - if ($token && $expired && $authMethod === SettingsService::AUTH_METHOD_OIDC) { + if ($token && $expired && $authMethod === Application::AUTH_METHOD_OIDC) { $configMock ->expects($this->exactly(2)) ->method("deleteUserValue") @@ -4837,7 +4837,7 @@ public function testGetAccessToken( $configMock->expects($this->never())->method("deleteUserValue"); } - if ($token && $authMethod === SettingsService::AUTH_METHOD_OIDC && (!$expired || $expectedToken)) { + if ($token && $authMethod === Application::AUTH_METHOD_OIDC && (!$expired || $expectedToken)) { $expectedTokenForInitUserInfo = $expired ? $expectedToken : $token; $service->expects($this->once()) ->method('initUserInfo') @@ -4846,7 +4846,7 @@ public function testGetAccessToken( $service->expects($this->never())->method('initUserInfo'); } - if ($authMethod === SettingsService::AUTH_METHOD_OAUTH && $expired) { + if ($authMethod === Application::AUTH_METHOD_OAUTH && $expired) { if ($tokenRefreshFailed) { $service->expects($this->once()) ->method('requestOAuthAccessToken') @@ -4883,7 +4883,7 @@ public function testGetAccessToken( } else { $service->expects($this->never())->method('requestOAuthAccessToken'); } - if ($authMethod === SettingsService::AUTH_METHOD_OIDC && $expired) { + if ($authMethod === Application::AUTH_METHOD_OIDC && $expired) { $service->expects($this->once()) ->method('getOIDCToken') ->with($userId) @@ -4920,7 +4920,7 @@ public function dataProviderForIsOIDCUser(): array { 'configure with Nextcloud Hub' => [ 'hasOIDCBackend' => true, 'userBackend' => new \stdClass(), - 'SSOProviderType' => OpenProjectAPIService::NEXTCLOUD_HUB_PROVIDER, + 'SSOProviderType' => Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE, 'expected' => true, ], ]; @@ -4935,7 +4935,7 @@ public function testIsOIDCUser($hasOIDCBackend, $userBackend, $SSOProviderType, $configMock = $this->getMockBuilder(IConfig::class)->getMock(); $configMock->method('getAppValue')->willReturn($SSOProviderType); - if ($SSOProviderType !== OpenProjectAPIService::NEXTCLOUD_HUB_PROVIDER) { + if ($SSOProviderType !== Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE) { $this->classExistsMock->expects($this->once())->willReturn($hasOIDCBackend); } @@ -4972,7 +4972,7 @@ public function getHigherVersionThanSupported(string $version): string { * Data provider for testIsUserOIDCAppSupported */ public function dataProviderForIsUserOIDCAppSupported(): array { - $supportedVersion = OpenProjectAPIService::MIN_SUPPORTED_USER_OIDC_APP_VERSION; + $supportedVersion = Application::MIN_SUPPORTED_USER_OIDC_APP_VERSION; return [ 'has installed supported user_oidc apps and all classes exist' => [ 'appInstalledAndEnabled' => true, @@ -5037,7 +5037,7 @@ public function testIsUserOIDCAppSupported($appInstalledAndEnabled, $classesExis * Data provider for testIsOIDCAppSupported */ public function dataProviderForIsOIDCAppSupported(): array { - $supportedVersion = OpenProjectAPIService::MIN_SUPPORTED_OIDC_APP_VERSION; + $supportedVersion = Application::MIN_SUPPORTED_OIDC_APP_VERSION; return [ 'supported app enabled' => [ 'appEnabled' => true, diff --git a/tests/lib/Service/SettingsServiceTest.php b/tests/lib/Service/SettingsServiceTest.php index 28d707e73..b7e1d9917 100644 --- a/tests/lib/Service/SettingsServiceTest.php +++ b/tests/lib/Service/SettingsServiceTest.php @@ -70,7 +70,7 @@ public function invalidSettingsProvider(): array { return [ "Random missing settings" => [ "configs" => [ - "authorization_method" => SettingsService::AUTH_METHOD_OAUTH, + "authorization_method" => Application::AUTH_METHOD_OAUTH, ], "completeSetup" => true, "message" => "invalid key", @@ -93,7 +93,7 @@ public function invalidSettingsProvider(): array { "incomplete settings: oauth2" => [ "configs" => [ "openproject_instance_url" => "http://test.op.example", - "authorization_method" => SettingsService::AUTH_METHOD_OAUTH, + "authorization_method" => Application::AUTH_METHOD_OAUTH, "default_enable_navigation" => false, "default_enable_unified_search" => false, 'openproject_client_id' => 'test', @@ -106,7 +106,7 @@ public function invalidSettingsProvider(): array { "incomplete settings(oidc): missing 'sso_provider_type'" => [ "configs" => [ "openproject_instance_url" => "http://test.op.example", - "authorization_method" => SettingsService::AUTH_METHOD_OIDC, + "authorization_method" => Application::AUTH_METHOD_OIDC, "default_enable_navigation" => false, "default_enable_unified_search" => false, "oidc_provider" => "Nextcloud Hub", @@ -121,10 +121,10 @@ public function invalidSettingsProvider(): array { "incomplete settings (oidc): missing 'token_exchange' with external provider" => [ "configs" => [ "openproject_instance_url" => "http://test.op.example", - "authorization_method" => SettingsService::AUTH_METHOD_OIDC, + "authorization_method" => Application::AUTH_METHOD_OIDC, "default_enable_navigation" => false, "default_enable_unified_search" => false, - 'sso_provider_type' => SettingsService::EXTERNAL_OIDC_PROVIDER_TYPE, + 'sso_provider_type' => Application::EXTERNAL_OIDC_PROVIDER_TYPE, "oidc_provider" => "Nextcloud Hub", "setup_project_folder" => false, "setup_app_password" => false, @@ -135,7 +135,7 @@ public function invalidSettingsProvider(): array { "invalid oidc provider type" => [ "configs" => [ "openproject_instance_url" => "http://test.op.example", - "authorization_method" => SettingsService::AUTH_METHOD_OIDC, + "authorization_method" => Application::AUTH_METHOD_OIDC, "default_enable_navigation" => false, "default_enable_unified_search" => false, 'sso_provider_type' => 'test', // invalid provider type @@ -151,7 +151,7 @@ public function invalidSettingsProvider(): array { "invalid groupfolder settings: true & false" => [ "configs" => [ "openproject_instance_url" => "http://test.op.example", - "authorization_method" => SettingsService::AUTH_METHOD_OAUTH, + "authorization_method" => Application::AUTH_METHOD_OAUTH, "default_enable_navigation" => false, "default_enable_unified_search" => false, 'openproject_client_id' => 'test', @@ -165,7 +165,7 @@ public function invalidSettingsProvider(): array { "invalid groupfolder settings: false & true" => [ "configs" => [ "openproject_instance_url" => "http://test.op.example", - "authorization_method" => SettingsService::AUTH_METHOD_OAUTH, + "authorization_method" => Application::AUTH_METHOD_OAUTH, "default_enable_navigation" => false, "default_enable_unified_search" => false, 'openproject_client_id' => 'test', @@ -179,7 +179,7 @@ public function invalidSettingsProvider(): array { "invalid settings value: incorrect data type" => [ "configs" => [ "openproject_instance_url" => "http://test.op.example", - "authorization_method" => SettingsService::AUTH_METHOD_OAUTH, + "authorization_method" => Application::AUTH_METHOD_OAUTH, "default_enable_navigation" => 'false', // string instead of boolean "default_enable_unified_search" => false, 'openproject_client_id' => 'test', @@ -193,7 +193,7 @@ public function invalidSettingsProvider(): array { "invalid settings value: empty string" => [ "configs" => [ "openproject_instance_url" => "", // empty string - "authorization_method" => SettingsService::AUTH_METHOD_OAUTH, + "authorization_method" => Application::AUTH_METHOD_OAUTH, "default_enable_navigation" => false, "default_enable_unified_search" => false, 'openproject_client_id' => 'test', @@ -207,7 +207,7 @@ public function invalidSettingsProvider(): array { "unknown settings" => [ "configs" => [ "openproject_instance_url" => "http://test.op.example", - "authorization_method" => SettingsService::AUTH_METHOD_OAUTH, + "authorization_method" => Application::AUTH_METHOD_OAUTH, "default_enable_navigation" => false, "default_enable_unified_search" => false, 'openproject_client_id' => 'test', @@ -242,7 +242,7 @@ public function validSettingsProvider(): array { "complete settings: oauth2" => [ "configs" => [ "openproject_instance_url" => "http://test.op.example", - "authorization_method" => SettingsService::AUTH_METHOD_OAUTH, + "authorization_method" => Application::AUTH_METHOD_OAUTH, "default_enable_navigation" => false, "default_enable_unified_search" => false, "openproject_client_id" => "test", @@ -255,10 +255,10 @@ public function validSettingsProvider(): array { "complete settings: oidc" => [ "configs" => [ "openproject_instance_url" => "http://test.op.example", - "authorization_method" => SettingsService::AUTH_METHOD_OIDC, + "authorization_method" => Application::AUTH_METHOD_OIDC, "default_enable_navigation" => false, "default_enable_unified_search" => false, - "sso_provider_type" => SettingsService::NEXTCLOUDHUB_OIDC_PROVIDER_TYPE, + "sso_provider_type" => Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE, "oidc_provider" => "Nextcloud Hub", "token_exchange" => false, "targeted_audience_client_id" => "test", @@ -270,10 +270,10 @@ public function validSettingsProvider(): array { "complete settings (oidc): missing 'token_exchange' with NC Hub" => [ "configs" => [ "openproject_instance_url" => "http://test.op.example", - "authorization_method" => SettingsService::AUTH_METHOD_OIDC, + "authorization_method" => Application::AUTH_METHOD_OIDC, "default_enable_navigation" => false, "default_enable_unified_search" => false, - "sso_provider_type" => SettingsService::NEXTCLOUDHUB_OIDC_PROVIDER_TYPE, + "sso_provider_type" => Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE, "oidc_provider" => "Nextcloud Hub", "targeted_audience_client_id" => "test", "setup_project_folder" => true, @@ -284,10 +284,10 @@ public function validSettingsProvider(): array { "complete settings (oidc): missing 'targeted_audience_client_id' with external and disabled token exchange" => [ "configs" => [ "openproject_instance_url" => "http://test.op.example", - "authorization_method" => SettingsService::AUTH_METHOD_OIDC, + "authorization_method" => Application::AUTH_METHOD_OIDC, "default_enable_navigation" => false, "default_enable_unified_search" => false, - "sso_provider_type" => SettingsService::EXTERNAL_OIDC_PROVIDER_TYPE, + "sso_provider_type" => Application::EXTERNAL_OIDC_PROVIDER_TYPE, "oidc_provider" => "Nextcloud Hub", "token_exchange" => false, "setup_project_folder" => true, diff --git a/tests/lib/Settings/AdminTest.php b/tests/lib/Settings/AdminTest.php index c9ba9476a..e97b80a7d 100644 --- a/tests/lib/Settings/AdminTest.php +++ b/tests/lib/Settings/AdminTest.php @@ -66,7 +66,7 @@ public function dataTestGetForm(): array { "complete oauth2 admin config with correct authorization_method" => [ "config" => [ "openproject_instance_url" => "http://op.local.test", - "authorization_method" => SettingsService::AUTH_METHOD_OAUTH, + "authorization_method" => Application::AUTH_METHOD_OAUTH, "openproject_client_id" => "openproject", "openproject_client_secret" => "op-secret", ], @@ -75,7 +75,7 @@ public function dataTestGetForm(): array { "complete oidc admin config" => [ "config" => [ "openproject_instance_url" => "http://op.local.test", - "authorization_method" => SettingsService::AUTH_METHOD_OIDC, + "authorization_method" => Application::AUTH_METHOD_OIDC, ], "setupWithOauth" => false, ], @@ -101,7 +101,7 @@ public function testGetForm(array $config, bool $setupWithOauth): void { if (!$config['authorization_method'] && $setupWithOauth) { $this->config->expects($this->once()) ->method('setAppValue') - ->with(Application::APP_ID, 'authorization_method', SettingsService::AUTH_METHOD_OAUTH); + ->with(Application::APP_ID, 'authorization_method', Application::AUTH_METHOD_OAUTH); } else { $this->config->expects($this->never())->method('setAppValue'); } diff --git a/tests/lib/Settings/PersonalTest.php b/tests/lib/Settings/PersonalTest.php index 37c8260dc..9aba89264 100644 --- a/tests/lib/Settings/PersonalTest.php +++ b/tests/lib/Settings/PersonalTest.php @@ -74,7 +74,7 @@ public function dataTestGetForm(): array { 'username' => 'testUser', "config" => [ "openproject_instance_url" => 'http://some.url', - "authentication_method" => OpenProjectAPIService::AUTH_METHOD_OAUTH, + "authentication_method" => Application::AUTH_METHOD_OAUTH, "openproject_client_id" => 'some-client-id', "openproject_client_secret" => 'some-client-secret', "nc_oauth_client_id" => 'nc-client', @@ -95,7 +95,7 @@ public function dataTestGetForm(): array { 'username' => 'testUser', "config" => [ "openproject_instance_url" => 'http://some.url', - "authentication_method" => OpenProjectAPIService::AUTH_METHOD_OIDC, + "authentication_method" => Application::AUTH_METHOD_OIDC, "openproject_client_id" => '', "openproject_client_secret" => '', "nc_oauth_client_id" => '', diff --git a/tests/lib/TokenEventFactoryTest.php b/tests/lib/TokenEventFactoryTest.php index 829c5c4c0..9696649be 100644 --- a/tests/lib/TokenEventFactoryTest.php +++ b/tests/lib/TokenEventFactoryTest.php @@ -22,7 +22,7 @@ class TokenEventFactoryTest extends TestCase { public function settingsProvider(): array { return [ "Nextcloud Hub setup" => [ - "providerType" => OpenProjectAPIService::NEXTCLOUD_HUB_PROVIDER, + "providerType" => Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE, "tokenExchange" => false, "class" => InternalTokenRequestedEvent::class, ], @@ -37,7 +37,7 @@ public function settingsProvider(): array { "class" => ExchangedTokenRequestedEvent::class, ], "Nextcloud Hub with token exchange enabled" => [ - "providerType" => OpenProjectAPIService::NEXTCLOUD_HUB_PROVIDER, + "providerType" => Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE, "tokenExchange" => true, "class" => InternalTokenRequestedEvent::class, ], From ba1291dccc0b3885ea1f7169978aaceb7d8f6553 Mon Sep 17 00:00:00 2001 From: Saw-jan Date: Fri, 29 May 2026 15:09:37 +0545 Subject: [PATCH 2/2] refactor: remove unused imports Signed-off-by: Saw-jan --- lib/TokenEventFactory.php | 1 - tests/lib/Controller/OpenProjectAPIControllerTest.php | 1 + tests/lib/Settings/AdminTest.php | 1 - tests/lib/TokenEventFactoryTest.php | 1 - 4 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/TokenEventFactory.php b/lib/TokenEventFactory.php index b22d38380..15db9e02f 100644 --- a/lib/TokenEventFactory.php +++ b/lib/TokenEventFactory.php @@ -8,7 +8,6 @@ namespace OCA\OpenProject; use OCA\OpenProject\AppInfo\Application; -use OCA\OpenProject\Service\OpenProjectAPIService; use OCA\UserOIDC\Event\ExchangedTokenRequestedEvent as ExchangedTokenEvent; use OCA\UserOIDC\Event\ExternalTokenRequestedEvent as ExternalTokenEvent; use OCA\UserOIDC\Event\InternalTokenRequestedEvent as InternalTokenEvent; diff --git a/tests/lib/Controller/OpenProjectAPIControllerTest.php b/tests/lib/Controller/OpenProjectAPIControllerTest.php index 8a0d7868b..3fcd72179 100644 --- a/tests/lib/Controller/OpenProjectAPIControllerTest.php +++ b/tests/lib/Controller/OpenProjectAPIControllerTest.php @@ -9,6 +9,7 @@ use Exception; use InvalidArgumentException; +use OCA\OpenProject\AppInfo\Application; use OCA\OpenProject\Exception\OpenprojectErrorException; use OCA\OpenProject\Exception\OpenprojectResponseException; use OCA\OpenProject\Service\OpenProjectAPIService; diff --git a/tests/lib/Settings/AdminTest.php b/tests/lib/Settings/AdminTest.php index e97b80a7d..3327d5659 100644 --- a/tests/lib/Settings/AdminTest.php +++ b/tests/lib/Settings/AdminTest.php @@ -10,7 +10,6 @@ use OCA\OpenProject\AppInfo\Application; use OCA\OpenProject\Service\OauthService; use OCA\OpenProject\Service\OpenProjectAPIService; -use OCA\OpenProject\Service\SettingsService; use OCP\AppFramework\Services\IInitialState; use OCP\IConfig; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/lib/TokenEventFactoryTest.php b/tests/lib/TokenEventFactoryTest.php index 9696649be..ec4d44a79 100644 --- a/tests/lib/TokenEventFactoryTest.php +++ b/tests/lib/TokenEventFactoryTest.php @@ -8,7 +8,6 @@ namespace OCA\OpenProject; use OCA\OpenProject\AppInfo\Application; -use OCA\OpenProject\Service\OpenProjectAPIService; use OCA\UserOIDC\Event\ExchangedTokenRequestedEvent; use OCA\UserOIDC\Event\ExternalTokenRequestedEvent; use OCA\UserOIDC\Event\InternalTokenRequestedEvent;