1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
<?php
namespace Illuminate\Tests\Integration\Http\Middleware;
use Illuminate\Encryption\Encrypter;
use Illuminate\Http\Request;
use Orchestra\Testbench\TestCase;
class VerifyCsrfTokenExceptTest extends TestCase
{
private $stub;
private $request;
protected function setUp(): void
{
parent::setUp();
$this->stub = new VerifyCsrfTokenExceptStub(app(), new Encrypter(Encrypter::generateKey('AES-128-CBC')));
$this->request = Request::create('http://example.com/foo/bar', 'POST');
}
public function testItCanExceptPaths()
{
$this->assertMatchingExcept(['/foo/bar']);
$this->assertMatchingExcept(['foo/bar']);
$this->assertNonMatchingExcept(['/bar/foo']);
}
public function testItCanExceptWildcardPaths()
{
$this->assertMatchingExcept(['/foo/*']);
$this->assertNonMatchingExcept(['/bar*']);
}
public function testItCanExceptFullUrlPaths()
{
$this->assertMatchingExcept(['http://example.com/foo/bar']);
$this->assertMatchingExcept(['http://example.com/foo/bar/']);
$this->assertNonMatchingExcept(['https://example.com/foo/bar/']);
$this->assertNonMatchingExcept(['http://foobar.com/']);
}
public function testItCanExceptFullUrlWildcardPaths()
{
$this->assertMatchingExcept(['http://example.com/*']);
$this->assertMatchingExcept(['*example.com*']);
$this->request = Request::create('https://example.com', 'POST');
$this->assertMatchingExcept(['*example.com']);
}
private function assertMatchingExcept(array $except, $bool = true)
{
$this->assertSame($bool, $this->stub->setExcept($except)->checkInExceptArray($this->request));
}
private function assertNonMatchingExcept(array $except)
{
return $this->assertMatchingExcept($except, false);
}
}
|