From 36a3c04b454fc4e4c15cc9a232d86ad08cfe4e2b Mon Sep 17 00:00:00 2001 From: Marcus Olsson Date: Fri, 9 Feb 2018 08:34:03 +0100 Subject: [PATCH 1/9] New testing-procedure. --- .travis.yml | 18 +++++++++++++++--- composer.json | 8 ++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 54f447e..a248516 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,22 @@ language: php -php: - - 7.0 - - nightly before_script: - travis_retry composer self-update - travis_retry composer install --prefer-dist --no-interaction script: composer test + +matrix: + include: + - php: 5.6 + env: ILLUMINATE_VERSION=5.1.* + - php: 5.6 + env: ILLUMINATE_VERSION=5.2.* + - php: 7.0 + env: ILLUMINATE_VERSION=5.3.* + - php: 7.1 + env: ILLUMINATE_VERSION=5.4.* + - php: 7.1 + env: ILLUMINATE_VERSION=5.5.* + - php: 7.1 + env: ILLUMINATE_VERSION=5.6.* diff --git a/composer.json b/composer.json index 00f8934..dc7a4a8 100644 --- a/composer.json +++ b/composer.json @@ -17,12 +17,12 @@ } ], "require": { - "illuminate/support": "~5.5", - "php" : ">=7.0" + "illuminate/support": ">=5.0", + "php" : ">=5.4" }, "require-dev": { - "phpunit/phpunit" : "~6.0", - "orchestra/testbench": "~3.5" + "phpunit/phpunit" : ">=6.0", + "orchestra/testbench": ">=3.0" }, "autoload": { "psr-4": { From 76d40c97101724504b7eb767bb43c3f441ce8cd7 Mon Sep 17 00:00:00 2001 From: Marcus Olsson Date: Fri, 9 Feb 2018 08:36:38 +0100 Subject: [PATCH 2/9] Travis CI-config update. --- .travis.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.travis.yml b/.travis.yml index a248516..0c7ef79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,11 @@ before_script: script: composer test +before_install: + - composer require "illuminate/support:${ILLUMINATE_VERSION}" --no-update + +install: composer update --prefer-source --no-interaction --dev + matrix: include: - php: 5.6 @@ -20,3 +25,7 @@ matrix: env: ILLUMINATE_VERSION=5.5.* - php: 7.1 env: ILLUMINATE_VERSION=5.6.* + - php: nightly + env: ILLUMINATE_VERSION=5.5.* + - php: nightly + env: ILLUMINATE_VERSION=5.6.* From 0afbdc5a9521bc4bd09060b09df396b61822e488 Mon Sep 17 00:00:00 2001 From: Marcus Olsson Date: Fri, 9 Feb 2018 08:50:30 +0100 Subject: [PATCH 3/9] Additional tweaks. --- .travis.yml | 8 ++------ README.jp.md | 11 +++++------ README.md | 13 +++++++------ composer.json | 8 ++++---- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0c7ef79..37ac4c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,12 +13,8 @@ install: composer update --prefer-source --no-interaction --dev matrix: include: - - php: 5.6 - env: ILLUMINATE_VERSION=5.1.* - - php: 5.6 - env: ILLUMINATE_VERSION=5.2.* - php: 7.0 - env: ILLUMINATE_VERSION=5.3.* + env: ILLUMINATE_VERSION=5.4.* - php: 7.1 env: ILLUMINATE_VERSION=5.4.* - php: 7.1 @@ -26,6 +22,6 @@ matrix: - php: 7.1 env: ILLUMINATE_VERSION=5.6.* - php: nightly - env: ILLUMINATE_VERSION=5.5.* + env: ILLUMINATE_VERSION=5.4.* - php: nightly env: ILLUMINATE_VERSION=5.6.* diff --git a/README.jp.md b/README.jp.md index d573755..bd62874 100644 --- a/README.jp.md +++ b/README.jp.md @@ -24,12 +24,11 @@ Basic認証は望まないユーザーからのアクセスを排除すること ## 対応バージョン - Laravel | l5-very-basic-auth -:---------------|:---------- - 5.1.x/5.2.x | 1.x - 5.3.x | 2.x - 5.4.x | 3.x - 5.5.x | 4.x +Laravel | l5-very-basic-auth +:--------------------------------|:---------- +`5.1.*/5.2.*` | `1.*` +`5.3.*` | `2.*` +`5.4.*`/`5.5.*`/`5.6.*` | `5.*` #### Laravel4.xを使っている場合 diff --git a/README.md b/README.md index adeb162..2033157 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,13 @@ While HTTP Basic Auth does give you a protection layer against unwanted visitors ## Version Compatibility - Laravel | l5-very-basic-auth -:---------------|:---------- - 5.1.x/5.2.x | 1.x - 5.3.x | 2.x - 5.4.x | 3.x - 5.5.x | 4.x +Laravel | l5-very-basic-auth +:--------------------------------|:---------- +`5.1.*/5.2.*` | `1.*` +`5.3.*` | `2.*` +`5.4.*`/`5.5.*`/`5.6.*` | `5.*` + +*The odd versioning is due to breaking changes in the testing framework. Else, `3.x` is usable for Laravel 5.4 and `4.x` for Laravel 5.5.* #### Using Laravel 4.x? diff --git a/composer.json b/composer.json index dc7a4a8..431b232 100644 --- a/composer.json +++ b/composer.json @@ -17,12 +17,12 @@ } ], "require": { - "illuminate/support": ">=5.0", - "php" : ">=5.4" + "illuminate/support": ">=5.4", + "php" : "7.*" }, "require-dev": { - "phpunit/phpunit" : ">=6.0", - "orchestra/testbench": ">=3.0" + "phpunit/phpunit" : ">=5.0", + "orchestra/testbench": "3.*" }, "autoload": { "psr-4": { From eb06ba1bbf7c120e709b481b9213a480908a8d26 Mon Sep 17 00:00:00 2001 From: Alexander Menk Date: Thu, 15 Mar 2018 10:20:07 +0100 Subject: [PATCH 4/9] Allow protecting all envs --- src/Http/Middleware/VeryBasicAuth.php | 2 +- src/config.stub | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Http/Middleware/VeryBasicAuth.php b/src/Http/Middleware/VeryBasicAuth.php index 62e8415..796c4bb 100644 --- a/src/Http/Middleware/VeryBasicAuth.php +++ b/src/Http/Middleware/VeryBasicAuth.php @@ -17,7 +17,7 @@ public function handle($request, Closure $next) $config = config('very_basic_auth'); // Check if middleware is in use in current environment - if(in_array(app()->environment(), $config['envs'])) { + if($config['envs'] == '*' || in_array(app()->environment(), $config['envs'])) { if($request->getUser() != $config['user'] || $request->getPassword() != $config['password']) { $header = ['WWW-Authenticate' => 'Basic']; diff --git a/src/config.stub b/src/config.stub index d9fd339..ccdb203 100644 --- a/src/config.stub +++ b/src/config.stub @@ -10,7 +10,7 @@ // Password 'password' => '%password%', - // Environments where the middleware is active + // Environments where the middleware is active, use 'envs' => '*' to protect all envs 'envs' => [ 'local', 'development', From d4afe1ffb012ad451a4e9c7e6d97ea76f6839328 Mon Sep 17 00:00:00 2001 From: Marcus Olsson Date: Fri, 16 Mar 2018 11:49:07 +0100 Subject: [PATCH 5/9] Wildcards to be placed in array Wildcard is also now the default. --- src/Http/Middleware/VeryBasicAuth.php | 2 +- src/config.stub | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Http/Middleware/VeryBasicAuth.php b/src/Http/Middleware/VeryBasicAuth.php index 796c4bb..187627b 100644 --- a/src/Http/Middleware/VeryBasicAuth.php +++ b/src/Http/Middleware/VeryBasicAuth.php @@ -17,7 +17,7 @@ public function handle($request, Closure $next) $config = config('very_basic_auth'); // Check if middleware is in use in current environment - if($config['envs'] == '*' || in_array(app()->environment(), $config['envs'])) { + if(in_array('*', $config['envs']) || in_array(app()->environment(), $config['envs'])) { if($request->getUser() != $config['user'] || $request->getPassword() != $config['password']) { $header = ['WWW-Authenticate' => 'Basic']; diff --git a/src/config.stub b/src/config.stub index ccdb203..a2d4ea6 100644 --- a/src/config.stub +++ b/src/config.stub @@ -10,11 +10,9 @@ // Password 'password' => '%password%', - // Environments where the middleware is active, use 'envs' => '*' to protect all envs + // Environments where the middleware is active. Use "*" to protect all envs 'envs' => [ - 'local', - 'development', - 'testing' + '*' ], // Message to display if the user "opts out"/clicks "cancel" From 30134b773f2968c551f7a0856dce49825cae8d41 Mon Sep 17 00:00:00 2001 From: Marcus Olsson Date: Fri, 16 Mar 2018 11:49:18 +0100 Subject: [PATCH 6/9] Updated tests for testing environments. --- README.md | 24 ++++++++++++++-- tests/VeryBasicAuthTests.php | 56 ++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9c32540..3d0ff2a 100644 --- a/README.md +++ b/README.md @@ -76,11 +76,31 @@ Run the command `$ php artisan vendor:publish` and select `Provider: Olssonm\Ver The file `very_basic_auth.php` will then be copied to your `app/config`-folder – here you can set various options such as username and password. -### Note +#### Note **There is no default password**. Upon installation a random password is set for added security (we don't want everyone to use the same default password). Please publish the packages configuration to have the ability to set a custom password. -#### Views and messages +### Environments + +You may set the environments that the package should be applied for. You may simply use "`*`" to use in all environments (this is also the default). + +``` php +'envs' => [ + '*' +], +``` + +Or + +``` php +'envs' => [ + 'production', + 'development', + 'local' +], +``` + +### Views and messages In the `very_basic_auth.php`-configuration you have the ability to set a custom view instead of a message. diff --git a/tests/VeryBasicAuthTests.php b/tests/VeryBasicAuthTests.php index b190163..4bfaaec 100644 --- a/tests/VeryBasicAuthTests.php +++ b/tests/VeryBasicAuthTests.php @@ -173,6 +173,62 @@ public function test_very_basic_auth_view_incorrect_credentials() $this->assertContains('This is the default view for the l5-very-basic-auth-package', $result->getContent()); } + /* test */ + public function test_very_basic_auth_env_local() + { + // Set the environment to only be "local" + config()->set('very_basic_auth.envs', ['local']); + + $request = new Request(); + $response = new JsonResponse(); + $next = function($request) use ($response) { + return $response; + }; + + $result = $this->middleware->handle($request, $next); + + // 200 becouse we should be locked out; tests occurs in the testing env. + $this->assertEquals(200, $result->getStatusCode()); + } + + /* test */ + public function test_very_basic_auth_env_testing() + { + // Set the environment to only be "testing" + config()->set('very_basic_auth.envs', ['testing']); + + $request = new Request(); + $response = new JsonResponse(); + $next = function($request) use ($response) { + return $response; + }; + + $result = $this->middleware->handle($request, $next); + + $this->assertEquals('Basic', $result->headers->get('www-authenticate')); + $this->assertEquals(401, $result->getStatusCode()); + $this->assertEquals(config('very_basic_auth.error_message'), $result->getContent()); + } + + /* test */ + public function test_very_basic_auth_env_wildcard() + { + // Set the environment to use wildcard + config()->set('very_basic_auth.envs', ['*']); + + $request = new Request(); + $response = new JsonResponse(); + $next = function($request) use ($response) { + return $response; + }; + + $result = $this->middleware->handle($request, $next); + + $this->assertEquals('Basic', $result->headers->get('www-authenticate')); + $this->assertEquals(401, $result->getStatusCode()); + $this->assertEquals(config('very_basic_auth.error_message'), $result->getContent()); + } + /** Teardown */ public static function tearDownAfterClass() { From f0a072178d6d974d41a1522c5465a72155fd56a6 Mon Sep 17 00:00:00 2001 From: Marcus Olsson Date: Fri, 16 Mar 2018 11:49:45 +0100 Subject: [PATCH 7/9] Allow for travis-wait. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 04f9657..f143ae5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ before_install: - travis_retry composer self-update - composer require "illuminate/support:${ILLUMINATE_VERSION}" --no-update -install: composer update --prefer-source --no-interaction --dev +install: travis_wait composer update --prefer-source --no-interaction script: composer test From 119881e3934cae2935112e2a7eb852585ab0b65f Mon Sep 17 00:00:00 2001 From: Marcus Olsson Date: Fri, 16 Mar 2018 12:16:08 +0100 Subject: [PATCH 8/9] Minor tweak to travis matrix. --- .travis.yml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index f143ae5..da7c450 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,24 +1,23 @@ language: php -before_install: - - travis_retry composer self-update - - composer require "illuminate/support:${ILLUMINATE_VERSION}" --no-update +sudo: false -install: travis_wait composer update --prefer-source --no-interaction +before_script: + - travis_retry composer self-update + - travis_retry composer require "illuminate/support:${ILLUMINATE_VERSION}" -script: composer test +script: + - composer test matrix: include: - php: 7.0 env: ILLUMINATE_VERSION=5.4.* - - php: 7.1 - env: ILLUMINATE_VERSION=5.4.* - php: 7.1 env: ILLUMINATE_VERSION=5.5.* - php: 7.1 env: ILLUMINATE_VERSION=5.6.* - - php: nightly - env: ILLUMINATE_VERSION=5.4.* + - php: 7.2 + env: ILLUMINATE_VERSION=5.6.* - php: nightly env: ILLUMINATE_VERSION=5.6.* From dd2138f9f9e97e04810db936ac7a955039cbfa54 Mon Sep 17 00:00:00 2001 From: Marcus Olsson Date: Fri, 16 Mar 2018 12:44:29 +0100 Subject: [PATCH 9/9] More efficient dependancy-lookups. --- .travis.yml | 2 +- composer.json | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index da7c450..d7337e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ before_script: - travis_retry composer require "illuminate/support:${ILLUMINATE_VERSION}" script: - - composer test + - phpunit matrix: include: diff --git a/composer.json b/composer.json index 4188ffe..d755c49 100644 --- a/composer.json +++ b/composer.json @@ -17,12 +17,12 @@ } ], "require": { - "illuminate/support": ">=5.4", - "php" : "7.*" + "illuminate/support": "~5.4.0|~5.5.0|~5.6.0", + "php" : "^7.0" }, "require-dev": { - "phpunit/phpunit" : ">=5.0", - "orchestra/testbench": "3.*" + "phpunit/phpunit": "^6.5 || ^7.0", + "orchestra/testbench": "~3.4.0|~3.5.0|~3.6.0" }, "autoload": { "psr-4": { @@ -35,7 +35,7 @@ } }, "scripts": { - "test": "phpunit" + "test": "vendor/bin/phpunit" }, "extra": { "branch-alias": {