예제 #1
0
 /**
  * Run the permission check and return any errors
  *
  * @return void
  */
 public function run()
 {
     $this->loader->parse();
     $files = $this->filesystem->getFiles();
     // Now we check all the files against the config
     while ($files->valid()) {
         /* @var SplFileInfo $file */
         $file = $files->current();
         // Skip symlinks as they are always 0777
         if ($file->isLink()) {
             $files->next();
             continue;
         }
         $filename = $this->getRelativeFilename($file);
         // Skip excluded files, of course.
         if ($this->isExcluded($filename)) {
             $files->next();
             continue;
         }
         $fileShouldBeExecutable = $this->shouldBeExecutable($filename);
         if (!$fileShouldBeExecutable && $file->isExecutable()) {
             $this->messageBag->addMessage($file->getPathname(), 'minx');
             $files->next();
             continue;
         }
         if ($fileShouldBeExecutable && !$file->isExecutable()) {
             $this->messageBag->addMessage($file->getPathname(), 'plusx');
             $files->next();
             continue;
         }
         $files->next();
     }
 }
예제 #2
0
    public function setUp()
    {
        $data = <<<ENDXML
        <permcheck>
            <excludes>
                <file>excluded/file5.txt</file>
                <dir>excluded2</dir>
            </excludes>
            <executables>
                <file>file1.sh</file>
                <file>file3.sh</file>
            </executables>
        </permcheck>
ENDXML;
        $this->config = \Mockery::mock(new Config());
        $this->loader = \Mockery::mock(new XmlLoader($data, $this->config));
        $this->fileSystem = \Mockery::mock(new Filesystem($this->config, '/does/not/exist'));
        $files = new \ArrayIterator();
        $mocks = array('/does/not/exist/file1.sh' => array(true, false), '/does/not/exist/file2.txt' => array(false, false), '/does/not/exist/file3.sh' => array(false, false), '/does/not/exist/file4.txt' => array(true, false), '/does/not/exist/excluded/file5.txt' => array(true, false), '/does/not/exist/excluded2/file6.sh' => array(false, false), '/does/not/exist/symlink' => array(true, true));
        foreach ($mocks as $file => $properties) {
            /** @var MockInterface|\SplFileInfo $file */
            $file = \Mockery::mock(new \SplFileInfo($file));
            $file->shouldReceive('getName')->andReturn($file);
            $file->shouldReceive('isExecutable')->andReturn($properties[0]);
            $file->shouldReceive('isLink')->andReturn($properties[1]);
            $files->append($file);
        }
        $this->fileSystem->shouldReceive('getFiles')->andReturn($files);
        $this->messageBag = \Mockery::mock(new Bag());
        $this->reporter = \Mockery::mock(new XmlReporter());
        $this->permCheck = new PermCheck($this->loader, $this->config, $this->fileSystem, $this->messageBag, $this->reporter, '/does/not/exist');
    }