Skip to content

Commit eedfbce

Browse files
Fix tests
1 parent e1166bb commit eedfbce

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Middleware/BlockBots.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ public function isWhitelisted()
126126

127127
$ips = $this->options->whitelist_ips;
128128

129+
if (is_null($this->client->ip)) {
130+
return false;
131+
}
132+
129133
if (IpUtils::checkIp($this->client->ip, $ips)) {
130134
//Add this to the redis list as it is faster
131135
Redis::sadd($this->options->whitelist_key, $this->client->ip);

tests/Unit/BlockBotsMiddlewareTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function test_should_block_after_limit()
1818
Queue::fake();
1919
$middleware = new BlockBots();
2020
$request = new Request();
21+
$request->server->set('REMOTE_ADDR', '192.168.2.1');
2122

2223
$limit = 10;
2324

@@ -41,6 +42,7 @@ public function test_should_not_block_after_limit_if_mode_never()
4142
Queue::fake();
4243
$middleware = new BlockBots();
4344
$request = new Request();
45+
$request->server->set('REMOTE_ADDR', '192.168.2.2');
4446

4547
$limit = 10;
4648

@@ -75,6 +77,7 @@ public function test_should_always_block_if_mode_always()
7577

7678
$middleware = new BlockBots();
7779
$request = new Request();
80+
$request->server->set('REMOTE_ADDR', '192.168.2.3');
7881

7982
$limit = 100;
8083

@@ -108,4 +111,4 @@ public function test_should_not_block_allowed_bot()
108111

109112
$this->assertContains('0.0.0.0', Redis::smembers(Config::get('block-bots.pending_bot_list_key')));
110113
}
111-
}
114+
}

0 commit comments

Comments
 (0)