Skip to content

Commit 6aee41a

Browse files
committed
add new test to revoke the oauth token. it should be the last one to run
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 9f5b6e0 commit 6aee41a

4 files changed

Lines changed: 52 additions & 9 deletions

tests/integration/GitHubIssuePrReferenceIntegrationTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use OCA\Github\Reference\GithubIssuePrReferenceProvider;
1313
use OCA\Github\Service\SecretService;
1414
use OCP\Collaboration\Reference\IReference;
15-
use OCP\IConfig;
1615
use OCP\Server;
1716
use PHPUnit\Framework\Attributes\DependsExternal;
1817
use PHPUnit\Framework\Attributes\Group;
@@ -22,14 +21,12 @@
2221
class GitHubIssuePrReferenceIntegrationTest extends TestCase {
2322
private GithubIssuePrReferenceProvider $referenceProvider;
2423
private SecretService $secretService;
25-
private IConfig $config;
2624

2725
protected function setUp(): void {
2826
parent::setUp();
2927

3028
$this->referenceProvider = Server::get(GithubIssuePrReferenceProvider::class);
3129
$this->secretService = Server::get(SecretService::class);
32-
$this->config = Server::get(IConfig::class);
3330
}
3431

3532
#[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')]

tests/integration/GitHubNotificationsIntegrationTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
use OCA\Github\Service\GithubAPIService;
1313
use OCA\Github\Service\SecretService;
14-
use OCP\IConfig;
1514
use OCP\Server;
1615
use PHPUnit\Framework\Attributes\DependsExternal;
1716
use PHPUnit\Framework\Attributes\Group;
@@ -21,14 +20,12 @@
2120
class GitHubNotificationsIntegrationTest extends TestCase {
2221
private GithubAPIService $githubAPIService;
2322
private SecretService $secretService;
24-
private IConfig $config;
2523

2624
protected function setUp(): void {
2725
parent::setUp();
2826

2927
$this->githubAPIService = Server::get(GithubAPIService::class);
3028
$this->secretService = Server::get(SecretService::class);
31-
$this->config = Server::get(IConfig::class);
3229
}
3330

3431
#[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')]

tests/integration/GitHubSearchIntegrationTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
use OCA\Github\Service\GithubAPIService;
1313
use OCA\Github\Service\SecretService;
14-
use OCP\IConfig;
1514
use OCP\Server;
1615
use PHPUnit\Framework\Attributes\DependsExternal;
1716
use PHPUnit\Framework\Attributes\Group;
@@ -21,14 +20,12 @@
2120
class GitHubSearchIntegrationTest extends TestCase {
2221
private GithubAPIService $githubAPIService;
2322
private SecretService $secretService;
24-
private IConfig $config;
2523

2624
protected function setUp(): void {
2725
parent::setUp();
2826

2927
$this->githubAPIService = Server::get(GithubAPIService::class);
3028
$this->secretService = Server::get(SecretService::class);
31-
$this->config = Server::get(IConfig::class);
3229
}
3330

3431
#[DependsExternal(GithubOauthIntegrationTest::class, 'testOAuthLogin')]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)