Merge pull request #2684 from mattmalec/develop

Fix API 500 error
This commit is contained in:
Dane Everitt 2020-11-10 20:16:32 -08:00 committed by GitHub
commit 3b4a096ddb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View file

@ -29,7 +29,7 @@ class AuthenticateIPAccess
} }
$find = new IP($request->ip()); $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)) { if (Range::parse($ip)->contains($find)) {
return $next($request); return $next($request);
} }

View file

@ -26,7 +26,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase
*/ */
public function testWithValidIP() 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->setRequestAttribute('api_key', $model);
$this->request->shouldReceive('ip')->withNoArgs()->once()->andReturn('127.0.0.1'); $this->request->shouldReceive('ip')->withNoArgs()->once()->andReturn('127.0.0.1');
@ -39,7 +39,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase
*/ */
public function testValidIPAgainstCIDRRange() 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->setRequestAttribute('api_key', $model);
$this->request->shouldReceive('ip')->withNoArgs()->once()->andReturn('192.168.1.15'); $this->request->shouldReceive('ip')->withNoArgs()->once()->andReturn('192.168.1.15');
@ -55,7 +55,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase
{ {
$this->expectException(AccessDeniedHttpException::class); $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->setRequestAttribute('api_key', $model);
$this->request->shouldReceive('ip')->withNoArgs()->twice()->andReturn('127.0.0.2'); $this->request->shouldReceive('ip')->withNoArgs()->twice()->andReturn('127.0.0.2');