123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace Barryvdh\Cors\Tests;
- class GroupMiddlewareTest extends TestCase
- {
- public function testOptionsAllowOriginAllowed()
- {
- $crawler = $this->call('OPTIONS', 'api/ping', [], [], [], [
- 'HTTP_ORIGIN' => 'localhost',
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST',
- ]);
- $this->assertEquals('localhost', $crawler->headers->get('Access-Control-Allow-Origin'));
- $this->assertEquals(200, $crawler->getStatusCode());
- }
- public function testAllowOriginAllowed()
- {
- $crawler = $this->call('POST', 'api/ping', [], [], [], [
- 'HTTP_ORIGIN' => 'localhost',
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST',
- ]);
- $this->assertEquals('localhost', $crawler->headers->get('Access-Control-Allow-Origin'));
- $this->assertEquals(200, $crawler->getStatusCode());
- $this->assertEquals('PONG', $crawler->getContent());
- }
- public function testAllowOriginNotAllowed()
- {
- $crawler = $this->call('POST', 'api/ping', [], [], [], [
- 'HTTP_ORIGIN' => 'otherhost',
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST',
- ]);
- $this->assertEquals(null, $crawler->headers->get('Access-Control-Allow-Origin'));
- $this->assertEquals(403, $crawler->getStatusCode());
- }
- public function testAllowMethodAllowed()
- {
- $crawler = $this->call('POST', 'api/ping', [], [], [], [
- 'HTTP_ORIGIN' => 'localhost',
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST',
- ]);
- $this->assertEquals(null, $crawler->headers->get('Access-Control-Allow-Methods'));
- $this->assertEquals(200, $crawler->getStatusCode());
- $this->assertEquals('PONG', $crawler->getContent());
- }
- public function testAllowMethodNotAllowed()
- {
- $crawler = $this->call('POST', 'api/ping', [], [], [], [
- 'HTTP_ORIGIN' => 'localhost',
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'PUT',
- ]);
- $this->assertEquals(null, $crawler->headers->get('Access-Control-Allow-Methods'));
- $this->assertEquals(200, $crawler->getStatusCode());
- }
- public function testAllowMethodsForWebNotAllowed()
- {
- $crawler = $this->call('POST', 'web/ping', [], [], [], [
- 'HTTP_ORIGIN' => 'localhost',
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST',
- ]);
- $this->assertEquals(null, $crawler->headers->get('Access-Control-Allow-Methods'));
- $this->assertEquals(200, $crawler->getStatusCode());
- }
- public function testAllowHeaderAllowed()
- {
- $crawler = $this->call('POST', 'api/ping', [], [], [], [
- 'HTTP_ORIGIN' => 'localhost',
- 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'x-custom-1, x-custom-2',
- ]);
- $this->assertEquals(null, $crawler->headers->get('Access-Control-Allow-Headers'));
- $this->assertEquals(200, $crawler->getStatusCode());
- $this->assertEquals('PONG', $crawler->getContent());
- }
- public function testAllowHeaderNotAllowed()
- {
- $crawler = $this->call('POST', 'api/ping', [], [], [], [
- 'HTTP_ORIGIN' => 'localhost',
- 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'x-custom-3',
- ]);
- $this->assertEquals(null, $crawler->headers->get('Access-Control-Allow-Headers'));
- $this->assertEquals(200, $crawler->getStatusCode());
- }
- public function testError()
- {
- if ($this->checkVersion('5.3', '<')) {
- $this->markTestSkipped('Catching exceptions is not possible on Laravel 5.1');
- }
- $crawler = $this->call('POST', 'api/error', [], [], [], [
- 'HTTP_ORIGIN' => 'localhost',
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST',
- ]);
- $this->assertEquals('localhost', $crawler->headers->get('Access-Control-Allow-Origin'));
- $this->assertEquals(500, $crawler->getStatusCode());
- }
- public function testValidationException()
- {
- if ($this->checkVersion('5.3', '<')) {
- $this->markTestSkipped('Catching exceptions is not possible on Laravel 5.1');
- }
- $crawler = $this->call('POST', 'api/validation', [], [], [], [
- 'HTTP_ORIGIN' => 'localhost',
- 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'POST',
- ]);
- $this->assertEquals('localhost', $crawler->headers->get('Access-Control-Allow-Origin'));
- $this->assertEquals(302, $crawler->getStatusCode());
- }
- }
|