-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add IPAddressACLTest and UserAgentACLTest
- Loading branch information
1 parent
f60ae5a
commit f9f05d0
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/* | ||
* Gatekeeper | ||
* Copyright (C) 2024 Christian Neff | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for | ||
* any purpose with or without fee is hereby granted, provided that the | ||
* above copyright notice and this permission notice appear in all copies. | ||
*/ | ||
|
||
namespace Secondtruth\Gatekeeper\Tests\ACL; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Secondtruth\Gatekeeper\Visitor; | ||
use Secondtruth\Gatekeeper\ACL\IPAddressACL; | ||
use Secondtruth\Gatekeeper\Listing\IPList; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class IPAddressACLTest extends TestCase | ||
{ | ||
private $acl; | ||
|
||
protected function setUp(): void | ||
{ | ||
$allowed = new IPList(['127.0.0.1']); | ||
$denied = new IPList(['192.168.1.1']); | ||
$this->acl = new IPAddressACL($allowed, $denied); | ||
} | ||
|
||
public function testIsAllowed() | ||
{ | ||
$request = Request::create('/', 'GET', [], [], [], ['REMOTE_ADDR' => '127.0.0.1']); | ||
$this->assertTrue($this->acl->isAllowed(Visitor::fromSymfonyRequest($request))); | ||
} | ||
|
||
public function testIsDenied() | ||
{ | ||
$request = Request::create('/', 'GET', [], [], [], ['REMOTE_ADDR' => '192.168.1.1']); | ||
$this->assertTrue($this->acl->isDenied(Visitor::fromSymfonyRequest($request))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/* | ||
* Gatekeeper | ||
* Copyright (C) 2024 Christian Neff | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for | ||
* any purpose with or without fee is hereby granted, provided that the | ||
* above copyright notice and this permission notice appear in all copies. | ||
*/ | ||
|
||
namespace Secondtruth\Gatekeeper\Tests\ACL; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Secondtruth\Gatekeeper\Visitor; | ||
use Secondtruth\Gatekeeper\ACL\UserAgentACL; | ||
use Secondtruth\Gatekeeper\Listing\StringList; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class UserAgentACLTest extends TestCase | ||
{ | ||
private $acl; | ||
|
||
protected function setUp(): void | ||
{ | ||
$allowed = new StringList(['Mozilla/5.0']); | ||
$denied = new StringList(['Googlebot']); | ||
$this->acl = new UserAgentACL($allowed, $denied); | ||
} | ||
|
||
public function testIsAllowed() | ||
{ | ||
$request = Request::create('/', 'GET', [], [], [], ['HTTP_USER_AGENT' => 'Mozilla/5.0']); | ||
$this->assertTrue($this->acl->isAllowed(Visitor::fromSymfonyRequest($request))); | ||
} | ||
|
||
public function testIsDenied() | ||
{ | ||
$request = Request::create('/', 'GET', [], [], [], ['HTTP_USER_AGENT' => 'Googlebot']); | ||
$this->assertTrue($this->acl->isDenied(Visitor::fromSymfonyRequest($request))); | ||
} | ||
} |