-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from bairwell/develop
v0.3.0 - Add handling of fully qualified origin settings
- Loading branch information
Showing
4 changed files
with
50 additions
and
2 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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
/phpcs.xml | ||
/phpunit.xml | ||
.idea/* | ||
/vendor/ | ||
/build | ||
composer.lock |
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
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
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
/** | ||
* Tests the main CORs system. | ||
* | ||
* | ||
* Part of the Bairwell\MiddlewareCors package. | ||
* | ||
* (c) Richard Bairwell <[email protected]> | ||
|
@@ -193,6 +193,47 @@ public function testInvokerWithOriginHeader() | |
|
||
}//end testInvokerWithOriginHeader() | ||
|
||
/** | ||
* Runs a test based on this having: | ||
* - Method: GET | ||
* - * allowed origin (default) | ||
* - Origin set to example.com (matching wildcard) | ||
* should get | ||
* Access-Control-Allow-Origin | ||
* and next called. | ||
* | ||
* @test | ||
* @covers \Bairwell\MiddlewareCors::__construct | ||
* @covers \Bairwell\MiddlewareCors::__invoke | ||
* @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOriginMatch | ||
* @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOrigin | ||
*/ | ||
public function testInvokerWithFullyQualifiedOriginHeader() | ||
{ | ||
$results = $this->runInvoke( | ||
[ | ||
'method' => 'GET', | ||
'setHeaders' => ['origin' => 'http://example.com:83/text.html'], | ||
'configuration' => [] | ||
] | ||
); | ||
$expected = ['withHeader:Access-Control-Allow-Origin' => '*', 'calledNext' => 'called']; | ||
$this->arraysAreSimilar($results, $expected); | ||
// check logs | ||
$expectedLogs=[ | ||
'Request has an origin setting and is being treated like a CORs request', | ||
'Processing origin of "http://example.com:83/text.html"', | ||
'Parsed a hostname from origin: example.com', | ||
'Attempting to match origin as string', | ||
'Checking configuration origin of "*" against user "example.com"', | ||
'Origin is either an empty string or wildcarded star. Returning *', | ||
'Processing with origin of "*"', | ||
'Calling next bit of middleware' | ||
]; | ||
$logEntries=$this->getLoggerStrings(); | ||
$this->assertEquals($expectedLogs,$logEntries); | ||
|
||
}//end testInvokerWithOriginHeader() | ||
/** | ||
* Runs a test based on this having: | ||
* - Method: GET | ||
|