Skip to content

Commit

Permalink
test: add tests for exception messages
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Mar 23, 2024
1 parent 8ce803f commit 4dfb2d0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/system/Filters/CorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ public function testItReturnsAllowHeadersHeaderOnAllowAllHeadersRequest()
public function testItDoesntPermitWildcardAllowedHeadersAndSupportsCredentials()
{
$this->expectException(ConfigException::class);
$this->expectExceptionMessage(
'When responding to a credentialed request, the server must not specify the "*" wildcard for the Access-Control-Allow-Headers response-header value.'
);

$this->cors = $this->createCors(['allowedHeaders' => ['*'], 'supportsCredentials' => true]);
$request = $this->createValidPreflightRequest();
Expand Down Expand Up @@ -233,6 +236,9 @@ public function testItSetsExposedHeadersWhenConfiguredOnActualRequest()
public function testItDoesNotPermitWildcardAllowedOriginsAndSupportsCredentials()
{
$this->expectException(ConfigException::class);
$this->expectExceptionMessage(
'When responding to a credentialed request, the server must not specify the "*" wildcard for the Access-Control-Allow-Origin response-header value.'
);

$this->cors = $this->createCors([
'allowedOrigins' => ['*'],
Expand All @@ -246,6 +252,9 @@ public function testItDoesNotPermitWildcardAllowedOriginsAndSupportsCredentials(
public function testItDoesNotPermitWildcardAllowedOriginsAllowedMethodAndSupportsCredentials()
{
$this->expectException(ConfigException::class);
$this->expectExceptionMessage(
'When responding to a credentialed request, the server must not specify the "*" wildcard for the Access-Control-Allow-Origin response-header value.'
);

$this->cors = $this->createCors([
'allowedOrigins' => ['*'],
Expand Down Expand Up @@ -273,6 +282,9 @@ public function testItAddsAVaryHeaderWhenHasOriginPatterns()
public function testItDoesntPermitWildcardAndOrigin()
{
$this->expectException(ConfigException::class);
$this->expectExceptionMessage(
"If wildcard is specified, you must set `'allowedOrigins' => ['*']`. But using wildcard is not recommended."
);

$this->cors = $this->createCors([
'allowedOrigins' => ['*', 'http://localhost'],
Expand Down

0 comments on commit 4dfb2d0

Please sign in to comment.