|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | + */ |
| 9 | + |
| 10 | +namespace OCA\Github\Tests\Integration; |
| 11 | + |
| 12 | +use OCA\Github\Controller\ConfigController; |
| 13 | +use OCA\Github\Service\SecretService; |
| 14 | +use OCP\Server; |
| 15 | +use PHPUnit\Framework\Attributes\DependsExternal; |
| 16 | +use PHPUnit\Framework\Attributes\Group; |
| 17 | +use Test\TestCase; |
| 18 | + |
| 19 | +#[Group('DB')] |
| 20 | +class GithubZTokenRevocationIntegrationTest extends TestCase { |
| 21 | + private SecretService $secretService; |
| 22 | + private ConfigController $configController; |
| 23 | + |
| 24 | + protected function setUp(): void { |
| 25 | + parent::setUp(); |
| 26 | + |
| 27 | + $this->secretService = Server::get(SecretService::class); |
| 28 | + $this->configController = Server::get(ConfigController::class); |
| 29 | + } |
| 30 | + |
| 31 | + #[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')] |
| 32 | + public function testRevokeToken(array $oauthData): void { |
| 33 | + $this->assertIsArray($oauthData, 'oauthData should be an array from OAuth test'); |
| 34 | + $this->assertArrayHasKey('userId', $oauthData, 'oauthData must contain userId'); |
| 35 | + $userId = $oauthData['userId']; |
| 36 | + |
| 37 | + self::loginAsUser($userId); |
| 38 | + |
| 39 | + $token = $this->secretService->getEncryptedUserValue($userId, 'token'); |
| 40 | + $this->assertNotSame('', $token, 'Token should exist before revocation'); |
| 41 | + echo 'TOKEN is not empty ' .strlen($token); |
| 42 | + |
| 43 | + $response = $this->configController->setConfig(['token' => '']); |
| 44 | + |
| 45 | + $this->assertArrayHasKey('user_name', $response->getData(), 'Response should contain user_name'); |
| 46 | + $this->assertSame('', $response->getData()['user_name'], 'user_name should be empty after token revocation'); |
| 47 | + |
| 48 | + $tokenAfter = $this->secretService->getEncryptedUserValue($userId, 'token'); |
| 49 | + $this->assertSame('', $tokenAfter, 'Token should be empty after revocation'); |
| 50 | + echo 'after revoke, TOKEN is empty ' .strlen($tokenAfter); |
| 51 | + } |
| 52 | +} |
0 commit comments