diff --git a/lib/private/IntegrityCheck/Checker.php b/lib/private/IntegrityCheck/Checker.php index fdecc7761c43..0852a5734b6d 100644 --- a/lib/private/IntegrityCheck/Checker.php +++ b/lib/private/IntegrityCheck/Checker.php @@ -179,22 +179,6 @@ private function generateHashes(\RecursiveIteratorIterator $iterator, continue; } - $exclusionList = [ - '/core/js/mimetypelist.js' - ]; - - $found = false; - foreach ($exclusionList as $entry) { - if($filename === $this->environmentHelper->getServerRoot() . $entry) { - $found = true; - break; - } - } - - if ($found) { - continue; - } - // The .user.ini and the .htaccess file of ownCloud can contain some // custom modifications such as for example the maximum upload size // to ensure that this will not lead to false positives this will diff --git a/lib/private/IntegrityCheck/Iterator/ExcludeFileByNameFilterIterator.php b/lib/private/IntegrityCheck/Iterator/ExcludeFileByNameFilterIterator.php index 8b197bd98781..b5f933a16862 100644 --- a/lib/private/IntegrityCheck/Iterator/ExcludeFileByNameFilterIterator.php +++ b/lib/private/IntegrityCheck/Iterator/ExcludeFileByNameFilterIterator.php @@ -23,8 +23,8 @@ namespace OC\IntegrityCheck\Iterator; /** - * Class ExcludeFileByNameFilterIterator provides a custom iterator which excludes - * entries with the specified file name from the file list. These file names are matched exactly. + * Class ExcludeFileByNameFilterIterator provides a custom iterator which excludes + * entries with the specified file name or name part from the file list. * * @package OC\Integritycheck\Iterator */ @@ -53,6 +53,18 @@ class ExcludeFileByNameFilterIterator extends \RecursiveFilterIterator { private $excludedFileNamePatterns = [ '/^\.webapp-owncloud-.*/', // Gentoo/Funtoo & derivatives use a tool known as webapp-config to manage wep-apps. ]; + + /** + * Array of excluded path and file name parts. Those are not scanned by the integrity checker. + * These strings are regular expressions and any filepath + * matching these expressions are ignored. + * + * @var array + */ + private $excludedFilePathPatterns = [ + '|/core/js/mimetypelist.js$|', // this file can be regenerated with additional entries with occ maintenance:mimetype:update-js + ]; + /** * @return bool @@ -75,6 +87,13 @@ public function accept() { return false; } } + + $currentFilePath = $current->getPathname(); + foreach ($this->excludedFilePathPatterns as $pattern){ + if (preg_match($pattern, $currentFilePath) > 0){ + return false; + } + } return true; } diff --git a/tests/data/integritycheck/app/core/js/mimetypelist.js b/tests/data/integritycheck/app/core/js/mimetypelist.js new file mode 100644 index 000000000000..9e26dfeeb6e6 --- /dev/null +++ b/tests/data/integritycheck/app/core/js/mimetypelist.js @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tests/lib/IntegrityCheck/Iterator/ExcludeFileByNameFilterIteratorTest.php b/tests/lib/IntegrityCheck/Iterator/ExcludeFileByNameFilterIteratorTest.php index f9810bb3692d..9aa8c09b1530 100644 --- a/tests/lib/IntegrityCheck/Iterator/ExcludeFileByNameFilterIteratorTest.php +++ b/tests/lib/IntegrityCheck/Iterator/ExcludeFileByNameFilterIteratorTest.php @@ -40,24 +40,31 @@ public function setUp() { public function fileNameProvider(){ return [ - ['a file', true], - ['Thumbs.db', false], - ['another file', true], - ['.directory', false], - ['.webapp-owncloud-obee', false], - ['wx.webapp-owncloud-obee', true], + ['', 'a file', true], + ['', 'Thumbs.db', false], + ['', 'another file', true], + ['', '.directory', false], + ['', '.webapp-owncloud-obee', false], + ['', 'wx.webapp-owncloud-obee', true], + ['/core/js', 'mimetypelist.js', false], + ['/core/css', 'mimetypelist.js', true], + ['/core/js', 'typelist.js', true], + ['/hardcore/js', 'mimetypelist.js', true], + ['/js', 'mimetypelist.js', true], + ]; } /** * @dataProvider fileNameProvider + * @param string $path * @param string $fileName * @param bool $expectedResult */ - public function testAcceptForFiles($fileName, $expectedResult){ + public function testAcceptForFiles($path, $fileName, $expectedResult){ $iteratorMock = $this->getMockBuilder(\RecursiveDirectoryIterator::class) ->disableOriginalConstructor() - ->setMethods(['getFilename', 'isDir']) + ->setMethods(['getPathname', 'getFilename', 'isDir']) ->getMock() ; $iteratorMock->method('getFilename') @@ -66,6 +73,9 @@ public function testAcceptForFiles($fileName, $expectedResult){ $iteratorMock->method('isDir') ->will($this->returnValue(false)); + $iteratorMock->method('getPathname') + ->will($this->returnValue("$path/$fileName")); + $this->filter->method('current') ->will($this->returnValue($iteratorMock)) ; @@ -73,6 +83,7 @@ public function testAcceptForFiles($fileName, $expectedResult){ $actualResult = $this->filter->accept(); $this->assertEquals($expectedResult, $actualResult); } + /** * @dataProvider fileNameProvider