Skip to content
Snippets Groups Projects
Commit 87fe8ca0 authored by Henri-Damien LAURENT's avatar Henri-Damien LAURENT
Browse files

hotline#158762 : donot show not readable directory of file

parent 03019f06
1 merge request!43hotline#158762 : donot show not readable directory of file
Pipeline #17953 passed with stage
in 42 seconds
test:php74: test:php74:
image: bokeh_php74_with_chrome image: bokeh-php-7.4-webmaster
script: script:
- bash build.sh - bash build.sh
except: except:
...@@ -9,7 +9,7 @@ test:php74: ...@@ -9,7 +9,7 @@ test:php74:
test:php81: test:php81:
image: bokeh_php81 image: bokeh-php-8.1-webmaster
script: script:
- bash build.sh - bash build.sh
except: except:
......
...@@ -82,13 +82,13 @@ class Storm_FileSystem_Disk extends Storm_FileSystem_Abstract { ...@@ -82,13 +82,13 @@ class Storm_FileSystem_Disk extends Storm_FileSystem_Abstract {
public function directoryNamesAt($path) { public function directoryNamesAt($path) {
if (!file_exists($path)) if (!file_exists($path) || !is_readable($path) )
return []; return [];
$dirs = []; $dirs = [];
foreach (new DirectoryIterator($path) as $entry) { foreach (new DirectoryIterator($path) as $entry) {
if ($entry->isDir() && !$entry->isDot()) if ($entry->isDir() && $entry->isReadable() && !$entry->isDot())
$dirs[$entry->getFilename()] = $entry->getFilename(); $dirs[$entry->getFilename()] = $entry->getFilename();
} }
asort($dirs); asort($dirs);
...@@ -97,12 +97,13 @@ class Storm_FileSystem_Disk extends Storm_FileSystem_Abstract { ...@@ -97,12 +97,13 @@ class Storm_FileSystem_Disk extends Storm_FileSystem_Abstract {
public function fileNamesAt($path) { public function fileNamesAt($path) {
if (!file_exists($path)) if (!file_exists($path)
|| !is_readable($path))
return []; return [];
$files = []; $files = [];
foreach (new DirectoryIterator($path) as $entry) { foreach (new DirectoryIterator($path) as $entry) {
if ($entry->isFile() && !$entry->isDot()) if ($entry->isFile() && $entry->isReadable() && !$entry->isDot())
$files[$entry->getFilename()] = $entry->getFilename(); $files[$entry->getFilename()] = $entry->getFilename();
} }
......
<?php
/**
* Copyright (c) 2012-2022, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
abstract class Storm_FileSystem_DiskTestCase extends PHPUnit_Framework_TestCase {
protected Storm_FileSystem_Disk $_fs;
public function setUp() {
parent::setUp();
$this->_fs = new Storm_FileSystem_Disk;
}
}
class Storm_FileSystem_DiskBasicTest extends Storm_FileSystem_DiskTestCase {
protected $_directory,$_subdirectory;
public function setUp() {
parent::setUp();
$this->_directory = uniqid();
$this->_subdirectory = uniqid();
mkdir($this->_directory);
mkdir($this->_directory.'/'.$this->_subdirectory);
$file = fopen( $this->_directory.'/testfile','c');
fclose($file);
}
public function tearDown() {
chmod($this->_directory.'/testfile',0700);
unlink($this->_directory.'/testfile');
chmod($this->_directory.'/'.$this->_subdirectory,0700);
rmdir($this->_directory.'/'.$this->_subdirectory);
rmdir($this->_directory);
parent::tearDown();
}
/** @test */
public function directoryNamesAtForTempShouldContainsReadableSubDirectory() {
$this->assertEquals([$this->_subdirectory => $this->_subdirectory],
$this->_fs->directoryNamesAt($this->_directory));
}
/** @test */
public function fileNamesAtShouldBetestfile() {
$this->assertEquals(['testfile' => 'testfile'],
$this->_fs->fileNamesAt($this->_directory));
}
/** @test */
public function directoryNamesTmpWithNoReadableDirectoryAtShouldBeEmpty() {
if (FALSE === chmod($this->_directory.'/'.$this->_subdirectory,0000))
$this->markTestSkipped();
$this->assertEmpty($this->_fs->directoryNamesAt($this->_directory));
}
/** @test */
public function directoryNamesAtForMytestDirectoryNotReadableShouldBeEmpty() {
if (FALSE === chmod($this->_directory.'/'.$this->_subdirectory,0000))
$this->markTestSkipped();
$this->assertEmpty($this->_fs->directoryNamesAt($this->_directory.'/'.$this->_subdirectory));
}
/** @test */
public function fileNamesAtTempForTmpDirectoryShouldBeEmpty() {
chmod( $this->_directory.'/testfile',0000);
$this->assertEmpty($this->_fs->fileNamesAt($this->_directory));
}
/** @test */
public function fileNamesAtForTestfileShouldBeEmpty() {
chmod( $this->_directory.'/testfile',0000);
$this->assertEmpty($this->_fs->fileNamesAt($this->_directory.'/testfile'));
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment