mirror of
https://github.com/silverstripe/silverstripe-environmentcheck
synced 2024-10-22 17:05:40 +02:00
Merge branch 'master' into feature/extra-checks
This commit is contained in:
commit
da9eddc0e1
@ -1,5 +1,11 @@
|
||||
inherit: true
|
||||
|
||||
build:
|
||||
nodes:
|
||||
analysis:
|
||||
tests:
|
||||
override: [php-scrutinizer-run]
|
||||
|
||||
checks:
|
||||
php:
|
||||
code_rating: true
|
||||
|
12
.travis.yml
12
.travis.yml
@ -7,21 +7,21 @@ env:
|
||||
matrix:
|
||||
include:
|
||||
- php: 5.6
|
||||
env: DB=MYSQL PHPCS_TEST=1 PHPUNIT_TEST=1
|
||||
env: DB=MYSQL RECIPE_VERSION=4.2.x-dev PHPCS_TEST=1 PHPUNIT_TEST=1
|
||||
- php: 7.0
|
||||
env: DB=PGSQL PHPUNIT_TEST=1
|
||||
env: DB=PGSQL RECIPE_VERSION=4.2.x-dev PHPUNIT_TEST=1
|
||||
- php: 7.1
|
||||
env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1
|
||||
env: DB=MYSQL RECIPE_VERSION=4.3.x-dev PHPUNIT_COVERAGE_TEST=1
|
||||
- php: 7.2
|
||||
env: DB=MYSQL PHPUNIT_TEST=1
|
||||
env: DB=MYSQL RECIPE_VERSION=4.x-dev PHPUNIT_TEST=1
|
||||
|
||||
before_script:
|
||||
- phpenv rehash
|
||||
- phpenv config-rm xdebug.ini
|
||||
|
||||
- composer validate
|
||||
- composer require --no-update silverstripe/recipe-core:1.0.x-dev
|
||||
- if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.0.x-dev; fi
|
||||
- composer require --no-update silverstripe/recipe-core:"$RECIPE_VERSION"
|
||||
- if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.x-dev; fi
|
||||
- composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
|
||||
|
||||
script:
|
||||
|
@ -23,6 +23,11 @@
|
||||
"phpunit/phpunit": "^5.7",
|
||||
"squizlabs/php_codesniffer": "^3.0"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"SilverStripe\\EnvironmentCheck\\": "src/",
|
||||
|
@ -1,6 +1,7 @@
|
||||
# SilverStripe Environment Checker Module
|
||||
|
||||
[![Build Status](https://travis-ci.org/silverstripe/silverstripe-environmentcheck.svg?branch=master)](https://travis-ci.org/silverstripe/silverstripe-environmentcheck)
|
||||
[![SilverStripe supported module](https://img.shields.io/badge/silverstripe-supported-0071C4.svg)](https://www.silverstripe.org/software/addons/silverstripe-commercially-supported-module-list/)
|
||||
[![Code Quality](https://scrutinizer-ci.com/g/silverstripe/silverstripe-environmentcheck/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/silverstripe/silverstripe-environmentcheck/?branch=master)
|
||||
[![Code Coverage](https://codecov.io/gh/silverstripe/silverstripe-environmentcheck/branch/master/graph/badge.svg)](https://codecov.io/gh/silverstripe/silverstripe-environmentcheck)
|
||||
[![Version](http://img.shields.io/packagist/v/silverstripe/environmentcheck.svg?style=flat-square)](https://packagist.org/packages/silverstripe/environmentcheck)
|
||||
@ -94,6 +95,7 @@ SilverStripe\EnvironmentCheck\EnvironmentCheckSuite:
|
||||
* `SessionCheck`: Checks that a given URL does not generate a session.
|
||||
* `CacheHeadersCheck`: Check cache headers in response for directives that must either be included or excluded as well
|
||||
checking for existence of ETag.
|
||||
* `EnvTypeCheck`: Checks environment type, dev and test should not be used on production environments.
|
||||
|
||||
## Monitoring Checks
|
||||
|
||||
|
40
src/Checks/EnvTypeCheck.php
Normal file
40
src/Checks/EnvTypeCheck.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\EnvironmentCheck\Checks;
|
||||
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
|
||||
|
||||
/**
|
||||
* Check whether the environment setting is safe. Useful for live sites where a
|
||||
* non "Live" setting might disclose sensitive information.
|
||||
*
|
||||
* @package environmentcheck
|
||||
*/
|
||||
class EnvTypeCheck implements EnvironmentCheck
|
||||
{
|
||||
/**
|
||||
* Check the environment setting.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
$envSetting = Director::get_environment_type();
|
||||
switch ($envSetting) {
|
||||
case 'live':
|
||||
return [
|
||||
EnvironmentCheck::OK,
|
||||
"Env setting is 'live'",
|
||||
];
|
||||
// Fallthrough
|
||||
default:
|
||||
case 'dev':
|
||||
case 'test':
|
||||
return [
|
||||
EnvironmentCheck::ERROR,
|
||||
"Env setting is '{$envSetting}' and may disclose information",
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
73
tests/Checks/EnvTypeCheckTest.php
Normal file
73
tests/Checks/EnvTypeCheckTest.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\EnvironmentCheck\Tests\Checks;
|
||||
|
||||
use SilverStripe\Core\Kernel;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
|
||||
use SilverStripe\EnvironmentCheck\Checks\EnvTypeCheck;
|
||||
|
||||
/**
|
||||
* Test the env setting check.
|
||||
*/
|
||||
class EnvTypeCheckTest extends SapphireTest
|
||||
{
|
||||
/**
|
||||
* Check is OK when in live mode
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEnvSettingLive()
|
||||
{
|
||||
/** @var Kernel $kernel */
|
||||
$kernel = Injector::inst()->get(Kernel::class);
|
||||
$kernel->setEnvironment('live');
|
||||
|
||||
$this->assertTrue(Director::isLive());
|
||||
|
||||
$checker = Injector::inst()->get(EnvTypeCheck::class);
|
||||
$result = $checker->check();
|
||||
|
||||
$this->assertSame($result[0], EnvironmentCheck::OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check is ERROR when in test mode
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEnvSettingTest()
|
||||
{
|
||||
/** @var Kernel $kernel */
|
||||
$kernel = Injector::inst()->get(Kernel::class);
|
||||
$kernel->setEnvironment('test');
|
||||
|
||||
$this->assertTrue(Director::isTest());
|
||||
|
||||
$checker = Injector::inst()->get(EnvTypeCheck::class);
|
||||
$result = $checker->check();
|
||||
|
||||
$this->assertSame($result[0], EnvironmentCheck::ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check is ERROR when in dev mode
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEnvSettingDev()
|
||||
{
|
||||
/** @var Kernel $kernel */
|
||||
$kernel = Injector::inst()->get(Kernel::class);
|
||||
$kernel->setEnvironment('dev');
|
||||
|
||||
$this->assertTrue(Director::isDev());
|
||||
|
||||
$checker = Injector::inst()->get(EnvTypeCheck::class);
|
||||
$result = $checker->check();
|
||||
|
||||
$this->assertSame($result[0], EnvironmentCheck::ERROR);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user