@@ -19,7 +19,7 @@ |
||
19 | 19 | * @package OCA\User_LDAP\Tests\Mapping |
20 | 20 | */ |
21 | 21 | class GroupMappingTest extends AbstractMappingTestCase { |
22 | - public function getMapper(IDBConnection $dbMock) { |
|
23 | - return new GroupMapping($dbMock); |
|
24 | - } |
|
22 | + public function getMapper(IDBConnection $dbMock) { |
|
23 | + return new GroupMapping($dbMock); |
|
24 | + } |
|
25 | 25 | } |
@@ -20,7 +20,7 @@ |
||
20 | 20 | * @package OCA\User_LDAP\Tests\Mapping |
21 | 21 | */ |
22 | 22 | class UserMappingTest extends AbstractMappingTestCase { |
23 | - public function getMapper(IDBConnection $dbMock) { |
|
24 | - return new UserMapping($dbMock, $this->createMock(IAssertion::class)); |
|
25 | - } |
|
23 | + public function getMapper(IDBConnection $dbMock) { |
|
24 | + return new UserMapping($dbMock, $this->createMock(IAssertion::class)); |
|
25 | + } |
|
26 | 26 | } |
@@ -34,851 +34,851 @@ |
||
34 | 34 | * @package OCA\User_LDAP\Tests |
35 | 35 | */ |
36 | 36 | class LDAPProviderTest extends \Test\TestCase { |
37 | - private function getServerMock(IUserLDAP $userBackend, IGroupLDAP $groupBackend) { |
|
38 | - $server = $this->getMockBuilder('OC\Server') |
|
39 | - ->onlyMethods(['getUserManager', 'getGroupManager']) |
|
40 | - ->setConstructorArgs(['', new Config(\OC::$configDir)]) |
|
41 | - ->getMock(); |
|
42 | - $server->expects($this->any()) |
|
43 | - ->method('getUserManager') |
|
44 | - ->willReturn($this->getUserManagerMock($userBackend)); |
|
45 | - $server->expects($this->any()) |
|
46 | - ->method('getGroupManager') |
|
47 | - ->willReturn($this->getGroupManagerMock($groupBackend)); |
|
48 | - |
|
49 | - return $server; |
|
50 | - } |
|
51 | - |
|
52 | - private function getUserManagerMock(IUserLDAP $userBackend) { |
|
53 | - $userManager = $this->getMockBuilder(Manager::class) |
|
54 | - ->onlyMethods(['getBackends']) |
|
55 | - ->setConstructorArgs([ |
|
56 | - $this->createMock(IConfig::class), |
|
57 | - $this->createMock(ICacheFactory::class), |
|
58 | - $this->createMock(IEventDispatcher::class), |
|
59 | - $this->createMock(LoggerInterface::class), |
|
60 | - ]) |
|
61 | - ->getMock(); |
|
62 | - $userManager->expects($this->any()) |
|
63 | - ->method('getBackends') |
|
64 | - ->willReturn([$userBackend]); |
|
65 | - return $userManager; |
|
66 | - } |
|
67 | - |
|
68 | - private function getGroupManagerMock(IGroupLDAP $groupBackend) { |
|
69 | - $groupManager = $this->getMockBuilder('OC\Group\Manager') |
|
70 | - ->onlyMethods(['getBackends']) |
|
71 | - ->disableOriginalConstructor() |
|
72 | - ->getMock(); |
|
73 | - $groupManager->expects($this->any()) |
|
74 | - ->method('getBackends') |
|
75 | - ->willReturn([$groupBackend]); |
|
76 | - return $groupManager; |
|
77 | - } |
|
78 | - |
|
79 | - private function getDefaultGroupBackendMock() { |
|
80 | - $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP') |
|
81 | - ->disableOriginalConstructor() |
|
82 | - ->getMock(); |
|
83 | - |
|
84 | - return $groupBackend; |
|
85 | - } |
|
86 | - |
|
87 | - private function getLDAPProvider(IServerContainer $serverContainer) { |
|
88 | - $factory = new LDAPProviderFactory($serverContainer); |
|
89 | - return $factory->getLDAPProvider(); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - public function testGetUserDNUserIDNotFound(): void { |
|
94 | - $this->expectException(\Exception::class); |
|
95 | - $this->expectExceptionMessage('User id not found in LDAP'); |
|
96 | - |
|
97 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
98 | - ->onlyMethods(['userExists']) |
|
99 | - ->disableOriginalConstructor() |
|
100 | - ->getMock(); |
|
101 | - $userBackend->expects($this->any())->method('userExists')->willReturn(false); |
|
102 | - |
|
103 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
104 | - |
|
105 | - $ldapProvider = $this->getLDAPProvider($server); |
|
106 | - $ldapProvider->getUserDN('nonexisting_user'); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - public function testGetUserDN(): void { |
|
111 | - $userAccess = $this->getMockBuilder(Access::class) |
|
112 | - ->onlyMethods(['username2dn']) |
|
113 | - ->disableOriginalConstructor() |
|
114 | - ->getMock(); |
|
115 | - $userAccess->expects($this->once()) |
|
116 | - ->method('username2dn') |
|
117 | - ->willReturn('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org'); |
|
118 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
119 | - ->onlyMethods(['userExists', 'getLDAPAccess']) |
|
120 | - ->disableOriginalConstructor() |
|
121 | - ->getMock(); |
|
122 | - $userBackend->expects($this->once()) |
|
123 | - ->method('userExists') |
|
124 | - ->willReturn(true); |
|
125 | - $userBackend->expects($this->any()) |
|
126 | - ->method('getLDAPAccess') |
|
127 | - ->willReturn($userAccess); |
|
128 | - |
|
129 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
130 | - |
|
131 | - $ldapProvider = $this->getLDAPProvider($server); |
|
132 | - $this->assertEquals('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org', |
|
133 | - $ldapProvider->getUserDN('existing_user')); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - public function testGetGroupDNGroupIDNotFound(): void { |
|
138 | - $this->expectException(\Exception::class); |
|
139 | - $this->expectExceptionMessage('Group id not found in LDAP'); |
|
140 | - |
|
141 | - $userBackend = $this->createMock(User_LDAP::class); |
|
142 | - $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
143 | - ->onlyMethods(['groupExists']) |
|
144 | - ->disableOriginalConstructor() |
|
145 | - ->getMock(); |
|
146 | - |
|
147 | - $groupBackend->expects($this->any())->method('groupExists')->willReturn(false); |
|
148 | - |
|
149 | - $server = $this->getServerMock($userBackend, $groupBackend); |
|
150 | - |
|
151 | - $ldapProvider = $this->getLDAPProvider($server); |
|
152 | - $ldapProvider->getGroupDN('nonexisting_group'); |
|
153 | - } |
|
154 | - |
|
155 | - public function testGetGroupDN(): void { |
|
156 | - $userBackend = $this->createMock(User_LDAP::class); |
|
157 | - |
|
158 | - $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
159 | - ->onlyMethods(['groupExists', 'getLDAPAccess']) |
|
160 | - ->disableOriginalConstructor() |
|
161 | - ->getMock(); |
|
162 | - |
|
163 | - $groupAccess = $this->createMock(Access::class); |
|
164 | - $groupAccess->expects($this->once()) |
|
165 | - ->method('groupname2dn') |
|
166 | - ->willReturn('cn=existing_group,ou=Are Sufficient To,ou=Test,dc=example,dc=org'); |
|
167 | - $groupBackend->expects($this->once()) |
|
168 | - ->method('groupExists') |
|
169 | - ->willReturn(true); |
|
170 | - $groupBackend->expects($this->any()) |
|
171 | - ->method('getLDAPAccess') |
|
172 | - ->willReturn($groupAccess); |
|
173 | - |
|
174 | - $server = $this->getServerMock($userBackend, $groupBackend); |
|
175 | - |
|
176 | - $ldapProvider = $this->getLDAPProvider($server); |
|
177 | - $this->assertEquals('cn=existing_group,ou=Are Sufficient To,ou=Test,dc=example,dc=org', |
|
178 | - $ldapProvider->getGroupDN('existing_group')); |
|
179 | - } |
|
180 | - |
|
181 | - public function testGetUserName(): void { |
|
182 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
183 | - ->onlyMethods(['dn2UserName']) |
|
184 | - ->disableOriginalConstructor() |
|
185 | - ->getMock(); |
|
186 | - $userBackend->expects($this->any()) |
|
187 | - ->method('dn2UserName') |
|
188 | - ->willReturn('existing_user'); |
|
189 | - |
|
190 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
191 | - |
|
192 | - $ldapProvider = $this->getLDAPProvider($server); |
|
193 | - $this->assertEquals('existing_user', |
|
194 | - $ldapProvider->getUserName('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org')); |
|
195 | - } |
|
196 | - |
|
197 | - public function testDNasBaseParameter(): void { |
|
198 | - $userBackend = $this->createMock(User_LDAP::class); |
|
199 | - |
|
200 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
37 | + private function getServerMock(IUserLDAP $userBackend, IGroupLDAP $groupBackend) { |
|
38 | + $server = $this->getMockBuilder('OC\Server') |
|
39 | + ->onlyMethods(['getUserManager', 'getGroupManager']) |
|
40 | + ->setConstructorArgs(['', new Config(\OC::$configDir)]) |
|
41 | + ->getMock(); |
|
42 | + $server->expects($this->any()) |
|
43 | + ->method('getUserManager') |
|
44 | + ->willReturn($this->getUserManagerMock($userBackend)); |
|
45 | + $server->expects($this->any()) |
|
46 | + ->method('getGroupManager') |
|
47 | + ->willReturn($this->getGroupManagerMock($groupBackend)); |
|
48 | + |
|
49 | + return $server; |
|
50 | + } |
|
51 | + |
|
52 | + private function getUserManagerMock(IUserLDAP $userBackend) { |
|
53 | + $userManager = $this->getMockBuilder(Manager::class) |
|
54 | + ->onlyMethods(['getBackends']) |
|
55 | + ->setConstructorArgs([ |
|
56 | + $this->createMock(IConfig::class), |
|
57 | + $this->createMock(ICacheFactory::class), |
|
58 | + $this->createMock(IEventDispatcher::class), |
|
59 | + $this->createMock(LoggerInterface::class), |
|
60 | + ]) |
|
61 | + ->getMock(); |
|
62 | + $userManager->expects($this->any()) |
|
63 | + ->method('getBackends') |
|
64 | + ->willReturn([$userBackend]); |
|
65 | + return $userManager; |
|
66 | + } |
|
67 | + |
|
68 | + private function getGroupManagerMock(IGroupLDAP $groupBackend) { |
|
69 | + $groupManager = $this->getMockBuilder('OC\Group\Manager') |
|
70 | + ->onlyMethods(['getBackends']) |
|
71 | + ->disableOriginalConstructor() |
|
72 | + ->getMock(); |
|
73 | + $groupManager->expects($this->any()) |
|
74 | + ->method('getBackends') |
|
75 | + ->willReturn([$groupBackend]); |
|
76 | + return $groupManager; |
|
77 | + } |
|
78 | + |
|
79 | + private function getDefaultGroupBackendMock() { |
|
80 | + $groupBackend = $this->getMockBuilder('OCA\User_LDAP\Group_LDAP') |
|
81 | + ->disableOriginalConstructor() |
|
82 | + ->getMock(); |
|
83 | + |
|
84 | + return $groupBackend; |
|
85 | + } |
|
86 | + |
|
87 | + private function getLDAPProvider(IServerContainer $serverContainer) { |
|
88 | + $factory = new LDAPProviderFactory($serverContainer); |
|
89 | + return $factory->getLDAPProvider(); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + public function testGetUserDNUserIDNotFound(): void { |
|
94 | + $this->expectException(\Exception::class); |
|
95 | + $this->expectExceptionMessage('User id not found in LDAP'); |
|
96 | + |
|
97 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
98 | + ->onlyMethods(['userExists']) |
|
99 | + ->disableOriginalConstructor() |
|
100 | + ->getMock(); |
|
101 | + $userBackend->expects($this->any())->method('userExists')->willReturn(false); |
|
102 | + |
|
103 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
104 | + |
|
105 | + $ldapProvider = $this->getLDAPProvider($server); |
|
106 | + $ldapProvider->getUserDN('nonexisting_user'); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + public function testGetUserDN(): void { |
|
111 | + $userAccess = $this->getMockBuilder(Access::class) |
|
112 | + ->onlyMethods(['username2dn']) |
|
113 | + ->disableOriginalConstructor() |
|
114 | + ->getMock(); |
|
115 | + $userAccess->expects($this->once()) |
|
116 | + ->method('username2dn') |
|
117 | + ->willReturn('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org'); |
|
118 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
119 | + ->onlyMethods(['userExists', 'getLDAPAccess']) |
|
120 | + ->disableOriginalConstructor() |
|
121 | + ->getMock(); |
|
122 | + $userBackend->expects($this->once()) |
|
123 | + ->method('userExists') |
|
124 | + ->willReturn(true); |
|
125 | + $userBackend->expects($this->any()) |
|
126 | + ->method('getLDAPAccess') |
|
127 | + ->willReturn($userAccess); |
|
128 | + |
|
129 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
130 | + |
|
131 | + $ldapProvider = $this->getLDAPProvider($server); |
|
132 | + $this->assertEquals('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org', |
|
133 | + $ldapProvider->getUserDN('existing_user')); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + public function testGetGroupDNGroupIDNotFound(): void { |
|
138 | + $this->expectException(\Exception::class); |
|
139 | + $this->expectExceptionMessage('Group id not found in LDAP'); |
|
140 | + |
|
141 | + $userBackend = $this->createMock(User_LDAP::class); |
|
142 | + $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
143 | + ->onlyMethods(['groupExists']) |
|
144 | + ->disableOriginalConstructor() |
|
145 | + ->getMock(); |
|
146 | + |
|
147 | + $groupBackend->expects($this->any())->method('groupExists')->willReturn(false); |
|
148 | + |
|
149 | + $server = $this->getServerMock($userBackend, $groupBackend); |
|
150 | + |
|
151 | + $ldapProvider = $this->getLDAPProvider($server); |
|
152 | + $ldapProvider->getGroupDN('nonexisting_group'); |
|
153 | + } |
|
154 | + |
|
155 | + public function testGetGroupDN(): void { |
|
156 | + $userBackend = $this->createMock(User_LDAP::class); |
|
157 | + |
|
158 | + $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
159 | + ->onlyMethods(['groupExists', 'getLDAPAccess']) |
|
160 | + ->disableOriginalConstructor() |
|
161 | + ->getMock(); |
|
162 | + |
|
163 | + $groupAccess = $this->createMock(Access::class); |
|
164 | + $groupAccess->expects($this->once()) |
|
165 | + ->method('groupname2dn') |
|
166 | + ->willReturn('cn=existing_group,ou=Are Sufficient To,ou=Test,dc=example,dc=org'); |
|
167 | + $groupBackend->expects($this->once()) |
|
168 | + ->method('groupExists') |
|
169 | + ->willReturn(true); |
|
170 | + $groupBackend->expects($this->any()) |
|
171 | + ->method('getLDAPAccess') |
|
172 | + ->willReturn($groupAccess); |
|
173 | + |
|
174 | + $server = $this->getServerMock($userBackend, $groupBackend); |
|
175 | + |
|
176 | + $ldapProvider = $this->getLDAPProvider($server); |
|
177 | + $this->assertEquals('cn=existing_group,ou=Are Sufficient To,ou=Test,dc=example,dc=org', |
|
178 | + $ldapProvider->getGroupDN('existing_group')); |
|
179 | + } |
|
180 | + |
|
181 | + public function testGetUserName(): void { |
|
182 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
183 | + ->onlyMethods(['dn2UserName']) |
|
184 | + ->disableOriginalConstructor() |
|
185 | + ->getMock(); |
|
186 | + $userBackend->expects($this->any()) |
|
187 | + ->method('dn2UserName') |
|
188 | + ->willReturn('existing_user'); |
|
189 | + |
|
190 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
191 | + |
|
192 | + $ldapProvider = $this->getLDAPProvider($server); |
|
193 | + $this->assertEquals('existing_user', |
|
194 | + $ldapProvider->getUserName('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org')); |
|
195 | + } |
|
196 | + |
|
197 | + public function testDNasBaseParameter(): void { |
|
198 | + $userBackend = $this->createMock(User_LDAP::class); |
|
199 | + |
|
200 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
201 | 201 | |
202 | - $helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class)); |
|
203 | - |
|
204 | - $ldapProvider = $this->getLDAPProvider($server); |
|
205 | - $this->assertEquals( |
|
206 | - $helper->DNasBaseParameter('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org'), |
|
207 | - $ldapProvider->DNasBaseParameter('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org')); |
|
208 | - } |
|
209 | - |
|
210 | - public function testSanitizeDN(): void { |
|
211 | - $userBackend = $this->createMock(User_LDAP::class); |
|
212 | - |
|
213 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
214 | - |
|
215 | - $helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class)); |
|
216 | - |
|
217 | - $ldapProvider = $this->getLDAPProvider($server); |
|
218 | - $this->assertEquals( |
|
219 | - $helper->sanitizeDN('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org'), |
|
220 | - $ldapProvider->sanitizeDN('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org')); |
|
221 | - } |
|
202 | + $helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class)); |
|
203 | + |
|
204 | + $ldapProvider = $this->getLDAPProvider($server); |
|
205 | + $this->assertEquals( |
|
206 | + $helper->DNasBaseParameter('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org'), |
|
207 | + $ldapProvider->DNasBaseParameter('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org')); |
|
208 | + } |
|
209 | + |
|
210 | + public function testSanitizeDN(): void { |
|
211 | + $userBackend = $this->createMock(User_LDAP::class); |
|
212 | + |
|
213 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
214 | + |
|
215 | + $helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class)); |
|
216 | + |
|
217 | + $ldapProvider = $this->getLDAPProvider($server); |
|
218 | + $this->assertEquals( |
|
219 | + $helper->sanitizeDN('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org'), |
|
220 | + $ldapProvider->sanitizeDN('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org')); |
|
221 | + } |
|
222 | 222 | |
223 | 223 | |
224 | - public function testGetLDAPConnectionUserIDNotFound(): void { |
|
225 | - $this->expectException(\Exception::class); |
|
226 | - $this->expectExceptionMessage('User id not found in LDAP'); |
|
224 | + public function testGetLDAPConnectionUserIDNotFound(): void { |
|
225 | + $this->expectException(\Exception::class); |
|
226 | + $this->expectExceptionMessage('User id not found in LDAP'); |
|
227 | 227 | |
228 | - $userBackend = $this->createMock(User_LDAP::class); |
|
229 | - $userBackend->expects($this->any())->method('userExists')->willReturn(false); |
|
230 | - |
|
231 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
232 | - |
|
233 | - $ldapProvider = $this->getLDAPProvider($server); |
|
234 | - $ldapProvider->getLDAPConnection('nonexisting_user'); |
|
235 | - } |
|
236 | - |
|
237 | - public function testGetLDAPConnection(): void { |
|
238 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
239 | - ->onlyMethods(['userExists', 'getNewLDAPConnection']) |
|
240 | - ->disableOriginalConstructor() |
|
241 | - ->getMock(); |
|
242 | - $userBackend->expects($this->any()) |
|
243 | - ->method('userExists') |
|
244 | - ->willReturn(true); |
|
245 | - $ldapConnection = ldap_connect('ldap://example.com'); |
|
246 | - $userBackend->expects($this->any()) |
|
247 | - ->method('getNewLDAPConnection') |
|
248 | - ->willReturn($ldapConnection); |
|
249 | - |
|
250 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
251 | - |
|
252 | - $ldapProvider = $this->getLDAPProvider($server); |
|
253 | - $this->assertEquals($ldapConnection, $ldapProvider->getLDAPConnection('existing_user')); |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - public function testGetGroupLDAPConnectionGroupIDNotFound(): void { |
|
258 | - $this->expectException(\Exception::class); |
|
259 | - $this->expectExceptionMessage('Group id not found in LDAP'); |
|
260 | - |
|
261 | - $userBackend = $this->createMock(User_LDAP::class); |
|
262 | - $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
263 | - ->onlyMethods(['groupExists']) |
|
264 | - ->disableOriginalConstructor() |
|
265 | - ->getMock(); |
|
266 | - |
|
267 | - $groupBackend->expects($this->any())->method('groupExists')->willReturn(false); |
|
268 | - |
|
269 | - $server = $this->getServerMock($userBackend, $groupBackend); |
|
270 | - |
|
271 | - $ldapProvider = $this->getLDAPProvider($server); |
|
272 | - $ldapProvider->getGroupLDAPConnection('nonexisting_group'); |
|
273 | - } |
|
274 | - |
|
275 | - public function testGetGroupLDAPConnection(): void { |
|
276 | - $userBackend = $this->createMock(User_LDAP::class); |
|
277 | - $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
278 | - ->onlyMethods(['groupExists','getNewLDAPConnection']) |
|
279 | - ->disableOriginalConstructor() |
|
280 | - ->getMock(); |
|
281 | - |
|
282 | - $groupBackend->expects($this->any()) |
|
283 | - ->method('groupExists') |
|
284 | - ->willReturn(true); |
|
285 | - |
|
286 | - $ldapConnection = ldap_connect('ldap://example.com'); |
|
287 | - $groupBackend->expects($this->any()) |
|
288 | - ->method('getNewLDAPConnection') |
|
289 | - ->willReturn($ldapConnection); |
|
290 | - |
|
291 | - $server = $this->getServerMock($userBackend, $groupBackend); |
|
292 | - |
|
293 | - $ldapProvider = $this->getLDAPProvider($server); |
|
294 | - $this->assertEquals($ldapConnection, $ldapProvider->getGroupLDAPConnection('existing_group')); |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - public function testGetLDAPBaseUsersUserIDNotFound(): void { |
|
299 | - $this->expectException(\Exception::class); |
|
300 | - $this->expectExceptionMessage('User id not found in LDAP'); |
|
301 | - |
|
302 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
303 | - ->onlyMethods(['userExists']) |
|
304 | - ->disableOriginalConstructor() |
|
305 | - ->getMock(); |
|
306 | - $userBackend->expects($this->any())->method('userExists')->willReturn(false); |
|
307 | - |
|
308 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
309 | - |
|
310 | - $ldapProvider = $this->getLDAPProvider($server); |
|
311 | - $ldapProvider->getLDAPBaseUsers('nonexisting_user'); |
|
312 | - } |
|
313 | - |
|
314 | - public function testGetLDAPBaseUsers(): void { |
|
315 | - $bases = [ |
|
316 | - 'ou=users,ou=foobar,dc=example,dc=org', |
|
317 | - 'ou=users,ou=barfoo,dc=example,dc=org', |
|
318 | - ]; |
|
319 | - $dn = 'uid=malik,' . $bases[1]; |
|
320 | - |
|
321 | - $connection = $this->getMockBuilder(Connection::class) |
|
322 | - ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
323 | - ->getMock(); |
|
324 | - $connection->expects($this->any()) |
|
325 | - ->method('__get') |
|
326 | - ->willReturnCallback(function ($key) use ($bases) { |
|
327 | - switch ($key) { |
|
328 | - case 'ldapBaseUsers': |
|
329 | - return $bases; |
|
330 | - } |
|
331 | - return null; |
|
332 | - }); |
|
333 | - |
|
334 | - $access = $this->createMock(Access::class); |
|
335 | - $access->expects($this->any()) |
|
336 | - ->method('getConnection') |
|
337 | - ->willReturn($connection); |
|
338 | - $access->expects($this->exactly(2)) |
|
339 | - ->method('isDNPartOfBase') |
|
340 | - ->willReturnOnConsecutiveCalls(false, true); |
|
341 | - $access->expects($this->atLeastOnce()) |
|
342 | - ->method('username2dn') |
|
343 | - ->willReturn($dn); |
|
344 | - |
|
345 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
346 | - ->onlyMethods(['userExists', 'getLDAPAccess']) |
|
347 | - ->disableOriginalConstructor() |
|
348 | - ->getMock(); |
|
349 | - $userBackend->expects($this->atLeastOnce()) |
|
350 | - ->method('userExists') |
|
351 | - ->willReturn(true); |
|
352 | - $userBackend->expects($this->any()) |
|
353 | - ->method('getLDAPAccess') |
|
354 | - ->willReturn($access); |
|
355 | - |
|
356 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
357 | - |
|
358 | - $ldapProvider = $this->getLDAPProvider($server); |
|
359 | - $this->assertEquals($bases[1], $ldapProvider->getLDAPBaseUsers('existing_user')); |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - public function testGetLDAPBaseGroupsUserIDNotFound(): void { |
|
364 | - $this->expectException(\Exception::class); |
|
365 | - $this->expectExceptionMessage('User id not found in LDAP'); |
|
366 | - |
|
367 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
368 | - ->onlyMethods(['userExists']) |
|
369 | - ->disableOriginalConstructor() |
|
370 | - ->getMock(); |
|
371 | - $userBackend->expects($this->any())->method('userExists')->willReturn(false); |
|
372 | - |
|
373 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
374 | - |
|
375 | - $ldapProvider = $this->getLDAPProvider($server); |
|
376 | - $ldapProvider->getLDAPBaseGroups('nonexisting_user'); |
|
377 | - } |
|
378 | - |
|
379 | - public function testGetLDAPBaseGroups(): void { |
|
380 | - $bases = [ |
|
381 | - 'ou=groupd,ou=foobar,dc=example,dc=org', |
|
382 | - 'ou=groups,ou=barfoo,dc=example,dc=org', |
|
383 | - ]; |
|
384 | - |
|
385 | - $connection = $this->getMockBuilder(Connection::class) |
|
386 | - ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
387 | - ->getMock(); |
|
388 | - $connection->expects($this->any()) |
|
389 | - ->method('__get') |
|
390 | - ->willReturnCallback(function ($key) use ($bases) { |
|
391 | - switch ($key) { |
|
392 | - case 'ldapBaseGroups': |
|
393 | - return $bases; |
|
394 | - } |
|
395 | - return null; |
|
396 | - }); |
|
397 | - |
|
398 | - $access = $this->createMock(Access::class); |
|
399 | - $access->expects($this->any()) |
|
400 | - ->method('getConnection') |
|
401 | - ->willReturn($connection); |
|
402 | - |
|
403 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
404 | - ->onlyMethods(['userExists', 'getLDAPAccess']) |
|
405 | - ->disableOriginalConstructor() |
|
406 | - ->getMock(); |
|
407 | - $userBackend->expects($this->any()) |
|
408 | - ->method('userExists') |
|
409 | - ->willReturn(true); |
|
410 | - $userBackend->expects($this->any()) |
|
411 | - ->method('getLDAPAccess') |
|
412 | - ->willReturn($access); |
|
413 | - |
|
414 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
415 | - |
|
416 | - $ldapProvider = $this->getLDAPProvider($server); |
|
417 | - $this->assertEquals($bases[0], $ldapProvider->getLDAPBaseGroups('existing_user')); |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - public function testClearCacheUserIDNotFound(): void { |
|
422 | - $this->expectException(\Exception::class); |
|
423 | - $this->expectExceptionMessage('User id not found in LDAP'); |
|
424 | - |
|
425 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
426 | - ->onlyMethods(['userExists']) |
|
427 | - ->disableOriginalConstructor() |
|
428 | - ->getMock(); |
|
429 | - $userBackend->expects($this->any())->method('userExists')->willReturn(false); |
|
430 | - |
|
431 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
432 | - |
|
433 | - $ldapProvider = $this->getLDAPProvider($server); |
|
434 | - $ldapProvider->clearCache('nonexisting_user'); |
|
435 | - } |
|
436 | - |
|
437 | - public function testClearCache(): void { |
|
438 | - $connection = $this->getMockBuilder(Connection::class) |
|
439 | - ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
440 | - ->getMock(); |
|
441 | - $connection->expects($this->once()) |
|
442 | - ->method('clearCache') |
|
443 | - ->willReturn(true); |
|
444 | - $access = $this->createMock(Access::class); |
|
445 | - $access->method('getConnection') |
|
446 | - ->willReturn($connection); |
|
447 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
448 | - ->onlyMethods(['userExists', 'getLDAPAccess']) |
|
449 | - ->disableOriginalConstructor() |
|
450 | - ->getMock(); |
|
451 | - $userBackend->expects($this->once()) |
|
452 | - ->method('userExists') |
|
453 | - ->willReturn(true); |
|
454 | - $userBackend->expects($this->any()) |
|
455 | - ->method('getLDAPAccess') |
|
456 | - ->willReturn($access); |
|
457 | - |
|
458 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
459 | - |
|
460 | - $ldapProvider = $this->getLDAPProvider($server); |
|
461 | - $ldapProvider->clearCache('existing_user'); |
|
462 | - $this->addToAssertionCount(1); |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - public function testClearGroupCacheGroupIDNotFound(): void { |
|
467 | - $this->expectException(\Exception::class); |
|
468 | - $this->expectExceptionMessage('Group id not found in LDAP'); |
|
469 | - |
|
470 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
471 | - ->disableOriginalConstructor() |
|
472 | - ->getMock(); |
|
473 | - $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
474 | - ->onlyMethods(['groupExists']) |
|
475 | - ->disableOriginalConstructor() |
|
476 | - ->getMock(); |
|
477 | - $groupBackend->expects($this->any())->method('groupExists')->willReturn(false); |
|
478 | - |
|
479 | - $server = $this->getServerMock($userBackend, $groupBackend); |
|
480 | - |
|
481 | - $ldapProvider = $this->getLDAPProvider($server); |
|
482 | - $ldapProvider->clearGroupCache('nonexisting_group'); |
|
483 | - } |
|
484 | - |
|
485 | - public function testClearGroupCache(): void { |
|
486 | - $userBackend = $this->createMock(User_LDAP::class); |
|
487 | - $connection = $this->getMockBuilder(Connection::class) |
|
488 | - ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
489 | - ->getMock(); |
|
490 | - $connection->expects($this->once()) |
|
491 | - ->method('clearCache') |
|
492 | - ->willReturn(true); |
|
493 | - $access = $this->createMock(Access::class); |
|
494 | - $access->method('getConnection') |
|
495 | - ->willReturn($connection); |
|
496 | - $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
497 | - ->onlyMethods(['groupExists', 'getLDAPAccess']) |
|
498 | - ->disableOriginalConstructor() |
|
499 | - ->getMock(); |
|
500 | - $groupBackend->expects($this->once()) |
|
501 | - ->method('groupExists') |
|
502 | - ->willReturn(true); |
|
503 | - $groupBackend->expects($this->any()) |
|
504 | - ->method('getLDAPAccess') |
|
505 | - ->willReturn($access); |
|
506 | - |
|
507 | - $server = $this->getServerMock($userBackend, $groupBackend); |
|
508 | - |
|
509 | - $ldapProvider = $this->getLDAPProvider($server); |
|
510 | - $ldapProvider->clearGroupCache('existing_group'); |
|
511 | - $this->addToAssertionCount(1); |
|
512 | - } |
|
513 | - |
|
514 | - public function testDnExists(): void { |
|
515 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
516 | - ->onlyMethods(['dn2UserName']) |
|
517 | - ->disableOriginalConstructor() |
|
518 | - ->getMock(); |
|
519 | - $userBackend->expects($this->any()) |
|
520 | - ->method('dn2UserName') |
|
521 | - ->willReturn('existing_user'); |
|
522 | - |
|
523 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
524 | - |
|
525 | - $ldapProvider = $this->getLDAPProvider($server); |
|
526 | - $this->assertTrue($ldapProvider->dnExists('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org')); |
|
527 | - } |
|
528 | - |
|
529 | - public function testFlagRecord(): void { |
|
530 | - $userBackend = $this->createMock(User_LDAP::class); |
|
531 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
532 | - |
|
533 | - $ldapProvider = $this->getLDAPProvider($server); |
|
534 | - $ldapProvider->flagRecord('existing_user'); |
|
535 | - $this->addToAssertionCount(1); |
|
536 | - } |
|
537 | - |
|
538 | - public function testUnflagRecord(): void { |
|
539 | - $userBackend = $this->createMock(User_LDAP::class); |
|
540 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
541 | - |
|
542 | - $ldapProvider = $this->getLDAPProvider($server); |
|
543 | - $ldapProvider->unflagRecord('existing_user'); |
|
544 | - $this->addToAssertionCount(1); |
|
545 | - } |
|
546 | - |
|
547 | - |
|
548 | - public function testGetLDAPDisplayNameFieldUserIDNotFound(): void { |
|
549 | - $this->expectException(\Exception::class); |
|
550 | - $this->expectExceptionMessage('User id not found in LDAP'); |
|
551 | - |
|
552 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
553 | - ->onlyMethods(['userExists']) |
|
554 | - ->disableOriginalConstructor() |
|
555 | - ->getMock(); |
|
556 | - $userBackend->expects($this->any())->method('userExists')->willReturn(false); |
|
557 | - |
|
558 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
559 | - |
|
560 | - $ldapProvider = $this->getLDAPProvider($server); |
|
561 | - $ldapProvider->getLDAPDisplayNameField('nonexisting_user'); |
|
562 | - } |
|
563 | - |
|
564 | - public function testGetLDAPDisplayNameField(): void { |
|
565 | - $connection = $this->getMockBuilder(Connection::class) |
|
566 | - ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
567 | - ->getMock(); |
|
568 | - $connection->expects($this->once()) |
|
569 | - ->method('getConfiguration') |
|
570 | - ->willReturn(['ldap_display_name' => 'displayName']); |
|
571 | - $access = $this->createMock(Access::class); |
|
572 | - $access->method('getConnection') |
|
573 | - ->willReturn($connection); |
|
574 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
575 | - ->onlyMethods(['userExists', 'getLDAPAccess']) |
|
576 | - ->disableOriginalConstructor() |
|
577 | - ->getMock(); |
|
578 | - $userBackend->expects($this->once()) |
|
579 | - ->method('userExists') |
|
580 | - ->willReturn(true); |
|
581 | - $userBackend->expects($this->any()) |
|
582 | - ->method('getLDAPAccess') |
|
583 | - ->willReturn($access); |
|
584 | - |
|
585 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
586 | - |
|
587 | - $ldapProvider = $this->getLDAPProvider($server); |
|
588 | - $this->assertEquals('displayName', $ldapProvider->getLDAPDisplayNameField('existing_user')); |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - public function testGetLDAPEmailFieldUserIDNotFound(): void { |
|
593 | - $this->expectException(\Exception::class); |
|
594 | - $this->expectExceptionMessage('User id not found in LDAP'); |
|
595 | - |
|
596 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
597 | - ->onlyMethods(['userExists']) |
|
598 | - ->disableOriginalConstructor() |
|
599 | - ->getMock(); |
|
600 | - $userBackend->expects($this->any())->method('userExists')->willReturn(false); |
|
601 | - |
|
602 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
603 | - |
|
604 | - $ldapProvider = $this->getLDAPProvider($server); |
|
605 | - $ldapProvider->getLDAPEmailField('nonexisting_user'); |
|
606 | - } |
|
607 | - |
|
608 | - public function testGetLDAPEmailField(): void { |
|
609 | - $connection = $this->getMockBuilder(Connection::class) |
|
610 | - ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
611 | - ->getMock(); |
|
612 | - $connection->expects($this->once()) |
|
613 | - ->method('getConfiguration') |
|
614 | - ->willReturn(['ldap_email_attr' => 'mail']); |
|
615 | - $access = $this->createMock(Access::class); |
|
616 | - $access->method('getConnection') |
|
617 | - ->willReturn($connection); |
|
618 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
619 | - ->onlyMethods(['userExists', 'getLDAPAccess']) |
|
620 | - ->disableOriginalConstructor() |
|
621 | - ->getMock(); |
|
622 | - $userBackend->expects($this->once()) |
|
623 | - ->method('userExists') |
|
624 | - ->willReturn(true); |
|
625 | - $userBackend->expects($this->any()) |
|
626 | - ->method('getLDAPAccess') |
|
627 | - ->willReturn($access); |
|
628 | - |
|
629 | - $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
630 | - |
|
631 | - $ldapProvider = $this->getLDAPProvider($server); |
|
632 | - $this->assertEquals('mail', $ldapProvider->getLDAPEmailField('existing_user')); |
|
633 | - } |
|
634 | - |
|
635 | - |
|
636 | - public function testGetLDAPGroupMemberAssocUserIDNotFound(): void { |
|
637 | - $this->expectException(\Exception::class); |
|
638 | - $this->expectExceptionMessage('Group id not found in LDAP'); |
|
639 | - |
|
640 | - $userBackend = $this->createMock(User_LDAP::class); |
|
641 | - $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
642 | - ->onlyMethods(['groupExists']) |
|
643 | - ->disableOriginalConstructor() |
|
644 | - ->getMock(); |
|
645 | - |
|
646 | - $groupBackend->expects($this->any()) |
|
647 | - ->method('groupExists') |
|
648 | - ->willReturn(false); |
|
649 | - |
|
650 | - $server = $this->getServerMock($userBackend, $groupBackend); |
|
651 | - |
|
652 | - $ldapProvider = $this->getLDAPProvider($server); |
|
653 | - $ldapProvider->getLDAPGroupMemberAssoc('nonexisting_group'); |
|
654 | - } |
|
655 | - |
|
656 | - public function testgetLDAPGroupMemberAssoc(): void { |
|
657 | - $userBackend = $this->createMock(User_LDAP::class); |
|
658 | - |
|
659 | - $connection = $this->getMockBuilder(Connection::class) |
|
660 | - ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
661 | - ->getMock(); |
|
662 | - $connection->expects($this->once()) |
|
663 | - ->method('getConfiguration') |
|
664 | - ->willReturn(['ldap_group_member_assoc_attribute' => 'assoc_type']); |
|
665 | - $access = $this->createMock(Access::class); |
|
666 | - $access->method('getConnection') |
|
667 | - ->willReturn($connection); |
|
668 | - $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
669 | - ->onlyMethods(['groupExists', 'getLDAPAccess']) |
|
670 | - ->disableOriginalConstructor() |
|
671 | - ->getMock(); |
|
672 | - |
|
673 | - $groupBackend->expects($this->once()) |
|
674 | - ->method('groupExists') |
|
675 | - ->willReturn(true); |
|
676 | - $groupBackend->expects($this->any()) |
|
677 | - ->method('getLDAPAccess') |
|
678 | - ->willReturn($access); |
|
679 | - |
|
680 | - $server = $this->getServerMock($userBackend, $groupBackend); |
|
681 | - |
|
682 | - $ldapProvider = $this->getLDAPProvider($server); |
|
683 | - $this->assertEquals('assoc_type', $ldapProvider->getLDAPGroupMemberAssoc('existing_group')); |
|
684 | - } |
|
685 | - |
|
686 | - public function testGetMultiValueUserAttributeUserNotFound(): void { |
|
687 | - $this->expectException(\Exception::class); |
|
688 | - $this->expectExceptionMessage('User id not found in LDAP'); |
|
689 | - |
|
690 | - $userBackend = $this->createMock(User_LDAP::class); |
|
691 | - $userBackend->expects(self::once()) |
|
692 | - ->method('userExists') |
|
693 | - ->with('admin') |
|
694 | - ->willReturn(false); |
|
695 | - $groupBackend = $this->createMock(Group_LDAP::class); |
|
696 | - $server = $this->getServerMock($userBackend, $groupBackend); |
|
697 | - |
|
698 | - $ldapProvider = $this->getLDAPProvider($server); |
|
699 | - $ldapProvider->getMultiValueUserAttribute('admin', 'mailAlias'); |
|
700 | - } |
|
701 | - |
|
702 | - public function testGetMultiValueUserAttributeCacheHit(): void { |
|
703 | - $connection = $this->getMockBuilder(Connection::class) |
|
704 | - ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
705 | - ->getMock(); |
|
706 | - $connection->expects(self::once()) |
|
707 | - ->method('getFromCache') |
|
708 | - ->with('admin-mailAlias') |
|
709 | - ->willReturn(['[email protected]', '[email protected]']); |
|
710 | - $access = $this->createMock(Access::class); |
|
711 | - $access->expects(self::once()) |
|
712 | - ->method('getConnection') |
|
713 | - ->willReturn($connection); |
|
714 | - $userBackend = $this->createMock(User_LDAP::class); |
|
715 | - $userBackend->expects(self::once()) |
|
716 | - ->method('userExists') |
|
717 | - ->with('admin') |
|
718 | - ->willReturn(true); |
|
719 | - $userBackend->expects(self::once()) |
|
720 | - ->method('getLDAPAccess') |
|
721 | - ->willReturn($access); |
|
722 | - $groupBackend = $this->createMock(Group_LDAP::class); |
|
723 | - $server = $this->getServerMock($userBackend, $groupBackend); |
|
724 | - |
|
725 | - $ldapProvider = $this->getLDAPProvider($server); |
|
726 | - $ldapProvider->getMultiValueUserAttribute('admin', 'mailAlias'); |
|
727 | - } |
|
728 | - |
|
729 | - public function testGetMultiValueUserAttributeLdapError(): void { |
|
730 | - $connection = $this->getMockBuilder(Connection::class) |
|
731 | - ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
732 | - ->getMock(); |
|
733 | - $connection->expects(self::once()) |
|
734 | - ->method('getFromCache') |
|
735 | - ->with('admin-mailAlias') |
|
736 | - ->willReturn(null); |
|
737 | - $access = $this->createMock(Access::class); |
|
738 | - $access->expects(self::once()) |
|
739 | - ->method('getConnection') |
|
740 | - ->willReturn($connection); |
|
741 | - $access->expects(self::once()) |
|
742 | - ->method('username2dn') |
|
743 | - ->with('admin') |
|
744 | - ->willReturn('admin'); |
|
745 | - $access->expects(self::once()) |
|
746 | - ->method('readAttribute') |
|
747 | - ->with('admin', 'mailAlias') |
|
748 | - ->willReturn(false); |
|
749 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
750 | - ->disableOriginalConstructor() |
|
751 | - ->getMock(); |
|
752 | - $userBackend->method('userExists') |
|
753 | - ->with('admin') |
|
754 | - ->willReturn(true); |
|
755 | - $userBackend->method('getLDAPAccess') |
|
756 | - ->willReturn($access); |
|
757 | - $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
758 | - ->disableOriginalConstructor() |
|
759 | - ->getMock(); |
|
760 | - $server = $this->getServerMock($userBackend, $groupBackend); |
|
761 | - |
|
762 | - $ldapProvider = $this->getLDAPProvider($server); |
|
763 | - $values = $ldapProvider->getMultiValueUserAttribute('admin', 'mailAlias'); |
|
764 | - |
|
765 | - self::assertCount(0, $values); |
|
766 | - } |
|
767 | - |
|
768 | - public function testGetMultiValueUserAttribute(): void { |
|
769 | - $connection = $this->getMockBuilder(Connection::class) |
|
770 | - ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
771 | - ->getMock(); |
|
772 | - $connection->expects(self::once()) |
|
773 | - ->method('getFromCache') |
|
774 | - ->with('admin-mailAlias') |
|
775 | - ->willReturn(null); |
|
776 | - $access = $this->createMock(Access::class); |
|
777 | - $access->expects(self::once()) |
|
778 | - ->method('getConnection') |
|
779 | - ->willReturn($connection); |
|
780 | - $access->expects(self::once()) |
|
781 | - ->method('username2dn') |
|
782 | - ->with('admin') |
|
783 | - ->willReturn('admin'); |
|
784 | - $access->expects(self::once()) |
|
785 | - ->method('readAttribute') |
|
786 | - ->with('admin', 'mailAlias') |
|
787 | - ->willReturn(['[email protected]', '[email protected]']); |
|
788 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
789 | - ->disableOriginalConstructor() |
|
790 | - ->getMock(); |
|
791 | - $userBackend->method('userExists') |
|
792 | - ->with('admin') |
|
793 | - ->willReturn(true); |
|
794 | - $userBackend->method('getLDAPAccess') |
|
795 | - ->willReturn($access); |
|
796 | - $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
797 | - ->disableOriginalConstructor() |
|
798 | - ->getMock(); |
|
799 | - $server = $this->getServerMock($userBackend, $groupBackend); |
|
800 | - |
|
801 | - $ldapProvider = $this->getLDAPProvider($server); |
|
802 | - $values = $ldapProvider->getMultiValueUserAttribute('admin', 'mailAlias'); |
|
803 | - |
|
804 | - self::assertCount(2, $values); |
|
805 | - } |
|
806 | - |
|
807 | - public function testGetUserAttributeLdapError(): void { |
|
808 | - $connection = $this->getMockBuilder(Connection::class) |
|
809 | - ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
810 | - ->getMock(); |
|
811 | - $connection->expects(self::once()) |
|
812 | - ->method('getFromCache') |
|
813 | - ->with('admin-mailAlias') |
|
814 | - ->willReturn(null); |
|
815 | - $access = $this->createMock(Access::class); |
|
816 | - $access->expects(self::once()) |
|
817 | - ->method('getConnection') |
|
818 | - ->willReturn($connection); |
|
819 | - $access->expects(self::once()) |
|
820 | - ->method('username2dn') |
|
821 | - ->with('admin') |
|
822 | - ->willReturn('admin'); |
|
823 | - $access->expects(self::once()) |
|
824 | - ->method('readAttribute') |
|
825 | - ->with('admin', 'mailAlias') |
|
826 | - ->willReturn(false); |
|
827 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
828 | - ->disableOriginalConstructor() |
|
829 | - ->getMock(); |
|
830 | - $userBackend->method('userExists') |
|
831 | - ->with('admin') |
|
832 | - ->willReturn(true); |
|
833 | - $userBackend->method('getLDAPAccess') |
|
834 | - ->willReturn($access); |
|
835 | - $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
836 | - ->disableOriginalConstructor() |
|
837 | - ->getMock(); |
|
838 | - $server = $this->getServerMock($userBackend, $groupBackend); |
|
839 | - |
|
840 | - $ldapProvider = $this->getLDAPProvider($server); |
|
841 | - $value = $ldapProvider->getUserAttribute('admin', 'mailAlias'); |
|
842 | - |
|
843 | - self::assertNull($value); |
|
844 | - } |
|
845 | - |
|
846 | - public function testGetUserAttribute(): void { |
|
847 | - $connection = $this->getMockBuilder(Connection::class) |
|
848 | - ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
849 | - ->getMock(); |
|
850 | - $connection->expects(self::once()) |
|
851 | - ->method('getFromCache') |
|
852 | - ->with('admin-mailAlias') |
|
853 | - ->willReturn(null); |
|
854 | - $access = $this->createMock(Access::class); |
|
855 | - $access->expects(self::once()) |
|
856 | - ->method('getConnection') |
|
857 | - ->willReturn($connection); |
|
858 | - $access->expects(self::once()) |
|
859 | - ->method('username2dn') |
|
860 | - ->with('admin') |
|
861 | - ->willReturn('admin'); |
|
862 | - $access->expects(self::once()) |
|
863 | - ->method('readAttribute') |
|
864 | - ->with('admin', 'mailAlias') |
|
865 | - ->willReturn(['[email protected]', '[email protected]']); |
|
866 | - $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
867 | - ->disableOriginalConstructor() |
|
868 | - ->getMock(); |
|
869 | - $userBackend->method('userExists') |
|
870 | - ->with('admin') |
|
871 | - ->willReturn(true); |
|
872 | - $userBackend->method('getLDAPAccess') |
|
873 | - ->willReturn($access); |
|
874 | - $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
875 | - ->disableOriginalConstructor() |
|
876 | - ->getMock(); |
|
877 | - $server = $this->getServerMock($userBackend, $groupBackend); |
|
878 | - |
|
879 | - $ldapProvider = $this->getLDAPProvider($server); |
|
880 | - $value = $ldapProvider->getUserAttribute('admin', 'mailAlias'); |
|
881 | - |
|
882 | - self::assertEquals('[email protected]', $value); |
|
883 | - } |
|
228 | + $userBackend = $this->createMock(User_LDAP::class); |
|
229 | + $userBackend->expects($this->any())->method('userExists')->willReturn(false); |
|
230 | + |
|
231 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
232 | + |
|
233 | + $ldapProvider = $this->getLDAPProvider($server); |
|
234 | + $ldapProvider->getLDAPConnection('nonexisting_user'); |
|
235 | + } |
|
236 | + |
|
237 | + public function testGetLDAPConnection(): void { |
|
238 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
239 | + ->onlyMethods(['userExists', 'getNewLDAPConnection']) |
|
240 | + ->disableOriginalConstructor() |
|
241 | + ->getMock(); |
|
242 | + $userBackend->expects($this->any()) |
|
243 | + ->method('userExists') |
|
244 | + ->willReturn(true); |
|
245 | + $ldapConnection = ldap_connect('ldap://example.com'); |
|
246 | + $userBackend->expects($this->any()) |
|
247 | + ->method('getNewLDAPConnection') |
|
248 | + ->willReturn($ldapConnection); |
|
249 | + |
|
250 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
251 | + |
|
252 | + $ldapProvider = $this->getLDAPProvider($server); |
|
253 | + $this->assertEquals($ldapConnection, $ldapProvider->getLDAPConnection('existing_user')); |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + public function testGetGroupLDAPConnectionGroupIDNotFound(): void { |
|
258 | + $this->expectException(\Exception::class); |
|
259 | + $this->expectExceptionMessage('Group id not found in LDAP'); |
|
260 | + |
|
261 | + $userBackend = $this->createMock(User_LDAP::class); |
|
262 | + $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
263 | + ->onlyMethods(['groupExists']) |
|
264 | + ->disableOriginalConstructor() |
|
265 | + ->getMock(); |
|
266 | + |
|
267 | + $groupBackend->expects($this->any())->method('groupExists')->willReturn(false); |
|
268 | + |
|
269 | + $server = $this->getServerMock($userBackend, $groupBackend); |
|
270 | + |
|
271 | + $ldapProvider = $this->getLDAPProvider($server); |
|
272 | + $ldapProvider->getGroupLDAPConnection('nonexisting_group'); |
|
273 | + } |
|
274 | + |
|
275 | + public function testGetGroupLDAPConnection(): void { |
|
276 | + $userBackend = $this->createMock(User_LDAP::class); |
|
277 | + $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
278 | + ->onlyMethods(['groupExists','getNewLDAPConnection']) |
|
279 | + ->disableOriginalConstructor() |
|
280 | + ->getMock(); |
|
281 | + |
|
282 | + $groupBackend->expects($this->any()) |
|
283 | + ->method('groupExists') |
|
284 | + ->willReturn(true); |
|
285 | + |
|
286 | + $ldapConnection = ldap_connect('ldap://example.com'); |
|
287 | + $groupBackend->expects($this->any()) |
|
288 | + ->method('getNewLDAPConnection') |
|
289 | + ->willReturn($ldapConnection); |
|
290 | + |
|
291 | + $server = $this->getServerMock($userBackend, $groupBackend); |
|
292 | + |
|
293 | + $ldapProvider = $this->getLDAPProvider($server); |
|
294 | + $this->assertEquals($ldapConnection, $ldapProvider->getGroupLDAPConnection('existing_group')); |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + public function testGetLDAPBaseUsersUserIDNotFound(): void { |
|
299 | + $this->expectException(\Exception::class); |
|
300 | + $this->expectExceptionMessage('User id not found in LDAP'); |
|
301 | + |
|
302 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
303 | + ->onlyMethods(['userExists']) |
|
304 | + ->disableOriginalConstructor() |
|
305 | + ->getMock(); |
|
306 | + $userBackend->expects($this->any())->method('userExists')->willReturn(false); |
|
307 | + |
|
308 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
309 | + |
|
310 | + $ldapProvider = $this->getLDAPProvider($server); |
|
311 | + $ldapProvider->getLDAPBaseUsers('nonexisting_user'); |
|
312 | + } |
|
313 | + |
|
314 | + public function testGetLDAPBaseUsers(): void { |
|
315 | + $bases = [ |
|
316 | + 'ou=users,ou=foobar,dc=example,dc=org', |
|
317 | + 'ou=users,ou=barfoo,dc=example,dc=org', |
|
318 | + ]; |
|
319 | + $dn = 'uid=malik,' . $bases[1]; |
|
320 | + |
|
321 | + $connection = $this->getMockBuilder(Connection::class) |
|
322 | + ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
323 | + ->getMock(); |
|
324 | + $connection->expects($this->any()) |
|
325 | + ->method('__get') |
|
326 | + ->willReturnCallback(function ($key) use ($bases) { |
|
327 | + switch ($key) { |
|
328 | + case 'ldapBaseUsers': |
|
329 | + return $bases; |
|
330 | + } |
|
331 | + return null; |
|
332 | + }); |
|
333 | + |
|
334 | + $access = $this->createMock(Access::class); |
|
335 | + $access->expects($this->any()) |
|
336 | + ->method('getConnection') |
|
337 | + ->willReturn($connection); |
|
338 | + $access->expects($this->exactly(2)) |
|
339 | + ->method('isDNPartOfBase') |
|
340 | + ->willReturnOnConsecutiveCalls(false, true); |
|
341 | + $access->expects($this->atLeastOnce()) |
|
342 | + ->method('username2dn') |
|
343 | + ->willReturn($dn); |
|
344 | + |
|
345 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
346 | + ->onlyMethods(['userExists', 'getLDAPAccess']) |
|
347 | + ->disableOriginalConstructor() |
|
348 | + ->getMock(); |
|
349 | + $userBackend->expects($this->atLeastOnce()) |
|
350 | + ->method('userExists') |
|
351 | + ->willReturn(true); |
|
352 | + $userBackend->expects($this->any()) |
|
353 | + ->method('getLDAPAccess') |
|
354 | + ->willReturn($access); |
|
355 | + |
|
356 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
357 | + |
|
358 | + $ldapProvider = $this->getLDAPProvider($server); |
|
359 | + $this->assertEquals($bases[1], $ldapProvider->getLDAPBaseUsers('existing_user')); |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + public function testGetLDAPBaseGroupsUserIDNotFound(): void { |
|
364 | + $this->expectException(\Exception::class); |
|
365 | + $this->expectExceptionMessage('User id not found in LDAP'); |
|
366 | + |
|
367 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
368 | + ->onlyMethods(['userExists']) |
|
369 | + ->disableOriginalConstructor() |
|
370 | + ->getMock(); |
|
371 | + $userBackend->expects($this->any())->method('userExists')->willReturn(false); |
|
372 | + |
|
373 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
374 | + |
|
375 | + $ldapProvider = $this->getLDAPProvider($server); |
|
376 | + $ldapProvider->getLDAPBaseGroups('nonexisting_user'); |
|
377 | + } |
|
378 | + |
|
379 | + public function testGetLDAPBaseGroups(): void { |
|
380 | + $bases = [ |
|
381 | + 'ou=groupd,ou=foobar,dc=example,dc=org', |
|
382 | + 'ou=groups,ou=barfoo,dc=example,dc=org', |
|
383 | + ]; |
|
384 | + |
|
385 | + $connection = $this->getMockBuilder(Connection::class) |
|
386 | + ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
387 | + ->getMock(); |
|
388 | + $connection->expects($this->any()) |
|
389 | + ->method('__get') |
|
390 | + ->willReturnCallback(function ($key) use ($bases) { |
|
391 | + switch ($key) { |
|
392 | + case 'ldapBaseGroups': |
|
393 | + return $bases; |
|
394 | + } |
|
395 | + return null; |
|
396 | + }); |
|
397 | + |
|
398 | + $access = $this->createMock(Access::class); |
|
399 | + $access->expects($this->any()) |
|
400 | + ->method('getConnection') |
|
401 | + ->willReturn($connection); |
|
402 | + |
|
403 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
404 | + ->onlyMethods(['userExists', 'getLDAPAccess']) |
|
405 | + ->disableOriginalConstructor() |
|
406 | + ->getMock(); |
|
407 | + $userBackend->expects($this->any()) |
|
408 | + ->method('userExists') |
|
409 | + ->willReturn(true); |
|
410 | + $userBackend->expects($this->any()) |
|
411 | + ->method('getLDAPAccess') |
|
412 | + ->willReturn($access); |
|
413 | + |
|
414 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
415 | + |
|
416 | + $ldapProvider = $this->getLDAPProvider($server); |
|
417 | + $this->assertEquals($bases[0], $ldapProvider->getLDAPBaseGroups('existing_user')); |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + public function testClearCacheUserIDNotFound(): void { |
|
422 | + $this->expectException(\Exception::class); |
|
423 | + $this->expectExceptionMessage('User id not found in LDAP'); |
|
424 | + |
|
425 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
426 | + ->onlyMethods(['userExists']) |
|
427 | + ->disableOriginalConstructor() |
|
428 | + ->getMock(); |
|
429 | + $userBackend->expects($this->any())->method('userExists')->willReturn(false); |
|
430 | + |
|
431 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
432 | + |
|
433 | + $ldapProvider = $this->getLDAPProvider($server); |
|
434 | + $ldapProvider->clearCache('nonexisting_user'); |
|
435 | + } |
|
436 | + |
|
437 | + public function testClearCache(): void { |
|
438 | + $connection = $this->getMockBuilder(Connection::class) |
|
439 | + ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
440 | + ->getMock(); |
|
441 | + $connection->expects($this->once()) |
|
442 | + ->method('clearCache') |
|
443 | + ->willReturn(true); |
|
444 | + $access = $this->createMock(Access::class); |
|
445 | + $access->method('getConnection') |
|
446 | + ->willReturn($connection); |
|
447 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
448 | + ->onlyMethods(['userExists', 'getLDAPAccess']) |
|
449 | + ->disableOriginalConstructor() |
|
450 | + ->getMock(); |
|
451 | + $userBackend->expects($this->once()) |
|
452 | + ->method('userExists') |
|
453 | + ->willReturn(true); |
|
454 | + $userBackend->expects($this->any()) |
|
455 | + ->method('getLDAPAccess') |
|
456 | + ->willReturn($access); |
|
457 | + |
|
458 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
459 | + |
|
460 | + $ldapProvider = $this->getLDAPProvider($server); |
|
461 | + $ldapProvider->clearCache('existing_user'); |
|
462 | + $this->addToAssertionCount(1); |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + public function testClearGroupCacheGroupIDNotFound(): void { |
|
467 | + $this->expectException(\Exception::class); |
|
468 | + $this->expectExceptionMessage('Group id not found in LDAP'); |
|
469 | + |
|
470 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
471 | + ->disableOriginalConstructor() |
|
472 | + ->getMock(); |
|
473 | + $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
474 | + ->onlyMethods(['groupExists']) |
|
475 | + ->disableOriginalConstructor() |
|
476 | + ->getMock(); |
|
477 | + $groupBackend->expects($this->any())->method('groupExists')->willReturn(false); |
|
478 | + |
|
479 | + $server = $this->getServerMock($userBackend, $groupBackend); |
|
480 | + |
|
481 | + $ldapProvider = $this->getLDAPProvider($server); |
|
482 | + $ldapProvider->clearGroupCache('nonexisting_group'); |
|
483 | + } |
|
484 | + |
|
485 | + public function testClearGroupCache(): void { |
|
486 | + $userBackend = $this->createMock(User_LDAP::class); |
|
487 | + $connection = $this->getMockBuilder(Connection::class) |
|
488 | + ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
489 | + ->getMock(); |
|
490 | + $connection->expects($this->once()) |
|
491 | + ->method('clearCache') |
|
492 | + ->willReturn(true); |
|
493 | + $access = $this->createMock(Access::class); |
|
494 | + $access->method('getConnection') |
|
495 | + ->willReturn($connection); |
|
496 | + $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
497 | + ->onlyMethods(['groupExists', 'getLDAPAccess']) |
|
498 | + ->disableOriginalConstructor() |
|
499 | + ->getMock(); |
|
500 | + $groupBackend->expects($this->once()) |
|
501 | + ->method('groupExists') |
|
502 | + ->willReturn(true); |
|
503 | + $groupBackend->expects($this->any()) |
|
504 | + ->method('getLDAPAccess') |
|
505 | + ->willReturn($access); |
|
506 | + |
|
507 | + $server = $this->getServerMock($userBackend, $groupBackend); |
|
508 | + |
|
509 | + $ldapProvider = $this->getLDAPProvider($server); |
|
510 | + $ldapProvider->clearGroupCache('existing_group'); |
|
511 | + $this->addToAssertionCount(1); |
|
512 | + } |
|
513 | + |
|
514 | + public function testDnExists(): void { |
|
515 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
516 | + ->onlyMethods(['dn2UserName']) |
|
517 | + ->disableOriginalConstructor() |
|
518 | + ->getMock(); |
|
519 | + $userBackend->expects($this->any()) |
|
520 | + ->method('dn2UserName') |
|
521 | + ->willReturn('existing_user'); |
|
522 | + |
|
523 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
524 | + |
|
525 | + $ldapProvider = $this->getLDAPProvider($server); |
|
526 | + $this->assertTrue($ldapProvider->dnExists('cn=existing_user,ou=Are Sufficient To,ou=Test,dc=example,dc=org')); |
|
527 | + } |
|
528 | + |
|
529 | + public function testFlagRecord(): void { |
|
530 | + $userBackend = $this->createMock(User_LDAP::class); |
|
531 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
532 | + |
|
533 | + $ldapProvider = $this->getLDAPProvider($server); |
|
534 | + $ldapProvider->flagRecord('existing_user'); |
|
535 | + $this->addToAssertionCount(1); |
|
536 | + } |
|
537 | + |
|
538 | + public function testUnflagRecord(): void { |
|
539 | + $userBackend = $this->createMock(User_LDAP::class); |
|
540 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
541 | + |
|
542 | + $ldapProvider = $this->getLDAPProvider($server); |
|
543 | + $ldapProvider->unflagRecord('existing_user'); |
|
544 | + $this->addToAssertionCount(1); |
|
545 | + } |
|
546 | + |
|
547 | + |
|
548 | + public function testGetLDAPDisplayNameFieldUserIDNotFound(): void { |
|
549 | + $this->expectException(\Exception::class); |
|
550 | + $this->expectExceptionMessage('User id not found in LDAP'); |
|
551 | + |
|
552 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
553 | + ->onlyMethods(['userExists']) |
|
554 | + ->disableOriginalConstructor() |
|
555 | + ->getMock(); |
|
556 | + $userBackend->expects($this->any())->method('userExists')->willReturn(false); |
|
557 | + |
|
558 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
559 | + |
|
560 | + $ldapProvider = $this->getLDAPProvider($server); |
|
561 | + $ldapProvider->getLDAPDisplayNameField('nonexisting_user'); |
|
562 | + } |
|
563 | + |
|
564 | + public function testGetLDAPDisplayNameField(): void { |
|
565 | + $connection = $this->getMockBuilder(Connection::class) |
|
566 | + ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
567 | + ->getMock(); |
|
568 | + $connection->expects($this->once()) |
|
569 | + ->method('getConfiguration') |
|
570 | + ->willReturn(['ldap_display_name' => 'displayName']); |
|
571 | + $access = $this->createMock(Access::class); |
|
572 | + $access->method('getConnection') |
|
573 | + ->willReturn($connection); |
|
574 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
575 | + ->onlyMethods(['userExists', 'getLDAPAccess']) |
|
576 | + ->disableOriginalConstructor() |
|
577 | + ->getMock(); |
|
578 | + $userBackend->expects($this->once()) |
|
579 | + ->method('userExists') |
|
580 | + ->willReturn(true); |
|
581 | + $userBackend->expects($this->any()) |
|
582 | + ->method('getLDAPAccess') |
|
583 | + ->willReturn($access); |
|
584 | + |
|
585 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
586 | + |
|
587 | + $ldapProvider = $this->getLDAPProvider($server); |
|
588 | + $this->assertEquals('displayName', $ldapProvider->getLDAPDisplayNameField('existing_user')); |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + public function testGetLDAPEmailFieldUserIDNotFound(): void { |
|
593 | + $this->expectException(\Exception::class); |
|
594 | + $this->expectExceptionMessage('User id not found in LDAP'); |
|
595 | + |
|
596 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
597 | + ->onlyMethods(['userExists']) |
|
598 | + ->disableOriginalConstructor() |
|
599 | + ->getMock(); |
|
600 | + $userBackend->expects($this->any())->method('userExists')->willReturn(false); |
|
601 | + |
|
602 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
603 | + |
|
604 | + $ldapProvider = $this->getLDAPProvider($server); |
|
605 | + $ldapProvider->getLDAPEmailField('nonexisting_user'); |
|
606 | + } |
|
607 | + |
|
608 | + public function testGetLDAPEmailField(): void { |
|
609 | + $connection = $this->getMockBuilder(Connection::class) |
|
610 | + ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
611 | + ->getMock(); |
|
612 | + $connection->expects($this->once()) |
|
613 | + ->method('getConfiguration') |
|
614 | + ->willReturn(['ldap_email_attr' => 'mail']); |
|
615 | + $access = $this->createMock(Access::class); |
|
616 | + $access->method('getConnection') |
|
617 | + ->willReturn($connection); |
|
618 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
619 | + ->onlyMethods(['userExists', 'getLDAPAccess']) |
|
620 | + ->disableOriginalConstructor() |
|
621 | + ->getMock(); |
|
622 | + $userBackend->expects($this->once()) |
|
623 | + ->method('userExists') |
|
624 | + ->willReturn(true); |
|
625 | + $userBackend->expects($this->any()) |
|
626 | + ->method('getLDAPAccess') |
|
627 | + ->willReturn($access); |
|
628 | + |
|
629 | + $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); |
|
630 | + |
|
631 | + $ldapProvider = $this->getLDAPProvider($server); |
|
632 | + $this->assertEquals('mail', $ldapProvider->getLDAPEmailField('existing_user')); |
|
633 | + } |
|
634 | + |
|
635 | + |
|
636 | + public function testGetLDAPGroupMemberAssocUserIDNotFound(): void { |
|
637 | + $this->expectException(\Exception::class); |
|
638 | + $this->expectExceptionMessage('Group id not found in LDAP'); |
|
639 | + |
|
640 | + $userBackend = $this->createMock(User_LDAP::class); |
|
641 | + $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
642 | + ->onlyMethods(['groupExists']) |
|
643 | + ->disableOriginalConstructor() |
|
644 | + ->getMock(); |
|
645 | + |
|
646 | + $groupBackend->expects($this->any()) |
|
647 | + ->method('groupExists') |
|
648 | + ->willReturn(false); |
|
649 | + |
|
650 | + $server = $this->getServerMock($userBackend, $groupBackend); |
|
651 | + |
|
652 | + $ldapProvider = $this->getLDAPProvider($server); |
|
653 | + $ldapProvider->getLDAPGroupMemberAssoc('nonexisting_group'); |
|
654 | + } |
|
655 | + |
|
656 | + public function testgetLDAPGroupMemberAssoc(): void { |
|
657 | + $userBackend = $this->createMock(User_LDAP::class); |
|
658 | + |
|
659 | + $connection = $this->getMockBuilder(Connection::class) |
|
660 | + ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
661 | + ->getMock(); |
|
662 | + $connection->expects($this->once()) |
|
663 | + ->method('getConfiguration') |
|
664 | + ->willReturn(['ldap_group_member_assoc_attribute' => 'assoc_type']); |
|
665 | + $access = $this->createMock(Access::class); |
|
666 | + $access->method('getConnection') |
|
667 | + ->willReturn($connection); |
|
668 | + $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
669 | + ->onlyMethods(['groupExists', 'getLDAPAccess']) |
|
670 | + ->disableOriginalConstructor() |
|
671 | + ->getMock(); |
|
672 | + |
|
673 | + $groupBackend->expects($this->once()) |
|
674 | + ->method('groupExists') |
|
675 | + ->willReturn(true); |
|
676 | + $groupBackend->expects($this->any()) |
|
677 | + ->method('getLDAPAccess') |
|
678 | + ->willReturn($access); |
|
679 | + |
|
680 | + $server = $this->getServerMock($userBackend, $groupBackend); |
|
681 | + |
|
682 | + $ldapProvider = $this->getLDAPProvider($server); |
|
683 | + $this->assertEquals('assoc_type', $ldapProvider->getLDAPGroupMemberAssoc('existing_group')); |
|
684 | + } |
|
685 | + |
|
686 | + public function testGetMultiValueUserAttributeUserNotFound(): void { |
|
687 | + $this->expectException(\Exception::class); |
|
688 | + $this->expectExceptionMessage('User id not found in LDAP'); |
|
689 | + |
|
690 | + $userBackend = $this->createMock(User_LDAP::class); |
|
691 | + $userBackend->expects(self::once()) |
|
692 | + ->method('userExists') |
|
693 | + ->with('admin') |
|
694 | + ->willReturn(false); |
|
695 | + $groupBackend = $this->createMock(Group_LDAP::class); |
|
696 | + $server = $this->getServerMock($userBackend, $groupBackend); |
|
697 | + |
|
698 | + $ldapProvider = $this->getLDAPProvider($server); |
|
699 | + $ldapProvider->getMultiValueUserAttribute('admin', 'mailAlias'); |
|
700 | + } |
|
701 | + |
|
702 | + public function testGetMultiValueUserAttributeCacheHit(): void { |
|
703 | + $connection = $this->getMockBuilder(Connection::class) |
|
704 | + ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
705 | + ->getMock(); |
|
706 | + $connection->expects(self::once()) |
|
707 | + ->method('getFromCache') |
|
708 | + ->with('admin-mailAlias') |
|
709 | + ->willReturn(['[email protected]', '[email protected]']); |
|
710 | + $access = $this->createMock(Access::class); |
|
711 | + $access->expects(self::once()) |
|
712 | + ->method('getConnection') |
|
713 | + ->willReturn($connection); |
|
714 | + $userBackend = $this->createMock(User_LDAP::class); |
|
715 | + $userBackend->expects(self::once()) |
|
716 | + ->method('userExists') |
|
717 | + ->with('admin') |
|
718 | + ->willReturn(true); |
|
719 | + $userBackend->expects(self::once()) |
|
720 | + ->method('getLDAPAccess') |
|
721 | + ->willReturn($access); |
|
722 | + $groupBackend = $this->createMock(Group_LDAP::class); |
|
723 | + $server = $this->getServerMock($userBackend, $groupBackend); |
|
724 | + |
|
725 | + $ldapProvider = $this->getLDAPProvider($server); |
|
726 | + $ldapProvider->getMultiValueUserAttribute('admin', 'mailAlias'); |
|
727 | + } |
|
728 | + |
|
729 | + public function testGetMultiValueUserAttributeLdapError(): void { |
|
730 | + $connection = $this->getMockBuilder(Connection::class) |
|
731 | + ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
732 | + ->getMock(); |
|
733 | + $connection->expects(self::once()) |
|
734 | + ->method('getFromCache') |
|
735 | + ->with('admin-mailAlias') |
|
736 | + ->willReturn(null); |
|
737 | + $access = $this->createMock(Access::class); |
|
738 | + $access->expects(self::once()) |
|
739 | + ->method('getConnection') |
|
740 | + ->willReturn($connection); |
|
741 | + $access->expects(self::once()) |
|
742 | + ->method('username2dn') |
|
743 | + ->with('admin') |
|
744 | + ->willReturn('admin'); |
|
745 | + $access->expects(self::once()) |
|
746 | + ->method('readAttribute') |
|
747 | + ->with('admin', 'mailAlias') |
|
748 | + ->willReturn(false); |
|
749 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
750 | + ->disableOriginalConstructor() |
|
751 | + ->getMock(); |
|
752 | + $userBackend->method('userExists') |
|
753 | + ->with('admin') |
|
754 | + ->willReturn(true); |
|
755 | + $userBackend->method('getLDAPAccess') |
|
756 | + ->willReturn($access); |
|
757 | + $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
758 | + ->disableOriginalConstructor() |
|
759 | + ->getMock(); |
|
760 | + $server = $this->getServerMock($userBackend, $groupBackend); |
|
761 | + |
|
762 | + $ldapProvider = $this->getLDAPProvider($server); |
|
763 | + $values = $ldapProvider->getMultiValueUserAttribute('admin', 'mailAlias'); |
|
764 | + |
|
765 | + self::assertCount(0, $values); |
|
766 | + } |
|
767 | + |
|
768 | + public function testGetMultiValueUserAttribute(): void { |
|
769 | + $connection = $this->getMockBuilder(Connection::class) |
|
770 | + ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
771 | + ->getMock(); |
|
772 | + $connection->expects(self::once()) |
|
773 | + ->method('getFromCache') |
|
774 | + ->with('admin-mailAlias') |
|
775 | + ->willReturn(null); |
|
776 | + $access = $this->createMock(Access::class); |
|
777 | + $access->expects(self::once()) |
|
778 | + ->method('getConnection') |
|
779 | + ->willReturn($connection); |
|
780 | + $access->expects(self::once()) |
|
781 | + ->method('username2dn') |
|
782 | + ->with('admin') |
|
783 | + ->willReturn('admin'); |
|
784 | + $access->expects(self::once()) |
|
785 | + ->method('readAttribute') |
|
786 | + ->with('admin', 'mailAlias') |
|
787 | + ->willReturn(['[email protected]', '[email protected]']); |
|
788 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
789 | + ->disableOriginalConstructor() |
|
790 | + ->getMock(); |
|
791 | + $userBackend->method('userExists') |
|
792 | + ->with('admin') |
|
793 | + ->willReturn(true); |
|
794 | + $userBackend->method('getLDAPAccess') |
|
795 | + ->willReturn($access); |
|
796 | + $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
797 | + ->disableOriginalConstructor() |
|
798 | + ->getMock(); |
|
799 | + $server = $this->getServerMock($userBackend, $groupBackend); |
|
800 | + |
|
801 | + $ldapProvider = $this->getLDAPProvider($server); |
|
802 | + $values = $ldapProvider->getMultiValueUserAttribute('admin', 'mailAlias'); |
|
803 | + |
|
804 | + self::assertCount(2, $values); |
|
805 | + } |
|
806 | + |
|
807 | + public function testGetUserAttributeLdapError(): void { |
|
808 | + $connection = $this->getMockBuilder(Connection::class) |
|
809 | + ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
810 | + ->getMock(); |
|
811 | + $connection->expects(self::once()) |
|
812 | + ->method('getFromCache') |
|
813 | + ->with('admin-mailAlias') |
|
814 | + ->willReturn(null); |
|
815 | + $access = $this->createMock(Access::class); |
|
816 | + $access->expects(self::once()) |
|
817 | + ->method('getConnection') |
|
818 | + ->willReturn($connection); |
|
819 | + $access->expects(self::once()) |
|
820 | + ->method('username2dn') |
|
821 | + ->with('admin') |
|
822 | + ->willReturn('admin'); |
|
823 | + $access->expects(self::once()) |
|
824 | + ->method('readAttribute') |
|
825 | + ->with('admin', 'mailAlias') |
|
826 | + ->willReturn(false); |
|
827 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
828 | + ->disableOriginalConstructor() |
|
829 | + ->getMock(); |
|
830 | + $userBackend->method('userExists') |
|
831 | + ->with('admin') |
|
832 | + ->willReturn(true); |
|
833 | + $userBackend->method('getLDAPAccess') |
|
834 | + ->willReturn($access); |
|
835 | + $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
836 | + ->disableOriginalConstructor() |
|
837 | + ->getMock(); |
|
838 | + $server = $this->getServerMock($userBackend, $groupBackend); |
|
839 | + |
|
840 | + $ldapProvider = $this->getLDAPProvider($server); |
|
841 | + $value = $ldapProvider->getUserAttribute('admin', 'mailAlias'); |
|
842 | + |
|
843 | + self::assertNull($value); |
|
844 | + } |
|
845 | + |
|
846 | + public function testGetUserAttribute(): void { |
|
847 | + $connection = $this->getMockBuilder(Connection::class) |
|
848 | + ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
|
849 | + ->getMock(); |
|
850 | + $connection->expects(self::once()) |
|
851 | + ->method('getFromCache') |
|
852 | + ->with('admin-mailAlias') |
|
853 | + ->willReturn(null); |
|
854 | + $access = $this->createMock(Access::class); |
|
855 | + $access->expects(self::once()) |
|
856 | + ->method('getConnection') |
|
857 | + ->willReturn($connection); |
|
858 | + $access->expects(self::once()) |
|
859 | + ->method('username2dn') |
|
860 | + ->with('admin') |
|
861 | + ->willReturn('admin'); |
|
862 | + $access->expects(self::once()) |
|
863 | + ->method('readAttribute') |
|
864 | + ->with('admin', 'mailAlias') |
|
865 | + ->willReturn(['[email protected]', '[email protected]']); |
|
866 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
|
867 | + ->disableOriginalConstructor() |
|
868 | + ->getMock(); |
|
869 | + $userBackend->method('userExists') |
|
870 | + ->with('admin') |
|
871 | + ->willReturn(true); |
|
872 | + $userBackend->method('getLDAPAccess') |
|
873 | + ->willReturn($access); |
|
874 | + $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
|
875 | + ->disableOriginalConstructor() |
|
876 | + ->getMock(); |
|
877 | + $server = $this->getServerMock($userBackend, $groupBackend); |
|
878 | + |
|
879 | + $ldapProvider = $this->getLDAPProvider($server); |
|
880 | + $value = $ldapProvider->getUserAttribute('admin', 'mailAlias'); |
|
881 | + |
|
882 | + self::assertEquals('[email protected]', $value); |
|
883 | + } |
|
884 | 884 | } |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | public function testGetGroupLDAPConnection(): void { |
276 | 276 | $userBackend = $this->createMock(User_LDAP::class); |
277 | 277 | $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
278 | - ->onlyMethods(['groupExists','getNewLDAPConnection']) |
|
278 | + ->onlyMethods(['groupExists', 'getNewLDAPConnection']) |
|
279 | 279 | ->disableOriginalConstructor() |
280 | 280 | ->getMock(); |
281 | 281 | |
@@ -316,14 +316,14 @@ discard block |
||
316 | 316 | 'ou=users,ou=foobar,dc=example,dc=org', |
317 | 317 | 'ou=users,ou=barfoo,dc=example,dc=org', |
318 | 318 | ]; |
319 | - $dn = 'uid=malik,' . $bases[1]; |
|
319 | + $dn = 'uid=malik,'.$bases[1]; |
|
320 | 320 | |
321 | 321 | $connection = $this->getMockBuilder(Connection::class) |
322 | 322 | ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)]) |
323 | 323 | ->getMock(); |
324 | 324 | $connection->expects($this->any()) |
325 | 325 | ->method('__get') |
326 | - ->willReturnCallback(function ($key) use ($bases) { |
|
326 | + ->willReturnCallback(function($key) use ($bases) { |
|
327 | 327 | switch ($key) { |
328 | 328 | case 'ldapBaseUsers': |
329 | 329 | return $bases; |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | ->getMock(); |
388 | 388 | $connection->expects($this->any()) |
389 | 389 | ->method('__get') |
390 | - ->willReturnCallback(function ($key) use ($bases) { |
|
390 | + ->willReturnCallback(function($key) use ($bases) { |
|
391 | 391 | switch ($key) { |
392 | 392 | case 'ldapBaseGroups': |
393 | 393 | return $bases; |
@@ -11,217 +11,217 @@ |
||
11 | 11 | use OCP\GroupInterface; |
12 | 12 | |
13 | 13 | class GroupLDAPPluginTest extends \Test\TestCase { |
14 | - private function getGroupPluginManager(): GroupPluginManager { |
|
15 | - return new GroupPluginManager(); |
|
16 | - } |
|
14 | + private function getGroupPluginManager(): GroupPluginManager { |
|
15 | + return new GroupPluginManager(); |
|
16 | + } |
|
17 | 17 | |
18 | - public function testImplementsActions(): void { |
|
19 | - $pluginManager = $this->getGroupPluginManager(); |
|
18 | + public function testImplementsActions(): void { |
|
19 | + $pluginManager = $this->getGroupPluginManager(); |
|
20 | 20 | |
21 | - $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class) |
|
22 | - ->onlyMethods(['respondToActions']) |
|
23 | - ->getMock(); |
|
21 | + $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class) |
|
22 | + ->onlyMethods(['respondToActions']) |
|
23 | + ->getMock(); |
|
24 | 24 | |
25 | - $plugin->expects($this->any()) |
|
26 | - ->method('respondToActions') |
|
27 | - ->willReturn(GroupInterface::CREATE_GROUP); |
|
25 | + $plugin->expects($this->any()) |
|
26 | + ->method('respondToActions') |
|
27 | + ->willReturn(GroupInterface::CREATE_GROUP); |
|
28 | 28 | |
29 | - $plugin2 = $this->getMockBuilder(LDAPGroupPluginDummy::class) |
|
30 | - ->onlyMethods(['respondToActions']) |
|
31 | - ->getMock(); |
|
29 | + $plugin2 = $this->getMockBuilder(LDAPGroupPluginDummy::class) |
|
30 | + ->onlyMethods(['respondToActions']) |
|
31 | + ->getMock(); |
|
32 | 32 | |
33 | - $plugin2->expects($this->any()) |
|
34 | - ->method('respondToActions') |
|
35 | - ->willReturn(GroupInterface::ADD_TO_GROUP); |
|
33 | + $plugin2->expects($this->any()) |
|
34 | + ->method('respondToActions') |
|
35 | + ->willReturn(GroupInterface::ADD_TO_GROUP); |
|
36 | 36 | |
37 | - $pluginManager->register($plugin); |
|
38 | - $pluginManager->register($plugin2); |
|
37 | + $pluginManager->register($plugin); |
|
38 | + $pluginManager->register($plugin2); |
|
39 | 39 | |
40 | - $this->assertEquals($pluginManager->getImplementedActions(), GroupInterface::CREATE_GROUP | GroupInterface::ADD_TO_GROUP); |
|
41 | - $this->assertTrue($pluginManager->implementsActions(GroupInterface::CREATE_GROUP)); |
|
42 | - $this->assertTrue($pluginManager->implementsActions(GroupInterface::ADD_TO_GROUP)); |
|
43 | - } |
|
40 | + $this->assertEquals($pluginManager->getImplementedActions(), GroupInterface::CREATE_GROUP | GroupInterface::ADD_TO_GROUP); |
|
41 | + $this->assertTrue($pluginManager->implementsActions(GroupInterface::CREATE_GROUP)); |
|
42 | + $this->assertTrue($pluginManager->implementsActions(GroupInterface::ADD_TO_GROUP)); |
|
43 | + } |
|
44 | 44 | |
45 | - public function testCreateGroup(): void { |
|
46 | - $pluginManager = $this->getGroupPluginManager(); |
|
45 | + public function testCreateGroup(): void { |
|
46 | + $pluginManager = $this->getGroupPluginManager(); |
|
47 | 47 | |
48 | - $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class) |
|
49 | - ->onlyMethods(['respondToActions', 'createGroup']) |
|
50 | - ->getMock(); |
|
48 | + $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class) |
|
49 | + ->onlyMethods(['respondToActions', 'createGroup']) |
|
50 | + ->getMock(); |
|
51 | 51 | |
52 | - $plugin->expects($this->any()) |
|
53 | - ->method('respondToActions') |
|
54 | - ->willReturn(GroupInterface::CREATE_GROUP); |
|
52 | + $plugin->expects($this->any()) |
|
53 | + ->method('respondToActions') |
|
54 | + ->willReturn(GroupInterface::CREATE_GROUP); |
|
55 | 55 | |
56 | - $plugin->expects($this->once()) |
|
57 | - ->method('createGroup') |
|
58 | - ->with( |
|
59 | - $this->equalTo('group') |
|
60 | - ); |
|
56 | + $plugin->expects($this->once()) |
|
57 | + ->method('createGroup') |
|
58 | + ->with( |
|
59 | + $this->equalTo('group') |
|
60 | + ); |
|
61 | 61 | |
62 | - $pluginManager->register($plugin); |
|
63 | - $pluginManager->createGroup('group'); |
|
64 | - } |
|
62 | + $pluginManager->register($plugin); |
|
63 | + $pluginManager->createGroup('group'); |
|
64 | + } |
|
65 | 65 | |
66 | 66 | |
67 | - public function testCreateGroupNotRegistered(): void { |
|
68 | - $this->expectException(\Exception::class); |
|
69 | - $this->expectExceptionMessage('No plugin implements createGroup in this LDAP Backend.'); |
|
67 | + public function testCreateGroupNotRegistered(): void { |
|
68 | + $this->expectException(\Exception::class); |
|
69 | + $this->expectExceptionMessage('No plugin implements createGroup in this LDAP Backend.'); |
|
70 | 70 | |
71 | - $pluginManager = $this->getGroupPluginManager(); |
|
72 | - $pluginManager->createGroup('foo'); |
|
73 | - } |
|
71 | + $pluginManager = $this->getGroupPluginManager(); |
|
72 | + $pluginManager->createGroup('foo'); |
|
73 | + } |
|
74 | 74 | |
75 | - public function testDeleteGroup(): void { |
|
76 | - $pluginManager = $this->getGroupPluginManager(); |
|
75 | + public function testDeleteGroup(): void { |
|
76 | + $pluginManager = $this->getGroupPluginManager(); |
|
77 | 77 | |
78 | - $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class) |
|
79 | - ->onlyMethods(['respondToActions', 'deleteGroup']) |
|
80 | - ->getMock(); |
|
78 | + $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class) |
|
79 | + ->onlyMethods(['respondToActions', 'deleteGroup']) |
|
80 | + ->getMock(); |
|
81 | 81 | |
82 | - $plugin->expects($this->any()) |
|
83 | - ->method('respondToActions') |
|
84 | - ->willReturn(GroupInterface::DELETE_GROUP); |
|
82 | + $plugin->expects($this->any()) |
|
83 | + ->method('respondToActions') |
|
84 | + ->willReturn(GroupInterface::DELETE_GROUP); |
|
85 | 85 | |
86 | - $plugin->expects($this->once()) |
|
87 | - ->method('deleteGroup') |
|
88 | - ->with( |
|
89 | - $this->equalTo('group') |
|
90 | - )->willReturn(true); |
|
86 | + $plugin->expects($this->once()) |
|
87 | + ->method('deleteGroup') |
|
88 | + ->with( |
|
89 | + $this->equalTo('group') |
|
90 | + )->willReturn(true); |
|
91 | 91 | |
92 | - $pluginManager->register($plugin); |
|
93 | - $this->assertTrue($pluginManager->deleteGroup('group')); |
|
94 | - } |
|
92 | + $pluginManager->register($plugin); |
|
93 | + $this->assertTrue($pluginManager->deleteGroup('group')); |
|
94 | + } |
|
95 | 95 | |
96 | 96 | |
97 | - public function testDeleteGroupNotRegistered(): void { |
|
98 | - $this->expectException(\Exception::class); |
|
99 | - $this->expectExceptionMessage('No plugin implements deleteGroup in this LDAP Backend.'); |
|
97 | + public function testDeleteGroupNotRegistered(): void { |
|
98 | + $this->expectException(\Exception::class); |
|
99 | + $this->expectExceptionMessage('No plugin implements deleteGroup in this LDAP Backend.'); |
|
100 | 100 | |
101 | - $pluginManager = $this->getGroupPluginManager(); |
|
102 | - $pluginManager->deleteGroup('foo'); |
|
103 | - } |
|
101 | + $pluginManager = $this->getGroupPluginManager(); |
|
102 | + $pluginManager->deleteGroup('foo'); |
|
103 | + } |
|
104 | 104 | |
105 | - public function testAddToGroup(): void { |
|
106 | - $pluginManager = $this->getGroupPluginManager(); |
|
105 | + public function testAddToGroup(): void { |
|
106 | + $pluginManager = $this->getGroupPluginManager(); |
|
107 | 107 | |
108 | - $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class) |
|
109 | - ->onlyMethods(['respondToActions', 'addToGroup']) |
|
110 | - ->getMock(); |
|
108 | + $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class) |
|
109 | + ->onlyMethods(['respondToActions', 'addToGroup']) |
|
110 | + ->getMock(); |
|
111 | 111 | |
112 | - $plugin->expects($this->any()) |
|
113 | - ->method('respondToActions') |
|
114 | - ->willReturn(GroupInterface::ADD_TO_GROUP); |
|
112 | + $plugin->expects($this->any()) |
|
113 | + ->method('respondToActions') |
|
114 | + ->willReturn(GroupInterface::ADD_TO_GROUP); |
|
115 | 115 | |
116 | - $plugin->expects($this->once()) |
|
117 | - ->method('addToGroup') |
|
118 | - ->with( |
|
119 | - $this->equalTo('uid'), |
|
120 | - $this->equalTo('gid') |
|
121 | - ); |
|
116 | + $plugin->expects($this->once()) |
|
117 | + ->method('addToGroup') |
|
118 | + ->with( |
|
119 | + $this->equalTo('uid'), |
|
120 | + $this->equalTo('gid') |
|
121 | + ); |
|
122 | 122 | |
123 | - $pluginManager->register($plugin); |
|
124 | - $pluginManager->addToGroup('uid', 'gid'); |
|
125 | - } |
|
123 | + $pluginManager->register($plugin); |
|
124 | + $pluginManager->addToGroup('uid', 'gid'); |
|
125 | + } |
|
126 | 126 | |
127 | 127 | |
128 | - public function testAddToGroupNotRegistered(): void { |
|
129 | - $this->expectException(\Exception::class); |
|
130 | - $this->expectExceptionMessage('No plugin implements addToGroup in this LDAP Backend.'); |
|
128 | + public function testAddToGroupNotRegistered(): void { |
|
129 | + $this->expectException(\Exception::class); |
|
130 | + $this->expectExceptionMessage('No plugin implements addToGroup in this LDAP Backend.'); |
|
131 | 131 | |
132 | - $pluginManager = $this->getGroupPluginManager(); |
|
133 | - $pluginManager->addToGroup('foo', 'bar'); |
|
134 | - } |
|
132 | + $pluginManager = $this->getGroupPluginManager(); |
|
133 | + $pluginManager->addToGroup('foo', 'bar'); |
|
134 | + } |
|
135 | 135 | |
136 | - public function testRemoveFromGroup(): void { |
|
137 | - $pluginManager = $this->getGroupPluginManager(); |
|
136 | + public function testRemoveFromGroup(): void { |
|
137 | + $pluginManager = $this->getGroupPluginManager(); |
|
138 | 138 | |
139 | - $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class) |
|
140 | - ->onlyMethods(['respondToActions', 'removeFromGroup']) |
|
141 | - ->getMock(); |
|
139 | + $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class) |
|
140 | + ->onlyMethods(['respondToActions', 'removeFromGroup']) |
|
141 | + ->getMock(); |
|
142 | 142 | |
143 | - $plugin->expects($this->any()) |
|
144 | - ->method('respondToActions') |
|
145 | - ->willReturn(GroupInterface::REMOVE_FROM_GROUP); |
|
143 | + $plugin->expects($this->any()) |
|
144 | + ->method('respondToActions') |
|
145 | + ->willReturn(GroupInterface::REMOVE_FROM_GROUP); |
|
146 | 146 | |
147 | - $plugin->expects($this->once()) |
|
148 | - ->method('removeFromGroup') |
|
149 | - ->with( |
|
150 | - $this->equalTo('uid'), |
|
151 | - $this->equalTo('gid') |
|
152 | - ); |
|
147 | + $plugin->expects($this->once()) |
|
148 | + ->method('removeFromGroup') |
|
149 | + ->with( |
|
150 | + $this->equalTo('uid'), |
|
151 | + $this->equalTo('gid') |
|
152 | + ); |
|
153 | 153 | |
154 | - $pluginManager->register($plugin); |
|
155 | - $pluginManager->removeFromGroup('uid', 'gid'); |
|
156 | - } |
|
154 | + $pluginManager->register($plugin); |
|
155 | + $pluginManager->removeFromGroup('uid', 'gid'); |
|
156 | + } |
|
157 | 157 | |
158 | 158 | |
159 | - public function testRemoveFromGroupNotRegistered(): void { |
|
160 | - $this->expectException(\Exception::class); |
|
161 | - $this->expectExceptionMessage('No plugin implements removeFromGroup in this LDAP Backend.'); |
|
159 | + public function testRemoveFromGroupNotRegistered(): void { |
|
160 | + $this->expectException(\Exception::class); |
|
161 | + $this->expectExceptionMessage('No plugin implements removeFromGroup in this LDAP Backend.'); |
|
162 | 162 | |
163 | - $pluginManager = $this->getGroupPluginManager(); |
|
164 | - $pluginManager->removeFromGroup('foo', 'bar'); |
|
165 | - } |
|
163 | + $pluginManager = $this->getGroupPluginManager(); |
|
164 | + $pluginManager->removeFromGroup('foo', 'bar'); |
|
165 | + } |
|
166 | 166 | |
167 | - public function testCountUsersInGroup(): void { |
|
168 | - $pluginManager = $this->getGroupPluginManager(); |
|
167 | + public function testCountUsersInGroup(): void { |
|
168 | + $pluginManager = $this->getGroupPluginManager(); |
|
169 | 169 | |
170 | - $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class) |
|
171 | - ->onlyMethods(['respondToActions', 'countUsersInGroup']) |
|
172 | - ->getMock(); |
|
170 | + $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class) |
|
171 | + ->onlyMethods(['respondToActions', 'countUsersInGroup']) |
|
172 | + ->getMock(); |
|
173 | 173 | |
174 | - $plugin->expects($this->any()) |
|
175 | - ->method('respondToActions') |
|
176 | - ->willReturn(GroupInterface::COUNT_USERS); |
|
174 | + $plugin->expects($this->any()) |
|
175 | + ->method('respondToActions') |
|
176 | + ->willReturn(GroupInterface::COUNT_USERS); |
|
177 | 177 | |
178 | - $plugin->expects($this->once()) |
|
179 | - ->method('countUsersInGroup') |
|
180 | - ->with( |
|
181 | - $this->equalTo('gid'), |
|
182 | - $this->equalTo('search') |
|
183 | - ); |
|
178 | + $plugin->expects($this->once()) |
|
179 | + ->method('countUsersInGroup') |
|
180 | + ->with( |
|
181 | + $this->equalTo('gid'), |
|
182 | + $this->equalTo('search') |
|
183 | + ); |
|
184 | 184 | |
185 | - $pluginManager->register($plugin); |
|
186 | - $pluginManager->countUsersInGroup('gid', 'search'); |
|
187 | - } |
|
185 | + $pluginManager->register($plugin); |
|
186 | + $pluginManager->countUsersInGroup('gid', 'search'); |
|
187 | + } |
|
188 | 188 | |
189 | 189 | |
190 | - public function testCountUsersInGroupNotRegistered(): void { |
|
191 | - $this->expectException(\Exception::class); |
|
192 | - $this->expectExceptionMessage('No plugin implements countUsersInGroup in this LDAP Backend.'); |
|
190 | + public function testCountUsersInGroupNotRegistered(): void { |
|
191 | + $this->expectException(\Exception::class); |
|
192 | + $this->expectExceptionMessage('No plugin implements countUsersInGroup in this LDAP Backend.'); |
|
193 | 193 | |
194 | - $pluginManager = $this->getGroupPluginManager(); |
|
195 | - $pluginManager->countUsersInGroup('foo', 'bar'); |
|
196 | - } |
|
194 | + $pluginManager = $this->getGroupPluginManager(); |
|
195 | + $pluginManager->countUsersInGroup('foo', 'bar'); |
|
196 | + } |
|
197 | 197 | |
198 | - public function testgetGroupDetails(): void { |
|
199 | - $pluginManager = $this->getGroupPluginManager(); |
|
198 | + public function testgetGroupDetails(): void { |
|
199 | + $pluginManager = $this->getGroupPluginManager(); |
|
200 | 200 | |
201 | - $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class) |
|
202 | - ->onlyMethods(['respondToActions', 'getGroupDetails']) |
|
203 | - ->getMock(); |
|
201 | + $plugin = $this->getMockBuilder(LDAPGroupPluginDummy::class) |
|
202 | + ->onlyMethods(['respondToActions', 'getGroupDetails']) |
|
203 | + ->getMock(); |
|
204 | 204 | |
205 | - $plugin->expects($this->any()) |
|
206 | - ->method('respondToActions') |
|
207 | - ->willReturn(GroupInterface::GROUP_DETAILS); |
|
205 | + $plugin->expects($this->any()) |
|
206 | + ->method('respondToActions') |
|
207 | + ->willReturn(GroupInterface::GROUP_DETAILS); |
|
208 | 208 | |
209 | - $plugin->expects($this->once()) |
|
210 | - ->method('getGroupDetails') |
|
211 | - ->with( |
|
212 | - $this->equalTo('gid') |
|
213 | - ); |
|
209 | + $plugin->expects($this->once()) |
|
210 | + ->method('getGroupDetails') |
|
211 | + ->with( |
|
212 | + $this->equalTo('gid') |
|
213 | + ); |
|
214 | 214 | |
215 | - $pluginManager->register($plugin); |
|
216 | - $pluginManager->getGroupDetails('gid'); |
|
217 | - } |
|
215 | + $pluginManager->register($plugin); |
|
216 | + $pluginManager->getGroupDetails('gid'); |
|
217 | + } |
|
218 | 218 | |
219 | 219 | |
220 | - public function testgetGroupDetailsNotRegistered(): void { |
|
221 | - $this->expectException(\Exception::class); |
|
222 | - $this->expectExceptionMessage('No plugin implements getGroupDetails in this LDAP Backend.'); |
|
220 | + public function testgetGroupDetailsNotRegistered(): void { |
|
221 | + $this->expectException(\Exception::class); |
|
222 | + $this->expectExceptionMessage('No plugin implements getGroupDetails in this LDAP Backend.'); |
|
223 | 223 | |
224 | - $pluginManager = $this->getGroupPluginManager(); |
|
225 | - $pluginManager->getGroupDetails('foo'); |
|
226 | - } |
|
224 | + $pluginManager = $this->getGroupPluginManager(); |
|
225 | + $pluginManager->getGroupDetails('foo'); |
|
226 | + } |
|
227 | 227 | } |
@@ -10,43 +10,43 @@ |
||
10 | 10 | use OCA\User_LDAP\ILDAPUserPlugin; |
11 | 11 | |
12 | 12 | class LDAPUserPluginDummy implements ILDAPUserPlugin { |
13 | - public function respondToActions() { |
|
14 | - return null; |
|
15 | - } |
|
13 | + public function respondToActions() { |
|
14 | + return null; |
|
15 | + } |
|
16 | 16 | |
17 | - public function createUser($username, $password) { |
|
18 | - return null; |
|
19 | - } |
|
17 | + public function createUser($username, $password) { |
|
18 | + return null; |
|
19 | + } |
|
20 | 20 | |
21 | - public function setPassword($uid, $password) { |
|
22 | - return null; |
|
23 | - } |
|
21 | + public function setPassword($uid, $password) { |
|
22 | + return null; |
|
23 | + } |
|
24 | 24 | |
25 | - public function getHome($uid) { |
|
26 | - return null; |
|
27 | - } |
|
25 | + public function getHome($uid) { |
|
26 | + return null; |
|
27 | + } |
|
28 | 28 | |
29 | - public function getDisplayName($uid) { |
|
30 | - return null; |
|
31 | - } |
|
29 | + public function getDisplayName($uid) { |
|
30 | + return null; |
|
31 | + } |
|
32 | 32 | |
33 | - public function setDisplayName($uid, $displayName) { |
|
34 | - return null; |
|
35 | - } |
|
33 | + public function setDisplayName($uid, $displayName) { |
|
34 | + return null; |
|
35 | + } |
|
36 | 36 | |
37 | - public function canChangeAvatar($uid) { |
|
38 | - return null; |
|
39 | - } |
|
37 | + public function canChangeAvatar($uid) { |
|
38 | + return null; |
|
39 | + } |
|
40 | 40 | |
41 | - public function countUsers() { |
|
42 | - return null; |
|
43 | - } |
|
41 | + public function countUsers() { |
|
42 | + return null; |
|
43 | + } |
|
44 | 44 | |
45 | - public function canDeleteUser() { |
|
46 | - return true; |
|
47 | - } |
|
45 | + public function canDeleteUser() { |
|
46 | + return true; |
|
47 | + } |
|
48 | 48 | |
49 | - public function deleteUser($uid) { |
|
50 | - return null; |
|
51 | - } |
|
49 | + public function deleteUser($uid) { |
|
50 | + return null; |
|
51 | + } |
|
52 | 52 | } |
@@ -31,352 +31,352 @@ |
||
31 | 31 | * @group DB |
32 | 32 | */ |
33 | 33 | class SyncTest extends TestCase { |
34 | - protected Helper&MockObject $helper; |
|
35 | - protected LDAP&MockObject $ldapWrapper; |
|
36 | - protected Manager&MockObject $userManager; |
|
37 | - protected UserMapping&MockObject $mapper; |
|
38 | - protected IConfig&MockObject $config; |
|
39 | - protected IAvatarManager&MockObject $avatarManager; |
|
40 | - protected IDBConnection&MockObject $dbc; |
|
41 | - protected IUserManager&MockObject $ncUserManager; |
|
42 | - protected IManager&MockObject $notificationManager; |
|
43 | - protected ConnectionFactory&MockObject $connectionFactory; |
|
44 | - protected AccessFactory&MockObject $accessFactory; |
|
45 | - protected array $arguments = []; |
|
46 | - protected Sync $sync; |
|
47 | - |
|
48 | - protected function setUp(): void { |
|
49 | - parent::setUp(); |
|
50 | - |
|
51 | - $this->helper = $this->createMock(Helper::class); |
|
52 | - $this->ldapWrapper = $this->createMock(LDAP::class); |
|
53 | - $this->userManager = $this->createMock(Manager::class); |
|
54 | - $this->mapper = $this->createMock(UserMapping::class); |
|
55 | - $this->config = $this->createMock(IConfig::class); |
|
56 | - $this->avatarManager = $this->createMock(IAvatarManager::class); |
|
57 | - $this->dbc = $this->createMock(IDBConnection::class); |
|
58 | - $this->ncUserManager = $this->createMock(IUserManager::class); |
|
59 | - $this->notificationManager = $this->createMock(IManager::class); |
|
60 | - $this->connectionFactory = $this->getMockBuilder(ConnectionFactory::class) |
|
61 | - ->setConstructorArgs([ |
|
62 | - $this->ldapWrapper, |
|
63 | - ]) |
|
64 | - ->getMock(); |
|
65 | - $this->accessFactory = $this->createMock(AccessFactory::class); |
|
66 | - |
|
67 | - $this->sync = new Sync( |
|
68 | - Server::get(ITimeFactory::class), |
|
69 | - Server::get(IEventDispatcher::class), |
|
70 | - $this->config, |
|
71 | - $this->dbc, |
|
72 | - $this->avatarManager, |
|
73 | - $this->ncUserManager, |
|
74 | - Server::get(LoggerInterface::class), |
|
75 | - $this->notificationManager, |
|
76 | - $this->mapper, |
|
77 | - $this->helper, |
|
78 | - $this->connectionFactory, |
|
79 | - $this->accessFactory, |
|
80 | - ); |
|
81 | - |
|
82 | - $this->sync->overwritePropertiesForTest($this->ldapWrapper); |
|
83 | - } |
|
84 | - |
|
85 | - public static function intervalDataProvider(): array { |
|
86 | - return [ |
|
87 | - [ |
|
88 | - 0, 1000, 750 |
|
89 | - ], |
|
90 | - [ |
|
91 | - 22, 0, 50 |
|
92 | - ], |
|
93 | - [ |
|
94 | - 500, 500, 500 |
|
95 | - ], |
|
96 | - [ |
|
97 | - 1357, 0, 0 |
|
98 | - ], |
|
99 | - [ |
|
100 | - 421337, 2000, 3000 |
|
101 | - ] |
|
102 | - ]; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @dataProvider intervalDataProvider |
|
107 | - */ |
|
108 | - public function testUpdateInterval(int $userCount, int $pagingSize1, int $pagingSize2): void { |
|
109 | - $this->config->expects($this->once()) |
|
110 | - ->method('setAppValue') |
|
111 | - ->with('user_ldap', 'background_sync_interval', $this->anything()) |
|
112 | - ->willReturnCallback(function ($a, $k, $interval) { |
|
113 | - $this->assertTrue($interval >= SYNC::MIN_INTERVAL); |
|
114 | - $this->assertTrue($interval <= SYNC::MAX_INTERVAL); |
|
115 | - return true; |
|
116 | - }); |
|
117 | - $this->config->expects($this->atLeastOnce()) |
|
118 | - ->method('getAppKeys') |
|
119 | - ->willReturn([ |
|
120 | - 'blabla', |
|
121 | - 'ldap_paging_size', |
|
122 | - 's07blabla', |
|
123 | - 'installed', |
|
124 | - 's07ldap_paging_size' |
|
125 | - ]); |
|
126 | - $this->config->expects($this->exactly(2)) |
|
127 | - ->method('getAppValue') |
|
128 | - ->willReturnOnConsecutiveCalls($pagingSize1, $pagingSize2); |
|
129 | - |
|
130 | - $this->mapper->expects($this->atLeastOnce()) |
|
131 | - ->method('count') |
|
132 | - ->willReturn($userCount); |
|
133 | - |
|
134 | - $this->sync->setArgument($this->arguments); |
|
135 | - $this->sync->updateInterval(); |
|
136 | - } |
|
137 | - |
|
138 | - public static function moreResultsProvider(): array { |
|
139 | - return [ |
|
140 | - [ 3, 3, true ], |
|
141 | - [ 3, 5, true ], |
|
142 | - [ 3, 2, false], |
|
143 | - [ 0, 4, false], |
|
144 | - [ null, 4, false] |
|
145 | - ]; |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * @dataProvider moreResultsProvider |
|
150 | - */ |
|
151 | - public function testMoreResults($pagingSize, $results, $expected): void { |
|
152 | - $connection = $this->getMockBuilder(Connection::class) |
|
153 | - ->setConstructorArgs([ |
|
154 | - $this->ldapWrapper, |
|
155 | - ]) |
|
156 | - ->getMock(); |
|
157 | - $this->connectionFactory->expects($this->any()) |
|
158 | - ->method('get') |
|
159 | - ->willReturn($connection); |
|
160 | - $connection->expects($this->any()) |
|
161 | - ->method('__get') |
|
162 | - ->willReturnCallback(function ($key) use ($pagingSize) { |
|
163 | - if ($key === 'ldapPagingSize') { |
|
164 | - return $pagingSize; |
|
165 | - } |
|
166 | - return null; |
|
167 | - }); |
|
168 | - |
|
169 | - /** @var Access&MockObject $access */ |
|
170 | - $access = $this->createMock(Access::class); |
|
171 | - $this->accessFactory->expects($this->any()) |
|
172 | - ->method('get') |
|
173 | - ->with($connection) |
|
174 | - ->willReturn($access); |
|
175 | - |
|
176 | - $this->userManager->expects($this->any()) |
|
177 | - ->method('getAttributes') |
|
178 | - ->willReturn(['dn', 'uid', 'mail', 'displayname']); |
|
179 | - |
|
180 | - $access->expects($this->once()) |
|
181 | - ->method('fetchListOfUsers') |
|
182 | - ->willReturn(array_pad([], $results, 'someUser')); |
|
183 | - $access->expects($this->any()) |
|
184 | - ->method('combineFilterWithAnd') |
|
185 | - ->willReturn('pseudo=filter'); |
|
186 | - $access->connection = $connection; |
|
187 | - $access->userManager = $this->userManager; |
|
188 | - |
|
189 | - $this->sync->setArgument($this->arguments); |
|
190 | - $hasMoreResults = $this->sync->runCycle(['prefix' => 's01', 'offset' => 100]); |
|
191 | - $this->assertSame($expected, $hasMoreResults); |
|
192 | - } |
|
193 | - |
|
194 | - public static function cycleDataProvider(): array { |
|
195 | - $lastCycle = ['prefix' => 's01', 'offset' => 1000]; |
|
196 | - $lastCycle2 = ['prefix' => '', 'offset' => 1000]; |
|
197 | - return [ |
|
198 | - [ null, ['s01'], ['prefix' => 's01', 'offset' => 0] ], |
|
199 | - [ null, [''], ['prefix' => '', 'offset' => 0] ], |
|
200 | - [ $lastCycle, ['s01', 's02'], ['prefix' => 's02', 'offset' => 0] ], |
|
201 | - [ $lastCycle, [''], ['prefix' => '', 'offset' => 0] ], |
|
202 | - [ $lastCycle2, ['', 's01'], ['prefix' => 's01', 'offset' => 0] ], |
|
203 | - [ $lastCycle, [], null ], |
|
204 | - ]; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * @dataProvider cycleDataProvider |
|
209 | - */ |
|
210 | - public function testDetermineNextCycle(?array $cycleData, array $prefixes, ?array $expectedCycle): void { |
|
211 | - $this->helper->expects($this->any()) |
|
212 | - ->method('getServerConfigurationPrefixes') |
|
213 | - ->with(true) |
|
214 | - ->willReturn($prefixes); |
|
215 | - |
|
216 | - if (is_array($expectedCycle)) { |
|
217 | - $calls = [ |
|
218 | - ['user_ldap', 'background_sync_prefix', $expectedCycle['prefix']], |
|
219 | - ['user_ldap', 'background_sync_offset', $expectedCycle['offset']], |
|
220 | - ]; |
|
221 | - $this->config->expects($this->exactly(2)) |
|
222 | - ->method('setAppValue') |
|
223 | - ->willReturnCallback(function () use (&$calls) { |
|
224 | - $expected = array_shift($calls); |
|
225 | - $this->assertEquals($expected, func_get_args()); |
|
226 | - }); |
|
227 | - } else { |
|
228 | - $this->config->expects($this->never()) |
|
229 | - ->method('setAppValue'); |
|
230 | - } |
|
231 | - |
|
232 | - $this->sync->setArgument($this->arguments); |
|
233 | - $nextCycle = $this->sync->determineNextCycle($cycleData); |
|
234 | - |
|
235 | - if ($expectedCycle === null) { |
|
236 | - $this->assertNull($nextCycle); |
|
237 | - } else { |
|
238 | - $this->assertSame($expectedCycle['prefix'], $nextCycle['prefix']); |
|
239 | - $this->assertSame($expectedCycle['offset'], $nextCycle['offset']); |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - public function testQualifiesToRun(): void { |
|
244 | - $cycleData = ['prefix' => 's01']; |
|
245 | - |
|
246 | - $this->config->expects($this->exactly(2)) |
|
247 | - ->method('getAppValue') |
|
248 | - ->willReturnOnConsecutiveCalls(time() - 60 * 40, time() - 60 * 20); |
|
249 | - |
|
250 | - $this->sync->setArgument($this->arguments); |
|
251 | - $this->assertTrue($this->sync->qualifiesToRun($cycleData)); |
|
252 | - $this->assertFalse($this->sync->qualifiesToRun($cycleData)); |
|
253 | - } |
|
254 | - |
|
255 | - public static function runDataProvider(): array { |
|
256 | - return [ |
|
257 | - #0 - one LDAP server, reset |
|
258 | - [[ |
|
259 | - 'prefixes' => [''], |
|
260 | - 'scheduledCycle' => ['prefix' => '', 'offset' => '4500'], |
|
261 | - 'pagingSize' => 500, |
|
262 | - 'usersThisCycle' => 0, |
|
263 | - 'expectedNextCycle' => ['prefix' => '', 'offset' => '0'], |
|
264 | - 'mappedUsers' => 123, |
|
265 | - ]], |
|
266 | - #1 - 2 LDAP servers, next prefix |
|
267 | - [[ |
|
268 | - 'prefixes' => ['', 's01'], |
|
269 | - 'scheduledCycle' => ['prefix' => '', 'offset' => '4500'], |
|
270 | - 'pagingSize' => 500, |
|
271 | - 'usersThisCycle' => 0, |
|
272 | - 'expectedNextCycle' => ['prefix' => 's01', 'offset' => '0'], |
|
273 | - 'mappedUsers' => 123, |
|
274 | - ]], |
|
275 | - #2 - 2 LDAP servers, rotate prefix |
|
276 | - [[ |
|
277 | - 'prefixes' => ['', 's01'], |
|
278 | - 'scheduledCycle' => ['prefix' => 's01', 'offset' => '4500'], |
|
279 | - 'pagingSize' => 500, |
|
280 | - 'usersThisCycle' => 0, |
|
281 | - 'expectedNextCycle' => ['prefix' => '', 'offset' => '0'], |
|
282 | - 'mappedUsers' => 123, |
|
283 | - ]], |
|
284 | - ]; |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * @dataProvider runDataProvider |
|
289 | - */ |
|
290 | - public function testRun(array $runData): void { |
|
291 | - $this->config->expects($this->any()) |
|
292 | - ->method('getAppValue') |
|
293 | - ->willReturnCallback(function ($app, $key, $default) use ($runData) { |
|
294 | - if ($app === 'core' && $key === 'backgroundjobs_mode') { |
|
295 | - return 'cron'; |
|
296 | - } |
|
297 | - if ($app = 'user_ldap') { |
|
298 | - // for getCycle() |
|
299 | - if ($key === 'background_sync_prefix') { |
|
300 | - return $runData['scheduledCycle']['prefix']; |
|
301 | - } |
|
302 | - if ($key === 'background_sync_offset') { |
|
303 | - return $runData['scheduledCycle']['offset']; |
|
304 | - } |
|
305 | - // for qualifiesToRun() |
|
306 | - if ($key === $runData['scheduledCycle']['prefix'] . '_lastChange') { |
|
307 | - return time() - 60 * 40; |
|
308 | - } |
|
309 | - // for getMinPagingSize |
|
310 | - if ($key === $runData['scheduledCycle']['prefix'] . 'ldap_paging_size') { |
|
311 | - return $runData['pagingSize']; |
|
312 | - } |
|
313 | - } |
|
314 | - |
|
315 | - return $default; |
|
316 | - }); |
|
317 | - |
|
318 | - $calls = [ |
|
319 | - ['user_ldap', 'background_sync_prefix', $runData['expectedNextCycle']['prefix']], |
|
320 | - ['user_ldap', 'background_sync_offset', $runData['expectedNextCycle']['offset']], |
|
321 | - ['user_ldap', 'background_sync_interval', '43200'], |
|
322 | - ]; |
|
323 | - $this->config->expects($this->exactly(3)) |
|
324 | - ->method('setAppValue') |
|
325 | - ->willReturnCallback(function () use (&$calls) { |
|
326 | - $expected = array_shift($calls); |
|
327 | - $this->assertEquals($expected, func_get_args()); |
|
328 | - }); |
|
329 | - $this->config->expects($this->any()) |
|
330 | - ->method('getAppKeys') |
|
331 | - ->with('user_ldap') |
|
332 | - ->willReturn([$runData['scheduledCycle']['prefix'] . 'ldap_paging_size']); |
|
333 | - |
|
334 | - $this->helper->expects($this->any()) |
|
335 | - ->method('getServerConfigurationPrefixes') |
|
336 | - ->with(true) |
|
337 | - ->willReturn($runData['prefixes']); |
|
338 | - |
|
339 | - $connection = $this->getMockBuilder(Connection::class) |
|
340 | - ->setConstructorArgs([ |
|
341 | - $this->ldapWrapper, |
|
342 | - ]) |
|
343 | - ->getMock(); |
|
344 | - $this->connectionFactory->expects($this->any()) |
|
345 | - ->method('get') |
|
346 | - ->willReturn($connection); |
|
347 | - $connection->expects($this->any()) |
|
348 | - ->method('__get') |
|
349 | - ->willReturnCallback(function ($key) use ($runData) { |
|
350 | - if ($key === 'ldapPagingSize') { |
|
351 | - return $runData['pagingSize']; |
|
352 | - } |
|
353 | - return null; |
|
354 | - }); |
|
355 | - |
|
356 | - /** @var Access&MockObject $access */ |
|
357 | - $access = $this->createMock(Access::class); |
|
358 | - $this->accessFactory->expects($this->any()) |
|
359 | - ->method('get') |
|
360 | - ->with($connection) |
|
361 | - ->willReturn($access); |
|
362 | - |
|
363 | - $this->userManager->expects($this->any()) |
|
364 | - ->method('getAttributes') |
|
365 | - ->willReturn(['dn', 'uid', 'mail', 'displayname']); |
|
366 | - |
|
367 | - $access->expects($this->once()) |
|
368 | - ->method('fetchListOfUsers') |
|
369 | - ->willReturn(array_pad([], $runData['usersThisCycle'], 'someUser')); |
|
370 | - $access->expects($this->any()) |
|
371 | - ->method('combineFilterWithAnd') |
|
372 | - ->willReturn('pseudo=filter'); |
|
373 | - $access->connection = $connection; |
|
374 | - $access->userManager = $this->userManager; |
|
375 | - |
|
376 | - $this->mapper->expects($this->any()) |
|
377 | - ->method('count') |
|
378 | - ->willReturn($runData['mappedUsers']); |
|
379 | - |
|
380 | - $this->sync->run($this->arguments); |
|
381 | - } |
|
34 | + protected Helper&MockObject $helper; |
|
35 | + protected LDAP&MockObject $ldapWrapper; |
|
36 | + protected Manager&MockObject $userManager; |
|
37 | + protected UserMapping&MockObject $mapper; |
|
38 | + protected IConfig&MockObject $config; |
|
39 | + protected IAvatarManager&MockObject $avatarManager; |
|
40 | + protected IDBConnection&MockObject $dbc; |
|
41 | + protected IUserManager&MockObject $ncUserManager; |
|
42 | + protected IManager&MockObject $notificationManager; |
|
43 | + protected ConnectionFactory&MockObject $connectionFactory; |
|
44 | + protected AccessFactory&MockObject $accessFactory; |
|
45 | + protected array $arguments = []; |
|
46 | + protected Sync $sync; |
|
47 | + |
|
48 | + protected function setUp(): void { |
|
49 | + parent::setUp(); |
|
50 | + |
|
51 | + $this->helper = $this->createMock(Helper::class); |
|
52 | + $this->ldapWrapper = $this->createMock(LDAP::class); |
|
53 | + $this->userManager = $this->createMock(Manager::class); |
|
54 | + $this->mapper = $this->createMock(UserMapping::class); |
|
55 | + $this->config = $this->createMock(IConfig::class); |
|
56 | + $this->avatarManager = $this->createMock(IAvatarManager::class); |
|
57 | + $this->dbc = $this->createMock(IDBConnection::class); |
|
58 | + $this->ncUserManager = $this->createMock(IUserManager::class); |
|
59 | + $this->notificationManager = $this->createMock(IManager::class); |
|
60 | + $this->connectionFactory = $this->getMockBuilder(ConnectionFactory::class) |
|
61 | + ->setConstructorArgs([ |
|
62 | + $this->ldapWrapper, |
|
63 | + ]) |
|
64 | + ->getMock(); |
|
65 | + $this->accessFactory = $this->createMock(AccessFactory::class); |
|
66 | + |
|
67 | + $this->sync = new Sync( |
|
68 | + Server::get(ITimeFactory::class), |
|
69 | + Server::get(IEventDispatcher::class), |
|
70 | + $this->config, |
|
71 | + $this->dbc, |
|
72 | + $this->avatarManager, |
|
73 | + $this->ncUserManager, |
|
74 | + Server::get(LoggerInterface::class), |
|
75 | + $this->notificationManager, |
|
76 | + $this->mapper, |
|
77 | + $this->helper, |
|
78 | + $this->connectionFactory, |
|
79 | + $this->accessFactory, |
|
80 | + ); |
|
81 | + |
|
82 | + $this->sync->overwritePropertiesForTest($this->ldapWrapper); |
|
83 | + } |
|
84 | + |
|
85 | + public static function intervalDataProvider(): array { |
|
86 | + return [ |
|
87 | + [ |
|
88 | + 0, 1000, 750 |
|
89 | + ], |
|
90 | + [ |
|
91 | + 22, 0, 50 |
|
92 | + ], |
|
93 | + [ |
|
94 | + 500, 500, 500 |
|
95 | + ], |
|
96 | + [ |
|
97 | + 1357, 0, 0 |
|
98 | + ], |
|
99 | + [ |
|
100 | + 421337, 2000, 3000 |
|
101 | + ] |
|
102 | + ]; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @dataProvider intervalDataProvider |
|
107 | + */ |
|
108 | + public function testUpdateInterval(int $userCount, int $pagingSize1, int $pagingSize2): void { |
|
109 | + $this->config->expects($this->once()) |
|
110 | + ->method('setAppValue') |
|
111 | + ->with('user_ldap', 'background_sync_interval', $this->anything()) |
|
112 | + ->willReturnCallback(function ($a, $k, $interval) { |
|
113 | + $this->assertTrue($interval >= SYNC::MIN_INTERVAL); |
|
114 | + $this->assertTrue($interval <= SYNC::MAX_INTERVAL); |
|
115 | + return true; |
|
116 | + }); |
|
117 | + $this->config->expects($this->atLeastOnce()) |
|
118 | + ->method('getAppKeys') |
|
119 | + ->willReturn([ |
|
120 | + 'blabla', |
|
121 | + 'ldap_paging_size', |
|
122 | + 's07blabla', |
|
123 | + 'installed', |
|
124 | + 's07ldap_paging_size' |
|
125 | + ]); |
|
126 | + $this->config->expects($this->exactly(2)) |
|
127 | + ->method('getAppValue') |
|
128 | + ->willReturnOnConsecutiveCalls($pagingSize1, $pagingSize2); |
|
129 | + |
|
130 | + $this->mapper->expects($this->atLeastOnce()) |
|
131 | + ->method('count') |
|
132 | + ->willReturn($userCount); |
|
133 | + |
|
134 | + $this->sync->setArgument($this->arguments); |
|
135 | + $this->sync->updateInterval(); |
|
136 | + } |
|
137 | + |
|
138 | + public static function moreResultsProvider(): array { |
|
139 | + return [ |
|
140 | + [ 3, 3, true ], |
|
141 | + [ 3, 5, true ], |
|
142 | + [ 3, 2, false], |
|
143 | + [ 0, 4, false], |
|
144 | + [ null, 4, false] |
|
145 | + ]; |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * @dataProvider moreResultsProvider |
|
150 | + */ |
|
151 | + public function testMoreResults($pagingSize, $results, $expected): void { |
|
152 | + $connection = $this->getMockBuilder(Connection::class) |
|
153 | + ->setConstructorArgs([ |
|
154 | + $this->ldapWrapper, |
|
155 | + ]) |
|
156 | + ->getMock(); |
|
157 | + $this->connectionFactory->expects($this->any()) |
|
158 | + ->method('get') |
|
159 | + ->willReturn($connection); |
|
160 | + $connection->expects($this->any()) |
|
161 | + ->method('__get') |
|
162 | + ->willReturnCallback(function ($key) use ($pagingSize) { |
|
163 | + if ($key === 'ldapPagingSize') { |
|
164 | + return $pagingSize; |
|
165 | + } |
|
166 | + return null; |
|
167 | + }); |
|
168 | + |
|
169 | + /** @var Access&MockObject $access */ |
|
170 | + $access = $this->createMock(Access::class); |
|
171 | + $this->accessFactory->expects($this->any()) |
|
172 | + ->method('get') |
|
173 | + ->with($connection) |
|
174 | + ->willReturn($access); |
|
175 | + |
|
176 | + $this->userManager->expects($this->any()) |
|
177 | + ->method('getAttributes') |
|
178 | + ->willReturn(['dn', 'uid', 'mail', 'displayname']); |
|
179 | + |
|
180 | + $access->expects($this->once()) |
|
181 | + ->method('fetchListOfUsers') |
|
182 | + ->willReturn(array_pad([], $results, 'someUser')); |
|
183 | + $access->expects($this->any()) |
|
184 | + ->method('combineFilterWithAnd') |
|
185 | + ->willReturn('pseudo=filter'); |
|
186 | + $access->connection = $connection; |
|
187 | + $access->userManager = $this->userManager; |
|
188 | + |
|
189 | + $this->sync->setArgument($this->arguments); |
|
190 | + $hasMoreResults = $this->sync->runCycle(['prefix' => 's01', 'offset' => 100]); |
|
191 | + $this->assertSame($expected, $hasMoreResults); |
|
192 | + } |
|
193 | + |
|
194 | + public static function cycleDataProvider(): array { |
|
195 | + $lastCycle = ['prefix' => 's01', 'offset' => 1000]; |
|
196 | + $lastCycle2 = ['prefix' => '', 'offset' => 1000]; |
|
197 | + return [ |
|
198 | + [ null, ['s01'], ['prefix' => 's01', 'offset' => 0] ], |
|
199 | + [ null, [''], ['prefix' => '', 'offset' => 0] ], |
|
200 | + [ $lastCycle, ['s01', 's02'], ['prefix' => 's02', 'offset' => 0] ], |
|
201 | + [ $lastCycle, [''], ['prefix' => '', 'offset' => 0] ], |
|
202 | + [ $lastCycle2, ['', 's01'], ['prefix' => 's01', 'offset' => 0] ], |
|
203 | + [ $lastCycle, [], null ], |
|
204 | + ]; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * @dataProvider cycleDataProvider |
|
209 | + */ |
|
210 | + public function testDetermineNextCycle(?array $cycleData, array $prefixes, ?array $expectedCycle): void { |
|
211 | + $this->helper->expects($this->any()) |
|
212 | + ->method('getServerConfigurationPrefixes') |
|
213 | + ->with(true) |
|
214 | + ->willReturn($prefixes); |
|
215 | + |
|
216 | + if (is_array($expectedCycle)) { |
|
217 | + $calls = [ |
|
218 | + ['user_ldap', 'background_sync_prefix', $expectedCycle['prefix']], |
|
219 | + ['user_ldap', 'background_sync_offset', $expectedCycle['offset']], |
|
220 | + ]; |
|
221 | + $this->config->expects($this->exactly(2)) |
|
222 | + ->method('setAppValue') |
|
223 | + ->willReturnCallback(function () use (&$calls) { |
|
224 | + $expected = array_shift($calls); |
|
225 | + $this->assertEquals($expected, func_get_args()); |
|
226 | + }); |
|
227 | + } else { |
|
228 | + $this->config->expects($this->never()) |
|
229 | + ->method('setAppValue'); |
|
230 | + } |
|
231 | + |
|
232 | + $this->sync->setArgument($this->arguments); |
|
233 | + $nextCycle = $this->sync->determineNextCycle($cycleData); |
|
234 | + |
|
235 | + if ($expectedCycle === null) { |
|
236 | + $this->assertNull($nextCycle); |
|
237 | + } else { |
|
238 | + $this->assertSame($expectedCycle['prefix'], $nextCycle['prefix']); |
|
239 | + $this->assertSame($expectedCycle['offset'], $nextCycle['offset']); |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + public function testQualifiesToRun(): void { |
|
244 | + $cycleData = ['prefix' => 's01']; |
|
245 | + |
|
246 | + $this->config->expects($this->exactly(2)) |
|
247 | + ->method('getAppValue') |
|
248 | + ->willReturnOnConsecutiveCalls(time() - 60 * 40, time() - 60 * 20); |
|
249 | + |
|
250 | + $this->sync->setArgument($this->arguments); |
|
251 | + $this->assertTrue($this->sync->qualifiesToRun($cycleData)); |
|
252 | + $this->assertFalse($this->sync->qualifiesToRun($cycleData)); |
|
253 | + } |
|
254 | + |
|
255 | + public static function runDataProvider(): array { |
|
256 | + return [ |
|
257 | + #0 - one LDAP server, reset |
|
258 | + [[ |
|
259 | + 'prefixes' => [''], |
|
260 | + 'scheduledCycle' => ['prefix' => '', 'offset' => '4500'], |
|
261 | + 'pagingSize' => 500, |
|
262 | + 'usersThisCycle' => 0, |
|
263 | + 'expectedNextCycle' => ['prefix' => '', 'offset' => '0'], |
|
264 | + 'mappedUsers' => 123, |
|
265 | + ]], |
|
266 | + #1 - 2 LDAP servers, next prefix |
|
267 | + [[ |
|
268 | + 'prefixes' => ['', 's01'], |
|
269 | + 'scheduledCycle' => ['prefix' => '', 'offset' => '4500'], |
|
270 | + 'pagingSize' => 500, |
|
271 | + 'usersThisCycle' => 0, |
|
272 | + 'expectedNextCycle' => ['prefix' => 's01', 'offset' => '0'], |
|
273 | + 'mappedUsers' => 123, |
|
274 | + ]], |
|
275 | + #2 - 2 LDAP servers, rotate prefix |
|
276 | + [[ |
|
277 | + 'prefixes' => ['', 's01'], |
|
278 | + 'scheduledCycle' => ['prefix' => 's01', 'offset' => '4500'], |
|
279 | + 'pagingSize' => 500, |
|
280 | + 'usersThisCycle' => 0, |
|
281 | + 'expectedNextCycle' => ['prefix' => '', 'offset' => '0'], |
|
282 | + 'mappedUsers' => 123, |
|
283 | + ]], |
|
284 | + ]; |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * @dataProvider runDataProvider |
|
289 | + */ |
|
290 | + public function testRun(array $runData): void { |
|
291 | + $this->config->expects($this->any()) |
|
292 | + ->method('getAppValue') |
|
293 | + ->willReturnCallback(function ($app, $key, $default) use ($runData) { |
|
294 | + if ($app === 'core' && $key === 'backgroundjobs_mode') { |
|
295 | + return 'cron'; |
|
296 | + } |
|
297 | + if ($app = 'user_ldap') { |
|
298 | + // for getCycle() |
|
299 | + if ($key === 'background_sync_prefix') { |
|
300 | + return $runData['scheduledCycle']['prefix']; |
|
301 | + } |
|
302 | + if ($key === 'background_sync_offset') { |
|
303 | + return $runData['scheduledCycle']['offset']; |
|
304 | + } |
|
305 | + // for qualifiesToRun() |
|
306 | + if ($key === $runData['scheduledCycle']['prefix'] . '_lastChange') { |
|
307 | + return time() - 60 * 40; |
|
308 | + } |
|
309 | + // for getMinPagingSize |
|
310 | + if ($key === $runData['scheduledCycle']['prefix'] . 'ldap_paging_size') { |
|
311 | + return $runData['pagingSize']; |
|
312 | + } |
|
313 | + } |
|
314 | + |
|
315 | + return $default; |
|
316 | + }); |
|
317 | + |
|
318 | + $calls = [ |
|
319 | + ['user_ldap', 'background_sync_prefix', $runData['expectedNextCycle']['prefix']], |
|
320 | + ['user_ldap', 'background_sync_offset', $runData['expectedNextCycle']['offset']], |
|
321 | + ['user_ldap', 'background_sync_interval', '43200'], |
|
322 | + ]; |
|
323 | + $this->config->expects($this->exactly(3)) |
|
324 | + ->method('setAppValue') |
|
325 | + ->willReturnCallback(function () use (&$calls) { |
|
326 | + $expected = array_shift($calls); |
|
327 | + $this->assertEquals($expected, func_get_args()); |
|
328 | + }); |
|
329 | + $this->config->expects($this->any()) |
|
330 | + ->method('getAppKeys') |
|
331 | + ->with('user_ldap') |
|
332 | + ->willReturn([$runData['scheduledCycle']['prefix'] . 'ldap_paging_size']); |
|
333 | + |
|
334 | + $this->helper->expects($this->any()) |
|
335 | + ->method('getServerConfigurationPrefixes') |
|
336 | + ->with(true) |
|
337 | + ->willReturn($runData['prefixes']); |
|
338 | + |
|
339 | + $connection = $this->getMockBuilder(Connection::class) |
|
340 | + ->setConstructorArgs([ |
|
341 | + $this->ldapWrapper, |
|
342 | + ]) |
|
343 | + ->getMock(); |
|
344 | + $this->connectionFactory->expects($this->any()) |
|
345 | + ->method('get') |
|
346 | + ->willReturn($connection); |
|
347 | + $connection->expects($this->any()) |
|
348 | + ->method('__get') |
|
349 | + ->willReturnCallback(function ($key) use ($runData) { |
|
350 | + if ($key === 'ldapPagingSize') { |
|
351 | + return $runData['pagingSize']; |
|
352 | + } |
|
353 | + return null; |
|
354 | + }); |
|
355 | + |
|
356 | + /** @var Access&MockObject $access */ |
|
357 | + $access = $this->createMock(Access::class); |
|
358 | + $this->accessFactory->expects($this->any()) |
|
359 | + ->method('get') |
|
360 | + ->with($connection) |
|
361 | + ->willReturn($access); |
|
362 | + |
|
363 | + $this->userManager->expects($this->any()) |
|
364 | + ->method('getAttributes') |
|
365 | + ->willReturn(['dn', 'uid', 'mail', 'displayname']); |
|
366 | + |
|
367 | + $access->expects($this->once()) |
|
368 | + ->method('fetchListOfUsers') |
|
369 | + ->willReturn(array_pad([], $runData['usersThisCycle'], 'someUser')); |
|
370 | + $access->expects($this->any()) |
|
371 | + ->method('combineFilterWithAnd') |
|
372 | + ->willReturn('pseudo=filter'); |
|
373 | + $access->connection = $connection; |
|
374 | + $access->userManager = $this->userManager; |
|
375 | + |
|
376 | + $this->mapper->expects($this->any()) |
|
377 | + ->method('count') |
|
378 | + ->willReturn($runData['mappedUsers']); |
|
379 | + |
|
380 | + $this->sync->run($this->arguments); |
|
381 | + } |
|
382 | 382 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | 0, 1000, 750 |
89 | 89 | ], |
90 | 90 | [ |
91 | - 22, 0, 50 |
|
91 | + 22, 0, 50 |
|
92 | 92 | ], |
93 | 93 | [ |
94 | 94 | 500, 500, 500 |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | $this->config->expects($this->once()) |
110 | 110 | ->method('setAppValue') |
111 | 111 | ->with('user_ldap', 'background_sync_interval', $this->anything()) |
112 | - ->willReturnCallback(function ($a, $k, $interval) { |
|
112 | + ->willReturnCallback(function($a, $k, $interval) { |
|
113 | 113 | $this->assertTrue($interval >= SYNC::MIN_INTERVAL); |
114 | 114 | $this->assertTrue($interval <= SYNC::MAX_INTERVAL); |
115 | 115 | return true; |
@@ -137,11 +137,11 @@ discard block |
||
137 | 137 | |
138 | 138 | public static function moreResultsProvider(): array { |
139 | 139 | return [ |
140 | - [ 3, 3, true ], |
|
141 | - [ 3, 5, true ], |
|
142 | - [ 3, 2, false], |
|
143 | - [ 0, 4, false], |
|
144 | - [ null, 4, false] |
|
140 | + [3, 3, true], |
|
141 | + [3, 5, true], |
|
142 | + [3, 2, false], |
|
143 | + [0, 4, false], |
|
144 | + [null, 4, false] |
|
145 | 145 | ]; |
146 | 146 | } |
147 | 147 | |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | ->willReturn($connection); |
160 | 160 | $connection->expects($this->any()) |
161 | 161 | ->method('__get') |
162 | - ->willReturnCallback(function ($key) use ($pagingSize) { |
|
162 | + ->willReturnCallback(function($key) use ($pagingSize) { |
|
163 | 163 | if ($key === 'ldapPagingSize') { |
164 | 164 | return $pagingSize; |
165 | 165 | } |
@@ -195,12 +195,12 @@ discard block |
||
195 | 195 | $lastCycle = ['prefix' => 's01', 'offset' => 1000]; |
196 | 196 | $lastCycle2 = ['prefix' => '', 'offset' => 1000]; |
197 | 197 | return [ |
198 | - [ null, ['s01'], ['prefix' => 's01', 'offset' => 0] ], |
|
199 | - [ null, [''], ['prefix' => '', 'offset' => 0] ], |
|
200 | - [ $lastCycle, ['s01', 's02'], ['prefix' => 's02', 'offset' => 0] ], |
|
201 | - [ $lastCycle, [''], ['prefix' => '', 'offset' => 0] ], |
|
202 | - [ $lastCycle2, ['', 's01'], ['prefix' => 's01', 'offset' => 0] ], |
|
203 | - [ $lastCycle, [], null ], |
|
198 | + [null, ['s01'], ['prefix' => 's01', 'offset' => 0]], |
|
199 | + [null, [''], ['prefix' => '', 'offset' => 0]], |
|
200 | + [$lastCycle, ['s01', 's02'], ['prefix' => 's02', 'offset' => 0]], |
|
201 | + [$lastCycle, [''], ['prefix' => '', 'offset' => 0]], |
|
202 | + [$lastCycle2, ['', 's01'], ['prefix' => 's01', 'offset' => 0]], |
|
203 | + [$lastCycle, [], null], |
|
204 | 204 | ]; |
205 | 205 | } |
206 | 206 | |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | ]; |
221 | 221 | $this->config->expects($this->exactly(2)) |
222 | 222 | ->method('setAppValue') |
223 | - ->willReturnCallback(function () use (&$calls) { |
|
223 | + ->willReturnCallback(function() use (&$calls) { |
|
224 | 224 | $expected = array_shift($calls); |
225 | 225 | $this->assertEquals($expected, func_get_args()); |
226 | 226 | }); |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | public function testRun(array $runData): void { |
291 | 291 | $this->config->expects($this->any()) |
292 | 292 | ->method('getAppValue') |
293 | - ->willReturnCallback(function ($app, $key, $default) use ($runData) { |
|
293 | + ->willReturnCallback(function($app, $key, $default) use ($runData) { |
|
294 | 294 | if ($app === 'core' && $key === 'backgroundjobs_mode') { |
295 | 295 | return 'cron'; |
296 | 296 | } |
@@ -303,11 +303,11 @@ discard block |
||
303 | 303 | return $runData['scheduledCycle']['offset']; |
304 | 304 | } |
305 | 305 | // for qualifiesToRun() |
306 | - if ($key === $runData['scheduledCycle']['prefix'] . '_lastChange') { |
|
306 | + if ($key === $runData['scheduledCycle']['prefix'].'_lastChange') { |
|
307 | 307 | return time() - 60 * 40; |
308 | 308 | } |
309 | 309 | // for getMinPagingSize |
310 | - if ($key === $runData['scheduledCycle']['prefix'] . 'ldap_paging_size') { |
|
310 | + if ($key === $runData['scheduledCycle']['prefix'].'ldap_paging_size') { |
|
311 | 311 | return $runData['pagingSize']; |
312 | 312 | } |
313 | 313 | } |
@@ -322,14 +322,14 @@ discard block |
||
322 | 322 | ]; |
323 | 323 | $this->config->expects($this->exactly(3)) |
324 | 324 | ->method('setAppValue') |
325 | - ->willReturnCallback(function () use (&$calls) { |
|
325 | + ->willReturnCallback(function() use (&$calls) { |
|
326 | 326 | $expected = array_shift($calls); |
327 | 327 | $this->assertEquals($expected, func_get_args()); |
328 | 328 | }); |
329 | 329 | $this->config->expects($this->any()) |
330 | 330 | ->method('getAppKeys') |
331 | 331 | ->with('user_ldap') |
332 | - ->willReturn([$runData['scheduledCycle']['prefix'] . 'ldap_paging_size']); |
|
332 | + ->willReturn([$runData['scheduledCycle']['prefix'].'ldap_paging_size']); |
|
333 | 333 | |
334 | 334 | $this->helper->expects($this->any()) |
335 | 335 | ->method('getServerConfigurationPrefixes') |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | ->willReturn($connection); |
347 | 347 | $connection->expects($this->any()) |
348 | 348 | ->method('__get') |
349 | - ->willReturnCallback(function ($key) use ($runData) { |
|
349 | + ->willReturnCallback(function($key) use ($runData) { |
|
350 | 350 | if ($key === 'ldapPagingSize') { |
351 | 351 | return $runData['pagingSize']; |
352 | 352 | } |
@@ -19,102 +19,102 @@ |
||
19 | 19 | use Test\TestCase; |
20 | 20 | |
21 | 21 | class CleanUpTest extends TestCase { |
22 | - protected CleanUp $bgJob; |
|
23 | - protected array $mocks; |
|
24 | - |
|
25 | - public function setUp(): void { |
|
26 | - parent::setUp(); |
|
27 | - $this->createMocks(); |
|
28 | - $this->bgJob = new CleanUp($this->mocks['timeFactory'], $this->mocks['userBackend'], $this->mocks['deletedUsersIndex']); |
|
29 | - $this->bgJob->setArguments($this->mocks); |
|
30 | - } |
|
31 | - |
|
32 | - protected function createMocks(): void { |
|
33 | - $this->mocks = []; |
|
34 | - $this->mocks['userBackend'] = $this->createMock(User_Proxy::class); |
|
35 | - $this->mocks['deletedUsersIndex'] = $this->createMock(DeletedUsersIndex::class); |
|
36 | - $this->mocks['ocConfig'] = $this->createMock(IConfig::class); |
|
37 | - $this->mocks['db'] = $this->createMock(IDBConnection::class); |
|
38 | - $this->mocks['helper'] = $this->createMock(Helper::class); |
|
39 | - $this->mocks['timeFactory'] = $this->createMock(ITimeFactory::class); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * clean up job must not run when there are disabled configurations |
|
44 | - */ |
|
45 | - public function test_runNotAllowedByDisabledConfigurations(): void { |
|
46 | - $this->mocks['helper']->expects($this->once()) |
|
47 | - ->method('haveDisabledConfigurations') |
|
48 | - ->willReturn(true); |
|
49 | - |
|
50 | - $this->mocks['ocConfig']->expects($this->never()) |
|
51 | - ->method('getSystemValue'); |
|
52 | - |
|
53 | - $result = $this->bgJob->isCleanUpAllowed(); |
|
54 | - $this->assertSame(false, $result); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * clean up job must not run when LDAP Helper is broken i.e. |
|
59 | - * returning unexpected results |
|
60 | - */ |
|
61 | - public function test_runNotAllowedByBrokenHelper(): void { |
|
62 | - $this->mocks['helper']->expects($this->once()) |
|
63 | - ->method('haveDisabledConfigurations') |
|
64 | - ->will($this->throwException(new Exception())); |
|
65 | - |
|
66 | - $this->mocks['ocConfig']->expects($this->never()) |
|
67 | - ->method('getSystemValue'); |
|
68 | - |
|
69 | - $result = $this->bgJob->isCleanUpAllowed(); |
|
70 | - $this->assertSame(false, $result); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * clean up job must not run when it is not enabled |
|
75 | - */ |
|
76 | - public function test_runNotAllowedBySysConfig(): void { |
|
77 | - $this->mocks['helper']->expects($this->once()) |
|
78 | - ->method('haveDisabledConfigurations') |
|
79 | - ->willReturn(false); |
|
80 | - |
|
81 | - $this->mocks['ocConfig']->expects($this->once()) |
|
82 | - ->method('getSystemValue') |
|
83 | - ->willReturn(false); |
|
84 | - |
|
85 | - $result = $this->bgJob->isCleanUpAllowed(); |
|
86 | - $this->assertSame(false, $result); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * clean up job is allowed to run |
|
91 | - */ |
|
92 | - public function test_runIsAllowed(): void { |
|
93 | - $this->mocks['helper']->expects($this->once()) |
|
94 | - ->method('haveDisabledConfigurations') |
|
95 | - ->willReturn(false); |
|
96 | - |
|
97 | - $this->mocks['ocConfig']->expects($this->once()) |
|
98 | - ->method('getSystemValue') |
|
99 | - ->willReturn(true); |
|
100 | - |
|
101 | - $result = $this->bgJob->isCleanUpAllowed(); |
|
102 | - $this->assertSame(true, $result); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * check whether offset will be reset when it needs to |
|
107 | - */ |
|
108 | - public function test_OffsetResetIsNecessary(): void { |
|
109 | - $result = $this->bgJob->isOffsetResetNecessary($this->bgJob->getChunkSize() - 1); |
|
110 | - $this->assertSame(true, $result); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * make sure offset is not reset when it is not due |
|
115 | - */ |
|
116 | - public function test_OffsetResetIsNotNecessary(): void { |
|
117 | - $result = $this->bgJob->isOffsetResetNecessary($this->bgJob->getChunkSize()); |
|
118 | - $this->assertSame(false, $result); |
|
119 | - } |
|
22 | + protected CleanUp $bgJob; |
|
23 | + protected array $mocks; |
|
24 | + |
|
25 | + public function setUp(): void { |
|
26 | + parent::setUp(); |
|
27 | + $this->createMocks(); |
|
28 | + $this->bgJob = new CleanUp($this->mocks['timeFactory'], $this->mocks['userBackend'], $this->mocks['deletedUsersIndex']); |
|
29 | + $this->bgJob->setArguments($this->mocks); |
|
30 | + } |
|
31 | + |
|
32 | + protected function createMocks(): void { |
|
33 | + $this->mocks = []; |
|
34 | + $this->mocks['userBackend'] = $this->createMock(User_Proxy::class); |
|
35 | + $this->mocks['deletedUsersIndex'] = $this->createMock(DeletedUsersIndex::class); |
|
36 | + $this->mocks['ocConfig'] = $this->createMock(IConfig::class); |
|
37 | + $this->mocks['db'] = $this->createMock(IDBConnection::class); |
|
38 | + $this->mocks['helper'] = $this->createMock(Helper::class); |
|
39 | + $this->mocks['timeFactory'] = $this->createMock(ITimeFactory::class); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * clean up job must not run when there are disabled configurations |
|
44 | + */ |
|
45 | + public function test_runNotAllowedByDisabledConfigurations(): void { |
|
46 | + $this->mocks['helper']->expects($this->once()) |
|
47 | + ->method('haveDisabledConfigurations') |
|
48 | + ->willReturn(true); |
|
49 | + |
|
50 | + $this->mocks['ocConfig']->expects($this->never()) |
|
51 | + ->method('getSystemValue'); |
|
52 | + |
|
53 | + $result = $this->bgJob->isCleanUpAllowed(); |
|
54 | + $this->assertSame(false, $result); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * clean up job must not run when LDAP Helper is broken i.e. |
|
59 | + * returning unexpected results |
|
60 | + */ |
|
61 | + public function test_runNotAllowedByBrokenHelper(): void { |
|
62 | + $this->mocks['helper']->expects($this->once()) |
|
63 | + ->method('haveDisabledConfigurations') |
|
64 | + ->will($this->throwException(new Exception())); |
|
65 | + |
|
66 | + $this->mocks['ocConfig']->expects($this->never()) |
|
67 | + ->method('getSystemValue'); |
|
68 | + |
|
69 | + $result = $this->bgJob->isCleanUpAllowed(); |
|
70 | + $this->assertSame(false, $result); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * clean up job must not run when it is not enabled |
|
75 | + */ |
|
76 | + public function test_runNotAllowedBySysConfig(): void { |
|
77 | + $this->mocks['helper']->expects($this->once()) |
|
78 | + ->method('haveDisabledConfigurations') |
|
79 | + ->willReturn(false); |
|
80 | + |
|
81 | + $this->mocks['ocConfig']->expects($this->once()) |
|
82 | + ->method('getSystemValue') |
|
83 | + ->willReturn(false); |
|
84 | + |
|
85 | + $result = $this->bgJob->isCleanUpAllowed(); |
|
86 | + $this->assertSame(false, $result); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * clean up job is allowed to run |
|
91 | + */ |
|
92 | + public function test_runIsAllowed(): void { |
|
93 | + $this->mocks['helper']->expects($this->once()) |
|
94 | + ->method('haveDisabledConfigurations') |
|
95 | + ->willReturn(false); |
|
96 | + |
|
97 | + $this->mocks['ocConfig']->expects($this->once()) |
|
98 | + ->method('getSystemValue') |
|
99 | + ->willReturn(true); |
|
100 | + |
|
101 | + $result = $this->bgJob->isCleanUpAllowed(); |
|
102 | + $this->assertSame(true, $result); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * check whether offset will be reset when it needs to |
|
107 | + */ |
|
108 | + public function test_OffsetResetIsNecessary(): void { |
|
109 | + $result = $this->bgJob->isOffsetResetNecessary($this->bgJob->getChunkSize() - 1); |
|
110 | + $this->assertSame(true, $result); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * make sure offset is not reset when it is not due |
|
115 | + */ |
|
116 | + public function test_OffsetResetIsNotNecessary(): void { |
|
117 | + $result = $this->bgJob->isOffsetResetNecessary($this->bgJob->getChunkSize()); |
|
118 | + $this->assertSame(false, $result); |
|
119 | + } |
|
120 | 120 | } |
@@ -24,114 +24,114 @@ |
||
24 | 24 | use Test\TestCase; |
25 | 25 | |
26 | 26 | class UpdateGroupsServiceTest extends TestCase { |
27 | - protected Group_Proxy&MockObject $groupBackend; |
|
28 | - protected IEventDispatcher&MockObject $dispatcher; |
|
29 | - protected IGroupManager&MockObject $groupManager; |
|
30 | - protected IUserManager&MockObject $userManager; |
|
31 | - protected LoggerInterface&MockObject $logger; |
|
32 | - protected GroupMembershipMapper&MockObject $groupMembershipMapper; |
|
33 | - protected UpdateGroupsService $updateGroupsService; |
|
27 | + protected Group_Proxy&MockObject $groupBackend; |
|
28 | + protected IEventDispatcher&MockObject $dispatcher; |
|
29 | + protected IGroupManager&MockObject $groupManager; |
|
30 | + protected IUserManager&MockObject $userManager; |
|
31 | + protected LoggerInterface&MockObject $logger; |
|
32 | + protected GroupMembershipMapper&MockObject $groupMembershipMapper; |
|
33 | + protected UpdateGroupsService $updateGroupsService; |
|
34 | 34 | |
35 | - public function setUp(): void { |
|
36 | - $this->groupBackend = $this->createMock(Group_Proxy::class); |
|
37 | - $this->dispatcher = $this->createMock(IEventDispatcher::class); |
|
38 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
39 | - $this->userManager = $this->createMock(IUserManager::class); |
|
40 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
41 | - $this->groupMembershipMapper = $this->createMock(GroupMembershipMapper::class); |
|
35 | + public function setUp(): void { |
|
36 | + $this->groupBackend = $this->createMock(Group_Proxy::class); |
|
37 | + $this->dispatcher = $this->createMock(IEventDispatcher::class); |
|
38 | + $this->groupManager = $this->createMock(IGroupManager::class); |
|
39 | + $this->userManager = $this->createMock(IUserManager::class); |
|
40 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
41 | + $this->groupMembershipMapper = $this->createMock(GroupMembershipMapper::class); |
|
42 | 42 | |
43 | - $this->updateGroupsService = new UpdateGroupsService( |
|
44 | - $this->groupBackend, |
|
45 | - $this->dispatcher, |
|
46 | - $this->groupManager, |
|
47 | - $this->userManager, |
|
48 | - $this->logger, |
|
49 | - $this->groupMembershipMapper, |
|
50 | - ); |
|
51 | - } |
|
43 | + $this->updateGroupsService = new UpdateGroupsService( |
|
44 | + $this->groupBackend, |
|
45 | + $this->dispatcher, |
|
46 | + $this->groupManager, |
|
47 | + $this->userManager, |
|
48 | + $this->logger, |
|
49 | + $this->groupMembershipMapper, |
|
50 | + ); |
|
51 | + } |
|
52 | 52 | |
53 | - public function testHandleKnownGroups(): void { |
|
54 | - $knownGroups = [ |
|
55 | - 'emptyGroup' => [], |
|
56 | - 'stableGroup' => ['userA', 'userC', 'userE'], |
|
57 | - 'groupWithAdditions' => ['userA', 'userC', 'userE'], |
|
58 | - 'groupWithRemovals' => ['userA', 'userC', 'userDeleted', 'userE'], |
|
59 | - 'groupWithAdditionsAndRemovals' => ['userA', 'userC', 'userE'], |
|
60 | - 'vanishedGroup' => ['userB', 'userDeleted'], |
|
61 | - ]; |
|
62 | - $knownGroupsDB = []; |
|
63 | - foreach ($knownGroups as $gid => $members) { |
|
64 | - $knownGroupsDB[] = [ |
|
65 | - 'owncloudname' => $gid, |
|
66 | - 'owncloudusers' => $members |
|
67 | - ]; |
|
68 | - } |
|
69 | - $actualGroups = [ |
|
70 | - 'emptyGroup' => [], |
|
71 | - 'stableGroup' => ['userA', 'userC', 'userE'], |
|
72 | - 'groupWithAdditions' => ['userA', 'userC', 'userE', 'userF'], |
|
73 | - 'groupWithRemovals' => ['userA', 'userE'], |
|
74 | - 'groupWithAdditionsAndRemovals' => ['userC', 'userE', 'userF'], |
|
75 | - 'newGroup' => ['userB', 'userF'], |
|
76 | - ]; |
|
77 | - $groups = array_intersect(array_keys($knownGroups), array_keys($actualGroups)); |
|
53 | + public function testHandleKnownGroups(): void { |
|
54 | + $knownGroups = [ |
|
55 | + 'emptyGroup' => [], |
|
56 | + 'stableGroup' => ['userA', 'userC', 'userE'], |
|
57 | + 'groupWithAdditions' => ['userA', 'userC', 'userE'], |
|
58 | + 'groupWithRemovals' => ['userA', 'userC', 'userDeleted', 'userE'], |
|
59 | + 'groupWithAdditionsAndRemovals' => ['userA', 'userC', 'userE'], |
|
60 | + 'vanishedGroup' => ['userB', 'userDeleted'], |
|
61 | + ]; |
|
62 | + $knownGroupsDB = []; |
|
63 | + foreach ($knownGroups as $gid => $members) { |
|
64 | + $knownGroupsDB[] = [ |
|
65 | + 'owncloudname' => $gid, |
|
66 | + 'owncloudusers' => $members |
|
67 | + ]; |
|
68 | + } |
|
69 | + $actualGroups = [ |
|
70 | + 'emptyGroup' => [], |
|
71 | + 'stableGroup' => ['userA', 'userC', 'userE'], |
|
72 | + 'groupWithAdditions' => ['userA', 'userC', 'userE', 'userF'], |
|
73 | + 'groupWithRemovals' => ['userA', 'userE'], |
|
74 | + 'groupWithAdditionsAndRemovals' => ['userC', 'userE', 'userF'], |
|
75 | + 'newGroup' => ['userB', 'userF'], |
|
76 | + ]; |
|
77 | + $groups = array_intersect(array_keys($knownGroups), array_keys($actualGroups)); |
|
78 | 78 | |
79 | - $this->groupMembershipMapper->expects($this->never()) |
|
80 | - ->method('getKnownGroups'); |
|
81 | - $this->groupMembershipMapper->expects($this->exactly(5)) |
|
82 | - ->method('findGroupMemberships') |
|
83 | - ->willReturnCallback( |
|
84 | - fn ($group) => array_map( |
|
85 | - fn ($userid) => GroupMembership::fromParams(['groupid' => $group,'userid' => $userid]), |
|
86 | - $knownGroups[$group] |
|
87 | - ) |
|
88 | - ); |
|
89 | - $this->groupMembershipMapper->expects($this->exactly(3)) |
|
90 | - ->method('delete'); |
|
91 | - $this->groupMembershipMapper->expects($this->exactly(2)) |
|
92 | - ->method('insert'); |
|
79 | + $this->groupMembershipMapper->expects($this->never()) |
|
80 | + ->method('getKnownGroups'); |
|
81 | + $this->groupMembershipMapper->expects($this->exactly(5)) |
|
82 | + ->method('findGroupMemberships') |
|
83 | + ->willReturnCallback( |
|
84 | + fn ($group) => array_map( |
|
85 | + fn ($userid) => GroupMembership::fromParams(['groupid' => $group,'userid' => $userid]), |
|
86 | + $knownGroups[$group] |
|
87 | + ) |
|
88 | + ); |
|
89 | + $this->groupMembershipMapper->expects($this->exactly(3)) |
|
90 | + ->method('delete'); |
|
91 | + $this->groupMembershipMapper->expects($this->exactly(2)) |
|
92 | + ->method('insert'); |
|
93 | 93 | |
94 | - $this->groupBackend->expects($this->any()) |
|
95 | - ->method('usersInGroup') |
|
96 | - ->willReturnCallback(function ($groupID) use ($actualGroups) { |
|
97 | - return $actualGroups[$groupID] ?? []; |
|
98 | - }); |
|
94 | + $this->groupBackend->expects($this->any()) |
|
95 | + ->method('usersInGroup') |
|
96 | + ->willReturnCallback(function ($groupID) use ($actualGroups) { |
|
97 | + return $actualGroups[$groupID] ?? []; |
|
98 | + }); |
|
99 | 99 | |
100 | - $this->groupManager->expects($this->any()) |
|
101 | - ->method('get') |
|
102 | - ->willReturnCallback(function (string $groupId): ?IGroup { |
|
103 | - if ($groupId === 'vanishedGroup') { |
|
104 | - return null; |
|
105 | - } |
|
106 | - return $this->createMock(IGroup::class); |
|
107 | - }); |
|
100 | + $this->groupManager->expects($this->any()) |
|
101 | + ->method('get') |
|
102 | + ->willReturnCallback(function (string $groupId): ?IGroup { |
|
103 | + if ($groupId === 'vanishedGroup') { |
|
104 | + return null; |
|
105 | + } |
|
106 | + return $this->createMock(IGroup::class); |
|
107 | + }); |
|
108 | 108 | |
109 | - $this->userManager->expects($this->exactly(5)) |
|
110 | - ->method('get') |
|
111 | - ->willReturnCallback(function (string $userId) { |
|
112 | - if ($userId === 'userDeleted') { |
|
113 | - // user already deleted |
|
114 | - return null; |
|
115 | - } |
|
116 | - return $this->createMock(IUser::class); |
|
117 | - }); |
|
109 | + $this->userManager->expects($this->exactly(5)) |
|
110 | + ->method('get') |
|
111 | + ->willReturnCallback(function (string $userId) { |
|
112 | + if ($userId === 'userDeleted') { |
|
113 | + // user already deleted |
|
114 | + return null; |
|
115 | + } |
|
116 | + return $this->createMock(IUser::class); |
|
117 | + }); |
|
118 | 118 | |
119 | - $addedEvents = 0; |
|
120 | - $removedEvents = 0; |
|
121 | - $this->dispatcher->expects($this->exactly(4)) |
|
122 | - ->method('dispatchTyped') |
|
123 | - ->willReturnCallback(function ($event) use (&$addedEvents, &$removedEvents): void { |
|
124 | - if ($event instanceof UserRemovedEvent) { |
|
125 | - $removedEvents++; |
|
126 | - } elseif ($event instanceof UserAddedEvent) { |
|
127 | - $addedEvents++; |
|
128 | - } |
|
129 | - }); |
|
119 | + $addedEvents = 0; |
|
120 | + $removedEvents = 0; |
|
121 | + $this->dispatcher->expects($this->exactly(4)) |
|
122 | + ->method('dispatchTyped') |
|
123 | + ->willReturnCallback(function ($event) use (&$addedEvents, &$removedEvents): void { |
|
124 | + if ($event instanceof UserRemovedEvent) { |
|
125 | + $removedEvents++; |
|
126 | + } elseif ($event instanceof UserAddedEvent) { |
|
127 | + $addedEvents++; |
|
128 | + } |
|
129 | + }); |
|
130 | 130 | |
131 | - $this->updateGroupsService->handleKnownGroups($groups); |
|
131 | + $this->updateGroupsService->handleKnownGroups($groups); |
|
132 | 132 | |
133 | - $this->assertSame(2, $removedEvents); |
|
134 | - $this->assertSame(2, $addedEvents); |
|
135 | - // and no event for the user that is already deleted, the DB is nevertheless updated, hence 5 |
|
136 | - } |
|
133 | + $this->assertSame(2, $removedEvents); |
|
134 | + $this->assertSame(2, $addedEvents); |
|
135 | + // and no event for the user that is already deleted, the DB is nevertheless updated, hence 5 |
|
136 | + } |
|
137 | 137 | } |
@@ -13,41 +13,41 @@ |
||
13 | 13 | use PHPUnit\Framework\TestCase; |
14 | 14 | |
15 | 15 | class BirthdateParserServiceTest extends TestCase { |
16 | - private BirthdateParserService $service; |
|
17 | - |
|
18 | - protected function setUp(): void { |
|
19 | - parent::setUp(); |
|
20 | - |
|
21 | - $this->service = new BirthdateParserService(); |
|
22 | - } |
|
23 | - |
|
24 | - public static function parseBirthdateDataProvider(): array { |
|
25 | - return [ |
|
26 | - ['2024-01-01', new DateTimeImmutable('2024-01-01'), false], |
|
27 | - ['20240101', new DateTimeImmutable('2024-01-01'), false], |
|
28 | - ['199412161032Z', new DateTimeImmutable('1994-12-16'), false], // LDAP generalized time |
|
29 | - ['199412160532-0500', new DateTimeImmutable('1994-12-16'), false], // LDAP generalized time |
|
30 | - ['2023-07-31T00:60:59.000Z', null, true], |
|
31 | - ['01.01.2024', null, true], |
|
32 | - ['01/01/2024', null, true], |
|
33 | - ['01 01 2024', null, true], |
|
34 | - ['foobar', null, true], |
|
35 | - ]; |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * @dataProvider parseBirthdateDataProvider |
|
40 | - */ |
|
41 | - public function testParseBirthdate( |
|
42 | - string $value, |
|
43 | - ?DateTimeImmutable $expected, |
|
44 | - bool $shouldThrow, |
|
45 | - ): void { |
|
46 | - if ($shouldThrow) { |
|
47 | - $this->expectException(\InvalidArgumentException::class); |
|
48 | - } |
|
49 | - |
|
50 | - $actual = $this->service->parseBirthdate($value); |
|
51 | - $this->assertEquals($expected, $actual); |
|
52 | - } |
|
16 | + private BirthdateParserService $service; |
|
17 | + |
|
18 | + protected function setUp(): void { |
|
19 | + parent::setUp(); |
|
20 | + |
|
21 | + $this->service = new BirthdateParserService(); |
|
22 | + } |
|
23 | + |
|
24 | + public static function parseBirthdateDataProvider(): array { |
|
25 | + return [ |
|
26 | + ['2024-01-01', new DateTimeImmutable('2024-01-01'), false], |
|
27 | + ['20240101', new DateTimeImmutable('2024-01-01'), false], |
|
28 | + ['199412161032Z', new DateTimeImmutable('1994-12-16'), false], // LDAP generalized time |
|
29 | + ['199412160532-0500', new DateTimeImmutable('1994-12-16'), false], // LDAP generalized time |
|
30 | + ['2023-07-31T00:60:59.000Z', null, true], |
|
31 | + ['01.01.2024', null, true], |
|
32 | + ['01/01/2024', null, true], |
|
33 | + ['01 01 2024', null, true], |
|
34 | + ['foobar', null, true], |
|
35 | + ]; |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * @dataProvider parseBirthdateDataProvider |
|
40 | + */ |
|
41 | + public function testParseBirthdate( |
|
42 | + string $value, |
|
43 | + ?DateTimeImmutable $expected, |
|
44 | + bool $shouldThrow, |
|
45 | + ): void { |
|
46 | + if ($shouldThrow) { |
|
47 | + $this->expectException(\InvalidArgumentException::class); |
|
48 | + } |
|
49 | + |
|
50 | + $actual = $this->service->parseBirthdate($value); |
|
51 | + $this->assertEquals($expected, $actual); |
|
52 | + } |
|
53 | 53 | } |