+ Displays a link to your OpenProject instance in the Nextcloud header.
+
+
+
+
+
+
+
+
+
+ Allows you to search OpenProject work packages via the universal search bar in Nextcloud.
+
+
+
+
+
+
+
+ Warning, everything you type in the search bar will be sent to your OpenProject instance.
+
+
+
+
`;
-exports[`PersonalSettings.vue oAuth user settings admin and user should be able to enable and disable the setting simultaneously 2`] = `
-Wrapper {
- "selector": ".openproject-prefs--form",
-}
+exports[`PersonalSettings.vue user settings admin and user should be able to enable and disable the setting simultaneously: oauth2 2`] = `
+
+
+
+
+
+
+
+ Displays a link to your OpenProject instance in the Nextcloud header.
+
+
+
+
+
+
+
+
+
+ Allows you to search OpenProject work packages via the universal search bar in Nextcloud.
+
+
+
+
+
+
+
+ Warning, everything you type in the search bar will be sent to your OpenProject instance.
+
+
+
+
`;
-exports[`PersonalSettings.vue oAuth user settings should be disabled if the admin has not enabled the settings 1`] = `
-Wrapper {
- "selector": ".openproject-prefs--form",
-}
+exports[`PersonalSettings.vue user settings admin and user should be able to enable and disable the setting simultaneously: oidc 1`] = `
+
+
+
+
+
+
+
+ Displays a link to your OpenProject instance in the Nextcloud header.
+
+
+
+
+
+
+
+
+
+ Allows you to search OpenProject work packages via the universal search bar in Nextcloud.
+
+
+
+
+
+
+
+ Warning, everything you type in the search bar will be sent to your OpenProject instance.
+
+
+
+
`;
-exports[`PersonalSettings.vue oAuth user settings should be enabled if the admin has enabled the settings 1`] = `
-Wrapper {
- "selector": ".openproject-prefs--form",
-}
+exports[`PersonalSettings.vue user settings admin and user should be able to enable and disable the setting simultaneously: oidc 2`] = `
+
+
+
+
+
+
+
+ Displays a link to your OpenProject instance in the Nextcloud header.
+
+
+
+
+
+
+
+
+
+ Allows you to search OpenProject work packages via the universal search bar in Nextcloud.
+
+
+
+
+
+
+
+ Warning, everything you type in the search bar will be sent to your OpenProject instance.
+
+
+
+
+`;
+
+exports[`PersonalSettings.vue user settings should be disabled if the admin has not enabled the settings: oauth2 1`] = `
+
+
+
+ Displays a link to your OpenProject instance in the Nextcloud header.
+
+
+
+
+
+ Allows you to search OpenProject work packages via the universal search bar in Nextcloud.
+
+
+
+
+
+`;
+
+exports[`PersonalSettings.vue user settings should be disabled if the admin has not enabled the settings: oidc 1`] = `
+
+
+
+ Displays a link to your OpenProject instance in the Nextcloud header.
+
+
+
+
+
+ Allows you to search OpenProject work packages via the universal search bar in Nextcloud.
+
+
+
+
+
+`;
+
+exports[`PersonalSettings.vue user settings should be enabled if the admin has enabled the settings: oauth2 1`] = `
+
+
+
+ Displays a link to your OpenProject instance in the Nextcloud header.
+
+
+
+
+
+ Allows you to search OpenProject work packages via the universal search bar in Nextcloud.
+
+
+
+
+
+ Warning, everything you type in the search bar will be sent to your OpenProject instance.
+
+
+
+
+`;
+
+exports[`PersonalSettings.vue user settings should be enabled if the admin has enabled the settings: oidc 1`] = `
+
+
+
+ Displays a link to your OpenProject instance in the Nextcloud header.
+
+
+
+
+
+ Allows you to search OpenProject work packages via the universal search bar in Nextcloud.
+
+
+
+
+
+ Warning, everything you type in the search bar will be sent to your OpenProject instance.
+
+
+
+
`;
diff --git a/tests/lib/Service/OpenProjectAPIServiceTest.php b/tests/lib/Service/OpenProjectAPIServiceTest.php
index 3860719c8..281577cfc 100644
--- a/tests/lib/Service/OpenProjectAPIServiceTest.php
+++ b/tests/lib/Service/OpenProjectAPIServiceTest.php
@@ -29,6 +29,7 @@
use OCA\UserOIDC\Event\ExchangedTokenRequestedEvent;
use OCA\UserOIDC\Exception\TokenExchangeFailedException;
use OCA\UserOIDC\Model\Token;
+use OCA\UserOIDC\User\Backend as OIDCBackend;
use OCP\App\IAppManager;
use OCP\AppFramework\Http;
use OCP\Encryption\IManager;
@@ -49,9 +50,11 @@
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
+use OCP\IUserSession;
use OCP\Log\ILogFactory;
use OCP\Security\IRemoteHostValidator;
use OCP\Security\ISecureRandom;
+use phpmock\phpunit\PHPMock;
use PhpPact\Consumer\InteractionBuilder;
use PhpPact\Consumer\Model\Body\Binary;
use PhpPact\Consumer\Model\ConsumerRequest;
@@ -61,19 +64,9 @@
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
-/**
- * overriding the class_exists method, so that the unit tests always pass,
- * no matter if the activity app is enabled or not
- */
-function class_exists(string $className): bool {
- if ($className === '\OCA\GroupFolders\Folder\FolderManager') {
- return true;
- } else {
- return \class_exists($className);
- }
-}
-
class OpenProjectAPIServiceTest extends TestCase {
+ use PHPMock;
+
/**
* @var InteractionBuilder
*/
@@ -662,6 +655,7 @@ private function getOpenProjectAPIServiceConstructArgs(array $constructParams =
'logFactory' => $this->createMock(ILogFactory::class),
'manager' => $this->createMock(IManager::class),
'exchangedTokenRequestedEventHelper' => $this->createMock(ExchangedTokenRequestedEventHelper::class),
+ 'userSession' => $this->createMock(IUserSession::class),
];
// replace default mocks with manually passed in mocks
@@ -4280,4 +4274,49 @@ public function testGetOIDCTokenNoToken(): void {
$result = $service->getOIDCToken();
$this->assertEquals(null, $result);
}
+
+ public function dataProviderForIsOIDCUser(): array {
+ $backendMock = $this->getMockBuilder(OIDCBackend::class)->disableOriginalConstructor()->getMock();
+ return [
+ 'has Backend class and OIDC user' => [
+ 'backend' => true,
+ 'oidcUser' => $backendMock,
+ 'expected' => true,
+ ],
+ 'has Backend class but not OIDC user' => [
+ 'backend' => true,
+ 'oidcUser' => new \stdClass(),
+ 'expected' => false,
+ ],
+ 'missing Backend class' => [
+ 'backend' => false,
+ 'oidcUser' => $backendMock,
+ 'expected' => false,
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider dataProviderForIsOIDCUser
+ *
+ * @return void
+ */
+ public function testIsOIDCUser($backend, $oidcUser, $expected): void {
+ $mock = $this->getFunctionMock(__NAMESPACE__, "class_exists");
+ $mock->expects($this->once())->willReturn($backend);
+
+ $userSessionMock = $this->createMock(IUserSession::class);
+ $userMock = $this->createMock(IUser::class);
+
+ $userMock->method('getBackend')->willReturn($oidcUser);
+ $userSessionMock->method('getUser')->willReturn($userMock);
+
+ $service = $this->getOpenProjectAPIServiceMock(
+ [],
+ ['userSession' => $userSessionMock],
+ );
+
+ $result = $service->isOIDCUser();
+ $this->assertEquals($expected, $result);
+ }
}
diff --git a/tests/lib/Settings/PersonalTest.php b/tests/lib/Settings/PersonalTest.php
index 02ef9a28a..6a7a489f9 100644
--- a/tests/lib/Settings/PersonalTest.php
+++ b/tests/lib/Settings/PersonalTest.php
@@ -136,7 +136,8 @@ public function testGetForm(
'search_enabled' => false,
'navigation_enabled' => false,
'admin_config_ok' => $adminConfigStatus,
- 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH
+ 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH,
+ 'oidc_user' => false,
]
],
['oauth-connection-result'],
@@ -198,7 +199,8 @@ public function testNoPersonalSettingsShouldUseValueFromTheDefaults() {
'search_enabled' => true,
'navigation_enabled' => true,
'admin_config_ok' => true,
- 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH
+ 'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH,
+ 'oidc_user' => false,
]
],
['oauth-connection-result'],