@@ -1472,4 +1472,100 @@ public function testUpdateTokens() {
14721472
14731473 $ this ->userSession ->updateTokens ('uid ' , 'pass ' );
14741474 }
1475+
1476+ public function testLogClientInThrottlerUsername () {
1477+ $ manager = $ this ->createMock (Manager::class);
1478+ $ session = $ this ->createMock (ISession::class);
1479+ $ request = $ this ->createMock (IRequest::class);
1480+
1481+ /** @var Session $userSession */
1482+ $ userSession = $ this ->getMockBuilder (Session::class)
1483+ ->setConstructorArgs ([$ manager , $ session , $ this ->timeFactory , $ this ->tokenProvider , $ this ->config , $ this ->random , $ this ->lockdownManager , $ this ->logger , $ this ->dispatcher ])
1484+ ->setMethods (['isTokenPassword ' , 'login ' , 'supportsCookies ' , 'createSessionToken ' , 'getUser ' ])
1485+ ->getMock ();
1486+
1487+ $ userSession ->expects ($ this ->once ())
1488+ ->method ('isTokenPassword ' )
1489+ ->willReturn (true );
1490+ $ userSession ->expects ($ this ->once ())
1491+ ->method ('login ' )
1492+ ->with ('john ' , 'I-AM-AN-PASSWORD ' )
1493+ ->willReturn (false );
1494+
1495+ $ session ->expects ($ this ->never ())
1496+ ->method ('set ' );
1497+ $ request
1498+ ->method ('getRemoteAddress ' )
1499+ ->willReturn ('192.168.0.1 ' );
1500+ $ this ->throttler
1501+ ->expects ($ this ->exactly (2 ))
1502+ ->method ('sleepDelay ' )
1503+ ->with ('192.168.0.1 ' );
1504+ $ this ->throttler
1505+ ->expects ($ this ->any ())
1506+ ->method ('getDelay ' )
1507+ ->with ('192.168.0.1 ' )
1508+ ->willReturn (0 );
1509+
1510+ $ this ->throttler
1511+ ->expects ($ this ->once ())
1512+ ->method ('registerAttempt ' )
1513+ ->with ('login ' , '192.168.0.1 ' , ['user ' => 'john ' ]);
1514+ $ this ->dispatcher
1515+ ->expects ($ this ->once ())
1516+ ->method ('dispatchTyped ' )
1517+ ->with (new LoginFailed ('john ' , 'I-AM-AN-PASSWORD ' ));
1518+
1519+ $ this ->assertFalse ($ userSession ->logClientIn ('john ' , 'I-AM-AN-PASSWORD ' , $ request , $ this ->throttler ));
1520+ }
1521+
1522+ public function testLogClientInThrottlerEmail () {
1523+ $ manager = $ this ->createMock (Manager::class);
1524+ $ session = $ this ->createMock (ISession::class);
1525+ $ request = $ this ->createMock (IRequest::class);
1526+
1527+ /** @var Session $userSession */
1528+ $ userSession = $ this ->getMockBuilder (Session::class)
1529+ ->setConstructorArgs ([$ manager , $ session , $ this ->timeFactory , $ this ->tokenProvider , $ this ->config , $ this ->random , $ this ->lockdownManager , $ this ->logger , $ this ->dispatcher ])
1530+ ->setMethods (['isTokenPassword ' , 'login ' , 'supportsCookies ' , 'createSessionToken ' , 'getUser ' ])
1531+ ->getMock ();
1532+
1533+ $ userSession ->expects ($ this ->once ())
1534+ ->method ('isTokenPassword ' )
1535+ ->willReturn (true );
1536+ $ userSession ->expects ($ this ->once ())
1537+ ->method ('login ' )
1538+ ->with ('john@foo.bar ' , 'I-AM-AN-PASSWORD ' )
1539+ ->willReturn (false );
1540+ $ manager
1541+ ->method ('getByEmail ' )
1542+ ->with ('john@foo.bar ' )
1543+ ->willReturn ([]);
1544+
1545+ $ session ->expects ($ this ->never ())
1546+ ->method ('set ' );
1547+ $ request
1548+ ->method ('getRemoteAddress ' )
1549+ ->willReturn ('192.168.0.1 ' );
1550+ $ this ->throttler
1551+ ->expects ($ this ->exactly (2 ))
1552+ ->method ('sleepDelay ' )
1553+ ->with ('192.168.0.1 ' );
1554+ $ this ->throttler
1555+ ->expects ($ this ->any ())
1556+ ->method ('getDelay ' )
1557+ ->with ('192.168.0.1 ' )
1558+ ->willReturn (0 );
1559+
1560+ $ this ->throttler
1561+ ->expects ($ this ->once ())
1562+ ->method ('registerAttempt ' )
1563+ ->with ('login ' , '192.168.0.1 ' , ['user ' => 'john@foo.bar ' ]);
1564+ $ this ->dispatcher
1565+ ->expects ($ this ->once ())
1566+ ->method ('dispatchTyped ' )
1567+ ->with (new LoginFailed ('john@foo.bar ' , 'I-AM-AN-PASSWORD ' ));
1568+
1569+ $ this ->assertFalse ($ userSession ->logClientIn ('john@foo.bar ' , 'I-AM-AN-PASSWORD ' , $ request , $ this ->throttler ));
1570+ }
14751571}
0 commit comments