@@ -223,6 +223,8 @@ public function when_checkPassword_is_called_with_wrong_credentials()
223223 $ specifiedPassword = 'a password ' ;
224224 /** @var int $returnedMaxRetries */
225225 $ returnedMaxRetries = 2 ;
226+ /** @var string $returnedUseSSL */
227+ $ returnedUseSSL = 'true ' ;
226228
227229 $ this ->injectedConfigMock ->expects ($ this ->at (0 ))
228230 ->method ('getAppValue ' )
@@ -236,12 +238,82 @@ public function when_checkPassword_is_called_with_wrong_credentials()
236238 ->method ('getAppValue ' )
237239 ->will ($ this ->returnValue ($ returnedMaxRetries ));
238240
241+ $ this ->injectedConfigMock ->expects ($ this ->at (3 ))
242+ ->method ('getAppValue ' )
243+ ->will ($ this ->returnValue ($ returnedUseSSL ));
244+
239245 $ this ->createSut ();
240246
241247 $ this ->injectedIMAPWrapperMock ->expects ($ this ->once ())
242248 ->method ('open ' )
243- ->with ("{ {$ returnedHost }: {$ returnedPort }/imap/ssl}INBOX " , $ specifiedUsername ,
244- $ specifiedPassword , OP_READONLY , $ returnedMaxRetries )
249+ ->with (sprintf ('{%s:%d/imap/ssl}INBOX ' , $ returnedHost , $ returnedPort ),
250+ $ specifiedUsername ,
251+ $ specifiedPassword ,
252+ OP_READONLY ,
253+ $ returnedMaxRetries )
254+ ->will ($ this ->returnValue (FALSE ));
255+
256+ $ this ->injectedIMAPWrapperMock ->expects ($ this ->once ())
257+ ->method ('getLastErrors ' )
258+ ->will ($ this ->returnValue ($ returnedIMAPErrors ));
259+
260+ $ this ->injectedLoggerMock ->expects ($ this ->once ())
261+ ->method ('warning ' )
262+ ->with (implode ('; ' , $ returnedIMAPErrors ), array ('app ' => APP_ID ));
263+
264+ $ result = $ this ->sut ->checkPassword ($ specifiedUsername , $ specifiedPassword );
265+
266+ $ this ->assertFalse ($ result );
267+ }
268+
269+ /**
270+ * @test
271+ */
272+ public function when_checkPassword_is_called_with_wrong_credentials_without_SSL ()
273+ {
274+ /** @var string $returnedHost */
275+ $ returnedHost = 'an host ' ;
276+ /** @var string $returnedPort */
277+ $ returnedPort = 1 ;
278+
279+ /** @var array $returnedIMAPErrors */
280+ $ returnedIMAPErrors = array ('error 1 ' ,
281+ 'error 2 ' );
282+
283+ /** @var string $specifiedUsername */
284+ $ specifiedUsername = 'an uid ' ;
285+ /** @var string $specifiedPassword */
286+ $ specifiedPassword = 'a password ' ;
287+ /** @var int $returnedMaxRetries */
288+ $ returnedMaxRetries = 2 ;
289+ /** @var string $returnedUseSSL */
290+ $ returnedUseSSL = 'false ' ;
291+
292+ $ this ->injectedConfigMock ->expects ($ this ->at (0 ))
293+ ->method ('getAppValue ' )
294+ ->will ($ this ->returnValue ($ returnedHost ));
295+
296+ $ this ->injectedConfigMock ->expects ($ this ->at (1 ))
297+ ->method ('getAppValue ' )
298+ ->will ($ this ->returnValue ($ returnedPort ));
299+
300+ $ this ->injectedConfigMock ->expects ($ this ->at (2 ))
301+ ->method ('getAppValue ' )
302+ ->will ($ this ->returnValue ($ returnedMaxRetries ));
303+
304+ $ this ->injectedConfigMock ->expects ($ this ->at (3 ))
305+ ->method ('getAppValue ' )
306+ ->will ($ this ->returnValue ($ returnedUseSSL ));
307+
308+ $ this ->createSut ();
309+
310+ $ this ->injectedIMAPWrapperMock ->expects ($ this ->once ())
311+ ->method ('open ' )
312+ ->with (sprintf ('{%s:%d/imap/novalidate-cert}INBOX ' , $ returnedHost , $ returnedPort ),
313+ $ specifiedUsername ,
314+ $ specifiedPassword ,
315+ OP_READONLY ,
316+ $ returnedMaxRetries )
245317 ->will ($ this ->returnValue (FALSE ));
246318
247319 $ this ->injectedIMAPWrapperMock ->expects ($ this ->once ())
@@ -273,6 +345,8 @@ public function when_checkPassword_is_called_with_valid_credentials_and_user_don
273345 $ specifiedPassword = 'a password ' ;
274346 /** @var int $returnedMaxRetries */
275347 $ returnedMaxRetries = 2 ;
348+ /** @var string $returnedUseSSL */
349+ $ returnedUseSSL = 'true ' ;
276350
277351 $ this ->injectedConfigMock ->expects ($ this ->at (0 ))
278352 ->method ('getAppValue ' )
@@ -286,11 +360,16 @@ public function when_checkPassword_is_called_with_valid_credentials_and_user_don
286360 ->method ('getAppValue ' )
287361 ->will ($ this ->returnValue ($ returnedMaxRetries ));
288362
363+ $ this ->injectedConfigMock ->expects ($ this ->at (3 ))
364+ ->method ('getAppValue ' )
365+ ->will ($ this ->returnValue ($ returnedUseSSL ));
366+
289367 $ this ->createSut ();
290368
291369 $ this ->injectedIMAPWrapperMock ->expects ($ this ->once ())
292370 ->method ('open ' )
293- ->with ("{ {$ returnedHost }: {$ returnedPort }/imap/ssl}INBOX " , $ specifiedUsername ,
371+ ->with (sprintf ('{%s:%d/imap/ssl}INBOX ' , $ returnedHost , $ returnedPort ),
372+ $ specifiedUsername ,
294373 $ specifiedPassword , OP_READONLY , $ returnedMaxRetries )
295374 ->will ($ this ->returnValue (TRUE ));
296375
@@ -324,6 +403,8 @@ public function when_checkPassword_is_called_with_valid_credentials_and_user_exi
324403 $ specifiedPassword = 'a password ' ;
325404 /** @var int $returnedMaxRetries */
326405 $ returnedMaxRetries = 2 ;
406+ /** @var string $returnedUseSSL */
407+ $ returnedUseSSL = 'true ' ;
327408
328409 $ this ->injectedConfigMock ->expects ($ this ->at (0 ))
329410 ->method ('getAppValue ' )
@@ -337,11 +418,16 @@ public function when_checkPassword_is_called_with_valid_credentials_and_user_exi
337418 ->method ('getAppValue ' )
338419 ->will ($ this ->returnValue ($ returnedMaxRetries ));
339420
421+ $ this ->injectedConfigMock ->expects ($ this ->at (3 ))
422+ ->method ('getAppValue ' )
423+ ->will ($ this ->returnValue ($ returnedUseSSL ));
424+
340425 $ this ->createSut ();
341426
342427 $ this ->injectedIMAPWrapperMock ->expects ($ this ->once ())
343428 ->method ('open ' )
344- ->with ("{ {$ returnedHost }: {$ returnedPort }/imap/ssl}INBOX " , $ specifiedUsername ,
429+ ->with (sprintf ('{%s:%d/imap/ssl}INBOX ' , $ returnedHost , $ returnedPort ),
430+ $ specifiedUsername ,
345431 $ specifiedPassword , OP_READONLY , $ returnedMaxRetries )
346432 ->will ($ this ->returnValue (TRUE ));
347433
@@ -515,11 +601,11 @@ protected function setUp()
515601 {
516602 parent ::setUp ();
517603
518- $ this ->injectedConfigMock = $ this ->getMock ('\OCP\IConfig ' );
604+ $ this ->injectedConfigMock = $ this ->getMock ('\OCP\IConfig ' );
519605 $ this ->injectedUserManagerMock = $ this ->getMock ('\OCP\IUserManager ' );
520- $ this ->injectedLoggerMock = $ this ->getMock ('\OCP\ILogger ' );
606+ $ this ->injectedLoggerMock = $ this ->getMock ('\OCP\ILogger ' );
521607 $ this ->injectedIMAPWrapperMock = $ this ->getMock ('\OCA\user_imapauth\lib\Contracts\IIMAPWrapper ' );
522- $ this ->returnedUserMock = $ this ->getMock ('\OCP\IUser ' );
608+ $ this ->returnedUserMock = $ this ->getMock ('\OCP\IUser ' );
523609 }
524610}
525611
0 commit comments