Skip to content

Commit

Permalink
Use block list in code and comments (#216)
Browse files Browse the repository at this point in the history
* Use block list in code and comments

* Update NoUpdatesTest.php

* Update NoUpdatesTest.php

* Update NoUpdatesTest.php

* Update NoUpdatesTest.php
  • Loading branch information
eiriksm committed Aug 19, 2021
1 parent 27ae098 commit ca99c19
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/CosyComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,23 +730,23 @@ public function run()
$this->log(sprintf('Skipping update of %s because it is not indicated as a security update', $item->name));
}
}
// Remove blacklisted packages.
$block_list = $config->getBlackList();
// Remove block listed packages.
$block_list = $config->getBlockList();
if (!is_array($block_list)) {
$this->log('The format for the package block list was not correct. Expected an array, got ' . gettype($cdata->extra->violinist->blacklist), Message::VIOLINIST_ERROR);
} else {
foreach ($data as $delta => $item) {
if (in_array($item->name, $block_list)) {
$this->log(sprintf('Skipping update of %s because it is blacklisted', $item->name), Message::BLACKLISTED, [
$this->log(sprintf('Skipping update of %s because it is on the block list', $item->name), Message::BLACKLISTED, [
'package' => $item->name,
]);
unset($data[$delta]);
continue;
}
// Also try to match on wildcards.
foreach ($block_list as $blacklist_item) {
if (fnmatch($blacklist_item, $item->name)) {
$this->log(sprintf('Skipping update of %s because it is blacklisted by pattern %s', $item->name, $blacklist_item), Message::BLACKLISTED, [
foreach ($block_list as $block_list_item) {
if (fnmatch($block_list_item, $item->name)) {
$this->log(sprintf('Skipping update of %s because it is on the block list by pattern %s', $item->name, $block_list_item), Message::BLACKLISTED, [
'package' => $item->name,
]);
unset($data[$delta]);
Expand Down
24 changes: 21 additions & 3 deletions test/integration/NoUpdatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ function ($cmd) use (&$called) {
$this->assertEquals(true, $called);
}

public function testNoUpdatesBecauseBlacklisted()
/**
* Test that block list works.
*
* @dataProvider getBlockListOptions
*/
public function testNoUpdatesBecauseBlocklisted($opt)
{
$c = $this->getMockCosy();
$dir = '/tmp/' . uniqid();
Expand All @@ -121,7 +126,7 @@ public function testNoUpdatesBecauseBlacklisted()
]);
$c->setOutput($mock_output);

$composer_contents = '{"require": {"drupal/core": "8.0.0"}, "extra": {"violinist": { "blacklist": ["eiriksm/fake-package"]}}}';
$composer_contents = '{"require": {"drupal/core": "8.0.0"}, "extra": {"violinist": { "' . $opt . '": ["eiriksm/fake-package"]}}}';
$composer_file = "$dir/composer.json";
file_put_contents($composer_file, $composer_contents);
$called = false;
Expand All @@ -139,7 +144,20 @@ function ($cmd) use (&$called) {
$this->assertEquals(false, $called);
$c->run();
$this->assertEquals(true, $called);
$this->assertOutputContainsMessage('Skipping update of eiriksm/fake-package because it is blacklisted', $c);
$this->assertOutputContainsMessage('Skipping update of eiriksm/fake-package because it is on the block list', $c);
$this->assertOutputContainsMessage('No updates found', $c);
}

public function getBlockListOptions()
{
return [
[
'blocklist',
],
[
// The old deprecated option name that we still support.
'blacklist',
],
];
}
}

0 comments on commit ca99c19

Please sign in to comment.