File tree Expand file tree Collapse file tree 5 files changed +63
-0
lines changed
Expand file tree Collapse file tree 5 files changed +63
-0
lines changed Original file line number Diff line number Diff line change 55namespace CodeIgniter \Shield \Filters ;
66
77use CodeIgniter \Filters \FilterInterface ;
8+ use CodeIgniter \HTTP \IncomingRequest ;
89use CodeIgniter \HTTP \RedirectResponse ;
910use CodeIgniter \HTTP \RequestInterface ;
1011use CodeIgniter \HTTP \Response ;
@@ -31,6 +32,10 @@ class AuthRates implements FilterInterface
3132 */
3233 public function before (RequestInterface $ request , $ arguments = null )
3334 {
35+ if (! $ request instanceof IncomingRequest) {
36+ return ;
37+ }
38+
3439 $ throttler = service ('throttler ' );
3540
3641 // Restrict an IP address to no more than 10 requests
Original file line number Diff line number Diff line change 55namespace CodeIgniter \Shield \Filters ;
66
77use CodeIgniter \Filters \FilterInterface ;
8+ use CodeIgniter \HTTP \IncomingRequest ;
89use CodeIgniter \HTTP \RedirectResponse ;
910use CodeIgniter \HTTP \RequestInterface ;
1011use CodeIgniter \HTTP \Response ;
@@ -35,6 +36,10 @@ class ChainAuth implements FilterInterface
3536 */
3637 public function before (RequestInterface $ request , $ arguments = null )
3738 {
39+ if (! $ request instanceof IncomingRequest) {
40+ return ;
41+ }
42+
3843 helper ('settings ' );
3944
4045 $ chain = config ('Auth ' )->authenticationChain ;
Original file line number Diff line number Diff line change 55namespace CodeIgniter \Shield \Filters ;
66
77use CodeIgniter \Filters \FilterInterface ;
8+ use CodeIgniter \HTTP \IncomingRequest ;
89use CodeIgniter \HTTP \RedirectResponse ;
910use CodeIgniter \HTTP \RequestInterface ;
1011use CodeIgniter \HTTP \Response ;
@@ -34,6 +35,10 @@ class SessionAuth implements FilterInterface
3435 */
3536 public function before (RequestInterface $ request , $ arguments = null )
3637 {
38+ if (! $ request instanceof IncomingRequest) {
39+ return ;
40+ }
41+
3742 helper ('setting ' );
3843
3944 /** @var Session $authenticator */
Original file line number Diff line number Diff line change 55namespace CodeIgniter \Shield \Filters ;
66
77use CodeIgniter \Filters \FilterInterface ;
8+ use CodeIgniter \HTTP \IncomingRequest ;
89use CodeIgniter \HTTP \RedirectResponse ;
910use CodeIgniter \HTTP \RequestInterface ;
1011use CodeIgniter \HTTP \Response ;
@@ -34,6 +35,10 @@ class TokenAuth implements FilterInterface
3435 */
3536 public function before (RequestInterface $ request , $ arguments = null )
3637 {
38+ if (! $ request instanceof IncomingRequest) {
39+ return ;
40+ }
41+
3742 helper ('setting ' );
3843
3944 /** @var AccessTokens $authenticator */
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Tests \Unit ;
6+
7+ use CodeIgniter \Filters \FilterInterface ;
8+ use CodeIgniter \HTTP \CLIRequest ;
9+ use CodeIgniter \Shield \Filters \AuthRates ;
10+ use CodeIgniter \Shield \Filters \ChainAuth ;
11+ use CodeIgniter \Shield \Filters \SessionAuth ;
12+ use CodeIgniter \Shield \Filters \TokenAuth ;
13+ use Generator ;
14+ use Tests \Support \TestCase ;
15+
16+ /**
17+ * @internal
18+ */
19+ final class FilterInCliTest extends TestCase
20+ {
21+ /**
22+ * @dataProvider filterProvider
23+ */
24+ public function testWhenInCliDoNothing (FilterInterface $ filter ): void
25+ {
26+ $ clirequest = $ this ->createMock (CLIRequest::class);
27+
28+ $ clirequest ->expects ($ this ->never ())
29+ ->method ('getHeaderLine ' );
30+
31+ $ filter ->before ($ clirequest );
32+ }
33+
34+ public function filterProvider (): Generator
35+ {
36+ yield from [
37+ [new AuthRates ()],
38+ [new ChainAuth ()],
39+ [new SessionAuth ()],
40+ [new TokenAuth ()],
41+ ];
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments