From bf5076f2dfdc1e57121fc0e1a139181576efaae6 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Wed, 13 Dec 2017 20:51:37 +1300 Subject: [PATCH 1/2] FIX Update BasicAuth call signature, remove deprecated code and update getenv --- _config/routes.yml | 6 ++++++ src/Controllers/DevCheckController.php | 2 ++ src/EnvironmentCheckSuite.php | 5 ----- src/EnvironmentChecker.php | 17 +++++++++-------- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/_config/routes.yml b/_config/routes.yml index c7f53fb..e2c2bed 100644 --- a/_config/routes.yml +++ b/_config/routes.yml @@ -6,3 +6,9 @@ SilverStripe\Control\Director: 'health/check': 'Silverstripe\EnvironmentCheck\Controllers\DevHealthController' 'dev/check/$Suite': 'Silverstripe\EnvironmentCheck\Controllers\DevCheckController' +SilverStripe\Dev\DevelopmentAdmin: + registered_controllers: + check: + controller: Silverstripe\EnvironmentCheck\Controllers\DevCheckController + links: + check: 'Run registered environment checks and display their status' diff --git a/src/Controllers/DevCheckController.php b/src/Controllers/DevCheckController.php index 6b53384..4e0d346 100644 --- a/src/Controllers/DevCheckController.php +++ b/src/Controllers/DevCheckController.php @@ -3,6 +3,8 @@ namespace SilverStripe\EnvironmentCheck\Controllers; use SilverStripe\Control\Controller; +use SilverStripe\Control\HTTPRequest; +use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\EnvironmentCheck\EnvironmentChecker; /** diff --git a/src/EnvironmentCheckSuite.php b/src/EnvironmentCheckSuite.php index 4807ef4..0fe8dea 100644 --- a/src/EnvironmentCheckSuite.php +++ b/src/EnvironmentCheckSuite.php @@ -8,10 +8,6 @@ use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Extensible; use SilverStripe\Core\Injector\Injectable; use SilverStripe\Core\Injector\Injector; -use SilverStripe\EnvironmentCheck\EnvironmentCheck; -use SilverStripe\ORM\ArrayList; -use SilverStripe\View\ArrayData; -use SilverStripe\View\ViewableData; /** * Represents a suite of environment checks. @@ -77,7 +73,6 @@ class EnvironmentCheckSuite */ public function __construct($suiteName) { - $this->constructExtensions(); if (empty($this->config()->registered_suites[$suiteName])) { // Not registered via config system, but it still may be configured later via self::register. return; diff --git a/src/EnvironmentChecker.php b/src/EnvironmentChecker.php index 96177c3..63617aa 100644 --- a/src/EnvironmentChecker.php +++ b/src/EnvironmentChecker.php @@ -9,14 +9,13 @@ use SilverStripe\Control\Email\Email; use SilverStripe\Control\HTTPResponse; use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\Control\RequestHandler; -use SilverStripe\Core\Config\Config; +use SilverStripe\Core\Environment; use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\Deprecation; -use SilverStripe\EnvironmentCheck\EnvironmentCheck; -use SilverStripe\EnvironmentCheck\EnvironmentCheckSuite; use SilverStripe\Security\BasicAuth; use SilverStripe\Security\Member; use SilverStripe\Security\Permission; +use SilverStripe\Security\Security; /** * Provides an interface for checking the given EnvironmentCheckSuite. @@ -102,12 +101,14 @@ class EnvironmentChecker extends RequestHandler public function init($permission = 'ADMIN') { // if the environment supports it, provide a basic auth challenge and see if it matches configured credentials - if (getenv('ENVCHECK_BASICAUTH_USERNAME') && getenv('ENVCHECK_BASICAUTH_PASSWORD')) { + if (Environment::getEnv('ENVCHECK_BASICAUTH_USERNAME') + && Environment::getEnv('ENVCHECK_BASICAUTH_PASSWORD') + ) { if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { // authenticate the input user/pass with the configured credentials if (!( - $_SERVER['PHP_AUTH_USER'] == getenv('ENVCHECK_BASICAUTH_USERNAME') - && $_SERVER['PHP_AUTH_PW'] == getenv('ENVCHECK_BASICAUTH_PASSWORD') + $_SERVER['PHP_AUTH_USER'] == Environment::getEnv('ENVCHECK_BASICAUTH_USERNAME') + && $_SERVER['PHP_AUTH_PW'] == Environment::getEnv('ENVCHECK_BASICAUTH_PASSWORD') ) ) { $response = new HTTPResponse(null, 401); @@ -143,11 +144,11 @@ class EnvironmentChecker extends RequestHandler public function canAccess($member = null, $permission = 'ADMIN') { if (!$member) { - $member = Member::currentUser(); + $member = Security::getCurrentUser(); } if (!$member) { - $member = BasicAuth::requireLogin('Environment Checker', $permission, false); + $member = BasicAuth::requireLogin($this->getRequest(), 'Environment Checker', $permission, false); } // We allow access to this controller regardless of live-status or ADMIN permission only From b1f5ef184b5848ab07b10d2a9deb6b10a0c66a6b Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Wed, 13 Dec 2017 21:00:56 +1300 Subject: [PATCH 2/2] Add PHP 7.2 to Travis, ensure phpcs passes stricter standard --- .gitattributes | 3 +- .travis.yml | 4 +- _config.php | 91 ++++++++++++++----- composer.json | 4 +- phpcs.xml.dist | 9 ++ src/Checks/ExternalURLCheck.php | 10 +- .../FileAccessibilityAndValidationCheck.php | 30 ++++-- 7 files changed, 113 insertions(+), 38 deletions(-) create mode 100644 phpcs.xml.dist diff --git a/.gitattributes b/.gitattributes index 475f5f2..7526f7d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,7 @@ /tests export-ignore -/docs export-ignore /.gitattributes export-ignore /.gitignore export-ignore /.travis.yml export-ignore /.scrutinizer.yml export-ignore +/codecov.yml export-ignore +/phpunit.xml.dist export-ignore diff --git a/.travis.yml b/.travis.yml index 70fc8c0..bec7188 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,8 @@ matrix: env: DB=PGSQL PHPUNIT_TEST=1 - php: 7.1 env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1 + - php: 7.2 + env: DB=MYSQL PHPUNIT_TEST=1 before_script: - phpenv rehash @@ -25,7 +27,7 @@ before_script: script: - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi - if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi - - if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs --standard=vendor/silverstripe/framework/phpcs.xml.dist src/ tests/ ; fi + - if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs src/ tests/ *.php; fi after_success: - if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi diff --git a/_config.php b/_config.php index bfdcd2b..294ccc0 100644 --- a/_config.php +++ b/_config.php @@ -1,23 +1,70 @@ + + CodeSniffer ruleset for SilverStripe coding conventions. + + + + + + diff --git a/src/Checks/ExternalURLCheck.php b/src/Checks/ExternalURLCheck.php index 3b15340..429cd46 100644 --- a/src/Checks/ExternalURLCheck.php +++ b/src/Checks/ExternalURLCheck.php @@ -10,9 +10,13 @@ use SilverStripe\EnvironmentCheck\EnvironmentCheck; * it can still fail if the URL in question is requested by the client, e.g. through an iframe. * * Requires curl to present, so ensure to check it before with the following: - * EnvironmentCheckSuite::register('check', 'HasFunctionCheck("curl_init")', "Does PHP have CURL support?"); - * - * @package environmentcheck + * + * EnvironmentCheckSuite::register( + * 'check', + * 'HasFunctionCheck("curl_init")', + * "Does PHP have CURL support?" + * ); + * */ class ExternalURLCheck implements EnvironmentCheck { diff --git a/src/Checks/FileAccessibilityAndValidationCheck.php b/src/Checks/FileAccessibilityAndValidationCheck.php index 99da854..e86558f 100644 --- a/src/Checks/FileAccessibilityAndValidationCheck.php +++ b/src/Checks/FileAccessibilityAndValidationCheck.php @@ -3,28 +3,40 @@ namespace SilverStripe\EnvironmentCheck\Checks; use SilverStripe\EnvironmentCheck\EnvironmentCheck; -use SilverStripe\ORM\Versioning\Versioned; +use SilverStripe\Versioned\Versioned; /** * Checks for the accessibility and file type validation of one or more files or folders. * * Examples: * // Checks /assets/calculator_files has .json files and all files are valid json files. - * EnvironmentCheckSuite::register('check', 'FileAccessibilityAndValidationCheck("' . BASE_PATH . '/assets/calculator_files/*.json", - * "jsonValidate", '.FileAccessibilityAndValidationCheck::CHECK_ALL.')', 'Check a json file exist and are all valid json files' + * EnvironmentCheckSuite::register( + * 'check', + * 'FileAccessibilityAndValidationCheck( + * "' . BASE_PATH . '/assets/calculator_files/*.json", + * "jsonValidate", + * '.FileAccessibilityAndValidationCheck::CHECK_ALL.' + * )', + * 'Check a json file exist and are all valid json files' * ); * * // Checks /assets/calculator_files/calculator.json exists and is valid json file. - * EnvironmentCheckSuite::register('check', 'FileAccessibilityAndValidationCheck("' . BASE_PATH . '/assets/calculator_files/calculator.json", - * "jsonValidate", '.FileAccessibilityAndValidationCheck::CHECK_SINGLE.')', 'Check a calculator.json exists and is valid json file' + * EnvironmentCheckSuite::register( + * 'check', + * 'FileAccessibilityAndValidationCheck( + * "' . BASE_PATH . '/assets/calculator_files/calculator.json", + * "jsonValidate", + * '.FileAccessibilityAndValidationCheck::CHECK_SINGLE.' + * )', + * 'Check a calculator.json exists and is valid json file' * ); * * // Check only existence - * EnvironmentCheckSuite::register('check', 'FileAccessibilityAndValidationCheck("' . BASE_PATH . '/assets/calculator_files/calculator.json")', - * 'Check a calculator.json exists only' + * EnvironmentCheckSuite::register( + * 'check', + * 'FileAccessibilityAndValidationCheck("' . BASE_PATH . '/assets/calculator_files/calculator.json")', + * 'Check a calculator.json exists only' * ); - * - * @package environmentcheck */ class FileAccessibilityAndValidationCheck implements EnvironmentCheck {