RemoteSecurityAdvisoryTest.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php declare(strict_types=1);
  2. namespace Packagist\WebBundle\Tests\SecurityAdvisory;
  3. use Packagist\WebBundle\Entity\SecurityAdvisory;
  4. use Packagist\WebBundle\SecurityAdvisory\RemoteSecurityAdvisory;
  5. use PHPUnit\Framework\TestCase;
  6. class RemoteSecurityAdvisoryTest extends TestCase
  7. {
  8. public function testCreateFromFriendsOfPhp(): void
  9. {
  10. $advisory = RemoteSecurityAdvisory::createFromFriendsOfPhp('3f/pygmentize/2017-05-15.yaml', [
  11. 'title' => 'Remote Code Execution',
  12. 'link' => 'https://github.com/dedalozzo/pygmentize/issues/1',
  13. 'cve' => null,
  14. 'branches' => [
  15. '1.x' => [
  16. 'time' => 1494806400,
  17. 'versions' => ['<1.2'],
  18. ],
  19. ],
  20. 'reference' => 'composer://3f/pygmentize'
  21. ]);
  22. $this->assertSame('3f/pygmentize/2017-05-15.yaml', $advisory->getId());
  23. $this->assertSame('Remote Code Execution', $advisory->getTitle());
  24. $this->assertSame('https://github.com/dedalozzo/pygmentize/issues/1', $advisory->getLink());
  25. $this->assertNull($advisory->getCve());
  26. $this->assertSame('<1.2', $advisory->getAffectedVersions());
  27. $this->assertSame('3f/pygmentize', $advisory->getPackageName());
  28. $this->assertSame('2017-05-15 00:00:00', $advisory->getDate()->format('Y-m-d H:i:s'));
  29. $this->assertSame(SecurityAdvisory::PACKAGIST_ORG, $advisory->getComposerRepository());
  30. }
  31. public function testCreateFromFriendsOfPhpOnlyYearAvailable(): void
  32. {
  33. $advisory = RemoteSecurityAdvisory::createFromFriendsOfPhp('erusev/parsedown/CVE-2019-10905.yaml', [
  34. 'title' => 'Class-Name Injection',
  35. 'link' => 'https://github.com/erusev/parsedown/issues/699',
  36. 'cve' => 'CVE-2019-10905',
  37. 'branches' => [
  38. '1.0.x' => [
  39. 'time' => null,
  40. 'versions' => ['<1.7.2'],
  41. ],
  42. ],
  43. 'reference' => 'composer://erusev/parsedown'
  44. ]);
  45. $this->assertSame('2019-01-01 00:00:00', $advisory->getDate()->format('Y-m-d H:i:s'));
  46. }
  47. public function testCreateFromFriendsOfPhpOnlyYearButBranchDatesAvailable(): void
  48. {
  49. $advisory = RemoteSecurityAdvisory::createFromFriendsOfPhp('magento/magento1ee/CVE-2019-8114.yaml', [
  50. 'title' => 'PRODSECBUG-2462: Remote code execution via file upload in admin import feature',
  51. 'link' => 'https://magento.com/security/patches/magento-2.3.3-and-2.2.10-security-update',
  52. 'cve' => 'CVE-2019-8114',
  53. 'branches' => [
  54. '1' => [
  55. 'time' => 1570492800,
  56. 'versions' => ['>=1', '<1.14.4.3'],
  57. ],
  58. ],
  59. 'reference' => 'composer://magento/magento1ee',
  60. 'composer-repository' => false,
  61. ]);
  62. $this->assertSame('2019-10-08 00:00:00', $advisory->getDate()->format('Y-m-d H:i:s'));
  63. }
  64. }