From 437fd9744543b14130d58c3ea5b7b10495e8e7a7 Mon Sep 17 00:00:00 2001 From: mattab Date: Mon, 8 Feb 2016 13:09:57 +1300 Subject: New release check list integration test to pro-actively detect 'abnormal whitespaces' issue Refs #9729 #9715 #9712 --- libs/bower_components/angular/angular.js | 2 +- plugins/CustomDimensions | 2 +- tests/PHPUnit/Integration/ReleaseCheckListTest.php | 65 +++++++++++++++++++++- 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/libs/bower_components/angular/angular.js b/libs/bower_components/angular/angular.js index ccf3b4bafe..a72a457951 100644 --- a/libs/bower_components/angular/angular.js +++ b/libs/bower_components/angular/angular.js @@ -13333,7 +13333,7 @@ function adjustMatchers(matchers) { * * - your app is hosted at url `http://myapp.example.com/` * - but some of your templates are hosted on other domains you control such as - * `http://srv01.assets.example.com/`,  `http://srv02.assets.example.com/`, etc. + * `http://srv01.assets.example.com/`, `http://srv02.assets.example.com/`, etc. * - and you have an open redirect at `http://myapp.example.com/clickThru?...`. * * Here is what a secure configuration for this scenario might look like: diff --git a/plugins/CustomDimensions b/plugins/CustomDimensions index 566313496c..03eed12ec5 160000 --- a/plugins/CustomDimensions +++ b/plugins/CustomDimensions @@ -1 +1 @@ -Subproject commit 566313496c8338794480c85adeb4aa854d878a35 +Subproject commit 03eed12ec5a6acaf489f7e6ba7d71c846e74fb10 diff --git a/tests/PHPUnit/Integration/ReleaseCheckListTest.php b/tests/PHPUnit/Integration/ReleaseCheckListTest.php index 58970199f0..6d8553802a 100644 --- a/tests/PHPUnit/Integration/ReleaseCheckListTest.php +++ b/tests/PHPUnit/Integration/ReleaseCheckListTest.php @@ -184,6 +184,30 @@ class ReleaseCheckListTest extends \PHPUnit_Framework_TestCase } } + public function test_jsfilesDoNotContainFakeSpaces() + { + $js = Filesystem::globr(PIWIK_INCLUDE_PATH, '*.js'); + $this->checkFilesDoNotHaveWeirdSpaces($js); + } + + public function test_phpfilesDoNotContainFakeSpaces() + { + $js = Filesystem::globr(PIWIK_INCLUDE_PATH, '*.php'); + $this->checkFilesDoNotHaveWeirdSpaces($js); + } + + public function test_twigfilesDoNotContainFakeSpaces() + { + $js = Filesystem::globr(PIWIK_INCLUDE_PATH, '*.twig'); + $this->checkFilesDoNotHaveWeirdSpaces($js); + } + + public function test_htmlfilesDoNotContainFakeSpaces() + { + $js = Filesystem::globr(PIWIK_INCLUDE_PATH, '*.html'); + $this->checkFilesDoNotHaveWeirdSpaces($js); + } + public function test_directoriesShouldBeChmod755() { $pluginsPath = realpath(PIWIK_INCLUDE_PATH . '/plugins/'); @@ -422,7 +446,7 @@ class ReleaseCheckListTest extends \PHPUnit_Framework_TestCase } // in build-package.sh we have: `find ./ -iname 'tests' -type d -prune -exec rm -rf {} \;` - if(stripos($file, "/tests/") !== false) { + if($this->isFileBelongToTests($file)) { return false; } if(strpos($file, PIWIK_INCLUDE_PATH . "/tmp/") !== false) { @@ -586,4 +610,43 @@ class ReleaseCheckListTest extends \PHPUnit_Framework_TestCase } return $filesizes; } + + /** + * @param $files + * @throws Exception + */ + protected function checkFilesDoNotHaveWeirdSpaces($files) + { + $weirdSpace = ' '; + $this->assertEquals('c2a0', bin2hex($weirdSpace), "Checking that this test file was not tampered with"); + $this->assertEquals('20', bin2hex(' '), "Checking that this test file was not tampered with"); + + $errors = array(); + foreach ($files as $file) { + + if($this->isFileBelongToTests($file)) { + continue; + } + + $content = file_get_contents($file); + $posWeirdSpace = strpos($content, $weirdSpace); + if ($posWeirdSpace !== false) { + $around = substr($content, $posWeirdSpace - 20, 40); + $around = trim($around); + $errors[] = "File $file contains an unusual space character, please remove it from here: ...$around..."; + } + } + if (!empty($errors)) { + throw new Exception(implode(",\n\n ", $errors)); + } + } + + /** + * @param $file + * @return bool + */ + private function isFileBelongToTests($file) + { + return stripos($file, "/tests/") !== false; + } } -- cgit v1.2.3