From df6402644999bc23a639e809d9095f92de8d071b Mon Sep 17 00:00:00 2001 From: Matt Malec Date: Sun, 8 Nov 2020 21:57:22 -0500 Subject: [PATCH 1/2] Update AuthenticateIPAccess.php Fix a 500 error when processing a request with an IP filter --- app/Http/Middleware/Api/AuthenticateIPAccess.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Middleware/Api/AuthenticateIPAccess.php b/app/Http/Middleware/Api/AuthenticateIPAccess.php index 30377794b..8f57b820d 100644 --- a/app/Http/Middleware/Api/AuthenticateIPAccess.php +++ b/app/Http/Middleware/Api/AuthenticateIPAccess.php @@ -29,7 +29,7 @@ class AuthenticateIPAccess } $find = new IP($request->ip()); - foreach (json_decode($model->allowed_ips) as $ip) { + foreach ($model->allowed_ips as $ip) { if (Range::parse($ip)->contains($find)) { return $next($request); } From 2f2d105a4f1d5178b42f938c96bd31f364056f25 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 10 Nov 2020 20:13:55 -0800 Subject: [PATCH 2/2] Fix test cases --- tests/Unit/Http/Middleware/Api/AuthenticateIPAccessTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Unit/Http/Middleware/Api/AuthenticateIPAccessTest.php b/tests/Unit/Http/Middleware/Api/AuthenticateIPAccessTest.php index 8d47fdd54..545626317 100644 --- a/tests/Unit/Http/Middleware/Api/AuthenticateIPAccessTest.php +++ b/tests/Unit/Http/Middleware/Api/AuthenticateIPAccessTest.php @@ -26,7 +26,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase */ public function testWithValidIP() { - $model = factory(ApiKey::class)->make(['allowed_ips' => '["127.0.0.1"]']); + $model = factory(ApiKey::class)->make(['allowed_ips' => ['127.0.0.1']]); $this->setRequestAttribute('api_key', $model); $this->request->shouldReceive('ip')->withNoArgs()->once()->andReturn('127.0.0.1'); @@ -39,7 +39,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase */ public function testValidIPAgainstCIDRRange() { - $model = factory(ApiKey::class)->make(['allowed_ips' => '["192.168.1.1/28"]']); + $model = factory(ApiKey::class)->make(['allowed_ips' => ['192.168.1.1/28']]); $this->setRequestAttribute('api_key', $model); $this->request->shouldReceive('ip')->withNoArgs()->once()->andReturn('192.168.1.15'); @@ -55,7 +55,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase { $this->expectException(AccessDeniedHttpException::class); - $model = factory(ApiKey::class)->make(['allowed_ips' => '["127.0.0.1"]']); + $model = factory(ApiKey::class)->make(['allowed_ips' => ['127.0.0.1']]); $this->setRequestAttribute('api_key', $model); $this->request->shouldReceive('ip')->withNoArgs()->twice()->andReturn('127.0.0.2');