Skip to content

Commit

Permalink
Merge pull request #23 from olssonm/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
olssonm authored Mar 16, 2018
2 parents 6c4dcf9 + dd2138f commit e2cd1b9
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 21 deletions.
17 changes: 8 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
language: php

before_install:
- travis_retry composer self-update
- composer require "illuminate/support:${ILLUMINATE_VERSION}" --no-update
sudo: false

install: composer update --prefer-source --no-interaction --dev
before_script:
- travis_retry composer self-update
- travis_retry composer require "illuminate/support:${ILLUMINATE_VERSION}"

script: composer test
script:
- phpunit

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.*
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -35,7 +35,7 @@
}
},
"scripts": {
"test": "phpunit"
"test": "vendor/bin/phpunit"
},
"extra": {
"branch-alias": {
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Middleware/VeryBasicAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(in_array('*', $config['envs']) || in_array(app()->environment(), $config['envs'])) {
if($request->getUser() != $config['user'] || $request->getPassword() != $config['password']) {

$header = ['WWW-Authenticate' => 'Basic'];
Expand Down
6 changes: 2 additions & 4 deletions src/config.stub
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
// Password
'password' => '%password%',

// Environments where the middleware is active
// 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"
Expand Down
56 changes: 56 additions & 0 deletions tests/VeryBasicAuthTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit e2cd1b9

Please sign in to comment.