Skip to content

Commit

Permalink
Implement SecurityChecker (#171)
Browse files Browse the repository at this point in the history
* Implement SecurityChecker

* Remove unused class; Load advisories only when var is empty
  • Loading branch information
karniv00l authored and akondas committed May 28, 2020
1 parent f89cfbc commit 5c15fc4
Show file tree
Hide file tree
Showing 25 changed files with 3,247 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ coverage:
project:
default:
informational: true
path:
patch:
default:
informational: true
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ GA_TRACKING=
###> storage ###
PROXY_DIST_DIR=%kernel.project_dir%/var/proxy
PACKAGES_DIST_DIR=%kernel.project_dir%/var/repo
SECURITY_ADVISORIES_DB_DIR=%kernel.project_dir%/var/security-advisories
###< storage ###
1 change: 1 addition & 0 deletions .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ GA_TRACKING=
###> storage ###
PROXY_DIST_DIR=%kernel.project_dir%/var/proxy
PACKAGES_DIST_DIR=%kernel.project_dir%/var/repo
SECURITY_ADVISORIES_DB_DIR=%kernel.project_dir%/var/security-advisories
###< storage ###

5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"require": {
"php": "^7.4.1",
"ext-ctype": "*",
"ext-curl": "*",
"ext-iconv": "*",
"ext-intl": "*",
"ext-zip": "*",
"ext-curl": "*",
"ext-pdo_pgsql": "*",
"ext-zip": "*",
"bitbucket/client": "^2.1",
"buddy-works/buddy-works-php-api": "^1.3",
"buddy-works/oauth2-client": "^0.1",
Expand Down Expand Up @@ -40,6 +40,7 @@
"symfony/messenger": "5.0.*",
"symfony/monolog-bundle": "^3.5",
"symfony/orm-pack": "^1.0",
"symfony/process": "5.0.*",
"symfony/security-bundle": "5.0.*",
"symfony/twig-pack": "^1.0",
"symfony/validator": "5.0.*",
Expand Down
60 changes: 44 additions & 16 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ parameters:
url_scheme: '%env(resolve:APP_URL_SCHEME)%'
router.request_context.scheme: '%env(resolve:APP_URL_SCHEME)%'
router.request_context.host: '%env(default:domain:APP_PUBLIC_HOST)%'
security_advisories_db_dir: '%env(resolve:SECURITY_ADVISORIES_DB_DIR)%'
security_advisories_db_repo: 'https://github.com/FriendsOfPHP/security-advisories.git'

services:
# default configuration for services in *this* file
Expand Down Expand Up @@ -78,6 +80,11 @@ services:
bitbucket: '%env(OAUTH_BITBUCKET_CLIENT_ID)%'
buddy: '%env(OAUTH_BUDDY_CLIENT_ID)%'

Buddy\Repman\Service\Security\SecurityChecker\SensioLabsSecurityChecker:
arguments:
$databaseDir: '%security_advisories_db_dir%'
$databaseRepo: '%security_advisories_db_repo%'

### Vendor
Github\Client:
arguments:
Expand Down
5 changes: 5 additions & 0 deletions config/services_test.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
parameters:
dists_dir: '%kernel.project_dir%/tests/Resources'
repo_dir: '%kernel.project_dir%/tests/Resources'
security_advisories_db_dir: '%kernel.project_dir%/tests/Resources/fixtures/security/security-advisories'
security_advisories_db_repo: 'bogus'

services:
Buddy\Repman\Service\Downloader:
Expand Down Expand Up @@ -31,3 +33,6 @@ services:

Buddy\Repman\Service\Security\PackageScanner:
class: Buddy\Repman\Tests\Doubles\FakePackageScanner

Buddy\Repman\Service\Security\SecurityChecker:
class: Buddy\Repman\Tests\Doubles\FakeSecurityChecker
41 changes: 41 additions & 0 deletions src/Command/UpdateAdvisoriesDbCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Buddy\Repman\Command;

use Buddy\Repman\Service\Security\SecurityChecker;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class UpdateAdvisoriesDbCommand extends Command
{
private SecurityChecker $checker;

public function __construct(SecurityChecker $checker)
{
parent::__construct();

$this->checker = $checker;
}

/**
* @return void
*/
protected function configure()
{
$this
->setName('repman:security:update-db')
->setDescription('Update security advisories database')
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$this->checker->update();
$output->writeln(sprintf('Database successfully updated'));

return 0;
}
}
47 changes: 47 additions & 0 deletions src/Service/Security/SecurityChecker/Advisory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Buddy\Repman\Service\Security\SecurityChecker;

final class Advisory
{
private string $title;
private string $cve;
private string $link;
/**
* @var Versions[]
*/
private array $branches;

/**
* @param Versions[] $branches
*/
public function __construct(string $title, string $cve, string $link, array $branches)
{
$this->title = $title;
$this->cve = $cve;
$this->link = $link;
$this->branches = $branches;
}

/**
* @return Versions[]
*/
public function branches(): array
{
return $this->branches;
}

/**
* @return array<string,string>
*/
public function toArray(): array
{
return [
'title' => $this->title,
'cve' => $this->cve,
'link' => $this->link,
];
}
}
27 changes: 27 additions & 0 deletions src/Service/Security/SecurityChecker/Package.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Buddy\Repman\Service\Security\SecurityChecker;

final class Package
{
private string $name;
private string $version;

public function __construct(string $name, string $version)
{
$this->name = $name;
$this->version = $version;
}

public function name(): string
{
return $this->name;
}

public function version(): string
{
return $this->version;
}
}
34 changes: 34 additions & 0 deletions src/Service/Security/SecurityChecker/Result.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Buddy\Repman\Service\Security\SecurityChecker;

final class Result
{
private string $version;
/**
* @var Advisory[]
*/
private array $advisories;

/**
* @param Advisory[] $advisories
*/
public function __construct(string $version, array $advisories)
{
$this->version = $version;
$this->advisories = $advisories;
}

/**
* @return array<string,string|array<string,string>>
*/
public function toArray(): array
{
return [
'version' => $this->version,
'advisories' => array_map(fn ($advisory) => $advisory->toArray(), $this->advisories),
];
}
}
Loading

0 comments on commit 5c15fc4

Please sign in to comment.