88namespace OCA \DAV \Tests \unit \Connector \Sabre ;
99
1010use OC \Authentication \TwoFactorAuth \Manager ;
11+ use OC \Security \CSRF \CsrfValidator ;
1112use OC \User \Session ;
1213use OCP \IRequest ;
1314use OCP \ISession ;
1415use OCP \IUser ;
1516use OCP \Security \Bruteforce \IThrottler ;
17+ use OCP \Security \CSRF \ICsrfValidator ;
1618use Sabre \DAV \Server ;
1719use Sabre \HTTP \RequestInterface ;
1820use Sabre \HTTP \ResponseInterface ;
@@ -37,6 +39,7 @@ class AuthTest extends TestCase {
3739 private $ twoFactorManager ;
3840 /** @var IThrottler */
3941 private $ throttler ;
42+ private ICsrfValidator $ csrfValidator ;
4043
4144 protected function setUp (): void {
4245 parent ::setUp ();
@@ -52,12 +55,14 @@ protected function setUp(): void {
5255 $ this ->throttler = $ this ->getMockBuilder (IThrottler::class)
5356 ->disableOriginalConstructor ()
5457 ->getMock ();
58+ $ this ->csrfValidator = $ this ->createMock (ICsrfValidator::class);
5559 $ this ->auth = new \OCA \DAV \Connector \Sabre \Auth (
5660 $ this ->session ,
5761 $ this ->userSession ,
5862 $ this ->request ,
5963 $ this ->twoFactorManager ,
60- $ this ->throttler
64+ $ this ->throttler ,
65+ $ this ->csrfValidator ,
6166 );
6267 }
6368
@@ -248,9 +253,9 @@ public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenForNonGet(): void
248253 ->expects ($ this ->any ())
249254 ->method ('getUser ' )
250255 ->willReturn ($ user );
251- $ this ->request
256+ $ this ->csrfValidator
252257 ->expects ($ this ->once ())
253- ->method ('passesCSRFCheck ' )
258+ ->method ('validate ' )
254259 ->willReturn (false );
255260
256261 $ expectedResponse = [
@@ -295,9 +300,9 @@ public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenAndCorrectlyDavAu
295300 ->expects ($ this ->any ())
296301 ->method ('getUser ' )
297302 ->willReturn ($ user );
298- $ this ->request
303+ $ this ->csrfValidator
299304 ->expects ($ this ->once ())
300- ->method ('passesCSRFCheck ' )
305+ ->method ('validate ' )
301306 ->willReturn (false );
302307 $ this ->auth ->check ($ request , $ response );
303308 }
@@ -340,9 +345,9 @@ public function testAuthenticateAlreadyLoggedInWithoutTwoFactorChallengePassed()
340345 ->expects ($ this ->any ())
341346 ->method ('getUser ' )
342347 ->willReturn ($ user );
343- $ this ->request
348+ $ this ->csrfValidator
344349 ->expects ($ this ->once ())
345- ->method ('passesCSRFCheck ' )
350+ ->method ('validate ' )
346351 ->willReturn (true );
347352 $ this ->twoFactorManager ->expects ($ this ->once ())
348353 ->method ('needsSecondFactor ' )
@@ -389,9 +394,9 @@ public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenAndIncorrectlyDav
389394 ->expects ($ this ->any ())
390395 ->method ('getUser ' )
391396 ->willReturn ($ user );
392- $ this ->request
397+ $ this ->csrfValidator
393398 ->expects ($ this ->once ())
394- ->method ('passesCSRFCheck ' )
399+ ->method ('validate ' )
395400 ->willReturn (false );
396401 $ this ->auth ->check ($ request , $ response );
397402 }
@@ -430,9 +435,9 @@ public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenForNonGetAndDeskt
430435 ->expects ($ this ->any ())
431436 ->method ('getUser ' )
432437 ->willReturn ($ user );
433- $ this ->request
438+ $ this ->csrfValidator
434439 ->expects ($ this ->once ())
435- ->method ('passesCSRFCheck ' )
440+ ->method ('validate ' )
436441 ->willReturn (false );
437442
438443 $ this ->auth ->check ($ request , $ response );
@@ -499,9 +504,9 @@ public function testAuthenticateAlreadyLoggedInWithCsrfTokenForGet(): void {
499504 ->expects ($ this ->any ())
500505 ->method ('getUser ' )
501506 ->willReturn ($ user );
502- $ this ->request
507+ $ this ->csrfValidator
503508 ->expects ($ this ->once ())
504- ->method ('passesCSRFCheck ' )
509+ ->method ('validate ' )
505510 ->willReturn (true );
506511
507512 $ response = $ this ->auth ->check ($ request , $ response );
0 commit comments