Skip to content

Commit 84832cf

Browse files
authored
Merge pull request #25 from IonBazan/plugin-security
Handle Composer 2.3.9+ strict plugin behaviour
2 parents 6ac141b + 4b84d9b commit 84832cf

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
- '7.4'
2222
- '8.0'
2323
- '8.1'
24+
- '8.2'
2425
include:
2526
- php-versions: '7.0'
2627
composer-flags: '--prefer-lowest'
@@ -61,14 +62,15 @@ jobs:
6162
- name: Upload coverage to Codecov
6263
uses: codecov/codecov-action@v1
6364
- name: Run mutation tests
64-
if: ${{ matrix.php-versions == 8.1 && matrix.operating-system == 'ubuntu-latest' }}
65+
if: ${{ matrix.php-versions == 8.2 && matrix.operating-system == 'ubuntu-latest' }}
6566
env:
6667
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
6768
run: |
69+
composer config --no-plugins allow-plugins.infection/extension-installer true
6870
composer req infection/infection -W
6971
vendor/bin/infection --ignore-msi-with-no-mutations --min-covered-msi=100 --min-msi=100 -s -j4
7072
- name: Run phpstan
71-
if: ${{ matrix.php-versions == 8.1 && matrix.operating-system == 'ubuntu-latest' }}
73+
if: ${{ matrix.php-versions == 8.2 && matrix.operating-system == 'ubuntu-latest' }}
7274
run: |
7375
composer req phpstan/phpstan
7476
vendor/bin/phpstan

src/Url/GitGenerator.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
abstract class GitGenerator implements UrlGenerator
88
{
9+
const REFERENCE_LENGTH = 40;
10+
const SHORT_REFERENCE_LENGTH = 7;
11+
912
/**
1013
* {@inheritdoc}
1114
*/
@@ -25,8 +28,8 @@ protected function getCompareRef(PackageInterface $package)
2528

2629
$reference = $package->getSourceReference();
2730

28-
if (40 === \strlen($reference)) {
29-
return \substr($reference, 0, 7);
31+
if (self::REFERENCE_LENGTH === \strlen($reference)) {
32+
return \substr($reference, 0, self::SHORT_REFERENCE_LENGTH);
3033
}
3134

3235
return $reference;
@@ -62,7 +65,7 @@ protected function getRepo(PackageInterface $package)
6265
protected function getRepositoryUrl(PackageInterface $package)
6366
{
6467
$httpsUrl = preg_replace(
65-
"/^git@({$this->getQuotedDomain()}):(.+)\/([^\/]+)(\.git)?$/",
68+
"/^git@(?:git\.)?({$this->getQuotedDomain()}):(.+)\/([^\/]+)(\.git)?$/",
6669
'https://$1/$2/$3',
6770
$package->getSourceUrl()
6871
);

tests/Integration/DiffCommandTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Composer\Factory;
88
use Composer\IO\IOInterface;
99
use Composer\IO\NullIO;
10+
use Composer\Package\Package;
1011
use Composer\Plugin\PluginManager;
1112
use IonBazan\ComposerDiff\Command\DiffCommand;
1213
use IonBazan\ComposerDiff\PackageDiff;
@@ -46,11 +47,13 @@ public function testComposerApplication($expectedOutput, array $input)
4647
$app = new ComposerApplication();
4748
$app->setIO(new NullIO()); // For Composer v1
4849
$app->setAutoExit(false);
49-
$composer = Factory::create($app->getIO(), null, true);
50+
$plugin = $this->getPluginPackage();
51+
$config = array('allow-plugins' => array($plugin->getName() => true));
52+
$composer = Factory::create($app->getIO(), array('config' => $config), true);
5053
$app->setComposer($composer);
5154
$pm = new PluginManager($app->getIO(), $composer);
5255
$composer->setPluginManager($pm);
53-
$pm->registerPackage($composer->getPackage(), true);
56+
$pm->registerPackage($plugin, true);
5457
$tester = new ApplicationTester($app);
5558
$result = $tester->run($input, array('verbosity' => Output::VERBOSITY_VERY_VERBOSE));
5659
$this->assertSame($expectedOutput, $tester->getDisplay());
@@ -232,6 +235,17 @@ public function commandArgumentsDataProvider()
232235
),
233236
);
234237
}
238+
239+
/**
240+
* @return Package
241+
*/
242+
private function getPluginPackage()
243+
{
244+
$plugin = new Package('test-plugin-package', '1.0', '1.0');
245+
$plugin->setExtra(array('class' => 'IonBazan\ComposerDiff\Composer\Plugin'));
246+
247+
return $plugin;
248+
}
235249
}
236250

237251
class ComposerApplication extends Application

0 commit comments

Comments
 (0)