@@ -20,127 +20,127 @@ |
||
20 | 20 | use Test\TestCase; |
21 | 21 | |
22 | 22 | class SettingsControllerTest extends TestCase { |
23 | - private SettingsController $controller; |
|
24 | - |
|
25 | - private IRequest&MockObject $request; |
|
26 | - private IL10N&MockObject $l10n; |
|
27 | - private TrustedServers&MockObject $trustedServers; |
|
28 | - private LoggerInterface&MockObject $logger; |
|
29 | - |
|
30 | - protected function setUp(): void { |
|
31 | - parent::setUp(); |
|
32 | - |
|
33 | - $this->request = $this->createMock(IRequest::class); |
|
34 | - $this->l10n = $this->createMock(IL10N::class); |
|
35 | - $this->trustedServers = $this->createMock(TrustedServers::class); |
|
36 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
37 | - |
|
38 | - $this->controller = new SettingsController( |
|
39 | - 'SettingsControllerTest', |
|
40 | - $this->request, |
|
41 | - $this->l10n, |
|
42 | - $this->trustedServers, |
|
43 | - $this->logger, |
|
44 | - ); |
|
45 | - } |
|
46 | - |
|
47 | - public function testAddServer(): void { |
|
48 | - $this->trustedServers |
|
49 | - ->expects($this->once()) |
|
50 | - ->method('isTrustedServer') |
|
51 | - ->with('url') |
|
52 | - ->willReturn(false); |
|
53 | - $this->trustedServers |
|
54 | - ->expects($this->once()) |
|
55 | - ->method('isNextcloudServer') |
|
56 | - ->with('url') |
|
57 | - ->willReturn(true); |
|
58 | - |
|
59 | - $result = $this->controller->addServer('url'); |
|
60 | - $this->assertInstanceOf(DataResponse::class, $result); |
|
61 | - |
|
62 | - $data = $result->getData(); |
|
63 | - $this->assertSame(200, $result->getStatus()); |
|
64 | - $this->assertSame('url', $data['url']); |
|
65 | - $this->assertArrayHasKey('id', $data); |
|
66 | - } |
|
67 | - |
|
68 | - #[\PHPUnit\Framework\Attributes\DataProvider('checkServerFails')] |
|
69 | - public function testAddServerFail(bool $isTrustedServer, bool $isNextcloud): void { |
|
70 | - $this->trustedServers |
|
71 | - ->expects($this->any()) |
|
72 | - ->method('isTrustedServer') |
|
73 | - ->with('url') |
|
74 | - ->willReturn($isTrustedServer); |
|
75 | - $this->trustedServers |
|
76 | - ->expects($this->any()) |
|
77 | - ->method('isNextcloudServer') |
|
78 | - ->with('url') |
|
79 | - ->willReturn($isNextcloud); |
|
80 | - |
|
81 | - if ($isTrustedServer) { |
|
82 | - $this->expectException(OCSException::class); |
|
83 | - } else { |
|
84 | - $this->expectException(OCSNotFoundException::class); |
|
85 | - } |
|
86 | - |
|
87 | - $this->controller->addServer('url'); |
|
88 | - } |
|
89 | - |
|
90 | - public function testRemoveServer(): void { |
|
91 | - $this->trustedServers->expects($this->once()) |
|
92 | - ->method('removeServer') |
|
93 | - ->with(1); |
|
94 | - $result = $this->controller->removeServer(1); |
|
95 | - $this->assertTrue($result instanceof DataResponse); |
|
96 | - $this->assertSame(200, $result->getStatus()); |
|
97 | - } |
|
98 | - |
|
99 | - public function testCheckServer(): void { |
|
100 | - $this->trustedServers |
|
101 | - ->expects($this->once()) |
|
102 | - ->method('isTrustedServer') |
|
103 | - ->with('url') |
|
104 | - ->willReturn(false); |
|
105 | - $this->trustedServers |
|
106 | - ->expects($this->once()) |
|
107 | - ->method('isNextcloudServer') |
|
108 | - ->with('url') |
|
109 | - ->willReturn(true); |
|
110 | - |
|
111 | - $this->assertNull( |
|
112 | - self::invokePrivate($this->controller, 'checkServer', ['url']) |
|
113 | - ); |
|
114 | - } |
|
115 | - |
|
116 | - #[\PHPUnit\Framework\Attributes\DataProvider('checkServerFails')] |
|
117 | - public function testCheckServerFail(bool $isTrustedServer, bool $isNextcloud): void { |
|
118 | - $this->trustedServers |
|
119 | - ->expects($this->any()) |
|
120 | - ->method('isTrustedServer') |
|
121 | - ->with('url') |
|
122 | - ->willReturn($isTrustedServer); |
|
123 | - $this->trustedServers |
|
124 | - ->expects($this->any()) |
|
125 | - ->method('isNextcloudServer') |
|
126 | - ->with('url') |
|
127 | - ->willReturn($isNextcloud); |
|
128 | - |
|
129 | - if ($isTrustedServer) { |
|
130 | - $this->expectException(OCSException::class); |
|
131 | - } else { |
|
132 | - $this->expectException(OCSNotFoundException::class); |
|
133 | - } |
|
134 | - |
|
135 | - $this->assertTrue( |
|
136 | - self::invokePrivate($this->controller, 'checkServer', ['url']) |
|
137 | - ); |
|
138 | - } |
|
139 | - |
|
140 | - public static function checkServerFails(): array { |
|
141 | - return [ |
|
142 | - [true, true], |
|
143 | - [false, false] |
|
144 | - ]; |
|
145 | - } |
|
23 | + private SettingsController $controller; |
|
24 | + |
|
25 | + private IRequest&MockObject $request; |
|
26 | + private IL10N&MockObject $l10n; |
|
27 | + private TrustedServers&MockObject $trustedServers; |
|
28 | + private LoggerInterface&MockObject $logger; |
|
29 | + |
|
30 | + protected function setUp(): void { |
|
31 | + parent::setUp(); |
|
32 | + |
|
33 | + $this->request = $this->createMock(IRequest::class); |
|
34 | + $this->l10n = $this->createMock(IL10N::class); |
|
35 | + $this->trustedServers = $this->createMock(TrustedServers::class); |
|
36 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
37 | + |
|
38 | + $this->controller = new SettingsController( |
|
39 | + 'SettingsControllerTest', |
|
40 | + $this->request, |
|
41 | + $this->l10n, |
|
42 | + $this->trustedServers, |
|
43 | + $this->logger, |
|
44 | + ); |
|
45 | + } |
|
46 | + |
|
47 | + public function testAddServer(): void { |
|
48 | + $this->trustedServers |
|
49 | + ->expects($this->once()) |
|
50 | + ->method('isTrustedServer') |
|
51 | + ->with('url') |
|
52 | + ->willReturn(false); |
|
53 | + $this->trustedServers |
|
54 | + ->expects($this->once()) |
|
55 | + ->method('isNextcloudServer') |
|
56 | + ->with('url') |
|
57 | + ->willReturn(true); |
|
58 | + |
|
59 | + $result = $this->controller->addServer('url'); |
|
60 | + $this->assertInstanceOf(DataResponse::class, $result); |
|
61 | + |
|
62 | + $data = $result->getData(); |
|
63 | + $this->assertSame(200, $result->getStatus()); |
|
64 | + $this->assertSame('url', $data['url']); |
|
65 | + $this->assertArrayHasKey('id', $data); |
|
66 | + } |
|
67 | + |
|
68 | + #[\PHPUnit\Framework\Attributes\DataProvider('checkServerFails')] |
|
69 | + public function testAddServerFail(bool $isTrustedServer, bool $isNextcloud): void { |
|
70 | + $this->trustedServers |
|
71 | + ->expects($this->any()) |
|
72 | + ->method('isTrustedServer') |
|
73 | + ->with('url') |
|
74 | + ->willReturn($isTrustedServer); |
|
75 | + $this->trustedServers |
|
76 | + ->expects($this->any()) |
|
77 | + ->method('isNextcloudServer') |
|
78 | + ->with('url') |
|
79 | + ->willReturn($isNextcloud); |
|
80 | + |
|
81 | + if ($isTrustedServer) { |
|
82 | + $this->expectException(OCSException::class); |
|
83 | + } else { |
|
84 | + $this->expectException(OCSNotFoundException::class); |
|
85 | + } |
|
86 | + |
|
87 | + $this->controller->addServer('url'); |
|
88 | + } |
|
89 | + |
|
90 | + public function testRemoveServer(): void { |
|
91 | + $this->trustedServers->expects($this->once()) |
|
92 | + ->method('removeServer') |
|
93 | + ->with(1); |
|
94 | + $result = $this->controller->removeServer(1); |
|
95 | + $this->assertTrue($result instanceof DataResponse); |
|
96 | + $this->assertSame(200, $result->getStatus()); |
|
97 | + } |
|
98 | + |
|
99 | + public function testCheckServer(): void { |
|
100 | + $this->trustedServers |
|
101 | + ->expects($this->once()) |
|
102 | + ->method('isTrustedServer') |
|
103 | + ->with('url') |
|
104 | + ->willReturn(false); |
|
105 | + $this->trustedServers |
|
106 | + ->expects($this->once()) |
|
107 | + ->method('isNextcloudServer') |
|
108 | + ->with('url') |
|
109 | + ->willReturn(true); |
|
110 | + |
|
111 | + $this->assertNull( |
|
112 | + self::invokePrivate($this->controller, 'checkServer', ['url']) |
|
113 | + ); |
|
114 | + } |
|
115 | + |
|
116 | + #[\PHPUnit\Framework\Attributes\DataProvider('checkServerFails')] |
|
117 | + public function testCheckServerFail(bool $isTrustedServer, bool $isNextcloud): void { |
|
118 | + $this->trustedServers |
|
119 | + ->expects($this->any()) |
|
120 | + ->method('isTrustedServer') |
|
121 | + ->with('url') |
|
122 | + ->willReturn($isTrustedServer); |
|
123 | + $this->trustedServers |
|
124 | + ->expects($this->any()) |
|
125 | + ->method('isNextcloudServer') |
|
126 | + ->with('url') |
|
127 | + ->willReturn($isNextcloud); |
|
128 | + |
|
129 | + if ($isTrustedServer) { |
|
130 | + $this->expectException(OCSException::class); |
|
131 | + } else { |
|
132 | + $this->expectException(OCSNotFoundException::class); |
|
133 | + } |
|
134 | + |
|
135 | + $this->assertTrue( |
|
136 | + self::invokePrivate($this->controller, 'checkServer', ['url']) |
|
137 | + ); |
|
138 | + } |
|
139 | + |
|
140 | + public static function checkServerFails(): array { |
|
141 | + return [ |
|
142 | + [true, true], |
|
143 | + [false, false] |
|
144 | + ]; |
|
145 | + } |
|
146 | 146 | } |
@@ -23,145 +23,145 @@ |
||
23 | 23 | use Test\TestCase; |
24 | 24 | |
25 | 25 | class OCSAuthAPIControllerTest extends TestCase { |
26 | - private IRequest&MockObject $request; |
|
27 | - private ISecureRandom&MockObject $secureRandom; |
|
28 | - private JobList&MockObject $jobList; |
|
29 | - private TrustedServers&MockObject $trustedServers; |
|
30 | - private DbHandler&MockObject $dbHandler; |
|
31 | - private LoggerInterface&MockObject $logger; |
|
32 | - private ITimeFactory&MockObject $timeFactory; |
|
33 | - private IThrottler&MockObject $throttler; |
|
34 | - private OCSAuthAPIController $ocsAuthApi; |
|
35 | - |
|
36 | - /** @var int simulated timestamp */ |
|
37 | - private int $currentTime = 1234567; |
|
38 | - |
|
39 | - protected function setUp(): void { |
|
40 | - parent::setUp(); |
|
41 | - |
|
42 | - $this->request = $this->createMock(IRequest::class); |
|
43 | - $this->secureRandom = $this->createMock(ISecureRandom::class); |
|
44 | - $this->trustedServers = $this->createMock(TrustedServers::class); |
|
45 | - $this->dbHandler = $this->createMock(DbHandler::class); |
|
46 | - $this->jobList = $this->createMock(JobList::class); |
|
47 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
48 | - $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
49 | - $this->throttler = $this->createMock(IThrottler::class); |
|
50 | - |
|
51 | - $this->ocsAuthApi = new OCSAuthAPIController( |
|
52 | - 'federation', |
|
53 | - $this->request, |
|
54 | - $this->secureRandom, |
|
55 | - $this->jobList, |
|
56 | - $this->trustedServers, |
|
57 | - $this->dbHandler, |
|
58 | - $this->logger, |
|
59 | - $this->timeFactory, |
|
60 | - $this->throttler |
|
61 | - ); |
|
62 | - |
|
63 | - $this->timeFactory->method('getTime') |
|
64 | - ->willReturn($this->currentTime); |
|
65 | - } |
|
66 | - |
|
67 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestRequestSharedSecret')] |
|
68 | - public function testRequestSharedSecret(string $token, string $localToken, bool $isTrustedServer, bool $ok): void { |
|
69 | - $url = 'url'; |
|
70 | - |
|
71 | - $this->trustedServers |
|
72 | - ->expects($this->once()) |
|
73 | - ->method('isTrustedServer')->with($url)->willReturn($isTrustedServer); |
|
74 | - $this->dbHandler->expects($this->any()) |
|
75 | - ->method('getToken')->with($url)->willReturn($localToken); |
|
76 | - |
|
77 | - if ($ok) { |
|
78 | - $this->jobList->expects($this->once())->method('add') |
|
79 | - ->with(GetSharedSecret::class, ['url' => $url, 'token' => $token, 'created' => $this->currentTime]); |
|
80 | - } else { |
|
81 | - $this->jobList->expects($this->never())->method('add'); |
|
82 | - $this->jobList->expects($this->never())->method('remove'); |
|
83 | - if (!$isTrustedServer) { |
|
84 | - $this->throttler->expects($this->once()) |
|
85 | - ->method('registerAttempt') |
|
86 | - ->with('federationSharedSecret'); |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - try { |
|
92 | - $this->ocsAuthApi->requestSharedSecret($url, $token); |
|
93 | - $this->assertTrue($ok); |
|
94 | - } catch (OCSForbiddenException $e) { |
|
95 | - $this->assertFalse($ok); |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - public static function dataTestRequestSharedSecret(): array { |
|
100 | - return [ |
|
101 | - ['token2', 'token1', true, true], |
|
102 | - ['token1', 'token2', false, false], |
|
103 | - ['token1', 'token2', true, false], |
|
104 | - ]; |
|
105 | - } |
|
106 | - |
|
107 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetSharedSecret')] |
|
108 | - public function testGetSharedSecret(bool $isTrustedServer, bool $isValidToken, bool $ok): void { |
|
109 | - $url = 'url'; |
|
110 | - $token = 'token'; |
|
111 | - |
|
112 | - /** @var OCSAuthAPIController&MockObject $ocsAuthApi */ |
|
113 | - $ocsAuthApi = $this->getMockBuilder(OCSAuthAPIController::class) |
|
114 | - ->setConstructorArgs( |
|
115 | - [ |
|
116 | - 'federation', |
|
117 | - $this->request, |
|
118 | - $this->secureRandom, |
|
119 | - $this->jobList, |
|
120 | - $this->trustedServers, |
|
121 | - $this->dbHandler, |
|
122 | - $this->logger, |
|
123 | - $this->timeFactory, |
|
124 | - $this->throttler |
|
125 | - ] |
|
126 | - ) |
|
127 | - ->onlyMethods(['isValidToken']) |
|
128 | - ->getMock(); |
|
129 | - |
|
130 | - $this->trustedServers |
|
131 | - ->expects($this->any()) |
|
132 | - ->method('isTrustedServer')->with($url)->willReturn($isTrustedServer); |
|
133 | - $ocsAuthApi->expects($this->any()) |
|
134 | - ->method('isValidToken')->with($url, $token)->willReturn($isValidToken); |
|
135 | - |
|
136 | - if ($ok) { |
|
137 | - $this->secureRandom->expects($this->once())->method('generate')->with(32) |
|
138 | - ->willReturn('secret'); |
|
139 | - $this->trustedServers->expects($this->once()) |
|
140 | - ->method('addSharedSecret')->with($url, 'secret'); |
|
141 | - } else { |
|
142 | - $this->secureRandom->expects($this->never())->method('generate'); |
|
143 | - $this->trustedServers->expects($this->never())->method('addSharedSecret'); |
|
144 | - $this->throttler->expects($this->once()) |
|
145 | - ->method('registerAttempt') |
|
146 | - ->with('federationSharedSecret'); |
|
147 | - } |
|
148 | - |
|
149 | - try { |
|
150 | - $result = $ocsAuthApi->getSharedSecret($url, $token); |
|
151 | - $this->assertTrue($ok); |
|
152 | - $data = $result->getData(); |
|
153 | - $this->assertSame('secret', $data['sharedSecret']); |
|
154 | - } catch (OCSForbiddenException $e) { |
|
155 | - $this->assertFalse($ok); |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - public static function dataTestGetSharedSecret(): array { |
|
160 | - return [ |
|
161 | - [true, true, true], |
|
162 | - [false, true, false], |
|
163 | - [true, false, false], |
|
164 | - [false, false, false], |
|
165 | - ]; |
|
166 | - } |
|
26 | + private IRequest&MockObject $request; |
|
27 | + private ISecureRandom&MockObject $secureRandom; |
|
28 | + private JobList&MockObject $jobList; |
|
29 | + private TrustedServers&MockObject $trustedServers; |
|
30 | + private DbHandler&MockObject $dbHandler; |
|
31 | + private LoggerInterface&MockObject $logger; |
|
32 | + private ITimeFactory&MockObject $timeFactory; |
|
33 | + private IThrottler&MockObject $throttler; |
|
34 | + private OCSAuthAPIController $ocsAuthApi; |
|
35 | + |
|
36 | + /** @var int simulated timestamp */ |
|
37 | + private int $currentTime = 1234567; |
|
38 | + |
|
39 | + protected function setUp(): void { |
|
40 | + parent::setUp(); |
|
41 | + |
|
42 | + $this->request = $this->createMock(IRequest::class); |
|
43 | + $this->secureRandom = $this->createMock(ISecureRandom::class); |
|
44 | + $this->trustedServers = $this->createMock(TrustedServers::class); |
|
45 | + $this->dbHandler = $this->createMock(DbHandler::class); |
|
46 | + $this->jobList = $this->createMock(JobList::class); |
|
47 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
48 | + $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
49 | + $this->throttler = $this->createMock(IThrottler::class); |
|
50 | + |
|
51 | + $this->ocsAuthApi = new OCSAuthAPIController( |
|
52 | + 'federation', |
|
53 | + $this->request, |
|
54 | + $this->secureRandom, |
|
55 | + $this->jobList, |
|
56 | + $this->trustedServers, |
|
57 | + $this->dbHandler, |
|
58 | + $this->logger, |
|
59 | + $this->timeFactory, |
|
60 | + $this->throttler |
|
61 | + ); |
|
62 | + |
|
63 | + $this->timeFactory->method('getTime') |
|
64 | + ->willReturn($this->currentTime); |
|
65 | + } |
|
66 | + |
|
67 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestRequestSharedSecret')] |
|
68 | + public function testRequestSharedSecret(string $token, string $localToken, bool $isTrustedServer, bool $ok): void { |
|
69 | + $url = 'url'; |
|
70 | + |
|
71 | + $this->trustedServers |
|
72 | + ->expects($this->once()) |
|
73 | + ->method('isTrustedServer')->with($url)->willReturn($isTrustedServer); |
|
74 | + $this->dbHandler->expects($this->any()) |
|
75 | + ->method('getToken')->with($url)->willReturn($localToken); |
|
76 | + |
|
77 | + if ($ok) { |
|
78 | + $this->jobList->expects($this->once())->method('add') |
|
79 | + ->with(GetSharedSecret::class, ['url' => $url, 'token' => $token, 'created' => $this->currentTime]); |
|
80 | + } else { |
|
81 | + $this->jobList->expects($this->never())->method('add'); |
|
82 | + $this->jobList->expects($this->never())->method('remove'); |
|
83 | + if (!$isTrustedServer) { |
|
84 | + $this->throttler->expects($this->once()) |
|
85 | + ->method('registerAttempt') |
|
86 | + ->with('federationSharedSecret'); |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + try { |
|
92 | + $this->ocsAuthApi->requestSharedSecret($url, $token); |
|
93 | + $this->assertTrue($ok); |
|
94 | + } catch (OCSForbiddenException $e) { |
|
95 | + $this->assertFalse($ok); |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + public static function dataTestRequestSharedSecret(): array { |
|
100 | + return [ |
|
101 | + ['token2', 'token1', true, true], |
|
102 | + ['token1', 'token2', false, false], |
|
103 | + ['token1', 'token2', true, false], |
|
104 | + ]; |
|
105 | + } |
|
106 | + |
|
107 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetSharedSecret')] |
|
108 | + public function testGetSharedSecret(bool $isTrustedServer, bool $isValidToken, bool $ok): void { |
|
109 | + $url = 'url'; |
|
110 | + $token = 'token'; |
|
111 | + |
|
112 | + /** @var OCSAuthAPIController&MockObject $ocsAuthApi */ |
|
113 | + $ocsAuthApi = $this->getMockBuilder(OCSAuthAPIController::class) |
|
114 | + ->setConstructorArgs( |
|
115 | + [ |
|
116 | + 'federation', |
|
117 | + $this->request, |
|
118 | + $this->secureRandom, |
|
119 | + $this->jobList, |
|
120 | + $this->trustedServers, |
|
121 | + $this->dbHandler, |
|
122 | + $this->logger, |
|
123 | + $this->timeFactory, |
|
124 | + $this->throttler |
|
125 | + ] |
|
126 | + ) |
|
127 | + ->onlyMethods(['isValidToken']) |
|
128 | + ->getMock(); |
|
129 | + |
|
130 | + $this->trustedServers |
|
131 | + ->expects($this->any()) |
|
132 | + ->method('isTrustedServer')->with($url)->willReturn($isTrustedServer); |
|
133 | + $ocsAuthApi->expects($this->any()) |
|
134 | + ->method('isValidToken')->with($url, $token)->willReturn($isValidToken); |
|
135 | + |
|
136 | + if ($ok) { |
|
137 | + $this->secureRandom->expects($this->once())->method('generate')->with(32) |
|
138 | + ->willReturn('secret'); |
|
139 | + $this->trustedServers->expects($this->once()) |
|
140 | + ->method('addSharedSecret')->with($url, 'secret'); |
|
141 | + } else { |
|
142 | + $this->secureRandom->expects($this->never())->method('generate'); |
|
143 | + $this->trustedServers->expects($this->never())->method('addSharedSecret'); |
|
144 | + $this->throttler->expects($this->once()) |
|
145 | + ->method('registerAttempt') |
|
146 | + ->with('federationSharedSecret'); |
|
147 | + } |
|
148 | + |
|
149 | + try { |
|
150 | + $result = $ocsAuthApi->getSharedSecret($url, $token); |
|
151 | + $this->assertTrue($ok); |
|
152 | + $data = $result->getData(); |
|
153 | + $this->assertSame('secret', $data['sharedSecret']); |
|
154 | + } catch (OCSForbiddenException $e) { |
|
155 | + $this->assertFalse($ok); |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + public static function dataTestGetSharedSecret(): array { |
|
160 | + return [ |
|
161 | + [true, true, true], |
|
162 | + [false, true, false], |
|
163 | + [true, false, false], |
|
164 | + [false, false, false], |
|
165 | + ]; |
|
166 | + } |
|
167 | 167 | } |
@@ -15,36 +15,36 @@ |
||
15 | 15 | use Test\TestCase; |
16 | 16 | |
17 | 17 | class AdminTest extends TestCase { |
18 | - private TrustedServers&MockObject $trustedServers; |
|
19 | - private Admin $admin; |
|
20 | - |
|
21 | - protected function setUp(): void { |
|
22 | - parent::setUp(); |
|
23 | - $this->trustedServers = $this->createMock(TrustedServers::class); |
|
24 | - $this->admin = new Admin( |
|
25 | - $this->trustedServers, |
|
26 | - $this->createMock(IL10N::class) |
|
27 | - ); |
|
28 | - } |
|
29 | - |
|
30 | - public function testGetForm(): void { |
|
31 | - $this->trustedServers |
|
32 | - ->expects($this->once()) |
|
33 | - ->method('getServers') |
|
34 | - ->willReturn(['myserver', 'secondserver']); |
|
35 | - |
|
36 | - $params = [ |
|
37 | - 'trustedServers' => ['myserver', 'secondserver'], |
|
38 | - ]; |
|
39 | - $expected = new TemplateResponse('federation', 'settings-admin', $params, ''); |
|
40 | - $this->assertEquals($expected, $this->admin->getForm()); |
|
41 | - } |
|
42 | - |
|
43 | - public function testGetSection(): void { |
|
44 | - $this->assertSame('sharing', $this->admin->getSection()); |
|
45 | - } |
|
46 | - |
|
47 | - public function testGetPriority(): void { |
|
48 | - $this->assertSame(30, $this->admin->getPriority()); |
|
49 | - } |
|
18 | + private TrustedServers&MockObject $trustedServers; |
|
19 | + private Admin $admin; |
|
20 | + |
|
21 | + protected function setUp(): void { |
|
22 | + parent::setUp(); |
|
23 | + $this->trustedServers = $this->createMock(TrustedServers::class); |
|
24 | + $this->admin = new Admin( |
|
25 | + $this->trustedServers, |
|
26 | + $this->createMock(IL10N::class) |
|
27 | + ); |
|
28 | + } |
|
29 | + |
|
30 | + public function testGetForm(): void { |
|
31 | + $this->trustedServers |
|
32 | + ->expects($this->once()) |
|
33 | + ->method('getServers') |
|
34 | + ->willReturn(['myserver', 'secondserver']); |
|
35 | + |
|
36 | + $params = [ |
|
37 | + 'trustedServers' => ['myserver', 'secondserver'], |
|
38 | + ]; |
|
39 | + $expected = new TemplateResponse('federation', 'settings-admin', $params, ''); |
|
40 | + $this->assertEquals($expected, $this->admin->getForm()); |
|
41 | + } |
|
42 | + |
|
43 | + public function testGetSection(): void { |
|
44 | + $this->assertSame('sharing', $this->admin->getSection()); |
|
45 | + } |
|
46 | + |
|
47 | + public function testGetPriority(): void { |
|
48 | + $this->assertSame(30, $this->admin->getPriority()); |
|
49 | + } |
|
50 | 50 | } |
@@ -26,256 +26,256 @@ |
||
26 | 26 | use Test\TestCase; |
27 | 27 | |
28 | 28 | class TrustedServersTest extends TestCase { |
29 | - private TrustedServers $trustedServers; |
|
30 | - private DbHandler&MockObject $dbHandler; |
|
31 | - private IClientService&MockObject $httpClientService; |
|
32 | - private IClient&MockObject $httpClient; |
|
33 | - private IResponse&MockObject $response; |
|
34 | - private LoggerInterface&MockObject $logger; |
|
35 | - private IJobList&MockObject $jobList; |
|
36 | - private ISecureRandom&MockObject $secureRandom; |
|
37 | - private IConfig&MockObject $config; |
|
38 | - private IEventDispatcher&MockObject $dispatcher; |
|
39 | - private ITimeFactory&MockObject $timeFactory; |
|
40 | - |
|
41 | - protected function setUp(): void { |
|
42 | - parent::setUp(); |
|
43 | - |
|
44 | - $this->dbHandler = $this->createMock(DbHandler::class); |
|
45 | - $this->dispatcher = $this->createMock(IEventDispatcher::class); |
|
46 | - $this->httpClientService = $this->createMock(IClientService::class); |
|
47 | - $this->httpClient = $this->createMock(IClient::class); |
|
48 | - $this->response = $this->createMock(IResponse::class); |
|
49 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
50 | - $this->jobList = $this->createMock(IJobList::class); |
|
51 | - $this->secureRandom = $this->createMock(ISecureRandom::class); |
|
52 | - $this->config = $this->createMock(IConfig::class); |
|
53 | - $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
54 | - |
|
55 | - $this->trustedServers = new TrustedServers( |
|
56 | - $this->dbHandler, |
|
57 | - $this->httpClientService, |
|
58 | - $this->logger, |
|
59 | - $this->jobList, |
|
60 | - $this->secureRandom, |
|
61 | - $this->config, |
|
62 | - $this->dispatcher, |
|
63 | - $this->timeFactory |
|
64 | - ); |
|
65 | - } |
|
66 | - |
|
67 | - public function testAddServer(): void { |
|
68 | - /** @var TrustedServers&MockObject $trustedServers */ |
|
69 | - $trustedServers = $this->getMockBuilder(TrustedServers::class) |
|
70 | - ->setConstructorArgs( |
|
71 | - [ |
|
72 | - $this->dbHandler, |
|
73 | - $this->httpClientService, |
|
74 | - $this->logger, |
|
75 | - $this->jobList, |
|
76 | - $this->secureRandom, |
|
77 | - $this->config, |
|
78 | - $this->dispatcher, |
|
79 | - $this->timeFactory |
|
80 | - ] |
|
81 | - ) |
|
82 | - ->onlyMethods(['updateProtocol']) |
|
83 | - ->getMock(); |
|
84 | - $trustedServers->expects($this->once())->method('updateProtocol') |
|
85 | - ->with('url')->willReturn('https://url'); |
|
86 | - $this->timeFactory->method('getTime') |
|
87 | - ->willReturn(1234567); |
|
88 | - $this->dbHandler->expects($this->once())->method('addServer')->with('https://url') |
|
89 | - ->willReturn(1); |
|
90 | - |
|
91 | - $this->secureRandom->expects($this->once())->method('generate') |
|
92 | - ->willReturn('token'); |
|
93 | - $this->dbHandler->expects($this->once())->method('addToken')->with('https://url', 'token'); |
|
94 | - $this->jobList->expects($this->once())->method('add') |
|
95 | - ->with(RequestSharedSecret::class, |
|
96 | - ['url' => 'https://url', 'token' => 'token', 'created' => 1234567]); |
|
97 | - |
|
98 | - $this->assertSame( |
|
99 | - 1, |
|
100 | - $trustedServers->addServer('url') |
|
101 | - ); |
|
102 | - } |
|
103 | - |
|
104 | - public function testAddSharedSecret(): void { |
|
105 | - $this->dbHandler->expects($this->once())->method('addSharedSecret') |
|
106 | - ->with('url', 'secret'); |
|
107 | - $this->trustedServers->addSharedSecret('url', 'secret'); |
|
108 | - } |
|
109 | - |
|
110 | - public function testGetSharedSecret(): void { |
|
111 | - $this->dbHandler->expects($this->once()) |
|
112 | - ->method('getSharedSecret') |
|
113 | - ->with('url') |
|
114 | - ->willReturn('secret'); |
|
115 | - $this->assertSame( |
|
116 | - $this->trustedServers->getSharedSecret('url'), |
|
117 | - 'secret' |
|
118 | - ); |
|
119 | - } |
|
120 | - |
|
121 | - public function testRemoveServer(): void { |
|
122 | - $id = 42; |
|
123 | - $server = ['url_hash' => 'url_hash']; |
|
124 | - $this->dbHandler->expects($this->once())->method('removeServer')->with($id); |
|
125 | - $this->dbHandler->expects($this->once())->method('getServerById')->with($id) |
|
126 | - ->willReturn($server); |
|
127 | - $this->dispatcher->expects($this->once())->method('dispatchTyped') |
|
128 | - ->willReturnCallback( |
|
129 | - function ($event): void { |
|
130 | - $this->assertSame(get_class($event), TrustedServerRemovedEvent::class); |
|
131 | - /** @var \OCP\Federated\Events\TrustedServerRemovedEvent $event */ |
|
132 | - $this->assertSame('url_hash', $event->getUrlHash()); |
|
133 | - } |
|
134 | - ); |
|
135 | - $this->trustedServers->removeServer($id); |
|
136 | - } |
|
137 | - |
|
138 | - public function testGetServers(): void { |
|
139 | - $this->dbHandler->expects($this->once())->method('getAllServer')->willReturn(['servers']); |
|
140 | - |
|
141 | - $this->assertEquals( |
|
142 | - ['servers'], |
|
143 | - $this->trustedServers->getServers() |
|
144 | - ); |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - public function testIsTrustedServer(): void { |
|
149 | - $this->dbHandler->expects($this->once()) |
|
150 | - ->method('serverExists')->with('url') |
|
151 | - ->willReturn(true); |
|
152 | - |
|
153 | - $this->assertTrue( |
|
154 | - $this->trustedServers->isTrustedServer('url') |
|
155 | - ); |
|
156 | - } |
|
157 | - |
|
158 | - public function testSetServerStatus(): void { |
|
159 | - $this->dbHandler->expects($this->once())->method('setServerStatus') |
|
160 | - ->with('url', 1); |
|
161 | - $this->trustedServers->setServerStatus('url', 1); |
|
162 | - } |
|
163 | - |
|
164 | - public function testGetServerStatus(): void { |
|
165 | - $this->dbHandler->expects($this->once())->method('getServerStatus') |
|
166 | - ->with('url')->willReturn(1); |
|
167 | - $this->assertSame( |
|
168 | - $this->trustedServers->getServerStatus('url'), |
|
169 | - 1 |
|
170 | - ); |
|
171 | - } |
|
172 | - |
|
173 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestIsNextcloudServer')] |
|
174 | - public function testIsNextcloudServer(int $statusCode, bool $isValidNextcloudVersion, bool $expected): void { |
|
175 | - $server = 'server1'; |
|
176 | - |
|
177 | - /** @var TrustedServers&MockObject $trustedServers */ |
|
178 | - $trustedServers = $this->getMockBuilder(TrustedServers::class) |
|
179 | - ->setConstructorArgs( |
|
180 | - [ |
|
181 | - $this->dbHandler, |
|
182 | - $this->httpClientService, |
|
183 | - $this->logger, |
|
184 | - $this->jobList, |
|
185 | - $this->secureRandom, |
|
186 | - $this->config, |
|
187 | - $this->dispatcher, |
|
188 | - $this->timeFactory |
|
189 | - ] |
|
190 | - ) |
|
191 | - ->onlyMethods(['checkNextcloudVersion']) |
|
192 | - ->getMock(); |
|
193 | - |
|
194 | - $this->httpClientService->expects($this->once())->method('newClient') |
|
195 | - ->willReturn($this->httpClient); |
|
196 | - |
|
197 | - $this->httpClient->expects($this->once())->method('get')->with($server . '/status.php') |
|
198 | - ->willReturn($this->response); |
|
199 | - |
|
200 | - $this->response->expects($this->once())->method('getStatusCode') |
|
201 | - ->willReturn($statusCode); |
|
202 | - |
|
203 | - if ($statusCode === 200) { |
|
204 | - $this->response->expects($this->once())->method('getBody') |
|
205 | - ->willReturn(''); |
|
206 | - $trustedServers->expects($this->once())->method('checkNextcloudVersion') |
|
207 | - ->willReturn($isValidNextcloudVersion); |
|
208 | - } else { |
|
209 | - $trustedServers->expects($this->never())->method('checkNextcloudVersion'); |
|
210 | - } |
|
211 | - |
|
212 | - $this->assertSame($expected, |
|
213 | - $trustedServers->isNextcloudServer($server) |
|
214 | - ); |
|
215 | - } |
|
216 | - |
|
217 | - public static function dataTestIsNextcloudServer(): array { |
|
218 | - return [ |
|
219 | - [200, true, true], |
|
220 | - [200, false, false], |
|
221 | - [404, true, false], |
|
222 | - ]; |
|
223 | - } |
|
224 | - |
|
225 | - public function testIsNextcloudServerFail(): void { |
|
226 | - $server = 'server1'; |
|
227 | - |
|
228 | - $this->httpClientService->expects($this->once()) |
|
229 | - ->method('newClient') |
|
230 | - ->willReturn($this->httpClient); |
|
231 | - |
|
232 | - $this->httpClient->expects($this->once()) |
|
233 | - ->method('get') |
|
234 | - ->with($server . '/status.php') |
|
235 | - ->willThrowException(new \Exception('simulated exception')); |
|
236 | - |
|
237 | - $this->assertFalse($this->trustedServers->isNextcloudServer($server)); |
|
238 | - } |
|
239 | - |
|
240 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestCheckNextcloudVersion')] |
|
241 | - public function testCheckNextcloudVersion(string $status): void { |
|
242 | - $this->assertTrue(self::invokePrivate($this->trustedServers, 'checkNextcloudVersion', [$status])); |
|
243 | - } |
|
244 | - |
|
245 | - public static function dataTestCheckNextcloudVersion(): array { |
|
246 | - return [ |
|
247 | - ['{"version":"9.0.0"}'], |
|
248 | - ['{"version":"9.1.0"}'] |
|
249 | - ]; |
|
250 | - } |
|
251 | - |
|
252 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestCheckNextcloudVersionTooLow')] |
|
253 | - public function testCheckNextcloudVersionTooLow(string $status): void { |
|
254 | - $this->expectException(HintException::class); |
|
255 | - $this->expectExceptionMessage('Remote server version is too low. 9.0 is required.'); |
|
256 | - |
|
257 | - self::invokePrivate($this->trustedServers, 'checkNextcloudVersion', [$status]); |
|
258 | - } |
|
259 | - |
|
260 | - public static function dataTestCheckNextcloudVersionTooLow(): array { |
|
261 | - return [ |
|
262 | - ['{"version":"8.2.3"}'], |
|
263 | - ]; |
|
264 | - } |
|
265 | - |
|
266 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestUpdateProtocol')] |
|
267 | - public function testUpdateProtocol(string $url, string $expected): void { |
|
268 | - $this->assertSame($expected, |
|
269 | - self::invokePrivate($this->trustedServers, 'updateProtocol', [$url]) |
|
270 | - ); |
|
271 | - } |
|
272 | - |
|
273 | - public static function dataTestUpdateProtocol(): array { |
|
274 | - return [ |
|
275 | - ['http://owncloud.org', 'http://owncloud.org'], |
|
276 | - ['https://owncloud.org', 'https://owncloud.org'], |
|
277 | - ['owncloud.org', 'https://owncloud.org'], |
|
278 | - ['httpserver', 'https://httpserver'], |
|
279 | - ]; |
|
280 | - } |
|
29 | + private TrustedServers $trustedServers; |
|
30 | + private DbHandler&MockObject $dbHandler; |
|
31 | + private IClientService&MockObject $httpClientService; |
|
32 | + private IClient&MockObject $httpClient; |
|
33 | + private IResponse&MockObject $response; |
|
34 | + private LoggerInterface&MockObject $logger; |
|
35 | + private IJobList&MockObject $jobList; |
|
36 | + private ISecureRandom&MockObject $secureRandom; |
|
37 | + private IConfig&MockObject $config; |
|
38 | + private IEventDispatcher&MockObject $dispatcher; |
|
39 | + private ITimeFactory&MockObject $timeFactory; |
|
40 | + |
|
41 | + protected function setUp(): void { |
|
42 | + parent::setUp(); |
|
43 | + |
|
44 | + $this->dbHandler = $this->createMock(DbHandler::class); |
|
45 | + $this->dispatcher = $this->createMock(IEventDispatcher::class); |
|
46 | + $this->httpClientService = $this->createMock(IClientService::class); |
|
47 | + $this->httpClient = $this->createMock(IClient::class); |
|
48 | + $this->response = $this->createMock(IResponse::class); |
|
49 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
50 | + $this->jobList = $this->createMock(IJobList::class); |
|
51 | + $this->secureRandom = $this->createMock(ISecureRandom::class); |
|
52 | + $this->config = $this->createMock(IConfig::class); |
|
53 | + $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
54 | + |
|
55 | + $this->trustedServers = new TrustedServers( |
|
56 | + $this->dbHandler, |
|
57 | + $this->httpClientService, |
|
58 | + $this->logger, |
|
59 | + $this->jobList, |
|
60 | + $this->secureRandom, |
|
61 | + $this->config, |
|
62 | + $this->dispatcher, |
|
63 | + $this->timeFactory |
|
64 | + ); |
|
65 | + } |
|
66 | + |
|
67 | + public function testAddServer(): void { |
|
68 | + /** @var TrustedServers&MockObject $trustedServers */ |
|
69 | + $trustedServers = $this->getMockBuilder(TrustedServers::class) |
|
70 | + ->setConstructorArgs( |
|
71 | + [ |
|
72 | + $this->dbHandler, |
|
73 | + $this->httpClientService, |
|
74 | + $this->logger, |
|
75 | + $this->jobList, |
|
76 | + $this->secureRandom, |
|
77 | + $this->config, |
|
78 | + $this->dispatcher, |
|
79 | + $this->timeFactory |
|
80 | + ] |
|
81 | + ) |
|
82 | + ->onlyMethods(['updateProtocol']) |
|
83 | + ->getMock(); |
|
84 | + $trustedServers->expects($this->once())->method('updateProtocol') |
|
85 | + ->with('url')->willReturn('https://url'); |
|
86 | + $this->timeFactory->method('getTime') |
|
87 | + ->willReturn(1234567); |
|
88 | + $this->dbHandler->expects($this->once())->method('addServer')->with('https://url') |
|
89 | + ->willReturn(1); |
|
90 | + |
|
91 | + $this->secureRandom->expects($this->once())->method('generate') |
|
92 | + ->willReturn('token'); |
|
93 | + $this->dbHandler->expects($this->once())->method('addToken')->with('https://url', 'token'); |
|
94 | + $this->jobList->expects($this->once())->method('add') |
|
95 | + ->with(RequestSharedSecret::class, |
|
96 | + ['url' => 'https://url', 'token' => 'token', 'created' => 1234567]); |
|
97 | + |
|
98 | + $this->assertSame( |
|
99 | + 1, |
|
100 | + $trustedServers->addServer('url') |
|
101 | + ); |
|
102 | + } |
|
103 | + |
|
104 | + public function testAddSharedSecret(): void { |
|
105 | + $this->dbHandler->expects($this->once())->method('addSharedSecret') |
|
106 | + ->with('url', 'secret'); |
|
107 | + $this->trustedServers->addSharedSecret('url', 'secret'); |
|
108 | + } |
|
109 | + |
|
110 | + public function testGetSharedSecret(): void { |
|
111 | + $this->dbHandler->expects($this->once()) |
|
112 | + ->method('getSharedSecret') |
|
113 | + ->with('url') |
|
114 | + ->willReturn('secret'); |
|
115 | + $this->assertSame( |
|
116 | + $this->trustedServers->getSharedSecret('url'), |
|
117 | + 'secret' |
|
118 | + ); |
|
119 | + } |
|
120 | + |
|
121 | + public function testRemoveServer(): void { |
|
122 | + $id = 42; |
|
123 | + $server = ['url_hash' => 'url_hash']; |
|
124 | + $this->dbHandler->expects($this->once())->method('removeServer')->with($id); |
|
125 | + $this->dbHandler->expects($this->once())->method('getServerById')->with($id) |
|
126 | + ->willReturn($server); |
|
127 | + $this->dispatcher->expects($this->once())->method('dispatchTyped') |
|
128 | + ->willReturnCallback( |
|
129 | + function ($event): void { |
|
130 | + $this->assertSame(get_class($event), TrustedServerRemovedEvent::class); |
|
131 | + /** @var \OCP\Federated\Events\TrustedServerRemovedEvent $event */ |
|
132 | + $this->assertSame('url_hash', $event->getUrlHash()); |
|
133 | + } |
|
134 | + ); |
|
135 | + $this->trustedServers->removeServer($id); |
|
136 | + } |
|
137 | + |
|
138 | + public function testGetServers(): void { |
|
139 | + $this->dbHandler->expects($this->once())->method('getAllServer')->willReturn(['servers']); |
|
140 | + |
|
141 | + $this->assertEquals( |
|
142 | + ['servers'], |
|
143 | + $this->trustedServers->getServers() |
|
144 | + ); |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + public function testIsTrustedServer(): void { |
|
149 | + $this->dbHandler->expects($this->once()) |
|
150 | + ->method('serverExists')->with('url') |
|
151 | + ->willReturn(true); |
|
152 | + |
|
153 | + $this->assertTrue( |
|
154 | + $this->trustedServers->isTrustedServer('url') |
|
155 | + ); |
|
156 | + } |
|
157 | + |
|
158 | + public function testSetServerStatus(): void { |
|
159 | + $this->dbHandler->expects($this->once())->method('setServerStatus') |
|
160 | + ->with('url', 1); |
|
161 | + $this->trustedServers->setServerStatus('url', 1); |
|
162 | + } |
|
163 | + |
|
164 | + public function testGetServerStatus(): void { |
|
165 | + $this->dbHandler->expects($this->once())->method('getServerStatus') |
|
166 | + ->with('url')->willReturn(1); |
|
167 | + $this->assertSame( |
|
168 | + $this->trustedServers->getServerStatus('url'), |
|
169 | + 1 |
|
170 | + ); |
|
171 | + } |
|
172 | + |
|
173 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestIsNextcloudServer')] |
|
174 | + public function testIsNextcloudServer(int $statusCode, bool $isValidNextcloudVersion, bool $expected): void { |
|
175 | + $server = 'server1'; |
|
176 | + |
|
177 | + /** @var TrustedServers&MockObject $trustedServers */ |
|
178 | + $trustedServers = $this->getMockBuilder(TrustedServers::class) |
|
179 | + ->setConstructorArgs( |
|
180 | + [ |
|
181 | + $this->dbHandler, |
|
182 | + $this->httpClientService, |
|
183 | + $this->logger, |
|
184 | + $this->jobList, |
|
185 | + $this->secureRandom, |
|
186 | + $this->config, |
|
187 | + $this->dispatcher, |
|
188 | + $this->timeFactory |
|
189 | + ] |
|
190 | + ) |
|
191 | + ->onlyMethods(['checkNextcloudVersion']) |
|
192 | + ->getMock(); |
|
193 | + |
|
194 | + $this->httpClientService->expects($this->once())->method('newClient') |
|
195 | + ->willReturn($this->httpClient); |
|
196 | + |
|
197 | + $this->httpClient->expects($this->once())->method('get')->with($server . '/status.php') |
|
198 | + ->willReturn($this->response); |
|
199 | + |
|
200 | + $this->response->expects($this->once())->method('getStatusCode') |
|
201 | + ->willReturn($statusCode); |
|
202 | + |
|
203 | + if ($statusCode === 200) { |
|
204 | + $this->response->expects($this->once())->method('getBody') |
|
205 | + ->willReturn(''); |
|
206 | + $trustedServers->expects($this->once())->method('checkNextcloudVersion') |
|
207 | + ->willReturn($isValidNextcloudVersion); |
|
208 | + } else { |
|
209 | + $trustedServers->expects($this->never())->method('checkNextcloudVersion'); |
|
210 | + } |
|
211 | + |
|
212 | + $this->assertSame($expected, |
|
213 | + $trustedServers->isNextcloudServer($server) |
|
214 | + ); |
|
215 | + } |
|
216 | + |
|
217 | + public static function dataTestIsNextcloudServer(): array { |
|
218 | + return [ |
|
219 | + [200, true, true], |
|
220 | + [200, false, false], |
|
221 | + [404, true, false], |
|
222 | + ]; |
|
223 | + } |
|
224 | + |
|
225 | + public function testIsNextcloudServerFail(): void { |
|
226 | + $server = 'server1'; |
|
227 | + |
|
228 | + $this->httpClientService->expects($this->once()) |
|
229 | + ->method('newClient') |
|
230 | + ->willReturn($this->httpClient); |
|
231 | + |
|
232 | + $this->httpClient->expects($this->once()) |
|
233 | + ->method('get') |
|
234 | + ->with($server . '/status.php') |
|
235 | + ->willThrowException(new \Exception('simulated exception')); |
|
236 | + |
|
237 | + $this->assertFalse($this->trustedServers->isNextcloudServer($server)); |
|
238 | + } |
|
239 | + |
|
240 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestCheckNextcloudVersion')] |
|
241 | + public function testCheckNextcloudVersion(string $status): void { |
|
242 | + $this->assertTrue(self::invokePrivate($this->trustedServers, 'checkNextcloudVersion', [$status])); |
|
243 | + } |
|
244 | + |
|
245 | + public static function dataTestCheckNextcloudVersion(): array { |
|
246 | + return [ |
|
247 | + ['{"version":"9.0.0"}'], |
|
248 | + ['{"version":"9.1.0"}'] |
|
249 | + ]; |
|
250 | + } |
|
251 | + |
|
252 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestCheckNextcloudVersionTooLow')] |
|
253 | + public function testCheckNextcloudVersionTooLow(string $status): void { |
|
254 | + $this->expectException(HintException::class); |
|
255 | + $this->expectExceptionMessage('Remote server version is too low. 9.0 is required.'); |
|
256 | + |
|
257 | + self::invokePrivate($this->trustedServers, 'checkNextcloudVersion', [$status]); |
|
258 | + } |
|
259 | + |
|
260 | + public static function dataTestCheckNextcloudVersionTooLow(): array { |
|
261 | + return [ |
|
262 | + ['{"version":"8.2.3"}'], |
|
263 | + ]; |
|
264 | + } |
|
265 | + |
|
266 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestUpdateProtocol')] |
|
267 | + public function testUpdateProtocol(string $url, string $expected): void { |
|
268 | + $this->assertSame($expected, |
|
269 | + self::invokePrivate($this->trustedServers, 'updateProtocol', [$url]) |
|
270 | + ); |
|
271 | + } |
|
272 | + |
|
273 | + public static function dataTestUpdateProtocol(): array { |
|
274 | + return [ |
|
275 | + ['http://owncloud.org', 'http://owncloud.org'], |
|
276 | + ['https://owncloud.org', 'https://owncloud.org'], |
|
277 | + ['owncloud.org', 'https://owncloud.org'], |
|
278 | + ['httpserver', 'https://httpserver'], |
|
279 | + ]; |
|
280 | + } |
|
281 | 281 | } |
@@ -20,266 +20,266 @@ |
||
20 | 20 | * @group DB |
21 | 21 | */ |
22 | 22 | class DbHandlerTest extends TestCase { |
23 | - private DbHandler $dbHandler; |
|
24 | - private IL10N&MockObject $il10n; |
|
25 | - private IDBConnection $connection; |
|
26 | - private string $dbTable = 'trusted_servers'; |
|
27 | - |
|
28 | - protected function setUp(): void { |
|
29 | - parent::setUp(); |
|
30 | - |
|
31 | - $this->connection = Server::get(IDBConnection::class); |
|
32 | - $this->il10n = $this->createMock(IL10N::class); |
|
33 | - |
|
34 | - $this->dbHandler = new DbHandler( |
|
35 | - $this->connection, |
|
36 | - $this->il10n |
|
37 | - ); |
|
38 | - |
|
39 | - $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
40 | - |
|
41 | - $qResult = $query->executeQuery(); |
|
42 | - $result = $qResult->fetchAll(); |
|
43 | - $qResult->closeCursor(); |
|
44 | - $this->assertEmpty($result, 'we need to start with a empty trusted_servers table'); |
|
45 | - } |
|
46 | - |
|
47 | - protected function tearDown(): void { |
|
48 | - $query = $this->connection->getQueryBuilder()->delete($this->dbTable); |
|
49 | - $query->executeStatement() |
|
50 | - ; |
|
51 | - parent::tearDown(); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * |
|
56 | - * @param string $url passed to the method |
|
57 | - * @param string $expectedUrl the url we expect to be written to the db |
|
58 | - * @param string $expectedHash the hash value we expect to be written to the db |
|
59 | - */ |
|
60 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestAddServer')] |
|
61 | - public function testAddServer(string $url, string $expectedUrl, string $expectedHash): void { |
|
62 | - $id = $this->dbHandler->addServer($url); |
|
63 | - |
|
64 | - $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
65 | - |
|
66 | - $qResult = $query->execute(); |
|
67 | - $result = $qResult->fetchAll(); |
|
68 | - $qResult->closeCursor(); |
|
69 | - $this->assertCount(1, $result); |
|
70 | - $this->assertSame($expectedUrl, $result[0]['url']); |
|
71 | - $this->assertSame($id, (int)$result[0]['id']); |
|
72 | - $this->assertSame($expectedHash, $result[0]['url_hash']); |
|
73 | - $this->assertSame(TrustedServers::STATUS_PENDING, (int)$result[0]['status']); |
|
74 | - } |
|
75 | - |
|
76 | - public static function dataTestAddServer(): array { |
|
77 | - return [ |
|
78 | - ['http://owncloud.org', 'http://owncloud.org', sha1('owncloud.org')], |
|
79 | - ['https://owncloud.org', 'https://owncloud.org', sha1('owncloud.org')], |
|
80 | - ['http://owncloud.org/', 'http://owncloud.org', sha1('owncloud.org')], |
|
81 | - ]; |
|
82 | - } |
|
83 | - |
|
84 | - public function testRemove(): void { |
|
85 | - $id1 = $this->dbHandler->addServer('server1'); |
|
86 | - $id2 = $this->dbHandler->addServer('server2'); |
|
87 | - |
|
88 | - $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
89 | - |
|
90 | - $qResult = $query->execute(); |
|
91 | - $result = $qResult->fetchAll(); |
|
92 | - $qResult->closeCursor(); |
|
93 | - $this->assertCount(2, $result); |
|
94 | - $this->assertSame('server1', $result[0]['url']); |
|
95 | - $this->assertSame('server2', $result[1]['url']); |
|
96 | - $this->assertSame($id1, (int)$result[0]['id']); |
|
97 | - $this->assertSame($id2, (int)$result[1]['id']); |
|
98 | - |
|
99 | - $this->dbHandler->removeServer($id2); |
|
100 | - $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
101 | - |
|
102 | - $qResult = $query->execute(); |
|
103 | - $result = $qResult->fetchAll(); |
|
104 | - $qResult->closeCursor(); |
|
105 | - $this->assertCount(1, $result); |
|
106 | - $this->assertSame('server1', $result[0]['url']); |
|
107 | - $this->assertSame($id1, (int)$result[0]['id']); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - public function testGetServerById(): void { |
|
112 | - $this->dbHandler->addServer('server1'); |
|
113 | - $id = $this->dbHandler->addServer('server2'); |
|
114 | - |
|
115 | - $result = $this->dbHandler->getServerById($id); |
|
116 | - $this->assertSame('server2', $result['url']); |
|
117 | - } |
|
118 | - |
|
119 | - public function testGetAll(): void { |
|
120 | - $id1 = $this->dbHandler->addServer('server1'); |
|
121 | - $id2 = $this->dbHandler->addServer('server2'); |
|
122 | - |
|
123 | - $result = $this->dbHandler->getAllServer(); |
|
124 | - $this->assertSame(2, count($result)); |
|
125 | - $this->assertSame('server1', $result[0]['url']); |
|
126 | - $this->assertSame('server2', $result[1]['url']); |
|
127 | - $this->assertSame($id1, (int)$result[0]['id']); |
|
128 | - $this->assertSame($id2, (int)$result[1]['id']); |
|
129 | - } |
|
130 | - |
|
131 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestServerExists')] |
|
132 | - public function testServerExists(string $serverInTable, string $checkForServer, bool $expected): void { |
|
133 | - $this->dbHandler->addServer($serverInTable); |
|
134 | - $this->assertSame($expected, |
|
135 | - $this->dbHandler->serverExists($checkForServer) |
|
136 | - ); |
|
137 | - } |
|
138 | - |
|
139 | - public static function dataTestServerExists(): array { |
|
140 | - return [ |
|
141 | - ['server1', 'server1', true], |
|
142 | - ['server1', 'http://server1', true], |
|
143 | - ['server1', 'server2', false] |
|
144 | - ]; |
|
145 | - } |
|
146 | - |
|
147 | - public function XtestAddToken() { |
|
148 | - $this->dbHandler->addServer('server1'); |
|
149 | - $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
150 | - |
|
151 | - $qResult = $query->executeQuery(); |
|
152 | - $result = $qResult->fetchAll(); |
|
153 | - $qResult->closeCursor(); |
|
154 | - $this->assertCount(1, $result); |
|
155 | - $this->assertSame(null, $result[0]['token']); |
|
156 | - $this->dbHandler->addToken('http://server1', 'token'); |
|
157 | - $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
158 | - |
|
159 | - $qResult = $query->executeQuery(); |
|
160 | - $result = $qResult->fetchAll(); |
|
161 | - $qResult->closeCursor(); |
|
162 | - $this->assertCount(1, $result); |
|
163 | - $this->assertSame('token', $result[0]['token']); |
|
164 | - } |
|
165 | - |
|
166 | - public function testGetToken(): void { |
|
167 | - $this->dbHandler->addServer('server1'); |
|
168 | - $this->dbHandler->addToken('http://server1', 'token'); |
|
169 | - $this->assertSame('token', |
|
170 | - $this->dbHandler->getToken('https://server1') |
|
171 | - ); |
|
172 | - } |
|
173 | - |
|
174 | - public function XtestAddSharedSecret() { |
|
175 | - $this->dbHandler->addServer('server1'); |
|
176 | - $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
177 | - |
|
178 | - $qResult = $query->execute(); |
|
179 | - $result = $qResult->fetchAll(); |
|
180 | - $qResult->closeCursor(); |
|
181 | - $this->assertCount(1, $result); |
|
182 | - $this->assertSame(null, $result[0]['shared_secret']); |
|
183 | - $this->dbHandler->addSharedSecret('http://server1', 'secret'); |
|
184 | - $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
185 | - |
|
186 | - $qResult = $query->execute(); |
|
187 | - $result = $qResult->fetchAll(); |
|
188 | - $qResult->closeCursor(); |
|
189 | - $this->assertCount(1, $result); |
|
190 | - $this->assertSame('secret', $result[0]['shared_secret']); |
|
191 | - } |
|
192 | - |
|
193 | - public function testGetSharedSecret(): void { |
|
194 | - $this->dbHandler->addServer('server1'); |
|
195 | - $this->dbHandler->addSharedSecret('http://server1', 'secret'); |
|
196 | - $this->assertSame('secret', |
|
197 | - $this->dbHandler->getSharedSecret('https://server1') |
|
198 | - ); |
|
199 | - } |
|
200 | - |
|
201 | - public function testSetServerStatus(): void { |
|
202 | - $this->dbHandler->addServer('server1'); |
|
203 | - $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
204 | - |
|
205 | - $qResult = $query->executeQuery(); |
|
206 | - $result = $qResult->fetchAll(); |
|
207 | - $qResult->closeCursor(); |
|
208 | - $this->assertCount(1, $result); |
|
209 | - $this->assertSame(TrustedServers::STATUS_PENDING, (int)$result[0]['status']); |
|
210 | - $this->dbHandler->setServerStatus('http://server1', TrustedServers::STATUS_OK); |
|
211 | - $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
212 | - |
|
213 | - $qResult = $query->executeQuery(); |
|
214 | - $result = $qResult->fetchAll(); |
|
215 | - $qResult->closeCursor(); |
|
216 | - $this->assertCount(1, $result); |
|
217 | - $this->assertSame(TrustedServers::STATUS_OK, (int)$result[0]['status']); |
|
218 | - } |
|
219 | - |
|
220 | - public function testGetServerStatus(): void { |
|
221 | - $this->dbHandler->addServer('server1'); |
|
222 | - $this->dbHandler->setServerStatus('http://server1', TrustedServers::STATUS_OK); |
|
223 | - $this->assertSame(TrustedServers::STATUS_OK, |
|
224 | - $this->dbHandler->getServerStatus('https://server1') |
|
225 | - ); |
|
226 | - |
|
227 | - // test sync token |
|
228 | - $this->dbHandler->setServerStatus('http://server1', TrustedServers::STATUS_OK, 'token1234567890'); |
|
229 | - $servers = $this->dbHandler->getAllServer(); |
|
230 | - $this->assertSame('token1234567890', $servers[0]['sync_token']); |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * hash should always be computed with the normalized URL |
|
235 | - */ |
|
236 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestHash')] |
|
237 | - public function testHash(string $url, string $expected): void { |
|
238 | - $this->assertSame($expected, |
|
239 | - $this->invokePrivate($this->dbHandler, 'hash', [$url]) |
|
240 | - ); |
|
241 | - } |
|
242 | - |
|
243 | - public static function dataTestHash(): array { |
|
244 | - return [ |
|
245 | - ['server1', sha1('server1')], |
|
246 | - ['http://server1', sha1('server1')], |
|
247 | - ['https://server1', sha1('server1')], |
|
248 | - ['http://server1/', sha1('server1')], |
|
249 | - ]; |
|
250 | - } |
|
251 | - |
|
252 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestNormalizeUrl')] |
|
253 | - public function testNormalizeUrl(string $url, string $expected): void { |
|
254 | - $this->assertSame($expected, |
|
255 | - $this->invokePrivate($this->dbHandler, 'normalizeUrl', [$url]) |
|
256 | - ); |
|
257 | - } |
|
258 | - |
|
259 | - public static function dataTestNormalizeUrl(): array { |
|
260 | - return [ |
|
261 | - ['owncloud.org', 'owncloud.org'], |
|
262 | - ['http://owncloud.org', 'owncloud.org'], |
|
263 | - ['https://owncloud.org', 'owncloud.org'], |
|
264 | - ['https://owncloud.org//mycloud', 'owncloud.org/mycloud'], |
|
265 | - ['https://owncloud.org/mycloud/', 'owncloud.org/mycloud'], |
|
266 | - ]; |
|
267 | - } |
|
268 | - |
|
269 | - #[\PHPUnit\Framework\Attributes\DataProvider('providesAuth')] |
|
270 | - public function testAuth(bool $expectedResult, string $user, string $password): void { |
|
271 | - if ($expectedResult) { |
|
272 | - $this->dbHandler->addServer('url1'); |
|
273 | - $this->dbHandler->addSharedSecret('url1', $password); |
|
274 | - } |
|
275 | - $result = $this->dbHandler->auth($user, $password); |
|
276 | - $this->assertEquals($expectedResult, $result); |
|
277 | - } |
|
278 | - |
|
279 | - public static function providesAuth(): array { |
|
280 | - return [ |
|
281 | - [false, 'foo', ''], |
|
282 | - [true, 'system', '123456789'], |
|
283 | - ]; |
|
284 | - } |
|
23 | + private DbHandler $dbHandler; |
|
24 | + private IL10N&MockObject $il10n; |
|
25 | + private IDBConnection $connection; |
|
26 | + private string $dbTable = 'trusted_servers'; |
|
27 | + |
|
28 | + protected function setUp(): void { |
|
29 | + parent::setUp(); |
|
30 | + |
|
31 | + $this->connection = Server::get(IDBConnection::class); |
|
32 | + $this->il10n = $this->createMock(IL10N::class); |
|
33 | + |
|
34 | + $this->dbHandler = new DbHandler( |
|
35 | + $this->connection, |
|
36 | + $this->il10n |
|
37 | + ); |
|
38 | + |
|
39 | + $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
40 | + |
|
41 | + $qResult = $query->executeQuery(); |
|
42 | + $result = $qResult->fetchAll(); |
|
43 | + $qResult->closeCursor(); |
|
44 | + $this->assertEmpty($result, 'we need to start with a empty trusted_servers table'); |
|
45 | + } |
|
46 | + |
|
47 | + protected function tearDown(): void { |
|
48 | + $query = $this->connection->getQueryBuilder()->delete($this->dbTable); |
|
49 | + $query->executeStatement() |
|
50 | + ; |
|
51 | + parent::tearDown(); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * |
|
56 | + * @param string $url passed to the method |
|
57 | + * @param string $expectedUrl the url we expect to be written to the db |
|
58 | + * @param string $expectedHash the hash value we expect to be written to the db |
|
59 | + */ |
|
60 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestAddServer')] |
|
61 | + public function testAddServer(string $url, string $expectedUrl, string $expectedHash): void { |
|
62 | + $id = $this->dbHandler->addServer($url); |
|
63 | + |
|
64 | + $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
65 | + |
|
66 | + $qResult = $query->execute(); |
|
67 | + $result = $qResult->fetchAll(); |
|
68 | + $qResult->closeCursor(); |
|
69 | + $this->assertCount(1, $result); |
|
70 | + $this->assertSame($expectedUrl, $result[0]['url']); |
|
71 | + $this->assertSame($id, (int)$result[0]['id']); |
|
72 | + $this->assertSame($expectedHash, $result[0]['url_hash']); |
|
73 | + $this->assertSame(TrustedServers::STATUS_PENDING, (int)$result[0]['status']); |
|
74 | + } |
|
75 | + |
|
76 | + public static function dataTestAddServer(): array { |
|
77 | + return [ |
|
78 | + ['http://owncloud.org', 'http://owncloud.org', sha1('owncloud.org')], |
|
79 | + ['https://owncloud.org', 'https://owncloud.org', sha1('owncloud.org')], |
|
80 | + ['http://owncloud.org/', 'http://owncloud.org', sha1('owncloud.org')], |
|
81 | + ]; |
|
82 | + } |
|
83 | + |
|
84 | + public function testRemove(): void { |
|
85 | + $id1 = $this->dbHandler->addServer('server1'); |
|
86 | + $id2 = $this->dbHandler->addServer('server2'); |
|
87 | + |
|
88 | + $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
89 | + |
|
90 | + $qResult = $query->execute(); |
|
91 | + $result = $qResult->fetchAll(); |
|
92 | + $qResult->closeCursor(); |
|
93 | + $this->assertCount(2, $result); |
|
94 | + $this->assertSame('server1', $result[0]['url']); |
|
95 | + $this->assertSame('server2', $result[1]['url']); |
|
96 | + $this->assertSame($id1, (int)$result[0]['id']); |
|
97 | + $this->assertSame($id2, (int)$result[1]['id']); |
|
98 | + |
|
99 | + $this->dbHandler->removeServer($id2); |
|
100 | + $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
101 | + |
|
102 | + $qResult = $query->execute(); |
|
103 | + $result = $qResult->fetchAll(); |
|
104 | + $qResult->closeCursor(); |
|
105 | + $this->assertCount(1, $result); |
|
106 | + $this->assertSame('server1', $result[0]['url']); |
|
107 | + $this->assertSame($id1, (int)$result[0]['id']); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + public function testGetServerById(): void { |
|
112 | + $this->dbHandler->addServer('server1'); |
|
113 | + $id = $this->dbHandler->addServer('server2'); |
|
114 | + |
|
115 | + $result = $this->dbHandler->getServerById($id); |
|
116 | + $this->assertSame('server2', $result['url']); |
|
117 | + } |
|
118 | + |
|
119 | + public function testGetAll(): void { |
|
120 | + $id1 = $this->dbHandler->addServer('server1'); |
|
121 | + $id2 = $this->dbHandler->addServer('server2'); |
|
122 | + |
|
123 | + $result = $this->dbHandler->getAllServer(); |
|
124 | + $this->assertSame(2, count($result)); |
|
125 | + $this->assertSame('server1', $result[0]['url']); |
|
126 | + $this->assertSame('server2', $result[1]['url']); |
|
127 | + $this->assertSame($id1, (int)$result[0]['id']); |
|
128 | + $this->assertSame($id2, (int)$result[1]['id']); |
|
129 | + } |
|
130 | + |
|
131 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestServerExists')] |
|
132 | + public function testServerExists(string $serverInTable, string $checkForServer, bool $expected): void { |
|
133 | + $this->dbHandler->addServer($serverInTable); |
|
134 | + $this->assertSame($expected, |
|
135 | + $this->dbHandler->serverExists($checkForServer) |
|
136 | + ); |
|
137 | + } |
|
138 | + |
|
139 | + public static function dataTestServerExists(): array { |
|
140 | + return [ |
|
141 | + ['server1', 'server1', true], |
|
142 | + ['server1', 'http://server1', true], |
|
143 | + ['server1', 'server2', false] |
|
144 | + ]; |
|
145 | + } |
|
146 | + |
|
147 | + public function XtestAddToken() { |
|
148 | + $this->dbHandler->addServer('server1'); |
|
149 | + $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
150 | + |
|
151 | + $qResult = $query->executeQuery(); |
|
152 | + $result = $qResult->fetchAll(); |
|
153 | + $qResult->closeCursor(); |
|
154 | + $this->assertCount(1, $result); |
|
155 | + $this->assertSame(null, $result[0]['token']); |
|
156 | + $this->dbHandler->addToken('http://server1', 'token'); |
|
157 | + $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
158 | + |
|
159 | + $qResult = $query->executeQuery(); |
|
160 | + $result = $qResult->fetchAll(); |
|
161 | + $qResult->closeCursor(); |
|
162 | + $this->assertCount(1, $result); |
|
163 | + $this->assertSame('token', $result[0]['token']); |
|
164 | + } |
|
165 | + |
|
166 | + public function testGetToken(): void { |
|
167 | + $this->dbHandler->addServer('server1'); |
|
168 | + $this->dbHandler->addToken('http://server1', 'token'); |
|
169 | + $this->assertSame('token', |
|
170 | + $this->dbHandler->getToken('https://server1') |
|
171 | + ); |
|
172 | + } |
|
173 | + |
|
174 | + public function XtestAddSharedSecret() { |
|
175 | + $this->dbHandler->addServer('server1'); |
|
176 | + $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
177 | + |
|
178 | + $qResult = $query->execute(); |
|
179 | + $result = $qResult->fetchAll(); |
|
180 | + $qResult->closeCursor(); |
|
181 | + $this->assertCount(1, $result); |
|
182 | + $this->assertSame(null, $result[0]['shared_secret']); |
|
183 | + $this->dbHandler->addSharedSecret('http://server1', 'secret'); |
|
184 | + $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
185 | + |
|
186 | + $qResult = $query->execute(); |
|
187 | + $result = $qResult->fetchAll(); |
|
188 | + $qResult->closeCursor(); |
|
189 | + $this->assertCount(1, $result); |
|
190 | + $this->assertSame('secret', $result[0]['shared_secret']); |
|
191 | + } |
|
192 | + |
|
193 | + public function testGetSharedSecret(): void { |
|
194 | + $this->dbHandler->addServer('server1'); |
|
195 | + $this->dbHandler->addSharedSecret('http://server1', 'secret'); |
|
196 | + $this->assertSame('secret', |
|
197 | + $this->dbHandler->getSharedSecret('https://server1') |
|
198 | + ); |
|
199 | + } |
|
200 | + |
|
201 | + public function testSetServerStatus(): void { |
|
202 | + $this->dbHandler->addServer('server1'); |
|
203 | + $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
204 | + |
|
205 | + $qResult = $query->executeQuery(); |
|
206 | + $result = $qResult->fetchAll(); |
|
207 | + $qResult->closeCursor(); |
|
208 | + $this->assertCount(1, $result); |
|
209 | + $this->assertSame(TrustedServers::STATUS_PENDING, (int)$result[0]['status']); |
|
210 | + $this->dbHandler->setServerStatus('http://server1', TrustedServers::STATUS_OK); |
|
211 | + $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
|
212 | + |
|
213 | + $qResult = $query->executeQuery(); |
|
214 | + $result = $qResult->fetchAll(); |
|
215 | + $qResult->closeCursor(); |
|
216 | + $this->assertCount(1, $result); |
|
217 | + $this->assertSame(TrustedServers::STATUS_OK, (int)$result[0]['status']); |
|
218 | + } |
|
219 | + |
|
220 | + public function testGetServerStatus(): void { |
|
221 | + $this->dbHandler->addServer('server1'); |
|
222 | + $this->dbHandler->setServerStatus('http://server1', TrustedServers::STATUS_OK); |
|
223 | + $this->assertSame(TrustedServers::STATUS_OK, |
|
224 | + $this->dbHandler->getServerStatus('https://server1') |
|
225 | + ); |
|
226 | + |
|
227 | + // test sync token |
|
228 | + $this->dbHandler->setServerStatus('http://server1', TrustedServers::STATUS_OK, 'token1234567890'); |
|
229 | + $servers = $this->dbHandler->getAllServer(); |
|
230 | + $this->assertSame('token1234567890', $servers[0]['sync_token']); |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * hash should always be computed with the normalized URL |
|
235 | + */ |
|
236 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestHash')] |
|
237 | + public function testHash(string $url, string $expected): void { |
|
238 | + $this->assertSame($expected, |
|
239 | + $this->invokePrivate($this->dbHandler, 'hash', [$url]) |
|
240 | + ); |
|
241 | + } |
|
242 | + |
|
243 | + public static function dataTestHash(): array { |
|
244 | + return [ |
|
245 | + ['server1', sha1('server1')], |
|
246 | + ['http://server1', sha1('server1')], |
|
247 | + ['https://server1', sha1('server1')], |
|
248 | + ['http://server1/', sha1('server1')], |
|
249 | + ]; |
|
250 | + } |
|
251 | + |
|
252 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestNormalizeUrl')] |
|
253 | + public function testNormalizeUrl(string $url, string $expected): void { |
|
254 | + $this->assertSame($expected, |
|
255 | + $this->invokePrivate($this->dbHandler, 'normalizeUrl', [$url]) |
|
256 | + ); |
|
257 | + } |
|
258 | + |
|
259 | + public static function dataTestNormalizeUrl(): array { |
|
260 | + return [ |
|
261 | + ['owncloud.org', 'owncloud.org'], |
|
262 | + ['http://owncloud.org', 'owncloud.org'], |
|
263 | + ['https://owncloud.org', 'owncloud.org'], |
|
264 | + ['https://owncloud.org//mycloud', 'owncloud.org/mycloud'], |
|
265 | + ['https://owncloud.org/mycloud/', 'owncloud.org/mycloud'], |
|
266 | + ]; |
|
267 | + } |
|
268 | + |
|
269 | + #[\PHPUnit\Framework\Attributes\DataProvider('providesAuth')] |
|
270 | + public function testAuth(bool $expectedResult, string $user, string $password): void { |
|
271 | + if ($expectedResult) { |
|
272 | + $this->dbHandler->addServer('url1'); |
|
273 | + $this->dbHandler->addSharedSecret('url1', $password); |
|
274 | + } |
|
275 | + $result = $this->dbHandler->auth($user, $password); |
|
276 | + $this->assertEquals($expectedResult, $result); |
|
277 | + } |
|
278 | + |
|
279 | + public static function providesAuth(): array { |
|
280 | + return [ |
|
281 | + [false, 'foo', ''], |
|
282 | + [true, 'system', '123456789'], |
|
283 | + ]; |
|
284 | + } |
|
285 | 285 | } |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | $qResult->closeCursor(); |
69 | 69 | $this->assertCount(1, $result); |
70 | 70 | $this->assertSame($expectedUrl, $result[0]['url']); |
71 | - $this->assertSame($id, (int)$result[0]['id']); |
|
71 | + $this->assertSame($id, (int) $result[0]['id']); |
|
72 | 72 | $this->assertSame($expectedHash, $result[0]['url_hash']); |
73 | - $this->assertSame(TrustedServers::STATUS_PENDING, (int)$result[0]['status']); |
|
73 | + $this->assertSame(TrustedServers::STATUS_PENDING, (int) $result[0]['status']); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | public static function dataTestAddServer(): array { |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | $this->assertCount(2, $result); |
94 | 94 | $this->assertSame('server1', $result[0]['url']); |
95 | 95 | $this->assertSame('server2', $result[1]['url']); |
96 | - $this->assertSame($id1, (int)$result[0]['id']); |
|
97 | - $this->assertSame($id2, (int)$result[1]['id']); |
|
96 | + $this->assertSame($id1, (int) $result[0]['id']); |
|
97 | + $this->assertSame($id2, (int) $result[1]['id']); |
|
98 | 98 | |
99 | 99 | $this->dbHandler->removeServer($id2); |
100 | 100 | $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | $qResult->closeCursor(); |
105 | 105 | $this->assertCount(1, $result); |
106 | 106 | $this->assertSame('server1', $result[0]['url']); |
107 | - $this->assertSame($id1, (int)$result[0]['id']); |
|
107 | + $this->assertSame($id1, (int) $result[0]['id']); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | $this->assertSame(2, count($result)); |
125 | 125 | $this->assertSame('server1', $result[0]['url']); |
126 | 126 | $this->assertSame('server2', $result[1]['url']); |
127 | - $this->assertSame($id1, (int)$result[0]['id']); |
|
128 | - $this->assertSame($id2, (int)$result[1]['id']); |
|
127 | + $this->assertSame($id1, (int) $result[0]['id']); |
|
128 | + $this->assertSame($id2, (int) $result[1]['id']); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | #[\PHPUnit\Framework\Attributes\DataProvider('dataTestServerExists')] |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | $result = $qResult->fetchAll(); |
207 | 207 | $qResult->closeCursor(); |
208 | 208 | $this->assertCount(1, $result); |
209 | - $this->assertSame(TrustedServers::STATUS_PENDING, (int)$result[0]['status']); |
|
209 | + $this->assertSame(TrustedServers::STATUS_PENDING, (int) $result[0]['status']); |
|
210 | 210 | $this->dbHandler->setServerStatus('http://server1', TrustedServers::STATUS_OK); |
211 | 211 | $query = $this->connection->getQueryBuilder()->select('*')->from($this->dbTable); |
212 | 212 | |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | $result = $qResult->fetchAll(); |
215 | 215 | $qResult->closeCursor(); |
216 | 216 | $this->assertCount(1, $result); |
217 | - $this->assertSame(TrustedServers::STATUS_OK, (int)$result[0]['status']); |
|
217 | + $this->assertSame(TrustedServers::STATUS_OK, (int) $result[0]['status']); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | public function testGetServerStatus(): void { |
@@ -33,230 +33,230 @@ |
||
33 | 33 | */ |
34 | 34 | class GetSharedSecretTest extends TestCase { |
35 | 35 | |
36 | - private MockObject&IClient $httpClient; |
|
37 | - private MockObject&IClientService $httpClientService; |
|
38 | - private MockObject&IJobList $jobList; |
|
39 | - private MockObject&IURLGenerator $urlGenerator; |
|
40 | - private MockObject&TrustedServers $trustedServers; |
|
41 | - private MockObject&LoggerInterface $logger; |
|
42 | - private MockObject&IResponse $response; |
|
43 | - private MockObject&IDiscoveryService $discoverService; |
|
44 | - private MockObject&ITimeFactory $timeFactory; |
|
45 | - private MockObject&IConfig $config; |
|
46 | - |
|
47 | - private GetSharedSecret $getSharedSecret; |
|
48 | - |
|
49 | - protected function setUp(): void { |
|
50 | - parent::setUp(); |
|
51 | - |
|
52 | - $this->httpClientService = $this->createMock(IClientService::class); |
|
53 | - $this->httpClient = $this->getMockBuilder(IClient::class)->getMock(); |
|
54 | - $this->jobList = $this->getMockBuilder(IJobList::class)->getMock(); |
|
55 | - $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock(); |
|
56 | - $this->trustedServers = $this->getMockBuilder(TrustedServers::class) |
|
57 | - ->disableOriginalConstructor()->getMock(); |
|
58 | - $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); |
|
59 | - $this->response = $this->getMockBuilder(IResponse::class)->getMock(); |
|
60 | - $this->discoverService = $this->getMockBuilder(IDiscoveryService::class)->getMock(); |
|
61 | - $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
62 | - $this->config = $this->createMock(IConfig::class); |
|
63 | - |
|
64 | - $this->discoverService->expects($this->any())->method('discover')->willReturn([]); |
|
65 | - $this->httpClientService->expects($this->any())->method('newClient')->willReturn($this->httpClient); |
|
66 | - |
|
67 | - $this->getSharedSecret = new GetSharedSecret( |
|
68 | - $this->httpClientService, |
|
69 | - $this->urlGenerator, |
|
70 | - $this->jobList, |
|
71 | - $this->trustedServers, |
|
72 | - $this->logger, |
|
73 | - $this->discoverService, |
|
74 | - $this->timeFactory, |
|
75 | - $this->config, |
|
76 | - ); |
|
77 | - } |
|
78 | - |
|
79 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestExecute')] |
|
80 | - public function testExecute(bool $isTrustedServer, bool $retainBackgroundJob): void { |
|
81 | - /** @var GetSharedSecret&MockObject $getSharedSecret */ |
|
82 | - $getSharedSecret = $this->getMockBuilder(GetSharedSecret::class) |
|
83 | - ->setConstructorArgs( |
|
84 | - [ |
|
85 | - $this->httpClientService, |
|
86 | - $this->urlGenerator, |
|
87 | - $this->jobList, |
|
88 | - $this->trustedServers, |
|
89 | - $this->logger, |
|
90 | - $this->discoverService, |
|
91 | - $this->timeFactory, |
|
92 | - $this->config, |
|
93 | - ] |
|
94 | - ) |
|
95 | - ->onlyMethods(['parentStart']) |
|
96 | - ->getMock(); |
|
97 | - self::invokePrivate($getSharedSecret, 'argument', [['url' => 'url', 'token' => 'token']]); |
|
98 | - |
|
99 | - $this->trustedServers->expects($this->once())->method('isTrustedServer') |
|
100 | - ->with('url')->willReturn($isTrustedServer); |
|
101 | - if ($isTrustedServer) { |
|
102 | - $getSharedSecret->expects($this->once())->method('parentStart'); |
|
103 | - } else { |
|
104 | - $getSharedSecret->expects($this->never())->method('parentStart'); |
|
105 | - } |
|
106 | - self::invokePrivate($getSharedSecret, 'retainJob', [$retainBackgroundJob]); |
|
107 | - $this->jobList->expects($this->once())->method('remove'); |
|
108 | - |
|
109 | - $this->timeFactory->method('getTime')->willReturn(42); |
|
110 | - |
|
111 | - if ($retainBackgroundJob) { |
|
112 | - $this->jobList->expects($this->once()) |
|
113 | - ->method('add') |
|
114 | - ->with( |
|
115 | - GetSharedSecret::class, |
|
116 | - [ |
|
117 | - 'url' => 'url', |
|
118 | - 'token' => 'token', |
|
119 | - 'created' => 42, |
|
120 | - ] |
|
121 | - ); |
|
122 | - } else { |
|
123 | - $this->jobList->expects($this->never())->method('add'); |
|
124 | - } |
|
125 | - |
|
126 | - $getSharedSecret->start($this->jobList); |
|
127 | - } |
|
128 | - |
|
129 | - public static function dataTestExecute(): array { |
|
130 | - return [ |
|
131 | - [true, true], |
|
132 | - [true, false], |
|
133 | - [false, false], |
|
134 | - ]; |
|
135 | - } |
|
136 | - |
|
137 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestRun')] |
|
138 | - public function testRun(int $statusCode): void { |
|
139 | - $target = 'targetURL'; |
|
140 | - $source = 'sourceURL'; |
|
141 | - $token = 'token'; |
|
142 | - |
|
143 | - $argument = ['url' => $target, 'token' => $token]; |
|
144 | - |
|
145 | - $this->timeFactory->method('getTime') |
|
146 | - ->willReturn(42); |
|
147 | - |
|
148 | - $this->urlGenerator->expects($this->once())->method('getAbsoluteURL')->with('/') |
|
149 | - ->willReturn($source); |
|
150 | - $this->httpClient->expects($this->once())->method('get') |
|
151 | - ->with( |
|
152 | - $target . '/ocs/v2.php/apps/federation/api/v1/shared-secret', |
|
153 | - [ |
|
154 | - 'query' => [ |
|
155 | - 'url' => $source, |
|
156 | - 'token' => $token, |
|
157 | - 'format' => 'json', |
|
158 | - ], |
|
159 | - 'timeout' => 3, |
|
160 | - 'connect_timeout' => 3, |
|
161 | - 'verify' => true, |
|
162 | - ] |
|
163 | - )->willReturn($this->response); |
|
164 | - |
|
165 | - $this->response->expects($this->once())->method('getStatusCode') |
|
166 | - ->willReturn($statusCode); |
|
167 | - |
|
168 | - if ($statusCode === Http::STATUS_OK) { |
|
169 | - $this->response->expects($this->once())->method('getBody') |
|
170 | - ->willReturn('{"ocs":{"data":{"sharedSecret":"secret"}}}'); |
|
171 | - $this->trustedServers->expects($this->once())->method('addSharedSecret') |
|
172 | - ->with($target, 'secret'); |
|
173 | - } else { |
|
174 | - $this->trustedServers->expects($this->never())->method('addSharedSecret'); |
|
175 | - } |
|
176 | - |
|
177 | - self::invokePrivate($this->getSharedSecret, 'run', [$argument]); |
|
178 | - if ( |
|
179 | - $statusCode !== Http::STATUS_OK |
|
180 | - && $statusCode !== Http::STATUS_FORBIDDEN |
|
181 | - ) { |
|
182 | - $this->assertTrue(self::invokePrivate($this->getSharedSecret, 'retainJob')); |
|
183 | - } else { |
|
184 | - $this->assertFalse(self::invokePrivate($this->getSharedSecret, 'retainJob')); |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - public static function dataTestRun(): array { |
|
189 | - return [ |
|
190 | - [Http::STATUS_OK], |
|
191 | - [Http::STATUS_FORBIDDEN], |
|
192 | - [Http::STATUS_CONFLICT], |
|
193 | - ]; |
|
194 | - } |
|
195 | - |
|
196 | - public function testRunExpired(): void { |
|
197 | - $target = 'targetURL'; |
|
198 | - $source = 'sourceURL'; |
|
199 | - $token = 'token'; |
|
200 | - $created = 42; |
|
201 | - |
|
202 | - $argument = [ |
|
203 | - 'url' => $target, |
|
204 | - 'token' => $token, |
|
205 | - 'created' => $created, |
|
206 | - ]; |
|
207 | - |
|
208 | - $this->urlGenerator->expects($this->once()) |
|
209 | - ->method('getAbsoluteURL') |
|
210 | - ->with('/') |
|
211 | - ->willReturn($source); |
|
212 | - |
|
213 | - $this->timeFactory->method('getTime') |
|
214 | - ->willReturn($created + 2592000 + 1); |
|
215 | - |
|
216 | - $this->trustedServers->expects($this->once()) |
|
217 | - ->method('setServerStatus') |
|
218 | - ->with( |
|
219 | - $target, |
|
220 | - TrustedServers::STATUS_FAILURE |
|
221 | - ); |
|
222 | - |
|
223 | - self::invokePrivate($this->getSharedSecret, 'run', [$argument]); |
|
224 | - } |
|
225 | - |
|
226 | - public function testRunConnectionError(): void { |
|
227 | - $target = 'targetURL'; |
|
228 | - $source = 'sourceURL'; |
|
229 | - $token = 'token'; |
|
230 | - |
|
231 | - $argument = ['url' => $target, 'token' => $token]; |
|
232 | - |
|
233 | - $this->timeFactory->method('getTime') |
|
234 | - ->willReturn(42); |
|
235 | - |
|
236 | - $this->urlGenerator |
|
237 | - ->expects($this->once()) |
|
238 | - ->method('getAbsoluteURL') |
|
239 | - ->with('/') |
|
240 | - ->willReturn($source); |
|
241 | - $this->httpClient->expects($this->once())->method('get') |
|
242 | - ->with( |
|
243 | - $target . '/ocs/v2.php/apps/federation/api/v1/shared-secret', |
|
244 | - [ |
|
245 | - 'query' => [ |
|
246 | - 'url' => $source, |
|
247 | - 'token' => $token, |
|
248 | - 'format' => 'json', |
|
249 | - ], |
|
250 | - 'timeout' => 3, |
|
251 | - 'connect_timeout' => 3, |
|
252 | - 'verify' => true, |
|
253 | - ] |
|
254 | - )->willThrowException($this->createMock(ConnectException::class)); |
|
255 | - |
|
256 | - $this->trustedServers->expects($this->never())->method('addSharedSecret'); |
|
257 | - |
|
258 | - self::invokePrivate($this->getSharedSecret, 'run', [$argument]); |
|
259 | - |
|
260 | - $this->assertTrue(self::invokePrivate($this->getSharedSecret, 'retainJob')); |
|
261 | - } |
|
36 | + private MockObject&IClient $httpClient; |
|
37 | + private MockObject&IClientService $httpClientService; |
|
38 | + private MockObject&IJobList $jobList; |
|
39 | + private MockObject&IURLGenerator $urlGenerator; |
|
40 | + private MockObject&TrustedServers $trustedServers; |
|
41 | + private MockObject&LoggerInterface $logger; |
|
42 | + private MockObject&IResponse $response; |
|
43 | + private MockObject&IDiscoveryService $discoverService; |
|
44 | + private MockObject&ITimeFactory $timeFactory; |
|
45 | + private MockObject&IConfig $config; |
|
46 | + |
|
47 | + private GetSharedSecret $getSharedSecret; |
|
48 | + |
|
49 | + protected function setUp(): void { |
|
50 | + parent::setUp(); |
|
51 | + |
|
52 | + $this->httpClientService = $this->createMock(IClientService::class); |
|
53 | + $this->httpClient = $this->getMockBuilder(IClient::class)->getMock(); |
|
54 | + $this->jobList = $this->getMockBuilder(IJobList::class)->getMock(); |
|
55 | + $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock(); |
|
56 | + $this->trustedServers = $this->getMockBuilder(TrustedServers::class) |
|
57 | + ->disableOriginalConstructor()->getMock(); |
|
58 | + $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); |
|
59 | + $this->response = $this->getMockBuilder(IResponse::class)->getMock(); |
|
60 | + $this->discoverService = $this->getMockBuilder(IDiscoveryService::class)->getMock(); |
|
61 | + $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
62 | + $this->config = $this->createMock(IConfig::class); |
|
63 | + |
|
64 | + $this->discoverService->expects($this->any())->method('discover')->willReturn([]); |
|
65 | + $this->httpClientService->expects($this->any())->method('newClient')->willReturn($this->httpClient); |
|
66 | + |
|
67 | + $this->getSharedSecret = new GetSharedSecret( |
|
68 | + $this->httpClientService, |
|
69 | + $this->urlGenerator, |
|
70 | + $this->jobList, |
|
71 | + $this->trustedServers, |
|
72 | + $this->logger, |
|
73 | + $this->discoverService, |
|
74 | + $this->timeFactory, |
|
75 | + $this->config, |
|
76 | + ); |
|
77 | + } |
|
78 | + |
|
79 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestExecute')] |
|
80 | + public function testExecute(bool $isTrustedServer, bool $retainBackgroundJob): void { |
|
81 | + /** @var GetSharedSecret&MockObject $getSharedSecret */ |
|
82 | + $getSharedSecret = $this->getMockBuilder(GetSharedSecret::class) |
|
83 | + ->setConstructorArgs( |
|
84 | + [ |
|
85 | + $this->httpClientService, |
|
86 | + $this->urlGenerator, |
|
87 | + $this->jobList, |
|
88 | + $this->trustedServers, |
|
89 | + $this->logger, |
|
90 | + $this->discoverService, |
|
91 | + $this->timeFactory, |
|
92 | + $this->config, |
|
93 | + ] |
|
94 | + ) |
|
95 | + ->onlyMethods(['parentStart']) |
|
96 | + ->getMock(); |
|
97 | + self::invokePrivate($getSharedSecret, 'argument', [['url' => 'url', 'token' => 'token']]); |
|
98 | + |
|
99 | + $this->trustedServers->expects($this->once())->method('isTrustedServer') |
|
100 | + ->with('url')->willReturn($isTrustedServer); |
|
101 | + if ($isTrustedServer) { |
|
102 | + $getSharedSecret->expects($this->once())->method('parentStart'); |
|
103 | + } else { |
|
104 | + $getSharedSecret->expects($this->never())->method('parentStart'); |
|
105 | + } |
|
106 | + self::invokePrivate($getSharedSecret, 'retainJob', [$retainBackgroundJob]); |
|
107 | + $this->jobList->expects($this->once())->method('remove'); |
|
108 | + |
|
109 | + $this->timeFactory->method('getTime')->willReturn(42); |
|
110 | + |
|
111 | + if ($retainBackgroundJob) { |
|
112 | + $this->jobList->expects($this->once()) |
|
113 | + ->method('add') |
|
114 | + ->with( |
|
115 | + GetSharedSecret::class, |
|
116 | + [ |
|
117 | + 'url' => 'url', |
|
118 | + 'token' => 'token', |
|
119 | + 'created' => 42, |
|
120 | + ] |
|
121 | + ); |
|
122 | + } else { |
|
123 | + $this->jobList->expects($this->never())->method('add'); |
|
124 | + } |
|
125 | + |
|
126 | + $getSharedSecret->start($this->jobList); |
|
127 | + } |
|
128 | + |
|
129 | + public static function dataTestExecute(): array { |
|
130 | + return [ |
|
131 | + [true, true], |
|
132 | + [true, false], |
|
133 | + [false, false], |
|
134 | + ]; |
|
135 | + } |
|
136 | + |
|
137 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestRun')] |
|
138 | + public function testRun(int $statusCode): void { |
|
139 | + $target = 'targetURL'; |
|
140 | + $source = 'sourceURL'; |
|
141 | + $token = 'token'; |
|
142 | + |
|
143 | + $argument = ['url' => $target, 'token' => $token]; |
|
144 | + |
|
145 | + $this->timeFactory->method('getTime') |
|
146 | + ->willReturn(42); |
|
147 | + |
|
148 | + $this->urlGenerator->expects($this->once())->method('getAbsoluteURL')->with('/') |
|
149 | + ->willReturn($source); |
|
150 | + $this->httpClient->expects($this->once())->method('get') |
|
151 | + ->with( |
|
152 | + $target . '/ocs/v2.php/apps/federation/api/v1/shared-secret', |
|
153 | + [ |
|
154 | + 'query' => [ |
|
155 | + 'url' => $source, |
|
156 | + 'token' => $token, |
|
157 | + 'format' => 'json', |
|
158 | + ], |
|
159 | + 'timeout' => 3, |
|
160 | + 'connect_timeout' => 3, |
|
161 | + 'verify' => true, |
|
162 | + ] |
|
163 | + )->willReturn($this->response); |
|
164 | + |
|
165 | + $this->response->expects($this->once())->method('getStatusCode') |
|
166 | + ->willReturn($statusCode); |
|
167 | + |
|
168 | + if ($statusCode === Http::STATUS_OK) { |
|
169 | + $this->response->expects($this->once())->method('getBody') |
|
170 | + ->willReturn('{"ocs":{"data":{"sharedSecret":"secret"}}}'); |
|
171 | + $this->trustedServers->expects($this->once())->method('addSharedSecret') |
|
172 | + ->with($target, 'secret'); |
|
173 | + } else { |
|
174 | + $this->trustedServers->expects($this->never())->method('addSharedSecret'); |
|
175 | + } |
|
176 | + |
|
177 | + self::invokePrivate($this->getSharedSecret, 'run', [$argument]); |
|
178 | + if ( |
|
179 | + $statusCode !== Http::STATUS_OK |
|
180 | + && $statusCode !== Http::STATUS_FORBIDDEN |
|
181 | + ) { |
|
182 | + $this->assertTrue(self::invokePrivate($this->getSharedSecret, 'retainJob')); |
|
183 | + } else { |
|
184 | + $this->assertFalse(self::invokePrivate($this->getSharedSecret, 'retainJob')); |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + public static function dataTestRun(): array { |
|
189 | + return [ |
|
190 | + [Http::STATUS_OK], |
|
191 | + [Http::STATUS_FORBIDDEN], |
|
192 | + [Http::STATUS_CONFLICT], |
|
193 | + ]; |
|
194 | + } |
|
195 | + |
|
196 | + public function testRunExpired(): void { |
|
197 | + $target = 'targetURL'; |
|
198 | + $source = 'sourceURL'; |
|
199 | + $token = 'token'; |
|
200 | + $created = 42; |
|
201 | + |
|
202 | + $argument = [ |
|
203 | + 'url' => $target, |
|
204 | + 'token' => $token, |
|
205 | + 'created' => $created, |
|
206 | + ]; |
|
207 | + |
|
208 | + $this->urlGenerator->expects($this->once()) |
|
209 | + ->method('getAbsoluteURL') |
|
210 | + ->with('/') |
|
211 | + ->willReturn($source); |
|
212 | + |
|
213 | + $this->timeFactory->method('getTime') |
|
214 | + ->willReturn($created + 2592000 + 1); |
|
215 | + |
|
216 | + $this->trustedServers->expects($this->once()) |
|
217 | + ->method('setServerStatus') |
|
218 | + ->with( |
|
219 | + $target, |
|
220 | + TrustedServers::STATUS_FAILURE |
|
221 | + ); |
|
222 | + |
|
223 | + self::invokePrivate($this->getSharedSecret, 'run', [$argument]); |
|
224 | + } |
|
225 | + |
|
226 | + public function testRunConnectionError(): void { |
|
227 | + $target = 'targetURL'; |
|
228 | + $source = 'sourceURL'; |
|
229 | + $token = 'token'; |
|
230 | + |
|
231 | + $argument = ['url' => $target, 'token' => $token]; |
|
232 | + |
|
233 | + $this->timeFactory->method('getTime') |
|
234 | + ->willReturn(42); |
|
235 | + |
|
236 | + $this->urlGenerator |
|
237 | + ->expects($this->once()) |
|
238 | + ->method('getAbsoluteURL') |
|
239 | + ->with('/') |
|
240 | + ->willReturn($source); |
|
241 | + $this->httpClient->expects($this->once())->method('get') |
|
242 | + ->with( |
|
243 | + $target . '/ocs/v2.php/apps/federation/api/v1/shared-secret', |
|
244 | + [ |
|
245 | + 'query' => [ |
|
246 | + 'url' => $source, |
|
247 | + 'token' => $token, |
|
248 | + 'format' => 'json', |
|
249 | + ], |
|
250 | + 'timeout' => 3, |
|
251 | + 'connect_timeout' => 3, |
|
252 | + 'verify' => true, |
|
253 | + ] |
|
254 | + )->willThrowException($this->createMock(ConnectException::class)); |
|
255 | + |
|
256 | + $this->trustedServers->expects($this->never())->method('addSharedSecret'); |
|
257 | + |
|
258 | + self::invokePrivate($this->getSharedSecret, 'run', [$argument]); |
|
259 | + |
|
260 | + $this->assertTrue(self::invokePrivate($this->getSharedSecret, 'retainJob')); |
|
261 | + } |
|
262 | 262 | } |
@@ -25,219 +25,219 @@ |
||
25 | 25 | use Test\TestCase; |
26 | 26 | |
27 | 27 | class RequestSharedSecretTest extends TestCase { |
28 | - private IClientService&MockObject $httpClientService; |
|
29 | - private IClient&MockObject $httpClient; |
|
30 | - private IJobList&MockObject $jobList; |
|
31 | - private IURLGenerator&MockObject $urlGenerator; |
|
32 | - private TrustedServers&MockObject $trustedServers; |
|
33 | - private IResponse&MockObject $response; |
|
34 | - private IDiscoveryService&MockObject $discoveryService; |
|
35 | - private LoggerInterface&MockObject $logger; |
|
36 | - private ITimeFactory&MockObject $timeFactory; |
|
37 | - private IConfig&MockObject $config; |
|
38 | - private RequestSharedSecret $requestSharedSecret; |
|
39 | - |
|
40 | - protected function setUp(): void { |
|
41 | - parent::setUp(); |
|
42 | - |
|
43 | - $this->httpClientService = $this->createMock(IClientService::class); |
|
44 | - $this->httpClient = $this->createMock(IClient::class); |
|
45 | - $this->jobList = $this->createMock(IJobList::class); |
|
46 | - $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
47 | - $this->trustedServers = $this->createMock(TrustedServers::class); |
|
48 | - $this->response = $this->createMock(IResponse::class); |
|
49 | - $this->discoveryService = $this->createMock(IDiscoveryService::class); |
|
50 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
51 | - $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
52 | - $this->config = $this->createMock(IConfig::class); |
|
53 | - |
|
54 | - $this->discoveryService->expects($this->any())->method('discover')->willReturn([]); |
|
55 | - $this->httpClientService->expects($this->any())->method('newClient')->willReturn($this->httpClient); |
|
56 | - |
|
57 | - $this->requestSharedSecret = new RequestSharedSecret( |
|
58 | - $this->httpClientService, |
|
59 | - $this->urlGenerator, |
|
60 | - $this->jobList, |
|
61 | - $this->trustedServers, |
|
62 | - $this->discoveryService, |
|
63 | - $this->logger, |
|
64 | - $this->timeFactory, |
|
65 | - $this->config, |
|
66 | - ); |
|
67 | - } |
|
68 | - |
|
69 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestStart')] |
|
70 | - public function testStart(bool $isTrustedServer, bool $retainBackgroundJob): void { |
|
71 | - /** @var RequestSharedSecret&MockObject $requestSharedSecret */ |
|
72 | - $requestSharedSecret = $this->getMockBuilder(RequestSharedSecret::class) |
|
73 | - ->setConstructorArgs( |
|
74 | - [ |
|
75 | - $this->httpClientService, |
|
76 | - $this->urlGenerator, |
|
77 | - $this->jobList, |
|
78 | - $this->trustedServers, |
|
79 | - $this->discoveryService, |
|
80 | - $this->logger, |
|
81 | - $this->timeFactory, |
|
82 | - $this->config, |
|
83 | - ] |
|
84 | - ) |
|
85 | - ->onlyMethods(['parentStart']) |
|
86 | - ->getMock(); |
|
87 | - self::invokePrivate($requestSharedSecret, 'argument', [['url' => 'url', 'token' => 'token']]); |
|
88 | - |
|
89 | - $this->trustedServers->expects($this->once())->method('isTrustedServer') |
|
90 | - ->with('url')->willReturn($isTrustedServer); |
|
91 | - if ($isTrustedServer) { |
|
92 | - $requestSharedSecret->expects($this->once())->method('parentStart'); |
|
93 | - } else { |
|
94 | - $requestSharedSecret->expects($this->never())->method('parentStart'); |
|
95 | - } |
|
96 | - self::invokePrivate($requestSharedSecret, 'retainJob', [$retainBackgroundJob]); |
|
97 | - $this->jobList->expects($this->once())->method('remove'); |
|
98 | - |
|
99 | - $this->timeFactory->method('getTime')->willReturn(42); |
|
100 | - |
|
101 | - if ($retainBackgroundJob) { |
|
102 | - $this->jobList->expects($this->once()) |
|
103 | - ->method('add') |
|
104 | - ->with( |
|
105 | - RequestSharedSecret::class, |
|
106 | - [ |
|
107 | - 'url' => 'url', |
|
108 | - 'token' => 'token', |
|
109 | - 'created' => 42, |
|
110 | - 'attempt' => 1, |
|
111 | - ] |
|
112 | - ); |
|
113 | - } else { |
|
114 | - $this->jobList->expects($this->never())->method('add'); |
|
115 | - } |
|
116 | - |
|
117 | - $requestSharedSecret->start($this->jobList); |
|
118 | - } |
|
119 | - |
|
120 | - public static function dataTestStart(): array { |
|
121 | - return [ |
|
122 | - [true, true], |
|
123 | - [true, false], |
|
124 | - [false, false], |
|
125 | - ]; |
|
126 | - } |
|
127 | - |
|
128 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestRun')] |
|
129 | - public function testRun(int $statusCode, int $attempt = 0): void { |
|
130 | - $target = 'targetURL'; |
|
131 | - $source = 'sourceURL'; |
|
132 | - $token = 'token'; |
|
133 | - |
|
134 | - $argument = ['url' => $target, 'token' => $token, 'attempt' => $attempt]; |
|
135 | - |
|
136 | - $this->timeFactory->method('getTime')->willReturn(42); |
|
137 | - |
|
138 | - $this->urlGenerator->expects($this->once())->method('getAbsoluteURL')->with('/') |
|
139 | - ->willReturn($source); |
|
140 | - $this->httpClient->expects($this->once())->method('post') |
|
141 | - ->with( |
|
142 | - $target . '/ocs/v2.php/apps/federation/api/v1/request-shared-secret', |
|
143 | - [ |
|
144 | - 'body' => [ |
|
145 | - 'url' => $source, |
|
146 | - 'token' => $token, |
|
147 | - 'format' => 'json', |
|
148 | - ], |
|
149 | - 'timeout' => 3, |
|
150 | - 'connect_timeout' => 3, |
|
151 | - 'verify' => true, |
|
152 | - ] |
|
153 | - )->willReturn($this->response); |
|
154 | - |
|
155 | - $this->response->expects($this->once())->method('getStatusCode') |
|
156 | - ->willReturn($statusCode); |
|
157 | - |
|
158 | - self::invokePrivate($this->requestSharedSecret, 'run', [$argument]); |
|
159 | - if ( |
|
160 | - $statusCode !== Http::STATUS_OK |
|
161 | - && ($statusCode !== Http::STATUS_FORBIDDEN || $attempt < 5) |
|
162 | - ) { |
|
163 | - $this->assertTrue(self::invokePrivate($this->requestSharedSecret, 'retainJob')); |
|
164 | - } else { |
|
165 | - $this->assertFalse(self::invokePrivate($this->requestSharedSecret, 'retainJob')); |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - public static function dataTestRun(): array { |
|
170 | - return [ |
|
171 | - [Http::STATUS_OK], |
|
172 | - [Http::STATUS_FORBIDDEN, 5], |
|
173 | - [Http::STATUS_FORBIDDEN], |
|
174 | - [Http::STATUS_CONFLICT], |
|
175 | - ]; |
|
176 | - } |
|
177 | - |
|
178 | - public function testRunExpired(): void { |
|
179 | - $target = 'targetURL'; |
|
180 | - $source = 'sourceURL'; |
|
181 | - $token = 'token'; |
|
182 | - $created = 42; |
|
183 | - |
|
184 | - $argument = [ |
|
185 | - 'url' => $target, |
|
186 | - 'token' => $token, |
|
187 | - 'created' => $created, |
|
188 | - ]; |
|
189 | - |
|
190 | - $this->urlGenerator->expects($this->once()) |
|
191 | - ->method('getAbsoluteURL') |
|
192 | - ->with('/') |
|
193 | - ->willReturn($source); |
|
194 | - |
|
195 | - $this->timeFactory->method('getTime') |
|
196 | - ->willReturn($created + 2592000 + 1); |
|
197 | - |
|
198 | - $this->trustedServers->expects($this->once()) |
|
199 | - ->method('setServerStatus') |
|
200 | - ->with( |
|
201 | - $target, |
|
202 | - TrustedServers::STATUS_FAILURE |
|
203 | - ); |
|
204 | - |
|
205 | - self::invokePrivate($this->requestSharedSecret, 'run', [$argument]); |
|
206 | - } |
|
207 | - |
|
208 | - public function testRunConnectionError(): void { |
|
209 | - $target = 'targetURL'; |
|
210 | - $source = 'sourceURL'; |
|
211 | - $token = 'token'; |
|
212 | - |
|
213 | - $argument = ['url' => $target, 'token' => $token]; |
|
214 | - |
|
215 | - $this->timeFactory->method('getTime')->willReturn(42); |
|
216 | - |
|
217 | - $this->urlGenerator |
|
218 | - ->expects($this->once()) |
|
219 | - ->method('getAbsoluteURL') |
|
220 | - ->with('/') |
|
221 | - ->willReturn($source); |
|
222 | - |
|
223 | - $this->httpClient |
|
224 | - ->expects($this->once()) |
|
225 | - ->method('post') |
|
226 | - ->with( |
|
227 | - $target . '/ocs/v2.php/apps/federation/api/v1/request-shared-secret', |
|
228 | - [ |
|
229 | - 'body' => [ |
|
230 | - 'url' => $source, |
|
231 | - 'token' => $token, |
|
232 | - 'format' => 'json', |
|
233 | - ], |
|
234 | - 'timeout' => 3, |
|
235 | - 'connect_timeout' => 3, |
|
236 | - 'verify' => true, |
|
237 | - ] |
|
238 | - )->willThrowException($this->createMock(ConnectException::class)); |
|
239 | - |
|
240 | - self::invokePrivate($this->requestSharedSecret, 'run', [$argument]); |
|
241 | - $this->assertTrue(self::invokePrivate($this->requestSharedSecret, 'retainJob')); |
|
242 | - } |
|
28 | + private IClientService&MockObject $httpClientService; |
|
29 | + private IClient&MockObject $httpClient; |
|
30 | + private IJobList&MockObject $jobList; |
|
31 | + private IURLGenerator&MockObject $urlGenerator; |
|
32 | + private TrustedServers&MockObject $trustedServers; |
|
33 | + private IResponse&MockObject $response; |
|
34 | + private IDiscoveryService&MockObject $discoveryService; |
|
35 | + private LoggerInterface&MockObject $logger; |
|
36 | + private ITimeFactory&MockObject $timeFactory; |
|
37 | + private IConfig&MockObject $config; |
|
38 | + private RequestSharedSecret $requestSharedSecret; |
|
39 | + |
|
40 | + protected function setUp(): void { |
|
41 | + parent::setUp(); |
|
42 | + |
|
43 | + $this->httpClientService = $this->createMock(IClientService::class); |
|
44 | + $this->httpClient = $this->createMock(IClient::class); |
|
45 | + $this->jobList = $this->createMock(IJobList::class); |
|
46 | + $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
47 | + $this->trustedServers = $this->createMock(TrustedServers::class); |
|
48 | + $this->response = $this->createMock(IResponse::class); |
|
49 | + $this->discoveryService = $this->createMock(IDiscoveryService::class); |
|
50 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
51 | + $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
52 | + $this->config = $this->createMock(IConfig::class); |
|
53 | + |
|
54 | + $this->discoveryService->expects($this->any())->method('discover')->willReturn([]); |
|
55 | + $this->httpClientService->expects($this->any())->method('newClient')->willReturn($this->httpClient); |
|
56 | + |
|
57 | + $this->requestSharedSecret = new RequestSharedSecret( |
|
58 | + $this->httpClientService, |
|
59 | + $this->urlGenerator, |
|
60 | + $this->jobList, |
|
61 | + $this->trustedServers, |
|
62 | + $this->discoveryService, |
|
63 | + $this->logger, |
|
64 | + $this->timeFactory, |
|
65 | + $this->config, |
|
66 | + ); |
|
67 | + } |
|
68 | + |
|
69 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestStart')] |
|
70 | + public function testStart(bool $isTrustedServer, bool $retainBackgroundJob): void { |
|
71 | + /** @var RequestSharedSecret&MockObject $requestSharedSecret */ |
|
72 | + $requestSharedSecret = $this->getMockBuilder(RequestSharedSecret::class) |
|
73 | + ->setConstructorArgs( |
|
74 | + [ |
|
75 | + $this->httpClientService, |
|
76 | + $this->urlGenerator, |
|
77 | + $this->jobList, |
|
78 | + $this->trustedServers, |
|
79 | + $this->discoveryService, |
|
80 | + $this->logger, |
|
81 | + $this->timeFactory, |
|
82 | + $this->config, |
|
83 | + ] |
|
84 | + ) |
|
85 | + ->onlyMethods(['parentStart']) |
|
86 | + ->getMock(); |
|
87 | + self::invokePrivate($requestSharedSecret, 'argument', [['url' => 'url', 'token' => 'token']]); |
|
88 | + |
|
89 | + $this->trustedServers->expects($this->once())->method('isTrustedServer') |
|
90 | + ->with('url')->willReturn($isTrustedServer); |
|
91 | + if ($isTrustedServer) { |
|
92 | + $requestSharedSecret->expects($this->once())->method('parentStart'); |
|
93 | + } else { |
|
94 | + $requestSharedSecret->expects($this->never())->method('parentStart'); |
|
95 | + } |
|
96 | + self::invokePrivate($requestSharedSecret, 'retainJob', [$retainBackgroundJob]); |
|
97 | + $this->jobList->expects($this->once())->method('remove'); |
|
98 | + |
|
99 | + $this->timeFactory->method('getTime')->willReturn(42); |
|
100 | + |
|
101 | + if ($retainBackgroundJob) { |
|
102 | + $this->jobList->expects($this->once()) |
|
103 | + ->method('add') |
|
104 | + ->with( |
|
105 | + RequestSharedSecret::class, |
|
106 | + [ |
|
107 | + 'url' => 'url', |
|
108 | + 'token' => 'token', |
|
109 | + 'created' => 42, |
|
110 | + 'attempt' => 1, |
|
111 | + ] |
|
112 | + ); |
|
113 | + } else { |
|
114 | + $this->jobList->expects($this->never())->method('add'); |
|
115 | + } |
|
116 | + |
|
117 | + $requestSharedSecret->start($this->jobList); |
|
118 | + } |
|
119 | + |
|
120 | + public static function dataTestStart(): array { |
|
121 | + return [ |
|
122 | + [true, true], |
|
123 | + [true, false], |
|
124 | + [false, false], |
|
125 | + ]; |
|
126 | + } |
|
127 | + |
|
128 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestRun')] |
|
129 | + public function testRun(int $statusCode, int $attempt = 0): void { |
|
130 | + $target = 'targetURL'; |
|
131 | + $source = 'sourceURL'; |
|
132 | + $token = 'token'; |
|
133 | + |
|
134 | + $argument = ['url' => $target, 'token' => $token, 'attempt' => $attempt]; |
|
135 | + |
|
136 | + $this->timeFactory->method('getTime')->willReturn(42); |
|
137 | + |
|
138 | + $this->urlGenerator->expects($this->once())->method('getAbsoluteURL')->with('/') |
|
139 | + ->willReturn($source); |
|
140 | + $this->httpClient->expects($this->once())->method('post') |
|
141 | + ->with( |
|
142 | + $target . '/ocs/v2.php/apps/federation/api/v1/request-shared-secret', |
|
143 | + [ |
|
144 | + 'body' => [ |
|
145 | + 'url' => $source, |
|
146 | + 'token' => $token, |
|
147 | + 'format' => 'json', |
|
148 | + ], |
|
149 | + 'timeout' => 3, |
|
150 | + 'connect_timeout' => 3, |
|
151 | + 'verify' => true, |
|
152 | + ] |
|
153 | + )->willReturn($this->response); |
|
154 | + |
|
155 | + $this->response->expects($this->once())->method('getStatusCode') |
|
156 | + ->willReturn($statusCode); |
|
157 | + |
|
158 | + self::invokePrivate($this->requestSharedSecret, 'run', [$argument]); |
|
159 | + if ( |
|
160 | + $statusCode !== Http::STATUS_OK |
|
161 | + && ($statusCode !== Http::STATUS_FORBIDDEN || $attempt < 5) |
|
162 | + ) { |
|
163 | + $this->assertTrue(self::invokePrivate($this->requestSharedSecret, 'retainJob')); |
|
164 | + } else { |
|
165 | + $this->assertFalse(self::invokePrivate($this->requestSharedSecret, 'retainJob')); |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + public static function dataTestRun(): array { |
|
170 | + return [ |
|
171 | + [Http::STATUS_OK], |
|
172 | + [Http::STATUS_FORBIDDEN, 5], |
|
173 | + [Http::STATUS_FORBIDDEN], |
|
174 | + [Http::STATUS_CONFLICT], |
|
175 | + ]; |
|
176 | + } |
|
177 | + |
|
178 | + public function testRunExpired(): void { |
|
179 | + $target = 'targetURL'; |
|
180 | + $source = 'sourceURL'; |
|
181 | + $token = 'token'; |
|
182 | + $created = 42; |
|
183 | + |
|
184 | + $argument = [ |
|
185 | + 'url' => $target, |
|
186 | + 'token' => $token, |
|
187 | + 'created' => $created, |
|
188 | + ]; |
|
189 | + |
|
190 | + $this->urlGenerator->expects($this->once()) |
|
191 | + ->method('getAbsoluteURL') |
|
192 | + ->with('/') |
|
193 | + ->willReturn($source); |
|
194 | + |
|
195 | + $this->timeFactory->method('getTime') |
|
196 | + ->willReturn($created + 2592000 + 1); |
|
197 | + |
|
198 | + $this->trustedServers->expects($this->once()) |
|
199 | + ->method('setServerStatus') |
|
200 | + ->with( |
|
201 | + $target, |
|
202 | + TrustedServers::STATUS_FAILURE |
|
203 | + ); |
|
204 | + |
|
205 | + self::invokePrivate($this->requestSharedSecret, 'run', [$argument]); |
|
206 | + } |
|
207 | + |
|
208 | + public function testRunConnectionError(): void { |
|
209 | + $target = 'targetURL'; |
|
210 | + $source = 'sourceURL'; |
|
211 | + $token = 'token'; |
|
212 | + |
|
213 | + $argument = ['url' => $target, 'token' => $token]; |
|
214 | + |
|
215 | + $this->timeFactory->method('getTime')->willReturn(42); |
|
216 | + |
|
217 | + $this->urlGenerator |
|
218 | + ->expects($this->once()) |
|
219 | + ->method('getAbsoluteURL') |
|
220 | + ->with('/') |
|
221 | + ->willReturn($source); |
|
222 | + |
|
223 | + $this->httpClient |
|
224 | + ->expects($this->once()) |
|
225 | + ->method('post') |
|
226 | + ->with( |
|
227 | + $target . '/ocs/v2.php/apps/federation/api/v1/request-shared-secret', |
|
228 | + [ |
|
229 | + 'body' => [ |
|
230 | + 'url' => $source, |
|
231 | + 'token' => $token, |
|
232 | + 'format' => 'json', |
|
233 | + ], |
|
234 | + 'timeout' => 3, |
|
235 | + 'connect_timeout' => 3, |
|
236 | + 'verify' => true, |
|
237 | + ] |
|
238 | + )->willThrowException($this->createMock(ConnectException::class)); |
|
239 | + |
|
240 | + self::invokePrivate($this->requestSharedSecret, 'run', [$argument]); |
|
241 | + $this->assertTrue(self::invokePrivate($this->requestSharedSecret, 'retainJob')); |
|
242 | + } |
|
243 | 243 | } |
@@ -50,1898 +50,1898 @@ |
||
50 | 50 | */ |
51 | 51 | class ShareByMailProviderTest extends TestCase { |
52 | 52 | |
53 | - private IDBConnection $connection; |
|
54 | - |
|
55 | - private IL10N&MockObject $l; |
|
56 | - private IShare&MockObject $share; |
|
57 | - private IConfig&MockObject $config; |
|
58 | - private IMailer&MockObject $mailer; |
|
59 | - private IHasher&MockObject $hasher; |
|
60 | - private Defaults&MockObject $defaults; |
|
61 | - private IManager&MockObject $shareManager; |
|
62 | - private LoggerInterface&MockObject $logger; |
|
63 | - private IRootFolder&MockObject $rootFolder; |
|
64 | - private IUserManager&MockObject $userManager; |
|
65 | - private ISecureRandom&MockObject $secureRandom; |
|
66 | - private IURLGenerator&MockObject $urlGenerator; |
|
67 | - private SettingsManager&MockObject $settingsManager; |
|
68 | - private IActivityManager&MockObject $activityManager; |
|
69 | - private IEventDispatcher&MockObject $eventDispatcher; |
|
70 | - |
|
71 | - protected function setUp(): void { |
|
72 | - parent::setUp(); |
|
73 | - |
|
74 | - $this->connection = Server::get(IDBConnection::class); |
|
75 | - |
|
76 | - $this->l = $this->createMock(IL10N::class); |
|
77 | - $this->l->method('t') |
|
78 | - ->willReturnCallback(function ($text, $parameters = []) { |
|
79 | - return vsprintf($text, $parameters); |
|
80 | - }); |
|
81 | - $this->config = $this->createMock(IConfig::class); |
|
82 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
83 | - $this->rootFolder = $this->createMock('OCP\Files\IRootFolder'); |
|
84 | - $this->userManager = $this->createMock(IUserManager::class); |
|
85 | - $this->secureRandom = $this->createMock('\OCP\Security\ISecureRandom'); |
|
86 | - $this->mailer = $this->createMock('\OCP\Mail\IMailer'); |
|
87 | - $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
88 | - $this->share = $this->createMock(IShare::class); |
|
89 | - $this->activityManager = $this->createMock('OCP\Activity\IManager'); |
|
90 | - $this->settingsManager = $this->createMock(SettingsManager::class); |
|
91 | - $this->defaults = $this->createMock(Defaults::class); |
|
92 | - $this->hasher = $this->createMock(IHasher::class); |
|
93 | - $this->eventDispatcher = $this->createMock(IEventDispatcher::class); |
|
94 | - $this->shareManager = $this->createMock(IManager::class); |
|
95 | - |
|
96 | - $this->userManager->expects($this->any())->method('userExists')->willReturn(true); |
|
97 | - $this->config->expects($this->any())->method('getAppValue')->with('core', 'enforce_strict_email_check')->willReturn('yes'); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * get instance of Mocked ShareByMailProvider |
|
102 | - * |
|
103 | - * @param array $mockedMethods internal methods which should be mocked |
|
104 | - * @return \PHPUnit\Framework\MockObject\MockObject | ShareByMailProvider |
|
105 | - */ |
|
106 | - private function getInstance(array $mockedMethods = []) { |
|
107 | - if (!empty($mockedMethods)) { |
|
108 | - return $this->getMockBuilder(ShareByMailProvider::class) |
|
109 | - ->setConstructorArgs([ |
|
110 | - $this->config, |
|
111 | - $this->connection, |
|
112 | - $this->secureRandom, |
|
113 | - $this->userManager, |
|
114 | - $this->rootFolder, |
|
115 | - $this->l, |
|
116 | - $this->logger, |
|
117 | - $this->mailer, |
|
118 | - $this->urlGenerator, |
|
119 | - $this->activityManager, |
|
120 | - $this->settingsManager, |
|
121 | - $this->defaults, |
|
122 | - $this->hasher, |
|
123 | - $this->eventDispatcher, |
|
124 | - $this->shareManager, |
|
125 | - ]) |
|
126 | - ->onlyMethods($mockedMethods) |
|
127 | - ->getMock(); |
|
128 | - } |
|
129 | - |
|
130 | - return new ShareByMailProvider( |
|
131 | - $this->config, |
|
132 | - $this->connection, |
|
133 | - $this->secureRandom, |
|
134 | - $this->userManager, |
|
135 | - $this->rootFolder, |
|
136 | - $this->l, |
|
137 | - $this->logger, |
|
138 | - $this->mailer, |
|
139 | - $this->urlGenerator, |
|
140 | - $this->activityManager, |
|
141 | - $this->settingsManager, |
|
142 | - $this->defaults, |
|
143 | - $this->hasher, |
|
144 | - $this->eventDispatcher, |
|
145 | - $this->shareManager, |
|
146 | - ); |
|
147 | - } |
|
148 | - |
|
149 | - protected function tearDown(): void { |
|
150 | - $this->connection |
|
151 | - ->getQueryBuilder() |
|
152 | - ->delete('share') |
|
153 | - ->executeStatement(); |
|
154 | - |
|
155 | - parent::tearDown(); |
|
156 | - } |
|
157 | - |
|
158 | - public function testCreate(): void { |
|
159 | - $expectedShare = $this->createMock(IShare::class); |
|
160 | - |
|
161 | - $share = $this->createMock(IShare::class); |
|
162 | - $share->expects($this->any())->method('getSharedWith')->willReturn('user1'); |
|
163 | - |
|
164 | - $node = $this->createMock(File::class); |
|
165 | - $node->expects($this->any())->method('getName')->willReturn('filename'); |
|
166 | - |
|
167 | - $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'sendEmail', 'sendPassword']); |
|
168 | - |
|
169 | - $instance->expects($this->once())->method('getSharedWith')->willReturn([]); |
|
170 | - $instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42); |
|
171 | - $instance->expects($this->once())->method('createShareActivity')->with($share); |
|
172 | - $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']); |
|
173 | - $instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($expectedShare); |
|
174 | - $share->expects($this->any())->method('getNode')->willReturn($node); |
|
175 | - |
|
176 | - // As share api link password is not enforced, the password will not be generated. |
|
177 | - $this->shareManager->expects($this->once())->method('shareApiLinkEnforcePassword')->willReturn(false); |
|
178 | - $this->settingsManager->expects($this->never())->method('sendPasswordByMail'); |
|
179 | - |
|
180 | - // Mail notification is triggered by the share manager. |
|
181 | - $instance->expects($this->never())->method('sendEmail'); |
|
182 | - $instance->expects($this->never())->method('sendPassword'); |
|
183 | - |
|
184 | - $this->assertSame($expectedShare, $instance->create($share)); |
|
185 | - } |
|
186 | - |
|
187 | - public function testCreateSendPasswordByMailWithoutEnforcedPasswordProtection(): void { |
|
188 | - $expectedShare = $this->createMock(IShare::class); |
|
189 | - |
|
190 | - $node = $this->createMock(File::class); |
|
191 | - $node->expects($this->any())->method('getName')->willReturn('filename'); |
|
192 | - |
|
193 | - $share = $this->createMock(IShare::class); |
|
194 | - $share->expects($this->any())->method('getSharedWith')->willReturn('receiver@examplelölöl.com'); |
|
195 | - $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false); |
|
196 | - $share->expects($this->any())->method('getSharedBy')->willReturn('owner'); |
|
197 | - $share->expects($this->any())->method('getNode')->willReturn($node); |
|
198 | - $share->expects($this->any())->method('getId')->willReturn(42); |
|
199 | - $share->expects($this->any())->method('getNote')->willReturn(''); |
|
200 | - $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
201 | - |
|
202 | - // Assume the mail address is valid. |
|
203 | - $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); |
|
204 | - |
|
205 | - $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'autoGeneratePassword', 'createPasswordSendActivity', 'sendEmail', 'sendPassword', 'sendPasswordToOwner']); |
|
206 | - $instance->expects($this->once())->method('getSharedWith')->willReturn([]); |
|
207 | - $instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42); |
|
208 | - $instance->expects($this->once())->method('createShareActivity')->with($share); |
|
209 | - $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']); |
|
210 | - $instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($expectedShare); |
|
211 | - $share->expects($this->any())->method('getNode')->willReturn($node); |
|
212 | - |
|
213 | - // The autogenerated password should not be mailed. |
|
214 | - $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false); |
|
215 | - $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true); |
|
216 | - $instance->expects($this->never())->method('autoGeneratePassword'); |
|
217 | - |
|
218 | - // No password is set and no password sent via talk is requested |
|
219 | - $instance->expects($this->once())->method('sendEmail')->with($share, ['receiver@examplelölöl.com']); |
|
220 | - $instance->expects($this->never())->method('sendPassword'); |
|
221 | - $instance->expects($this->never())->method('sendPasswordToOwner'); |
|
222 | - |
|
223 | - // The manager sends the mail notification. |
|
224 | - // For the sake of testing simplicity, we will handle it ourselves. |
|
225 | - $this->assertSame($expectedShare, $instance->create($share)); |
|
226 | - $instance->sendMailNotification($share); |
|
227 | - } |
|
228 | - |
|
229 | - public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswordProtectionWithPermanentPassword(): void { |
|
230 | - $expectedShare = $this->createMock(IShare::class); |
|
231 | - |
|
232 | - $node = $this->createMock(File::class); |
|
233 | - $node->expects($this->any())->method('getName')->willReturn('filename'); |
|
234 | - |
|
235 | - $share = $this->createMock(IShare::class); |
|
236 | - $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
237 | - $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false); |
|
238 | - $share->expects($this->any())->method('getSharedBy')->willReturn('owner'); |
|
239 | - $share->expects($this->any())->method('getNode')->willReturn($node); |
|
240 | - $share->expects($this->any())->method('getId')->willReturn(42); |
|
241 | - $share->expects($this->any())->method('getNote')->willReturn(''); |
|
242 | - $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
243 | - |
|
244 | - // Assume the mail address is valid. |
|
245 | - $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); |
|
246 | - |
|
247 | - $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'autoGeneratePassword', 'createPasswordSendActivity', 'sendEmail', 'sendPassword', 'sendPasswordToOwner']); |
|
248 | - |
|
249 | - $instance->expects($this->once())->method('getSharedWith')->willReturn([]); |
|
250 | - $instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42); |
|
251 | - $instance->expects($this->once())->method('createShareActivity')->with($share); |
|
252 | - $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare', 'password' => 'password']); |
|
253 | - $instance->expects($this->once())->method('createShareObject')->with(['rawShare', 'password' => 'password'])->willReturn($expectedShare); |
|
254 | - $share->expects($this->any())->method('getNode')->willReturn($node); |
|
255 | - |
|
256 | - $share->expects($this->any())->method('getPassword')->willReturn('password'); |
|
257 | - $this->hasher->expects($this->once())->method('hash')->with('password')->willReturn('passwordHashed'); |
|
258 | - $share->expects($this->once())->method('setPassword')->with('passwordHashed'); |
|
259 | - |
|
260 | - // The given password (but not the autogenerated password) should not be |
|
261 | - // mailed to the receiver of the share because permanent passwords are not enforced. |
|
262 | - $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false); |
|
263 | - $this->config->expects($this->once())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(false); |
|
264 | - $instance->expects($this->never())->method('autoGeneratePassword'); |
|
265 | - |
|
266 | - // A password is set but no password sent via talk has been requested |
|
267 | - $instance->expects($this->once())->method('sendEmail')->with($share, ['[email protected]']); |
|
268 | - $instance->expects($this->once())->method('sendPassword')->with($share, 'password'); |
|
269 | - $instance->expects($this->never())->method('sendPasswordToOwner'); |
|
270 | - |
|
271 | - $this->assertSame($expectedShare, $instance->create($share)); |
|
272 | - $instance->sendMailNotification($share); |
|
273 | - } |
|
274 | - |
|
275 | - public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswordProtectionWithoutPermanentPassword(): void { |
|
276 | - $expectedShare = $this->createMock(IShare::class); |
|
277 | - |
|
278 | - $node = $this->createMock(File::class); |
|
279 | - $node->expects($this->any())->method('getName')->willReturn('filename'); |
|
280 | - |
|
281 | - $share = $this->createMock(IShare::class); |
|
282 | - $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
283 | - $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false); |
|
284 | - $share->expects($this->any())->method('getSharedBy')->willReturn('owner'); |
|
285 | - $share->expects($this->any())->method('getNode')->willReturn($node); |
|
286 | - $share->expects($this->any())->method('getId')->willReturn(42); |
|
287 | - $share->expects($this->any())->method('getNote')->willReturn(''); |
|
288 | - $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
289 | - |
|
290 | - // Assume the mail address is valid. |
|
291 | - $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); |
|
292 | - |
|
293 | - $instance = $this->getInstance([ |
|
294 | - 'getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', |
|
295 | - 'createShareActivity', 'autoGeneratePassword', 'createPasswordSendActivity', |
|
296 | - 'sendEmail', 'sendPassword', 'sendPasswordToOwner', |
|
297 | - ]); |
|
298 | - |
|
299 | - $instance->expects($this->once())->method('getSharedWith')->willReturn([]); |
|
300 | - $instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42); |
|
301 | - $instance->expects($this->once())->method('createShareActivity')->with($share); |
|
302 | - $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare', 'password' => 'password']); |
|
303 | - $instance->expects($this->once())->method('createShareObject')->with(['rawShare', 'password' => 'password'])->willReturn($expectedShare); |
|
304 | - $share->expects($this->any())->method('getNode')->willReturn($node); |
|
305 | - |
|
306 | - $share->expects($this->any())->method('getPassword')->willReturn('password'); |
|
307 | - $this->hasher->expects($this->once())->method('hash')->with('password')->willReturn('passwordHashed'); |
|
308 | - $share->expects($this->once())->method('setPassword')->with('passwordHashed'); |
|
309 | - |
|
310 | - // No password is generated, so no emails need to be sent |
|
311 | - // aside from the main email notification. |
|
312 | - $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false); |
|
313 | - $instance->expects($this->never())->method('autoGeneratePassword'); |
|
314 | - $this->config->expects($this->once())->method('getSystemValue') |
|
315 | - ->with('sharing.enable_mail_link_password_expiration') |
|
316 | - ->willReturn(true); |
|
317 | - |
|
318 | - // No password has been set and no password sent via talk has been requested, |
|
319 | - // but password has been enforced for the whole instance and will be generated. |
|
320 | - $instance->expects($this->once())->method('sendEmail')->with($share, ['[email protected]']); |
|
321 | - $instance->expects($this->never())->method('sendPassword'); |
|
322 | - $instance->expects($this->never())->method('sendPasswordToOwner'); |
|
323 | - |
|
324 | - $this->assertSame($expectedShare, $instance->create($share)); |
|
325 | - $instance->sendMailNotification($share); |
|
326 | - } |
|
327 | - |
|
328 | - public function testCreateSendPasswordByMailWithEnforcedPasswordProtectionWithPermanentPassword(): void { |
|
329 | - $expectedShare = $this->createMock(IShare::class); |
|
330 | - |
|
331 | - $node = $this->createMock(File::class); |
|
332 | - $node->expects($this->any())->method('getName')->willReturn('filename'); |
|
333 | - |
|
334 | - $share = $this->createMock(IShare::class); |
|
335 | - $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
336 | - $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false); |
|
337 | - $share->expects($this->any())->method('getSharedBy')->willReturn('owner'); |
|
338 | - $share->expects($this->any())->method('getNode')->willReturn($node); |
|
339 | - $share->expects($this->any())->method('getId')->willReturn(42); |
|
340 | - $share->expects($this->any())->method('getNote')->willReturn(''); |
|
341 | - $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
342 | - |
|
343 | - $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute') |
|
344 | - ->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) |
|
345 | - ->willReturn('https://example.com/file.txt'); |
|
346 | - |
|
347 | - $this->secureRandom->expects($this->once()) |
|
348 | - ->method('generate') |
|
349 | - ->with(8, ISecureRandom::CHAR_HUMAN_READABLE) |
|
350 | - ->willReturn('autogeneratedPassword'); |
|
351 | - $this->eventDispatcher->expects($this->once()) |
|
352 | - ->method('dispatchTyped') |
|
353 | - ->with(new GenerateSecurePasswordEvent(PasswordContext::SHARING)); |
|
354 | - |
|
355 | - // Assume the mail address is valid. |
|
356 | - $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); |
|
357 | - |
|
358 | - $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'createPasswordSendActivity', 'sendPasswordToOwner']); |
|
359 | - |
|
360 | - $instance->expects($this->once())->method('getSharedWith')->willReturn([]); |
|
361 | - $instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42); |
|
362 | - $instance->expects($this->once())->method('createShareActivity')->with($share); |
|
363 | - $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare', 'password' => 'autogeneratedPassword']); |
|
364 | - $instance->expects($this->once())->method('createShareObject')->with(['rawShare', 'password' => 'autogeneratedPassword'])->willReturn($expectedShare); |
|
365 | - |
|
366 | - // Initially not set, but will be set by the autoGeneratePassword method. |
|
367 | - $share->expects($this->exactly(3))->method('getPassword')->willReturnOnConsecutiveCalls(null, 'autogeneratedPassword', 'autogeneratedPassword'); |
|
368 | - $this->hasher->expects($this->once())->method('hash')->with('autogeneratedPassword')->willReturn('autogeneratedPasswordHashed'); |
|
369 | - $share->expects($this->once())->method('setPassword')->with('autogeneratedPasswordHashed'); |
|
370 | - |
|
371 | - // The autogenerated password should be mailed to the receiver of the share because permanent passwords are enforced. |
|
372 | - $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(true); |
|
373 | - $this->config->expects($this->any())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(false); |
|
374 | - $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true); |
|
375 | - |
|
376 | - $message = $this->createMock(IMessage::class); |
|
377 | - $message->expects($this->exactly(2))->method('setTo')->with(['[email protected]']); |
|
378 | - $this->mailer->expects($this->exactly(2))->method('createMessage')->willReturn($message); |
|
379 | - $calls = [ |
|
380 | - [ |
|
381 | - 'sharebymail.RecipientNotification', |
|
382 | - [ |
|
383 | - 'filename' => 'filename', |
|
384 | - 'link' => 'https://example.com/file.txt', |
|
385 | - 'initiator' => 'owner', |
|
386 | - 'expiration' => null, |
|
387 | - 'shareWith' => '[email protected]', |
|
388 | - 'note' => '', |
|
389 | - ], |
|
390 | - ], |
|
391 | - [ |
|
392 | - 'sharebymail.RecipientPasswordNotification', |
|
393 | - [ |
|
394 | - 'filename' => 'filename', |
|
395 | - 'password' => 'autogeneratedPassword', |
|
396 | - 'initiator' => 'owner', |
|
397 | - 'initiatorEmail' => null, |
|
398 | - 'shareWith' => '[email protected]', |
|
399 | - ], |
|
400 | - ], |
|
401 | - ]; |
|
402 | - $this->mailer->expects($this->exactly(2)) |
|
403 | - ->method('createEMailTemplate') |
|
404 | - ->willReturnCallback(function () use (&$calls) { |
|
405 | - $expected = array_shift($calls); |
|
406 | - $this->assertEquals($expected, func_get_args()); |
|
407 | - return $this->createMock(IEMailTemplate::class); |
|
408 | - }); |
|
409 | - |
|
410 | - // Main email notification is sent as well as the password |
|
411 | - // to the recipient because shareApiLinkEnforcePassword is enabled. |
|
412 | - $this->mailer->expects($this->exactly(2))->method('send'); |
|
413 | - $instance->expects($this->never())->method('sendPasswordToOwner'); |
|
414 | - |
|
415 | - $this->assertSame($expectedShare, $instance->create($share)); |
|
416 | - $instance->sendMailNotification($share); |
|
417 | - } |
|
418 | - |
|
419 | - public function testCreateSendPasswordByMailWithPasswordAndWithEnforcedPasswordProtectionWithPermanentPassword(): void { |
|
420 | - $expectedShare = $this->createMock(IShare::class); |
|
421 | - |
|
422 | - $node = $this->createMock(File::class); |
|
423 | - $node->expects($this->any())->method('getName')->willReturn('filename'); |
|
424 | - |
|
425 | - $share = $this->createMock(IShare::class); |
|
426 | - $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
427 | - $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false); |
|
428 | - $share->expects($this->any())->method('getSharedBy')->willReturn('owner'); |
|
429 | - $share->expects($this->any())->method('getNode')->willReturn($node); |
|
430 | - $share->expects($this->any())->method('getId')->willReturn(42); |
|
431 | - $share->expects($this->any())->method('getNote')->willReturn(''); |
|
432 | - $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
433 | - |
|
434 | - $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute') |
|
435 | - ->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) |
|
436 | - ->willReturn('https://example.com/file.txt'); |
|
437 | - |
|
438 | - // Assume the mail address is valid. |
|
439 | - $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); |
|
440 | - |
|
441 | - $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'autoGeneratePassword', 'createPasswordSendActivity', 'sendPasswordToOwner']); |
|
442 | - |
|
443 | - $instance->expects($this->once())->method('getSharedWith')->willReturn([]); |
|
444 | - $instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42); |
|
445 | - $instance->expects($this->once())->method('createShareActivity')->with($share); |
|
446 | - $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare', 'password' => 'password']); |
|
447 | - $instance->expects($this->once())->method('createShareObject')->with(['rawShare', 'password' => 'password'])->willReturn($expectedShare); |
|
448 | - |
|
449 | - $share->expects($this->exactly(3))->method('getPassword')->willReturn('password'); |
|
450 | - $this->hasher->expects($this->once())->method('hash')->with('password')->willReturn('passwordHashed'); |
|
451 | - $share->expects($this->once())->method('setPassword')->with('passwordHashed'); |
|
452 | - |
|
453 | - // The given password (but not the autogenerated password) should be |
|
454 | - // mailed to the receiver of the share. |
|
455 | - $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(true); |
|
456 | - $this->config->expects($this->any())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(false); |
|
457 | - $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true); |
|
458 | - $instance->expects($this->never())->method('autoGeneratePassword'); |
|
459 | - |
|
460 | - $message = $this->createMock(IMessage::class); |
|
461 | - $message->expects($this->exactly(2))->method('setTo')->with(['[email protected]']); |
|
462 | - $this->mailer->expects($this->exactly(2))->method('createMessage')->willReturn($message); |
|
463 | - |
|
464 | - $calls = [ |
|
465 | - [ |
|
466 | - 'sharebymail.RecipientNotification', |
|
467 | - [ |
|
468 | - 'filename' => 'filename', |
|
469 | - 'link' => 'https://example.com/file.txt', |
|
470 | - 'initiator' => 'owner', |
|
471 | - 'expiration' => null, |
|
472 | - 'shareWith' => '[email protected]', |
|
473 | - 'note' => '', |
|
474 | - ], |
|
475 | - ], |
|
476 | - [ |
|
477 | - 'sharebymail.RecipientPasswordNotification', |
|
478 | - [ |
|
479 | - 'filename' => 'filename', |
|
480 | - 'password' => 'password', |
|
481 | - 'initiator' => 'owner', |
|
482 | - 'initiatorEmail' => null, |
|
483 | - 'shareWith' => '[email protected]', |
|
484 | - ], |
|
485 | - ], |
|
486 | - ]; |
|
487 | - $this->mailer->expects($this->exactly(2)) |
|
488 | - ->method('createEMailTemplate') |
|
489 | - ->willReturnCallback(function () use (&$calls) { |
|
490 | - $expected = array_shift($calls); |
|
491 | - $this->assertEquals($expected, func_get_args()); |
|
492 | - return $this->createMock(IEMailTemplate::class); |
|
493 | - }); |
|
494 | - |
|
495 | - // Main email notification is sent as well as the password |
|
496 | - // to the recipient because the password is set. |
|
497 | - $this->mailer->expects($this->exactly(2))->method('send'); |
|
498 | - $instance->expects($this->never())->method('sendPasswordToOwner'); |
|
499 | - |
|
500 | - $this->assertSame($expectedShare, $instance->create($share)); |
|
501 | - $instance->sendMailNotification($share); |
|
502 | - } |
|
503 | - |
|
504 | - public function testCreateSendPasswordByTalkWithEnforcedPasswordProtectionWithPermanentPassword(): void { |
|
505 | - $expectedShare = $this->createMock(IShare::class); |
|
506 | - |
|
507 | - // The owner of the share. |
|
508 | - $owner = $this->createMock(IUser::class); |
|
509 | - $this->userManager->expects($this->any())->method('get')->with('owner')->willReturn($owner); |
|
510 | - $owner->expects($this->any())->method('getEMailAddress')->willReturn('[email protected]'); |
|
511 | - $owner->expects($this->any())->method('getDisplayName')->willReturn('owner'); |
|
512 | - |
|
513 | - $node = $this->createMock(File::class); |
|
514 | - $node->expects($this->any())->method('getName')->willReturn('filename'); |
|
515 | - |
|
516 | - $share = $this->createMock(IShare::class); |
|
517 | - $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
518 | - $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(true); |
|
519 | - $share->expects($this->any())->method('getSharedBy')->willReturn('owner'); |
|
520 | - $share->expects($this->any())->method('getNode')->willReturn($node); |
|
521 | - $share->expects($this->any())->method('getId')->willReturn(42); |
|
522 | - $share->expects($this->any())->method('getNote')->willReturn(''); |
|
523 | - $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
524 | - |
|
525 | - $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute') |
|
526 | - ->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) |
|
527 | - ->willReturn('https://example.com/file.txt'); |
|
528 | - |
|
529 | - // Assume the mail address is valid. |
|
530 | - $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); |
|
531 | - |
|
532 | - $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'autoGeneratePassword', 'createPasswordSendActivity']); |
|
533 | - |
|
534 | - $instance->expects($this->once())->method('getSharedWith')->willReturn([]); |
|
535 | - $instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42); |
|
536 | - $instance->expects($this->once())->method('createShareActivity')->with($share); |
|
537 | - $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare', 'password' => 'autogeneratedPassword']); |
|
538 | - $instance->expects($this->once())->method('createShareObject')->with(['rawShare', 'password' => 'autogeneratedPassword'])->willReturn($expectedShare); |
|
539 | - |
|
540 | - $share->expects($this->exactly(4))->method('getPassword')->willReturnOnConsecutiveCalls(null, 'autogeneratedPassword', 'autogeneratedPassword', 'autogeneratedPassword'); |
|
541 | - $this->hasher->expects($this->once())->method('hash')->with('autogeneratedPassword')->willReturn('autogeneratedPasswordHashed'); |
|
542 | - $share->expects($this->once())->method('setPassword')->with('autogeneratedPasswordHashed'); |
|
543 | - |
|
544 | - // The autogenerated password should be mailed to the owner of the share. |
|
545 | - $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(true); |
|
546 | - $this->config->expects($this->any())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(false); |
|
547 | - $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true); |
|
548 | - $instance->expects($this->once())->method('autoGeneratePassword')->with($share)->willReturn('autogeneratedPassword'); |
|
549 | - |
|
550 | - $message = $this->createMock(IMessage::class); |
|
551 | - $setToCalls = [ |
|
552 | - [['[email protected]']], |
|
553 | - [['[email protected]' => 'owner']], |
|
554 | - ]; |
|
555 | - $message->expects($this->exactly(2)) |
|
556 | - ->method('setTo') |
|
557 | - ->willReturnCallback(function () use (&$setToCalls, $message) { |
|
558 | - $expected = array_shift($setToCalls); |
|
559 | - $this->assertEquals($expected, func_get_args()); |
|
560 | - return $message; |
|
561 | - }); |
|
562 | - $this->mailer->expects($this->exactly(2))->method('createMessage')->willReturn($message); |
|
563 | - |
|
564 | - $calls = [ |
|
565 | - [ |
|
566 | - 'sharebymail.RecipientNotification', |
|
567 | - [ |
|
568 | - 'filename' => 'filename', |
|
569 | - 'link' => 'https://example.com/file.txt', |
|
570 | - 'initiator' => 'owner', |
|
571 | - 'expiration' => null, |
|
572 | - 'shareWith' => '[email protected]', |
|
573 | - 'note' => '', |
|
574 | - ], |
|
575 | - ], |
|
576 | - [ |
|
577 | - 'sharebymail.OwnerPasswordNotification', |
|
578 | - [ |
|
579 | - 'filename' => 'filename', |
|
580 | - 'password' => 'autogeneratedPassword', |
|
581 | - 'initiator' => 'owner', |
|
582 | - 'initiatorEmail' => '[email protected]', |
|
583 | - 'shareWith' => '[email protected]', |
|
584 | - ], |
|
585 | - ], |
|
586 | - ]; |
|
587 | - $this->mailer->expects($this->exactly(2)) |
|
588 | - ->method('createEMailTemplate') |
|
589 | - ->willReturnCallback(function () use (&$calls) { |
|
590 | - $expected = array_shift($calls); |
|
591 | - $this->assertEquals($expected, func_get_args()); |
|
592 | - return $this->createMock(IEMailTemplate::class); |
|
593 | - }); |
|
594 | - |
|
595 | - // Main email notification is sent as well as the password to owner |
|
596 | - // because the password is set and SendPasswordByTalk is enabled. |
|
597 | - $this->mailer->expects($this->exactly(2))->method('send'); |
|
598 | - |
|
599 | - $this->assertSame($expectedShare, $instance->create($share)); |
|
600 | - $instance->sendMailNotification($share); |
|
601 | - } |
|
602 | - |
|
603 | - // If attributes is set to multiple emails, use them as BCC |
|
604 | - public function sendNotificationToMultipleEmails() { |
|
605 | - $expectedShare = $this->createMock(IShare::class); |
|
606 | - |
|
607 | - $node = $this->createMock(File::class); |
|
608 | - $node->expects($this->any())->method('getName')->willReturn('filename'); |
|
609 | - |
|
610 | - $share = $this->createMock(IShare::class); |
|
611 | - $share->expects($this->any())->method('getSharedWith')->willReturn(''); |
|
612 | - $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false); |
|
613 | - $share->expects($this->any())->method('getSharedBy')->willReturn('owner'); |
|
614 | - $share->expects($this->any())->method('getNode')->willReturn($node); |
|
615 | - $share->expects($this->any())->method('getId')->willReturn(42); |
|
616 | - $share->expects($this->any())->method('getNote')->willReturn(''); |
|
617 | - $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
618 | - |
|
619 | - $attributes = $this->createMock(IAttributes::class); |
|
620 | - $share->expects($this->any())->method('getAttributes')->willReturn($attributes); |
|
621 | - $attributes->expects($this->any())->method('getAttribute')->with('shareWith', 'emails')->willReturn([ |
|
622 | - '[email protected]', |
|
623 | - '[email protected]', |
|
624 | - '[email protected]', |
|
625 | - ]); |
|
626 | - |
|
627 | - // Assume the mail address is valid. |
|
628 | - $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); |
|
629 | - |
|
630 | - $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'autoGeneratePassword', 'createPasswordSendActivity', 'sendEmail', 'sendPassword', 'sendPasswordToOwner']); |
|
631 | - |
|
632 | - $instance->expects($this->once())->method('getSharedWith')->willReturn([]); |
|
633 | - $instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42); |
|
634 | - $instance->expects($this->once())->method('createShareActivity')->with($share); |
|
635 | - $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare', 'password' => 'password']); |
|
636 | - $instance->expects($this->once())->method('createShareObject')->with(['rawShare', 'password' => 'password'])->willReturn($expectedShare); |
|
637 | - $share->expects($this->any())->method('getNode')->willReturn($node); |
|
638 | - |
|
639 | - $share->expects($this->any())->method('getPassword')->willReturn('password'); |
|
640 | - $this->hasher->expects($this->once())->method('hash')->with('password')->willReturn('passwordHashed'); |
|
641 | - $share->expects($this->once())->method('setPassword')->with('passwordHashed'); |
|
642 | - |
|
643 | - // The given password (but not the autogenerated password) should not be |
|
644 | - // mailed to the receiver of the share because permanent passwords are not enforced. |
|
645 | - $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false); |
|
646 | - $this->config->expects($this->once())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(false); |
|
647 | - $instance->expects($this->never())->method('autoGeneratePassword'); |
|
648 | - |
|
649 | - // A password is set but no password sent via talk has been requested |
|
650 | - $instance->expects($this->once())->method('sendEmail') |
|
651 | - ->with($share, ['[email protected]', '[email protected]', '[email protected]']); |
|
652 | - $instance->expects($this->once())->method('sendPassword')->with($share, 'password'); |
|
653 | - $instance->expects($this->never())->method('sendPasswordToOwner'); |
|
654 | - |
|
655 | - |
|
656 | - $message = $this->createMock(IMessage::class); |
|
657 | - $message->expects($this->never())->method('setTo'); |
|
658 | - $message->expects($this->exactly(2))->method('setBcc')->with(['[email protected]', '[email protected]', '[email protected]']); |
|
659 | - $this->mailer->expects($this->exactly(2))->method('createMessage')->willReturn($message); |
|
660 | - |
|
661 | - // Main email notification is sent as well as the password |
|
662 | - // to recipients because the password is set. |
|
663 | - $this->mailer->expects($this->exactly(2))->method('send'); |
|
664 | - |
|
665 | - $this->assertSame($expectedShare, $instance->create($share)); |
|
666 | - $instance->sendMailNotification($share); |
|
667 | - } |
|
668 | - |
|
669 | - public function testCreateFailed(): void { |
|
670 | - $this->expectException(\Exception::class); |
|
671 | - |
|
672 | - $this->share->expects($this->once())->method('getSharedWith')->willReturn('user1'); |
|
673 | - $node = $this->createMock('OCP\Files\Node'); |
|
674 | - $node->expects($this->any())->method('getName')->willReturn('fileName'); |
|
675 | - $this->share->expects($this->any())->method('getNode')->willReturn($node); |
|
676 | - |
|
677 | - $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject']); |
|
678 | - |
|
679 | - $instance->expects($this->once())->method('getSharedWith')->willReturn(['found']); |
|
680 | - $instance->expects($this->never())->method('createMailShare'); |
|
681 | - $instance->expects($this->never())->method('getRawShare'); |
|
682 | - $instance->expects($this->never())->method('createShareObject'); |
|
683 | - |
|
684 | - $this->assertSame('shareObject', |
|
685 | - $instance->create($this->share) |
|
686 | - ); |
|
687 | - } |
|
688 | - |
|
689 | - public function testCreateMailShare(): void { |
|
690 | - $this->share->expects($this->any())->method('getToken')->willReturn('token'); |
|
691 | - $this->share->expects($this->once())->method('setToken')->with('token'); |
|
692 | - $this->share->expects($this->any())->method('getSharedBy')->willReturn('[email protected]'); |
|
693 | - $this->share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
694 | - $this->share->expects($this->any())->method('getNote')->willReturn('Check this!'); |
|
695 | - $this->share->expects($this->any())->method('getMailSend')->willReturn(true); |
|
696 | - |
|
697 | - $node = $this->createMock('OCP\Files\Node'); |
|
698 | - $node->expects($this->any())->method('getName')->willReturn('fileName'); |
|
699 | - $this->share->expects($this->any())->method('getNode')->willReturn($node); |
|
700 | - |
|
701 | - $instance = $this->getInstance(['generateToken', 'addShareToDB', 'sendMailNotification']); |
|
702 | - |
|
703 | - $instance->expects($this->once())->method('generateToken')->willReturn('token'); |
|
704 | - $instance->expects($this->once())->method('addShareToDB')->willReturn(42); |
|
705 | - |
|
706 | - // The manager handle the mail sending |
|
707 | - $instance->expects($this->never())->method('sendMailNotification'); |
|
708 | - |
|
709 | - $this->assertSame(42, |
|
710 | - $this->invokePrivate($instance, 'createMailShare', [$this->share]) |
|
711 | - ); |
|
712 | - } |
|
713 | - |
|
714 | - public function testGenerateToken(): void { |
|
715 | - $instance = $this->getInstance(); |
|
716 | - |
|
717 | - $this->secureRandom->expects($this->once())->method('generate')->willReturn('token'); |
|
718 | - |
|
719 | - $this->assertSame('token', |
|
720 | - $this->invokePrivate($instance, 'generateToken') |
|
721 | - ); |
|
722 | - } |
|
723 | - |
|
724 | - public function testAddShareToDB(): void { |
|
725 | - $itemSource = 11; |
|
726 | - $itemType = 'file'; |
|
727 | - $shareWith = '[email protected]'; |
|
728 | - $sharedBy = 'user1'; |
|
729 | - $uidOwner = 'user2'; |
|
730 | - $permissions = 1; |
|
731 | - $token = 'token'; |
|
732 | - $password = 'password'; |
|
733 | - $sendPasswordByTalk = true; |
|
734 | - $hideDownload = true; |
|
735 | - $label = 'label'; |
|
736 | - $expiration = new \DateTime(); |
|
737 | - $passwordExpirationTime = new \DateTime(); |
|
738 | - |
|
739 | - |
|
740 | - $instance = $this->getInstance(); |
|
741 | - $id = $this->invokePrivate( |
|
742 | - $instance, |
|
743 | - 'addShareToDB', |
|
744 | - [ |
|
745 | - $itemSource, |
|
746 | - $itemType, |
|
747 | - $shareWith, |
|
748 | - $sharedBy, |
|
749 | - $uidOwner, |
|
750 | - $permissions, |
|
751 | - $token, |
|
752 | - $password, |
|
753 | - $passwordExpirationTime, |
|
754 | - $sendPasswordByTalk, |
|
755 | - $hideDownload, |
|
756 | - $label, |
|
757 | - $expiration |
|
758 | - ] |
|
759 | - ); |
|
760 | - |
|
761 | - $qb = $this->connection->getQueryBuilder(); |
|
762 | - $qb->select('*') |
|
763 | - ->from('share') |
|
764 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
765 | - |
|
766 | - $qResult = $qb->execute(); |
|
767 | - $result = $qResult->fetchAll(); |
|
768 | - $qResult->closeCursor(); |
|
769 | - |
|
770 | - $this->assertSame(1, count($result)); |
|
771 | - |
|
772 | - $this->assertSame($itemSource, (int)$result[0]['item_source']); |
|
773 | - $this->assertSame($itemType, $result[0]['item_type']); |
|
774 | - $this->assertSame($shareWith, $result[0]['share_with']); |
|
775 | - $this->assertSame($sharedBy, $result[0]['uid_initiator']); |
|
776 | - $this->assertSame($uidOwner, $result[0]['uid_owner']); |
|
777 | - $this->assertSame($permissions, (int)$result[0]['permissions']); |
|
778 | - $this->assertSame($token, $result[0]['token']); |
|
779 | - $this->assertSame($password, $result[0]['password']); |
|
780 | - $this->assertSame($passwordExpirationTime->getTimestamp(), \DateTime::createFromFormat('Y-m-d H:i:s', $result[0]['password_expiration_time'])->getTimestamp()); |
|
781 | - $this->assertSame($sendPasswordByTalk, (bool)$result[0]['password_by_talk']); |
|
782 | - $this->assertSame($hideDownload, (bool)$result[0]['hide_download']); |
|
783 | - $this->assertSame($label, $result[0]['label']); |
|
784 | - $this->assertSame($expiration->getTimestamp(), \DateTime::createFromFormat('Y-m-d H:i:s', $result[0]['expiration'])->getTimestamp()); |
|
785 | - } |
|
786 | - |
|
787 | - public function testUpdate(): void { |
|
788 | - $itemSource = 11; |
|
789 | - $itemType = 'file'; |
|
790 | - $shareWith = '[email protected]'; |
|
791 | - $sharedBy = 'user1'; |
|
792 | - $uidOwner = 'user2'; |
|
793 | - $permissions = 1; |
|
794 | - $token = 'token'; |
|
795 | - $note = 'personal note'; |
|
796 | - |
|
797 | - |
|
798 | - $instance = $this->getInstance(); |
|
799 | - |
|
800 | - $id = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $note); |
|
801 | - |
|
802 | - $this->share->expects($this->once())->method('getPermissions')->willReturn($permissions + 1); |
|
803 | - $this->share->expects($this->once())->method('getShareOwner')->willReturn($uidOwner); |
|
804 | - $this->share->expects($this->once())->method('getSharedBy')->willReturn($sharedBy); |
|
805 | - $this->share->expects($this->any())->method('getNote')->willReturn($note); |
|
806 | - $this->share->expects($this->atLeastOnce())->method('getId')->willReturn($id); |
|
807 | - $this->share->expects($this->atLeastOnce())->method('getNodeId')->willReturn($itemSource); |
|
808 | - $this->share->expects($this->once())->method('getSharedWith')->willReturn($shareWith); |
|
809 | - |
|
810 | - $this->assertSame($this->share, |
|
811 | - $instance->update($this->share) |
|
812 | - ); |
|
813 | - |
|
814 | - $qb = $this->connection->getQueryBuilder(); |
|
815 | - $qb->select('*') |
|
816 | - ->from('share') |
|
817 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
818 | - |
|
819 | - $qResult = $qb->execute(); |
|
820 | - $result = $qResult->fetchAll(); |
|
821 | - $qResult->closeCursor(); |
|
822 | - |
|
823 | - $this->assertSame(1, count($result)); |
|
824 | - |
|
825 | - $this->assertSame($itemSource, (int)$result[0]['item_source']); |
|
826 | - $this->assertSame($itemType, $result[0]['item_type']); |
|
827 | - $this->assertSame($shareWith, $result[0]['share_with']); |
|
828 | - $this->assertSame($sharedBy, $result[0]['uid_initiator']); |
|
829 | - $this->assertSame($uidOwner, $result[0]['uid_owner']); |
|
830 | - $this->assertSame($permissions + 1, (int)$result[0]['permissions']); |
|
831 | - $this->assertSame($token, $result[0]['token']); |
|
832 | - $this->assertSame($note, $result[0]['note']); |
|
833 | - } |
|
834 | - |
|
835 | - public static function dataUpdateSendPassword(): array { |
|
836 | - return [ |
|
837 | - ['password', 'hashed', 'hashed new', false, false, true], |
|
838 | - ['', 'hashed', 'hashed new', false, false, false], |
|
839 | - [null, 'hashed', 'hashed new', false, false, false], |
|
840 | - ['password', 'hashed', 'hashed', false, false, false], |
|
841 | - ['password', 'hashed', 'hashed new', false, true, false], |
|
842 | - ['password', 'hashed', 'hashed new', true, false, true], |
|
843 | - ['password', 'hashed', 'hashed', true, false, true], |
|
844 | - ]; |
|
845 | - } |
|
846 | - |
|
847 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataUpdateSendPassword')] |
|
848 | - public function testUpdateSendPassword(?string $plainTextPassword, string $originalPassword, string $newPassword, bool $originalSendPasswordByTalk, bool $newSendPasswordByTalk, bool $sendMail): void { |
|
849 | - $node = $this->createMock(File::class); |
|
850 | - $node->expects($this->any())->method('getName')->willReturn('filename'); |
|
851 | - |
|
852 | - $this->settingsManager->method('sendPasswordByMail')->willReturn(true); |
|
853 | - |
|
854 | - $originalShare = $this->createMock(IShare::class); |
|
855 | - $originalShare->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
856 | - $originalShare->expects($this->any())->method('getNode')->willReturn($node); |
|
857 | - $originalShare->expects($this->any())->method('getId')->willReturn(42); |
|
858 | - $originalShare->expects($this->any())->method('getPassword')->willReturn($originalPassword); |
|
859 | - $originalShare->expects($this->any())->method('getSendPasswordByTalk')->willReturn($originalSendPasswordByTalk); |
|
860 | - |
|
861 | - $share = $this->createMock(IShare::class); |
|
862 | - $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
863 | - $share->expects($this->any())->method('getNode')->willReturn($node); |
|
864 | - $share->expects($this->any())->method('getId')->willReturn(42); |
|
865 | - $share->expects($this->any())->method('getPassword')->willReturn($newPassword); |
|
866 | - $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn($newSendPasswordByTalk); |
|
867 | - |
|
868 | - if ($sendMail) { |
|
869 | - $this->mailer->expects($this->once())->method('createEMailTemplate')->with('sharebymail.RecipientPasswordNotification', [ |
|
870 | - 'filename' => 'filename', |
|
871 | - 'password' => $plainTextPassword, |
|
872 | - 'initiator' => null, |
|
873 | - 'initiatorEmail' => null, |
|
874 | - 'shareWith' => '[email protected]', |
|
875 | - ]); |
|
876 | - $this->mailer->expects($this->once())->method('send'); |
|
877 | - } else { |
|
878 | - $this->mailer->expects($this->never())->method('send'); |
|
879 | - } |
|
880 | - |
|
881 | - $instance = $this->getInstance(['getShareById', 'createPasswordSendActivity']); |
|
882 | - $instance->expects($this->once())->method('getShareById')->willReturn($originalShare); |
|
883 | - |
|
884 | - $this->assertSame($share, |
|
885 | - $instance->update($share, $plainTextPassword) |
|
886 | - ); |
|
887 | - } |
|
888 | - |
|
889 | - public function testDelete(): void { |
|
890 | - $instance = $this->getInstance(['removeShareFromTable', 'createShareActivity']); |
|
891 | - $this->share->expects($this->once())->method('getId')->willReturn(42); |
|
892 | - $instance->expects($this->once())->method('removeShareFromTable')->with(42); |
|
893 | - $instance->expects($this->once())->method('createShareActivity')->with($this->share, 'unshare'); |
|
894 | - $instance->delete($this->share); |
|
895 | - } |
|
896 | - |
|
897 | - public function testGetShareById(): void { |
|
898 | - $instance = $this->getInstance(['createShareObject']); |
|
899 | - |
|
900 | - $itemSource = 11; |
|
901 | - $itemType = 'file'; |
|
902 | - $shareWith = '[email protected]'; |
|
903 | - $sharedBy = 'user1'; |
|
904 | - $uidOwner = 'user2'; |
|
905 | - $permissions = 1; |
|
906 | - $token = 'token'; |
|
907 | - |
|
908 | - $this->createDummyShare($itemType, $itemSource, $shareWith, 'user1wrong', 'user2wrong', $permissions, $token); |
|
909 | - $id2 = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
910 | - |
|
911 | - $instance->expects($this->once())->method('createShareObject') |
|
912 | - ->willReturnCallback( |
|
913 | - function ($data) use ($uidOwner, $sharedBy, $id2) { |
|
914 | - $this->assertSame($uidOwner, $data['uid_owner']); |
|
915 | - $this->assertSame($sharedBy, $data['uid_initiator']); |
|
916 | - $this->assertSame($id2, (int)$data['id']); |
|
917 | - return $this->share; |
|
918 | - } |
|
919 | - ); |
|
920 | - |
|
921 | - $result = $instance->getShareById($id2); |
|
922 | - |
|
923 | - $this->assertInstanceOf('OCP\Share\IShare', $result); |
|
924 | - } |
|
925 | - |
|
926 | - |
|
927 | - public function testGetShareByIdFailed(): void { |
|
928 | - $this->expectException(ShareNotFound::class); |
|
929 | - |
|
930 | - $instance = $this->getInstance(['createShareObject']); |
|
931 | - |
|
932 | - $itemSource = 11; |
|
933 | - $itemType = 'file'; |
|
934 | - $shareWith = '[email protected]'; |
|
935 | - $sharedBy = 'user1'; |
|
936 | - $uidOwner = 'user2'; |
|
937 | - $permissions = 1; |
|
938 | - $token = 'token'; |
|
939 | - |
|
940 | - $id = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
941 | - |
|
942 | - $instance->getShareById($id + 1); |
|
943 | - } |
|
944 | - |
|
945 | - public function testGetShareByPath(): void { |
|
946 | - $itemSource = 11; |
|
947 | - $itemType = 'file'; |
|
948 | - $shareWith = '[email protected]'; |
|
949 | - $sharedBy = 'user1'; |
|
950 | - $uidOwner = 'user2'; |
|
951 | - $permissions = 1; |
|
952 | - $token = 'token'; |
|
953 | - |
|
954 | - $node = $this->createMock(Node::class); |
|
955 | - $node->expects($this->once())->method('getId')->willReturn($itemSource); |
|
956 | - |
|
957 | - |
|
958 | - $instance = $this->getInstance(['createShareObject']); |
|
959 | - |
|
960 | - $this->createDummyShare($itemType, 111, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
961 | - $id = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
962 | - |
|
963 | - $instance->expects($this->once())->method('createShareObject') |
|
964 | - ->willReturnCallback( |
|
965 | - function ($data) use ($uidOwner, $sharedBy, $id) { |
|
966 | - $this->assertSame($uidOwner, $data['uid_owner']); |
|
967 | - $this->assertSame($sharedBy, $data['uid_initiator']); |
|
968 | - $this->assertSame($id, (int)$data['id']); |
|
969 | - return $this->share; |
|
970 | - } |
|
971 | - ); |
|
972 | - |
|
973 | - $result = $instance->getSharesByPath($node); |
|
974 | - |
|
975 | - $this->assertTrue(is_array($result)); |
|
976 | - $this->assertSame(1, count($result)); |
|
977 | - $this->assertInstanceOf('OCP\Share\IShare', $result[0]); |
|
978 | - } |
|
979 | - |
|
980 | - public function testGetShareByToken(): void { |
|
981 | - $itemSource = 11; |
|
982 | - $itemType = 'file'; |
|
983 | - $shareWith = '[email protected]'; |
|
984 | - $sharedBy = 'user1'; |
|
985 | - $uidOwner = 'user2'; |
|
986 | - $permissions = 1; |
|
987 | - $token = 'token'; |
|
53 | + private IDBConnection $connection; |
|
54 | + |
|
55 | + private IL10N&MockObject $l; |
|
56 | + private IShare&MockObject $share; |
|
57 | + private IConfig&MockObject $config; |
|
58 | + private IMailer&MockObject $mailer; |
|
59 | + private IHasher&MockObject $hasher; |
|
60 | + private Defaults&MockObject $defaults; |
|
61 | + private IManager&MockObject $shareManager; |
|
62 | + private LoggerInterface&MockObject $logger; |
|
63 | + private IRootFolder&MockObject $rootFolder; |
|
64 | + private IUserManager&MockObject $userManager; |
|
65 | + private ISecureRandom&MockObject $secureRandom; |
|
66 | + private IURLGenerator&MockObject $urlGenerator; |
|
67 | + private SettingsManager&MockObject $settingsManager; |
|
68 | + private IActivityManager&MockObject $activityManager; |
|
69 | + private IEventDispatcher&MockObject $eventDispatcher; |
|
70 | + |
|
71 | + protected function setUp(): void { |
|
72 | + parent::setUp(); |
|
73 | + |
|
74 | + $this->connection = Server::get(IDBConnection::class); |
|
75 | + |
|
76 | + $this->l = $this->createMock(IL10N::class); |
|
77 | + $this->l->method('t') |
|
78 | + ->willReturnCallback(function ($text, $parameters = []) { |
|
79 | + return vsprintf($text, $parameters); |
|
80 | + }); |
|
81 | + $this->config = $this->createMock(IConfig::class); |
|
82 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
83 | + $this->rootFolder = $this->createMock('OCP\Files\IRootFolder'); |
|
84 | + $this->userManager = $this->createMock(IUserManager::class); |
|
85 | + $this->secureRandom = $this->createMock('\OCP\Security\ISecureRandom'); |
|
86 | + $this->mailer = $this->createMock('\OCP\Mail\IMailer'); |
|
87 | + $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
88 | + $this->share = $this->createMock(IShare::class); |
|
89 | + $this->activityManager = $this->createMock('OCP\Activity\IManager'); |
|
90 | + $this->settingsManager = $this->createMock(SettingsManager::class); |
|
91 | + $this->defaults = $this->createMock(Defaults::class); |
|
92 | + $this->hasher = $this->createMock(IHasher::class); |
|
93 | + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); |
|
94 | + $this->shareManager = $this->createMock(IManager::class); |
|
95 | + |
|
96 | + $this->userManager->expects($this->any())->method('userExists')->willReturn(true); |
|
97 | + $this->config->expects($this->any())->method('getAppValue')->with('core', 'enforce_strict_email_check')->willReturn('yes'); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * get instance of Mocked ShareByMailProvider |
|
102 | + * |
|
103 | + * @param array $mockedMethods internal methods which should be mocked |
|
104 | + * @return \PHPUnit\Framework\MockObject\MockObject | ShareByMailProvider |
|
105 | + */ |
|
106 | + private function getInstance(array $mockedMethods = []) { |
|
107 | + if (!empty($mockedMethods)) { |
|
108 | + return $this->getMockBuilder(ShareByMailProvider::class) |
|
109 | + ->setConstructorArgs([ |
|
110 | + $this->config, |
|
111 | + $this->connection, |
|
112 | + $this->secureRandom, |
|
113 | + $this->userManager, |
|
114 | + $this->rootFolder, |
|
115 | + $this->l, |
|
116 | + $this->logger, |
|
117 | + $this->mailer, |
|
118 | + $this->urlGenerator, |
|
119 | + $this->activityManager, |
|
120 | + $this->settingsManager, |
|
121 | + $this->defaults, |
|
122 | + $this->hasher, |
|
123 | + $this->eventDispatcher, |
|
124 | + $this->shareManager, |
|
125 | + ]) |
|
126 | + ->onlyMethods($mockedMethods) |
|
127 | + ->getMock(); |
|
128 | + } |
|
129 | + |
|
130 | + return new ShareByMailProvider( |
|
131 | + $this->config, |
|
132 | + $this->connection, |
|
133 | + $this->secureRandom, |
|
134 | + $this->userManager, |
|
135 | + $this->rootFolder, |
|
136 | + $this->l, |
|
137 | + $this->logger, |
|
138 | + $this->mailer, |
|
139 | + $this->urlGenerator, |
|
140 | + $this->activityManager, |
|
141 | + $this->settingsManager, |
|
142 | + $this->defaults, |
|
143 | + $this->hasher, |
|
144 | + $this->eventDispatcher, |
|
145 | + $this->shareManager, |
|
146 | + ); |
|
147 | + } |
|
148 | + |
|
149 | + protected function tearDown(): void { |
|
150 | + $this->connection |
|
151 | + ->getQueryBuilder() |
|
152 | + ->delete('share') |
|
153 | + ->executeStatement(); |
|
154 | + |
|
155 | + parent::tearDown(); |
|
156 | + } |
|
157 | + |
|
158 | + public function testCreate(): void { |
|
159 | + $expectedShare = $this->createMock(IShare::class); |
|
160 | + |
|
161 | + $share = $this->createMock(IShare::class); |
|
162 | + $share->expects($this->any())->method('getSharedWith')->willReturn('user1'); |
|
163 | + |
|
164 | + $node = $this->createMock(File::class); |
|
165 | + $node->expects($this->any())->method('getName')->willReturn('filename'); |
|
166 | + |
|
167 | + $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'sendEmail', 'sendPassword']); |
|
168 | + |
|
169 | + $instance->expects($this->once())->method('getSharedWith')->willReturn([]); |
|
170 | + $instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42); |
|
171 | + $instance->expects($this->once())->method('createShareActivity')->with($share); |
|
172 | + $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']); |
|
173 | + $instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($expectedShare); |
|
174 | + $share->expects($this->any())->method('getNode')->willReturn($node); |
|
175 | + |
|
176 | + // As share api link password is not enforced, the password will not be generated. |
|
177 | + $this->shareManager->expects($this->once())->method('shareApiLinkEnforcePassword')->willReturn(false); |
|
178 | + $this->settingsManager->expects($this->never())->method('sendPasswordByMail'); |
|
179 | + |
|
180 | + // Mail notification is triggered by the share manager. |
|
181 | + $instance->expects($this->never())->method('sendEmail'); |
|
182 | + $instance->expects($this->never())->method('sendPassword'); |
|
183 | + |
|
184 | + $this->assertSame($expectedShare, $instance->create($share)); |
|
185 | + } |
|
186 | + |
|
187 | + public function testCreateSendPasswordByMailWithoutEnforcedPasswordProtection(): void { |
|
188 | + $expectedShare = $this->createMock(IShare::class); |
|
189 | + |
|
190 | + $node = $this->createMock(File::class); |
|
191 | + $node->expects($this->any())->method('getName')->willReturn('filename'); |
|
192 | + |
|
193 | + $share = $this->createMock(IShare::class); |
|
194 | + $share->expects($this->any())->method('getSharedWith')->willReturn('receiver@examplelölöl.com'); |
|
195 | + $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false); |
|
196 | + $share->expects($this->any())->method('getSharedBy')->willReturn('owner'); |
|
197 | + $share->expects($this->any())->method('getNode')->willReturn($node); |
|
198 | + $share->expects($this->any())->method('getId')->willReturn(42); |
|
199 | + $share->expects($this->any())->method('getNote')->willReturn(''); |
|
200 | + $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
201 | + |
|
202 | + // Assume the mail address is valid. |
|
203 | + $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); |
|
204 | + |
|
205 | + $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'autoGeneratePassword', 'createPasswordSendActivity', 'sendEmail', 'sendPassword', 'sendPasswordToOwner']); |
|
206 | + $instance->expects($this->once())->method('getSharedWith')->willReturn([]); |
|
207 | + $instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42); |
|
208 | + $instance->expects($this->once())->method('createShareActivity')->with($share); |
|
209 | + $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']); |
|
210 | + $instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($expectedShare); |
|
211 | + $share->expects($this->any())->method('getNode')->willReturn($node); |
|
212 | + |
|
213 | + // The autogenerated password should not be mailed. |
|
214 | + $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false); |
|
215 | + $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true); |
|
216 | + $instance->expects($this->never())->method('autoGeneratePassword'); |
|
217 | + |
|
218 | + // No password is set and no password sent via talk is requested |
|
219 | + $instance->expects($this->once())->method('sendEmail')->with($share, ['receiver@examplelölöl.com']); |
|
220 | + $instance->expects($this->never())->method('sendPassword'); |
|
221 | + $instance->expects($this->never())->method('sendPasswordToOwner'); |
|
222 | + |
|
223 | + // The manager sends the mail notification. |
|
224 | + // For the sake of testing simplicity, we will handle it ourselves. |
|
225 | + $this->assertSame($expectedShare, $instance->create($share)); |
|
226 | + $instance->sendMailNotification($share); |
|
227 | + } |
|
228 | + |
|
229 | + public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswordProtectionWithPermanentPassword(): void { |
|
230 | + $expectedShare = $this->createMock(IShare::class); |
|
231 | + |
|
232 | + $node = $this->createMock(File::class); |
|
233 | + $node->expects($this->any())->method('getName')->willReturn('filename'); |
|
234 | + |
|
235 | + $share = $this->createMock(IShare::class); |
|
236 | + $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
237 | + $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false); |
|
238 | + $share->expects($this->any())->method('getSharedBy')->willReturn('owner'); |
|
239 | + $share->expects($this->any())->method('getNode')->willReturn($node); |
|
240 | + $share->expects($this->any())->method('getId')->willReturn(42); |
|
241 | + $share->expects($this->any())->method('getNote')->willReturn(''); |
|
242 | + $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
243 | + |
|
244 | + // Assume the mail address is valid. |
|
245 | + $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); |
|
246 | + |
|
247 | + $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'autoGeneratePassword', 'createPasswordSendActivity', 'sendEmail', 'sendPassword', 'sendPasswordToOwner']); |
|
248 | + |
|
249 | + $instance->expects($this->once())->method('getSharedWith')->willReturn([]); |
|
250 | + $instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42); |
|
251 | + $instance->expects($this->once())->method('createShareActivity')->with($share); |
|
252 | + $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare', 'password' => 'password']); |
|
253 | + $instance->expects($this->once())->method('createShareObject')->with(['rawShare', 'password' => 'password'])->willReturn($expectedShare); |
|
254 | + $share->expects($this->any())->method('getNode')->willReturn($node); |
|
255 | + |
|
256 | + $share->expects($this->any())->method('getPassword')->willReturn('password'); |
|
257 | + $this->hasher->expects($this->once())->method('hash')->with('password')->willReturn('passwordHashed'); |
|
258 | + $share->expects($this->once())->method('setPassword')->with('passwordHashed'); |
|
259 | + |
|
260 | + // The given password (but not the autogenerated password) should not be |
|
261 | + // mailed to the receiver of the share because permanent passwords are not enforced. |
|
262 | + $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false); |
|
263 | + $this->config->expects($this->once())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(false); |
|
264 | + $instance->expects($this->never())->method('autoGeneratePassword'); |
|
265 | + |
|
266 | + // A password is set but no password sent via talk has been requested |
|
267 | + $instance->expects($this->once())->method('sendEmail')->with($share, ['[email protected]']); |
|
268 | + $instance->expects($this->once())->method('sendPassword')->with($share, 'password'); |
|
269 | + $instance->expects($this->never())->method('sendPasswordToOwner'); |
|
270 | + |
|
271 | + $this->assertSame($expectedShare, $instance->create($share)); |
|
272 | + $instance->sendMailNotification($share); |
|
273 | + } |
|
274 | + |
|
275 | + public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswordProtectionWithoutPermanentPassword(): void { |
|
276 | + $expectedShare = $this->createMock(IShare::class); |
|
277 | + |
|
278 | + $node = $this->createMock(File::class); |
|
279 | + $node->expects($this->any())->method('getName')->willReturn('filename'); |
|
280 | + |
|
281 | + $share = $this->createMock(IShare::class); |
|
282 | + $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
283 | + $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false); |
|
284 | + $share->expects($this->any())->method('getSharedBy')->willReturn('owner'); |
|
285 | + $share->expects($this->any())->method('getNode')->willReturn($node); |
|
286 | + $share->expects($this->any())->method('getId')->willReturn(42); |
|
287 | + $share->expects($this->any())->method('getNote')->willReturn(''); |
|
288 | + $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
289 | + |
|
290 | + // Assume the mail address is valid. |
|
291 | + $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); |
|
292 | + |
|
293 | + $instance = $this->getInstance([ |
|
294 | + 'getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', |
|
295 | + 'createShareActivity', 'autoGeneratePassword', 'createPasswordSendActivity', |
|
296 | + 'sendEmail', 'sendPassword', 'sendPasswordToOwner', |
|
297 | + ]); |
|
298 | + |
|
299 | + $instance->expects($this->once())->method('getSharedWith')->willReturn([]); |
|
300 | + $instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42); |
|
301 | + $instance->expects($this->once())->method('createShareActivity')->with($share); |
|
302 | + $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare', 'password' => 'password']); |
|
303 | + $instance->expects($this->once())->method('createShareObject')->with(['rawShare', 'password' => 'password'])->willReturn($expectedShare); |
|
304 | + $share->expects($this->any())->method('getNode')->willReturn($node); |
|
305 | + |
|
306 | + $share->expects($this->any())->method('getPassword')->willReturn('password'); |
|
307 | + $this->hasher->expects($this->once())->method('hash')->with('password')->willReturn('passwordHashed'); |
|
308 | + $share->expects($this->once())->method('setPassword')->with('passwordHashed'); |
|
309 | + |
|
310 | + // No password is generated, so no emails need to be sent |
|
311 | + // aside from the main email notification. |
|
312 | + $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false); |
|
313 | + $instance->expects($this->never())->method('autoGeneratePassword'); |
|
314 | + $this->config->expects($this->once())->method('getSystemValue') |
|
315 | + ->with('sharing.enable_mail_link_password_expiration') |
|
316 | + ->willReturn(true); |
|
317 | + |
|
318 | + // No password has been set and no password sent via talk has been requested, |
|
319 | + // but password has been enforced for the whole instance and will be generated. |
|
320 | + $instance->expects($this->once())->method('sendEmail')->with($share, ['[email protected]']); |
|
321 | + $instance->expects($this->never())->method('sendPassword'); |
|
322 | + $instance->expects($this->never())->method('sendPasswordToOwner'); |
|
323 | + |
|
324 | + $this->assertSame($expectedShare, $instance->create($share)); |
|
325 | + $instance->sendMailNotification($share); |
|
326 | + } |
|
327 | + |
|
328 | + public function testCreateSendPasswordByMailWithEnforcedPasswordProtectionWithPermanentPassword(): void { |
|
329 | + $expectedShare = $this->createMock(IShare::class); |
|
330 | + |
|
331 | + $node = $this->createMock(File::class); |
|
332 | + $node->expects($this->any())->method('getName')->willReturn('filename'); |
|
333 | + |
|
334 | + $share = $this->createMock(IShare::class); |
|
335 | + $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
336 | + $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false); |
|
337 | + $share->expects($this->any())->method('getSharedBy')->willReturn('owner'); |
|
338 | + $share->expects($this->any())->method('getNode')->willReturn($node); |
|
339 | + $share->expects($this->any())->method('getId')->willReturn(42); |
|
340 | + $share->expects($this->any())->method('getNote')->willReturn(''); |
|
341 | + $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
342 | + |
|
343 | + $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute') |
|
344 | + ->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) |
|
345 | + ->willReturn('https://example.com/file.txt'); |
|
346 | + |
|
347 | + $this->secureRandom->expects($this->once()) |
|
348 | + ->method('generate') |
|
349 | + ->with(8, ISecureRandom::CHAR_HUMAN_READABLE) |
|
350 | + ->willReturn('autogeneratedPassword'); |
|
351 | + $this->eventDispatcher->expects($this->once()) |
|
352 | + ->method('dispatchTyped') |
|
353 | + ->with(new GenerateSecurePasswordEvent(PasswordContext::SHARING)); |
|
354 | + |
|
355 | + // Assume the mail address is valid. |
|
356 | + $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); |
|
357 | + |
|
358 | + $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'createPasswordSendActivity', 'sendPasswordToOwner']); |
|
359 | + |
|
360 | + $instance->expects($this->once())->method('getSharedWith')->willReturn([]); |
|
361 | + $instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42); |
|
362 | + $instance->expects($this->once())->method('createShareActivity')->with($share); |
|
363 | + $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare', 'password' => 'autogeneratedPassword']); |
|
364 | + $instance->expects($this->once())->method('createShareObject')->with(['rawShare', 'password' => 'autogeneratedPassword'])->willReturn($expectedShare); |
|
365 | + |
|
366 | + // Initially not set, but will be set by the autoGeneratePassword method. |
|
367 | + $share->expects($this->exactly(3))->method('getPassword')->willReturnOnConsecutiveCalls(null, 'autogeneratedPassword', 'autogeneratedPassword'); |
|
368 | + $this->hasher->expects($this->once())->method('hash')->with('autogeneratedPassword')->willReturn('autogeneratedPasswordHashed'); |
|
369 | + $share->expects($this->once())->method('setPassword')->with('autogeneratedPasswordHashed'); |
|
370 | + |
|
371 | + // The autogenerated password should be mailed to the receiver of the share because permanent passwords are enforced. |
|
372 | + $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(true); |
|
373 | + $this->config->expects($this->any())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(false); |
|
374 | + $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true); |
|
375 | + |
|
376 | + $message = $this->createMock(IMessage::class); |
|
377 | + $message->expects($this->exactly(2))->method('setTo')->with(['[email protected]']); |
|
378 | + $this->mailer->expects($this->exactly(2))->method('createMessage')->willReturn($message); |
|
379 | + $calls = [ |
|
380 | + [ |
|
381 | + 'sharebymail.RecipientNotification', |
|
382 | + [ |
|
383 | + 'filename' => 'filename', |
|
384 | + 'link' => 'https://example.com/file.txt', |
|
385 | + 'initiator' => 'owner', |
|
386 | + 'expiration' => null, |
|
387 | + 'shareWith' => '[email protected]', |
|
388 | + 'note' => '', |
|
389 | + ], |
|
390 | + ], |
|
391 | + [ |
|
392 | + 'sharebymail.RecipientPasswordNotification', |
|
393 | + [ |
|
394 | + 'filename' => 'filename', |
|
395 | + 'password' => 'autogeneratedPassword', |
|
396 | + 'initiator' => 'owner', |
|
397 | + 'initiatorEmail' => null, |
|
398 | + 'shareWith' => '[email protected]', |
|
399 | + ], |
|
400 | + ], |
|
401 | + ]; |
|
402 | + $this->mailer->expects($this->exactly(2)) |
|
403 | + ->method('createEMailTemplate') |
|
404 | + ->willReturnCallback(function () use (&$calls) { |
|
405 | + $expected = array_shift($calls); |
|
406 | + $this->assertEquals($expected, func_get_args()); |
|
407 | + return $this->createMock(IEMailTemplate::class); |
|
408 | + }); |
|
409 | + |
|
410 | + // Main email notification is sent as well as the password |
|
411 | + // to the recipient because shareApiLinkEnforcePassword is enabled. |
|
412 | + $this->mailer->expects($this->exactly(2))->method('send'); |
|
413 | + $instance->expects($this->never())->method('sendPasswordToOwner'); |
|
414 | + |
|
415 | + $this->assertSame($expectedShare, $instance->create($share)); |
|
416 | + $instance->sendMailNotification($share); |
|
417 | + } |
|
418 | + |
|
419 | + public function testCreateSendPasswordByMailWithPasswordAndWithEnforcedPasswordProtectionWithPermanentPassword(): void { |
|
420 | + $expectedShare = $this->createMock(IShare::class); |
|
421 | + |
|
422 | + $node = $this->createMock(File::class); |
|
423 | + $node->expects($this->any())->method('getName')->willReturn('filename'); |
|
424 | + |
|
425 | + $share = $this->createMock(IShare::class); |
|
426 | + $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
427 | + $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false); |
|
428 | + $share->expects($this->any())->method('getSharedBy')->willReturn('owner'); |
|
429 | + $share->expects($this->any())->method('getNode')->willReturn($node); |
|
430 | + $share->expects($this->any())->method('getId')->willReturn(42); |
|
431 | + $share->expects($this->any())->method('getNote')->willReturn(''); |
|
432 | + $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
433 | + |
|
434 | + $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute') |
|
435 | + ->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) |
|
436 | + ->willReturn('https://example.com/file.txt'); |
|
437 | + |
|
438 | + // Assume the mail address is valid. |
|
439 | + $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); |
|
440 | + |
|
441 | + $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'autoGeneratePassword', 'createPasswordSendActivity', 'sendPasswordToOwner']); |
|
442 | + |
|
443 | + $instance->expects($this->once())->method('getSharedWith')->willReturn([]); |
|
444 | + $instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42); |
|
445 | + $instance->expects($this->once())->method('createShareActivity')->with($share); |
|
446 | + $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare', 'password' => 'password']); |
|
447 | + $instance->expects($this->once())->method('createShareObject')->with(['rawShare', 'password' => 'password'])->willReturn($expectedShare); |
|
448 | + |
|
449 | + $share->expects($this->exactly(3))->method('getPassword')->willReturn('password'); |
|
450 | + $this->hasher->expects($this->once())->method('hash')->with('password')->willReturn('passwordHashed'); |
|
451 | + $share->expects($this->once())->method('setPassword')->with('passwordHashed'); |
|
452 | + |
|
453 | + // The given password (but not the autogenerated password) should be |
|
454 | + // mailed to the receiver of the share. |
|
455 | + $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(true); |
|
456 | + $this->config->expects($this->any())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(false); |
|
457 | + $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true); |
|
458 | + $instance->expects($this->never())->method('autoGeneratePassword'); |
|
459 | + |
|
460 | + $message = $this->createMock(IMessage::class); |
|
461 | + $message->expects($this->exactly(2))->method('setTo')->with(['[email protected]']); |
|
462 | + $this->mailer->expects($this->exactly(2))->method('createMessage')->willReturn($message); |
|
463 | + |
|
464 | + $calls = [ |
|
465 | + [ |
|
466 | + 'sharebymail.RecipientNotification', |
|
467 | + [ |
|
468 | + 'filename' => 'filename', |
|
469 | + 'link' => 'https://example.com/file.txt', |
|
470 | + 'initiator' => 'owner', |
|
471 | + 'expiration' => null, |
|
472 | + 'shareWith' => '[email protected]', |
|
473 | + 'note' => '', |
|
474 | + ], |
|
475 | + ], |
|
476 | + [ |
|
477 | + 'sharebymail.RecipientPasswordNotification', |
|
478 | + [ |
|
479 | + 'filename' => 'filename', |
|
480 | + 'password' => 'password', |
|
481 | + 'initiator' => 'owner', |
|
482 | + 'initiatorEmail' => null, |
|
483 | + 'shareWith' => '[email protected]', |
|
484 | + ], |
|
485 | + ], |
|
486 | + ]; |
|
487 | + $this->mailer->expects($this->exactly(2)) |
|
488 | + ->method('createEMailTemplate') |
|
489 | + ->willReturnCallback(function () use (&$calls) { |
|
490 | + $expected = array_shift($calls); |
|
491 | + $this->assertEquals($expected, func_get_args()); |
|
492 | + return $this->createMock(IEMailTemplate::class); |
|
493 | + }); |
|
494 | + |
|
495 | + // Main email notification is sent as well as the password |
|
496 | + // to the recipient because the password is set. |
|
497 | + $this->mailer->expects($this->exactly(2))->method('send'); |
|
498 | + $instance->expects($this->never())->method('sendPasswordToOwner'); |
|
499 | + |
|
500 | + $this->assertSame($expectedShare, $instance->create($share)); |
|
501 | + $instance->sendMailNotification($share); |
|
502 | + } |
|
503 | + |
|
504 | + public function testCreateSendPasswordByTalkWithEnforcedPasswordProtectionWithPermanentPassword(): void { |
|
505 | + $expectedShare = $this->createMock(IShare::class); |
|
506 | + |
|
507 | + // The owner of the share. |
|
508 | + $owner = $this->createMock(IUser::class); |
|
509 | + $this->userManager->expects($this->any())->method('get')->with('owner')->willReturn($owner); |
|
510 | + $owner->expects($this->any())->method('getEMailAddress')->willReturn('[email protected]'); |
|
511 | + $owner->expects($this->any())->method('getDisplayName')->willReturn('owner'); |
|
512 | + |
|
513 | + $node = $this->createMock(File::class); |
|
514 | + $node->expects($this->any())->method('getName')->willReturn('filename'); |
|
515 | + |
|
516 | + $share = $this->createMock(IShare::class); |
|
517 | + $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
518 | + $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(true); |
|
519 | + $share->expects($this->any())->method('getSharedBy')->willReturn('owner'); |
|
520 | + $share->expects($this->any())->method('getNode')->willReturn($node); |
|
521 | + $share->expects($this->any())->method('getId')->willReturn(42); |
|
522 | + $share->expects($this->any())->method('getNote')->willReturn(''); |
|
523 | + $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
524 | + |
|
525 | + $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute') |
|
526 | + ->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) |
|
527 | + ->willReturn('https://example.com/file.txt'); |
|
528 | + |
|
529 | + // Assume the mail address is valid. |
|
530 | + $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); |
|
531 | + |
|
532 | + $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'autoGeneratePassword', 'createPasswordSendActivity']); |
|
533 | + |
|
534 | + $instance->expects($this->once())->method('getSharedWith')->willReturn([]); |
|
535 | + $instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42); |
|
536 | + $instance->expects($this->once())->method('createShareActivity')->with($share); |
|
537 | + $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare', 'password' => 'autogeneratedPassword']); |
|
538 | + $instance->expects($this->once())->method('createShareObject')->with(['rawShare', 'password' => 'autogeneratedPassword'])->willReturn($expectedShare); |
|
539 | + |
|
540 | + $share->expects($this->exactly(4))->method('getPassword')->willReturnOnConsecutiveCalls(null, 'autogeneratedPassword', 'autogeneratedPassword', 'autogeneratedPassword'); |
|
541 | + $this->hasher->expects($this->once())->method('hash')->with('autogeneratedPassword')->willReturn('autogeneratedPasswordHashed'); |
|
542 | + $share->expects($this->once())->method('setPassword')->with('autogeneratedPasswordHashed'); |
|
543 | + |
|
544 | + // The autogenerated password should be mailed to the owner of the share. |
|
545 | + $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(true); |
|
546 | + $this->config->expects($this->any())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(false); |
|
547 | + $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true); |
|
548 | + $instance->expects($this->once())->method('autoGeneratePassword')->with($share)->willReturn('autogeneratedPassword'); |
|
549 | + |
|
550 | + $message = $this->createMock(IMessage::class); |
|
551 | + $setToCalls = [ |
|
552 | + [['[email protected]']], |
|
553 | + [['[email protected]' => 'owner']], |
|
554 | + ]; |
|
555 | + $message->expects($this->exactly(2)) |
|
556 | + ->method('setTo') |
|
557 | + ->willReturnCallback(function () use (&$setToCalls, $message) { |
|
558 | + $expected = array_shift($setToCalls); |
|
559 | + $this->assertEquals($expected, func_get_args()); |
|
560 | + return $message; |
|
561 | + }); |
|
562 | + $this->mailer->expects($this->exactly(2))->method('createMessage')->willReturn($message); |
|
563 | + |
|
564 | + $calls = [ |
|
565 | + [ |
|
566 | + 'sharebymail.RecipientNotification', |
|
567 | + [ |
|
568 | + 'filename' => 'filename', |
|
569 | + 'link' => 'https://example.com/file.txt', |
|
570 | + 'initiator' => 'owner', |
|
571 | + 'expiration' => null, |
|
572 | + 'shareWith' => '[email protected]', |
|
573 | + 'note' => '', |
|
574 | + ], |
|
575 | + ], |
|
576 | + [ |
|
577 | + 'sharebymail.OwnerPasswordNotification', |
|
578 | + [ |
|
579 | + 'filename' => 'filename', |
|
580 | + 'password' => 'autogeneratedPassword', |
|
581 | + 'initiator' => 'owner', |
|
582 | + 'initiatorEmail' => '[email protected]', |
|
583 | + 'shareWith' => '[email protected]', |
|
584 | + ], |
|
585 | + ], |
|
586 | + ]; |
|
587 | + $this->mailer->expects($this->exactly(2)) |
|
588 | + ->method('createEMailTemplate') |
|
589 | + ->willReturnCallback(function () use (&$calls) { |
|
590 | + $expected = array_shift($calls); |
|
591 | + $this->assertEquals($expected, func_get_args()); |
|
592 | + return $this->createMock(IEMailTemplate::class); |
|
593 | + }); |
|
594 | + |
|
595 | + // Main email notification is sent as well as the password to owner |
|
596 | + // because the password is set and SendPasswordByTalk is enabled. |
|
597 | + $this->mailer->expects($this->exactly(2))->method('send'); |
|
598 | + |
|
599 | + $this->assertSame($expectedShare, $instance->create($share)); |
|
600 | + $instance->sendMailNotification($share); |
|
601 | + } |
|
602 | + |
|
603 | + // If attributes is set to multiple emails, use them as BCC |
|
604 | + public function sendNotificationToMultipleEmails() { |
|
605 | + $expectedShare = $this->createMock(IShare::class); |
|
606 | + |
|
607 | + $node = $this->createMock(File::class); |
|
608 | + $node->expects($this->any())->method('getName')->willReturn('filename'); |
|
609 | + |
|
610 | + $share = $this->createMock(IShare::class); |
|
611 | + $share->expects($this->any())->method('getSharedWith')->willReturn(''); |
|
612 | + $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false); |
|
613 | + $share->expects($this->any())->method('getSharedBy')->willReturn('owner'); |
|
614 | + $share->expects($this->any())->method('getNode')->willReturn($node); |
|
615 | + $share->expects($this->any())->method('getId')->willReturn(42); |
|
616 | + $share->expects($this->any())->method('getNote')->willReturn(''); |
|
617 | + $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
618 | + |
|
619 | + $attributes = $this->createMock(IAttributes::class); |
|
620 | + $share->expects($this->any())->method('getAttributes')->willReturn($attributes); |
|
621 | + $attributes->expects($this->any())->method('getAttribute')->with('shareWith', 'emails')->willReturn([ |
|
622 | + '[email protected]', |
|
623 | + '[email protected]', |
|
624 | + '[email protected]', |
|
625 | + ]); |
|
626 | + |
|
627 | + // Assume the mail address is valid. |
|
628 | + $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); |
|
629 | + |
|
630 | + $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'autoGeneratePassword', 'createPasswordSendActivity', 'sendEmail', 'sendPassword', 'sendPasswordToOwner']); |
|
631 | + |
|
632 | + $instance->expects($this->once())->method('getSharedWith')->willReturn([]); |
|
633 | + $instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42); |
|
634 | + $instance->expects($this->once())->method('createShareActivity')->with($share); |
|
635 | + $instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare', 'password' => 'password']); |
|
636 | + $instance->expects($this->once())->method('createShareObject')->with(['rawShare', 'password' => 'password'])->willReturn($expectedShare); |
|
637 | + $share->expects($this->any())->method('getNode')->willReturn($node); |
|
638 | + |
|
639 | + $share->expects($this->any())->method('getPassword')->willReturn('password'); |
|
640 | + $this->hasher->expects($this->once())->method('hash')->with('password')->willReturn('passwordHashed'); |
|
641 | + $share->expects($this->once())->method('setPassword')->with('passwordHashed'); |
|
642 | + |
|
643 | + // The given password (but not the autogenerated password) should not be |
|
644 | + // mailed to the receiver of the share because permanent passwords are not enforced. |
|
645 | + $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false); |
|
646 | + $this->config->expects($this->once())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(false); |
|
647 | + $instance->expects($this->never())->method('autoGeneratePassword'); |
|
648 | + |
|
649 | + // A password is set but no password sent via talk has been requested |
|
650 | + $instance->expects($this->once())->method('sendEmail') |
|
651 | + ->with($share, ['[email protected]', '[email protected]', '[email protected]']); |
|
652 | + $instance->expects($this->once())->method('sendPassword')->with($share, 'password'); |
|
653 | + $instance->expects($this->never())->method('sendPasswordToOwner'); |
|
654 | + |
|
655 | + |
|
656 | + $message = $this->createMock(IMessage::class); |
|
657 | + $message->expects($this->never())->method('setTo'); |
|
658 | + $message->expects($this->exactly(2))->method('setBcc')->with(['[email protected]', '[email protected]', '[email protected]']); |
|
659 | + $this->mailer->expects($this->exactly(2))->method('createMessage')->willReturn($message); |
|
660 | + |
|
661 | + // Main email notification is sent as well as the password |
|
662 | + // to recipients because the password is set. |
|
663 | + $this->mailer->expects($this->exactly(2))->method('send'); |
|
664 | + |
|
665 | + $this->assertSame($expectedShare, $instance->create($share)); |
|
666 | + $instance->sendMailNotification($share); |
|
667 | + } |
|
668 | + |
|
669 | + public function testCreateFailed(): void { |
|
670 | + $this->expectException(\Exception::class); |
|
671 | + |
|
672 | + $this->share->expects($this->once())->method('getSharedWith')->willReturn('user1'); |
|
673 | + $node = $this->createMock('OCP\Files\Node'); |
|
674 | + $node->expects($this->any())->method('getName')->willReturn('fileName'); |
|
675 | + $this->share->expects($this->any())->method('getNode')->willReturn($node); |
|
676 | + |
|
677 | + $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject']); |
|
678 | + |
|
679 | + $instance->expects($this->once())->method('getSharedWith')->willReturn(['found']); |
|
680 | + $instance->expects($this->never())->method('createMailShare'); |
|
681 | + $instance->expects($this->never())->method('getRawShare'); |
|
682 | + $instance->expects($this->never())->method('createShareObject'); |
|
683 | + |
|
684 | + $this->assertSame('shareObject', |
|
685 | + $instance->create($this->share) |
|
686 | + ); |
|
687 | + } |
|
688 | + |
|
689 | + public function testCreateMailShare(): void { |
|
690 | + $this->share->expects($this->any())->method('getToken')->willReturn('token'); |
|
691 | + $this->share->expects($this->once())->method('setToken')->with('token'); |
|
692 | + $this->share->expects($this->any())->method('getSharedBy')->willReturn('[email protected]'); |
|
693 | + $this->share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
694 | + $this->share->expects($this->any())->method('getNote')->willReturn('Check this!'); |
|
695 | + $this->share->expects($this->any())->method('getMailSend')->willReturn(true); |
|
696 | + |
|
697 | + $node = $this->createMock('OCP\Files\Node'); |
|
698 | + $node->expects($this->any())->method('getName')->willReturn('fileName'); |
|
699 | + $this->share->expects($this->any())->method('getNode')->willReturn($node); |
|
700 | + |
|
701 | + $instance = $this->getInstance(['generateToken', 'addShareToDB', 'sendMailNotification']); |
|
702 | + |
|
703 | + $instance->expects($this->once())->method('generateToken')->willReturn('token'); |
|
704 | + $instance->expects($this->once())->method('addShareToDB')->willReturn(42); |
|
705 | + |
|
706 | + // The manager handle the mail sending |
|
707 | + $instance->expects($this->never())->method('sendMailNotification'); |
|
708 | + |
|
709 | + $this->assertSame(42, |
|
710 | + $this->invokePrivate($instance, 'createMailShare', [$this->share]) |
|
711 | + ); |
|
712 | + } |
|
713 | + |
|
714 | + public function testGenerateToken(): void { |
|
715 | + $instance = $this->getInstance(); |
|
716 | + |
|
717 | + $this->secureRandom->expects($this->once())->method('generate')->willReturn('token'); |
|
718 | + |
|
719 | + $this->assertSame('token', |
|
720 | + $this->invokePrivate($instance, 'generateToken') |
|
721 | + ); |
|
722 | + } |
|
723 | + |
|
724 | + public function testAddShareToDB(): void { |
|
725 | + $itemSource = 11; |
|
726 | + $itemType = 'file'; |
|
727 | + $shareWith = '[email protected]'; |
|
728 | + $sharedBy = 'user1'; |
|
729 | + $uidOwner = 'user2'; |
|
730 | + $permissions = 1; |
|
731 | + $token = 'token'; |
|
732 | + $password = 'password'; |
|
733 | + $sendPasswordByTalk = true; |
|
734 | + $hideDownload = true; |
|
735 | + $label = 'label'; |
|
736 | + $expiration = new \DateTime(); |
|
737 | + $passwordExpirationTime = new \DateTime(); |
|
738 | + |
|
739 | + |
|
740 | + $instance = $this->getInstance(); |
|
741 | + $id = $this->invokePrivate( |
|
742 | + $instance, |
|
743 | + 'addShareToDB', |
|
744 | + [ |
|
745 | + $itemSource, |
|
746 | + $itemType, |
|
747 | + $shareWith, |
|
748 | + $sharedBy, |
|
749 | + $uidOwner, |
|
750 | + $permissions, |
|
751 | + $token, |
|
752 | + $password, |
|
753 | + $passwordExpirationTime, |
|
754 | + $sendPasswordByTalk, |
|
755 | + $hideDownload, |
|
756 | + $label, |
|
757 | + $expiration |
|
758 | + ] |
|
759 | + ); |
|
760 | + |
|
761 | + $qb = $this->connection->getQueryBuilder(); |
|
762 | + $qb->select('*') |
|
763 | + ->from('share') |
|
764 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
765 | + |
|
766 | + $qResult = $qb->execute(); |
|
767 | + $result = $qResult->fetchAll(); |
|
768 | + $qResult->closeCursor(); |
|
769 | + |
|
770 | + $this->assertSame(1, count($result)); |
|
771 | + |
|
772 | + $this->assertSame($itemSource, (int)$result[0]['item_source']); |
|
773 | + $this->assertSame($itemType, $result[0]['item_type']); |
|
774 | + $this->assertSame($shareWith, $result[0]['share_with']); |
|
775 | + $this->assertSame($sharedBy, $result[0]['uid_initiator']); |
|
776 | + $this->assertSame($uidOwner, $result[0]['uid_owner']); |
|
777 | + $this->assertSame($permissions, (int)$result[0]['permissions']); |
|
778 | + $this->assertSame($token, $result[0]['token']); |
|
779 | + $this->assertSame($password, $result[0]['password']); |
|
780 | + $this->assertSame($passwordExpirationTime->getTimestamp(), \DateTime::createFromFormat('Y-m-d H:i:s', $result[0]['password_expiration_time'])->getTimestamp()); |
|
781 | + $this->assertSame($sendPasswordByTalk, (bool)$result[0]['password_by_talk']); |
|
782 | + $this->assertSame($hideDownload, (bool)$result[0]['hide_download']); |
|
783 | + $this->assertSame($label, $result[0]['label']); |
|
784 | + $this->assertSame($expiration->getTimestamp(), \DateTime::createFromFormat('Y-m-d H:i:s', $result[0]['expiration'])->getTimestamp()); |
|
785 | + } |
|
786 | + |
|
787 | + public function testUpdate(): void { |
|
788 | + $itemSource = 11; |
|
789 | + $itemType = 'file'; |
|
790 | + $shareWith = '[email protected]'; |
|
791 | + $sharedBy = 'user1'; |
|
792 | + $uidOwner = 'user2'; |
|
793 | + $permissions = 1; |
|
794 | + $token = 'token'; |
|
795 | + $note = 'personal note'; |
|
796 | + |
|
797 | + |
|
798 | + $instance = $this->getInstance(); |
|
799 | + |
|
800 | + $id = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $note); |
|
801 | + |
|
802 | + $this->share->expects($this->once())->method('getPermissions')->willReturn($permissions + 1); |
|
803 | + $this->share->expects($this->once())->method('getShareOwner')->willReturn($uidOwner); |
|
804 | + $this->share->expects($this->once())->method('getSharedBy')->willReturn($sharedBy); |
|
805 | + $this->share->expects($this->any())->method('getNote')->willReturn($note); |
|
806 | + $this->share->expects($this->atLeastOnce())->method('getId')->willReturn($id); |
|
807 | + $this->share->expects($this->atLeastOnce())->method('getNodeId')->willReturn($itemSource); |
|
808 | + $this->share->expects($this->once())->method('getSharedWith')->willReturn($shareWith); |
|
809 | + |
|
810 | + $this->assertSame($this->share, |
|
811 | + $instance->update($this->share) |
|
812 | + ); |
|
813 | + |
|
814 | + $qb = $this->connection->getQueryBuilder(); |
|
815 | + $qb->select('*') |
|
816 | + ->from('share') |
|
817 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
818 | + |
|
819 | + $qResult = $qb->execute(); |
|
820 | + $result = $qResult->fetchAll(); |
|
821 | + $qResult->closeCursor(); |
|
822 | + |
|
823 | + $this->assertSame(1, count($result)); |
|
824 | + |
|
825 | + $this->assertSame($itemSource, (int)$result[0]['item_source']); |
|
826 | + $this->assertSame($itemType, $result[0]['item_type']); |
|
827 | + $this->assertSame($shareWith, $result[0]['share_with']); |
|
828 | + $this->assertSame($sharedBy, $result[0]['uid_initiator']); |
|
829 | + $this->assertSame($uidOwner, $result[0]['uid_owner']); |
|
830 | + $this->assertSame($permissions + 1, (int)$result[0]['permissions']); |
|
831 | + $this->assertSame($token, $result[0]['token']); |
|
832 | + $this->assertSame($note, $result[0]['note']); |
|
833 | + } |
|
834 | + |
|
835 | + public static function dataUpdateSendPassword(): array { |
|
836 | + return [ |
|
837 | + ['password', 'hashed', 'hashed new', false, false, true], |
|
838 | + ['', 'hashed', 'hashed new', false, false, false], |
|
839 | + [null, 'hashed', 'hashed new', false, false, false], |
|
840 | + ['password', 'hashed', 'hashed', false, false, false], |
|
841 | + ['password', 'hashed', 'hashed new', false, true, false], |
|
842 | + ['password', 'hashed', 'hashed new', true, false, true], |
|
843 | + ['password', 'hashed', 'hashed', true, false, true], |
|
844 | + ]; |
|
845 | + } |
|
846 | + |
|
847 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataUpdateSendPassword')] |
|
848 | + public function testUpdateSendPassword(?string $plainTextPassword, string $originalPassword, string $newPassword, bool $originalSendPasswordByTalk, bool $newSendPasswordByTalk, bool $sendMail): void { |
|
849 | + $node = $this->createMock(File::class); |
|
850 | + $node->expects($this->any())->method('getName')->willReturn('filename'); |
|
851 | + |
|
852 | + $this->settingsManager->method('sendPasswordByMail')->willReturn(true); |
|
853 | + |
|
854 | + $originalShare = $this->createMock(IShare::class); |
|
855 | + $originalShare->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
856 | + $originalShare->expects($this->any())->method('getNode')->willReturn($node); |
|
857 | + $originalShare->expects($this->any())->method('getId')->willReturn(42); |
|
858 | + $originalShare->expects($this->any())->method('getPassword')->willReturn($originalPassword); |
|
859 | + $originalShare->expects($this->any())->method('getSendPasswordByTalk')->willReturn($originalSendPasswordByTalk); |
|
860 | + |
|
861 | + $share = $this->createMock(IShare::class); |
|
862 | + $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
863 | + $share->expects($this->any())->method('getNode')->willReturn($node); |
|
864 | + $share->expects($this->any())->method('getId')->willReturn(42); |
|
865 | + $share->expects($this->any())->method('getPassword')->willReturn($newPassword); |
|
866 | + $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn($newSendPasswordByTalk); |
|
867 | + |
|
868 | + if ($sendMail) { |
|
869 | + $this->mailer->expects($this->once())->method('createEMailTemplate')->with('sharebymail.RecipientPasswordNotification', [ |
|
870 | + 'filename' => 'filename', |
|
871 | + 'password' => $plainTextPassword, |
|
872 | + 'initiator' => null, |
|
873 | + 'initiatorEmail' => null, |
|
874 | + 'shareWith' => '[email protected]', |
|
875 | + ]); |
|
876 | + $this->mailer->expects($this->once())->method('send'); |
|
877 | + } else { |
|
878 | + $this->mailer->expects($this->never())->method('send'); |
|
879 | + } |
|
880 | + |
|
881 | + $instance = $this->getInstance(['getShareById', 'createPasswordSendActivity']); |
|
882 | + $instance->expects($this->once())->method('getShareById')->willReturn($originalShare); |
|
883 | + |
|
884 | + $this->assertSame($share, |
|
885 | + $instance->update($share, $plainTextPassword) |
|
886 | + ); |
|
887 | + } |
|
888 | + |
|
889 | + public function testDelete(): void { |
|
890 | + $instance = $this->getInstance(['removeShareFromTable', 'createShareActivity']); |
|
891 | + $this->share->expects($this->once())->method('getId')->willReturn(42); |
|
892 | + $instance->expects($this->once())->method('removeShareFromTable')->with(42); |
|
893 | + $instance->expects($this->once())->method('createShareActivity')->with($this->share, 'unshare'); |
|
894 | + $instance->delete($this->share); |
|
895 | + } |
|
896 | + |
|
897 | + public function testGetShareById(): void { |
|
898 | + $instance = $this->getInstance(['createShareObject']); |
|
899 | + |
|
900 | + $itemSource = 11; |
|
901 | + $itemType = 'file'; |
|
902 | + $shareWith = '[email protected]'; |
|
903 | + $sharedBy = 'user1'; |
|
904 | + $uidOwner = 'user2'; |
|
905 | + $permissions = 1; |
|
906 | + $token = 'token'; |
|
907 | + |
|
908 | + $this->createDummyShare($itemType, $itemSource, $shareWith, 'user1wrong', 'user2wrong', $permissions, $token); |
|
909 | + $id2 = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
910 | + |
|
911 | + $instance->expects($this->once())->method('createShareObject') |
|
912 | + ->willReturnCallback( |
|
913 | + function ($data) use ($uidOwner, $sharedBy, $id2) { |
|
914 | + $this->assertSame($uidOwner, $data['uid_owner']); |
|
915 | + $this->assertSame($sharedBy, $data['uid_initiator']); |
|
916 | + $this->assertSame($id2, (int)$data['id']); |
|
917 | + return $this->share; |
|
918 | + } |
|
919 | + ); |
|
920 | + |
|
921 | + $result = $instance->getShareById($id2); |
|
922 | + |
|
923 | + $this->assertInstanceOf('OCP\Share\IShare', $result); |
|
924 | + } |
|
925 | + |
|
926 | + |
|
927 | + public function testGetShareByIdFailed(): void { |
|
928 | + $this->expectException(ShareNotFound::class); |
|
929 | + |
|
930 | + $instance = $this->getInstance(['createShareObject']); |
|
931 | + |
|
932 | + $itemSource = 11; |
|
933 | + $itemType = 'file'; |
|
934 | + $shareWith = '[email protected]'; |
|
935 | + $sharedBy = 'user1'; |
|
936 | + $uidOwner = 'user2'; |
|
937 | + $permissions = 1; |
|
938 | + $token = 'token'; |
|
939 | + |
|
940 | + $id = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
941 | + |
|
942 | + $instance->getShareById($id + 1); |
|
943 | + } |
|
944 | + |
|
945 | + public function testGetShareByPath(): void { |
|
946 | + $itemSource = 11; |
|
947 | + $itemType = 'file'; |
|
948 | + $shareWith = '[email protected]'; |
|
949 | + $sharedBy = 'user1'; |
|
950 | + $uidOwner = 'user2'; |
|
951 | + $permissions = 1; |
|
952 | + $token = 'token'; |
|
953 | + |
|
954 | + $node = $this->createMock(Node::class); |
|
955 | + $node->expects($this->once())->method('getId')->willReturn($itemSource); |
|
956 | + |
|
957 | + |
|
958 | + $instance = $this->getInstance(['createShareObject']); |
|
959 | + |
|
960 | + $this->createDummyShare($itemType, 111, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
961 | + $id = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
962 | + |
|
963 | + $instance->expects($this->once())->method('createShareObject') |
|
964 | + ->willReturnCallback( |
|
965 | + function ($data) use ($uidOwner, $sharedBy, $id) { |
|
966 | + $this->assertSame($uidOwner, $data['uid_owner']); |
|
967 | + $this->assertSame($sharedBy, $data['uid_initiator']); |
|
968 | + $this->assertSame($id, (int)$data['id']); |
|
969 | + return $this->share; |
|
970 | + } |
|
971 | + ); |
|
972 | + |
|
973 | + $result = $instance->getSharesByPath($node); |
|
974 | + |
|
975 | + $this->assertTrue(is_array($result)); |
|
976 | + $this->assertSame(1, count($result)); |
|
977 | + $this->assertInstanceOf('OCP\Share\IShare', $result[0]); |
|
978 | + } |
|
979 | + |
|
980 | + public function testGetShareByToken(): void { |
|
981 | + $itemSource = 11; |
|
982 | + $itemType = 'file'; |
|
983 | + $shareWith = '[email protected]'; |
|
984 | + $sharedBy = 'user1'; |
|
985 | + $uidOwner = 'user2'; |
|
986 | + $permissions = 1; |
|
987 | + $token = 'token'; |
|
988 | 988 | |
989 | - $instance = $this->getInstance(['createShareObject']); |
|
989 | + $instance = $this->getInstance(['createShareObject']); |
|
990 | 990 | |
991 | - $idMail = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
992 | - $idPublic = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token, '', IShare::TYPE_LINK); |
|
991 | + $idMail = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
992 | + $idPublic = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token, '', IShare::TYPE_LINK); |
|
993 | 993 | |
994 | - $this->assertTrue($idMail !== $idPublic); |
|
994 | + $this->assertTrue($idMail !== $idPublic); |
|
995 | 995 | |
996 | - $instance->expects($this->once())->method('createShareObject') |
|
997 | - ->willReturnCallback( |
|
998 | - function ($data) use ($idMail) { |
|
999 | - $this->assertSame($idMail, (int)$data['id']); |
|
1000 | - return $this->share; |
|
1001 | - } |
|
1002 | - ); |
|
996 | + $instance->expects($this->once())->method('createShareObject') |
|
997 | + ->willReturnCallback( |
|
998 | + function ($data) use ($idMail) { |
|
999 | + $this->assertSame($idMail, (int)$data['id']); |
|
1000 | + return $this->share; |
|
1001 | + } |
|
1002 | + ); |
|
1003 | 1003 | |
1004 | - $result = $instance->getShareByToken('token'); |
|
1004 | + $result = $instance->getShareByToken('token'); |
|
1005 | 1005 | |
1006 | - $this->assertInstanceOf('OCP\Share\IShare', $result); |
|
1007 | - } |
|
1006 | + $this->assertInstanceOf('OCP\Share\IShare', $result); |
|
1007 | + } |
|
1008 | 1008 | |
1009 | 1009 | |
1010 | - public function testGetShareByTokenFailed(): void { |
|
1011 | - $this->expectException(ShareNotFound::class); |
|
1010 | + public function testGetShareByTokenFailed(): void { |
|
1011 | + $this->expectException(ShareNotFound::class); |
|
1012 | 1012 | |
1013 | 1013 | |
1014 | - $itemSource = 11; |
|
1015 | - $itemType = 'file'; |
|
1016 | - $shareWith = '[email protected]'; |
|
1017 | - $sharedBy = 'user1'; |
|
1018 | - $uidOwner = 'user2'; |
|
1019 | - $permissions = 1; |
|
1020 | - $token = 'token'; |
|
1014 | + $itemSource = 11; |
|
1015 | + $itemType = 'file'; |
|
1016 | + $shareWith = '[email protected]'; |
|
1017 | + $sharedBy = 'user1'; |
|
1018 | + $uidOwner = 'user2'; |
|
1019 | + $permissions = 1; |
|
1020 | + $token = 'token'; |
|
1021 | 1021 | |
1022 | - $instance = $this->getInstance(['createShareObject']); |
|
1022 | + $instance = $this->getInstance(['createShareObject']); |
|
1023 | 1023 | |
1024 | - $idMail = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
1025 | - $idPublic = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, 'token2', '', IShare::TYPE_LINK); |
|
1024 | + $idMail = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
1025 | + $idPublic = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, 'token2', '', IShare::TYPE_LINK); |
|
1026 | 1026 | |
1027 | - $this->assertTrue($idMail !== $idPublic); |
|
1027 | + $this->assertTrue($idMail !== $idPublic); |
|
1028 | 1028 | |
1029 | - $this->assertInstanceOf('OCP\Share\IShare', |
|
1030 | - $instance->getShareByToken('token2') |
|
1031 | - ); |
|
1032 | - } |
|
1029 | + $this->assertInstanceOf('OCP\Share\IShare', |
|
1030 | + $instance->getShareByToken('token2') |
|
1031 | + ); |
|
1032 | + } |
|
1033 | 1033 | |
1034 | - public function testRemoveShareFromTable(): void { |
|
1035 | - $itemSource = 11; |
|
1036 | - $itemType = 'file'; |
|
1037 | - $shareWith = '[email protected]'; |
|
1038 | - $sharedBy = 'user1'; |
|
1039 | - $uidOwner = 'user2'; |
|
1040 | - $permissions = 1; |
|
1041 | - $token = 'token'; |
|
1034 | + public function testRemoveShareFromTable(): void { |
|
1035 | + $itemSource = 11; |
|
1036 | + $itemType = 'file'; |
|
1037 | + $shareWith = '[email protected]'; |
|
1038 | + $sharedBy = 'user1'; |
|
1039 | + $uidOwner = 'user2'; |
|
1040 | + $permissions = 1; |
|
1041 | + $token = 'token'; |
|
1042 | 1042 | |
1043 | - $instance = $this->getInstance(); |
|
1043 | + $instance = $this->getInstance(); |
|
1044 | 1044 | |
1045 | - $id = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
1045 | + $id = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
1046 | 1046 | |
1047 | - $query = $this->connection->getQueryBuilder(); |
|
1048 | - $query->select('*')->from('share') |
|
1049 | - ->where($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
1047 | + $query = $this->connection->getQueryBuilder(); |
|
1048 | + $query->select('*')->from('share') |
|
1049 | + ->where($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
1050 | 1050 | |
1051 | - $result = $query->execute(); |
|
1052 | - $before = $result->fetchAll(); |
|
1053 | - $result->closeCursor(); |
|
1051 | + $result = $query->execute(); |
|
1052 | + $before = $result->fetchAll(); |
|
1053 | + $result->closeCursor(); |
|
1054 | 1054 | |
1055 | - $this->assertTrue(is_array($before)); |
|
1056 | - $this->assertSame(1, count($before)); |
|
1055 | + $this->assertTrue(is_array($before)); |
|
1056 | + $this->assertSame(1, count($before)); |
|
1057 | 1057 | |
1058 | - $this->invokePrivate($instance, 'removeShareFromTable', [$id]); |
|
1058 | + $this->invokePrivate($instance, 'removeShareFromTable', [$id]); |
|
1059 | 1059 | |
1060 | - $query = $this->connection->getQueryBuilder(); |
|
1061 | - $query->select('*')->from('share') |
|
1062 | - ->where($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
1060 | + $query = $this->connection->getQueryBuilder(); |
|
1061 | + $query->select('*')->from('share') |
|
1062 | + ->where($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
1063 | 1063 | |
1064 | - $result = $query->execute(); |
|
1065 | - $after = $result->fetchAll(); |
|
1066 | - $result->closeCursor(); |
|
1064 | + $result = $query->execute(); |
|
1065 | + $after = $result->fetchAll(); |
|
1066 | + $result->closeCursor(); |
|
1067 | 1067 | |
1068 | - $this->assertTrue(is_array($after)); |
|
1069 | - $this->assertEmpty($after); |
|
1070 | - } |
|
1068 | + $this->assertTrue(is_array($after)); |
|
1069 | + $this->assertEmpty($after); |
|
1070 | + } |
|
1071 | 1071 | |
1072 | - public function testUserDeleted(): void { |
|
1073 | - $itemSource = 11; |
|
1074 | - $itemType = 'file'; |
|
1075 | - $shareWith = '[email protected]'; |
|
1076 | - $sharedBy = 'user1'; |
|
1077 | - $uidOwner = 'user2'; |
|
1078 | - $permissions = 1; |
|
1079 | - $token = 'token'; |
|
1072 | + public function testUserDeleted(): void { |
|
1073 | + $itemSource = 11; |
|
1074 | + $itemType = 'file'; |
|
1075 | + $shareWith = '[email protected]'; |
|
1076 | + $sharedBy = 'user1'; |
|
1077 | + $uidOwner = 'user2'; |
|
1078 | + $permissions = 1; |
|
1079 | + $token = 'token'; |
|
1080 | 1080 | |
1081 | - $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
1082 | - $id = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, 'user2Wrong', $permissions, $token); |
|
1081 | + $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
1082 | + $id = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, 'user2Wrong', $permissions, $token); |
|
1083 | 1083 | |
1084 | - $query = $this->connection->getQueryBuilder(); |
|
1085 | - $query->select('*')->from('share'); |
|
1084 | + $query = $this->connection->getQueryBuilder(); |
|
1085 | + $query->select('*')->from('share'); |
|
1086 | 1086 | |
1087 | - $result = $query->execute(); |
|
1088 | - $before = $result->fetchAll(); |
|
1089 | - $result->closeCursor(); |
|
1087 | + $result = $query->execute(); |
|
1088 | + $before = $result->fetchAll(); |
|
1089 | + $result->closeCursor(); |
|
1090 | 1090 | |
1091 | - $this->assertTrue(is_array($before)); |
|
1092 | - $this->assertSame(2, count($before)); |
|
1091 | + $this->assertTrue(is_array($before)); |
|
1092 | + $this->assertSame(2, count($before)); |
|
1093 | 1093 | |
1094 | 1094 | |
1095 | - $instance = $this->getInstance(); |
|
1095 | + $instance = $this->getInstance(); |
|
1096 | 1096 | |
1097 | - $instance->userDeleted($uidOwner, IShare::TYPE_EMAIL); |
|
1097 | + $instance->userDeleted($uidOwner, IShare::TYPE_EMAIL); |
|
1098 | 1098 | |
1099 | - $query = $this->connection->getQueryBuilder(); |
|
1100 | - $query->select('*')->from('share'); |
|
1099 | + $query = $this->connection->getQueryBuilder(); |
|
1100 | + $query->select('*')->from('share'); |
|
1101 | 1101 | |
1102 | - $result = $query->execute(); |
|
1103 | - $after = $result->fetchAll(); |
|
1104 | - $result->closeCursor(); |
|
1102 | + $result = $query->execute(); |
|
1103 | + $after = $result->fetchAll(); |
|
1104 | + $result->closeCursor(); |
|
1105 | 1105 | |
1106 | - $this->assertTrue(is_array($after)); |
|
1107 | - $this->assertSame(1, count($after)); |
|
1108 | - $this->assertSame($id, (int)$after[0]['id']); |
|
1109 | - } |
|
1106 | + $this->assertTrue(is_array($after)); |
|
1107 | + $this->assertSame(1, count($after)); |
|
1108 | + $this->assertSame($id, (int)$after[0]['id']); |
|
1109 | + } |
|
1110 | 1110 | |
1111 | - public function testGetRawShare(): void { |
|
1112 | - $itemSource = 11; |
|
1113 | - $itemType = 'file'; |
|
1114 | - $shareWith = '[email protected]'; |
|
1115 | - $sharedBy = 'user1'; |
|
1116 | - $uidOwner = 'user2'; |
|
1117 | - $permissions = 1; |
|
1118 | - $token = 'token'; |
|
1111 | + public function testGetRawShare(): void { |
|
1112 | + $itemSource = 11; |
|
1113 | + $itemType = 'file'; |
|
1114 | + $shareWith = '[email protected]'; |
|
1115 | + $sharedBy = 'user1'; |
|
1116 | + $uidOwner = 'user2'; |
|
1117 | + $permissions = 1; |
|
1118 | + $token = 'token'; |
|
1119 | 1119 | |
1120 | - $instance = $this->getInstance(); |
|
1120 | + $instance = $this->getInstance(); |
|
1121 | 1121 | |
1122 | - $id = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
1122 | + $id = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
1123 | 1123 | |
1124 | - $result = $this->invokePrivate($instance, 'getRawShare', [$id]); |
|
1125 | - |
|
1126 | - $this->assertTrue(is_array($result)); |
|
1127 | - $this->assertSame($itemSource, (int)$result['item_source']); |
|
1128 | - $this->assertSame($itemType, $result['item_type']); |
|
1129 | - $this->assertSame($shareWith, $result['share_with']); |
|
1130 | - $this->assertSame($sharedBy, $result['uid_initiator']); |
|
1131 | - $this->assertSame($uidOwner, $result['uid_owner']); |
|
1132 | - $this->assertSame($permissions, (int)$result['permissions']); |
|
1133 | - $this->assertSame($token, $result['token']); |
|
1134 | - } |
|
1124 | + $result = $this->invokePrivate($instance, 'getRawShare', [$id]); |
|
1125 | + |
|
1126 | + $this->assertTrue(is_array($result)); |
|
1127 | + $this->assertSame($itemSource, (int)$result['item_source']); |
|
1128 | + $this->assertSame($itemType, $result['item_type']); |
|
1129 | + $this->assertSame($shareWith, $result['share_with']); |
|
1130 | + $this->assertSame($sharedBy, $result['uid_initiator']); |
|
1131 | + $this->assertSame($uidOwner, $result['uid_owner']); |
|
1132 | + $this->assertSame($permissions, (int)$result['permissions']); |
|
1133 | + $this->assertSame($token, $result['token']); |
|
1134 | + } |
|
1135 | 1135 | |
1136 | 1136 | |
1137 | - public function testGetRawShareFailed(): void { |
|
1138 | - $this->expectException(ShareNotFound::class); |
|
1137 | + public function testGetRawShareFailed(): void { |
|
1138 | + $this->expectException(ShareNotFound::class); |
|
1139 | 1139 | |
1140 | - $itemSource = 11; |
|
1141 | - $itemType = 'file'; |
|
1142 | - $shareWith = '[email protected]'; |
|
1143 | - $sharedBy = 'user1'; |
|
1144 | - $uidOwner = 'user2'; |
|
1145 | - $permissions = 1; |
|
1146 | - $token = 'token'; |
|
1147 | - |
|
1148 | - $instance = $this->getInstance(); |
|
1140 | + $itemSource = 11; |
|
1141 | + $itemType = 'file'; |
|
1142 | + $shareWith = '[email protected]'; |
|
1143 | + $sharedBy = 'user1'; |
|
1144 | + $uidOwner = 'user2'; |
|
1145 | + $permissions = 1; |
|
1146 | + $token = 'token'; |
|
1147 | + |
|
1148 | + $instance = $this->getInstance(); |
|
1149 | 1149 | |
1150 | - $id = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
1151 | - |
|
1152 | - $this->invokePrivate($instance, 'getRawShare', [$id + 1]); |
|
1153 | - } |
|
1150 | + $id = $this->createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token); |
|
1151 | + |
|
1152 | + $this->invokePrivate($instance, 'getRawShare', [$id + 1]); |
|
1153 | + } |
|
1154 | 1154 | |
1155 | - private function createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $note = '', $shareType = IShare::TYPE_EMAIL) { |
|
1156 | - $qb = $this->connection->getQueryBuilder(); |
|
1157 | - $qb->insert('share') |
|
1158 | - ->setValue('share_type', $qb->createNamedParameter($shareType)) |
|
1159 | - ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
1160 | - ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
1161 | - ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
1162 | - ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
1163 | - ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
1164 | - ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
1165 | - ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
1166 | - ->setValue('token', $qb->createNamedParameter($token)) |
|
1167 | - ->setValue('note', $qb->createNamedParameter($note)) |
|
1168 | - ->setValue('stime', $qb->createNamedParameter(time())); |
|
1169 | - |
|
1170 | - /* |
|
1155 | + private function createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $note = '', $shareType = IShare::TYPE_EMAIL) { |
|
1156 | + $qb = $this->connection->getQueryBuilder(); |
|
1157 | + $qb->insert('share') |
|
1158 | + ->setValue('share_type', $qb->createNamedParameter($shareType)) |
|
1159 | + ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
1160 | + ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
1161 | + ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
1162 | + ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
1163 | + ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
1164 | + ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
1165 | + ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
1166 | + ->setValue('token', $qb->createNamedParameter($token)) |
|
1167 | + ->setValue('note', $qb->createNamedParameter($note)) |
|
1168 | + ->setValue('stime', $qb->createNamedParameter(time())); |
|
1169 | + |
|
1170 | + /* |
|
1171 | 1171 | * Added to fix https://github.com/owncloud/core/issues/22215 |
1172 | 1172 | * Can be removed once we get rid of ajax/share.php |
1173 | 1173 | */ |
1174 | - $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
1175 | - |
|
1176 | - $qb->execute(); |
|
1177 | - $id = $qb->getLastInsertId(); |
|
1178 | - |
|
1179 | - return (int)$id; |
|
1180 | - } |
|
1181 | - |
|
1182 | - public function testGetSharesInFolder(): void { |
|
1183 | - $userManager = Server::get(IUserManager::class); |
|
1184 | - $rootFolder = Server::get(IRootFolder::class); |
|
1185 | - |
|
1186 | - $this->shareManager->expects($this->any()) |
|
1187 | - ->method('newShare') |
|
1188 | - ->willReturn(new Share($rootFolder, $userManager)); |
|
1189 | - |
|
1190 | - $provider = $this->getInstance(['sendMailNotification', 'createShareActivity']); |
|
1191 | - $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); |
|
1192 | - |
|
1193 | - $u1 = $userManager->createUser('testFed', md5((string)time())); |
|
1194 | - $u2 = $userManager->createUser('testFed2', md5((string)time())); |
|
1195 | - |
|
1196 | - $folder1 = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo'); |
|
1197 | - $file1 = $folder1->newFile('bar1'); |
|
1198 | - $file2 = $folder1->newFile('bar2'); |
|
1199 | - |
|
1200 | - $share1 = $this->shareManager->newShare(); |
|
1201 | - $share1->setSharedWith('[email protected]') |
|
1202 | - ->setSharedBy($u1->getUID()) |
|
1203 | - ->setShareOwner($u1->getUID()) |
|
1204 | - ->setPermissions(Constants::PERMISSION_READ) |
|
1205 | - ->setNode($file1); |
|
1206 | - $provider->create($share1); |
|
1207 | - |
|
1208 | - $share2 = $this->shareManager->newShare(); |
|
1209 | - $share2->setSharedWith('[email protected]') |
|
1210 | - ->setSharedBy($u2->getUID()) |
|
1211 | - ->setShareOwner($u1->getUID()) |
|
1212 | - ->setPermissions(Constants::PERMISSION_READ) |
|
1213 | - ->setNode($file2); |
|
1214 | - $provider->create($share2); |
|
1215 | - |
|
1216 | - $result = $provider->getSharesInFolder($u1->getUID(), $folder1, false); |
|
1217 | - $this->assertCount(1, $result); |
|
1218 | - $this->assertCount(1, $result[$file1->getId()]); |
|
1219 | - |
|
1220 | - $result = $provider->getSharesInFolder($u1->getUID(), $folder1, true); |
|
1221 | - $this->assertCount(2, $result); |
|
1222 | - $this->assertCount(1, $result[$file1->getId()]); |
|
1223 | - $this->assertCount(1, $result[$file2->getId()]); |
|
1224 | - |
|
1225 | - $u1->delete(); |
|
1226 | - $u2->delete(); |
|
1227 | - } |
|
1228 | - |
|
1229 | - public function testGetAccessList(): void { |
|
1230 | - $userManager = Server::get(IUserManager::class); |
|
1231 | - $rootFolder = Server::get(IRootFolder::class); |
|
1232 | - |
|
1233 | - $this->shareManager->expects($this->any()) |
|
1234 | - ->method('newShare') |
|
1235 | - ->willReturn(new Share($rootFolder, $userManager)); |
|
1236 | - |
|
1237 | - $provider = $this->getInstance(['sendMailNotification', 'createShareActivity']); |
|
1238 | - $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); |
|
1239 | - |
|
1240 | - $u1 = $userManager->createUser('testFed', md5((string)time())); |
|
1241 | - $u2 = $userManager->createUser('testFed2', md5((string)time())); |
|
1242 | - |
|
1243 | - $folder = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo'); |
|
1244 | - |
|
1245 | - $accessList = $provider->getAccessList([$folder], true); |
|
1246 | - $this->assertArrayHasKey('public', $accessList); |
|
1247 | - $this->assertFalse($accessList['public']); |
|
1248 | - $accessList = $provider->getAccessList([$folder], false); |
|
1249 | - $this->assertArrayHasKey('public', $accessList); |
|
1250 | - $this->assertFalse($accessList['public']); |
|
1251 | - |
|
1252 | - $share1 = $this->shareManager->newShare(); |
|
1253 | - $share1->setSharedWith('[email protected]') |
|
1254 | - ->setSharedBy($u1->getUID()) |
|
1255 | - ->setShareOwner($u1->getUID()) |
|
1256 | - ->setPermissions(Constants::PERMISSION_READ) |
|
1257 | - ->setNode($folder); |
|
1258 | - $share1 = $provider->create($share1); |
|
1259 | - |
|
1260 | - $share2 = $this->shareManager->newShare(); |
|
1261 | - $share2->setSharedWith('[email protected]') |
|
1262 | - ->setSharedBy($u2->getUID()) |
|
1263 | - ->setShareOwner($u1->getUID()) |
|
1264 | - ->setPermissions(Constants::PERMISSION_READ) |
|
1265 | - ->setNode($folder); |
|
1266 | - $share2 = $provider->create($share2); |
|
1267 | - |
|
1268 | - $accessList = $provider->getAccessList([$folder], true); |
|
1269 | - $this->assertArrayHasKey('public', $accessList); |
|
1270 | - $this->assertTrue($accessList['public']); |
|
1271 | - $accessList = $provider->getAccessList([$folder], false); |
|
1272 | - $this->assertArrayHasKey('public', $accessList); |
|
1273 | - $this->assertTrue($accessList['public']); |
|
1274 | - |
|
1275 | - $provider->delete($share2); |
|
1276 | - |
|
1277 | - $accessList = $provider->getAccessList([$folder], true); |
|
1278 | - $this->assertArrayHasKey('public', $accessList); |
|
1279 | - $this->assertTrue($accessList['public']); |
|
1280 | - $accessList = $provider->getAccessList([$folder], false); |
|
1281 | - $this->assertArrayHasKey('public', $accessList); |
|
1282 | - $this->assertTrue($accessList['public']); |
|
1283 | - |
|
1284 | - $provider->delete($share1); |
|
1285 | - |
|
1286 | - $accessList = $provider->getAccessList([$folder], true); |
|
1287 | - $this->assertArrayHasKey('public', $accessList); |
|
1288 | - $this->assertFalse($accessList['public']); |
|
1289 | - $accessList = $provider->getAccessList([$folder], false); |
|
1290 | - $this->assertArrayHasKey('public', $accessList); |
|
1291 | - $this->assertFalse($accessList['public']); |
|
1292 | - |
|
1293 | - $u1->delete(); |
|
1294 | - $u2->delete(); |
|
1295 | - } |
|
1296 | - |
|
1297 | - public function testSendMailNotificationWithSameUserAndUserEmail(): void { |
|
1298 | - $provider = $this->getInstance(); |
|
1299 | - $user = $this->createMock(IUser::class); |
|
1300 | - $this->settingsManager->expects($this->any())->method('replyToInitiator')->willReturn(true); |
|
1301 | - $this->userManager |
|
1302 | - ->expects($this->once()) |
|
1303 | - ->method('get') |
|
1304 | - ->with('OwnerUser') |
|
1305 | - ->willReturn($user); |
|
1306 | - $user |
|
1307 | - ->expects($this->once()) |
|
1308 | - ->method('getDisplayName') |
|
1309 | - ->willReturn('Mrs. Owner User'); |
|
1310 | - $message = $this->createMock(Message::class); |
|
1311 | - $this->mailer |
|
1312 | - ->expects($this->once()) |
|
1313 | - ->method('createMessage') |
|
1314 | - ->willReturn($message); |
|
1315 | - $template = $this->createMock(IEMailTemplate::class); |
|
1316 | - $this->mailer |
|
1317 | - ->expects($this->once()) |
|
1318 | - ->method('createEMailTemplate') |
|
1319 | - ->willReturn($template); |
|
1320 | - $template |
|
1321 | - ->expects($this->once()) |
|
1322 | - ->method('addHeader'); |
|
1323 | - $template |
|
1324 | - ->expects($this->once()) |
|
1325 | - ->method('addHeading') |
|
1326 | - ->with('Mrs. Owner User shared file.txt with you'); |
|
1327 | - $template |
|
1328 | - ->expects($this->once()) |
|
1329 | - ->method('addBodyButton') |
|
1330 | - ->with( |
|
1331 | - 'Open file.txt', |
|
1332 | - 'https://example.com/file.txt' |
|
1333 | - ); |
|
1334 | - $message |
|
1335 | - ->expects($this->once()) |
|
1336 | - ->method('setTo') |
|
1337 | - ->with(['[email protected]']); |
|
1338 | - $this->defaults |
|
1339 | - ->expects($this->once()) |
|
1340 | - ->method('getName') |
|
1341 | - ->willReturn('UnitTestCloud'); |
|
1342 | - $message |
|
1343 | - ->expects($this->once()) |
|
1344 | - ->method('setFrom') |
|
1345 | - ->with([ |
|
1346 | - Util::getDefaultEmailAddress('UnitTestCloud') => 'Mrs. Owner User via UnitTestCloud' |
|
1347 | - ]); |
|
1348 | - $user |
|
1349 | - ->expects($this->once()) |
|
1350 | - ->method('getEMailAddress') |
|
1351 | - ->willReturn('[email protected]'); |
|
1352 | - $message |
|
1353 | - ->expects($this->once()) |
|
1354 | - ->method('setReplyTo') |
|
1355 | - ->with(['[email protected]' => 'Mrs. Owner User']); |
|
1356 | - $this->defaults |
|
1357 | - ->expects($this->exactly(2)) |
|
1358 | - ->method('getSlogan') |
|
1359 | - ->willReturn('Testing like 1990'); |
|
1360 | - $template |
|
1361 | - ->expects($this->once()) |
|
1362 | - ->method('addFooter') |
|
1363 | - ->with('UnitTestCloud - Testing like 1990'); |
|
1364 | - $template |
|
1365 | - ->expects($this->once()) |
|
1366 | - ->method('setSubject') |
|
1367 | - ->with('Mrs. Owner User shared file.txt with you'); |
|
1368 | - $message |
|
1369 | - ->expects($this->once()) |
|
1370 | - ->method('useTemplate') |
|
1371 | - ->with($template); |
|
1372 | - |
|
1373 | - $this->mailer->expects($this->once()) |
|
1374 | - ->method('validateMailAddress') |
|
1375 | - ->willReturn(true); |
|
1376 | - $this->mailer |
|
1377 | - ->expects($this->once()) |
|
1378 | - ->method('send') |
|
1379 | - ->with($message); |
|
1380 | - |
|
1381 | - $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute') |
|
1382 | - ->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) |
|
1383 | - ->willReturn('https://example.com/file.txt'); |
|
1384 | - |
|
1385 | - $node = $this->createMock(File::class); |
|
1386 | - $node->expects($this->any())->method('getName')->willReturn('file.txt'); |
|
1387 | - |
|
1388 | - $share = $this->createMock(IShare::class); |
|
1389 | - $share->expects($this->any())->method('getSharedBy')->willReturn('OwnerUser'); |
|
1390 | - $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
1391 | - $share->expects($this->any())->method('getNode')->willReturn($node); |
|
1392 | - $share->expects($this->any())->method('getId')->willReturn(42); |
|
1393 | - $share->expects($this->any())->method('getNote')->willReturn(''); |
|
1394 | - $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
1395 | - |
|
1396 | - self::invokePrivate( |
|
1397 | - $provider, |
|
1398 | - 'sendMailNotification', |
|
1399 | - [$share] |
|
1400 | - ); |
|
1401 | - } |
|
1402 | - |
|
1403 | - public function testSendMailNotificationWithSameUserAndUserEmailAndNote(): void { |
|
1404 | - $provider = $this->getInstance(); |
|
1405 | - $user = $this->createMock(IUser::class); |
|
1406 | - $this->settingsManager->expects($this->any())->method('replyToInitiator')->willReturn(true); |
|
1407 | - $this->userManager |
|
1408 | - ->expects($this->once()) |
|
1409 | - ->method('get') |
|
1410 | - ->with('OwnerUser') |
|
1411 | - ->willReturn($user); |
|
1412 | - $user |
|
1413 | - ->expects($this->once()) |
|
1414 | - ->method('getDisplayName') |
|
1415 | - ->willReturn('Mrs. Owner User'); |
|
1416 | - $message = $this->createMock(Message::class); |
|
1417 | - $this->mailer |
|
1418 | - ->expects($this->once()) |
|
1419 | - ->method('createMessage') |
|
1420 | - ->willReturn($message); |
|
1421 | - $template = $this->createMock(IEMailTemplate::class); |
|
1422 | - $this->mailer |
|
1423 | - ->expects($this->once()) |
|
1424 | - ->method('createEMailTemplate') |
|
1425 | - ->willReturn($template); |
|
1426 | - $template |
|
1427 | - ->expects($this->once()) |
|
1428 | - ->method('addHeader'); |
|
1429 | - $template |
|
1430 | - ->expects($this->once()) |
|
1431 | - ->method('addHeading') |
|
1432 | - ->with('Mrs. Owner User shared file.txt with you'); |
|
1433 | - |
|
1434 | - $this->urlGenerator->expects($this->once())->method('imagePath') |
|
1435 | - ->with('core', 'caldav/description.png') |
|
1436 | - ->willReturn('core/img/caldav/description.png'); |
|
1437 | - $this->urlGenerator->expects($this->once())->method('getAbsoluteURL') |
|
1438 | - ->with('core/img/caldav/description.png') |
|
1439 | - ->willReturn('https://example.com/core/img/caldav/description.png'); |
|
1440 | - $template |
|
1441 | - ->expects($this->once()) |
|
1442 | - ->method('addBodyListItem') |
|
1443 | - ->with( |
|
1444 | - 'This is a note to the recipient', |
|
1445 | - 'Note:', |
|
1446 | - 'https://example.com/core/img/caldav/description.png', |
|
1447 | - 'This is a note to the recipient' |
|
1448 | - ); |
|
1449 | - $template |
|
1450 | - ->expects($this->once()) |
|
1451 | - ->method('addBodyButton') |
|
1452 | - ->with( |
|
1453 | - 'Open file.txt', |
|
1454 | - 'https://example.com/file.txt' |
|
1455 | - ); |
|
1456 | - $message |
|
1457 | - ->expects($this->once()) |
|
1458 | - ->method('setTo') |
|
1459 | - ->with(['[email protected]']); |
|
1460 | - $this->defaults |
|
1461 | - ->expects($this->once()) |
|
1462 | - ->method('getName') |
|
1463 | - ->willReturn('UnitTestCloud'); |
|
1464 | - $message |
|
1465 | - ->expects($this->once()) |
|
1466 | - ->method('setFrom') |
|
1467 | - ->with([ |
|
1468 | - Util::getDefaultEmailAddress('UnitTestCloud') => 'Mrs. Owner User via UnitTestCloud' |
|
1469 | - ]); |
|
1470 | - $user |
|
1471 | - ->expects($this->once()) |
|
1472 | - ->method('getEMailAddress') |
|
1473 | - ->willReturn('[email protected]'); |
|
1474 | - $message |
|
1475 | - ->expects($this->once()) |
|
1476 | - ->method('setReplyTo') |
|
1477 | - ->with(['[email protected]' => 'Mrs. Owner User']); |
|
1478 | - $this->defaults |
|
1479 | - ->expects($this->exactly(2)) |
|
1480 | - ->method('getSlogan') |
|
1481 | - ->willReturn('Testing like 1990'); |
|
1482 | - $template |
|
1483 | - ->expects($this->once()) |
|
1484 | - ->method('addFooter') |
|
1485 | - ->with('UnitTestCloud - Testing like 1990'); |
|
1486 | - $template |
|
1487 | - ->expects($this->once()) |
|
1488 | - ->method('setSubject') |
|
1489 | - ->with('Mrs. Owner User shared file.txt with you'); |
|
1490 | - $message |
|
1491 | - ->expects($this->once()) |
|
1492 | - ->method('useTemplate') |
|
1493 | - ->with($template); |
|
1494 | - |
|
1495 | - $this->mailer->expects($this->once()) |
|
1496 | - ->method('validateMailAddress') |
|
1497 | - ->willReturn(true); |
|
1498 | - $this->mailer |
|
1499 | - ->expects($this->once()) |
|
1500 | - ->method('send') |
|
1501 | - ->with($message); |
|
1502 | - |
|
1503 | - $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute') |
|
1504 | - ->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) |
|
1505 | - ->willReturn('https://example.com/file.txt'); |
|
1506 | - |
|
1507 | - $node = $this->createMock(File::class); |
|
1508 | - $node->expects($this->any())->method('getName')->willReturn('file.txt'); |
|
1509 | - |
|
1510 | - $share = $this->createMock(IShare::class); |
|
1511 | - $share->expects($this->any())->method('getSharedBy')->willReturn('OwnerUser'); |
|
1512 | - $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
1513 | - $share->expects($this->any())->method('getNode')->willReturn($node); |
|
1514 | - $share->expects($this->any())->method('getId')->willReturn(42); |
|
1515 | - $share->expects($this->any())->method('getNote')->willReturn('This is a note to the recipient'); |
|
1516 | - $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
1517 | - |
|
1518 | - self::invokePrivate( |
|
1519 | - $provider, |
|
1520 | - 'sendMailNotification', |
|
1521 | - [$share] |
|
1522 | - ); |
|
1523 | - } |
|
1524 | - |
|
1525 | - public function testSendMailNotificationWithSameUserAndUserEmailAndExpiration(): void { |
|
1526 | - $provider = $this->getInstance(); |
|
1527 | - $user = $this->createMock(IUser::class); |
|
1528 | - $this->settingsManager->expects($this->any())->method('replyToInitiator')->willReturn(true); |
|
1529 | - $this->userManager |
|
1530 | - ->expects($this->once()) |
|
1531 | - ->method('get') |
|
1532 | - ->with('OwnerUser') |
|
1533 | - ->willReturn($user); |
|
1534 | - $user |
|
1535 | - ->expects($this->once()) |
|
1536 | - ->method('getDisplayName') |
|
1537 | - ->willReturn('Mrs. Owner User'); |
|
1538 | - $message = $this->createMock(Message::class); |
|
1539 | - $this->mailer |
|
1540 | - ->expects($this->once()) |
|
1541 | - ->method('createMessage') |
|
1542 | - ->willReturn($message); |
|
1543 | - $template = $this->createMock(IEMailTemplate::class); |
|
1544 | - $this->mailer |
|
1545 | - ->expects($this->once()) |
|
1546 | - ->method('createEMailTemplate') |
|
1547 | - ->willReturn($template); |
|
1548 | - $template |
|
1549 | - ->expects($this->once()) |
|
1550 | - ->method('addHeader'); |
|
1551 | - $template |
|
1552 | - ->expects($this->once()) |
|
1553 | - ->method('addHeading') |
|
1554 | - ->with('Mrs. Owner User shared file.txt with you'); |
|
1555 | - |
|
1556 | - $expiration = new DateTime('2001-01-01'); |
|
1557 | - $this->l->expects($this->once()) |
|
1558 | - ->method('l') |
|
1559 | - ->with('date', $expiration, ['width' => 'medium']) |
|
1560 | - ->willReturn('2001-01-01'); |
|
1561 | - $this->urlGenerator->expects($this->once())->method('imagePath') |
|
1562 | - ->with('core', 'caldav/time.png') |
|
1563 | - ->willReturn('core/img/caldav/time.png'); |
|
1564 | - $this->urlGenerator->expects($this->once())->method('getAbsoluteURL') |
|
1565 | - ->with('core/img/caldav/time.png') |
|
1566 | - ->willReturn('https://example.com/core/img/caldav/time.png'); |
|
1567 | - $template |
|
1568 | - ->expects($this->once()) |
|
1569 | - ->method('addBodyListItem') |
|
1570 | - ->with( |
|
1571 | - 'This share is valid until 2001-01-01 at midnight', |
|
1572 | - 'Expiration:', |
|
1573 | - 'https://example.com/core/img/caldav/time.png', |
|
1574 | - ); |
|
1575 | - |
|
1576 | - $template |
|
1577 | - ->expects($this->once()) |
|
1578 | - ->method('addBodyButton') |
|
1579 | - ->with( |
|
1580 | - 'Open file.txt', |
|
1581 | - 'https://example.com/file.txt' |
|
1582 | - ); |
|
1583 | - $message |
|
1584 | - ->expects($this->once()) |
|
1585 | - ->method('setTo') |
|
1586 | - ->with(['[email protected]']); |
|
1587 | - $this->defaults |
|
1588 | - ->expects($this->once()) |
|
1589 | - ->method('getName') |
|
1590 | - ->willReturn('UnitTestCloud'); |
|
1591 | - $message |
|
1592 | - ->expects($this->once()) |
|
1593 | - ->method('setFrom') |
|
1594 | - ->with([ |
|
1595 | - Util::getDefaultEmailAddress('UnitTestCloud') => 'Mrs. Owner User via UnitTestCloud' |
|
1596 | - ]); |
|
1597 | - $user |
|
1598 | - ->expects($this->once()) |
|
1599 | - ->method('getEMailAddress') |
|
1600 | - ->willReturn('[email protected]'); |
|
1601 | - $message |
|
1602 | - ->expects($this->once()) |
|
1603 | - ->method('setReplyTo') |
|
1604 | - ->with(['[email protected]' => 'Mrs. Owner User']); |
|
1605 | - $this->defaults |
|
1606 | - ->expects($this->exactly(2)) |
|
1607 | - ->method('getSlogan') |
|
1608 | - ->willReturn('Testing like 1990'); |
|
1609 | - $template |
|
1610 | - ->expects($this->once()) |
|
1611 | - ->method('addFooter') |
|
1612 | - ->with('UnitTestCloud - Testing like 1990'); |
|
1613 | - $template |
|
1614 | - ->expects($this->once()) |
|
1615 | - ->method('setSubject') |
|
1616 | - ->with('Mrs. Owner User shared file.txt with you'); |
|
1617 | - $message |
|
1618 | - ->expects($this->once()) |
|
1619 | - ->method('useTemplate') |
|
1620 | - ->with($template); |
|
1621 | - |
|
1622 | - $this->mailer->expects($this->once()) |
|
1623 | - ->method('validateMailAddress') |
|
1624 | - ->willReturn(true); |
|
1625 | - $this->mailer |
|
1626 | - ->expects($this->once()) |
|
1627 | - ->method('send') |
|
1628 | - ->with($message); |
|
1629 | - |
|
1630 | - $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute') |
|
1631 | - ->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) |
|
1632 | - ->willReturn('https://example.com/file.txt'); |
|
1633 | - |
|
1634 | - $node = $this->createMock(File::class); |
|
1635 | - $node->expects($this->any())->method('getName')->willReturn('file.txt'); |
|
1636 | - |
|
1637 | - $share = $this->createMock(IShare::class); |
|
1638 | - $share->expects($this->any())->method('getSharedBy')->willReturn('OwnerUser'); |
|
1639 | - $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
1640 | - $share->expects($this->any())->method('getNode')->willReturn($node); |
|
1641 | - $share->expects($this->any())->method('getId')->willReturn(42); |
|
1642 | - $share->expects($this->any())->method('getNote')->willReturn(''); |
|
1643 | - $share->expects($this->any())->method('getExpirationDate')->willReturn($expiration); |
|
1644 | - $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
1645 | - |
|
1646 | - self::invokePrivate( |
|
1647 | - $provider, |
|
1648 | - 'sendMailNotification', |
|
1649 | - [$share] |
|
1650 | - ); |
|
1651 | - } |
|
1652 | - |
|
1653 | - public function testSendMailNotificationWithDifferentUserAndNoUserEmail(): void { |
|
1654 | - $provider = $this->getInstance(); |
|
1655 | - $initiatorUser = $this->createMock(IUser::class); |
|
1656 | - $this->settingsManager->expects($this->any())->method('replyToInitiator')->willReturn(true); |
|
1657 | - $this->userManager |
|
1658 | - ->expects($this->once()) |
|
1659 | - ->method('get') |
|
1660 | - ->with('InitiatorUser') |
|
1661 | - ->willReturn($initiatorUser); |
|
1662 | - $initiatorUser |
|
1663 | - ->expects($this->once()) |
|
1664 | - ->method('getDisplayName') |
|
1665 | - ->willReturn('Mr. Initiator User'); |
|
1666 | - $message = $this->createMock(Message::class); |
|
1667 | - $this->mailer |
|
1668 | - ->expects($this->once()) |
|
1669 | - ->method('createMessage') |
|
1670 | - ->willReturn($message); |
|
1671 | - $template = $this->createMock(IEMailTemplate::class); |
|
1672 | - $this->mailer |
|
1673 | - ->expects($this->once()) |
|
1674 | - ->method('createEMailTemplate') |
|
1675 | - ->willReturn($template); |
|
1676 | - $template |
|
1677 | - ->expects($this->once()) |
|
1678 | - ->method('addHeader'); |
|
1679 | - $template |
|
1680 | - ->expects($this->once()) |
|
1681 | - ->method('addHeading') |
|
1682 | - ->with('Mr. Initiator User shared file.txt with you'); |
|
1683 | - $template |
|
1684 | - ->expects($this->once()) |
|
1685 | - ->method('addBodyButton') |
|
1686 | - ->with( |
|
1687 | - 'Open file.txt', |
|
1688 | - 'https://example.com/file.txt' |
|
1689 | - ); |
|
1690 | - $message |
|
1691 | - ->expects($this->once()) |
|
1692 | - ->method('setTo') |
|
1693 | - ->with(['[email protected]']); |
|
1694 | - $this->defaults |
|
1695 | - ->expects($this->once()) |
|
1696 | - ->method('getName') |
|
1697 | - ->willReturn('UnitTestCloud'); |
|
1698 | - $message |
|
1699 | - ->expects($this->once()) |
|
1700 | - ->method('setFrom') |
|
1701 | - ->with([ |
|
1702 | - Util::getDefaultEmailAddress('UnitTestCloud') => 'Mr. Initiator User via UnitTestCloud' |
|
1703 | - ]); |
|
1704 | - $message |
|
1705 | - ->expects($this->never()) |
|
1706 | - ->method('setReplyTo'); |
|
1707 | - $template |
|
1708 | - ->expects($this->once()) |
|
1709 | - ->method('addFooter') |
|
1710 | - ->with(''); |
|
1711 | - $template |
|
1712 | - ->expects($this->once()) |
|
1713 | - ->method('setSubject') |
|
1714 | - ->with('Mr. Initiator User shared file.txt with you'); |
|
1715 | - $message |
|
1716 | - ->expects($this->once()) |
|
1717 | - ->method('useTemplate') |
|
1718 | - ->with($template); |
|
1719 | - |
|
1720 | - $this->mailer->expects($this->once()) |
|
1721 | - ->method('validateMailAddress') |
|
1722 | - ->willReturn(true); |
|
1723 | - $this->mailer |
|
1724 | - ->expects($this->once()) |
|
1725 | - ->method('send') |
|
1726 | - ->with($message); |
|
1727 | - |
|
1728 | - $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute') |
|
1729 | - ->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) |
|
1730 | - ->willReturn('https://example.com/file.txt'); |
|
1731 | - |
|
1732 | - $node = $this->createMock(File::class); |
|
1733 | - $node->expects($this->any())->method('getName')->willReturn('file.txt'); |
|
1734 | - |
|
1735 | - $share = $this->createMock(IShare::class); |
|
1736 | - $share->expects($this->any())->method('getSharedBy')->willReturn('InitiatorUser'); |
|
1737 | - $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
1738 | - $share->expects($this->any())->method('getNode')->willReturn($node); |
|
1739 | - $share->expects($this->any())->method('getId')->willReturn(42); |
|
1740 | - $share->expects($this->any())->method('getNote')->willReturn(''); |
|
1741 | - $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
1742 | - |
|
1743 | - self::invokePrivate( |
|
1744 | - $provider, |
|
1745 | - 'sendMailNotification', |
|
1746 | - [$share] |
|
1747 | - ); |
|
1748 | - } |
|
1749 | - |
|
1750 | - public function testSendMailNotificationWithSameUserAndUserEmailAndReplyToDesactivate(): void { |
|
1751 | - $provider = $this->getInstance(); |
|
1752 | - $user = $this->createMock(IUser::class); |
|
1753 | - $this->settingsManager->expects($this->any())->method('replyToInitiator')->willReturn(false); |
|
1754 | - $this->userManager |
|
1755 | - ->expects($this->once()) |
|
1756 | - ->method('get') |
|
1757 | - ->with('OwnerUser') |
|
1758 | - ->willReturn($user); |
|
1759 | - $user |
|
1760 | - ->expects($this->once()) |
|
1761 | - ->method('getDisplayName') |
|
1762 | - ->willReturn('Mrs. Owner User'); |
|
1763 | - $message = $this->createMock(Message::class); |
|
1764 | - $this->mailer |
|
1765 | - ->expects($this->once()) |
|
1766 | - ->method('createMessage') |
|
1767 | - ->willReturn($message); |
|
1768 | - $template = $this->createMock(IEMailTemplate::class); |
|
1769 | - $this->mailer |
|
1770 | - ->expects($this->once()) |
|
1771 | - ->method('createEMailTemplate') |
|
1772 | - ->willReturn($template); |
|
1773 | - $template |
|
1774 | - ->expects($this->once()) |
|
1775 | - ->method('addHeader'); |
|
1776 | - $template |
|
1777 | - ->expects($this->once()) |
|
1778 | - ->method('addHeading') |
|
1779 | - ->with('Mrs. Owner User shared file.txt with you'); |
|
1780 | - $template |
|
1781 | - ->expects($this->once()) |
|
1782 | - ->method('addBodyButton') |
|
1783 | - ->with( |
|
1784 | - 'Open file.txt', |
|
1785 | - 'https://example.com/file.txt' |
|
1786 | - ); |
|
1787 | - $message |
|
1788 | - ->expects($this->once()) |
|
1789 | - ->method('setTo') |
|
1790 | - ->with(['[email protected]']); |
|
1791 | - $this->defaults |
|
1792 | - ->expects($this->once()) |
|
1793 | - ->method('getName') |
|
1794 | - ->willReturn('UnitTestCloud'); |
|
1795 | - $message |
|
1796 | - ->expects($this->once()) |
|
1797 | - ->method('setFrom') |
|
1798 | - ->with([ |
|
1799 | - Util::getDefaultEmailAddress('UnitTestCloud') => 'UnitTestCloud' |
|
1800 | - ]); |
|
1801 | - // Since replyToInitiator is false, we never get the initiator email address |
|
1802 | - $user |
|
1803 | - ->expects($this->never()) |
|
1804 | - ->method('getEMailAddress'); |
|
1805 | - $message |
|
1806 | - ->expects($this->never()) |
|
1807 | - ->method('setReplyTo'); |
|
1808 | - $template |
|
1809 | - ->expects($this->once()) |
|
1810 | - ->method('addFooter') |
|
1811 | - ->with(''); |
|
1812 | - $template |
|
1813 | - ->expects($this->once()) |
|
1814 | - ->method('setSubject') |
|
1815 | - ->with('Mrs. Owner User shared file.txt with you'); |
|
1816 | - $message |
|
1817 | - ->expects($this->once()) |
|
1818 | - ->method('useTemplate') |
|
1819 | - ->with($template); |
|
1820 | - |
|
1821 | - $this->mailer->expects($this->once()) |
|
1822 | - ->method('validateMailAddress') |
|
1823 | - ->willReturn(true); |
|
1824 | - $this->mailer |
|
1825 | - ->expects($this->once()) |
|
1826 | - ->method('send') |
|
1827 | - ->with($message); |
|
1828 | - |
|
1829 | - $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute') |
|
1830 | - ->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) |
|
1831 | - ->willReturn('https://example.com/file.txt'); |
|
1832 | - |
|
1833 | - $node = $this->createMock(File::class); |
|
1834 | - $node->expects($this->any())->method('getName')->willReturn('file.txt'); |
|
1835 | - |
|
1836 | - $share = $this->createMock(IShare::class); |
|
1837 | - $share->expects($this->any())->method('getSharedBy')->willReturn('OwnerUser'); |
|
1838 | - $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
1839 | - $share->expects($this->any())->method('getNode')->willReturn($node); |
|
1840 | - $share->expects($this->any())->method('getId')->willReturn(42); |
|
1841 | - $share->expects($this->any())->method('getNote')->willReturn(''); |
|
1842 | - $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
1843 | - |
|
1844 | - self::invokePrivate( |
|
1845 | - $provider, |
|
1846 | - 'sendMailNotification', |
|
1847 | - [$share] |
|
1848 | - ); |
|
1849 | - } |
|
1850 | - |
|
1851 | - public function testSendMailNotificationWithDifferentUserAndNoUserEmailAndReplyToDesactivate(): void { |
|
1852 | - $provider = $this->getInstance(); |
|
1853 | - $initiatorUser = $this->createMock(IUser::class); |
|
1854 | - $this->settingsManager->expects($this->any())->method('replyToInitiator')->willReturn(false); |
|
1855 | - $this->userManager |
|
1856 | - ->expects($this->once()) |
|
1857 | - ->method('get') |
|
1858 | - ->with('InitiatorUser') |
|
1859 | - ->willReturn($initiatorUser); |
|
1860 | - $initiatorUser |
|
1861 | - ->expects($this->once()) |
|
1862 | - ->method('getDisplayName') |
|
1863 | - ->willReturn('Mr. Initiator User'); |
|
1864 | - $message = $this->createMock(Message::class); |
|
1865 | - $this->mailer |
|
1866 | - ->expects($this->once()) |
|
1867 | - ->method('createMessage') |
|
1868 | - ->willReturn($message); |
|
1869 | - $template = $this->createMock(IEMailTemplate::class); |
|
1870 | - $this->mailer |
|
1871 | - ->expects($this->once()) |
|
1872 | - ->method('createEMailTemplate') |
|
1873 | - ->willReturn($template); |
|
1874 | - $template |
|
1875 | - ->expects($this->once()) |
|
1876 | - ->method('addHeader'); |
|
1877 | - $template |
|
1878 | - ->expects($this->once()) |
|
1879 | - ->method('addHeading') |
|
1880 | - ->with('Mr. Initiator User shared file.txt with you'); |
|
1881 | - $template |
|
1882 | - ->expects($this->once()) |
|
1883 | - ->method('addBodyButton') |
|
1884 | - ->with( |
|
1885 | - 'Open file.txt', |
|
1886 | - 'https://example.com/file.txt' |
|
1887 | - ); |
|
1888 | - $message |
|
1889 | - ->expects($this->once()) |
|
1890 | - ->method('setTo') |
|
1891 | - ->with(['[email protected]']); |
|
1892 | - $this->defaults |
|
1893 | - ->expects($this->once()) |
|
1894 | - ->method('getName') |
|
1895 | - ->willReturn('UnitTestCloud'); |
|
1896 | - $message |
|
1897 | - ->expects($this->once()) |
|
1898 | - ->method('setFrom') |
|
1899 | - ->with([ |
|
1900 | - Util::getDefaultEmailAddress('UnitTestCloud') => 'UnitTestCloud' |
|
1901 | - ]); |
|
1902 | - $message |
|
1903 | - ->expects($this->never()) |
|
1904 | - ->method('setReplyTo'); |
|
1905 | - $template |
|
1906 | - ->expects($this->once()) |
|
1907 | - ->method('addFooter') |
|
1908 | - ->with(''); |
|
1909 | - $template |
|
1910 | - ->expects($this->once()) |
|
1911 | - ->method('setSubject') |
|
1912 | - ->with('Mr. Initiator User shared file.txt with you'); |
|
1913 | - $message |
|
1914 | - ->expects($this->once()) |
|
1915 | - ->method('useTemplate') |
|
1916 | - ->with($template); |
|
1917 | - |
|
1918 | - $this->mailer->expects($this->once()) |
|
1919 | - ->method('validateMailAddress') |
|
1920 | - ->willReturn(true); |
|
1921 | - $this->mailer |
|
1922 | - ->expects($this->once()) |
|
1923 | - ->method('send') |
|
1924 | - ->with($message); |
|
1925 | - |
|
1926 | - $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute') |
|
1927 | - ->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) |
|
1928 | - ->willReturn('https://example.com/file.txt'); |
|
1929 | - |
|
1930 | - $node = $this->createMock(File::class); |
|
1931 | - $node->expects($this->any())->method('getName')->willReturn('file.txt'); |
|
1932 | - |
|
1933 | - $share = $this->createMock(IShare::class); |
|
1934 | - $share->expects($this->any())->method('getSharedBy')->willReturn('InitiatorUser'); |
|
1935 | - $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
1936 | - $share->expects($this->any())->method('getNode')->willReturn($node); |
|
1937 | - $share->expects($this->any())->method('getId')->willReturn(42); |
|
1938 | - $share->expects($this->any())->method('getNote')->willReturn(''); |
|
1939 | - $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
1940 | - |
|
1941 | - self::invokePrivate( |
|
1942 | - $provider, |
|
1943 | - 'sendMailNotification', |
|
1944 | - [$share] |
|
1945 | - ); |
|
1946 | - } |
|
1174 | + $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
1175 | + |
|
1176 | + $qb->execute(); |
|
1177 | + $id = $qb->getLastInsertId(); |
|
1178 | + |
|
1179 | + return (int)$id; |
|
1180 | + } |
|
1181 | + |
|
1182 | + public function testGetSharesInFolder(): void { |
|
1183 | + $userManager = Server::get(IUserManager::class); |
|
1184 | + $rootFolder = Server::get(IRootFolder::class); |
|
1185 | + |
|
1186 | + $this->shareManager->expects($this->any()) |
|
1187 | + ->method('newShare') |
|
1188 | + ->willReturn(new Share($rootFolder, $userManager)); |
|
1189 | + |
|
1190 | + $provider = $this->getInstance(['sendMailNotification', 'createShareActivity']); |
|
1191 | + $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); |
|
1192 | + |
|
1193 | + $u1 = $userManager->createUser('testFed', md5((string)time())); |
|
1194 | + $u2 = $userManager->createUser('testFed2', md5((string)time())); |
|
1195 | + |
|
1196 | + $folder1 = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo'); |
|
1197 | + $file1 = $folder1->newFile('bar1'); |
|
1198 | + $file2 = $folder1->newFile('bar2'); |
|
1199 | + |
|
1200 | + $share1 = $this->shareManager->newShare(); |
|
1201 | + $share1->setSharedWith('[email protected]') |
|
1202 | + ->setSharedBy($u1->getUID()) |
|
1203 | + ->setShareOwner($u1->getUID()) |
|
1204 | + ->setPermissions(Constants::PERMISSION_READ) |
|
1205 | + ->setNode($file1); |
|
1206 | + $provider->create($share1); |
|
1207 | + |
|
1208 | + $share2 = $this->shareManager->newShare(); |
|
1209 | + $share2->setSharedWith('[email protected]') |
|
1210 | + ->setSharedBy($u2->getUID()) |
|
1211 | + ->setShareOwner($u1->getUID()) |
|
1212 | + ->setPermissions(Constants::PERMISSION_READ) |
|
1213 | + ->setNode($file2); |
|
1214 | + $provider->create($share2); |
|
1215 | + |
|
1216 | + $result = $provider->getSharesInFolder($u1->getUID(), $folder1, false); |
|
1217 | + $this->assertCount(1, $result); |
|
1218 | + $this->assertCount(1, $result[$file1->getId()]); |
|
1219 | + |
|
1220 | + $result = $provider->getSharesInFolder($u1->getUID(), $folder1, true); |
|
1221 | + $this->assertCount(2, $result); |
|
1222 | + $this->assertCount(1, $result[$file1->getId()]); |
|
1223 | + $this->assertCount(1, $result[$file2->getId()]); |
|
1224 | + |
|
1225 | + $u1->delete(); |
|
1226 | + $u2->delete(); |
|
1227 | + } |
|
1228 | + |
|
1229 | + public function testGetAccessList(): void { |
|
1230 | + $userManager = Server::get(IUserManager::class); |
|
1231 | + $rootFolder = Server::get(IRootFolder::class); |
|
1232 | + |
|
1233 | + $this->shareManager->expects($this->any()) |
|
1234 | + ->method('newShare') |
|
1235 | + ->willReturn(new Share($rootFolder, $userManager)); |
|
1236 | + |
|
1237 | + $provider = $this->getInstance(['sendMailNotification', 'createShareActivity']); |
|
1238 | + $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); |
|
1239 | + |
|
1240 | + $u1 = $userManager->createUser('testFed', md5((string)time())); |
|
1241 | + $u2 = $userManager->createUser('testFed2', md5((string)time())); |
|
1242 | + |
|
1243 | + $folder = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo'); |
|
1244 | + |
|
1245 | + $accessList = $provider->getAccessList([$folder], true); |
|
1246 | + $this->assertArrayHasKey('public', $accessList); |
|
1247 | + $this->assertFalse($accessList['public']); |
|
1248 | + $accessList = $provider->getAccessList([$folder], false); |
|
1249 | + $this->assertArrayHasKey('public', $accessList); |
|
1250 | + $this->assertFalse($accessList['public']); |
|
1251 | + |
|
1252 | + $share1 = $this->shareManager->newShare(); |
|
1253 | + $share1->setSharedWith('[email protected]') |
|
1254 | + ->setSharedBy($u1->getUID()) |
|
1255 | + ->setShareOwner($u1->getUID()) |
|
1256 | + ->setPermissions(Constants::PERMISSION_READ) |
|
1257 | + ->setNode($folder); |
|
1258 | + $share1 = $provider->create($share1); |
|
1259 | + |
|
1260 | + $share2 = $this->shareManager->newShare(); |
|
1261 | + $share2->setSharedWith('[email protected]') |
|
1262 | + ->setSharedBy($u2->getUID()) |
|
1263 | + ->setShareOwner($u1->getUID()) |
|
1264 | + ->setPermissions(Constants::PERMISSION_READ) |
|
1265 | + ->setNode($folder); |
|
1266 | + $share2 = $provider->create($share2); |
|
1267 | + |
|
1268 | + $accessList = $provider->getAccessList([$folder], true); |
|
1269 | + $this->assertArrayHasKey('public', $accessList); |
|
1270 | + $this->assertTrue($accessList['public']); |
|
1271 | + $accessList = $provider->getAccessList([$folder], false); |
|
1272 | + $this->assertArrayHasKey('public', $accessList); |
|
1273 | + $this->assertTrue($accessList['public']); |
|
1274 | + |
|
1275 | + $provider->delete($share2); |
|
1276 | + |
|
1277 | + $accessList = $provider->getAccessList([$folder], true); |
|
1278 | + $this->assertArrayHasKey('public', $accessList); |
|
1279 | + $this->assertTrue($accessList['public']); |
|
1280 | + $accessList = $provider->getAccessList([$folder], false); |
|
1281 | + $this->assertArrayHasKey('public', $accessList); |
|
1282 | + $this->assertTrue($accessList['public']); |
|
1283 | + |
|
1284 | + $provider->delete($share1); |
|
1285 | + |
|
1286 | + $accessList = $provider->getAccessList([$folder], true); |
|
1287 | + $this->assertArrayHasKey('public', $accessList); |
|
1288 | + $this->assertFalse($accessList['public']); |
|
1289 | + $accessList = $provider->getAccessList([$folder], false); |
|
1290 | + $this->assertArrayHasKey('public', $accessList); |
|
1291 | + $this->assertFalse($accessList['public']); |
|
1292 | + |
|
1293 | + $u1->delete(); |
|
1294 | + $u2->delete(); |
|
1295 | + } |
|
1296 | + |
|
1297 | + public function testSendMailNotificationWithSameUserAndUserEmail(): void { |
|
1298 | + $provider = $this->getInstance(); |
|
1299 | + $user = $this->createMock(IUser::class); |
|
1300 | + $this->settingsManager->expects($this->any())->method('replyToInitiator')->willReturn(true); |
|
1301 | + $this->userManager |
|
1302 | + ->expects($this->once()) |
|
1303 | + ->method('get') |
|
1304 | + ->with('OwnerUser') |
|
1305 | + ->willReturn($user); |
|
1306 | + $user |
|
1307 | + ->expects($this->once()) |
|
1308 | + ->method('getDisplayName') |
|
1309 | + ->willReturn('Mrs. Owner User'); |
|
1310 | + $message = $this->createMock(Message::class); |
|
1311 | + $this->mailer |
|
1312 | + ->expects($this->once()) |
|
1313 | + ->method('createMessage') |
|
1314 | + ->willReturn($message); |
|
1315 | + $template = $this->createMock(IEMailTemplate::class); |
|
1316 | + $this->mailer |
|
1317 | + ->expects($this->once()) |
|
1318 | + ->method('createEMailTemplate') |
|
1319 | + ->willReturn($template); |
|
1320 | + $template |
|
1321 | + ->expects($this->once()) |
|
1322 | + ->method('addHeader'); |
|
1323 | + $template |
|
1324 | + ->expects($this->once()) |
|
1325 | + ->method('addHeading') |
|
1326 | + ->with('Mrs. Owner User shared file.txt with you'); |
|
1327 | + $template |
|
1328 | + ->expects($this->once()) |
|
1329 | + ->method('addBodyButton') |
|
1330 | + ->with( |
|
1331 | + 'Open file.txt', |
|
1332 | + 'https://example.com/file.txt' |
|
1333 | + ); |
|
1334 | + $message |
|
1335 | + ->expects($this->once()) |
|
1336 | + ->method('setTo') |
|
1337 | + ->with(['[email protected]']); |
|
1338 | + $this->defaults |
|
1339 | + ->expects($this->once()) |
|
1340 | + ->method('getName') |
|
1341 | + ->willReturn('UnitTestCloud'); |
|
1342 | + $message |
|
1343 | + ->expects($this->once()) |
|
1344 | + ->method('setFrom') |
|
1345 | + ->with([ |
|
1346 | + Util::getDefaultEmailAddress('UnitTestCloud') => 'Mrs. Owner User via UnitTestCloud' |
|
1347 | + ]); |
|
1348 | + $user |
|
1349 | + ->expects($this->once()) |
|
1350 | + ->method('getEMailAddress') |
|
1351 | + ->willReturn('[email protected]'); |
|
1352 | + $message |
|
1353 | + ->expects($this->once()) |
|
1354 | + ->method('setReplyTo') |
|
1355 | + ->with(['[email protected]' => 'Mrs. Owner User']); |
|
1356 | + $this->defaults |
|
1357 | + ->expects($this->exactly(2)) |
|
1358 | + ->method('getSlogan') |
|
1359 | + ->willReturn('Testing like 1990'); |
|
1360 | + $template |
|
1361 | + ->expects($this->once()) |
|
1362 | + ->method('addFooter') |
|
1363 | + ->with('UnitTestCloud - Testing like 1990'); |
|
1364 | + $template |
|
1365 | + ->expects($this->once()) |
|
1366 | + ->method('setSubject') |
|
1367 | + ->with('Mrs. Owner User shared file.txt with you'); |
|
1368 | + $message |
|
1369 | + ->expects($this->once()) |
|
1370 | + ->method('useTemplate') |
|
1371 | + ->with($template); |
|
1372 | + |
|
1373 | + $this->mailer->expects($this->once()) |
|
1374 | + ->method('validateMailAddress') |
|
1375 | + ->willReturn(true); |
|
1376 | + $this->mailer |
|
1377 | + ->expects($this->once()) |
|
1378 | + ->method('send') |
|
1379 | + ->with($message); |
|
1380 | + |
|
1381 | + $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute') |
|
1382 | + ->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) |
|
1383 | + ->willReturn('https://example.com/file.txt'); |
|
1384 | + |
|
1385 | + $node = $this->createMock(File::class); |
|
1386 | + $node->expects($this->any())->method('getName')->willReturn('file.txt'); |
|
1387 | + |
|
1388 | + $share = $this->createMock(IShare::class); |
|
1389 | + $share->expects($this->any())->method('getSharedBy')->willReturn('OwnerUser'); |
|
1390 | + $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
1391 | + $share->expects($this->any())->method('getNode')->willReturn($node); |
|
1392 | + $share->expects($this->any())->method('getId')->willReturn(42); |
|
1393 | + $share->expects($this->any())->method('getNote')->willReturn(''); |
|
1394 | + $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
1395 | + |
|
1396 | + self::invokePrivate( |
|
1397 | + $provider, |
|
1398 | + 'sendMailNotification', |
|
1399 | + [$share] |
|
1400 | + ); |
|
1401 | + } |
|
1402 | + |
|
1403 | + public function testSendMailNotificationWithSameUserAndUserEmailAndNote(): void { |
|
1404 | + $provider = $this->getInstance(); |
|
1405 | + $user = $this->createMock(IUser::class); |
|
1406 | + $this->settingsManager->expects($this->any())->method('replyToInitiator')->willReturn(true); |
|
1407 | + $this->userManager |
|
1408 | + ->expects($this->once()) |
|
1409 | + ->method('get') |
|
1410 | + ->with('OwnerUser') |
|
1411 | + ->willReturn($user); |
|
1412 | + $user |
|
1413 | + ->expects($this->once()) |
|
1414 | + ->method('getDisplayName') |
|
1415 | + ->willReturn('Mrs. Owner User'); |
|
1416 | + $message = $this->createMock(Message::class); |
|
1417 | + $this->mailer |
|
1418 | + ->expects($this->once()) |
|
1419 | + ->method('createMessage') |
|
1420 | + ->willReturn($message); |
|
1421 | + $template = $this->createMock(IEMailTemplate::class); |
|
1422 | + $this->mailer |
|
1423 | + ->expects($this->once()) |
|
1424 | + ->method('createEMailTemplate') |
|
1425 | + ->willReturn($template); |
|
1426 | + $template |
|
1427 | + ->expects($this->once()) |
|
1428 | + ->method('addHeader'); |
|
1429 | + $template |
|
1430 | + ->expects($this->once()) |
|
1431 | + ->method('addHeading') |
|
1432 | + ->with('Mrs. Owner User shared file.txt with you'); |
|
1433 | + |
|
1434 | + $this->urlGenerator->expects($this->once())->method('imagePath') |
|
1435 | + ->with('core', 'caldav/description.png') |
|
1436 | + ->willReturn('core/img/caldav/description.png'); |
|
1437 | + $this->urlGenerator->expects($this->once())->method('getAbsoluteURL') |
|
1438 | + ->with('core/img/caldav/description.png') |
|
1439 | + ->willReturn('https://example.com/core/img/caldav/description.png'); |
|
1440 | + $template |
|
1441 | + ->expects($this->once()) |
|
1442 | + ->method('addBodyListItem') |
|
1443 | + ->with( |
|
1444 | + 'This is a note to the recipient', |
|
1445 | + 'Note:', |
|
1446 | + 'https://example.com/core/img/caldav/description.png', |
|
1447 | + 'This is a note to the recipient' |
|
1448 | + ); |
|
1449 | + $template |
|
1450 | + ->expects($this->once()) |
|
1451 | + ->method('addBodyButton') |
|
1452 | + ->with( |
|
1453 | + 'Open file.txt', |
|
1454 | + 'https://example.com/file.txt' |
|
1455 | + ); |
|
1456 | + $message |
|
1457 | + ->expects($this->once()) |
|
1458 | + ->method('setTo') |
|
1459 | + ->with(['[email protected]']); |
|
1460 | + $this->defaults |
|
1461 | + ->expects($this->once()) |
|
1462 | + ->method('getName') |
|
1463 | + ->willReturn('UnitTestCloud'); |
|
1464 | + $message |
|
1465 | + ->expects($this->once()) |
|
1466 | + ->method('setFrom') |
|
1467 | + ->with([ |
|
1468 | + Util::getDefaultEmailAddress('UnitTestCloud') => 'Mrs. Owner User via UnitTestCloud' |
|
1469 | + ]); |
|
1470 | + $user |
|
1471 | + ->expects($this->once()) |
|
1472 | + ->method('getEMailAddress') |
|
1473 | + ->willReturn('[email protected]'); |
|
1474 | + $message |
|
1475 | + ->expects($this->once()) |
|
1476 | + ->method('setReplyTo') |
|
1477 | + ->with(['[email protected]' => 'Mrs. Owner User']); |
|
1478 | + $this->defaults |
|
1479 | + ->expects($this->exactly(2)) |
|
1480 | + ->method('getSlogan') |
|
1481 | + ->willReturn('Testing like 1990'); |
|
1482 | + $template |
|
1483 | + ->expects($this->once()) |
|
1484 | + ->method('addFooter') |
|
1485 | + ->with('UnitTestCloud - Testing like 1990'); |
|
1486 | + $template |
|
1487 | + ->expects($this->once()) |
|
1488 | + ->method('setSubject') |
|
1489 | + ->with('Mrs. Owner User shared file.txt with you'); |
|
1490 | + $message |
|
1491 | + ->expects($this->once()) |
|
1492 | + ->method('useTemplate') |
|
1493 | + ->with($template); |
|
1494 | + |
|
1495 | + $this->mailer->expects($this->once()) |
|
1496 | + ->method('validateMailAddress') |
|
1497 | + ->willReturn(true); |
|
1498 | + $this->mailer |
|
1499 | + ->expects($this->once()) |
|
1500 | + ->method('send') |
|
1501 | + ->with($message); |
|
1502 | + |
|
1503 | + $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute') |
|
1504 | + ->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) |
|
1505 | + ->willReturn('https://example.com/file.txt'); |
|
1506 | + |
|
1507 | + $node = $this->createMock(File::class); |
|
1508 | + $node->expects($this->any())->method('getName')->willReturn('file.txt'); |
|
1509 | + |
|
1510 | + $share = $this->createMock(IShare::class); |
|
1511 | + $share->expects($this->any())->method('getSharedBy')->willReturn('OwnerUser'); |
|
1512 | + $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
1513 | + $share->expects($this->any())->method('getNode')->willReturn($node); |
|
1514 | + $share->expects($this->any())->method('getId')->willReturn(42); |
|
1515 | + $share->expects($this->any())->method('getNote')->willReturn('This is a note to the recipient'); |
|
1516 | + $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
1517 | + |
|
1518 | + self::invokePrivate( |
|
1519 | + $provider, |
|
1520 | + 'sendMailNotification', |
|
1521 | + [$share] |
|
1522 | + ); |
|
1523 | + } |
|
1524 | + |
|
1525 | + public function testSendMailNotificationWithSameUserAndUserEmailAndExpiration(): void { |
|
1526 | + $provider = $this->getInstance(); |
|
1527 | + $user = $this->createMock(IUser::class); |
|
1528 | + $this->settingsManager->expects($this->any())->method('replyToInitiator')->willReturn(true); |
|
1529 | + $this->userManager |
|
1530 | + ->expects($this->once()) |
|
1531 | + ->method('get') |
|
1532 | + ->with('OwnerUser') |
|
1533 | + ->willReturn($user); |
|
1534 | + $user |
|
1535 | + ->expects($this->once()) |
|
1536 | + ->method('getDisplayName') |
|
1537 | + ->willReturn('Mrs. Owner User'); |
|
1538 | + $message = $this->createMock(Message::class); |
|
1539 | + $this->mailer |
|
1540 | + ->expects($this->once()) |
|
1541 | + ->method('createMessage') |
|
1542 | + ->willReturn($message); |
|
1543 | + $template = $this->createMock(IEMailTemplate::class); |
|
1544 | + $this->mailer |
|
1545 | + ->expects($this->once()) |
|
1546 | + ->method('createEMailTemplate') |
|
1547 | + ->willReturn($template); |
|
1548 | + $template |
|
1549 | + ->expects($this->once()) |
|
1550 | + ->method('addHeader'); |
|
1551 | + $template |
|
1552 | + ->expects($this->once()) |
|
1553 | + ->method('addHeading') |
|
1554 | + ->with('Mrs. Owner User shared file.txt with you'); |
|
1555 | + |
|
1556 | + $expiration = new DateTime('2001-01-01'); |
|
1557 | + $this->l->expects($this->once()) |
|
1558 | + ->method('l') |
|
1559 | + ->with('date', $expiration, ['width' => 'medium']) |
|
1560 | + ->willReturn('2001-01-01'); |
|
1561 | + $this->urlGenerator->expects($this->once())->method('imagePath') |
|
1562 | + ->with('core', 'caldav/time.png') |
|
1563 | + ->willReturn('core/img/caldav/time.png'); |
|
1564 | + $this->urlGenerator->expects($this->once())->method('getAbsoluteURL') |
|
1565 | + ->with('core/img/caldav/time.png') |
|
1566 | + ->willReturn('https://example.com/core/img/caldav/time.png'); |
|
1567 | + $template |
|
1568 | + ->expects($this->once()) |
|
1569 | + ->method('addBodyListItem') |
|
1570 | + ->with( |
|
1571 | + 'This share is valid until 2001-01-01 at midnight', |
|
1572 | + 'Expiration:', |
|
1573 | + 'https://example.com/core/img/caldav/time.png', |
|
1574 | + ); |
|
1575 | + |
|
1576 | + $template |
|
1577 | + ->expects($this->once()) |
|
1578 | + ->method('addBodyButton') |
|
1579 | + ->with( |
|
1580 | + 'Open file.txt', |
|
1581 | + 'https://example.com/file.txt' |
|
1582 | + ); |
|
1583 | + $message |
|
1584 | + ->expects($this->once()) |
|
1585 | + ->method('setTo') |
|
1586 | + ->with(['[email protected]']); |
|
1587 | + $this->defaults |
|
1588 | + ->expects($this->once()) |
|
1589 | + ->method('getName') |
|
1590 | + ->willReturn('UnitTestCloud'); |
|
1591 | + $message |
|
1592 | + ->expects($this->once()) |
|
1593 | + ->method('setFrom') |
|
1594 | + ->with([ |
|
1595 | + Util::getDefaultEmailAddress('UnitTestCloud') => 'Mrs. Owner User via UnitTestCloud' |
|
1596 | + ]); |
|
1597 | + $user |
|
1598 | + ->expects($this->once()) |
|
1599 | + ->method('getEMailAddress') |
|
1600 | + ->willReturn('[email protected]'); |
|
1601 | + $message |
|
1602 | + ->expects($this->once()) |
|
1603 | + ->method('setReplyTo') |
|
1604 | + ->with(['[email protected]' => 'Mrs. Owner User']); |
|
1605 | + $this->defaults |
|
1606 | + ->expects($this->exactly(2)) |
|
1607 | + ->method('getSlogan') |
|
1608 | + ->willReturn('Testing like 1990'); |
|
1609 | + $template |
|
1610 | + ->expects($this->once()) |
|
1611 | + ->method('addFooter') |
|
1612 | + ->with('UnitTestCloud - Testing like 1990'); |
|
1613 | + $template |
|
1614 | + ->expects($this->once()) |
|
1615 | + ->method('setSubject') |
|
1616 | + ->with('Mrs. Owner User shared file.txt with you'); |
|
1617 | + $message |
|
1618 | + ->expects($this->once()) |
|
1619 | + ->method('useTemplate') |
|
1620 | + ->with($template); |
|
1621 | + |
|
1622 | + $this->mailer->expects($this->once()) |
|
1623 | + ->method('validateMailAddress') |
|
1624 | + ->willReturn(true); |
|
1625 | + $this->mailer |
|
1626 | + ->expects($this->once()) |
|
1627 | + ->method('send') |
|
1628 | + ->with($message); |
|
1629 | + |
|
1630 | + $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute') |
|
1631 | + ->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) |
|
1632 | + ->willReturn('https://example.com/file.txt'); |
|
1633 | + |
|
1634 | + $node = $this->createMock(File::class); |
|
1635 | + $node->expects($this->any())->method('getName')->willReturn('file.txt'); |
|
1636 | + |
|
1637 | + $share = $this->createMock(IShare::class); |
|
1638 | + $share->expects($this->any())->method('getSharedBy')->willReturn('OwnerUser'); |
|
1639 | + $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
1640 | + $share->expects($this->any())->method('getNode')->willReturn($node); |
|
1641 | + $share->expects($this->any())->method('getId')->willReturn(42); |
|
1642 | + $share->expects($this->any())->method('getNote')->willReturn(''); |
|
1643 | + $share->expects($this->any())->method('getExpirationDate')->willReturn($expiration); |
|
1644 | + $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
1645 | + |
|
1646 | + self::invokePrivate( |
|
1647 | + $provider, |
|
1648 | + 'sendMailNotification', |
|
1649 | + [$share] |
|
1650 | + ); |
|
1651 | + } |
|
1652 | + |
|
1653 | + public function testSendMailNotificationWithDifferentUserAndNoUserEmail(): void { |
|
1654 | + $provider = $this->getInstance(); |
|
1655 | + $initiatorUser = $this->createMock(IUser::class); |
|
1656 | + $this->settingsManager->expects($this->any())->method('replyToInitiator')->willReturn(true); |
|
1657 | + $this->userManager |
|
1658 | + ->expects($this->once()) |
|
1659 | + ->method('get') |
|
1660 | + ->with('InitiatorUser') |
|
1661 | + ->willReturn($initiatorUser); |
|
1662 | + $initiatorUser |
|
1663 | + ->expects($this->once()) |
|
1664 | + ->method('getDisplayName') |
|
1665 | + ->willReturn('Mr. Initiator User'); |
|
1666 | + $message = $this->createMock(Message::class); |
|
1667 | + $this->mailer |
|
1668 | + ->expects($this->once()) |
|
1669 | + ->method('createMessage') |
|
1670 | + ->willReturn($message); |
|
1671 | + $template = $this->createMock(IEMailTemplate::class); |
|
1672 | + $this->mailer |
|
1673 | + ->expects($this->once()) |
|
1674 | + ->method('createEMailTemplate') |
|
1675 | + ->willReturn($template); |
|
1676 | + $template |
|
1677 | + ->expects($this->once()) |
|
1678 | + ->method('addHeader'); |
|
1679 | + $template |
|
1680 | + ->expects($this->once()) |
|
1681 | + ->method('addHeading') |
|
1682 | + ->with('Mr. Initiator User shared file.txt with you'); |
|
1683 | + $template |
|
1684 | + ->expects($this->once()) |
|
1685 | + ->method('addBodyButton') |
|
1686 | + ->with( |
|
1687 | + 'Open file.txt', |
|
1688 | + 'https://example.com/file.txt' |
|
1689 | + ); |
|
1690 | + $message |
|
1691 | + ->expects($this->once()) |
|
1692 | + ->method('setTo') |
|
1693 | + ->with(['[email protected]']); |
|
1694 | + $this->defaults |
|
1695 | + ->expects($this->once()) |
|
1696 | + ->method('getName') |
|
1697 | + ->willReturn('UnitTestCloud'); |
|
1698 | + $message |
|
1699 | + ->expects($this->once()) |
|
1700 | + ->method('setFrom') |
|
1701 | + ->with([ |
|
1702 | + Util::getDefaultEmailAddress('UnitTestCloud') => 'Mr. Initiator User via UnitTestCloud' |
|
1703 | + ]); |
|
1704 | + $message |
|
1705 | + ->expects($this->never()) |
|
1706 | + ->method('setReplyTo'); |
|
1707 | + $template |
|
1708 | + ->expects($this->once()) |
|
1709 | + ->method('addFooter') |
|
1710 | + ->with(''); |
|
1711 | + $template |
|
1712 | + ->expects($this->once()) |
|
1713 | + ->method('setSubject') |
|
1714 | + ->with('Mr. Initiator User shared file.txt with you'); |
|
1715 | + $message |
|
1716 | + ->expects($this->once()) |
|
1717 | + ->method('useTemplate') |
|
1718 | + ->with($template); |
|
1719 | + |
|
1720 | + $this->mailer->expects($this->once()) |
|
1721 | + ->method('validateMailAddress') |
|
1722 | + ->willReturn(true); |
|
1723 | + $this->mailer |
|
1724 | + ->expects($this->once()) |
|
1725 | + ->method('send') |
|
1726 | + ->with($message); |
|
1727 | + |
|
1728 | + $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute') |
|
1729 | + ->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) |
|
1730 | + ->willReturn('https://example.com/file.txt'); |
|
1731 | + |
|
1732 | + $node = $this->createMock(File::class); |
|
1733 | + $node->expects($this->any())->method('getName')->willReturn('file.txt'); |
|
1734 | + |
|
1735 | + $share = $this->createMock(IShare::class); |
|
1736 | + $share->expects($this->any())->method('getSharedBy')->willReturn('InitiatorUser'); |
|
1737 | + $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
1738 | + $share->expects($this->any())->method('getNode')->willReturn($node); |
|
1739 | + $share->expects($this->any())->method('getId')->willReturn(42); |
|
1740 | + $share->expects($this->any())->method('getNote')->willReturn(''); |
|
1741 | + $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
1742 | + |
|
1743 | + self::invokePrivate( |
|
1744 | + $provider, |
|
1745 | + 'sendMailNotification', |
|
1746 | + [$share] |
|
1747 | + ); |
|
1748 | + } |
|
1749 | + |
|
1750 | + public function testSendMailNotificationWithSameUserAndUserEmailAndReplyToDesactivate(): void { |
|
1751 | + $provider = $this->getInstance(); |
|
1752 | + $user = $this->createMock(IUser::class); |
|
1753 | + $this->settingsManager->expects($this->any())->method('replyToInitiator')->willReturn(false); |
|
1754 | + $this->userManager |
|
1755 | + ->expects($this->once()) |
|
1756 | + ->method('get') |
|
1757 | + ->with('OwnerUser') |
|
1758 | + ->willReturn($user); |
|
1759 | + $user |
|
1760 | + ->expects($this->once()) |
|
1761 | + ->method('getDisplayName') |
|
1762 | + ->willReturn('Mrs. Owner User'); |
|
1763 | + $message = $this->createMock(Message::class); |
|
1764 | + $this->mailer |
|
1765 | + ->expects($this->once()) |
|
1766 | + ->method('createMessage') |
|
1767 | + ->willReturn($message); |
|
1768 | + $template = $this->createMock(IEMailTemplate::class); |
|
1769 | + $this->mailer |
|
1770 | + ->expects($this->once()) |
|
1771 | + ->method('createEMailTemplate') |
|
1772 | + ->willReturn($template); |
|
1773 | + $template |
|
1774 | + ->expects($this->once()) |
|
1775 | + ->method('addHeader'); |
|
1776 | + $template |
|
1777 | + ->expects($this->once()) |
|
1778 | + ->method('addHeading') |
|
1779 | + ->with('Mrs. Owner User shared file.txt with you'); |
|
1780 | + $template |
|
1781 | + ->expects($this->once()) |
|
1782 | + ->method('addBodyButton') |
|
1783 | + ->with( |
|
1784 | + 'Open file.txt', |
|
1785 | + 'https://example.com/file.txt' |
|
1786 | + ); |
|
1787 | + $message |
|
1788 | + ->expects($this->once()) |
|
1789 | + ->method('setTo') |
|
1790 | + ->with(['[email protected]']); |
|
1791 | + $this->defaults |
|
1792 | + ->expects($this->once()) |
|
1793 | + ->method('getName') |
|
1794 | + ->willReturn('UnitTestCloud'); |
|
1795 | + $message |
|
1796 | + ->expects($this->once()) |
|
1797 | + ->method('setFrom') |
|
1798 | + ->with([ |
|
1799 | + Util::getDefaultEmailAddress('UnitTestCloud') => 'UnitTestCloud' |
|
1800 | + ]); |
|
1801 | + // Since replyToInitiator is false, we never get the initiator email address |
|
1802 | + $user |
|
1803 | + ->expects($this->never()) |
|
1804 | + ->method('getEMailAddress'); |
|
1805 | + $message |
|
1806 | + ->expects($this->never()) |
|
1807 | + ->method('setReplyTo'); |
|
1808 | + $template |
|
1809 | + ->expects($this->once()) |
|
1810 | + ->method('addFooter') |
|
1811 | + ->with(''); |
|
1812 | + $template |
|
1813 | + ->expects($this->once()) |
|
1814 | + ->method('setSubject') |
|
1815 | + ->with('Mrs. Owner User shared file.txt with you'); |
|
1816 | + $message |
|
1817 | + ->expects($this->once()) |
|
1818 | + ->method('useTemplate') |
|
1819 | + ->with($template); |
|
1820 | + |
|
1821 | + $this->mailer->expects($this->once()) |
|
1822 | + ->method('validateMailAddress') |
|
1823 | + ->willReturn(true); |
|
1824 | + $this->mailer |
|
1825 | + ->expects($this->once()) |
|
1826 | + ->method('send') |
|
1827 | + ->with($message); |
|
1828 | + |
|
1829 | + $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute') |
|
1830 | + ->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) |
|
1831 | + ->willReturn('https://example.com/file.txt'); |
|
1832 | + |
|
1833 | + $node = $this->createMock(File::class); |
|
1834 | + $node->expects($this->any())->method('getName')->willReturn('file.txt'); |
|
1835 | + |
|
1836 | + $share = $this->createMock(IShare::class); |
|
1837 | + $share->expects($this->any())->method('getSharedBy')->willReturn('OwnerUser'); |
|
1838 | + $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
1839 | + $share->expects($this->any())->method('getNode')->willReturn($node); |
|
1840 | + $share->expects($this->any())->method('getId')->willReturn(42); |
|
1841 | + $share->expects($this->any())->method('getNote')->willReturn(''); |
|
1842 | + $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
1843 | + |
|
1844 | + self::invokePrivate( |
|
1845 | + $provider, |
|
1846 | + 'sendMailNotification', |
|
1847 | + [$share] |
|
1848 | + ); |
|
1849 | + } |
|
1850 | + |
|
1851 | + public function testSendMailNotificationWithDifferentUserAndNoUserEmailAndReplyToDesactivate(): void { |
|
1852 | + $provider = $this->getInstance(); |
|
1853 | + $initiatorUser = $this->createMock(IUser::class); |
|
1854 | + $this->settingsManager->expects($this->any())->method('replyToInitiator')->willReturn(false); |
|
1855 | + $this->userManager |
|
1856 | + ->expects($this->once()) |
|
1857 | + ->method('get') |
|
1858 | + ->with('InitiatorUser') |
|
1859 | + ->willReturn($initiatorUser); |
|
1860 | + $initiatorUser |
|
1861 | + ->expects($this->once()) |
|
1862 | + ->method('getDisplayName') |
|
1863 | + ->willReturn('Mr. Initiator User'); |
|
1864 | + $message = $this->createMock(Message::class); |
|
1865 | + $this->mailer |
|
1866 | + ->expects($this->once()) |
|
1867 | + ->method('createMessage') |
|
1868 | + ->willReturn($message); |
|
1869 | + $template = $this->createMock(IEMailTemplate::class); |
|
1870 | + $this->mailer |
|
1871 | + ->expects($this->once()) |
|
1872 | + ->method('createEMailTemplate') |
|
1873 | + ->willReturn($template); |
|
1874 | + $template |
|
1875 | + ->expects($this->once()) |
|
1876 | + ->method('addHeader'); |
|
1877 | + $template |
|
1878 | + ->expects($this->once()) |
|
1879 | + ->method('addHeading') |
|
1880 | + ->with('Mr. Initiator User shared file.txt with you'); |
|
1881 | + $template |
|
1882 | + ->expects($this->once()) |
|
1883 | + ->method('addBodyButton') |
|
1884 | + ->with( |
|
1885 | + 'Open file.txt', |
|
1886 | + 'https://example.com/file.txt' |
|
1887 | + ); |
|
1888 | + $message |
|
1889 | + ->expects($this->once()) |
|
1890 | + ->method('setTo') |
|
1891 | + ->with(['[email protected]']); |
|
1892 | + $this->defaults |
|
1893 | + ->expects($this->once()) |
|
1894 | + ->method('getName') |
|
1895 | + ->willReturn('UnitTestCloud'); |
|
1896 | + $message |
|
1897 | + ->expects($this->once()) |
|
1898 | + ->method('setFrom') |
|
1899 | + ->with([ |
|
1900 | + Util::getDefaultEmailAddress('UnitTestCloud') => 'UnitTestCloud' |
|
1901 | + ]); |
|
1902 | + $message |
|
1903 | + ->expects($this->never()) |
|
1904 | + ->method('setReplyTo'); |
|
1905 | + $template |
|
1906 | + ->expects($this->once()) |
|
1907 | + ->method('addFooter') |
|
1908 | + ->with(''); |
|
1909 | + $template |
|
1910 | + ->expects($this->once()) |
|
1911 | + ->method('setSubject') |
|
1912 | + ->with('Mr. Initiator User shared file.txt with you'); |
|
1913 | + $message |
|
1914 | + ->expects($this->once()) |
|
1915 | + ->method('useTemplate') |
|
1916 | + ->with($template); |
|
1917 | + |
|
1918 | + $this->mailer->expects($this->once()) |
|
1919 | + ->method('validateMailAddress') |
|
1920 | + ->willReturn(true); |
|
1921 | + $this->mailer |
|
1922 | + ->expects($this->once()) |
|
1923 | + ->method('send') |
|
1924 | + ->with($message); |
|
1925 | + |
|
1926 | + $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute') |
|
1927 | + ->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) |
|
1928 | + ->willReturn('https://example.com/file.txt'); |
|
1929 | + |
|
1930 | + $node = $this->createMock(File::class); |
|
1931 | + $node->expects($this->any())->method('getName')->willReturn('file.txt'); |
|
1932 | + |
|
1933 | + $share = $this->createMock(IShare::class); |
|
1934 | + $share->expects($this->any())->method('getSharedBy')->willReturn('InitiatorUser'); |
|
1935 | + $share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]'); |
|
1936 | + $share->expects($this->any())->method('getNode')->willReturn($node); |
|
1937 | + $share->expects($this->any())->method('getId')->willReturn(42); |
|
1938 | + $share->expects($this->any())->method('getNote')->willReturn(''); |
|
1939 | + $share->expects($this->any())->method('getToken')->willReturn('token'); |
|
1940 | + |
|
1941 | + self::invokePrivate( |
|
1942 | + $provider, |
|
1943 | + 'sendMailNotification', |
|
1944 | + [$share] |
|
1945 | + ); |
|
1946 | + } |
|
1947 | 1947 | } |
@@ -28,111 +28,111 @@ |
||
28 | 28 | */ |
29 | 29 | class DeleteOrphanedFilesTest extends TestCase { |
30 | 30 | |
31 | - private DeleteOrphanedFiles $command; |
|
32 | - private IDBConnection $connection; |
|
33 | - private string $user1; |
|
31 | + private DeleteOrphanedFiles $command; |
|
32 | + private IDBConnection $connection; |
|
33 | + private string $user1; |
|
34 | 34 | |
35 | - protected function setUp(): void { |
|
36 | - parent::setUp(); |
|
35 | + protected function setUp(): void { |
|
36 | + parent::setUp(); |
|
37 | 37 | |
38 | - $this->connection = Server::get(IDBConnection::class); |
|
38 | + $this->connection = Server::get(IDBConnection::class); |
|
39 | 39 | |
40 | - $this->user1 = $this->getUniqueID('user1_'); |
|
40 | + $this->user1 = $this->getUniqueID('user1_'); |
|
41 | 41 | |
42 | - $userManager = Server::get(IUserManager::class); |
|
43 | - $userManager->createUser($this->user1, 'pass'); |
|
42 | + $userManager = Server::get(IUserManager::class); |
|
43 | + $userManager->createUser($this->user1, 'pass'); |
|
44 | 44 | |
45 | - $this->command = new DeleteOrphanedFiles($this->connection); |
|
46 | - } |
|
45 | + $this->command = new DeleteOrphanedFiles($this->connection); |
|
46 | + } |
|
47 | 47 | |
48 | - protected function tearDown(): void { |
|
49 | - $userManager = Server::get(IUserManager::class); |
|
50 | - $user1 = $userManager->get($this->user1); |
|
51 | - if ($user1) { |
|
52 | - $user1->delete(); |
|
53 | - } |
|
48 | + protected function tearDown(): void { |
|
49 | + $userManager = Server::get(IUserManager::class); |
|
50 | + $user1 = $userManager->get($this->user1); |
|
51 | + if ($user1) { |
|
52 | + $user1->delete(); |
|
53 | + } |
|
54 | 54 | |
55 | - $this->logout(); |
|
55 | + $this->logout(); |
|
56 | 56 | |
57 | - parent::tearDown(); |
|
58 | - } |
|
57 | + parent::tearDown(); |
|
58 | + } |
|
59 | 59 | |
60 | - protected function getFile(int $fileId): array { |
|
61 | - $query = $this->connection->getQueryBuilder(); |
|
62 | - $query->select('*') |
|
63 | - ->from('filecache') |
|
64 | - ->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId))); |
|
65 | - return $query->executeQuery()->fetchAll(); |
|
66 | - } |
|
60 | + protected function getFile(int $fileId): array { |
|
61 | + $query = $this->connection->getQueryBuilder(); |
|
62 | + $query->select('*') |
|
63 | + ->from('filecache') |
|
64 | + ->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId))); |
|
65 | + return $query->executeQuery()->fetchAll(); |
|
66 | + } |
|
67 | 67 | |
68 | - protected function getMounts(int $storageId): array { |
|
69 | - $query = $this->connection->getQueryBuilder(); |
|
70 | - $query->select('*') |
|
71 | - ->from('mounts') |
|
72 | - ->where($query->expr()->eq('storage_id', $query->createNamedParameter($storageId))); |
|
73 | - return $query->executeQuery()->fetchAll(); |
|
74 | - } |
|
68 | + protected function getMounts(int $storageId): array { |
|
69 | + $query = $this->connection->getQueryBuilder(); |
|
70 | + $query->select('*') |
|
71 | + ->from('mounts') |
|
72 | + ->where($query->expr()->eq('storage_id', $query->createNamedParameter($storageId))); |
|
73 | + return $query->executeQuery()->fetchAll(); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Test clearing orphaned files |
|
78 | - */ |
|
79 | - public function testClearFiles(): void { |
|
80 | - $input = $this->createMock(InputInterface::class); |
|
81 | - $output = $this->createMock(OutputInterface::class); |
|
76 | + /** |
|
77 | + * Test clearing orphaned files |
|
78 | + */ |
|
79 | + public function testClearFiles(): void { |
|
80 | + $input = $this->createMock(InputInterface::class); |
|
81 | + $output = $this->createMock(OutputInterface::class); |
|
82 | 82 | |
83 | - $rootFolder = Server::get(IRootFolder::class); |
|
83 | + $rootFolder = Server::get(IRootFolder::class); |
|
84 | 84 | |
85 | - // scan home storage so that mounts are properly setup |
|
86 | - $rootFolder->getUserFolder($this->user1)->getStorage()->getScanner()->scan(''); |
|
85 | + // scan home storage so that mounts are properly setup |
|
86 | + $rootFolder->getUserFolder($this->user1)->getStorage()->getScanner()->scan(''); |
|
87 | 87 | |
88 | - $this->loginAsUser($this->user1); |
|
88 | + $this->loginAsUser($this->user1); |
|
89 | 89 | |
90 | - $view = new View('/' . $this->user1 . '/'); |
|
91 | - $view->mkdir('files/test'); |
|
90 | + $view = new View('/' . $this->user1 . '/'); |
|
91 | + $view->mkdir('files/test'); |
|
92 | 92 | |
93 | - $fileInfo = $view->getFileInfo('files/test'); |
|
93 | + $fileInfo = $view->getFileInfo('files/test'); |
|
94 | 94 | |
95 | - $storageId = $fileInfo->getStorage()->getId(); |
|
96 | - $numericStorageId = $fileInfo->getStorage()->getStorageCache()->getNumericId(); |
|
95 | + $storageId = $fileInfo->getStorage()->getId(); |
|
96 | + $numericStorageId = $fileInfo->getStorage()->getStorageCache()->getNumericId(); |
|
97 | 97 | |
98 | - $this->assertCount(1, $this->getFile($fileInfo->getId()), 'Asserts that file is available'); |
|
99 | - $this->assertCount(1, $this->getMounts($numericStorageId), 'Asserts that mount is available'); |
|
98 | + $this->assertCount(1, $this->getFile($fileInfo->getId()), 'Asserts that file is available'); |
|
99 | + $this->assertCount(1, $this->getMounts($numericStorageId), 'Asserts that mount is available'); |
|
100 | 100 | |
101 | - $this->command->execute($input, $output); |
|
101 | + $this->command->execute($input, $output); |
|
102 | 102 | |
103 | - $this->assertCount(1, $this->getFile($fileInfo->getId()), 'Asserts that file is still available'); |
|
104 | - $this->assertCount(1, $this->getMounts($numericStorageId), 'Asserts that mount is still available'); |
|
103 | + $this->assertCount(1, $this->getFile($fileInfo->getId()), 'Asserts that file is still available'); |
|
104 | + $this->assertCount(1, $this->getMounts($numericStorageId), 'Asserts that mount is still available'); |
|
105 | 105 | |
106 | 106 | |
107 | - $deletedRows = $this->connection->executeUpdate('DELETE FROM `*PREFIX*storages` WHERE `id` = ?', [$storageId]); |
|
108 | - $this->assertNotNull($deletedRows, 'Asserts that storage got deleted'); |
|
109 | - $this->assertSame(1, $deletedRows, 'Asserts that storage got deleted'); |
|
107 | + $deletedRows = $this->connection->executeUpdate('DELETE FROM `*PREFIX*storages` WHERE `id` = ?', [$storageId]); |
|
108 | + $this->assertNotNull($deletedRows, 'Asserts that storage got deleted'); |
|
109 | + $this->assertSame(1, $deletedRows, 'Asserts that storage got deleted'); |
|
110 | 110 | |
111 | - // parent folder, `files`, ´test` and `welcome.txt` => 4 elements |
|
112 | - $calls = [ |
|
113 | - '3 orphaned file cache entries deleted', |
|
114 | - '0 orphaned file cache extended entries deleted', |
|
115 | - '1 orphaned mount entries deleted', |
|
116 | - ]; |
|
117 | - $output |
|
118 | - ->expects($this->exactly(3)) |
|
119 | - ->method('writeln') |
|
120 | - ->willReturnCallback(function (string $message) use (&$calls): void { |
|
121 | - $expected = array_shift($calls); |
|
122 | - $this->assertSame($expected, $message); |
|
123 | - }); |
|
111 | + // parent folder, `files`, ´test` and `welcome.txt` => 4 elements |
|
112 | + $calls = [ |
|
113 | + '3 orphaned file cache entries deleted', |
|
114 | + '0 orphaned file cache extended entries deleted', |
|
115 | + '1 orphaned mount entries deleted', |
|
116 | + ]; |
|
117 | + $output |
|
118 | + ->expects($this->exactly(3)) |
|
119 | + ->method('writeln') |
|
120 | + ->willReturnCallback(function (string $message) use (&$calls): void { |
|
121 | + $expected = array_shift($calls); |
|
122 | + $this->assertSame($expected, $message); |
|
123 | + }); |
|
124 | 124 | |
125 | - $this->command->execute($input, $output); |
|
125 | + $this->command->execute($input, $output); |
|
126 | 126 | |
127 | - $this->assertCount(0, $this->getFile($fileInfo->getId()), 'Asserts that file gets cleaned up'); |
|
128 | - $this->assertCount(0, $this->getMounts($numericStorageId), 'Asserts that mount gets cleaned up'); |
|
127 | + $this->assertCount(0, $this->getFile($fileInfo->getId()), 'Asserts that file gets cleaned up'); |
|
128 | + $this->assertCount(0, $this->getMounts($numericStorageId), 'Asserts that mount gets cleaned up'); |
|
129 | 129 | |
130 | - // Rescan folder to add back to cache before deleting |
|
131 | - $rootFolder->getUserFolder($this->user1)->getStorage()->getScanner()->scan(''); |
|
132 | - // since we deleted the storage it might throw a (valid) StorageNotAvailableException |
|
133 | - try { |
|
134 | - $view->unlink('files/test'); |
|
135 | - } catch (StorageNotAvailableException $e) { |
|
136 | - } |
|
137 | - } |
|
130 | + // Rescan folder to add back to cache before deleting |
|
131 | + $rootFolder->getUserFolder($this->user1)->getStorage()->getScanner()->scan(''); |
|
132 | + // since we deleted the storage it might throw a (valid) StorageNotAvailableException |
|
133 | + try { |
|
134 | + $view->unlink('files/test'); |
|
135 | + } catch (StorageNotAvailableException $e) { |
|
136 | + } |
|
137 | + } |
|
138 | 138 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | |
88 | 88 | $this->loginAsUser($this->user1); |
89 | 89 | |
90 | - $view = new View('/' . $this->user1 . '/'); |
|
90 | + $view = new View('/'.$this->user1.'/'); |
|
91 | 91 | $view->mkdir('files/test'); |
92 | 92 | |
93 | 93 | $fileInfo = $view->getFileInfo('files/test'); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $output |
118 | 118 | ->expects($this->exactly(3)) |
119 | 119 | ->method('writeln') |
120 | - ->willReturnCallback(function (string $message) use (&$calls): void { |
|
120 | + ->willReturnCallback(function(string $message) use (&$calls): void { |
|
121 | 121 | $expected = array_shift($calls); |
122 | 122 | $this->assertSame($expected, $message); |
123 | 123 | }); |