@@ -25,8 +25,6 @@ public function setUp()
2525
2626 $ this ->container ->shouldReceive ('boot ' )->atLeast ()->once ();
2727 $ this ->container ->shouldReceive ('make ' )->once ()->with ('dingo.api.auth ' )->andReturn ($ this ->auth );
28-
29- $ this ->auth ->shouldReceive ('check ' )->once ()->andReturn (false );
3028 }
3129
3230
@@ -40,6 +38,8 @@ public function testWrappedKernelIsHandledForInternalRequests()
4038 {
4139 $ request = InternalRequest::create ('/ ' , 'GET ' );
4240
41+ $ this ->auth ->shouldReceive ('check ' )->once ()->andReturn (false );
42+
4343 $ this ->container ->shouldReceive ('make ' )->once ()->with ('config ' )->andReturn (m::mock (['get ' => []]));
4444 $ this ->app ->shouldReceive ('handle ' )->once ()->with ($ request , HttpKernelInterface::MASTER_REQUEST , true )->andReturn (new Response ('test ' ));
4545 $ this ->assertEquals ('test ' , $ this ->middleware ->handle ($ request )->getContent ());
@@ -50,6 +50,8 @@ public function testWrappedKernelIsHandledForRequestsNotTargettingTheApi()
5050 {
5151 $ request = Request::create ('/ ' , 'GET ' );
5252
53+ $ this ->auth ->shouldReceive ('check ' )->once ()->andReturn (false );
54+
5355 $ this ->container ->shouldReceive ('make ' )->once ()->with ('config ' )->andReturn (m::mock (['get ' => []]));
5456 $ this ->container ->shouldReceive ('make ' )->once ()->with ('router ' )->andReturn ($ this ->router );
5557
@@ -64,6 +66,8 @@ public function testWrappedKernelIsHandledForRequestsWhereRateLimitingIsDisabled
6466 {
6567 $ request = Request::create ('/ ' , 'GET ' );
6668
69+ $ this ->auth ->shouldReceive ('check ' )->once ()->andReturn (false );
70+
6771 $ this ->container ->shouldReceive ('make ' )->once ()->with ('config ' )->andReturn (m::mock (['get ' => ['unauthenticated ' => ['limit ' => 0 ]]]));
6872 $ this ->container ->shouldReceive ('make ' )->once ()->with ('router ' )->andReturn ($ this ->router );
6973
@@ -74,17 +78,34 @@ public function testWrappedKernelIsHandledForRequestsWhereRateLimitingIsDisabled
7478 }
7579
7680
81+ public function testAuthenticatedConfigurationIsUsedForAuthenticatedRequest ()
82+ {
83+ $ request = Request::create ('/ ' , 'GET ' );
84+
85+ $ this ->auth ->shouldReceive ('check ' )->once ()->andReturn (true );
86+
87+ $ this ->container ->shouldReceive ('make ' )->once ()->with ('config ' )->andReturn (m::mock (['get ' => ['authenticated ' => ['limit ' => 0 ]]]));
88+ $ this ->container ->shouldReceive ('make ' )->once ()->with ('router ' )->andReturn ($ this ->router );
89+
90+ $ this ->router ->shouldReceive ('requestTargettingApi ' )->once ()->with ($ request )->andReturn (true );
91+
92+ $ this ->app ->shouldReceive ('handle ' )->once ()->with ($ request , HttpKernelInterface::MASTER_REQUEST , true )->andReturn (new Response ('test ' ));
93+ $ this ->assertEquals ('test ' , $ this ->middleware ->handle ($ request )->getContent ());
94+ }
95+
96+
7797 public function testWrappedKernelIsHandledWhenRateLimitHasNotBeenExceeded ()
7898 {
7999 $ request = Request::create ('/ ' , 'GET ' );
80100
101+ $ this ->auth ->shouldReceive ('check ' )->once ()->andReturn (false );
102+
81103 $ this ->container ->shouldReceive ('make ' )->once ()->with ('config ' )->andReturn (m::mock (['get ' => ['unauthenticated ' => ['limit ' => 1 , 'reset ' => 1 ]]]));
82104 $ this ->container ->shouldReceive ('make ' )->once ()->with ('router ' )->andReturn ($ this ->router );
83105 $ this ->container ->shouldReceive ('make ' )->once ()->with ('cache ' )->andReturn ($ this ->cache );
84106
85107 $ this ->router ->shouldReceive ('requestTargettingApi ' )->once ()->with ($ request )->andReturn (true );
86108
87-
88109 $ ip = $ request ->getClientIp ();
89110
90111 $ this ->cache ->shouldReceive ('add ' )->once ()->with ('dingo:api:requests: ' .$ ip , 0 , 1 );
@@ -105,6 +126,8 @@ public function testForbiddenResponseIsReturnedWhenRateLimitIsExceeded()
105126 {
106127 $ request = Request::create ('/ ' , 'GET ' );
107128
129+ $ this ->auth ->shouldReceive ('check ' )->once ()->andReturn (false );
130+
108131 $ this ->container ->shouldReceive ('make ' )->once ()->with ('config ' )->andReturn (m::mock (['get ' => ['unauthenticated ' => ['limit ' => 1 , 'reset ' => 1 ]]]));
109132 $ this ->container ->shouldReceive ('make ' )->once ()->with ('router ' )->andReturn ($ this ->router );
110133 $ this ->container ->shouldReceive ('make ' )->once ()->with ('cache ' )->andReturn ($ this ->cache );
0 commit comments