-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathManagerUpdateAccessTokenTest.php
More file actions
114 lines (93 loc) · 3.68 KB
/
Copy pathManagerUpdateAccessTokenTest.php
File metadata and controls
114 lines (93 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files_Sharing\Tests\External;
use OCA\Files_Sharing\External\ExternalShare;
use OCA\Files_Sharing\External\ExternalShareMapper;
use OCA\Files_Sharing\External\Manager;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\DB\Exception;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\ICloudFederationFactory;
use OCP\Federation\ICloudFederationProviderManager;
use OCP\Files\IRootFolder;
use OCP\Files\ISetupManager;
use OCP\Files\Storage\IStorageFactory;
use OCP\Http\Client\IClientService;
use OCP\ICertificateManager;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IUserSession;
use OCP\Notification\IManager as INotificationManager;
use OCP\OCS\IDiscoveryService;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
class ManagerUpdateAccessTokenTest extends TestCase {
private ExternalShareMapper&MockObject $externalShareMapper;
private LoggerInterface&MockObject $logger;
private Manager $manager;
protected function setUp(): void {
parent::setUp();
$this->externalShareMapper = $this->createMock(ExternalShareMapper::class);
$this->logger = $this->createMock(LoggerInterface::class);
$userSession = $this->createMock(IUserSession::class);
$userSession->method('getUser')->willReturn(null);
$this->manager = new Manager(
$this->createMock(IDBConnection::class),
$this->createMock(\OC\Files\Mount\Manager::class),
$this->createMock(IStorageFactory::class),
$this->createMock(IClientService::class),
$this->createMock(INotificationManager::class),
$this->createMock(IDiscoveryService::class),
$this->createMock(ICloudFederationProviderManager::class),
$this->createMock(ICloudFederationFactory::class),
$this->createMock(IGroupManager::class),
$userSession,
$this->createMock(IEventDispatcher::class),
$this->logger,
$this->createMock(IRootFolder::class),
$this->createMock(ISetupManager::class),
$this->createMock(ICertificateManager::class),
$this->externalShareMapper,
$this->createMock(IConfig::class),
);
}
public function testUpdateAccessTokenUpdatesShareInDb(): void {
$share = new ExternalShare();
$share->setRefreshToken('refresh-token');
$this->externalShareMapper->expects($this->once())
->method('getShareByToken')
->with('refresh-token')
->willReturn($share);
$this->externalShareMapper->expects($this->once())
->method('update')
->with($this->callback(function (ExternalShare $s) {
return $s->getAccessToken() === 'new-access-token'
&& $s->getAccessTokenExpires() === 9999;
}));
$this->manager->updateAccessToken('refresh-token', 'new-access-token', 9999);
}
public function testUpdateAccessTokenLogsWarningWhenShareNotFound(): void {
$this->externalShareMapper->method('getShareByToken')
->willThrowException(new DoesNotExistException('not found'));
$this->externalShareMapper->expects($this->never())->method('update');
$this->logger->expects($this->once())
->method('warning')
->with($this->stringContains('Could not find share'));
$this->manager->updateAccessToken('missing-token', 'access', 0);
}
public function testUpdateAccessTokenLogsErrorOnDbException(): void {
$this->externalShareMapper->method('getShareByToken')
->willThrowException(new Exception('db error'));
$this->externalShareMapper->expects($this->never())->method('update');
$this->logger->expects($this->once())
->method('error')
->with($this->stringContains('Failed to update access token'));
$this->manager->updateAccessToken('some-token', 'access', 0);
}
}