Skip to content

Commit

Permalink
Phive Install > Default to accepting everything unsigned for the moment.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihai Stancu committed Mar 8, 2021
1 parent ff49cf0 commit c7c43a5
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 63 deletions.
9 changes: 5 additions & 4 deletions resources/architecture.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"website": "https://dephpend.com/",
"command": {
"phive-install": {
"alias": "dephpend@^0.7.0",
"alias": "dephpend",
"bin": "%target-dir%/dephpend"
}
},
Expand All @@ -19,7 +19,7 @@
"website": "https://github.com/qossmic/deptrac",
"command": {
"phive-install": {
"alias": "qossmic/deptrac@^0.11.1",
"alias": "deptrac",
"bin": "%target-dir%/deptrac"
}
},
Expand All @@ -32,8 +32,9 @@
"website": "https://pdepend.org/",
"command": {
"phive-install": {
"alias": "pdepend/pdepend@^2.8.0",
"bin": "%target-dir%/pdepend"
"alias": "pdepend/pdepend@^2.0",
"bin": "%target-dir%/pdepend",
"unsigned": true
}
},
"test": "pdepend --version",
Expand Down
2 changes: 1 addition & 1 deletion resources/checkstyle.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"website": "https://github.com/friendsoftwig/twigcs",
"command": {
"phive-install": {
"alias": "friendsoftwig/twigcs@^5.0.0",
"alias": "friendsoftwig/twigcs@^5.0",
"bin": "%target-dir%/twigcs",
"unsigned": true
}
Expand Down
2 changes: 1 addition & 1 deletion resources/compatibility.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"website": "https://github.com/Roave/BackwardCompatibilityCheck",
"command": {
"phive-install": {
"alias": "Roave/BackwardCompatibilityCheck@^5.0.0",
"alias": "roave/backwardcompatibilitycheck@^5.0",
"bin": "%target-dir%/roave-backward-compatibility-check",
"unsigned": true
}
Expand Down
2 changes: 1 addition & 1 deletion resources/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"website": "https://github.com/icanhazstring/composer-unused",
"command": {
"phive-install": {
"alias": "composer-unused@^0.7.5",
"alias": "composer-unused",
"bin": "%target-dir%/composer-unused"
}
},
Expand Down
4 changes: 2 additions & 2 deletions resources/deprecation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"website": "https://github.com/sensiolabs-de/deprecation-detector",
"command": {
"phive-install": {
"alias": "sensiolabs-de/deprecation-detector@^0.1.0-alpha4",
"alias": "sensiolabs-de/deprecation-detector",
"bin": "%target-dir%/deprecation-detector",
"unsigned": true
}
Expand All @@ -20,7 +20,7 @@
"website": "http://wapmorgan.github.io/PhpDeprecationDetector",
"command": {
"phive-install": {
"alias": "wapmorgan/PhpDeprecationDetector@^2.0.25",
"alias": "wapmorgan/phpdeprecationdetector@^2.0",
"bin": "%target-dir%/phpdd",
"unsigned": true
}
Expand Down
5 changes: 3 additions & 2 deletions resources/linting.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
"website": "https://github.com/j13k/yaml-lint",
"command": {
"phive-install": {
"alias": "j13k/yaml-lint@^1.1.3",
"bin": "%target-dir%/yaml-lint"
"alias": "j13k/yaml-lint@^1.0",
"bin": "%target-dir%/yaml-lint",
"unsigned": true
}
},
"test": "yaml-lint --version",
Expand Down
5 changes: 3 additions & 2 deletions resources/metrics.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@
"website": "http://www.phpmetrics.org/",
"command": {
"phive-install": {
"alias": "https://github.com/phpmetrics/PhpMetrics/releases/download/v2.7.3/phpmetrics.phar",
"bin": "%target-dir%/phpmetrics"
"alias": "phpmetrics/PhpMetrics@^2.0",
"bin": "%target-dir%/phpmetrics",
"unsigned": true
}
},
"test": "phpmetrics --version",
Expand Down
5 changes: 1 addition & 4 deletions resources/pre-installation.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
"phar-download": {
"phar": "https://phar.io/releases/phive.phar",
"bin": "%target-dir%/phive"
},
"sh": {
"command": "phive --home %target-dir%"
}
},
"test": "phive --version",
Expand All @@ -49,7 +46,7 @@
"website": "https://github.com/humbug/box",
"command": {
"phive-install": {
"alias": "humbug/box@^3.11.1",
"alias": "humbug/box@^3.0",
"bin": "%target-dir%/box",
"unsigned": true
}
Expand Down
2 changes: 1 addition & 1 deletion resources/psalm.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"website": "https://psalm.dev/",
"command": {
"phive-install": {
"alias": "psalm@^4.6.2",
"alias": "psalm@^4.0",
"bin": "%target-dir%/psalm"
}
},
Expand Down
2 changes: 1 addition & 1 deletion resources/refactoring.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"website": "https://github.com/bmitch/churn-php",
"command": {
"phive-install": {
"alias": "churn@^1.5.0",
"alias": "churn@^1.0",
"bin": "%target-dir%/churn"
}
},
Expand Down
3 changes: 2 additions & 1 deletion resources/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"name": "infection",
"summary": "AST based PHP Mutation Testing Framework",
"website": "https://infection.github.io/",
"command": {
"phive-install": {
"alias": "infection@^0.21",
"bin": "%target-dir%/infection"
Expand Down Expand Up @@ -58,7 +59,7 @@
"website": "http://www.phpspec.net/",
"command": {
"phive-install": {
"alias": "https://github.com/phpspec/phpspec/releases/download/7.0.1/phpspec.phar",
"alias": "phpspec/phpspec@^7.0",
"bin": "%target-dir%/phpspec",
"unsigned": true
}
Expand Down
2 changes: 1 addition & 1 deletion resources/tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"website": "https://github.com/phpbench/phpbench",
"command": {
"phive-install": {
"alias": "phpbench/phpbench",
"alias": "phpbench",
"bin": "%target-dir%/phpbench"
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/Json/Factory/PhiveInstallCommandFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public static function import(array $command): Command
{
Assert::requireFields(['alias', 'bin'], $command, 'PhiveInstallCommand');

return new PhiveInstallCommand($command['alias'], $command['bin'], $command['trust'] ?? false, $command['unsigned'] ?? false);
return new PhiveInstallCommand($command['alias'], $command['bin'], $command['unsigned'] ?? false);
}
}
13 changes: 8 additions & 5 deletions src/Tool/Command/PhiveInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,27 @@ final class PhiveInstallCommand implements Command
{
private $alias;
private $bin;
private $trust;
private $unsigned;

public function __construct(string $alias, string $bin, bool $trust = true, bool $unsigned = false)
public function __construct(string $alias, string $bin, bool $unsigned)
{
$this->alias = $alias;
$this->bin = $bin;
$this->trust = $trust;
$this->unsigned = $unsigned;
}

public function __toString(): string
{
$home = \dirname($this->bin);
$tmp = \md5($this->alias);

return \sprintf(
'phive install %s %s %s -t %s',
$this->trust ? '--trust-gpg-keys' : '',
'echo "y" | phive --no-progress --home %s install %s %s -t %s && mv %s/* %s',
$home,
$this->unsigned ? '--force-accept-unsigned' : '',
$this->alias,
$tmp,
$tmp,
$this->bin
);
}
Expand Down
26 changes: 2 additions & 24 deletions tests/Json/Factory/PhiveInstallCommandFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function test_it_creates_a_command()
]);

$this->assertInstanceOf(PhiveInstallCommand::class, $command);
$this->assertStringNotContainsString('unsigned', (string)$command);
}

/**
Expand All @@ -35,31 +36,8 @@ public function test_it_complains_if_any_of_required_properties_is_missing(strin

unset($properties[$property]);

PhiveInstallCommandFactory::import($properties);
}

public function test_it_accepts_signed_trusted_phars()
{
$properties = [
'alias' => self::ALIAS,
'bin' => self::BIN,
];

$command = PhiveInstallCommandFactory::import($properties);
$this->assertStringNotContainsString('trust', (string)$command);
$this->assertStringNotContainsString('unsigned', (string)$command);
}

public function test_it_accepts_signed_untrusted_phars()
{
$properties = [
'alias' => self::ALIAS,
'bin' => self::BIN,
'trust' => true,
];

$command = PhiveInstallCommandFactory::import($properties);
$this->assertStringContainsString('trust', (string)$command);
$this->assertStringContainsString('unsigned', (string)$command);
}

public function test_it_accepts_unsigned_phars()
Expand Down
14 changes: 4 additions & 10 deletions tests/Tool/Command/PhiveInstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class PhiveInstallCommandTest extends TestCase

protected function setUp(): void
{
$this->command = new PhiveInstallCommand(self::ALIAS, self::BIN);
$this->command = new PhiveInstallCommand(self::ALIAS, self::BIN, false);
}

public function test_it_is_a_command()
Expand All @@ -25,18 +25,12 @@ public function test_it_is_a_command()

public function test_it_generates_the_installation_command()
{
$this->assertMatchesRegularExpression(\sprintf('#phive install(\s++)--trust-gpg-keys(\s++)%s -t %s#', self::ALIAS, self::BIN), (string) $this->command);
}

public function test_it_trusts_gpg_keys_command()
{
$command = new PhiveInstallCommand(self::ALIAS, self::BIN, false);
$this->assertMatchesRegularExpression(\sprintf('#phive install(\s++)%s -t %s#', self::ALIAS, self::BIN), (string) $command);
$this->assertMatchesRegularExpression(\sprintf('#echo "y" | phive --no-progress --home [^\s]*? install %s -t %s#', self::ALIAS, self::BIN), (string) $this->command);
}

public function test_it_accepts_unsigned_phar_command()
{
$command = new PhiveInstallCommand(self::ALIAS, self::BIN, false, true);
$this->assertMatchesRegularExpression(\sprintf('#phive install(\s++)--force-accept-unsigned(\s++)%s -t %s#', self::ALIAS, self::BIN), (string) $command);
$command = new PhiveInstallCommand(self::ALIAS, self::BIN, true);
$this->assertMatchesRegularExpression(\sprintf('#echo "y" | phive --no-progress --home [^\s]*? install --force-accept-unsigned %s -t %s#', self::ALIAS, self::BIN), (string) $command);
}
}
4 changes: 2 additions & 2 deletions tests/UseCase/InstallToolsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ public function test_it_includes_phar_download_commands()
public function test_it_includes_phive_install_commands()
{
$this->tools->all(Argument::type(Filter::class))->willReturn(Collection::create([
$this->tool(new PhiveInstallCommand('phpunit', '/tools/phpunit')),
$this->tool(new PhiveInstallCommand('phpunit', '/tools/phpunit', false)),
]));

$command = $this->useCase->__invoke($this->filter());

$this->assertMatchesRegularExpression('#phive install[^&]*?phpunit[^&]*?/tools/phpunit#', (string)$command);
$this->assertMatchesRegularExpression('#echo "y" | phive --no-progress --home /tools install[^&]*?phpunit[^&]*?/tools/phpunit#', (string)$command);
}

public function test_it_includes_file_download_commands()
Expand Down

0 comments on commit c7c43a5

Please sign in to comment.