mirror of
https://github.com/composer/composer
synced 2025-05-09 00:22:53 +00:00
Merge pull request from GHSA-x7cr-6qr6-2hh6
* GitDriver: filter branch names starting with a - character * GitDriver: getFileContent prevent identifiers starting with a - * HgDriver: prevent invalid identifiers and prevent file from running commands * HgDriver: filter branches starting with a - character
This commit is contained in:
parent
915b97fc39
commit
2c40c53637
4 changed files with 139 additions and 4 deletions
81
tests/Composer/Test/Repository/Vcs/GitDriverTest.php
Normal file
81
tests/Composer/Test/Repository/Vcs/GitDriverTest.php
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace Composer\Test\Repository\Vcs;
|
||||
|
||||
use Composer\Config;
|
||||
use Composer\Repository\Vcs\GitDriver;
|
||||
use Composer\Test\Mock\ProcessExecutorMock;
|
||||
use Composer\Test\TestCase;
|
||||
|
||||
class GitDriverTest extends TestCase
|
||||
{
|
||||
/** @var Config */
|
||||
private $config;
|
||||
/** @var string */
|
||||
private $home;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->home = self::getUniqueTmpDirectory();
|
||||
$this->config = new Config();
|
||||
$this->config->merge(array(
|
||||
'config' => array(
|
||||
'home' => $this->home,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
public function testGetBranchesFilterInvalidBranchNames()
|
||||
{
|
||||
$process = new ProcessExecutorMock;
|
||||
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
||||
|
||||
$driver = new GitDriver(array('url' => 'https://example.org/acme.git'), $io, $this->config, $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(), $process);
|
||||
$this->setRepoDir($driver, $this->home);
|
||||
|
||||
// Branches starting with a - character are not valid git branches names
|
||||
// Still assert that they get filtered to prevent issues later on
|
||||
$stdout = <<<GIT
|
||||
* main 089681446ba44d6d9004350192486f2ceb4eaa06 commit
|
||||
2.2 12681446ba44d6d9004350192486f2ceb4eaa06 commit
|
||||
-h 089681446ba44d6d9004350192486f2ceb4eaa06 commit
|
||||
GIT;
|
||||
|
||||
$process
|
||||
->expects(array(array(
|
||||
'cmd' => 'git branch --no-color --no-abbrev -v',
|
||||
'stdout' => $stdout,
|
||||
)));
|
||||
|
||||
$branches = $driver->getBranches();
|
||||
$this->assertSame(array(
|
||||
'main' => '089681446ba44d6d9004350192486f2ceb4eaa06',
|
||||
'2.2' => '12681446ba44d6d9004350192486f2ceb4eaa06',
|
||||
), $branches);
|
||||
}
|
||||
|
||||
public function testFileGetContentInvalidIdentifier()
|
||||
{
|
||||
$this->expectException('\RuntimeException');
|
||||
|
||||
$process = new ProcessExecutorMock;
|
||||
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
||||
$driver = new GitDriver(array('url' => 'https://example.org/acme.git'), $io, $this->config, $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(), $process);
|
||||
|
||||
$this->assertNull($driver->getFileContent('file.txt', 'h'));
|
||||
|
||||
$driver->getFileContent('file.txt', '-h');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GitDriver $driver
|
||||
* @param string $path
|
||||
*/
|
||||
private function setRepoDir($driver, $path)
|
||||
{
|
||||
$reflectionClass = new \ReflectionClass($driver);
|
||||
$reflectionProperty = $reflectionClass->getProperty('repoDir');
|
||||
$reflectionProperty->setAccessible(true);
|
||||
$reflectionProperty->setValue($driver, $path);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue