diff --git a/CHANGELOG.md b/CHANGELOG.md index 66c2477..09516d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +v0.2.0 - 5th Jan 2016 + Renamed from Bairwell/Cors to Bairwell/MiddlewareCors (packagist name Bairwell\Middleware-Cors) + Remove Slim dependency from dev (moved to examples) (fixes https://github.com/bairwell/middleware-cors/issues/2 ) + Added code of conduct and installation instructions (fixed https://github.com/bairwell/middleware-cors/issues/3 ) v0.1.1 - 31st Dec 2015 Made Preflight and ValidateSettings (formerly Validate) their own classes instead of being traits. Migrated from Bitbucket to Github. diff --git a/CONDUCT.md b/CONDUCT.md new file mode 100644 index 0000000..01b8644 --- /dev/null +++ b/CONDUCT.md @@ -0,0 +1,22 @@ +# Contributor Code of Conduct + +As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. + +We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery +* Personal attacks +* Trolling or insulting/derogatory comments +* Public or private harassment +* Publishing other's private information, such as physical or electronic addresses, without explicit permission +* Other unethical or unprofessional conduct. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. + +This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. + +This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e1d6641..025ea81 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,7 +16,7 @@ All pull requests must adhere to the [PSR-2 standard](http://www.php-fig.org/psr This can be checked via, you can run the following commands to check if everything is ready to submit: - cd cors + cd cors-middleware vendor/bin/phpcs -np Which should give you no output, indicating that there are no coding standard errors. And then: @@ -24,11 +24,11 @@ Which should give you no output, indicating that there are no coding standard er ## Unit Testing -All pull requests must be accompanied by passing unit tests and complete code coverage. The Bairwell\Cors library uses phpunit for testing. +All pull requests must be accompanied by passing unit tests and complete code coverage. The Bairwell\MiddlewareCors library uses phpunit for testing. [Learn about PHPUnit](https://github.com/sebastianbergmann/phpunit/) - cd cors + cd cors-middleware vendor/bin/phpunit Which should give you no failures or errors. You can ignore any skipped tests as these are for external tools. diff --git a/LICENSE.md b/LICENSE.md index 7f7f324..2943c22 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2016 Bairwell Ltd. +Copyright (c) 2016 Bairwell Ltd/Richard Bairwell. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README.md b/README.md index 6789b91..868bd8a 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# Bairwell\Cors +# Bairwell\Middleware-Cors -[![Latest Stable Version](https://poser.pugx.org/bairwell/cors/v/stable)](https://packagist.org/packages/bairwell/cors) -[![License](https://poser.pugx.org/bairwell/cors/license)](https://packagist.org/packages/bairwell/cors) +[![Latest Stable Version](https://poser.pugx.org/bairwell/middleware-cors/v/stable)](https://packagist.org/packages/bairwell/middleware-cors) +[![License](https://poser.pugx.org/bairwell/middleware-cors/license)](https://packagist.org/packages/bairwell/middleware-cors) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/8aea9987-e478-4faa-a3fe-728e9423b4e7/mini.png)](https://insight.sensiolabs.com/projects/8aea9987-e478-4faa-a3fe-728e9423b4e7) -[![Coverage Status](https://coveralls.io/repos/bairwell/cors/badge.svg?branch=master&service=github)](https://coveralls.io/github/bairwell/cors?branch=master) -[![Build Status](https://travis-ci.org/bairwell/cors.svg?branch=master)](https://travis-ci.org/bairwell/cors) -[![Total Downloads](https://poser.pugx.org/bairwell/cors/downloads)](https://packagist.org/packages/bairwell/cors) +[![Coverage Status](https://coveralls.io/repos/bairwell/middleware-cors/badge.svg?branch=master&service=github)](https://coveralls.io/github/bairwell/middleware-cors?branch=master) +[![Build Status](https://travis-ci.org/bairwell/middleware-cors.svg?branch=master)](https://travis-ci.org/bairwell/middleware-cors) +[![Total Downloads](https://poser.pugx.org/bairwell/middleware-cors/downloads)](https://packagist.org/packages/bairwell/middleware-cors) This is a PHP 7 [Composer](https://getcomposer.org/) compatible library for providing a [PSR-7]((http://www.php-fig.org/psr/psr-7/) compatible middleware layer for handling "[CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS)" (Cross Origin Request Security/Cross-Origin Http Request/HTTP access control) headers and security. @@ -24,7 +24,28 @@ This is a PHP 7 [Composer](https://getcomposer.org/) compatible library for prov * Licensed under the [MIT License](https://opensource.org/licenses/MIT) allowing you to practically do whatever you want. * Uses namespaces and is 100% object orientated. * Blocks invalid settings. -* Minimal third party requirements (just the definition files "psr/http-message" and "psr/log" for main, and PHPUnit, PHPCodeSniffer, SlimFramework and Monolog for development/testing). +* Minimal third party requirements (just the definition files "[psr/http-message](https://github.com/php-fig/http-message)" and "[psr/log](https://github.com/php-fig/log)" as interface definitions, and [PHPUnit](https://phpunit.de/), [PHPCodeSniffer](http://www.squizlabs.com/php-codesniffer), and [Monolog](https://github.com/Seldaek/monolog) for development/testing). + +# Installation +Install the latest version with Composer via: + +```bash +$ composer require bairwell/middleware-cors +``` + +or by modifying your `composer.json` file: +```` +{ + "require": { + "bairwell/middleware-cors" : "@stable" + } +} +```` + +or from the Github repository (which is needed to be able to fork and contribute): +```` +$ git clone git://github.com:bairwell/middleware-cors.git +```` # Usage @@ -32,7 +53,7 @@ You can utilise this CORs library as simply as: ```php $slim=new \Slim\App(); // use Slim3 as it supports PSR7 middleware -$slim->add(new Cors()); // add CORs +$slim->add(new MiddlewareCors()); // add CORs // add routes $slim->run(); // get Slim running ``` @@ -46,7 +67,7 @@ $slim=new \Slim\App(); // use Slim3 as it supports PSR7 middleware $config=[ 'origin'=>'*.example.com' // allow all hosts ending example.com ]; -$slim->add(new Cors($config)); // add CORs +$slim->add(new MiddlewareCors($config)); // add CORs // add routes $slim->run(); // get Slim running ``` @@ -59,7 +80,7 @@ $config=[ 'origin'=>['*.example.com','*.example.com.test','example.com','dev.*', 'allowCredentials'=>true ]; -$slim->add(new Cors($config)); // add CORs +$slim->add(new MiddlewareCors($config)); // add CORs // add routes $slim->run(); // get Slim running ``` @@ -68,7 +89,7 @@ which will allow all Origins ending .example.com or *.example.com.test, the exac any host starting with dev. It'll also allow credentials to be allowed. For a more complicated integration which relies on the Slim router to feed back which methods are actually -allowed per route, see ``tests/Cors/FunctionalTests/SlimTest.php`` +allowed per route, see ``tests/MiddlewareCors/FunctionalTests/SlimTest.php`` ## Standards @@ -101,7 +122,7 @@ For a list of the tests that have ran: `vendor/bin/phpunit --tap` To restrict the tests run: -`vendor/bin/phpunit --filter 'Cors\\Exceptions\\BadOrigin'` +`vendor/bin/phpunit --filter 'MiddlewareCors\\Exceptions\\BadOrigin'` or just @@ -110,5 +131,21 @@ or just for all tests which have "Exception" in them and: `vendor/bin/phpunit --filter '(ExceptionTest::testEverything|ExceptionTest::testStub)'` -to test the two testEverything and testStub methods in the ExceptionTest class. +to test the two testEverything and testStub methods in the ExceptionTest class (for example). + +# Licence/License + +Licenced under the MIT license. See LICENSE.md for full information. + +Bairwell/MiddlewareCors is Copyright (c) Bairwell Ltd/Richard Bairwell 2016. + +# Supporting development + +You can help support development of this library via a variety of methods: + + * "Sponsorship" via a monthly donation via [Patreon](https://www.patreon.com/rbairwell) + * [Reporting issues](https://github.com/bairwell/middleware-cors/issues) + * Making updates via [Github](https://github.com/bairwell/middleware-cors) + * Spreading the word. + * Just letting me know what you think of it via [Twitter](http://twitter.com/rbairwell) or via [Bairwell Ltd](http://www.bairwell.com) diff --git a/composer.json b/composer.json index 0273b5f..e4d73f7 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { - "name": "bairwell/cors", + "name": "bairwell/middleware-cors", "description": "A PSR-7 middleware layer for providing CORS (Cross Origin Request Security) headers and security provisions. Instead of just allowing invalid CORs requests to come through, this middleware actively blocks them after validating.", - "keywords": ["psr-7","middleware","cors"], - "homepage": "https://bitbucket.org/bairwell/cors", + "keywords": ["psr-7","middleware","cors","cross origin request security"], + "homepage": "https://github.com/bairwell/middleware-cors", "license": "MIT", "authors": [ { @@ -20,7 +20,6 @@ "require-dev": { "phpunit/phpunit": "^5.1", "squizlabs/php_codesniffer": "^2.5", - "slim/slim": "^3.0", "monolog/monolog": "^1.13" }, "autoload": { diff --git a/tests/Cors/FunctionalTests/SlimTest.php b/examples/SlimTest.php similarity index 98% rename from tests/Cors/FunctionalTests/SlimTest.php rename to examples/SlimTest.php index 33159d6..69ca845 100644 --- a/tests/Cors/FunctionalTests/SlimTest.php +++ b/examples/SlimTest.php @@ -1,11 +1,11 @@ $this->allowedHosts, 'exposeHeaders' => '', @@ -253,7 +253,7 @@ public function testOptionsWithOrigin() { $body=$result->getBody(); $body->rewind(); $contents=$body->getContents(); - $this->assertEquals('Error Handler caught exception type Bairwell\Cors\Exceptions\NoMethod: No method provided',$contents); + $this->assertEquals('Error Handler caught exception type Bairwell\MiddlewareCors\Exceptions\NoMethod: No method provided',$contents); $this->assertEquals(500,$result->getStatusCode()); $this->assertEquals('Internal Server Error',$result->getReasonPhrase()); $headers=$result->getHeaders(); diff --git a/src/Cors.php b/src/MiddlewareCors.php similarity index 97% rename from src/Cors.php rename to src/MiddlewareCors.php index 3550dc9..2b2d2f9 100644 --- a/src/Cors.php +++ b/src/MiddlewareCors.php @@ -1,6 +1,6 @@ * @@ -13,14 +13,14 @@ */ declare (strict_types = 1); -namespace Bairwell\Cors; +namespace Bairwell\MiddlewareCors; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Bairwell\Cors\Exceptions\NoMethod; -use Bairwell\Cors\Exceptions\MethodNotAllowed; -use Bairwell\Cors\Exceptions\NoHeadersAllowed; -use Bairwell\Cors\Exceptions\HeaderNotAllowed; +use Bairwell\MiddlewareCors\Exceptions\NoMethod; +use Bairwell\MiddlewareCors\Exceptions\MethodNotAllowed; +use Bairwell\MiddlewareCors\Exceptions\NoHeadersAllowed; +use Bairwell\MiddlewareCors\Exceptions\HeaderNotAllowed; /** * Preflight. diff --git a/src/Cors/Traits/Parse.php b/src/MiddlewareCors/Traits/Parse.php similarity index 99% rename from src/Cors/Traits/Parse.php rename to src/MiddlewareCors/Traits/Parse.php index 355770f..51e3a2e 100644 --- a/src/Cors/Traits/Parse.php +++ b/src/MiddlewareCors/Traits/Parse.php @@ -4,7 +4,7 @@ * * All the CORs orientated parsing code. * - * Part of the Bairwell\Cors package. + * Part of the Bairwell\MiddlewareCors package. * * (c) Richard Bairwell * @@ -13,7 +13,7 @@ */ declare (strict_types = 1); -namespace Bairwell\Cors\Traits; +namespace Bairwell\MiddlewareCors\Traits; use Psr\Http\Message\ServerRequestInterface; diff --git a/src/Cors/ValidateSettings.php b/src/MiddlewareCors/ValidateSettings.php similarity index 98% rename from src/Cors/ValidateSettings.php rename to src/MiddlewareCors/ValidateSettings.php index 03e7526..d28551b 100644 --- a/src/Cors/ValidateSettings.php +++ b/src/MiddlewareCors/ValidateSettings.php @@ -4,7 +4,7 @@ * * All the CORs orientated settings validation code. * - * Part of the Bairwell\Cors package. + * Part of the Bairwell\MiddlewareCors package. * * (c) Richard Bairwell * @@ -13,7 +13,7 @@ */ declare (strict_types = 1); -namespace Bairwell\Cors; +namespace Bairwell\MiddlewareCors; /** * Validate settings. diff --git a/tests/Cors/Exceptions/ExceptionTest.php b/tests/MiddlewareCors/Exceptions/ExceptionTest.php similarity index 59% rename from tests/Cors/Exceptions/ExceptionTest.php rename to tests/MiddlewareCors/Exceptions/ExceptionTest.php index 812cdc7..7b44fa8 100644 --- a/tests/Cors/Exceptions/ExceptionTest.php +++ b/tests/MiddlewareCors/Exceptions/ExceptionTest.php @@ -2,7 +2,7 @@ /** * Tests the exceptions. * - * Part of the Bairwell\Cors package. + * Part of the Bairwell\MiddlewareCors package. * * (c) Richard Bairwell * @@ -11,7 +11,7 @@ */ declare (strict_types = 1); -namespace Bairwell\Cors\Exceptions; +namespace Bairwell\MiddlewareCors\Exceptions; /** * Class ExceptionsTest. @@ -23,13 +23,13 @@ class ExceptionsTest extends \PHPUnit_Framework_TestCase * Bad Origin. * * @test - * @covers \Bairwell\Cors\Exceptions\BadOrigin - * @covers \Bairwell\Cors\Exceptions\ExceptionAbstract + * @covers \Bairwell\MiddlewareCors\Exceptions\BadOrigin + * @covers \Bairwell\MiddlewareCors\Exceptions\ExceptionAbstract */ public function testBadOrigin() { $sut=new BadOrigin(); - $this->assertInstanceOf('\Bairwell\Cors\Exceptions\BadOrigin',$sut); - $this->assertInstanceOf('\Bairwell\Cors\Exceptions\ExceptionAbstract',$sut); + $this->assertInstanceOf('\Bairwell\MiddlewareCors\Exceptions\BadOrigin',$sut); + $this->assertInstanceOf('\Bairwell\MiddlewareCors\Exceptions\ExceptionAbstract',$sut); $this->basicChecks($sut); } @@ -37,13 +37,13 @@ public function testBadOrigin() { * Header not allowed. * * @test - * @covers \Bairwell\Cors\Exceptions\HeaderNotAllowed - * @covers \Bairwell\Cors\Exceptions\ExceptionAbstract + * @covers \Bairwell\MiddlewareCors\Exceptions\HeaderNotAllowed + * @covers \Bairwell\MiddlewareCors\Exceptions\ExceptionAbstract */ public function testHeaderNotAllowed() { $sut=new HeaderNotAllowed(); - $this->assertInstanceOf('\Bairwell\Cors\Exceptions\HeaderNotAllowed',$sut); - $this->assertInstanceOf('\Bairwell\Cors\Exceptions\ExceptionAbstract',$sut); + $this->assertInstanceOf('\Bairwell\MiddlewareCors\Exceptions\HeaderNotAllowed',$sut); + $this->assertInstanceOf('\Bairwell\MiddlewareCors\Exceptions\ExceptionAbstract',$sut); $this->basicChecks($sut); } @@ -51,39 +51,39 @@ public function testHeaderNotAllowed() { * Method not allowed. * * @test - * @covers \Bairwell\Cors\Exceptions\MethodNotAllowed - * @covers \Bairwell\Cors\Exceptions\ExceptionAbstract + * @covers \Bairwell\MiddlewareCors\Exceptions\MethodNotAllowed + * @covers \Bairwell\MiddlewareCors\Exceptions\ExceptionAbstract */ public function testMethodNotAllowed() { $sut=new MethodNotAllowed(); - $this->assertInstanceOf('\Bairwell\Cors\Exceptions\MethodNotAllowed',$sut); - $this->assertInstanceOf('\Bairwell\Cors\Exceptions\ExceptionAbstract',$sut); + $this->assertInstanceOf('\Bairwell\MiddlewareCors\Exceptions\MethodNotAllowed',$sut); + $this->assertInstanceOf('\Bairwell\MiddlewareCors\Exceptions\ExceptionAbstract',$sut); $this->basicChecks($sut); } /** * No Headers Allowed. * * @test - * @covers \Bairwell\Cors\Exceptions\MethodNotAllowed - * @covers \Bairwell\Cors\Exceptions\ExceptionAbstract + * @covers \Bairwell\MiddlewareCors\Exceptions\MethodNotAllowed + * @covers \Bairwell\MiddlewareCors\Exceptions\ExceptionAbstract */ public function testNoHeadersAllowed() { $sut=new NoHeadersAllowed(); - $this->assertInstanceOf('\Bairwell\Cors\Exceptions\NoHeadersAllowed',$sut); - $this->assertInstanceOf('\Bairwell\Cors\Exceptions\ExceptionAbstract',$sut); + $this->assertInstanceOf('\Bairwell\MiddlewareCors\Exceptions\NoHeadersAllowed',$sut); + $this->assertInstanceOf('\Bairwell\MiddlewareCors\Exceptions\ExceptionAbstract',$sut); $this->basicChecks($sut); } /** * No Method. * * @test - * @covers \Bairwell\Cors\Exceptions\MethodNotAllowed - * @covers \Bairwell\Cors\Exceptions\ExceptionAbstract + * @covers \Bairwell\MiddlewareCors\Exceptions\MethodNotAllowed + * @covers \Bairwell\MiddlewareCors\Exceptions\ExceptionAbstract */ public function testNoMethod() { $sut=new NoMethod(); - $this->assertInstanceOf('\Bairwell\Cors\Exceptions\NoMethod',$sut); - $this->assertInstanceOf('\Bairwell\Cors\Exceptions\ExceptionAbstract',$sut); + $this->assertInstanceOf('\Bairwell\MiddlewareCors\Exceptions\NoMethod',$sut); + $this->assertInstanceOf('\Bairwell\MiddlewareCors\Exceptions\ExceptionAbstract',$sut); $this->basicChecks($sut); } diff --git a/tests/Cors/PreflightTest.php b/tests/MiddlewareCors/PreflightTest.php similarity index 75% rename from tests/Cors/PreflightTest.php rename to tests/MiddlewareCors/PreflightTest.php index e2dca79..671bddd 100644 --- a/tests/Cors/PreflightTest.php +++ b/tests/MiddlewareCors/PreflightTest.php @@ -1,35 +1,35 @@ getProperty('settings'); $settingsProperty->setAccessible(true); @@ -369,11 +369,11 @@ public function testParseAllowCredentialsCallables() * Uses reflection as this is a protected method. * * @test - * @covers \Bairwell\Cors\Traits\Parse::parseAllowCredentials + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseAllowCredentials */ public function testParseAllowCredentialValues() { - $sut = new Cors(); + $sut = new MiddlewareCors(); $reflection = new \ReflectionClass(get_class($sut)); $settingsProperty = $reflection->getProperty('settings'); $settingsProperty->setAccessible(true); @@ -413,11 +413,11 @@ public function testParseAllowCredentialValues() * Uses reflection as this is a protected method. * * @test - * @covers \Bairwell\Cors\Traits\Parse::parseMaxAge + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseMaxAge */ public function testParseMaxAgeCallables() { - $sut = new Cors(); + $sut = new MiddlewareCors(); $reflection = new \ReflectionClass(get_class($sut)); $settingsProperty = $reflection->getProperty('settings'); $settingsProperty->setAccessible(true); @@ -496,11 +496,11 @@ public function testParseMaxAgeCallables() * Uses reflection as this is a protected method. * * @test - * @covers \Bairwell\Cors\Traits\Parse::parseOrigin + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOrigin */ public function testParseOriginEmptyString() { - $sut = new Cors(); + $sut = new MiddlewareCors(); // setup the logger $this->logger = new Logger('test'); $this->testLogger = new TestHandler(); @@ -530,11 +530,11 @@ public function testParseOriginEmptyString() * Uses reflection as this is a protected method. * * @test - * @covers \Bairwell\Cors\Traits\Parse::parseOrigin + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOrigin */ public function testParseOriginInvalidString() { - $sut = new Cors(); + $sut = new MiddlewareCors(); // setup the logger $this->logger = new Logger('test'); $this->testLogger = new TestHandler(); @@ -564,11 +564,11 @@ public function testParseOriginInvalidString() * Uses reflection as this is a protected method. * * @test - * @covers \Bairwell\Cors\Traits\Parse::parseMaxAge + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseMaxAge */ public function testParseMaxAgeValues() { - $sut = new Cors(); + $sut = new MiddlewareCors(); $reflection = new \ReflectionClass(get_class($sut)); $settingsProperty = $reflection->getProperty('settings'); $settingsProperty->setAccessible(true); @@ -622,7 +622,7 @@ public function testParseMaxAgeValues() */ protected function parseItem($settingValue, string $expectedResult, bool $isSingle = false) { - $sut = new Cors(); + $sut = new MiddlewareCors(); $reflection = new \ReflectionClass(get_class($sut)); $settingsProperty = $reflection->getProperty('settings'); $settingsProperty->setAccessible(true); diff --git a/tests/Cors/Traits/RunInvokeArrays.php b/tests/MiddlewareCors/Traits/RunInvokeArrays.php similarity index 96% rename from tests/Cors/Traits/RunInvokeArrays.php rename to tests/MiddlewareCors/Traits/RunInvokeArrays.php index 4d400fa..a6686ff 100644 --- a/tests/Cors/Traits/RunInvokeArrays.php +++ b/tests/MiddlewareCors/Traits/RunInvokeArrays.php @@ -1,14 +1,14 @@ assertInstanceOf('Bairwell\Cors', $sut); + $this->assertInstanceOf('Bairwell\MiddlewareCors', $sut); $sutSettings = array_merge($this->defaults, $settings['configuration']); $this->arraysAreSimilar($sutSettings, $sut->getSettings(), 'Matching internal settings'); // setup the logger diff --git a/tests/Cors/ValidateSettingsTest.php b/tests/MiddlewareCors/ValidateSettingsTest.php similarity index 80% rename from tests/Cors/ValidateSettingsTest.php rename to tests/MiddlewareCors/ValidateSettingsTest.php index abfe0ee..77486c6 100644 --- a/tests/Cors/ValidateSettingsTest.php +++ b/tests/MiddlewareCors/ValidateSettingsTest.php @@ -1,21 +1,21 @@ 'string', 'value' => 'abc'], diff --git a/tests/CorsTest.php b/tests/MiddlewareCorsTest.php similarity index 83% rename from tests/CorsTest.php rename to tests/MiddlewareCorsTest.php index 164f359..51f56f6 100644 --- a/tests/CorsTest.php +++ b/tests/MiddlewareCorsTest.php @@ -2,7 +2,7 @@ /** * Tests the main CORs system. * - * Part of the Bairwell\Cors package. + * Part of the Bairwell\MiddlewareCors package. * * (c) Richard Bairwell * @@ -13,34 +13,34 @@ namespace Bairwell; -use Bairwell\Cors\Exceptions\BadOrigin; +use Bairwell\MiddlewareCors\Exceptions\BadOrigin; /** * Class CorsTest. * Tests the CORs middleware layer. * - * @uses \Bairwell\Cors - * @uses \Bairwell\Cors\ValidateSettings - * @uses \Bairwell\Cors\Traits\Parse - * @uses \Bairwell\Cors\Preflight - * @uses \Bairwell\Cors\Exceptions\ExceptionAbstract + * @uses \Bairwell\MiddlewareCors + * @uses \Bairwell\MiddlewareCors\ValidateSettings + * @uses \Bairwell\MiddlewareCors\Traits\Parse + * @uses \Bairwell\MiddlewareCors\Preflight + * @uses \Bairwell\MiddlewareCors\Exceptions\ExceptionAbstract */ -class CorsTest extends \PHPUnit_Framework_TestCase +class MiddlewareCorsTest extends \PHPUnit_Framework_TestCase { - use \Bairwell\Cors\Traits\RunInvokeArrays; + use \Bairwell\MiddlewareCors\Traits\RunInvokeArrays; /** * Checks the default settings. * * @test - * @covers \Bairwell\Cors::__construct - * @covers \Bairwell\Cors::getDefaults - * @covers \Bairwell\Cors::getSettings - * @covers \Bairwell\Cors::getAllowedSettings + * @covers \Bairwell\MiddlewareCors::__construct + * @covers \Bairwell\MiddlewareCors::getDefaults + * @covers \Bairwell\MiddlewareCors::getSettings + * @covers \Bairwell\MiddlewareCors::getAllowedSettings */ public function testCheckDefaultSettings() { - $sut = new Cors(); + $sut = new MiddlewareCors(); $defaults = $sut->getDefaults(); $this->arraysAreSimilar($this->defaults, $defaults); $settings = $sut->getSettings(); @@ -53,11 +53,11 @@ public function testCheckDefaultSettings() * Test the logger can be configured. * * @test - * @covers \Bairwell\Cors::addLog - * @covers \Bairwell\Cors::setLogger + * @covers \Bairwell\MiddlewareCors::addLog + * @covers \Bairwell\MiddlewareCors::setLogger */ public function testLogger() { - $sut = new Cors(); + $sut = new MiddlewareCors(); $addLog=new \ReflectionMethod($sut,'addLog'); $addLog->setAccessible(true); $this->assertFalse($addLog->invoke($sut,'Log entry')); @@ -73,12 +73,12 @@ public function testLogger() { * Checks the settings can be changed via the constructor. * * @test - * @covers \Bairwell\Cors::__construct - * @covers \Bairwell\Cors::getSettings + * @covers \Bairwell\MiddlewareCors::__construct + * @covers \Bairwell\MiddlewareCors::getSettings */ public function testCheckChangedSettingsViaConstructor() { - $sut = new Cors(['origin' => 'test']); + $sut = new MiddlewareCors(['origin' => 'test']); $expected = $this->defaults; $expected['origin'] = 'test'; $settings = $sut->getSettings(); @@ -89,13 +89,13 @@ public function testCheckChangedSettingsViaConstructor() * Checks the settings can be changed via the setter. * * @test - * @covers \Bairwell\Cors::__construct - * @covers \Bairwell\Cors::getSettings - * @covers \Bairwell\Cors::setSettings + * @covers \Bairwell\MiddlewareCors::__construct + * @covers \Bairwell\MiddlewareCors::getSettings + * @covers \Bairwell\MiddlewareCors::setSettings */ public function testCheckChangedSettingsViaSetter() { - $sut = new Cors(); + $sut = new MiddlewareCors(); $sut->setSettings(['maxAge' => 123, 'allowCredentials' => true]); $expected = $this->defaults; $expected['maxAge'] = 123; @@ -108,12 +108,12 @@ public function testCheckChangedSettingsViaSetter() * Checks the settings will allow random stuff to be set. * * @test - * @covers \Bairwell\Cors::__construct - * @covers \Bairwell\Cors::getSettings + * @covers \Bairwell\MiddlewareCors::__construct + * @covers \Bairwell\MiddlewareCors::getSettings */ public function testCheckChangedSettingsViaSetterRandomSettings() { - $sut = new Cors(); + $sut = new MiddlewareCors(); $sut->setSettings(['maxAge' => 123, 'allowCredentials' => true, 'random' => '123']); $expected = $this->defaults; $expected['maxAge'] = 123; @@ -130,8 +130,8 @@ public function testCheckChangedSettingsViaSetterRandomSettings() * Should have no CORS headers back. * * @test - * @covers \Bairwell\Cors::__construct - * @covers \Bairwell\Cors::__invoke + * @covers \Bairwell\MiddlewareCors::__construct + * @covers \Bairwell\MiddlewareCors::__invoke */ public function testInvokerGetDefaults() { @@ -162,10 +162,10 @@ public function testInvokerGetDefaults() * and next called. * * @test - * @covers \Bairwell\Cors::__construct - * @covers \Bairwell\Cors::__invoke - * @covers \Bairwell\Cors\Traits\Parse::parseOriginMatch - * @covers \Bairwell\Cors\Traits\Parse::parseOrigin + * @covers \Bairwell\MiddlewareCors::__construct + * @covers \Bairwell\MiddlewareCors::__invoke + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOriginMatch + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOrigin */ public function testInvokerWithOriginHeader() { @@ -203,10 +203,10 @@ public function testInvokerWithOriginHeader() * and next called. * * @test - * @covers \Bairwell\Cors::__construct - * @covers \Bairwell\Cors::__invoke - * @covers \Bairwell\Cors\Traits\Parse::parseOriginMatch - * @covers \Bairwell\Cors\Traits\Parse::parseOrigin + * @covers \Bairwell\MiddlewareCors::__construct + * @covers \Bairwell\MiddlewareCors::__invoke + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOriginMatch + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOrigin */ public function testInvokerWithCustomOriginHeader() { @@ -241,11 +241,11 @@ public function testInvokerWithCustomOriginHeader() * should get access denied. * * @test - * @covers \Bairwell\Cors::__construct - * @covers \Bairwell\Cors::__invoke - * @covers \Bairwell\Cors\Traits\Parse::parseOriginMatch - * @covers \Bairwell\Cors\Traits\Parse::parseOrigin - * @uses \Bairwell\Cors\Exceptions\BadOrigin + * @covers \Bairwell\MiddlewareCors::__construct + * @covers \Bairwell\MiddlewareCors::__invoke + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOriginMatch + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOrigin + * @uses \Bairwell\MiddlewareCors\Exceptions\BadOrigin */ public function testInvokerWithCustomOriginHeaderInvalid() { @@ -284,10 +284,10 @@ public function testInvokerWithCustomOriginHeaderInvalid() * should just get "Next" as (with a blank/unset origin), this is not a cors call. * * @test - * @covers \Bairwell\Cors::__construct - * @covers \Bairwell\Cors::__invoke - * @covers \Bairwell\Cors\Traits\Parse::parseOriginMatch - * @covers \Bairwell\Cors\Traits\Parse::parseOrigin + * @covers \Bairwell\MiddlewareCors::__construct + * @covers \Bairwell\MiddlewareCors::__invoke + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOriginMatch + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOrigin */ public function testInvokerWithCustomOriginHeaderEmpty() { @@ -316,11 +316,11 @@ public function testInvokerWithCustomOriginHeaderEmpty() * should get access denied. * * @test - * @covers \Bairwell\Cors::__construct - * @covers \Bairwell\Cors::__invoke - * @covers \Bairwell\Cors\Traits\Parse::parseOriginMatch - * @covers \Bairwell\Cors\Traits\Parse::parseOrigin - * @uses \Bairwell\Cors\Exceptions\BadOrigin + * @covers \Bairwell\MiddlewareCors::__construct + * @covers \Bairwell\MiddlewareCors::__invoke + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOriginMatch + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOrigin + * @uses \Bairwell\MiddlewareCors\Exceptions\BadOrigin */ public function testInvokerWithCustomOriginHeaderDummyCallback() { @@ -358,11 +358,11 @@ public function testInvokerWithCustomOriginHeaderDummyCallback() * should get access denied. * * @test - * @covers \Bairwell\Cors::__construct - * @covers \Bairwell\Cors::__invoke - * @covers \Bairwell\Cors\Traits\Parse::parseOriginMatch - * @covers \Bairwell\Cors\Traits\Parse::parseOrigin - * @uses \Bairwell\Cors\Exceptions\BadOrigin + * @covers \Bairwell\MiddlewareCors::__construct + * @covers \Bairwell\MiddlewareCors::__invoke + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOriginMatch + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOrigin + * @uses \Bairwell\MiddlewareCors\Exceptions\BadOrigin */ public function testInvokerWithCustomOriginHeaderCustomCallbacks() { @@ -406,10 +406,10 @@ public function testInvokerWithCustomOriginHeaderCustomCallbacks() * and next called. * * @test - * @covers \Bairwell\Cors::__construct - * @covers \Bairwell\Cors::__invoke - * @covers \Bairwell\Cors\Traits\Parse::parseOriginMatch - * @covers \Bairwell\Cors\Traits\Parse::parseOrigin + * @covers \Bairwell\MiddlewareCors::__construct + * @covers \Bairwell\MiddlewareCors::__invoke + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOriginMatch + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOrigin */ public function testInvokerWithCustomOriginHeaderCustomAllowedCallbacks() { @@ -450,10 +450,10 @@ public function testInvokerWithCustomOriginHeaderCustomAllowedCallbacks() * and next called. * * @test - * @covers \Bairwell\Cors::__construct - * @covers \Bairwell\Cors::__invoke - * @covers \Bairwell\Cors\Traits\Parse::parseOriginMatch - * @covers \Bairwell\Cors\Traits\Parse::parseOrigin + * @covers \Bairwell\MiddlewareCors::__construct + * @covers \Bairwell\MiddlewareCors::__invoke + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOriginMatch + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOrigin */ public function testInvokerWithOriginArray() { @@ -493,10 +493,10 @@ public function testInvokerWithOriginArray() * and next called. * * @test - * @covers \Bairwell\Cors::__construct - * @covers \Bairwell\Cors::__invoke - * @covers \Bairwell\Cors\Traits\Parse::parseOriginMatch - * @covers \Bairwell\Cors\Traits\Parse::parseOrigin + * @covers \Bairwell\MiddlewareCors::__construct + * @covers \Bairwell\MiddlewareCors::__invoke + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOriginMatch + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOrigin */ public function testInvokerWithOriginArrayWildcard() { @@ -535,11 +535,11 @@ public function testInvokerWithOriginArrayWildcard() * access denied. * * @test - * @covers \Bairwell\Cors::__construct - * @covers \Bairwell\Cors::__invoke - * @covers \Bairwell\Cors\Traits\Parse::parseOriginMatch - * @covers \Bairwell\Cors\Traits\Parse::parseOrigin - * @uses \Bairwell\Cors\Exceptions\BadOrigin + * @covers \Bairwell\MiddlewareCors::__construct + * @covers \Bairwell\MiddlewareCors::__invoke + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOriginMatch + * @covers \Bairwell\MiddlewareCors\Traits\Parse::parseOrigin + * @uses \Bairwell\MiddlewareCors\Exceptions\BadOrigin */ public function testInvokerWithOriginArrayInvalid() { @@ -583,8 +583,8 @@ public function testInvokerWithOriginArrayInvalid() * and next called. * * @test - * @covers \Bairwell\Cors::__construct - * @covers \Bairwell\Cors::__invoke + * @covers \Bairwell\MiddlewareCors::__construct + * @covers \Bairwell\MiddlewareCors::__invoke */ public function testInvokerWithOriginHeaderAndCredentials() { @@ -629,8 +629,8 @@ public function testInvokerWithOriginHeaderAndCredentials() * and next called. * * @test - * @covers \Bairwell\Cors::__construct - * @covers \Bairwell\Cors::__invoke + * @covers \Bairwell\MiddlewareCors::__construct + * @covers \Bairwell\MiddlewareCors::__invoke */ public function testInvokerWithOriginHeaderAndCredentialsWithHeaders() {