Merge branch 'master' into feature/extra-checks

This commit is contained in:
Frank Mullenger 2019-03-20 10:23:03 +13:00 committed by GitHub
commit da9eddc0e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 132 additions and 6 deletions

View File

@ -1,5 +1,11 @@
inherit: true
build:
nodes:
analysis:
tests:
override: [php-scrutinizer-run]
checks:
php:
code_rating: true

View File

@ -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:

View File

@ -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/",

View File

@ -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

View 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",
];
}
}
}

View 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);
}
}