diff --git a/.github/workflows/test-staging.yml b/.github/workflows/test-staging.yml index bc0739f..606dea6 100644 --- a/.github/workflows/test-staging.yml +++ b/.github/workflows/test-staging.yml @@ -1,6 +1,6 @@ name: Test CI pipeline for staging -on: [push] +on: [push, pull_request] jobs: tests: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index db0131a..1f2d4d6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,6 @@ name: Test CI pipeline -on: [push] +on: [push, pull_request] jobs: tests: diff --git a/src/Command/CheckScanCommand.php b/src/Command/CheckScanCommand.php index b8f0e76..2279b41 100644 --- a/src/Command/CheckScanCommand.php +++ b/src/Command/CheckScanCommand.php @@ -74,14 +74,17 @@ protected function configure(): void } private const ACTION_STRINGS = [ - 'warnPipeline' => "a pipeline warning", - 'failPipeline' => "a pipeline failure", + 'warnPipeline' => 'a pipeline warning', + 'failPipeline' => 'a pipeline failure', 'sendEmail' => 'an email notification', 'markUnaffected' => 'the vulnerabilities to be marked as unaffected', 'markVulnerable' => 'the vulnerabilities to be flagged as vulnerable', ]; - private function writeAutomationOutput(array $ruleOutputData, SymfonyStyle $io) + /** + * @param mixed[] $ruleOutputData + */ + private function writeAutomationOutput(array $ruleOutputData, SymfonyStyle $io): void { $io->block($ruleOutputData['ruleDescription'], null, 'fg=cyan;bg=default', ' | '); @@ -91,7 +94,7 @@ private function writeAutomationOutput(array $ruleOutputData, SymfonyStyle $io) $actions = $ruleOutputData['ruleActions']; $causingString = ''; - for ($i = 0; $i < \count($actions); $i++) { + for ($i = 0; $i < \count($actions); ++$i) { if ($i !== 0) { $causingString .= $i + 1 === \count($actions) ? ' and ' : ', '; } @@ -102,7 +105,7 @@ private function writeAutomationOutput(array $ruleOutputData, SymfonyStyle $io) if (\in_array('failPipeline', $actions)) { $fgColor = 'red'; - } else if (\in_array('warnPipeline', $actions)) { + } elseif (\in_array('warnPipeline', $actions)) { $fgColor = 'yellow'; } else { $fgColor = 'blue'; @@ -111,7 +114,7 @@ private function writeAutomationOutput(array $ruleOutputData, SymfonyStyle $io) $io->text("тип The rule triggered, causing ${causingString}"); } - $io->text(' Manage rule: ' . $ruleOutputData['ruleLink'] . ''); + $io->text(' Manage rule: '.$ruleOutputData['ruleLink'].''); if ($ruleOutputData['triggered'] === true) { $io->newLine(); @@ -127,12 +130,12 @@ private function writeAutomationOutput(array $ruleOutputData, SymfonyStyle $io) $tableRows = \array_map(function ($trigger) use ($hasCves) { $row = []; if ($hasCves === true) { - $row[] = $trigger['cve'] . "\n" . $trigger['cveLink'] . "\n"; + $row[] = $trigger['cve']."\n".$trigger['cveLink']."\n"; $row[] = $trigger['cvss2'] ?? ''; $row[] = $trigger['cvss3'] ?? ''; } - $row[] = $trigger['dependency'] . "\n" . $trigger['dependencyLink'] . "\n"; + $row[] = $trigger['dependency']."\n".$trigger['dependencyLink']."\n"; $row[] = \implode(', ', $trigger['licenses']); return $row; @@ -228,13 +231,13 @@ public function execute(InputInterface $input, OutputInterface $output): int $io->text($urlMessage); if (isset($status['automationRules'])) { - $io->section("Output from automations"); + $io->section('Output from automations'); $numRulesChecked = \count($status['automationRules']); if ($numRulesChecked === 0) { - $io->text("No rules were checked"); - } else if ($numRulesChecked === 1) { - $io->text("1 rule was checked:"); + $io->text('No rules were checked'); + } elseif ($numRulesChecked === 1) { + $io->text('1 rule was checked:'); } else { $io->text("${numRulesChecked} rules were checked:"); } diff --git a/tests/Command/CheckScanCommandTest.php b/tests/Command/CheckScanCommandTest.php index 41f9bdc..d636cfe 100644 --- a/tests/Command/CheckScanCommandTest.php +++ b/tests/Command/CheckScanCommandTest.php @@ -72,8 +72,7 @@ private function runAutomationsActionTest( int $expectedStatusCode = 0, string $automationsActionFieldName = 'automationsAction', array $automationRules = null - ): string - { + ): string { $response = new MockResponse(\json_encode([ 'progress' => 100, 'vulnerabilitiesFound' => 0, @@ -132,7 +131,7 @@ public function testAutomationOutputUntriggered() 'ruleDescription' => 'untriggered description', 'ruleLink' => 'link-to-rule', 'triggered' => false, - ] + ], ]); $this->assertContains("\nOutput from automations\n", $output); @@ -152,7 +151,7 @@ public function testAutomationOutputPipelineFailure() 'ruleActions' => ['failPipeline', 'sendEmail'], 'hasCves' => true, 'triggerEvents' => [], - ] + ], ]); $this->assertContains("\nOutput from automations\n", $output); @@ -173,7 +172,7 @@ public function testAutomationOutputPipelineWarning() 'ruleActions' => ['warnPipeline'], 'hasCves' => true, 'triggerEvents' => [], - ] + ], ]); $this->assertContains("\nOutput from automations\n", $output); @@ -188,7 +187,7 @@ public function testAutomationOutputMultipleRules() { $output = $this->runAutomationsActionTest('fail', 2, 'automationsAction', [ [ - 'ruleDescription' => "rule description 1", + 'ruleDescription' => 'rule description 1', 'ruleLink' => 'link-to-rule-1', 'triggered' => true, 'ruleActions' => ['failPipeline'], @@ -201,7 +200,7 @@ public function testAutomationOutputMultipleRules() 'cveLink' => 'cve-link-1', 'dependency' => 'dep-1', 'dependencyLink' => 'dep-link-1', - 'licenses' => ['gpl3'] + 'licenses' => ['gpl3'], ], [ 'cve' => 'cve-2', @@ -209,18 +208,18 @@ public function testAutomationOutputMultipleRules() 'cvss2' => 7, 'dependency' => 'dep-2', 'dependencyLink' => 'dep-link-2', - 'licenses' => ['mit'] - ] + 'licenses' => ['mit'], + ], ], ], [ - 'ruleDescription' => "rule description 2", + 'ruleDescription' => 'rule description 2', 'ruleLink' => 'link-to-rule-2', 'triggered' => false, - 'ruleActions' => ['failPipeline'] + 'ruleActions' => ['failPipeline'], ], [ - 'ruleDescription' => "rule description 3", + 'ruleDescription' => 'rule description 3', 'ruleLink' => 'link-to-rule-3', 'triggered' => true, 'ruleActions' => ['warnPipeline', 'sendEmail'], @@ -229,13 +228,13 @@ public function testAutomationOutputMultipleRules() [ 'dependency' => 'dep-1', 'dependencyLink' => 'dep-link-1', - 'licenses' => ['apache', 'mit'] + 'licenses' => ['apache', 'mit'], ], [ 'dependency' => 'dep-3', 'dependencyLink' => 'dep-link-3', - 'licenses' => ['mit'] - ] + 'licenses' => ['mit'], + ], ], ], ]); @@ -253,25 +252,25 @@ public function testAutomationOutputMultipleRules() $this->assertStringStartsWith(' ---', $outputLines[$rule1Begin + 6]); $this->assertEquals( ['Vulnerability', 'CVSS2', 'CVSS3', 'Dependency', 'Dependency', 'Licenses'], - \preg_split('/\s+/', $outputLines[$rule1Begin + 7], NULL, PREG_SPLIT_NO_EMPTY) + \preg_split('/\s+/', $outputLines[$rule1Begin + 7], null, PREG_SPLIT_NO_EMPTY) ); $this->assertStringStartsWith(' ---', $outputLines[$rule1Begin + 8]); $this->assertEquals( ['cve-1', '8', '9', 'dep-1', 'gpl3'], - \preg_split('/\s+/', $outputLines[$rule1Begin + 9], NULL, PREG_SPLIT_NO_EMPTY) + \preg_split('/\s+/', $outputLines[$rule1Begin + 9], null, PREG_SPLIT_NO_EMPTY) ); $this->assertEquals( ['cve-link-1', 'dep-link-1'], - \preg_split('/\s+/', $outputLines[$rule1Begin + 10], NULL, PREG_SPLIT_NO_EMPTY) + \preg_split('/\s+/', $outputLines[$rule1Begin + 10], null, PREG_SPLIT_NO_EMPTY) ); $this->assertEquals('', $outputLines[$rule1Begin + 11]); $this->assertEquals( ['cve-2', '7', 'dep-2', 'mit'], - \preg_split('/\s+/', $outputLines[$rule1Begin + 12], NULL, PREG_SPLIT_NO_EMPTY) + \preg_split('/\s+/', $outputLines[$rule1Begin + 12], null, PREG_SPLIT_NO_EMPTY) ); $this->assertEquals( ['cve-link-2', 'dep-link-2'], - \preg_split('/\s+/', $outputLines[$rule1Begin + 13], NULL, PREG_SPLIT_NO_EMPTY) + \preg_split('/\s+/', $outputLines[$rule1Begin + 13], null, PREG_SPLIT_NO_EMPTY) ); $rule2Begin = \array_search(' | rule description 2', $outputLines); @@ -287,25 +286,25 @@ public function testAutomationOutputMultipleRules() $this->assertStringStartsWith(' ---', $outputLines[$rule3Begin + 6]); $this->assertEquals( ['Dependency', 'Dependency', 'Licenses'], - \preg_split('/\s+/', $outputLines[$rule3Begin + 7], NULL, PREG_SPLIT_NO_EMPTY) + \preg_split('/\s+/', $outputLines[$rule3Begin + 7], null, PREG_SPLIT_NO_EMPTY) ); $this->assertStringStartsWith(' ---', $outputLines[$rule3Begin + 8]); $this->assertEquals( ['dep-1', 'apache,', 'mit'], - \preg_split('/\s+/', $outputLines[$rule3Begin + 9], NULL, PREG_SPLIT_NO_EMPTY) + \preg_split('/\s+/', $outputLines[$rule3Begin + 9], null, PREG_SPLIT_NO_EMPTY) ); $this->assertEquals( ['dep-link-1'], - \preg_split('/\s+/', $outputLines[$rule3Begin + 10], NULL, PREG_SPLIT_NO_EMPTY) + \preg_split('/\s+/', $outputLines[$rule3Begin + 10], null, PREG_SPLIT_NO_EMPTY) ); $this->assertEquals('', $outputLines[$rule3Begin + 11]); $this->assertEquals( ['dep-3', 'mit'], - \preg_split('/\s+/', $outputLines[$rule3Begin + 12], NULL, PREG_SPLIT_NO_EMPTY) + \preg_split('/\s+/', $outputLines[$rule3Begin + 12], null, PREG_SPLIT_NO_EMPTY) ); $this->assertEquals( ['dep-link-3'], - \preg_split('/\s+/', $outputLines[$rule3Begin + 13], NULL, PREG_SPLIT_NO_EMPTY) + \preg_split('/\s+/', $outputLines[$rule3Begin + 13], null, PREG_SPLIT_NO_EMPTY) ); $this->assertGreaterThan($rule1Begin, $rule2Begin);