@@ -46,153 +46,153 @@ discard block |
||
46 | 46 | abstract class AbstractCalDavBackend extends TestCase { |
47 | 47 | |
48 | 48 | |
49 | - protected CalDavBackend $backend; |
|
50 | - protected Principal&MockObject $principal; |
|
51 | - protected IUserManager&MockObject $userManager; |
|
52 | - protected IGroupManager&MockObject $groupManager; |
|
53 | - protected IEventDispatcher&MockObject $dispatcher; |
|
54 | - private LoggerInterface&MockObject $logger; |
|
55 | - private IConfig&MockObject $config; |
|
56 | - private ISecureRandom $random; |
|
57 | - protected SharingBackend $sharingBackend; |
|
58 | - protected IDBConnection $db; |
|
59 | - protected RemoteUserPrincipalBackend&MockObject $remoteUserPrincipalBackend; |
|
60 | - protected FederationSharingService&MockObject $federationSharingService; |
|
61 | - protected FederatedCalendarMapper&MockObject $federatedCalendarMapper; |
|
62 | - public const UNIT_TEST_USER = 'principals/users/caldav-unit-test'; |
|
63 | - public const UNIT_TEST_USER1 = 'principals/users/caldav-unit-test1'; |
|
64 | - public const UNIT_TEST_GROUP = 'principals/groups/caldav-unit-test-group'; |
|
65 | - public const UNIT_TEST_GROUP2 = 'principals/groups/caldav-unit-test-group2'; |
|
49 | + protected CalDavBackend $backend; |
|
50 | + protected Principal&MockObject $principal; |
|
51 | + protected IUserManager&MockObject $userManager; |
|
52 | + protected IGroupManager&MockObject $groupManager; |
|
53 | + protected IEventDispatcher&MockObject $dispatcher; |
|
54 | + private LoggerInterface&MockObject $logger; |
|
55 | + private IConfig&MockObject $config; |
|
56 | + private ISecureRandom $random; |
|
57 | + protected SharingBackend $sharingBackend; |
|
58 | + protected IDBConnection $db; |
|
59 | + protected RemoteUserPrincipalBackend&MockObject $remoteUserPrincipalBackend; |
|
60 | + protected FederationSharingService&MockObject $federationSharingService; |
|
61 | + protected FederatedCalendarMapper&MockObject $federatedCalendarMapper; |
|
62 | + public const UNIT_TEST_USER = 'principals/users/caldav-unit-test'; |
|
63 | + public const UNIT_TEST_USER1 = 'principals/users/caldav-unit-test1'; |
|
64 | + public const UNIT_TEST_GROUP = 'principals/groups/caldav-unit-test-group'; |
|
65 | + public const UNIT_TEST_GROUP2 = 'principals/groups/caldav-unit-test-group2'; |
|
66 | 66 | |
67 | - protected function setUp(): void { |
|
68 | - parent::setUp(); |
|
67 | + protected function setUp(): void { |
|
68 | + parent::setUp(); |
|
69 | 69 | |
70 | - $this->userManager = $this->createMock(IUserManager::class); |
|
71 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
72 | - $this->dispatcher = $this->createMock(IEventDispatcher::class); |
|
73 | - $this->principal = $this->getMockBuilder(Principal::class) |
|
74 | - ->setConstructorArgs([ |
|
75 | - $this->userManager, |
|
76 | - $this->groupManager, |
|
77 | - $this->createMock(IAccountManager::class), |
|
78 | - $this->createMock(ShareManager::class), |
|
79 | - $this->createMock(IUserSession::class), |
|
80 | - $this->createMock(IAppManager::class), |
|
81 | - $this->createMock(ProxyMapper::class), |
|
82 | - $this->createMock(KnownUserService::class), |
|
83 | - $this->createMock(IConfig::class), |
|
84 | - $this->createMock(IFactory::class) |
|
85 | - ]) |
|
86 | - ->onlyMethods(['getPrincipalByPath', 'getGroupMembership', 'findByUri']) |
|
87 | - ->getMock(); |
|
88 | - $this->principal->expects($this->any())->method('getPrincipalByPath') |
|
89 | - ->willReturn([ |
|
90 | - 'uri' => 'principals/best-friend', |
|
91 | - '{DAV:}displayname' => 'User\'s displayname', |
|
92 | - ]); |
|
93 | - $this->principal->expects($this->any())->method('getGroupMembership') |
|
94 | - ->withAnyParameters() |
|
95 | - ->willReturn([self::UNIT_TEST_GROUP, self::UNIT_TEST_GROUP2]); |
|
70 | + $this->userManager = $this->createMock(IUserManager::class); |
|
71 | + $this->groupManager = $this->createMock(IGroupManager::class); |
|
72 | + $this->dispatcher = $this->createMock(IEventDispatcher::class); |
|
73 | + $this->principal = $this->getMockBuilder(Principal::class) |
|
74 | + ->setConstructorArgs([ |
|
75 | + $this->userManager, |
|
76 | + $this->groupManager, |
|
77 | + $this->createMock(IAccountManager::class), |
|
78 | + $this->createMock(ShareManager::class), |
|
79 | + $this->createMock(IUserSession::class), |
|
80 | + $this->createMock(IAppManager::class), |
|
81 | + $this->createMock(ProxyMapper::class), |
|
82 | + $this->createMock(KnownUserService::class), |
|
83 | + $this->createMock(IConfig::class), |
|
84 | + $this->createMock(IFactory::class) |
|
85 | + ]) |
|
86 | + ->onlyMethods(['getPrincipalByPath', 'getGroupMembership', 'findByUri']) |
|
87 | + ->getMock(); |
|
88 | + $this->principal->expects($this->any())->method('getPrincipalByPath') |
|
89 | + ->willReturn([ |
|
90 | + 'uri' => 'principals/best-friend', |
|
91 | + '{DAV:}displayname' => 'User\'s displayname', |
|
92 | + ]); |
|
93 | + $this->principal->expects($this->any())->method('getGroupMembership') |
|
94 | + ->withAnyParameters() |
|
95 | + ->willReturn([self::UNIT_TEST_GROUP, self::UNIT_TEST_GROUP2]); |
|
96 | 96 | |
97 | - $this->db = Server::get(IDBConnection::class); |
|
98 | - $this->random = Server::get(ISecureRandom::class); |
|
99 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
100 | - $this->config = $this->createMock(IConfig::class); |
|
101 | - $this->remoteUserPrincipalBackend = $this->createMock(RemoteUserPrincipalBackend::class); |
|
102 | - $this->federationSharingService = $this->createMock(FederationSharingService::class); |
|
103 | - $this->federatedCalendarMapper = $this->createMock(FederatedCalendarMapper::class); |
|
104 | - $this->sharingBackend = new SharingBackend( |
|
105 | - $this->userManager, |
|
106 | - $this->groupManager, |
|
107 | - $this->principal, |
|
108 | - $this->remoteUserPrincipalBackend, |
|
109 | - $this->createMock(ICacheFactory::class), |
|
110 | - new Service(new SharingMapper($this->db)), |
|
111 | - $this->federationSharingService, |
|
112 | - $this->logger); |
|
113 | - $this->backend = new CalDavBackend( |
|
114 | - $this->db, |
|
115 | - $this->principal, |
|
116 | - $this->userManager, |
|
117 | - $this->random, |
|
118 | - $this->logger, |
|
119 | - $this->dispatcher, |
|
120 | - $this->config, |
|
121 | - $this->sharingBackend, |
|
122 | - $this->federatedCalendarMapper, |
|
123 | - false, |
|
124 | - ); |
|
97 | + $this->db = Server::get(IDBConnection::class); |
|
98 | + $this->random = Server::get(ISecureRandom::class); |
|
99 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
100 | + $this->config = $this->createMock(IConfig::class); |
|
101 | + $this->remoteUserPrincipalBackend = $this->createMock(RemoteUserPrincipalBackend::class); |
|
102 | + $this->federationSharingService = $this->createMock(FederationSharingService::class); |
|
103 | + $this->federatedCalendarMapper = $this->createMock(FederatedCalendarMapper::class); |
|
104 | + $this->sharingBackend = new SharingBackend( |
|
105 | + $this->userManager, |
|
106 | + $this->groupManager, |
|
107 | + $this->principal, |
|
108 | + $this->remoteUserPrincipalBackend, |
|
109 | + $this->createMock(ICacheFactory::class), |
|
110 | + new Service(new SharingMapper($this->db)), |
|
111 | + $this->federationSharingService, |
|
112 | + $this->logger); |
|
113 | + $this->backend = new CalDavBackend( |
|
114 | + $this->db, |
|
115 | + $this->principal, |
|
116 | + $this->userManager, |
|
117 | + $this->random, |
|
118 | + $this->logger, |
|
119 | + $this->dispatcher, |
|
120 | + $this->config, |
|
121 | + $this->sharingBackend, |
|
122 | + $this->federatedCalendarMapper, |
|
123 | + false, |
|
124 | + ); |
|
125 | 125 | |
126 | - $this->cleanUpBackend(); |
|
127 | - } |
|
126 | + $this->cleanUpBackend(); |
|
127 | + } |
|
128 | 128 | |
129 | - protected function tearDown(): void { |
|
130 | - $this->cleanUpBackend(); |
|
131 | - parent::tearDown(); |
|
132 | - } |
|
129 | + protected function tearDown(): void { |
|
130 | + $this->cleanUpBackend(); |
|
131 | + parent::tearDown(); |
|
132 | + } |
|
133 | 133 | |
134 | - public function cleanUpBackend(): void { |
|
135 | - if (is_null($this->backend)) { |
|
136 | - return; |
|
137 | - } |
|
138 | - $this->principal->expects($this->any())->method('getGroupMembership') |
|
139 | - ->withAnyParameters() |
|
140 | - ->willReturn([self::UNIT_TEST_GROUP, self::UNIT_TEST_GROUP2]); |
|
141 | - $this->cleanupForPrincipal(self::UNIT_TEST_USER); |
|
142 | - $this->cleanupForPrincipal(self::UNIT_TEST_USER1); |
|
143 | - } |
|
134 | + public function cleanUpBackend(): void { |
|
135 | + if (is_null($this->backend)) { |
|
136 | + return; |
|
137 | + } |
|
138 | + $this->principal->expects($this->any())->method('getGroupMembership') |
|
139 | + ->withAnyParameters() |
|
140 | + ->willReturn([self::UNIT_TEST_GROUP, self::UNIT_TEST_GROUP2]); |
|
141 | + $this->cleanupForPrincipal(self::UNIT_TEST_USER); |
|
142 | + $this->cleanupForPrincipal(self::UNIT_TEST_USER1); |
|
143 | + } |
|
144 | 144 | |
145 | - private function cleanupForPrincipal($principal): void { |
|
146 | - $calendars = $this->backend->getCalendarsForUser($principal); |
|
147 | - $this->dispatcher->expects(self::any()) |
|
148 | - ->method('dispatchTyped'); |
|
149 | - foreach ($calendars as $calendar) { |
|
150 | - $this->backend->deleteCalendar($calendar['id'], true); |
|
151 | - } |
|
152 | - $subscriptions = $this->backend->getSubscriptionsForUser($principal); |
|
153 | - foreach ($subscriptions as $subscription) { |
|
154 | - $this->backend->deleteSubscription($subscription['id']); |
|
155 | - } |
|
156 | - } |
|
145 | + private function cleanupForPrincipal($principal): void { |
|
146 | + $calendars = $this->backend->getCalendarsForUser($principal); |
|
147 | + $this->dispatcher->expects(self::any()) |
|
148 | + ->method('dispatchTyped'); |
|
149 | + foreach ($calendars as $calendar) { |
|
150 | + $this->backend->deleteCalendar($calendar['id'], true); |
|
151 | + } |
|
152 | + $subscriptions = $this->backend->getSubscriptionsForUser($principal); |
|
153 | + foreach ($subscriptions as $subscription) { |
|
154 | + $this->backend->deleteSubscription($subscription['id']); |
|
155 | + } |
|
156 | + } |
|
157 | 157 | |
158 | - protected function createTestCalendar(): int { |
|
159 | - $this->dispatcher->expects(self::any()) |
|
160 | - ->method('dispatchTyped'); |
|
158 | + protected function createTestCalendar(): int { |
|
159 | + $this->dispatcher->expects(self::any()) |
|
160 | + ->method('dispatchTyped'); |
|
161 | 161 | |
162 | - $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', [ |
|
163 | - '{http://apple.com/ns/ical/}calendar-color' => '#1C4587FF' |
|
164 | - ]); |
|
165 | - $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); |
|
166 | - $this->assertEquals(1, count($calendars)); |
|
167 | - $this->assertEquals(self::UNIT_TEST_USER, $calendars[0]['principaluri']); |
|
168 | - /** @var SupportedCalendarComponentSet $components */ |
|
169 | - $components = $calendars[0]['{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set']; |
|
170 | - $this->assertEquals(['VEVENT','VTODO','VJOURNAL'], $components->getValue()); |
|
171 | - $color = $calendars[0]['{http://apple.com/ns/ical/}calendar-color']; |
|
172 | - $this->assertEquals('#1C4587FF', $color); |
|
173 | - $this->assertEquals('Example', $calendars[0]['uri']); |
|
174 | - $this->assertEquals('Example', $calendars[0]['{DAV:}displayname']); |
|
175 | - return (int)$calendars[0]['id']; |
|
176 | - } |
|
162 | + $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', [ |
|
163 | + '{http://apple.com/ns/ical/}calendar-color' => '#1C4587FF' |
|
164 | + ]); |
|
165 | + $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); |
|
166 | + $this->assertEquals(1, count($calendars)); |
|
167 | + $this->assertEquals(self::UNIT_TEST_USER, $calendars[0]['principaluri']); |
|
168 | + /** @var SupportedCalendarComponentSet $components */ |
|
169 | + $components = $calendars[0]['{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set']; |
|
170 | + $this->assertEquals(['VEVENT','VTODO','VJOURNAL'], $components->getValue()); |
|
171 | + $color = $calendars[0]['{http://apple.com/ns/ical/}calendar-color']; |
|
172 | + $this->assertEquals('#1C4587FF', $color); |
|
173 | + $this->assertEquals('Example', $calendars[0]['uri']); |
|
174 | + $this->assertEquals('Example', $calendars[0]['{DAV:}displayname']); |
|
175 | + return (int)$calendars[0]['id']; |
|
176 | + } |
|
177 | 177 | |
178 | - protected function createTestSubscription() { |
|
179 | - $this->backend->createSubscription(self::UNIT_TEST_USER, 'Example', [ |
|
180 | - '{http://apple.com/ns/ical/}calendar-color' => '#1C4587FF', |
|
181 | - '{http://calendarserver.org/ns/}source' => new Href(['foo']), |
|
182 | - ]); |
|
183 | - $calendars = $this->backend->getSubscriptionsForUser(self::UNIT_TEST_USER); |
|
184 | - $this->assertEquals(1, count($calendars)); |
|
185 | - $this->assertEquals(self::UNIT_TEST_USER, $calendars[0]['principaluri']); |
|
186 | - $this->assertEquals('Example', $calendars[0]['uri']); |
|
187 | - $calendarId = $calendars[0]['id']; |
|
178 | + protected function createTestSubscription() { |
|
179 | + $this->backend->createSubscription(self::UNIT_TEST_USER, 'Example', [ |
|
180 | + '{http://apple.com/ns/ical/}calendar-color' => '#1C4587FF', |
|
181 | + '{http://calendarserver.org/ns/}source' => new Href(['foo']), |
|
182 | + ]); |
|
183 | + $calendars = $this->backend->getSubscriptionsForUser(self::UNIT_TEST_USER); |
|
184 | + $this->assertEquals(1, count($calendars)); |
|
185 | + $this->assertEquals(self::UNIT_TEST_USER, $calendars[0]['principaluri']); |
|
186 | + $this->assertEquals('Example', $calendars[0]['uri']); |
|
187 | + $calendarId = $calendars[0]['id']; |
|
188 | 188 | |
189 | - return $calendarId; |
|
190 | - } |
|
189 | + return $calendarId; |
|
190 | + } |
|
191 | 191 | |
192 | - protected function createEvent($calendarId, $start = '20130912T130000Z', $end = '20130912T140000Z') { |
|
193 | - $randomPart = self::getUniqueID(); |
|
192 | + protected function createEvent($calendarId, $start = '20130912T130000Z', $end = '20130912T140000Z') { |
|
193 | + $randomPart = self::getUniqueID(); |
|
194 | 194 | |
195 | - $calData = <<<EOD |
|
195 | + $calData = <<<EOD |
|
196 | 196 | BEGIN:VCALENDAR |
197 | 197 | VERSION:2.0 |
198 | 198 | PRODID:ownCloud Calendar |
@@ -208,20 +208,20 @@ discard block |
||
208 | 208 | END:VEVENT |
209 | 209 | END:VCALENDAR |
210 | 210 | EOD; |
211 | - $uri0 = $this->getUniqueID('event'); |
|
211 | + $uri0 = $this->getUniqueID('event'); |
|
212 | 212 | |
213 | - $this->dispatcher->expects(self::atLeastOnce()) |
|
214 | - ->method('dispatchTyped'); |
|
213 | + $this->dispatcher->expects(self::atLeastOnce()) |
|
214 | + ->method('dispatchTyped'); |
|
215 | 215 | |
216 | - $this->backend->createCalendarObject($calendarId, $uri0, $calData); |
|
216 | + $this->backend->createCalendarObject($calendarId, $uri0, $calData); |
|
217 | 217 | |
218 | - return $uri0; |
|
219 | - } |
|
218 | + return $uri0; |
|
219 | + } |
|
220 | 220 | |
221 | - protected function modifyEvent($calendarId, $objectId, $start = '20130912T130000Z', $end = '20130912T140000Z') { |
|
222 | - $randomPart = self::getUniqueID(); |
|
221 | + protected function modifyEvent($calendarId, $objectId, $start = '20130912T130000Z', $end = '20130912T140000Z') { |
|
222 | + $randomPart = self::getUniqueID(); |
|
223 | 223 | |
224 | - $calData = <<<EOD |
|
224 | + $calData = <<<EOD |
|
225 | 225 | BEGIN:VCALENDAR |
226 | 226 | VERSION:2.0 |
227 | 227 | PRODID:ownCloud Calendar |
@@ -238,38 +238,38 @@ discard block |
||
238 | 238 | END:VCALENDAR |
239 | 239 | EOD; |
240 | 240 | |
241 | - $this->backend->updateCalendarObject($calendarId, $objectId, $calData); |
|
242 | - } |
|
241 | + $this->backend->updateCalendarObject($calendarId, $objectId, $calData); |
|
242 | + } |
|
243 | 243 | |
244 | - protected function deleteEvent($calendarId, $objectId) { |
|
245 | - $this->backend->deleteCalendarObject($calendarId, $objectId); |
|
246 | - } |
|
244 | + protected function deleteEvent($calendarId, $objectId) { |
|
245 | + $this->backend->deleteCalendarObject($calendarId, $objectId); |
|
246 | + } |
|
247 | 247 | |
248 | - protected function assertAcl($principal, $privilege, $acl) { |
|
249 | - foreach ($acl as $a) { |
|
250 | - if ($a['principal'] === $principal && $a['privilege'] === $privilege) { |
|
251 | - $this->addToAssertionCount(1); |
|
252 | - return; |
|
253 | - } |
|
254 | - } |
|
255 | - $this->fail("ACL does not contain $principal / $privilege"); |
|
256 | - } |
|
248 | + protected function assertAcl($principal, $privilege, $acl) { |
|
249 | + foreach ($acl as $a) { |
|
250 | + if ($a['principal'] === $principal && $a['privilege'] === $privilege) { |
|
251 | + $this->addToAssertionCount(1); |
|
252 | + return; |
|
253 | + } |
|
254 | + } |
|
255 | + $this->fail("ACL does not contain $principal / $privilege"); |
|
256 | + } |
|
257 | 257 | |
258 | - protected function assertNotAcl($principal, $privilege, $acl) { |
|
259 | - foreach ($acl as $a) { |
|
260 | - if ($a['principal'] === $principal && $a['privilege'] === $privilege) { |
|
261 | - $this->fail("ACL contains $principal / $privilege"); |
|
262 | - return; |
|
263 | - } |
|
264 | - } |
|
265 | - $this->addToAssertionCount(1); |
|
266 | - } |
|
258 | + protected function assertNotAcl($principal, $privilege, $acl) { |
|
259 | + foreach ($acl as $a) { |
|
260 | + if ($a['principal'] === $principal && $a['privilege'] === $privilege) { |
|
261 | + $this->fail("ACL contains $principal / $privilege"); |
|
262 | + return; |
|
263 | + } |
|
264 | + } |
|
265 | + $this->addToAssertionCount(1); |
|
266 | + } |
|
267 | 267 | |
268 | - protected function assertAccess($shouldHaveAcl, $principal, $privilege, $acl) { |
|
269 | - if ($shouldHaveAcl) { |
|
270 | - $this->assertAcl($principal, $privilege, $acl); |
|
271 | - } else { |
|
272 | - $this->assertNotAcl($principal, $privilege, $acl); |
|
273 | - } |
|
274 | - } |
|
268 | + protected function assertAccess($shouldHaveAcl, $principal, $privilege, $acl) { |
|
269 | + if ($shouldHaveAcl) { |
|
270 | + $this->assertAcl($principal, $privilege, $acl); |
|
271 | + } else { |
|
272 | + $this->assertNotAcl($principal, $privilege, $acl); |
|
273 | + } |
|
274 | + } |
|
275 | 275 | } |
@@ -33,114 +33,114 @@ |
||
33 | 33 | * @package OCA\DAV\Tests\unit\CalDAV |
34 | 34 | */ |
35 | 35 | class PublicCalendarRootTest extends TestCase { |
36 | - public const UNIT_TEST_USER = ''; |
|
37 | - private CalDavBackend $backend; |
|
38 | - private PublicCalendarRoot $publicCalendarRoot; |
|
39 | - private IL10N&MockObject $l10n; |
|
40 | - private Principal&MockObject $principal; |
|
41 | - protected IUserManager&MockObject $userManager; |
|
42 | - protected IGroupManager&MockObject $groupManager; |
|
43 | - protected IConfig&MockObject $config; |
|
44 | - private ISecureRandom $random; |
|
45 | - private LoggerInterface&MockObject $logger; |
|
46 | - |
|
47 | - protected FederatedCalendarMapper&MockObject $federatedCalendarMapper; |
|
48 | - |
|
49 | - protected function setUp(): void { |
|
50 | - parent::setUp(); |
|
51 | - |
|
52 | - $db = Server::get(IDBConnection::class); |
|
53 | - $this->principal = $this->createMock('OCA\DAV\Connector\Sabre\Principal'); |
|
54 | - $this->userManager = $this->createMock(IUserManager::class); |
|
55 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
56 | - $this->random = Server::get(ISecureRandom::class); |
|
57 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
58 | - $this->federatedCalendarMapper = $this->createMock(FederatedCalendarMapper::class); |
|
59 | - $dispatcher = $this->createMock(IEventDispatcher::class); |
|
60 | - $config = $this->createMock(IConfig::class); |
|
61 | - $sharingBackend = $this->createMock(\OCA\DAV\CalDAV\Sharing\Backend::class); |
|
62 | - |
|
63 | - $this->principal->expects($this->any())->method('getGroupMembership') |
|
64 | - ->withAnyParameters() |
|
65 | - ->willReturn([]); |
|
66 | - |
|
67 | - $this->principal->expects($this->any())->method('getCircleMembership') |
|
68 | - ->withAnyParameters() |
|
69 | - ->willReturn([]); |
|
70 | - |
|
71 | - $this->backend = new CalDavBackend( |
|
72 | - $db, |
|
73 | - $this->principal, |
|
74 | - $this->userManager, |
|
75 | - $this->random, |
|
76 | - $this->logger, |
|
77 | - $dispatcher, |
|
78 | - $config, |
|
79 | - $sharingBackend, |
|
80 | - $this->federatedCalendarMapper, |
|
81 | - false, |
|
82 | - ); |
|
83 | - $this->l10n = $this->createMock(IL10N::class); |
|
84 | - $this->config = $this->createMock(IConfig::class); |
|
85 | - |
|
86 | - $this->publicCalendarRoot = new PublicCalendarRoot($this->backend, |
|
87 | - $this->l10n, $this->config, $this->logger); |
|
88 | - } |
|
89 | - |
|
90 | - protected function tearDown(): void { |
|
91 | - parent::tearDown(); |
|
92 | - |
|
93 | - if (is_null($this->backend)) { |
|
94 | - return; |
|
95 | - } |
|
96 | - $this->principal->expects($this->any())->method('getGroupMembership') |
|
97 | - ->withAnyParameters() |
|
98 | - ->willReturn([]); |
|
99 | - |
|
100 | - $this->principal->expects($this->any())->method('getCircleMembership') |
|
101 | - ->withAnyParameters() |
|
102 | - ->willReturn([]); |
|
103 | - |
|
104 | - $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); |
|
105 | - foreach ($books as $book) { |
|
106 | - $this->backend->deleteCalendar($book['id'], true); |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - public function testGetName(): void { |
|
111 | - $name = $this->publicCalendarRoot->getName(); |
|
112 | - $this->assertEquals('public-calendars', $name); |
|
113 | - } |
|
114 | - |
|
115 | - public function testGetChild(): void { |
|
116 | - $calendar = $this->createPublicCalendar(); |
|
117 | - |
|
118 | - $publicCalendars = $this->backend->getPublicCalendars(); |
|
119 | - $this->assertEquals(1, count($publicCalendars)); |
|
120 | - $this->assertEquals(true, $publicCalendars[0]['{http://owncloud.org/ns}public']); |
|
121 | - |
|
122 | - $publicCalendarURI = $publicCalendars[0]['uri']; |
|
123 | - |
|
124 | - $calendarResult = $this->publicCalendarRoot->getChild($publicCalendarURI); |
|
125 | - $this->assertEquals($calendar, $calendarResult); |
|
126 | - } |
|
127 | - |
|
128 | - public function testGetChildren(): void { |
|
129 | - $this->createPublicCalendar(); |
|
130 | - $calendarResults = $this->publicCalendarRoot->getChildren(); |
|
131 | - $this->assertSame([], $calendarResults); |
|
132 | - } |
|
133 | - |
|
134 | - protected function createPublicCalendar(): Calendar { |
|
135 | - $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []); |
|
136 | - |
|
137 | - $calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0]; |
|
138 | - $calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
139 | - $publicUri = $calendar->setPublishStatus(true); |
|
140 | - |
|
141 | - $calendarInfo = $this->backend->getPublicCalendar($publicUri); |
|
142 | - $calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
143 | - |
|
144 | - return $calendar; |
|
145 | - } |
|
36 | + public const UNIT_TEST_USER = ''; |
|
37 | + private CalDavBackend $backend; |
|
38 | + private PublicCalendarRoot $publicCalendarRoot; |
|
39 | + private IL10N&MockObject $l10n; |
|
40 | + private Principal&MockObject $principal; |
|
41 | + protected IUserManager&MockObject $userManager; |
|
42 | + protected IGroupManager&MockObject $groupManager; |
|
43 | + protected IConfig&MockObject $config; |
|
44 | + private ISecureRandom $random; |
|
45 | + private LoggerInterface&MockObject $logger; |
|
46 | + |
|
47 | + protected FederatedCalendarMapper&MockObject $federatedCalendarMapper; |
|
48 | + |
|
49 | + protected function setUp(): void { |
|
50 | + parent::setUp(); |
|
51 | + |
|
52 | + $db = Server::get(IDBConnection::class); |
|
53 | + $this->principal = $this->createMock('OCA\DAV\Connector\Sabre\Principal'); |
|
54 | + $this->userManager = $this->createMock(IUserManager::class); |
|
55 | + $this->groupManager = $this->createMock(IGroupManager::class); |
|
56 | + $this->random = Server::get(ISecureRandom::class); |
|
57 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
58 | + $this->federatedCalendarMapper = $this->createMock(FederatedCalendarMapper::class); |
|
59 | + $dispatcher = $this->createMock(IEventDispatcher::class); |
|
60 | + $config = $this->createMock(IConfig::class); |
|
61 | + $sharingBackend = $this->createMock(\OCA\DAV\CalDAV\Sharing\Backend::class); |
|
62 | + |
|
63 | + $this->principal->expects($this->any())->method('getGroupMembership') |
|
64 | + ->withAnyParameters() |
|
65 | + ->willReturn([]); |
|
66 | + |
|
67 | + $this->principal->expects($this->any())->method('getCircleMembership') |
|
68 | + ->withAnyParameters() |
|
69 | + ->willReturn([]); |
|
70 | + |
|
71 | + $this->backend = new CalDavBackend( |
|
72 | + $db, |
|
73 | + $this->principal, |
|
74 | + $this->userManager, |
|
75 | + $this->random, |
|
76 | + $this->logger, |
|
77 | + $dispatcher, |
|
78 | + $config, |
|
79 | + $sharingBackend, |
|
80 | + $this->federatedCalendarMapper, |
|
81 | + false, |
|
82 | + ); |
|
83 | + $this->l10n = $this->createMock(IL10N::class); |
|
84 | + $this->config = $this->createMock(IConfig::class); |
|
85 | + |
|
86 | + $this->publicCalendarRoot = new PublicCalendarRoot($this->backend, |
|
87 | + $this->l10n, $this->config, $this->logger); |
|
88 | + } |
|
89 | + |
|
90 | + protected function tearDown(): void { |
|
91 | + parent::tearDown(); |
|
92 | + |
|
93 | + if (is_null($this->backend)) { |
|
94 | + return; |
|
95 | + } |
|
96 | + $this->principal->expects($this->any())->method('getGroupMembership') |
|
97 | + ->withAnyParameters() |
|
98 | + ->willReturn([]); |
|
99 | + |
|
100 | + $this->principal->expects($this->any())->method('getCircleMembership') |
|
101 | + ->withAnyParameters() |
|
102 | + ->willReturn([]); |
|
103 | + |
|
104 | + $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); |
|
105 | + foreach ($books as $book) { |
|
106 | + $this->backend->deleteCalendar($book['id'], true); |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + public function testGetName(): void { |
|
111 | + $name = $this->publicCalendarRoot->getName(); |
|
112 | + $this->assertEquals('public-calendars', $name); |
|
113 | + } |
|
114 | + |
|
115 | + public function testGetChild(): void { |
|
116 | + $calendar = $this->createPublicCalendar(); |
|
117 | + |
|
118 | + $publicCalendars = $this->backend->getPublicCalendars(); |
|
119 | + $this->assertEquals(1, count($publicCalendars)); |
|
120 | + $this->assertEquals(true, $publicCalendars[0]['{http://owncloud.org/ns}public']); |
|
121 | + |
|
122 | + $publicCalendarURI = $publicCalendars[0]['uri']; |
|
123 | + |
|
124 | + $calendarResult = $this->publicCalendarRoot->getChild($publicCalendarURI); |
|
125 | + $this->assertEquals($calendar, $calendarResult); |
|
126 | + } |
|
127 | + |
|
128 | + public function testGetChildren(): void { |
|
129 | + $this->createPublicCalendar(); |
|
130 | + $calendarResults = $this->publicCalendarRoot->getChildren(); |
|
131 | + $this->assertSame([], $calendarResults); |
|
132 | + } |
|
133 | + |
|
134 | + protected function createPublicCalendar(): Calendar { |
|
135 | + $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []); |
|
136 | + |
|
137 | + $calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0]; |
|
138 | + $calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
139 | + $publicUri = $calendar->setPublishStatus(true); |
|
140 | + |
|
141 | + $calendarInfo = $this->backend->getPublicCalendar($publicUri); |
|
142 | + $calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
143 | + |
|
144 | + return $calendar; |
|
145 | + } |
|
146 | 146 | } |
@@ -16,34 +16,34 @@ |
||
16 | 16 | use Test\TestCase; |
17 | 17 | |
18 | 18 | class CalendarFederationConfigTest extends TestCase { |
19 | - private CalendarFederationConfig $config; |
|
19 | + private CalendarFederationConfig $config; |
|
20 | 20 | |
21 | - private IAppConfig&MockObject $appConfig; |
|
21 | + private IAppConfig&MockObject $appConfig; |
|
22 | 22 | |
23 | - protected function setUp(): void { |
|
24 | - parent::setUp(); |
|
23 | + protected function setUp(): void { |
|
24 | + parent::setUp(); |
|
25 | 25 | |
26 | - $this->appConfig = $this->createMock(IAppConfig::class); |
|
26 | + $this->appConfig = $this->createMock(IAppConfig::class); |
|
27 | 27 | |
28 | - $this->config = new CalendarFederationConfig( |
|
29 | - $this->appConfig, |
|
30 | - ); |
|
31 | - } |
|
28 | + $this->config = new CalendarFederationConfig( |
|
29 | + $this->appConfig, |
|
30 | + ); |
|
31 | + } |
|
32 | 32 | |
33 | - public static function provideIsFederationEnabledData(): array { |
|
34 | - return [ |
|
35 | - [true], |
|
36 | - [false], |
|
37 | - ]; |
|
38 | - } |
|
33 | + public static function provideIsFederationEnabledData(): array { |
|
34 | + return [ |
|
35 | + [true], |
|
36 | + [false], |
|
37 | + ]; |
|
38 | + } |
|
39 | 39 | |
40 | - #[DataProvider('provideIsFederationEnabledData')] |
|
41 | - public function testIsFederationEnabled(bool $configValue): void { |
|
42 | - $this->appConfig->expects(self::once()) |
|
43 | - ->method('getAppValueBool') |
|
44 | - ->with('enableCalendarFederation', true) |
|
45 | - ->willReturn($configValue); |
|
40 | + #[DataProvider('provideIsFederationEnabledData')] |
|
41 | + public function testIsFederationEnabled(bool $configValue): void { |
|
42 | + $this->appConfig->expects(self::once()) |
|
43 | + ->method('getAppValueBool') |
|
44 | + ->with('enableCalendarFederation', true) |
|
45 | + ->willReturn($configValue); |
|
46 | 46 | |
47 | - $this->assertEquals($configValue, $this->config->isFederationEnabled()); |
|
48 | - } |
|
47 | + $this->assertEquals($configValue, $this->config->isFederationEnabled()); |
|
48 | + } |
|
49 | 49 | } |
@@ -28,457 +28,457 @@ |
||
28 | 28 | use Test\TestCase; |
29 | 29 | |
30 | 30 | class CalendarFederationProviderTest extends TestCase { |
31 | - private CalendarFederationProvider $calendarFederationProvider; |
|
32 | - |
|
33 | - private LoggerInterface&MockObject $logger; |
|
34 | - private FederatedCalendarMapper&MockObject $federatedCalendarMapper; |
|
35 | - private CalendarFederationConfig&MockObject $calendarFederationConfig; |
|
36 | - private IJobList&MockObject $jobList; |
|
37 | - private ICloudIdManager&MockObject $cloudIdManager; |
|
38 | - |
|
39 | - protected function setUp(): void { |
|
40 | - parent::setUp(); |
|
41 | - |
|
42 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
43 | - $this->federatedCalendarMapper = $this->createMock(FederatedCalendarMapper::class); |
|
44 | - $this->calendarFederationConfig = $this->createMock(CalendarFederationConfig::class); |
|
45 | - $this->jobList = $this->createMock(JobList::class); |
|
46 | - $this->cloudIdManager = $this->createMock(ICloudIdManager::class); |
|
47 | - |
|
48 | - $this->calendarFederationProvider = new CalendarFederationProvider( |
|
49 | - $this->logger, |
|
50 | - $this->federatedCalendarMapper, |
|
51 | - $this->calendarFederationConfig, |
|
52 | - $this->jobList, |
|
53 | - $this->cloudIdManager, |
|
54 | - ); |
|
55 | - } |
|
56 | - |
|
57 | - public function testGetShareType(): void { |
|
58 | - $this->assertEquals('calendar', $this->calendarFederationProvider->getShareType()); |
|
59 | - } |
|
60 | - |
|
61 | - public function testGetSupportedShareTypes(): void { |
|
62 | - $this->assertEqualsCanonicalizing( |
|
63 | - ['user'], |
|
64 | - $this->calendarFederationProvider->getSupportedShareTypes(), |
|
65 | - ); |
|
66 | - } |
|
67 | - |
|
68 | - public function testShareReceived(): void { |
|
69 | - $share = $this->createMock(ICloudFederationShare::class); |
|
70 | - $share->method('getShareType') |
|
71 | - ->willReturn('user'); |
|
72 | - $share->method('getProtocol') |
|
73 | - ->willReturn([ |
|
74 | - 'version' => 'v1', |
|
75 | - 'url' => 'https://nextcloud.remote/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user1', |
|
76 | - 'displayName' => 'Calendar 1', |
|
77 | - 'color' => '#ff0000', |
|
78 | - 'access' => 3, |
|
79 | - 'components' => 'VEVENT,VTODO', |
|
80 | - ]); |
|
81 | - $share->method('getShareWith') |
|
82 | - ->willReturn('sharee1'); |
|
83 | - $share->method('getShareSecret') |
|
84 | - ->willReturn('token'); |
|
85 | - $share->method('getSharedBy') |
|
86 | - ->willReturn('[email protected]'); |
|
87 | - $share->method('getSharedByDisplayName') |
|
88 | - ->willReturn('User 1'); |
|
89 | - |
|
90 | - $this->calendarFederationConfig->expects(self::once()) |
|
91 | - ->method('isFederationEnabled') |
|
92 | - ->willReturn(true); |
|
93 | - |
|
94 | - $this->federatedCalendarMapper->expects(self::once()) |
|
95 | - ->method('deleteByUri') |
|
96 | - ->with( |
|
97 | - 'principals/users/sharee1', |
|
98 | - 'ae4b8ab904076fff2b955ea21b1a0d92', |
|
99 | - ); |
|
100 | - |
|
101 | - $this->federatedCalendarMapper->expects(self::once()) |
|
102 | - ->method('insert') |
|
103 | - ->willReturnCallback(function (FederatedCalendarEntity $calendar) { |
|
104 | - $this->assertEquals('principals/users/sharee1', $calendar->getPrincipaluri()); |
|
105 | - $this->assertEquals('ae4b8ab904076fff2b955ea21b1a0d92', $calendar->getUri()); |
|
106 | - $this->assertEquals('https://nextcloud.remote/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user1', $calendar->getRemoteUrl()); |
|
107 | - $this->assertEquals('Calendar 1', $calendar->getDisplayName()); |
|
108 | - $this->assertEquals('#ff0000', $calendar->getColor()); |
|
109 | - $this->assertEquals('token', $calendar->getToken()); |
|
110 | - $this->assertEquals('[email protected]', $calendar->getSharedBy()); |
|
111 | - $this->assertEquals('User 1', $calendar->getSharedByDisplayName()); |
|
112 | - $this->assertEquals(1, $calendar->getPermissions()); |
|
113 | - $this->assertEquals('VEVENT,VTODO', $calendar->getComponents()); |
|
114 | - |
|
115 | - $calendar->setId(10); |
|
116 | - return $calendar; |
|
117 | - }); |
|
118 | - |
|
119 | - $this->jobList->expects(self::once()) |
|
120 | - ->method('add') |
|
121 | - ->with(FederatedCalendarSyncJob::class, ['id' => 10]); |
|
122 | - |
|
123 | - $this->assertEquals(10, $this->calendarFederationProvider->shareReceived($share)); |
|
124 | - } |
|
125 | - |
|
126 | - public function testShareReceivedWithInvalidProtocolVersion(): void { |
|
127 | - $share = $this->createMock(ICloudFederationShare::class); |
|
128 | - $share->method('getShareType') |
|
129 | - ->willReturn('user'); |
|
130 | - $share->method('getProtocol') |
|
131 | - ->willReturn([ |
|
132 | - 'version' => 'unknown', |
|
133 | - 'url' => 'https://nextcloud.remote/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user1', |
|
134 | - 'displayName' => 'Calendar 1', |
|
135 | - 'color' => '#ff0000', |
|
136 | - 'access' => 3, |
|
137 | - 'components' => 'VEVENT,VTODO', |
|
138 | - ]); |
|
139 | - |
|
140 | - $this->calendarFederationConfig->expects(self::once()) |
|
141 | - ->method('isFederationEnabled') |
|
142 | - ->willReturn(true); |
|
143 | - |
|
144 | - $this->federatedCalendarMapper->expects(self::never()) |
|
145 | - ->method('insert'); |
|
146 | - $this->jobList->expects(self::never()) |
|
147 | - ->method('add'); |
|
148 | - |
|
149 | - $this->expectException(ProviderCouldNotAddShareException::class); |
|
150 | - $this->expectExceptionMessage('Unknown protocol version'); |
|
151 | - $this->expectExceptionCode(400); |
|
152 | - $this->assertEquals(10, $this->calendarFederationProvider->shareReceived($share)); |
|
153 | - } |
|
154 | - |
|
155 | - public function testShareReceivedWithoutProtocolVersion(): void { |
|
156 | - $share = $this->createMock(ICloudFederationShare::class); |
|
157 | - $share->method('getShareType') |
|
158 | - ->willReturn('user'); |
|
159 | - $share->method('getProtocol') |
|
160 | - ->willReturn([ |
|
161 | - 'url' => 'https://nextcloud.remote/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user1', |
|
162 | - 'displayName' => 'Calendar 1', |
|
163 | - 'color' => '#ff0000', |
|
164 | - 'access' => 3, |
|
165 | - 'components' => 'VEVENT,VTODO', |
|
166 | - ]); |
|
167 | - |
|
168 | - $this->calendarFederationConfig->expects(self::once()) |
|
169 | - ->method('isFederationEnabled') |
|
170 | - ->willReturn(true); |
|
171 | - |
|
172 | - $this->federatedCalendarMapper->expects(self::never()) |
|
173 | - ->method('insert'); |
|
174 | - $this->jobList->expects(self::never()) |
|
175 | - ->method('add'); |
|
176 | - |
|
177 | - $this->expectException(ProviderCouldNotAddShareException::class); |
|
178 | - $this->expectExceptionMessage('Unknown protocol version'); |
|
179 | - $this->expectExceptionCode(400); |
|
180 | - $this->assertEquals(10, $this->calendarFederationProvider->shareReceived($share)); |
|
181 | - } |
|
182 | - |
|
183 | - public function testShareReceivedWithDisabledConfig(): void { |
|
184 | - $share = $this->createMock(ICloudFederationShare::class); |
|
185 | - |
|
186 | - $this->calendarFederationConfig->expects(self::once()) |
|
187 | - ->method('isFederationEnabled') |
|
188 | - ->willReturn(false); |
|
189 | - |
|
190 | - $this->federatedCalendarMapper->expects(self::never()) |
|
191 | - ->method('insert'); |
|
192 | - $this->jobList->expects(self::never()) |
|
193 | - ->method('add'); |
|
194 | - |
|
195 | - $this->expectException(ProviderCouldNotAddShareException::class); |
|
196 | - $this->expectExceptionMessage('Server does not support calendar federation'); |
|
197 | - $this->expectExceptionCode(503); |
|
198 | - $this->calendarFederationProvider->shareReceived($share); |
|
199 | - } |
|
200 | - |
|
201 | - public function testShareReceivedWithUnsupportedShareType(): void { |
|
202 | - $share = $this->createMock(ICloudFederationShare::class); |
|
203 | - $share->method('getShareType') |
|
204 | - ->willReturn('foobar'); |
|
205 | - |
|
206 | - $this->calendarFederationConfig->expects(self::once()) |
|
207 | - ->method('isFederationEnabled') |
|
208 | - ->willReturn(true); |
|
209 | - |
|
210 | - $this->federatedCalendarMapper->expects(self::never()) |
|
211 | - ->method('insert'); |
|
212 | - $this->jobList->expects(self::never()) |
|
213 | - ->method('add'); |
|
214 | - |
|
215 | - $this->expectException(ProviderCouldNotAddShareException::class); |
|
216 | - $this->expectExceptionMessage('Support for sharing with non-users not implemented yet'); |
|
217 | - $this->expectExceptionCode(501); |
|
218 | - $this->calendarFederationProvider->shareReceived($share); |
|
219 | - } |
|
220 | - |
|
221 | - public static function provideIncompleteProtocolData(): array { |
|
222 | - return [ |
|
223 | - [[ |
|
224 | - 'version' => 'v1', |
|
225 | - 'url' => '', |
|
226 | - 'displayName' => 'Calendar 1', |
|
227 | - 'color' => '#ff0000', |
|
228 | - 'access' => 3, |
|
229 | - 'components' => 'VEVENT,VTODO', |
|
230 | - ]], |
|
231 | - [[ |
|
232 | - 'version' => 'v1', |
|
233 | - 'url' => 'https://nextcloud.remote/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user1', |
|
234 | - 'displayName' => '', |
|
235 | - 'color' => '#ff0000', |
|
236 | - 'access' => 3, |
|
237 | - 'components' => 'VEVENT,VTODO', |
|
238 | - ]], |
|
239 | - ]; |
|
240 | - } |
|
241 | - |
|
242 | - #[DataProvider('provideIncompleteProtocolData')] |
|
243 | - public function testShareReceivedWithIncompleteProtocolData(array $protocol): void { |
|
244 | - $share = $this->createMock(ICloudFederationShare::class); |
|
245 | - $share->method('getShareType') |
|
246 | - ->willReturn('user'); |
|
247 | - $share->method('getProtocol') |
|
248 | - ->willReturn($protocol); |
|
249 | - $share->method('getShareWith') |
|
250 | - ->willReturn('sharee1'); |
|
251 | - $share->method('getShareSecret') |
|
252 | - ->willReturn('token'); |
|
253 | - $share->method('getSharedBy') |
|
254 | - ->willReturn('[email protected]'); |
|
255 | - $share->method('getSharedByDisplayName') |
|
256 | - ->willReturn('User 1'); |
|
257 | - |
|
258 | - $this->calendarFederationConfig->expects(self::once()) |
|
259 | - ->method('isFederationEnabled') |
|
260 | - ->willReturn(true); |
|
261 | - |
|
262 | - $this->federatedCalendarMapper->expects(self::never()) |
|
263 | - ->method('insert'); |
|
264 | - $this->jobList->expects(self::never()) |
|
265 | - ->method('add'); |
|
266 | - |
|
267 | - $this->expectException(ProviderCouldNotAddShareException::class); |
|
268 | - $this->expectExceptionMessage('Incomplete protocol data'); |
|
269 | - $this->expectExceptionCode(400); |
|
270 | - $this->calendarFederationProvider->shareReceived($share); |
|
271 | - } |
|
272 | - |
|
273 | - public function testShareReceivedWithUnsupportedAccess(): void { |
|
274 | - $share = $this->createMock(ICloudFederationShare::class); |
|
275 | - $share->method('getShareType') |
|
276 | - ->willReturn('user'); |
|
277 | - $share->method('getProtocol') |
|
278 | - ->willReturn([ |
|
279 | - 'version' => 'v1', |
|
280 | - 'url' => 'https://nextcloud.remote/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user1', |
|
281 | - 'displayName' => 'Calendar 1', |
|
282 | - 'color' => '#ff0000', |
|
283 | - 'access' => 2, // Backend::ACCESS_READ_WRITE |
|
284 | - 'components' => 'VEVENT,VTODO', |
|
285 | - ]); |
|
286 | - $share->method('getShareWith') |
|
287 | - ->willReturn('sharee1'); |
|
288 | - $share->method('getShareSecret') |
|
289 | - ->willReturn('token'); |
|
290 | - $share->method('getSharedBy') |
|
291 | - ->willReturn('[email protected]'); |
|
292 | - $share->method('getSharedByDisplayName') |
|
293 | - ->willReturn('User 1'); |
|
294 | - |
|
295 | - $this->calendarFederationConfig->expects(self::once()) |
|
296 | - ->method('isFederationEnabled') |
|
297 | - ->willReturn(true); |
|
298 | - |
|
299 | - $this->federatedCalendarMapper->expects(self::never()) |
|
300 | - ->method('insert'); |
|
301 | - $this->jobList->expects(self::never()) |
|
302 | - ->method('add'); |
|
303 | - |
|
304 | - $this->expectException(ProviderCouldNotAddShareException::class); |
|
305 | - $this->expectExceptionMessageMatches('/Unsupported access value: [0-9]+/'); |
|
306 | - $this->expectExceptionCode(400); |
|
307 | - $this->calendarFederationProvider->shareReceived($share); |
|
308 | - } |
|
309 | - |
|
310 | - public function testNotificationReceivedWithUnknownNotification(): void { |
|
311 | - $actual = $this->calendarFederationProvider->notificationReceived('UNKNOWN', 'calendar', [ |
|
312 | - 'sharedSecret' => 'token', |
|
313 | - 'foobar' => 'baz', |
|
314 | - ]); |
|
315 | - $this->assertEquals([], $actual); |
|
316 | - } |
|
317 | - |
|
318 | - public function testNotificationReceivedWithInvalidProviderId(): void { |
|
319 | - $this->expectException(BadRequestException::class); |
|
320 | - $this->calendarFederationProvider->notificationReceived('SYNC_CALENDAR', 'foobar', [ |
|
321 | - 'sharedSecret' => 'token', |
|
322 | - 'shareWith' => '[email protected]', |
|
323 | - 'calendarUrl' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
324 | - ]); |
|
325 | - } |
|
326 | - |
|
327 | - public function testNotificationReceivedWithSyncCalendarNotification(): void { |
|
328 | - $cloudId = $this->createMock(ICloudId::class); |
|
329 | - $cloudId->method('getId') |
|
330 | - ->willReturn('[email protected]'); |
|
331 | - $cloudId->method('getUser') |
|
332 | - ->willReturn('remote1'); |
|
333 | - $cloudId->method('getRemote') |
|
334 | - ->willReturn('nextcloud.remote'); |
|
335 | - |
|
336 | - $this->cloudIdManager->expects(self::once()) |
|
337 | - ->method('resolveCloudId') |
|
338 | - ->with('[email protected]') |
|
339 | - ->willReturn($cloudId); |
|
340 | - |
|
341 | - $calendar1 = new FederatedCalendarEntity(); |
|
342 | - $calendar1->setId(10); |
|
343 | - $calendar2 = new FederatedCalendarEntity(); |
|
344 | - $calendar2->setId(11); |
|
345 | - $calendars = [ |
|
346 | - $calendar1, |
|
347 | - $calendar2, |
|
348 | - ]; |
|
349 | - $this->federatedCalendarMapper->expects(self::once()) |
|
350 | - ->method('findByRemoteUrl') |
|
351 | - ->with( |
|
352 | - 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
353 | - 'principals/users/remote1', |
|
354 | - 'token', |
|
355 | - ) |
|
356 | - ->willReturn($calendars); |
|
357 | - |
|
358 | - $this->jobList->expects(self::exactly(2)) |
|
359 | - ->method('add') |
|
360 | - ->willReturnMap([ |
|
361 | - [FederatedCalendarSyncJob::class, ['id' => 10]], |
|
362 | - [FederatedCalendarSyncJob::class, ['id' => 11]], |
|
363 | - ]); |
|
364 | - |
|
365 | - $actual = $this->calendarFederationProvider->notificationReceived( |
|
366 | - 'SYNC_CALENDAR', |
|
367 | - 'calendar', |
|
368 | - [ |
|
369 | - 'sharedSecret' => 'token', |
|
370 | - 'shareWith' => '[email protected]', |
|
371 | - 'calendarUrl' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
372 | - ], |
|
373 | - ); |
|
374 | - $this->assertEquals([], $actual); |
|
375 | - } |
|
376 | - |
|
377 | - public static function provideIncompleteSyncCalendarNotificationData(): array { |
|
378 | - return [ |
|
379 | - // Missing shareWith |
|
380 | - [[ |
|
381 | - 'sharedSecret' => 'token', |
|
382 | - 'shareWith' => '', |
|
383 | - 'calendarUrl' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
384 | - ]], |
|
385 | - [[ |
|
386 | - 'sharedSecret' => 'token', |
|
387 | - 'calendarUrl' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
388 | - ]], |
|
389 | - |
|
390 | - // Missing calendarUrl |
|
391 | - [[ |
|
392 | - 'sharedSecret' => 'token', |
|
393 | - 'shareWith' => '[email protected]', |
|
394 | - 'calendarUrl' => '', |
|
395 | - ]], |
|
396 | - [[ |
|
397 | - 'sharedSecret' => 'token', |
|
398 | - 'shareWith' => '[email protected]', |
|
399 | - ]], |
|
400 | - ]; |
|
401 | - } |
|
402 | - |
|
403 | - #[DataProvider('provideIncompleteSyncCalendarNotificationData')] |
|
404 | - public function testNotificationReceivedWithSyncCalendarNotificationAndIncompleteData( |
|
405 | - array $notification, |
|
406 | - ): void { |
|
407 | - $this->cloudIdManager->expects(self::never()) |
|
408 | - ->method('resolveCloudId'); |
|
409 | - $this->federatedCalendarMapper->expects(self::never()) |
|
410 | - ->method('findByRemoteUrl'); |
|
411 | - $this->jobList->expects(self::never()) |
|
412 | - ->method('add'); |
|
413 | - |
|
414 | - $this->expectException(BadRequestException::class); |
|
415 | - $this->calendarFederationProvider->notificationReceived( |
|
416 | - 'SYNC_CALENDAR', |
|
417 | - 'calendar', |
|
418 | - $notification, |
|
419 | - ); |
|
420 | - } |
|
421 | - |
|
422 | - public function testNotificationReceivedWithSyncCalendarNotificationAndInvalidCloudId(): void { |
|
423 | - $this->cloudIdManager->expects(self::once()) |
|
424 | - ->method('resolveCloudId') |
|
425 | - ->with('invalid-cloud-id') |
|
426 | - ->willThrowException(new \InvalidArgumentException()); |
|
427 | - |
|
428 | - $this->federatedCalendarMapper->expects(self::never()) |
|
429 | - ->method('findByRemoteUrl'); |
|
430 | - $this->jobList->expects(self::never()) |
|
431 | - ->method('add'); |
|
432 | - |
|
433 | - $this->expectException(ShareNotFound::class); |
|
434 | - $this->expectExceptionMessage('Invalid sharee cloud id'); |
|
435 | - $this->calendarFederationProvider->notificationReceived( |
|
436 | - 'SYNC_CALENDAR', |
|
437 | - 'calendar', |
|
438 | - [ |
|
439 | - 'sharedSecret' => 'token', |
|
440 | - 'shareWith' => 'invalid-cloud-id', |
|
441 | - 'calendarUrl' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
442 | - ], |
|
443 | - ); |
|
444 | - } |
|
445 | - |
|
446 | - public function testNotificationReceivedWithSyncCalendarNotificationAndNoCalendars(): void { |
|
447 | - $cloudId = $this->createMock(ICloudId::class); |
|
448 | - $cloudId->method('getId') |
|
449 | - ->willReturn('[email protected]'); |
|
450 | - $cloudId->method('getUser') |
|
451 | - ->willReturn('remote1'); |
|
452 | - $cloudId->method('getRemote') |
|
453 | - ->willReturn('nextcloud.remote'); |
|
454 | - |
|
455 | - $this->cloudIdManager->expects(self::once()) |
|
456 | - ->method('resolveCloudId') |
|
457 | - ->with('[email protected]') |
|
458 | - ->willReturn($cloudId); |
|
459 | - |
|
460 | - $this->federatedCalendarMapper->expects(self::once()) |
|
461 | - ->method('findByRemoteUrl') |
|
462 | - ->with( |
|
463 | - 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
464 | - 'principals/users/remote1', |
|
465 | - 'token', |
|
466 | - ) |
|
467 | - ->willReturn([]); |
|
468 | - |
|
469 | - $this->jobList->expects(self::never()) |
|
470 | - ->method('add'); |
|
471 | - |
|
472 | - $this->expectException(ShareNotFound::class); |
|
473 | - $this->expectExceptionMessage('Calendar is not shared with the sharee'); |
|
474 | - $this->calendarFederationProvider->notificationReceived( |
|
475 | - 'SYNC_CALENDAR', |
|
476 | - 'calendar', |
|
477 | - [ |
|
478 | - 'sharedSecret' => 'token', |
|
479 | - 'shareWith' => '[email protected]', |
|
480 | - 'calendarUrl' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
481 | - ], |
|
482 | - ); |
|
483 | - } |
|
31 | + private CalendarFederationProvider $calendarFederationProvider; |
|
32 | + |
|
33 | + private LoggerInterface&MockObject $logger; |
|
34 | + private FederatedCalendarMapper&MockObject $federatedCalendarMapper; |
|
35 | + private CalendarFederationConfig&MockObject $calendarFederationConfig; |
|
36 | + private IJobList&MockObject $jobList; |
|
37 | + private ICloudIdManager&MockObject $cloudIdManager; |
|
38 | + |
|
39 | + protected function setUp(): void { |
|
40 | + parent::setUp(); |
|
41 | + |
|
42 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
43 | + $this->federatedCalendarMapper = $this->createMock(FederatedCalendarMapper::class); |
|
44 | + $this->calendarFederationConfig = $this->createMock(CalendarFederationConfig::class); |
|
45 | + $this->jobList = $this->createMock(JobList::class); |
|
46 | + $this->cloudIdManager = $this->createMock(ICloudIdManager::class); |
|
47 | + |
|
48 | + $this->calendarFederationProvider = new CalendarFederationProvider( |
|
49 | + $this->logger, |
|
50 | + $this->federatedCalendarMapper, |
|
51 | + $this->calendarFederationConfig, |
|
52 | + $this->jobList, |
|
53 | + $this->cloudIdManager, |
|
54 | + ); |
|
55 | + } |
|
56 | + |
|
57 | + public function testGetShareType(): void { |
|
58 | + $this->assertEquals('calendar', $this->calendarFederationProvider->getShareType()); |
|
59 | + } |
|
60 | + |
|
61 | + public function testGetSupportedShareTypes(): void { |
|
62 | + $this->assertEqualsCanonicalizing( |
|
63 | + ['user'], |
|
64 | + $this->calendarFederationProvider->getSupportedShareTypes(), |
|
65 | + ); |
|
66 | + } |
|
67 | + |
|
68 | + public function testShareReceived(): void { |
|
69 | + $share = $this->createMock(ICloudFederationShare::class); |
|
70 | + $share->method('getShareType') |
|
71 | + ->willReturn('user'); |
|
72 | + $share->method('getProtocol') |
|
73 | + ->willReturn([ |
|
74 | + 'version' => 'v1', |
|
75 | + 'url' => 'https://nextcloud.remote/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user1', |
|
76 | + 'displayName' => 'Calendar 1', |
|
77 | + 'color' => '#ff0000', |
|
78 | + 'access' => 3, |
|
79 | + 'components' => 'VEVENT,VTODO', |
|
80 | + ]); |
|
81 | + $share->method('getShareWith') |
|
82 | + ->willReturn('sharee1'); |
|
83 | + $share->method('getShareSecret') |
|
84 | + ->willReturn('token'); |
|
85 | + $share->method('getSharedBy') |
|
86 | + ->willReturn('[email protected]'); |
|
87 | + $share->method('getSharedByDisplayName') |
|
88 | + ->willReturn('User 1'); |
|
89 | + |
|
90 | + $this->calendarFederationConfig->expects(self::once()) |
|
91 | + ->method('isFederationEnabled') |
|
92 | + ->willReturn(true); |
|
93 | + |
|
94 | + $this->federatedCalendarMapper->expects(self::once()) |
|
95 | + ->method('deleteByUri') |
|
96 | + ->with( |
|
97 | + 'principals/users/sharee1', |
|
98 | + 'ae4b8ab904076fff2b955ea21b1a0d92', |
|
99 | + ); |
|
100 | + |
|
101 | + $this->federatedCalendarMapper->expects(self::once()) |
|
102 | + ->method('insert') |
|
103 | + ->willReturnCallback(function (FederatedCalendarEntity $calendar) { |
|
104 | + $this->assertEquals('principals/users/sharee1', $calendar->getPrincipaluri()); |
|
105 | + $this->assertEquals('ae4b8ab904076fff2b955ea21b1a0d92', $calendar->getUri()); |
|
106 | + $this->assertEquals('https://nextcloud.remote/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user1', $calendar->getRemoteUrl()); |
|
107 | + $this->assertEquals('Calendar 1', $calendar->getDisplayName()); |
|
108 | + $this->assertEquals('#ff0000', $calendar->getColor()); |
|
109 | + $this->assertEquals('token', $calendar->getToken()); |
|
110 | + $this->assertEquals('[email protected]', $calendar->getSharedBy()); |
|
111 | + $this->assertEquals('User 1', $calendar->getSharedByDisplayName()); |
|
112 | + $this->assertEquals(1, $calendar->getPermissions()); |
|
113 | + $this->assertEquals('VEVENT,VTODO', $calendar->getComponents()); |
|
114 | + |
|
115 | + $calendar->setId(10); |
|
116 | + return $calendar; |
|
117 | + }); |
|
118 | + |
|
119 | + $this->jobList->expects(self::once()) |
|
120 | + ->method('add') |
|
121 | + ->with(FederatedCalendarSyncJob::class, ['id' => 10]); |
|
122 | + |
|
123 | + $this->assertEquals(10, $this->calendarFederationProvider->shareReceived($share)); |
|
124 | + } |
|
125 | + |
|
126 | + public function testShareReceivedWithInvalidProtocolVersion(): void { |
|
127 | + $share = $this->createMock(ICloudFederationShare::class); |
|
128 | + $share->method('getShareType') |
|
129 | + ->willReturn('user'); |
|
130 | + $share->method('getProtocol') |
|
131 | + ->willReturn([ |
|
132 | + 'version' => 'unknown', |
|
133 | + 'url' => 'https://nextcloud.remote/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user1', |
|
134 | + 'displayName' => 'Calendar 1', |
|
135 | + 'color' => '#ff0000', |
|
136 | + 'access' => 3, |
|
137 | + 'components' => 'VEVENT,VTODO', |
|
138 | + ]); |
|
139 | + |
|
140 | + $this->calendarFederationConfig->expects(self::once()) |
|
141 | + ->method('isFederationEnabled') |
|
142 | + ->willReturn(true); |
|
143 | + |
|
144 | + $this->federatedCalendarMapper->expects(self::never()) |
|
145 | + ->method('insert'); |
|
146 | + $this->jobList->expects(self::never()) |
|
147 | + ->method('add'); |
|
148 | + |
|
149 | + $this->expectException(ProviderCouldNotAddShareException::class); |
|
150 | + $this->expectExceptionMessage('Unknown protocol version'); |
|
151 | + $this->expectExceptionCode(400); |
|
152 | + $this->assertEquals(10, $this->calendarFederationProvider->shareReceived($share)); |
|
153 | + } |
|
154 | + |
|
155 | + public function testShareReceivedWithoutProtocolVersion(): void { |
|
156 | + $share = $this->createMock(ICloudFederationShare::class); |
|
157 | + $share->method('getShareType') |
|
158 | + ->willReturn('user'); |
|
159 | + $share->method('getProtocol') |
|
160 | + ->willReturn([ |
|
161 | + 'url' => 'https://nextcloud.remote/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user1', |
|
162 | + 'displayName' => 'Calendar 1', |
|
163 | + 'color' => '#ff0000', |
|
164 | + 'access' => 3, |
|
165 | + 'components' => 'VEVENT,VTODO', |
|
166 | + ]); |
|
167 | + |
|
168 | + $this->calendarFederationConfig->expects(self::once()) |
|
169 | + ->method('isFederationEnabled') |
|
170 | + ->willReturn(true); |
|
171 | + |
|
172 | + $this->federatedCalendarMapper->expects(self::never()) |
|
173 | + ->method('insert'); |
|
174 | + $this->jobList->expects(self::never()) |
|
175 | + ->method('add'); |
|
176 | + |
|
177 | + $this->expectException(ProviderCouldNotAddShareException::class); |
|
178 | + $this->expectExceptionMessage('Unknown protocol version'); |
|
179 | + $this->expectExceptionCode(400); |
|
180 | + $this->assertEquals(10, $this->calendarFederationProvider->shareReceived($share)); |
|
181 | + } |
|
182 | + |
|
183 | + public function testShareReceivedWithDisabledConfig(): void { |
|
184 | + $share = $this->createMock(ICloudFederationShare::class); |
|
185 | + |
|
186 | + $this->calendarFederationConfig->expects(self::once()) |
|
187 | + ->method('isFederationEnabled') |
|
188 | + ->willReturn(false); |
|
189 | + |
|
190 | + $this->federatedCalendarMapper->expects(self::never()) |
|
191 | + ->method('insert'); |
|
192 | + $this->jobList->expects(self::never()) |
|
193 | + ->method('add'); |
|
194 | + |
|
195 | + $this->expectException(ProviderCouldNotAddShareException::class); |
|
196 | + $this->expectExceptionMessage('Server does not support calendar federation'); |
|
197 | + $this->expectExceptionCode(503); |
|
198 | + $this->calendarFederationProvider->shareReceived($share); |
|
199 | + } |
|
200 | + |
|
201 | + public function testShareReceivedWithUnsupportedShareType(): void { |
|
202 | + $share = $this->createMock(ICloudFederationShare::class); |
|
203 | + $share->method('getShareType') |
|
204 | + ->willReturn('foobar'); |
|
205 | + |
|
206 | + $this->calendarFederationConfig->expects(self::once()) |
|
207 | + ->method('isFederationEnabled') |
|
208 | + ->willReturn(true); |
|
209 | + |
|
210 | + $this->federatedCalendarMapper->expects(self::never()) |
|
211 | + ->method('insert'); |
|
212 | + $this->jobList->expects(self::never()) |
|
213 | + ->method('add'); |
|
214 | + |
|
215 | + $this->expectException(ProviderCouldNotAddShareException::class); |
|
216 | + $this->expectExceptionMessage('Support for sharing with non-users not implemented yet'); |
|
217 | + $this->expectExceptionCode(501); |
|
218 | + $this->calendarFederationProvider->shareReceived($share); |
|
219 | + } |
|
220 | + |
|
221 | + public static function provideIncompleteProtocolData(): array { |
|
222 | + return [ |
|
223 | + [[ |
|
224 | + 'version' => 'v1', |
|
225 | + 'url' => '', |
|
226 | + 'displayName' => 'Calendar 1', |
|
227 | + 'color' => '#ff0000', |
|
228 | + 'access' => 3, |
|
229 | + 'components' => 'VEVENT,VTODO', |
|
230 | + ]], |
|
231 | + [[ |
|
232 | + 'version' => 'v1', |
|
233 | + 'url' => 'https://nextcloud.remote/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user1', |
|
234 | + 'displayName' => '', |
|
235 | + 'color' => '#ff0000', |
|
236 | + 'access' => 3, |
|
237 | + 'components' => 'VEVENT,VTODO', |
|
238 | + ]], |
|
239 | + ]; |
|
240 | + } |
|
241 | + |
|
242 | + #[DataProvider('provideIncompleteProtocolData')] |
|
243 | + public function testShareReceivedWithIncompleteProtocolData(array $protocol): void { |
|
244 | + $share = $this->createMock(ICloudFederationShare::class); |
|
245 | + $share->method('getShareType') |
|
246 | + ->willReturn('user'); |
|
247 | + $share->method('getProtocol') |
|
248 | + ->willReturn($protocol); |
|
249 | + $share->method('getShareWith') |
|
250 | + ->willReturn('sharee1'); |
|
251 | + $share->method('getShareSecret') |
|
252 | + ->willReturn('token'); |
|
253 | + $share->method('getSharedBy') |
|
254 | + ->willReturn('[email protected]'); |
|
255 | + $share->method('getSharedByDisplayName') |
|
256 | + ->willReturn('User 1'); |
|
257 | + |
|
258 | + $this->calendarFederationConfig->expects(self::once()) |
|
259 | + ->method('isFederationEnabled') |
|
260 | + ->willReturn(true); |
|
261 | + |
|
262 | + $this->federatedCalendarMapper->expects(self::never()) |
|
263 | + ->method('insert'); |
|
264 | + $this->jobList->expects(self::never()) |
|
265 | + ->method('add'); |
|
266 | + |
|
267 | + $this->expectException(ProviderCouldNotAddShareException::class); |
|
268 | + $this->expectExceptionMessage('Incomplete protocol data'); |
|
269 | + $this->expectExceptionCode(400); |
|
270 | + $this->calendarFederationProvider->shareReceived($share); |
|
271 | + } |
|
272 | + |
|
273 | + public function testShareReceivedWithUnsupportedAccess(): void { |
|
274 | + $share = $this->createMock(ICloudFederationShare::class); |
|
275 | + $share->method('getShareType') |
|
276 | + ->willReturn('user'); |
|
277 | + $share->method('getProtocol') |
|
278 | + ->willReturn([ |
|
279 | + 'version' => 'v1', |
|
280 | + 'url' => 'https://nextcloud.remote/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user1', |
|
281 | + 'displayName' => 'Calendar 1', |
|
282 | + 'color' => '#ff0000', |
|
283 | + 'access' => 2, // Backend::ACCESS_READ_WRITE |
|
284 | + 'components' => 'VEVENT,VTODO', |
|
285 | + ]); |
|
286 | + $share->method('getShareWith') |
|
287 | + ->willReturn('sharee1'); |
|
288 | + $share->method('getShareSecret') |
|
289 | + ->willReturn('token'); |
|
290 | + $share->method('getSharedBy') |
|
291 | + ->willReturn('[email protected]'); |
|
292 | + $share->method('getSharedByDisplayName') |
|
293 | + ->willReturn('User 1'); |
|
294 | + |
|
295 | + $this->calendarFederationConfig->expects(self::once()) |
|
296 | + ->method('isFederationEnabled') |
|
297 | + ->willReturn(true); |
|
298 | + |
|
299 | + $this->federatedCalendarMapper->expects(self::never()) |
|
300 | + ->method('insert'); |
|
301 | + $this->jobList->expects(self::never()) |
|
302 | + ->method('add'); |
|
303 | + |
|
304 | + $this->expectException(ProviderCouldNotAddShareException::class); |
|
305 | + $this->expectExceptionMessageMatches('/Unsupported access value: [0-9]+/'); |
|
306 | + $this->expectExceptionCode(400); |
|
307 | + $this->calendarFederationProvider->shareReceived($share); |
|
308 | + } |
|
309 | + |
|
310 | + public function testNotificationReceivedWithUnknownNotification(): void { |
|
311 | + $actual = $this->calendarFederationProvider->notificationReceived('UNKNOWN', 'calendar', [ |
|
312 | + 'sharedSecret' => 'token', |
|
313 | + 'foobar' => 'baz', |
|
314 | + ]); |
|
315 | + $this->assertEquals([], $actual); |
|
316 | + } |
|
317 | + |
|
318 | + public function testNotificationReceivedWithInvalidProviderId(): void { |
|
319 | + $this->expectException(BadRequestException::class); |
|
320 | + $this->calendarFederationProvider->notificationReceived('SYNC_CALENDAR', 'foobar', [ |
|
321 | + 'sharedSecret' => 'token', |
|
322 | + 'shareWith' => '[email protected]', |
|
323 | + 'calendarUrl' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
324 | + ]); |
|
325 | + } |
|
326 | + |
|
327 | + public function testNotificationReceivedWithSyncCalendarNotification(): void { |
|
328 | + $cloudId = $this->createMock(ICloudId::class); |
|
329 | + $cloudId->method('getId') |
|
330 | + ->willReturn('[email protected]'); |
|
331 | + $cloudId->method('getUser') |
|
332 | + ->willReturn('remote1'); |
|
333 | + $cloudId->method('getRemote') |
|
334 | + ->willReturn('nextcloud.remote'); |
|
335 | + |
|
336 | + $this->cloudIdManager->expects(self::once()) |
|
337 | + ->method('resolveCloudId') |
|
338 | + ->with('[email protected]') |
|
339 | + ->willReturn($cloudId); |
|
340 | + |
|
341 | + $calendar1 = new FederatedCalendarEntity(); |
|
342 | + $calendar1->setId(10); |
|
343 | + $calendar2 = new FederatedCalendarEntity(); |
|
344 | + $calendar2->setId(11); |
|
345 | + $calendars = [ |
|
346 | + $calendar1, |
|
347 | + $calendar2, |
|
348 | + ]; |
|
349 | + $this->federatedCalendarMapper->expects(self::once()) |
|
350 | + ->method('findByRemoteUrl') |
|
351 | + ->with( |
|
352 | + 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
353 | + 'principals/users/remote1', |
|
354 | + 'token', |
|
355 | + ) |
|
356 | + ->willReturn($calendars); |
|
357 | + |
|
358 | + $this->jobList->expects(self::exactly(2)) |
|
359 | + ->method('add') |
|
360 | + ->willReturnMap([ |
|
361 | + [FederatedCalendarSyncJob::class, ['id' => 10]], |
|
362 | + [FederatedCalendarSyncJob::class, ['id' => 11]], |
|
363 | + ]); |
|
364 | + |
|
365 | + $actual = $this->calendarFederationProvider->notificationReceived( |
|
366 | + 'SYNC_CALENDAR', |
|
367 | + 'calendar', |
|
368 | + [ |
|
369 | + 'sharedSecret' => 'token', |
|
370 | + 'shareWith' => '[email protected]', |
|
371 | + 'calendarUrl' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
372 | + ], |
|
373 | + ); |
|
374 | + $this->assertEquals([], $actual); |
|
375 | + } |
|
376 | + |
|
377 | + public static function provideIncompleteSyncCalendarNotificationData(): array { |
|
378 | + return [ |
|
379 | + // Missing shareWith |
|
380 | + [[ |
|
381 | + 'sharedSecret' => 'token', |
|
382 | + 'shareWith' => '', |
|
383 | + 'calendarUrl' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
384 | + ]], |
|
385 | + [[ |
|
386 | + 'sharedSecret' => 'token', |
|
387 | + 'calendarUrl' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
388 | + ]], |
|
389 | + |
|
390 | + // Missing calendarUrl |
|
391 | + [[ |
|
392 | + 'sharedSecret' => 'token', |
|
393 | + 'shareWith' => '[email protected]', |
|
394 | + 'calendarUrl' => '', |
|
395 | + ]], |
|
396 | + [[ |
|
397 | + 'sharedSecret' => 'token', |
|
398 | + 'shareWith' => '[email protected]', |
|
399 | + ]], |
|
400 | + ]; |
|
401 | + } |
|
402 | + |
|
403 | + #[DataProvider('provideIncompleteSyncCalendarNotificationData')] |
|
404 | + public function testNotificationReceivedWithSyncCalendarNotificationAndIncompleteData( |
|
405 | + array $notification, |
|
406 | + ): void { |
|
407 | + $this->cloudIdManager->expects(self::never()) |
|
408 | + ->method('resolveCloudId'); |
|
409 | + $this->federatedCalendarMapper->expects(self::never()) |
|
410 | + ->method('findByRemoteUrl'); |
|
411 | + $this->jobList->expects(self::never()) |
|
412 | + ->method('add'); |
|
413 | + |
|
414 | + $this->expectException(BadRequestException::class); |
|
415 | + $this->calendarFederationProvider->notificationReceived( |
|
416 | + 'SYNC_CALENDAR', |
|
417 | + 'calendar', |
|
418 | + $notification, |
|
419 | + ); |
|
420 | + } |
|
421 | + |
|
422 | + public function testNotificationReceivedWithSyncCalendarNotificationAndInvalidCloudId(): void { |
|
423 | + $this->cloudIdManager->expects(self::once()) |
|
424 | + ->method('resolveCloudId') |
|
425 | + ->with('invalid-cloud-id') |
|
426 | + ->willThrowException(new \InvalidArgumentException()); |
|
427 | + |
|
428 | + $this->federatedCalendarMapper->expects(self::never()) |
|
429 | + ->method('findByRemoteUrl'); |
|
430 | + $this->jobList->expects(self::never()) |
|
431 | + ->method('add'); |
|
432 | + |
|
433 | + $this->expectException(ShareNotFound::class); |
|
434 | + $this->expectExceptionMessage('Invalid sharee cloud id'); |
|
435 | + $this->calendarFederationProvider->notificationReceived( |
|
436 | + 'SYNC_CALENDAR', |
|
437 | + 'calendar', |
|
438 | + [ |
|
439 | + 'sharedSecret' => 'token', |
|
440 | + 'shareWith' => 'invalid-cloud-id', |
|
441 | + 'calendarUrl' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
442 | + ], |
|
443 | + ); |
|
444 | + } |
|
445 | + |
|
446 | + public function testNotificationReceivedWithSyncCalendarNotificationAndNoCalendars(): void { |
|
447 | + $cloudId = $this->createMock(ICloudId::class); |
|
448 | + $cloudId->method('getId') |
|
449 | + ->willReturn('[email protected]'); |
|
450 | + $cloudId->method('getUser') |
|
451 | + ->willReturn('remote1'); |
|
452 | + $cloudId->method('getRemote') |
|
453 | + ->willReturn('nextcloud.remote'); |
|
454 | + |
|
455 | + $this->cloudIdManager->expects(self::once()) |
|
456 | + ->method('resolveCloudId') |
|
457 | + ->with('[email protected]') |
|
458 | + ->willReturn($cloudId); |
|
459 | + |
|
460 | + $this->federatedCalendarMapper->expects(self::once()) |
|
461 | + ->method('findByRemoteUrl') |
|
462 | + ->with( |
|
463 | + 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
464 | + 'principals/users/remote1', |
|
465 | + 'token', |
|
466 | + ) |
|
467 | + ->willReturn([]); |
|
468 | + |
|
469 | + $this->jobList->expects(self::never()) |
|
470 | + ->method('add'); |
|
471 | + |
|
472 | + $this->expectException(ShareNotFound::class); |
|
473 | + $this->expectExceptionMessage('Calendar is not shared with the sharee'); |
|
474 | + $this->calendarFederationProvider->notificationReceived( |
|
475 | + 'SYNC_CALENDAR', |
|
476 | + 'calendar', |
|
477 | + [ |
|
478 | + 'sharedSecret' => 'token', |
|
479 | + 'shareWith' => '[email protected]', |
|
480 | + 'calendarUrl' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
481 | + ], |
|
482 | + ); |
|
483 | + } |
|
484 | 484 | } |
@@ -100,7 +100,7 @@ |
||
100 | 100 | |
101 | 101 | $this->federatedCalendarMapper->expects(self::once()) |
102 | 102 | ->method('insert') |
103 | - ->willReturnCallback(function (FederatedCalendarEntity $calendar) { |
|
103 | + ->willReturnCallback(function(FederatedCalendarEntity $calendar) { |
|
104 | 104 | $this->assertEquals('principals/users/sharee1', $calendar->getPrincipaluri()); |
105 | 105 | $this->assertEquals('ae4b8ab904076fff2b955ea21b1a0d92', $calendar->getUri()); |
106 | 106 | $this->assertEquals('https://nextcloud.remote/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user1', $calendar->getRemoteUrl()); |
@@ -20,102 +20,102 @@ |
||
20 | 20 | use Test\TestCase; |
21 | 21 | |
22 | 22 | class RemoteUserCalendarHomeTest extends TestCase { |
23 | - private RemoteUserCalendarHome $remoteUserCalendarHome; |
|
24 | - |
|
25 | - private BackendInterface&MockObject $calDavBackend; |
|
26 | - private IL10N&MockObject $l10n; |
|
27 | - private IConfig&MockObject $config; |
|
28 | - private LoggerInterface&MockObject $logger; |
|
29 | - |
|
30 | - protected function setUp(): void { |
|
31 | - parent::setUp(); |
|
32 | - |
|
33 | - $this->calDavBackend = $this->createMock(BackendInterface::class); |
|
34 | - $this->l10n = $this->createMock(IL10N::class); |
|
35 | - $this->config = $this->createMock(IConfig::class); |
|
36 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
37 | - |
|
38 | - $this->remoteUserCalendarHome = new RemoteUserCalendarHome( |
|
39 | - $this->calDavBackend, |
|
40 | - [ |
|
41 | - 'uri' => 'principals/remote-users/abcdef123', |
|
42 | - ], |
|
43 | - $this->l10n, |
|
44 | - $this->config, |
|
45 | - $this->logger, |
|
46 | - ); |
|
47 | - } |
|
48 | - |
|
49 | - public function testGetChild(): void { |
|
50 | - $calendar1 = [ |
|
51 | - 'id' => 10, |
|
52 | - 'uri' => 'cal1', |
|
53 | - ]; |
|
54 | - $calendar2 = [ |
|
55 | - 'id' => 11, |
|
56 | - 'uri' => 'cal2', |
|
57 | - ]; |
|
58 | - |
|
59 | - $this->calDavBackend->expects(self::once()) |
|
60 | - ->method('getCalendarsForUser') |
|
61 | - ->with('principals/remote-users/abcdef123') |
|
62 | - ->willReturn([ |
|
63 | - $calendar1, |
|
64 | - $calendar2, |
|
65 | - ]); |
|
66 | - |
|
67 | - $actual = $this->remoteUserCalendarHome->getChild('cal2'); |
|
68 | - $this->assertInstanceOf(Calendar::class, $actual); |
|
69 | - $this->assertEquals(11, $actual->getResourceId()); |
|
70 | - $this->assertEquals('cal2', $actual->getName()); |
|
71 | - } |
|
72 | - |
|
73 | - public function testGetChildNotFound(): void { |
|
74 | - $calendar1 = [ |
|
75 | - 'id' => 10, |
|
76 | - 'uri' => 'cal1', |
|
77 | - ]; |
|
78 | - $calendar2 = [ |
|
79 | - 'id' => 11, |
|
80 | - 'uri' => 'cal2', |
|
81 | - ]; |
|
82 | - |
|
83 | - $this->calDavBackend->expects(self::once()) |
|
84 | - ->method('getCalendarsForUser') |
|
85 | - ->with('principals/remote-users/abcdef123') |
|
86 | - ->willReturn([ |
|
87 | - $calendar1, |
|
88 | - $calendar2, |
|
89 | - ]); |
|
90 | - |
|
91 | - $this->expectException(NotFound::class); |
|
92 | - $this->remoteUserCalendarHome->getChild('cal3'); |
|
93 | - } |
|
94 | - |
|
95 | - public function testGetChildren(): void { |
|
96 | - $calendar1 = [ |
|
97 | - 'id' => 10, |
|
98 | - 'uri' => 'cal1', |
|
99 | - ]; |
|
100 | - $calendar2 = [ |
|
101 | - 'id' => 11, |
|
102 | - 'uri' => 'cal2', |
|
103 | - ]; |
|
104 | - |
|
105 | - $this->calDavBackend->expects(self::once()) |
|
106 | - ->method('getCalendarsForUser') |
|
107 | - ->with('principals/remote-users/abcdef123') |
|
108 | - ->willReturn([ |
|
109 | - $calendar1, |
|
110 | - $calendar2, |
|
111 | - ]); |
|
112 | - |
|
113 | - $actual = $this->remoteUserCalendarHome->getChildren(); |
|
114 | - $this->assertInstanceOf(Calendar::class, $actual[0]); |
|
115 | - $this->assertEquals(10, $actual[0]->getResourceId()); |
|
116 | - $this->assertEquals('cal1', $actual[0]->getName()); |
|
117 | - $this->assertInstanceOf(Calendar::class, $actual[1]); |
|
118 | - $this->assertEquals(11, $actual[1]->getResourceId()); |
|
119 | - $this->assertEquals('cal2', $actual[1]->getName()); |
|
120 | - } |
|
23 | + private RemoteUserCalendarHome $remoteUserCalendarHome; |
|
24 | + |
|
25 | + private BackendInterface&MockObject $calDavBackend; |
|
26 | + private IL10N&MockObject $l10n; |
|
27 | + private IConfig&MockObject $config; |
|
28 | + private LoggerInterface&MockObject $logger; |
|
29 | + |
|
30 | + protected function setUp(): void { |
|
31 | + parent::setUp(); |
|
32 | + |
|
33 | + $this->calDavBackend = $this->createMock(BackendInterface::class); |
|
34 | + $this->l10n = $this->createMock(IL10N::class); |
|
35 | + $this->config = $this->createMock(IConfig::class); |
|
36 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
37 | + |
|
38 | + $this->remoteUserCalendarHome = new RemoteUserCalendarHome( |
|
39 | + $this->calDavBackend, |
|
40 | + [ |
|
41 | + 'uri' => 'principals/remote-users/abcdef123', |
|
42 | + ], |
|
43 | + $this->l10n, |
|
44 | + $this->config, |
|
45 | + $this->logger, |
|
46 | + ); |
|
47 | + } |
|
48 | + |
|
49 | + public function testGetChild(): void { |
|
50 | + $calendar1 = [ |
|
51 | + 'id' => 10, |
|
52 | + 'uri' => 'cal1', |
|
53 | + ]; |
|
54 | + $calendar2 = [ |
|
55 | + 'id' => 11, |
|
56 | + 'uri' => 'cal2', |
|
57 | + ]; |
|
58 | + |
|
59 | + $this->calDavBackend->expects(self::once()) |
|
60 | + ->method('getCalendarsForUser') |
|
61 | + ->with('principals/remote-users/abcdef123') |
|
62 | + ->willReturn([ |
|
63 | + $calendar1, |
|
64 | + $calendar2, |
|
65 | + ]); |
|
66 | + |
|
67 | + $actual = $this->remoteUserCalendarHome->getChild('cal2'); |
|
68 | + $this->assertInstanceOf(Calendar::class, $actual); |
|
69 | + $this->assertEquals(11, $actual->getResourceId()); |
|
70 | + $this->assertEquals('cal2', $actual->getName()); |
|
71 | + } |
|
72 | + |
|
73 | + public function testGetChildNotFound(): void { |
|
74 | + $calendar1 = [ |
|
75 | + 'id' => 10, |
|
76 | + 'uri' => 'cal1', |
|
77 | + ]; |
|
78 | + $calendar2 = [ |
|
79 | + 'id' => 11, |
|
80 | + 'uri' => 'cal2', |
|
81 | + ]; |
|
82 | + |
|
83 | + $this->calDavBackend->expects(self::once()) |
|
84 | + ->method('getCalendarsForUser') |
|
85 | + ->with('principals/remote-users/abcdef123') |
|
86 | + ->willReturn([ |
|
87 | + $calendar1, |
|
88 | + $calendar2, |
|
89 | + ]); |
|
90 | + |
|
91 | + $this->expectException(NotFound::class); |
|
92 | + $this->remoteUserCalendarHome->getChild('cal3'); |
|
93 | + } |
|
94 | + |
|
95 | + public function testGetChildren(): void { |
|
96 | + $calendar1 = [ |
|
97 | + 'id' => 10, |
|
98 | + 'uri' => 'cal1', |
|
99 | + ]; |
|
100 | + $calendar2 = [ |
|
101 | + 'id' => 11, |
|
102 | + 'uri' => 'cal2', |
|
103 | + ]; |
|
104 | + |
|
105 | + $this->calDavBackend->expects(self::once()) |
|
106 | + ->method('getCalendarsForUser') |
|
107 | + ->with('principals/remote-users/abcdef123') |
|
108 | + ->willReturn([ |
|
109 | + $calendar1, |
|
110 | + $calendar2, |
|
111 | + ]); |
|
112 | + |
|
113 | + $actual = $this->remoteUserCalendarHome->getChildren(); |
|
114 | + $this->assertInstanceOf(Calendar::class, $actual[0]); |
|
115 | + $this->assertEquals(10, $actual[0]->getResourceId()); |
|
116 | + $this->assertEquals('cal1', $actual[0]->getName()); |
|
117 | + $this->assertInstanceOf(Calendar::class, $actual[1]); |
|
118 | + $this->assertEquals(11, $actual[1]->getResourceId()); |
|
119 | + $this->assertEquals('cal2', $actual[1]->getName()); |
|
120 | + } |
|
121 | 121 | } |
@@ -29,435 +29,435 @@ |
||
29 | 29 | use Test\TestCase; |
30 | 30 | |
31 | 31 | class FederationSharingServiceTest extends TestCase { |
32 | - private FederationSharingService $federationSharingService; |
|
33 | - |
|
34 | - private readonly ICloudFederationProviderManager&MockObject $federationManager; |
|
35 | - private readonly ICloudFederationFactory&MockObject $federationFactory; |
|
36 | - private readonly IUserManager&MockObject $userManager; |
|
37 | - private readonly IURLGenerator&MockObject $url; |
|
38 | - private readonly LoggerInterface&MockObject $logger; |
|
39 | - private readonly ISecureRandom&MockObject $random; |
|
40 | - private readonly SharingMapper&MockObject $sharingMapper; |
|
41 | - |
|
42 | - protected function setUp(): void { |
|
43 | - parent::setUp(); |
|
44 | - |
|
45 | - $this->federationManager = $this->createMock(ICloudFederationProviderManager::class); |
|
46 | - $this->federationFactory = $this->createMock(ICloudFederationFactory::class); |
|
47 | - $this->userManager = $this->createMock(IUserManager::class); |
|
48 | - $this->url = $this->createMock(IURLGenerator::class); |
|
49 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
50 | - $this->random = $this->createMock(ISecureRandom::class); |
|
51 | - $this->sharingMapper = $this->createMock(SharingMapper::class); |
|
52 | - |
|
53 | - $this->federationSharingService = new FederationSharingService( |
|
54 | - $this->federationManager, |
|
55 | - $this->federationFactory, |
|
56 | - $this->userManager, |
|
57 | - $this->url, |
|
58 | - $this->logger, |
|
59 | - $this->random, |
|
60 | - $this->sharingMapper, |
|
61 | - ); |
|
62 | - } |
|
63 | - |
|
64 | - public function testShareWith(): void { |
|
65 | - $shareable = $this->createMock(Calendar::class); |
|
66 | - $shareable->method('getOwner') |
|
67 | - ->willReturn('principals/users/host1'); |
|
68 | - $shareable->method('getName') |
|
69 | - ->willReturn('cal1'); |
|
70 | - $shareable->method('getResourceId') |
|
71 | - ->willReturn(10); |
|
72 | - $shareable->method('getProperties') |
|
73 | - ->willReturnCallback(static fn (array $props) => match ($props[0]) { |
|
74 | - '{DAV:}displayname' => ['{DAV:}displayname' => 'Calendar 1'], |
|
75 | - '{http://apple.com/ns/ical/}calendar-color' => [ |
|
76 | - '{http://apple.com/ns/ical/}calendar-color' => '#ff0000', |
|
77 | - ], |
|
78 | - '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => [ |
|
79 | - '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new SupportedCalendarComponentSet([ |
|
80 | - 'VEVENT', |
|
81 | - 'VTODO', |
|
82 | - ]), |
|
83 | - ] |
|
84 | - }); |
|
85 | - |
|
86 | - $hostUser = $this->createMock(IUser::class); |
|
87 | - $hostUser->method('getCloudId') |
|
88 | - ->willReturn('[email protected]'); |
|
89 | - $hostUser->method('getDisplayName') |
|
90 | - ->willReturn('Host 1'); |
|
91 | - $hostUser->method('getUID') |
|
92 | - ->willReturn('host1'); |
|
93 | - $this->userManager->expects(self::once()) |
|
94 | - ->method('get') |
|
95 | - ->with('host1') |
|
96 | - ->willReturn($hostUser); |
|
97 | - |
|
98 | - $this->random->expects(self::once()) |
|
99 | - ->method('generate') |
|
100 | - ->with(32) |
|
101 | - ->willReturn('token'); |
|
102 | - |
|
103 | - $share = $this->createMock(ICloudFederationShare::class); |
|
104 | - $share->expects(self::once()) |
|
105 | - ->method('getProtocol') |
|
106 | - ->willReturn([ |
|
107 | - 'preservedValue1' => 'foobar', |
|
108 | - 'preservedValue2' => 'baz', |
|
109 | - ]); |
|
110 | - $share->expects(self::once()) |
|
111 | - ->method('setProtocol') |
|
112 | - ->with([ |
|
113 | - 'preservedValue1' => 'foobar', |
|
114 | - 'preservedValue2' => 'baz', |
|
115 | - 'version' => 'v1', |
|
116 | - 'url' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
117 | - 'displayName' => 'Calendar 1', |
|
118 | - 'color' => '#ff0000', |
|
119 | - 'access' => 3, |
|
120 | - 'components' => 'VEVENT,VTODO', |
|
121 | - ]); |
|
122 | - $this->federationFactory->expects(self::once()) |
|
123 | - ->method('getCloudFederationShare') |
|
124 | - ->with( |
|
125 | - '[email protected]', |
|
126 | - 'cal1', |
|
127 | - 'Calendar 1', |
|
128 | - 'calendar', |
|
129 | - '[email protected]', |
|
130 | - 'Host 1', |
|
131 | - '[email protected]', |
|
132 | - 'Host 1', |
|
133 | - 'token', |
|
134 | - 'user', |
|
135 | - 'calendar', |
|
136 | - ) |
|
137 | - ->willReturn($share); |
|
138 | - |
|
139 | - $this->url->expects(self::once()) |
|
140 | - ->method('linkTo') |
|
141 | - ->with('', 'remote.php') |
|
142 | - ->willReturn('/remote.php'); |
|
143 | - $this->url->expects(self::once()) |
|
144 | - ->method('getAbsoluteURL') |
|
145 | - ->with('/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1') |
|
146 | - ->willReturn('https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1'); |
|
147 | - |
|
148 | - $response = $this->createMock(IResponse::class); |
|
149 | - $response->method('getStatusCode') |
|
150 | - ->willReturn(201); |
|
151 | - $this->federationManager->expects(self::once()) |
|
152 | - ->method('sendCloudShare') |
|
153 | - ->with($share) |
|
154 | - ->willReturn($response); |
|
155 | - |
|
156 | - $this->sharingMapper->expects(self::once()) |
|
157 | - ->method('deleteShare') |
|
158 | - ->with(10, 'calendar', 'principals/remote-users/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl'); |
|
159 | - $this->sharingMapper->expects(self::once()) |
|
160 | - ->method('shareWithToken') |
|
161 | - ->with( |
|
162 | - 10, |
|
163 | - 'calendar', |
|
164 | - 3, |
|
165 | - 'principals/remote-users/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl', |
|
166 | - 'token', |
|
167 | - ); |
|
168 | - |
|
169 | - $this->federationSharingService->shareWith( |
|
170 | - $shareable, |
|
171 | - 'principals/remote-users/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl', |
|
172 | - 3, // Read-only |
|
173 | - ); |
|
174 | - } |
|
175 | - |
|
176 | - public function testShareWithWithFailingFederationManager(): void { |
|
177 | - $shareable = $this->createMock(Calendar::class); |
|
178 | - $shareable->method('getOwner') |
|
179 | - ->willReturn('principals/users/host1'); |
|
180 | - $shareable->method('getName') |
|
181 | - ->willReturn('cal1'); |
|
182 | - $shareable->method('getResourceId') |
|
183 | - ->willReturn(10); |
|
184 | - $shareable->method('getProperties') |
|
185 | - ->willReturnCallback(static fn (array $props) => match ($props[0]) { |
|
186 | - '{DAV:}displayname' => ['{DAV:}displayname' => 'Calendar 1'], |
|
187 | - '{http://apple.com/ns/ical/}calendar-color' => [ |
|
188 | - '{http://apple.com/ns/ical/}calendar-color' => '#ff0000', |
|
189 | - ], |
|
190 | - '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => [ |
|
191 | - '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new SupportedCalendarComponentSet([ |
|
192 | - 'VEVENT', |
|
193 | - 'VTODO', |
|
194 | - ]), |
|
195 | - ] |
|
196 | - }); |
|
197 | - |
|
198 | - $hostUser = $this->createMock(IUser::class); |
|
199 | - $hostUser->method('getCloudId') |
|
200 | - ->willReturn('[email protected]'); |
|
201 | - $hostUser->method('getDisplayName') |
|
202 | - ->willReturn('Host 1'); |
|
203 | - $hostUser->method('getUID') |
|
204 | - ->willReturn('host1'); |
|
205 | - $this->userManager->expects(self::once()) |
|
206 | - ->method('get') |
|
207 | - ->with('host1') |
|
208 | - ->willReturn($hostUser); |
|
209 | - |
|
210 | - $this->random->expects(self::once()) |
|
211 | - ->method('generate') |
|
212 | - ->with(32) |
|
213 | - ->willReturn('token'); |
|
214 | - |
|
215 | - $share = $this->createMock(ICloudFederationShare::class); |
|
216 | - $share->expects(self::once()) |
|
217 | - ->method('getProtocol') |
|
218 | - ->willReturn([ |
|
219 | - 'preservedValue1' => 'foobar', |
|
220 | - 'preservedValue2' => 'baz', |
|
221 | - ]); |
|
222 | - $share->expects(self::once()) |
|
223 | - ->method('setProtocol') |
|
224 | - ->with([ |
|
225 | - 'preservedValue1' => 'foobar', |
|
226 | - 'preservedValue2' => 'baz', |
|
227 | - 'version' => 'v1', |
|
228 | - 'url' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
229 | - 'displayName' => 'Calendar 1', |
|
230 | - 'color' => '#ff0000', |
|
231 | - 'access' => 3, |
|
232 | - 'components' => 'VEVENT,VTODO', |
|
233 | - ]); |
|
234 | - $this->federationFactory->expects(self::once()) |
|
235 | - ->method('getCloudFederationShare') |
|
236 | - ->with( |
|
237 | - '[email protected]', |
|
238 | - 'cal1', |
|
239 | - 'Calendar 1', |
|
240 | - 'calendar', |
|
241 | - '[email protected]', |
|
242 | - 'Host 1', |
|
243 | - '[email protected]', |
|
244 | - 'Host 1', |
|
245 | - 'token', |
|
246 | - 'user', |
|
247 | - 'calendar', |
|
248 | - ) |
|
249 | - ->willReturn($share); |
|
250 | - |
|
251 | - $this->url->expects(self::once()) |
|
252 | - ->method('linkTo') |
|
253 | - ->with('', 'remote.php') |
|
254 | - ->willReturn('/remote.php'); |
|
255 | - $this->url->expects(self::once()) |
|
256 | - ->method('getAbsoluteURL') |
|
257 | - ->with('/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1') |
|
258 | - ->willReturn('https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1'); |
|
259 | - |
|
260 | - $response = $this->createMock(IResponse::class); |
|
261 | - $response->method('getStatusCode') |
|
262 | - ->willReturn(201); |
|
263 | - $this->federationManager->expects(self::once()) |
|
264 | - ->method('sendCloudShare') |
|
265 | - ->with($share) |
|
266 | - ->willThrowException(new OCMProviderException()); |
|
267 | - |
|
268 | - $this->sharingMapper->expects(self::never()) |
|
269 | - ->method('deleteShare'); |
|
270 | - $this->sharingMapper->expects(self::never()) |
|
271 | - ->method('shareWithToken'); |
|
272 | - |
|
273 | - $this->federationSharingService->shareWith( |
|
274 | - $shareable, |
|
275 | - 'principals/remote-users/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl', |
|
276 | - 3, // Read-only |
|
277 | - ); |
|
278 | - } |
|
279 | - |
|
280 | - public function testShareWithWithUnsuccessfulResponse(): void { |
|
281 | - $shareable = $this->createMock(Calendar::class); |
|
282 | - $shareable->method('getOwner') |
|
283 | - ->willReturn('principals/users/host1'); |
|
284 | - $shareable->method('getName') |
|
285 | - ->willReturn('cal1'); |
|
286 | - $shareable->method('getResourceId') |
|
287 | - ->willReturn(10); |
|
288 | - $shareable->method('getProperties') |
|
289 | - ->willReturnCallback(static fn (array $props) => match ($props[0]) { |
|
290 | - '{DAV:}displayname' => ['{DAV:}displayname' => 'Calendar 1'], |
|
291 | - '{http://apple.com/ns/ical/}calendar-color' => [ |
|
292 | - '{http://apple.com/ns/ical/}calendar-color' => '#ff0000', |
|
293 | - ], |
|
294 | - '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => [ |
|
295 | - '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new SupportedCalendarComponentSet([ |
|
296 | - 'VEVENT', |
|
297 | - 'VTODO', |
|
298 | - ]), |
|
299 | - ] |
|
300 | - }); |
|
301 | - |
|
302 | - $hostUser = $this->createMock(IUser::class); |
|
303 | - $hostUser->method('getCloudId') |
|
304 | - ->willReturn('[email protected]'); |
|
305 | - $hostUser->method('getDisplayName') |
|
306 | - ->willReturn('Host 1'); |
|
307 | - $hostUser->method('getUID') |
|
308 | - ->willReturn('host1'); |
|
309 | - $this->userManager->expects(self::once()) |
|
310 | - ->method('get') |
|
311 | - ->with('host1') |
|
312 | - ->willReturn($hostUser); |
|
313 | - |
|
314 | - $this->random->expects(self::once()) |
|
315 | - ->method('generate') |
|
316 | - ->with(32) |
|
317 | - ->willReturn('token'); |
|
318 | - |
|
319 | - $share = $this->createMock(ICloudFederationShare::class); |
|
320 | - $share->expects(self::once()) |
|
321 | - ->method('getProtocol') |
|
322 | - ->willReturn([ |
|
323 | - 'preservedValue1' => 'foobar', |
|
324 | - 'preservedValue2' => 'baz', |
|
325 | - ]); |
|
326 | - $share->expects(self::once()) |
|
327 | - ->method('setProtocol') |
|
328 | - ->with([ |
|
329 | - 'preservedValue1' => 'foobar', |
|
330 | - 'preservedValue2' => 'baz', |
|
331 | - 'version' => 'v1', |
|
332 | - 'url' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
333 | - 'displayName' => 'Calendar 1', |
|
334 | - 'color' => '#ff0000', |
|
335 | - 'access' => 3, |
|
336 | - 'components' => 'VEVENT,VTODO', |
|
337 | - ]); |
|
338 | - $this->federationFactory->expects(self::once()) |
|
339 | - ->method('getCloudFederationShare') |
|
340 | - ->with( |
|
341 | - '[email protected]', |
|
342 | - 'cal1', |
|
343 | - 'Calendar 1', |
|
344 | - 'calendar', |
|
345 | - '[email protected]', |
|
346 | - 'Host 1', |
|
347 | - '[email protected]', |
|
348 | - 'Host 1', |
|
349 | - 'token', |
|
350 | - 'user', |
|
351 | - 'calendar', |
|
352 | - ) |
|
353 | - ->willReturn($share); |
|
354 | - |
|
355 | - $this->url->expects(self::once()) |
|
356 | - ->method('linkTo') |
|
357 | - ->with('', 'remote.php') |
|
358 | - ->willReturn('/remote.php'); |
|
359 | - $this->url->expects(self::once()) |
|
360 | - ->method('getAbsoluteURL') |
|
361 | - ->with('/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1') |
|
362 | - ->willReturn('https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1'); |
|
363 | - |
|
364 | - $response = $this->createMock(IResponse::class); |
|
365 | - $response->method('getStatusCode') |
|
366 | - ->willReturn(400); |
|
367 | - $this->federationManager->expects(self::once()) |
|
368 | - ->method('sendCloudShare') |
|
369 | - ->with($share) |
|
370 | - ->willReturn($response); |
|
371 | - |
|
372 | - $this->sharingMapper->expects(self::never()) |
|
373 | - ->method('deleteShare'); |
|
374 | - $this->sharingMapper->expects(self::never()) |
|
375 | - ->method('shareWithToken'); |
|
376 | - |
|
377 | - $this->federationSharingService->shareWith( |
|
378 | - $shareable, |
|
379 | - 'principals/remote-users/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl', |
|
380 | - 3, // Read-only |
|
381 | - ); |
|
382 | - } |
|
383 | - |
|
384 | - public static function provideInvalidRemoteUserPrincipalData(): array { |
|
385 | - return [ |
|
386 | - ['principals/users/foobar'], |
|
387 | - ['remote-users/remote1'], |
|
388 | - ['foobar/remote-users/remote1'], |
|
389 | - ['principals/remote-groups/group1'], |
|
390 | - ]; |
|
391 | - } |
|
392 | - |
|
393 | - #[DataProvider('provideInvalidRemoteUserPrincipalData')] |
|
394 | - public function testShareWithWithInvalidRemoteUserPrincipal(string $remoteUserPrincipal): void { |
|
395 | - $shareable = $this->createMock(Calendar::class); |
|
396 | - $shareable->method('getOwner') |
|
397 | - ->willReturn('principals/users/host1'); |
|
398 | - |
|
399 | - $this->userManager->expects(self::never()) |
|
400 | - ->method('get'); |
|
401 | - |
|
402 | - $this->federationManager->expects(self::never()) |
|
403 | - ->method('sendCloudShare'); |
|
404 | - $this->sharingMapper->expects(self::never()) |
|
405 | - ->method('deleteShare'); |
|
406 | - $this->sharingMapper->expects(self::never()) |
|
407 | - ->method('shareWithToken'); |
|
408 | - |
|
409 | - $this->federationSharingService->shareWith( |
|
410 | - $shareable, |
|
411 | - $remoteUserPrincipal, |
|
412 | - 3, // Read-only |
|
413 | - ); |
|
414 | - } |
|
415 | - |
|
416 | - public function testShareWithWithUnknownUser(): void { |
|
417 | - $shareable = $this->createMock(Calendar::class); |
|
418 | - $shareable->method('getOwner') |
|
419 | - ->willReturn('principals/users/host1'); |
|
420 | - |
|
421 | - $this->userManager->expects(self::once()) |
|
422 | - ->method('get') |
|
423 | - ->with('host1') |
|
424 | - ->willReturn(null); |
|
425 | - |
|
426 | - $this->federationManager->expects(self::never()) |
|
427 | - ->method('sendCloudShare'); |
|
428 | - $this->sharingMapper->expects(self::never()) |
|
429 | - ->method('deleteShare'); |
|
430 | - $this->sharingMapper->expects(self::never()) |
|
431 | - ->method('shareWithToken'); |
|
432 | - |
|
433 | - $this->federationSharingService->shareWith( |
|
434 | - $shareable, |
|
435 | - 'principals/remote-users/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl', |
|
436 | - 3, // Read-only |
|
437 | - ); |
|
438 | - } |
|
439 | - |
|
440 | - public function testShareWithWithInvalidShareable(): void { |
|
441 | - $shareable = $this->createMock(IShareable::class); |
|
442 | - $shareable->method('getOwner') |
|
443 | - ->willReturn('principals/users/host1'); |
|
444 | - |
|
445 | - $this->userManager->expects(self::once()) |
|
446 | - ->method('get') |
|
447 | - ->with('host1') |
|
448 | - ->willReturn(null); |
|
449 | - |
|
450 | - $this->federationManager->expects(self::never()) |
|
451 | - ->method('sendCloudShare'); |
|
452 | - $this->sharingMapper->expects(self::never()) |
|
453 | - ->method('deleteShare'); |
|
454 | - $this->sharingMapper->expects(self::never()) |
|
455 | - ->method('shareWithToken'); |
|
456 | - |
|
457 | - $this->federationSharingService->shareWith( |
|
458 | - $shareable, |
|
459 | - 'principals/remote-users/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl', |
|
460 | - 3, // Read-only |
|
461 | - ); |
|
462 | - } |
|
32 | + private FederationSharingService $federationSharingService; |
|
33 | + |
|
34 | + private readonly ICloudFederationProviderManager&MockObject $federationManager; |
|
35 | + private readonly ICloudFederationFactory&MockObject $federationFactory; |
|
36 | + private readonly IUserManager&MockObject $userManager; |
|
37 | + private readonly IURLGenerator&MockObject $url; |
|
38 | + private readonly LoggerInterface&MockObject $logger; |
|
39 | + private readonly ISecureRandom&MockObject $random; |
|
40 | + private readonly SharingMapper&MockObject $sharingMapper; |
|
41 | + |
|
42 | + protected function setUp(): void { |
|
43 | + parent::setUp(); |
|
44 | + |
|
45 | + $this->federationManager = $this->createMock(ICloudFederationProviderManager::class); |
|
46 | + $this->federationFactory = $this->createMock(ICloudFederationFactory::class); |
|
47 | + $this->userManager = $this->createMock(IUserManager::class); |
|
48 | + $this->url = $this->createMock(IURLGenerator::class); |
|
49 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
50 | + $this->random = $this->createMock(ISecureRandom::class); |
|
51 | + $this->sharingMapper = $this->createMock(SharingMapper::class); |
|
52 | + |
|
53 | + $this->federationSharingService = new FederationSharingService( |
|
54 | + $this->federationManager, |
|
55 | + $this->federationFactory, |
|
56 | + $this->userManager, |
|
57 | + $this->url, |
|
58 | + $this->logger, |
|
59 | + $this->random, |
|
60 | + $this->sharingMapper, |
|
61 | + ); |
|
62 | + } |
|
63 | + |
|
64 | + public function testShareWith(): void { |
|
65 | + $shareable = $this->createMock(Calendar::class); |
|
66 | + $shareable->method('getOwner') |
|
67 | + ->willReturn('principals/users/host1'); |
|
68 | + $shareable->method('getName') |
|
69 | + ->willReturn('cal1'); |
|
70 | + $shareable->method('getResourceId') |
|
71 | + ->willReturn(10); |
|
72 | + $shareable->method('getProperties') |
|
73 | + ->willReturnCallback(static fn (array $props) => match ($props[0]) { |
|
74 | + '{DAV:}displayname' => ['{DAV:}displayname' => 'Calendar 1'], |
|
75 | + '{http://apple.com/ns/ical/}calendar-color' => [ |
|
76 | + '{http://apple.com/ns/ical/}calendar-color' => '#ff0000', |
|
77 | + ], |
|
78 | + '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => [ |
|
79 | + '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new SupportedCalendarComponentSet([ |
|
80 | + 'VEVENT', |
|
81 | + 'VTODO', |
|
82 | + ]), |
|
83 | + ] |
|
84 | + }); |
|
85 | + |
|
86 | + $hostUser = $this->createMock(IUser::class); |
|
87 | + $hostUser->method('getCloudId') |
|
88 | + ->willReturn('[email protected]'); |
|
89 | + $hostUser->method('getDisplayName') |
|
90 | + ->willReturn('Host 1'); |
|
91 | + $hostUser->method('getUID') |
|
92 | + ->willReturn('host1'); |
|
93 | + $this->userManager->expects(self::once()) |
|
94 | + ->method('get') |
|
95 | + ->with('host1') |
|
96 | + ->willReturn($hostUser); |
|
97 | + |
|
98 | + $this->random->expects(self::once()) |
|
99 | + ->method('generate') |
|
100 | + ->with(32) |
|
101 | + ->willReturn('token'); |
|
102 | + |
|
103 | + $share = $this->createMock(ICloudFederationShare::class); |
|
104 | + $share->expects(self::once()) |
|
105 | + ->method('getProtocol') |
|
106 | + ->willReturn([ |
|
107 | + 'preservedValue1' => 'foobar', |
|
108 | + 'preservedValue2' => 'baz', |
|
109 | + ]); |
|
110 | + $share->expects(self::once()) |
|
111 | + ->method('setProtocol') |
|
112 | + ->with([ |
|
113 | + 'preservedValue1' => 'foobar', |
|
114 | + 'preservedValue2' => 'baz', |
|
115 | + 'version' => 'v1', |
|
116 | + 'url' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
117 | + 'displayName' => 'Calendar 1', |
|
118 | + 'color' => '#ff0000', |
|
119 | + 'access' => 3, |
|
120 | + 'components' => 'VEVENT,VTODO', |
|
121 | + ]); |
|
122 | + $this->federationFactory->expects(self::once()) |
|
123 | + ->method('getCloudFederationShare') |
|
124 | + ->with( |
|
125 | + '[email protected]', |
|
126 | + 'cal1', |
|
127 | + 'Calendar 1', |
|
128 | + 'calendar', |
|
129 | + '[email protected]', |
|
130 | + 'Host 1', |
|
131 | + '[email protected]', |
|
132 | + 'Host 1', |
|
133 | + 'token', |
|
134 | + 'user', |
|
135 | + 'calendar', |
|
136 | + ) |
|
137 | + ->willReturn($share); |
|
138 | + |
|
139 | + $this->url->expects(self::once()) |
|
140 | + ->method('linkTo') |
|
141 | + ->with('', 'remote.php') |
|
142 | + ->willReturn('/remote.php'); |
|
143 | + $this->url->expects(self::once()) |
|
144 | + ->method('getAbsoluteURL') |
|
145 | + ->with('/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1') |
|
146 | + ->willReturn('https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1'); |
|
147 | + |
|
148 | + $response = $this->createMock(IResponse::class); |
|
149 | + $response->method('getStatusCode') |
|
150 | + ->willReturn(201); |
|
151 | + $this->federationManager->expects(self::once()) |
|
152 | + ->method('sendCloudShare') |
|
153 | + ->with($share) |
|
154 | + ->willReturn($response); |
|
155 | + |
|
156 | + $this->sharingMapper->expects(self::once()) |
|
157 | + ->method('deleteShare') |
|
158 | + ->with(10, 'calendar', 'principals/remote-users/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl'); |
|
159 | + $this->sharingMapper->expects(self::once()) |
|
160 | + ->method('shareWithToken') |
|
161 | + ->with( |
|
162 | + 10, |
|
163 | + 'calendar', |
|
164 | + 3, |
|
165 | + 'principals/remote-users/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl', |
|
166 | + 'token', |
|
167 | + ); |
|
168 | + |
|
169 | + $this->federationSharingService->shareWith( |
|
170 | + $shareable, |
|
171 | + 'principals/remote-users/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl', |
|
172 | + 3, // Read-only |
|
173 | + ); |
|
174 | + } |
|
175 | + |
|
176 | + public function testShareWithWithFailingFederationManager(): void { |
|
177 | + $shareable = $this->createMock(Calendar::class); |
|
178 | + $shareable->method('getOwner') |
|
179 | + ->willReturn('principals/users/host1'); |
|
180 | + $shareable->method('getName') |
|
181 | + ->willReturn('cal1'); |
|
182 | + $shareable->method('getResourceId') |
|
183 | + ->willReturn(10); |
|
184 | + $shareable->method('getProperties') |
|
185 | + ->willReturnCallback(static fn (array $props) => match ($props[0]) { |
|
186 | + '{DAV:}displayname' => ['{DAV:}displayname' => 'Calendar 1'], |
|
187 | + '{http://apple.com/ns/ical/}calendar-color' => [ |
|
188 | + '{http://apple.com/ns/ical/}calendar-color' => '#ff0000', |
|
189 | + ], |
|
190 | + '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => [ |
|
191 | + '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new SupportedCalendarComponentSet([ |
|
192 | + 'VEVENT', |
|
193 | + 'VTODO', |
|
194 | + ]), |
|
195 | + ] |
|
196 | + }); |
|
197 | + |
|
198 | + $hostUser = $this->createMock(IUser::class); |
|
199 | + $hostUser->method('getCloudId') |
|
200 | + ->willReturn('[email protected]'); |
|
201 | + $hostUser->method('getDisplayName') |
|
202 | + ->willReturn('Host 1'); |
|
203 | + $hostUser->method('getUID') |
|
204 | + ->willReturn('host1'); |
|
205 | + $this->userManager->expects(self::once()) |
|
206 | + ->method('get') |
|
207 | + ->with('host1') |
|
208 | + ->willReturn($hostUser); |
|
209 | + |
|
210 | + $this->random->expects(self::once()) |
|
211 | + ->method('generate') |
|
212 | + ->with(32) |
|
213 | + ->willReturn('token'); |
|
214 | + |
|
215 | + $share = $this->createMock(ICloudFederationShare::class); |
|
216 | + $share->expects(self::once()) |
|
217 | + ->method('getProtocol') |
|
218 | + ->willReturn([ |
|
219 | + 'preservedValue1' => 'foobar', |
|
220 | + 'preservedValue2' => 'baz', |
|
221 | + ]); |
|
222 | + $share->expects(self::once()) |
|
223 | + ->method('setProtocol') |
|
224 | + ->with([ |
|
225 | + 'preservedValue1' => 'foobar', |
|
226 | + 'preservedValue2' => 'baz', |
|
227 | + 'version' => 'v1', |
|
228 | + 'url' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
229 | + 'displayName' => 'Calendar 1', |
|
230 | + 'color' => '#ff0000', |
|
231 | + 'access' => 3, |
|
232 | + 'components' => 'VEVENT,VTODO', |
|
233 | + ]); |
|
234 | + $this->federationFactory->expects(self::once()) |
|
235 | + ->method('getCloudFederationShare') |
|
236 | + ->with( |
|
237 | + '[email protected]', |
|
238 | + 'cal1', |
|
239 | + 'Calendar 1', |
|
240 | + 'calendar', |
|
241 | + '[email protected]', |
|
242 | + 'Host 1', |
|
243 | + '[email protected]', |
|
244 | + 'Host 1', |
|
245 | + 'token', |
|
246 | + 'user', |
|
247 | + 'calendar', |
|
248 | + ) |
|
249 | + ->willReturn($share); |
|
250 | + |
|
251 | + $this->url->expects(self::once()) |
|
252 | + ->method('linkTo') |
|
253 | + ->with('', 'remote.php') |
|
254 | + ->willReturn('/remote.php'); |
|
255 | + $this->url->expects(self::once()) |
|
256 | + ->method('getAbsoluteURL') |
|
257 | + ->with('/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1') |
|
258 | + ->willReturn('https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1'); |
|
259 | + |
|
260 | + $response = $this->createMock(IResponse::class); |
|
261 | + $response->method('getStatusCode') |
|
262 | + ->willReturn(201); |
|
263 | + $this->federationManager->expects(self::once()) |
|
264 | + ->method('sendCloudShare') |
|
265 | + ->with($share) |
|
266 | + ->willThrowException(new OCMProviderException()); |
|
267 | + |
|
268 | + $this->sharingMapper->expects(self::never()) |
|
269 | + ->method('deleteShare'); |
|
270 | + $this->sharingMapper->expects(self::never()) |
|
271 | + ->method('shareWithToken'); |
|
272 | + |
|
273 | + $this->federationSharingService->shareWith( |
|
274 | + $shareable, |
|
275 | + 'principals/remote-users/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl', |
|
276 | + 3, // Read-only |
|
277 | + ); |
|
278 | + } |
|
279 | + |
|
280 | + public function testShareWithWithUnsuccessfulResponse(): void { |
|
281 | + $shareable = $this->createMock(Calendar::class); |
|
282 | + $shareable->method('getOwner') |
|
283 | + ->willReturn('principals/users/host1'); |
|
284 | + $shareable->method('getName') |
|
285 | + ->willReturn('cal1'); |
|
286 | + $shareable->method('getResourceId') |
|
287 | + ->willReturn(10); |
|
288 | + $shareable->method('getProperties') |
|
289 | + ->willReturnCallback(static fn (array $props) => match ($props[0]) { |
|
290 | + '{DAV:}displayname' => ['{DAV:}displayname' => 'Calendar 1'], |
|
291 | + '{http://apple.com/ns/ical/}calendar-color' => [ |
|
292 | + '{http://apple.com/ns/ical/}calendar-color' => '#ff0000', |
|
293 | + ], |
|
294 | + '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => [ |
|
295 | + '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new SupportedCalendarComponentSet([ |
|
296 | + 'VEVENT', |
|
297 | + 'VTODO', |
|
298 | + ]), |
|
299 | + ] |
|
300 | + }); |
|
301 | + |
|
302 | + $hostUser = $this->createMock(IUser::class); |
|
303 | + $hostUser->method('getCloudId') |
|
304 | + ->willReturn('[email protected]'); |
|
305 | + $hostUser->method('getDisplayName') |
|
306 | + ->willReturn('Host 1'); |
|
307 | + $hostUser->method('getUID') |
|
308 | + ->willReturn('host1'); |
|
309 | + $this->userManager->expects(self::once()) |
|
310 | + ->method('get') |
|
311 | + ->with('host1') |
|
312 | + ->willReturn($hostUser); |
|
313 | + |
|
314 | + $this->random->expects(self::once()) |
|
315 | + ->method('generate') |
|
316 | + ->with(32) |
|
317 | + ->willReturn('token'); |
|
318 | + |
|
319 | + $share = $this->createMock(ICloudFederationShare::class); |
|
320 | + $share->expects(self::once()) |
|
321 | + ->method('getProtocol') |
|
322 | + ->willReturn([ |
|
323 | + 'preservedValue1' => 'foobar', |
|
324 | + 'preservedValue2' => 'baz', |
|
325 | + ]); |
|
326 | + $share->expects(self::once()) |
|
327 | + ->method('setProtocol') |
|
328 | + ->with([ |
|
329 | + 'preservedValue1' => 'foobar', |
|
330 | + 'preservedValue2' => 'baz', |
|
331 | + 'version' => 'v1', |
|
332 | + 'url' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
333 | + 'displayName' => 'Calendar 1', |
|
334 | + 'color' => '#ff0000', |
|
335 | + 'access' => 3, |
|
336 | + 'components' => 'VEVENT,VTODO', |
|
337 | + ]); |
|
338 | + $this->federationFactory->expects(self::once()) |
|
339 | + ->method('getCloudFederationShare') |
|
340 | + ->with( |
|
341 | + '[email protected]', |
|
342 | + 'cal1', |
|
343 | + 'Calendar 1', |
|
344 | + 'calendar', |
|
345 | + '[email protected]', |
|
346 | + 'Host 1', |
|
347 | + '[email protected]', |
|
348 | + 'Host 1', |
|
349 | + 'token', |
|
350 | + 'user', |
|
351 | + 'calendar', |
|
352 | + ) |
|
353 | + ->willReturn($share); |
|
354 | + |
|
355 | + $this->url->expects(self::once()) |
|
356 | + ->method('linkTo') |
|
357 | + ->with('', 'remote.php') |
|
358 | + ->willReturn('/remote.php'); |
|
359 | + $this->url->expects(self::once()) |
|
360 | + ->method('getAbsoluteURL') |
|
361 | + ->with('/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1') |
|
362 | + ->willReturn('https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1'); |
|
363 | + |
|
364 | + $response = $this->createMock(IResponse::class); |
|
365 | + $response->method('getStatusCode') |
|
366 | + ->willReturn(400); |
|
367 | + $this->federationManager->expects(self::once()) |
|
368 | + ->method('sendCloudShare') |
|
369 | + ->with($share) |
|
370 | + ->willReturn($response); |
|
371 | + |
|
372 | + $this->sharingMapper->expects(self::never()) |
|
373 | + ->method('deleteShare'); |
|
374 | + $this->sharingMapper->expects(self::never()) |
|
375 | + ->method('shareWithToken'); |
|
376 | + |
|
377 | + $this->federationSharingService->shareWith( |
|
378 | + $shareable, |
|
379 | + 'principals/remote-users/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl', |
|
380 | + 3, // Read-only |
|
381 | + ); |
|
382 | + } |
|
383 | + |
|
384 | + public static function provideInvalidRemoteUserPrincipalData(): array { |
|
385 | + return [ |
|
386 | + ['principals/users/foobar'], |
|
387 | + ['remote-users/remote1'], |
|
388 | + ['foobar/remote-users/remote1'], |
|
389 | + ['principals/remote-groups/group1'], |
|
390 | + ]; |
|
391 | + } |
|
392 | + |
|
393 | + #[DataProvider('provideInvalidRemoteUserPrincipalData')] |
|
394 | + public function testShareWithWithInvalidRemoteUserPrincipal(string $remoteUserPrincipal): void { |
|
395 | + $shareable = $this->createMock(Calendar::class); |
|
396 | + $shareable->method('getOwner') |
|
397 | + ->willReturn('principals/users/host1'); |
|
398 | + |
|
399 | + $this->userManager->expects(self::never()) |
|
400 | + ->method('get'); |
|
401 | + |
|
402 | + $this->federationManager->expects(self::never()) |
|
403 | + ->method('sendCloudShare'); |
|
404 | + $this->sharingMapper->expects(self::never()) |
|
405 | + ->method('deleteShare'); |
|
406 | + $this->sharingMapper->expects(self::never()) |
|
407 | + ->method('shareWithToken'); |
|
408 | + |
|
409 | + $this->federationSharingService->shareWith( |
|
410 | + $shareable, |
|
411 | + $remoteUserPrincipal, |
|
412 | + 3, // Read-only |
|
413 | + ); |
|
414 | + } |
|
415 | + |
|
416 | + public function testShareWithWithUnknownUser(): void { |
|
417 | + $shareable = $this->createMock(Calendar::class); |
|
418 | + $shareable->method('getOwner') |
|
419 | + ->willReturn('principals/users/host1'); |
|
420 | + |
|
421 | + $this->userManager->expects(self::once()) |
|
422 | + ->method('get') |
|
423 | + ->with('host1') |
|
424 | + ->willReturn(null); |
|
425 | + |
|
426 | + $this->federationManager->expects(self::never()) |
|
427 | + ->method('sendCloudShare'); |
|
428 | + $this->sharingMapper->expects(self::never()) |
|
429 | + ->method('deleteShare'); |
|
430 | + $this->sharingMapper->expects(self::never()) |
|
431 | + ->method('shareWithToken'); |
|
432 | + |
|
433 | + $this->federationSharingService->shareWith( |
|
434 | + $shareable, |
|
435 | + 'principals/remote-users/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl', |
|
436 | + 3, // Read-only |
|
437 | + ); |
|
438 | + } |
|
439 | + |
|
440 | + public function testShareWithWithInvalidShareable(): void { |
|
441 | + $shareable = $this->createMock(IShareable::class); |
|
442 | + $shareable->method('getOwner') |
|
443 | + ->willReturn('principals/users/host1'); |
|
444 | + |
|
445 | + $this->userManager->expects(self::once()) |
|
446 | + ->method('get') |
|
447 | + ->with('host1') |
|
448 | + ->willReturn(null); |
|
449 | + |
|
450 | + $this->federationManager->expects(self::never()) |
|
451 | + ->method('sendCloudShare'); |
|
452 | + $this->sharingMapper->expects(self::never()) |
|
453 | + ->method('deleteShare'); |
|
454 | + $this->sharingMapper->expects(self::never()) |
|
455 | + ->method('shareWithToken'); |
|
456 | + |
|
457 | + $this->federationSharingService->shareWith( |
|
458 | + $shareable, |
|
459 | + 'principals/remote-users/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl', |
|
460 | + 3, // Read-only |
|
461 | + ); |
|
462 | + } |
|
463 | 463 | } |
@@ -15,34 +15,34 @@ |
||
15 | 15 | use Test\TestCase; |
16 | 16 | |
17 | 17 | class FederatedCalendarImplTest extends TestCase { |
18 | - private FederatedCalendarImpl $federatedCalendarImpl; |
|
18 | + private FederatedCalendarImpl $federatedCalendarImpl; |
|
19 | 19 | |
20 | - private CalDavBackend&MockObject $calDavBackend; |
|
20 | + private CalDavBackend&MockObject $calDavBackend; |
|
21 | 21 | |
22 | - protected function setUp(): void { |
|
23 | - parent::setUp(); |
|
22 | + protected function setUp(): void { |
|
23 | + parent::setUp(); |
|
24 | 24 | |
25 | - $this->calDavBackend = $this->createMock(CalDavBackend::class); |
|
25 | + $this->calDavBackend = $this->createMock(CalDavBackend::class); |
|
26 | 26 | |
27 | - $this->federatedCalendarImpl = new FederatedCalendarImpl( |
|
28 | - [], |
|
29 | - $this->calDavBackend, |
|
30 | - ); |
|
31 | - } |
|
27 | + $this->federatedCalendarImpl = new FederatedCalendarImpl( |
|
28 | + [], |
|
29 | + $this->calDavBackend, |
|
30 | + ); |
|
31 | + } |
|
32 | 32 | |
33 | - public function testGetPermissions(): void { |
|
34 | - $this->assertEquals(1, $this->federatedCalendarImpl->getPermissions()); |
|
35 | - } |
|
33 | + public function testGetPermissions(): void { |
|
34 | + $this->assertEquals(1, $this->federatedCalendarImpl->getPermissions()); |
|
35 | + } |
|
36 | 36 | |
37 | - public function testIsDeleted(): void { |
|
38 | - $this->assertFalse($this->federatedCalendarImpl->isDeleted()); |
|
39 | - } |
|
37 | + public function testIsDeleted(): void { |
|
38 | + $this->assertFalse($this->federatedCalendarImpl->isDeleted()); |
|
39 | + } |
|
40 | 40 | |
41 | - public function testIsShared(): void { |
|
42 | - $this->assertTrue($this->federatedCalendarImpl->isShared()); |
|
43 | - } |
|
41 | + public function testIsShared(): void { |
|
42 | + $this->assertTrue($this->federatedCalendarImpl->isShared()); |
|
43 | + } |
|
44 | 44 | |
45 | - public function testIsWritable(): void { |
|
46 | - $this->assertFalse($this->federatedCalendarImpl->isWritable()); |
|
47 | - } |
|
45 | + public function testIsWritable(): void { |
|
46 | + $this->assertFalse($this->federatedCalendarImpl->isWritable()); |
|
47 | + } |
|
48 | 48 | } |
@@ -21,108 +21,108 @@ |
||
21 | 21 | use Test\TestCase; |
22 | 22 | |
23 | 23 | class CalendarFederationNotifierTest extends TestCase { |
24 | - private readonly CalendarFederationNotifier $calendarFederationNotifier; |
|
25 | - |
|
26 | - private readonly ICloudFederationFactory&MockObject $federationFactory; |
|
27 | - private readonly ICloudFederationProviderManager&MockObject $federationManager; |
|
28 | - private readonly IURLGenerator&MockObject $url; |
|
29 | - |
|
30 | - protected function setUp(): void { |
|
31 | - parent::setUp(); |
|
32 | - |
|
33 | - $this->federationFactory = $this->createMock(ICloudFederationFactory::class); |
|
34 | - $this->federationManager = $this->createMock(ICloudFederationProviderManager::class); |
|
35 | - $this->url = $this->createMock(IURLGenerator::class); |
|
36 | - |
|
37 | - $this->calendarFederationNotifier = new CalendarFederationNotifier( |
|
38 | - $this->federationFactory, |
|
39 | - $this->federationManager, |
|
40 | - $this->url, |
|
41 | - ); |
|
42 | - } |
|
43 | - |
|
44 | - public function testNotifySyncCalendar(): void { |
|
45 | - $cloudId = $this->createMock(ICloudId::class); |
|
46 | - $cloudId->method('getId') |
|
47 | - ->willReturn('[email protected]'); |
|
48 | - $cloudId->method('getRemote') |
|
49 | - ->willReturn('nextcloud.remote'); |
|
50 | - |
|
51 | - $this->url->expects(self::once()) |
|
52 | - ->method('linkTo') |
|
53 | - ->with('', 'remote.php') |
|
54 | - ->willReturn('/remote.php'); |
|
55 | - $this->url->expects(self::once()) |
|
56 | - ->method('getAbsoluteURL') |
|
57 | - ->with('/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1') |
|
58 | - ->willReturn('https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1'); |
|
59 | - |
|
60 | - $notification = $this->createMock(ICloudFederationNotification::class); |
|
61 | - $notification->expects(self::once()) |
|
62 | - ->method('setMessage') |
|
63 | - ->with( |
|
64 | - 'SYNC_CALENDAR', |
|
65 | - 'calendar', |
|
66 | - 'calendar', |
|
67 | - [ |
|
68 | - 'sharedSecret' => 'token', |
|
69 | - 'shareWith' => '[email protected]', |
|
70 | - 'calendarUrl' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
71 | - ], |
|
72 | - ); |
|
73 | - $this->federationFactory->expects(self::once()) |
|
74 | - ->method('getCloudFederationNotification') |
|
75 | - ->willReturn($notification); |
|
76 | - |
|
77 | - $response = $this->createMock(IResponse::class); |
|
78 | - $this->federationManager->expects(self::once()) |
|
79 | - ->method('sendCloudNotification') |
|
80 | - ->with('nextcloud.remote', $notification) |
|
81 | - ->willReturn($response); |
|
82 | - |
|
83 | - $this->calendarFederationNotifier->notifySyncCalendar($cloudId, 'host1', 'cal1', 'token'); |
|
84 | - } |
|
85 | - |
|
86 | - public function testNotifySyncCalendarShouldRethrowOcmException(): void { |
|
87 | - $cloudId = $this->createMock(ICloudId::class); |
|
88 | - $cloudId->method('getId') |
|
89 | - ->willReturn('[email protected]'); |
|
90 | - $cloudId->method('getRemote') |
|
91 | - ->willReturn('nextcloud.remote'); |
|
92 | - |
|
93 | - $this->url->expects(self::once()) |
|
94 | - ->method('linkTo') |
|
95 | - ->with('', 'remote.php') |
|
96 | - ->willReturn('/remote.php'); |
|
97 | - $this->url->expects(self::once()) |
|
98 | - ->method('getAbsoluteURL') |
|
99 | - ->with('/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1') |
|
100 | - ->willReturn('https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1'); |
|
101 | - |
|
102 | - $notification = $this->createMock(ICloudFederationNotification::class); |
|
103 | - $notification->expects(self::once()) |
|
104 | - ->method('setMessage') |
|
105 | - ->with( |
|
106 | - 'SYNC_CALENDAR', |
|
107 | - 'calendar', |
|
108 | - 'calendar', |
|
109 | - [ |
|
110 | - 'sharedSecret' => 'token', |
|
111 | - 'shareWith' => '[email protected]', |
|
112 | - 'calendarUrl' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
113 | - ], |
|
114 | - ); |
|
115 | - $this->federationFactory->expects(self::once()) |
|
116 | - ->method('getCloudFederationNotification') |
|
117 | - ->willReturn($notification); |
|
118 | - |
|
119 | - $this->federationManager->expects(self::once()) |
|
120 | - ->method('sendCloudNotification') |
|
121 | - ->with('nextcloud.remote', $notification) |
|
122 | - ->willThrowException(new OCMProviderException('I threw this')); |
|
123 | - |
|
124 | - $this->expectException(OCMProviderException::class); |
|
125 | - $this->expectExceptionMessage('I threw this'); |
|
126 | - $this->calendarFederationNotifier->notifySyncCalendar($cloudId, 'host1', 'cal1', 'token'); |
|
127 | - } |
|
24 | + private readonly CalendarFederationNotifier $calendarFederationNotifier; |
|
25 | + |
|
26 | + private readonly ICloudFederationFactory&MockObject $federationFactory; |
|
27 | + private readonly ICloudFederationProviderManager&MockObject $federationManager; |
|
28 | + private readonly IURLGenerator&MockObject $url; |
|
29 | + |
|
30 | + protected function setUp(): void { |
|
31 | + parent::setUp(); |
|
32 | + |
|
33 | + $this->federationFactory = $this->createMock(ICloudFederationFactory::class); |
|
34 | + $this->federationManager = $this->createMock(ICloudFederationProviderManager::class); |
|
35 | + $this->url = $this->createMock(IURLGenerator::class); |
|
36 | + |
|
37 | + $this->calendarFederationNotifier = new CalendarFederationNotifier( |
|
38 | + $this->federationFactory, |
|
39 | + $this->federationManager, |
|
40 | + $this->url, |
|
41 | + ); |
|
42 | + } |
|
43 | + |
|
44 | + public function testNotifySyncCalendar(): void { |
|
45 | + $cloudId = $this->createMock(ICloudId::class); |
|
46 | + $cloudId->method('getId') |
|
47 | + ->willReturn('[email protected]'); |
|
48 | + $cloudId->method('getRemote') |
|
49 | + ->willReturn('nextcloud.remote'); |
|
50 | + |
|
51 | + $this->url->expects(self::once()) |
|
52 | + ->method('linkTo') |
|
53 | + ->with('', 'remote.php') |
|
54 | + ->willReturn('/remote.php'); |
|
55 | + $this->url->expects(self::once()) |
|
56 | + ->method('getAbsoluteURL') |
|
57 | + ->with('/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1') |
|
58 | + ->willReturn('https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1'); |
|
59 | + |
|
60 | + $notification = $this->createMock(ICloudFederationNotification::class); |
|
61 | + $notification->expects(self::once()) |
|
62 | + ->method('setMessage') |
|
63 | + ->with( |
|
64 | + 'SYNC_CALENDAR', |
|
65 | + 'calendar', |
|
66 | + 'calendar', |
|
67 | + [ |
|
68 | + 'sharedSecret' => 'token', |
|
69 | + 'shareWith' => '[email protected]', |
|
70 | + 'calendarUrl' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
71 | + ], |
|
72 | + ); |
|
73 | + $this->federationFactory->expects(self::once()) |
|
74 | + ->method('getCloudFederationNotification') |
|
75 | + ->willReturn($notification); |
|
76 | + |
|
77 | + $response = $this->createMock(IResponse::class); |
|
78 | + $this->federationManager->expects(self::once()) |
|
79 | + ->method('sendCloudNotification') |
|
80 | + ->with('nextcloud.remote', $notification) |
|
81 | + ->willReturn($response); |
|
82 | + |
|
83 | + $this->calendarFederationNotifier->notifySyncCalendar($cloudId, 'host1', 'cal1', 'token'); |
|
84 | + } |
|
85 | + |
|
86 | + public function testNotifySyncCalendarShouldRethrowOcmException(): void { |
|
87 | + $cloudId = $this->createMock(ICloudId::class); |
|
88 | + $cloudId->method('getId') |
|
89 | + ->willReturn('[email protected]'); |
|
90 | + $cloudId->method('getRemote') |
|
91 | + ->willReturn('nextcloud.remote'); |
|
92 | + |
|
93 | + $this->url->expects(self::once()) |
|
94 | + ->method('linkTo') |
|
95 | + ->with('', 'remote.php') |
|
96 | + ->willReturn('/remote.php'); |
|
97 | + $this->url->expects(self::once()) |
|
98 | + ->method('getAbsoluteURL') |
|
99 | + ->with('/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1') |
|
100 | + ->willReturn('https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1'); |
|
101 | + |
|
102 | + $notification = $this->createMock(ICloudFederationNotification::class); |
|
103 | + $notification->expects(self::once()) |
|
104 | + ->method('setMessage') |
|
105 | + ->with( |
|
106 | + 'SYNC_CALENDAR', |
|
107 | + 'calendar', |
|
108 | + 'calendar', |
|
109 | + [ |
|
110 | + 'sharedSecret' => 'token', |
|
111 | + 'shareWith' => '[email protected]', |
|
112 | + 'calendarUrl' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', |
|
113 | + ], |
|
114 | + ); |
|
115 | + $this->federationFactory->expects(self::once()) |
|
116 | + ->method('getCloudFederationNotification') |
|
117 | + ->willReturn($notification); |
|
118 | + |
|
119 | + $this->federationManager->expects(self::once()) |
|
120 | + ->method('sendCloudNotification') |
|
121 | + ->with('nextcloud.remote', $notification) |
|
122 | + ->willThrowException(new OCMProviderException('I threw this')); |
|
123 | + |
|
124 | + $this->expectException(OCMProviderException::class); |
|
125 | + $this->expectExceptionMessage('I threw this'); |
|
126 | + $this->calendarFederationNotifier->notifySyncCalendar($cloudId, 'host1', 'cal1', 'token'); |
|
127 | + } |
|
128 | 128 | } |
@@ -22,143 +22,143 @@ |
||
22 | 22 | use Test\TestCase; |
23 | 23 | |
24 | 24 | class FederatedCalendarSyncServiceTest extends TestCase { |
25 | - private FederatedCalendarSyncService $federatedCalendarSyncService; |
|
26 | - |
|
27 | - private FederatedCalendarMapper&MockObject $federatedCalendarMapper; |
|
28 | - private LoggerInterface&MockObject $logger; |
|
29 | - private CalDavSyncService&MockObject $calDavSyncService; |
|
30 | - private ICloudIdManager&MockObject $cloudIdManager; |
|
31 | - |
|
32 | - protected function setUp(): void { |
|
33 | - parent::setUp(); |
|
34 | - |
|
35 | - $this->federatedCalendarMapper = $this->createMock(FederatedCalendarMapper::class); |
|
36 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
37 | - $this->calDavSyncService = $this->createMock(CalDavSyncService::class); |
|
38 | - $this->cloudIdManager = $this->createMock(ICloudIdManager::class); |
|
39 | - |
|
40 | - $this->federatedCalendarSyncService = new FederatedCalendarSyncService( |
|
41 | - $this->federatedCalendarMapper, |
|
42 | - $this->logger, |
|
43 | - $this->calDavSyncService, |
|
44 | - $this->cloudIdManager, |
|
45 | - ); |
|
46 | - } |
|
47 | - |
|
48 | - public function testSyncOne(): void { |
|
49 | - $calendar = new FederatedCalendarEntity(); |
|
50 | - $calendar->setId(1); |
|
51 | - $calendar->setPrincipaluri('principals/users/user1'); |
|
52 | - $calendar->setRemoteUrl('https://remote.tld/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user2'); |
|
53 | - $calendar->setSyncToken(100); |
|
54 | - $calendar->setToken('token'); |
|
55 | - |
|
56 | - $cloudId = $this->createMock(ICloudId::class); |
|
57 | - $cloudId->method('getId') |
|
58 | - ->willReturn('[email protected]'); |
|
59 | - $this->cloudIdManager->expects(self::once()) |
|
60 | - ->method('getCloudId') |
|
61 | - ->with('user1') |
|
62 | - ->willReturn($cloudId); |
|
63 | - |
|
64 | - $this->calDavSyncService->expects(self::once()) |
|
65 | - ->method('syncRemoteCalendar') |
|
66 | - ->with( |
|
67 | - 'https://remote.tld/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user2', |
|
68 | - 'dXNlcjFAbmV4dGNsb3VkLnRlc3Rpbmc=', |
|
69 | - 'token', |
|
70 | - 'http://sabre.io/ns/sync/100', |
|
71 | - $calendar, |
|
72 | - ) |
|
73 | - ->willReturn(new SyncServiceResult('http://sabre.io/ns/sync/101', 10)); |
|
74 | - |
|
75 | - $this->federatedCalendarMapper->expects(self::once()) |
|
76 | - ->method('updateSyncTokenAndTime') |
|
77 | - ->with(1, 101); |
|
78 | - $this->federatedCalendarMapper->expects(self::never()) |
|
79 | - ->method('updateSyncTime'); |
|
80 | - |
|
81 | - $this->assertEquals(10, $this->federatedCalendarSyncService->syncOne($calendar)); |
|
82 | - } |
|
83 | - |
|
84 | - public function testSyncOneUnchanged(): void { |
|
85 | - $calendar = new FederatedCalendarEntity(); |
|
86 | - $calendar->setId(1); |
|
87 | - $calendar->setPrincipaluri('principals/users/user1'); |
|
88 | - $calendar->setRemoteUrl('https://remote.tld/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user2'); |
|
89 | - $calendar->setSyncToken(100); |
|
90 | - $calendar->setToken('token'); |
|
91 | - |
|
92 | - $cloudId = $this->createMock(ICloudId::class); |
|
93 | - $cloudId->method('getId') |
|
94 | - ->willReturn('[email protected]'); |
|
95 | - $this->cloudIdManager->expects(self::once()) |
|
96 | - ->method('getCloudId') |
|
97 | - ->with('user1') |
|
98 | - ->willReturn($cloudId); |
|
99 | - |
|
100 | - $this->calDavSyncService->expects(self::once()) |
|
101 | - ->method('syncRemoteCalendar') |
|
102 | - ->with( |
|
103 | - 'https://remote.tld/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user2', |
|
104 | - 'dXNlcjFAbmV4dGNsb3VkLnRlc3Rpbmc=', |
|
105 | - 'token', |
|
106 | - 'http://sabre.io/ns/sync/100', |
|
107 | - $calendar, |
|
108 | - ) |
|
109 | - ->willReturn(new SyncServiceResult('http://sabre.io/ns/sync/100', 0)); |
|
110 | - |
|
111 | - $this->federatedCalendarMapper->expects(self::never()) |
|
112 | - ->method('updateSyncTokenAndTime'); |
|
113 | - $this->federatedCalendarMapper->expects(self::once()) |
|
114 | - ->method('updateSyncTime') |
|
115 | - ->with(1); |
|
116 | - |
|
117 | - $this->assertEquals(0, $this->federatedCalendarSyncService->syncOne($calendar)); |
|
118 | - } |
|
119 | - |
|
120 | - public static function provideUnexpectedSyncTokenData(): array { |
|
121 | - return [ |
|
122 | - ['http://sabre.io/ns/sync/'], |
|
123 | - ['http://sabre.io/ns/sync/foobar'], |
|
124 | - ['http://sabre.io/ns/sync/23abc'], |
|
125 | - ['http://nextcloud.com/ns/sync/33'], |
|
126 | - ]; |
|
127 | - } |
|
128 | - |
|
129 | - #[DataProvider('provideUnexpectedSyncTokenData')] |
|
130 | - public function testSyncOneWithUnexpectedSyncTokenFormat(string $syncToken): void { |
|
131 | - $calendar = new FederatedCalendarEntity(); |
|
132 | - $calendar->setId(1); |
|
133 | - $calendar->setPrincipaluri('principals/users/user1'); |
|
134 | - $calendar->setRemoteUrl('https://remote.tld/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user2'); |
|
135 | - $calendar->setSyncToken(100); |
|
136 | - $calendar->setToken('token'); |
|
137 | - |
|
138 | - $cloudId = $this->createMock(ICloudId::class); |
|
139 | - $cloudId->method('getId') |
|
140 | - ->willReturn('[email protected]'); |
|
141 | - $this->cloudIdManager->expects(self::once()) |
|
142 | - ->method('getCloudId') |
|
143 | - ->with('user1') |
|
144 | - ->willReturn($cloudId); |
|
145 | - |
|
146 | - $this->calDavSyncService->expects(self::once()) |
|
147 | - ->method('syncRemoteCalendar') |
|
148 | - ->with( |
|
149 | - 'https://remote.tld/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user2', |
|
150 | - 'dXNlcjFAbmV4dGNsb3VkLnRlc3Rpbmc=', |
|
151 | - 'token', |
|
152 | - 'http://sabre.io/ns/sync/100', |
|
153 | - $calendar, |
|
154 | - ) |
|
155 | - ->willReturn(new SyncServiceResult($syncToken, 10)); |
|
156 | - |
|
157 | - $this->federatedCalendarMapper->expects(self::never()) |
|
158 | - ->method('updateSyncTokenAndTime'); |
|
159 | - $this->federatedCalendarMapper->expects(self::never()) |
|
160 | - ->method('updateSyncTime'); |
|
161 | - |
|
162 | - $this->assertEquals(0, $this->federatedCalendarSyncService->syncOne($calendar)); |
|
163 | - } |
|
25 | + private FederatedCalendarSyncService $federatedCalendarSyncService; |
|
26 | + |
|
27 | + private FederatedCalendarMapper&MockObject $federatedCalendarMapper; |
|
28 | + private LoggerInterface&MockObject $logger; |
|
29 | + private CalDavSyncService&MockObject $calDavSyncService; |
|
30 | + private ICloudIdManager&MockObject $cloudIdManager; |
|
31 | + |
|
32 | + protected function setUp(): void { |
|
33 | + parent::setUp(); |
|
34 | + |
|
35 | + $this->federatedCalendarMapper = $this->createMock(FederatedCalendarMapper::class); |
|
36 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
37 | + $this->calDavSyncService = $this->createMock(CalDavSyncService::class); |
|
38 | + $this->cloudIdManager = $this->createMock(ICloudIdManager::class); |
|
39 | + |
|
40 | + $this->federatedCalendarSyncService = new FederatedCalendarSyncService( |
|
41 | + $this->federatedCalendarMapper, |
|
42 | + $this->logger, |
|
43 | + $this->calDavSyncService, |
|
44 | + $this->cloudIdManager, |
|
45 | + ); |
|
46 | + } |
|
47 | + |
|
48 | + public function testSyncOne(): void { |
|
49 | + $calendar = new FederatedCalendarEntity(); |
|
50 | + $calendar->setId(1); |
|
51 | + $calendar->setPrincipaluri('principals/users/user1'); |
|
52 | + $calendar->setRemoteUrl('https://remote.tld/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user2'); |
|
53 | + $calendar->setSyncToken(100); |
|
54 | + $calendar->setToken('token'); |
|
55 | + |
|
56 | + $cloudId = $this->createMock(ICloudId::class); |
|
57 | + $cloudId->method('getId') |
|
58 | + ->willReturn('[email protected]'); |
|
59 | + $this->cloudIdManager->expects(self::once()) |
|
60 | + ->method('getCloudId') |
|
61 | + ->with('user1') |
|
62 | + ->willReturn($cloudId); |
|
63 | + |
|
64 | + $this->calDavSyncService->expects(self::once()) |
|
65 | + ->method('syncRemoteCalendar') |
|
66 | + ->with( |
|
67 | + 'https://remote.tld/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user2', |
|
68 | + 'dXNlcjFAbmV4dGNsb3VkLnRlc3Rpbmc=', |
|
69 | + 'token', |
|
70 | + 'http://sabre.io/ns/sync/100', |
|
71 | + $calendar, |
|
72 | + ) |
|
73 | + ->willReturn(new SyncServiceResult('http://sabre.io/ns/sync/101', 10)); |
|
74 | + |
|
75 | + $this->federatedCalendarMapper->expects(self::once()) |
|
76 | + ->method('updateSyncTokenAndTime') |
|
77 | + ->with(1, 101); |
|
78 | + $this->federatedCalendarMapper->expects(self::never()) |
|
79 | + ->method('updateSyncTime'); |
|
80 | + |
|
81 | + $this->assertEquals(10, $this->federatedCalendarSyncService->syncOne($calendar)); |
|
82 | + } |
|
83 | + |
|
84 | + public function testSyncOneUnchanged(): void { |
|
85 | + $calendar = new FederatedCalendarEntity(); |
|
86 | + $calendar->setId(1); |
|
87 | + $calendar->setPrincipaluri('principals/users/user1'); |
|
88 | + $calendar->setRemoteUrl('https://remote.tld/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user2'); |
|
89 | + $calendar->setSyncToken(100); |
|
90 | + $calendar->setToken('token'); |
|
91 | + |
|
92 | + $cloudId = $this->createMock(ICloudId::class); |
|
93 | + $cloudId->method('getId') |
|
94 | + ->willReturn('[email protected]'); |
|
95 | + $this->cloudIdManager->expects(self::once()) |
|
96 | + ->method('getCloudId') |
|
97 | + ->with('user1') |
|
98 | + ->willReturn($cloudId); |
|
99 | + |
|
100 | + $this->calDavSyncService->expects(self::once()) |
|
101 | + ->method('syncRemoteCalendar') |
|
102 | + ->with( |
|
103 | + 'https://remote.tld/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user2', |
|
104 | + 'dXNlcjFAbmV4dGNsb3VkLnRlc3Rpbmc=', |
|
105 | + 'token', |
|
106 | + 'http://sabre.io/ns/sync/100', |
|
107 | + $calendar, |
|
108 | + ) |
|
109 | + ->willReturn(new SyncServiceResult('http://sabre.io/ns/sync/100', 0)); |
|
110 | + |
|
111 | + $this->federatedCalendarMapper->expects(self::never()) |
|
112 | + ->method('updateSyncTokenAndTime'); |
|
113 | + $this->federatedCalendarMapper->expects(self::once()) |
|
114 | + ->method('updateSyncTime') |
|
115 | + ->with(1); |
|
116 | + |
|
117 | + $this->assertEquals(0, $this->federatedCalendarSyncService->syncOne($calendar)); |
|
118 | + } |
|
119 | + |
|
120 | + public static function provideUnexpectedSyncTokenData(): array { |
|
121 | + return [ |
|
122 | + ['http://sabre.io/ns/sync/'], |
|
123 | + ['http://sabre.io/ns/sync/foobar'], |
|
124 | + ['http://sabre.io/ns/sync/23abc'], |
|
125 | + ['http://nextcloud.com/ns/sync/33'], |
|
126 | + ]; |
|
127 | + } |
|
128 | + |
|
129 | + #[DataProvider('provideUnexpectedSyncTokenData')] |
|
130 | + public function testSyncOneWithUnexpectedSyncTokenFormat(string $syncToken): void { |
|
131 | + $calendar = new FederatedCalendarEntity(); |
|
132 | + $calendar->setId(1); |
|
133 | + $calendar->setPrincipaluri('principals/users/user1'); |
|
134 | + $calendar->setRemoteUrl('https://remote.tld/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user2'); |
|
135 | + $calendar->setSyncToken(100); |
|
136 | + $calendar->setToken('token'); |
|
137 | + |
|
138 | + $cloudId = $this->createMock(ICloudId::class); |
|
139 | + $cloudId->method('getId') |
|
140 | + ->willReturn('[email protected]'); |
|
141 | + $this->cloudIdManager->expects(self::once()) |
|
142 | + ->method('getCloudId') |
|
143 | + ->with('user1') |
|
144 | + ->willReturn($cloudId); |
|
145 | + |
|
146 | + $this->calDavSyncService->expects(self::once()) |
|
147 | + ->method('syncRemoteCalendar') |
|
148 | + ->with( |
|
149 | + 'https://remote.tld/remote.php/dav/remote-calendars/abcdef123/cal1_shared_by_user2', |
|
150 | + 'dXNlcjFAbmV4dGNsb3VkLnRlc3Rpbmc=', |
|
151 | + 'token', |
|
152 | + 'http://sabre.io/ns/sync/100', |
|
153 | + $calendar, |
|
154 | + ) |
|
155 | + ->willReturn(new SyncServiceResult($syncToken, 10)); |
|
156 | + |
|
157 | + $this->federatedCalendarMapper->expects(self::never()) |
|
158 | + ->method('updateSyncTokenAndTime'); |
|
159 | + $this->federatedCalendarMapper->expects(self::never()) |
|
160 | + ->method('updateSyncTime'); |
|
161 | + |
|
162 | + $this->assertEquals(0, $this->federatedCalendarSyncService->syncOne($calendar)); |
|
163 | + } |
|
164 | 164 | } |