Skip to content

Commit

Permalink
Add insecure option
Browse files Browse the repository at this point in the history
  • Loading branch information
dshemin committed Oct 2, 2020
1 parent 32094f4 commit 749a466
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/Bundle/CoverallsBundle/Command/CoverallsJobsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
*/
class CoverallsJobsCommand extends Command
{
/**
* Skip SSL verification while sending a report if true.
*
* @var bool
*/
protected $allowInsecure;

/**
* Path to project root directory.
*
Expand Down Expand Up @@ -114,6 +121,12 @@ protected function configure()
InputOption::VALUE_OPTIONAL,
'Root directory of the project.',
'.'
)
->addOption(
'insecure',
'-k',
InputOption::VALUE_NONE,
'Skip SSL certificate check.'
);
}

Expand All @@ -136,6 +149,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$config = $this->loadConfiguration($input, $this->rootDir);
$this->logger = $config->isVerbose() && !$config->isTestEnv() ? new ConsoleLogger($output) : new NullLogger();
$this->allowInsecure = (bool) $input->getOption('insecure');

$executionStatus = $this->executeApi($config);

Expand Down Expand Up @@ -175,13 +189,19 @@ protected function loadConfiguration(InputInterface $input, $rootDir)
/**
* Execute Jobs API.
*
* @param Configuration $config configuration
* @param InputInterface $input input arguments
* @param Configuration $config configuration
*
* @return bool
*/
protected function executeApi(Configuration $config)
{
$client = new Client();
$params = [];
if ($this->allowInsecure) {
$params['verify'] = false;
}

$client = new Client($params);
$api = new Jobs($config, $client);
$repository = new JobsRepository($api, $config);

Expand Down
33 changes: 33 additions & 0 deletions tests/Bundle/CoverallsBundle/Command/CoverallsJobsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,39 @@ public function shouldExecuteCoverallsJobsCommandThrowInvalidConfigurationExcept
);
}

/**
* @test
*/
public function shouldExecuteCoverallsJobsCommandWithInsecureOption()
{
$this->makeProjectDir(null, $this->logsDir);
$this->dumpCloverXml();

$command = new CoverallsJobsCommand();
$command->setRootDir($this->rootDir);

$app = new Application();
$app->add($command);

$command = $app->find('coveralls:v1:jobs');
$commandTester = new CommandTester($command);

$_SERVER['TRAVIS'] = true;
$_SERVER['TRAVIS_JOB_ID'] = 'command_test';

$actual = $commandTester->execute(
[
'command' => $command->getName(),
'--dry-run' => true,
'--config' => 'coveralls.yml',
'--env' => 'test',
'--insecure' => true,
]
);

$this->assertSame(0, $actual);
}

protected function legacySetUp()
{
$this->setUpDir(realpath(__DIR__ . '/../../..'));
Expand Down

0 comments on commit 749a466

Please sign in to comment.