Issues (143)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Tests/Command/EnqueueWebhooksCommandTest.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Loevgaard\DandomainAltapayBundle\Tests\Command;
4
5
use JMS\Serializer\SerializerBuilder;
6
use JMS\Serializer\SerializerInterface;
7
use Loevgaard\DandomainAltapayBundle\Command\EnqueueWebhooksCommand;
8
use Loevgaard\DandomainAltapayBundle\Entity\Event;
9
use Loevgaard\DandomainAltapayBundle\Entity\EventRepository;
10
use Loevgaard\DandomainAltapayBundle\Entity\WebhookExchange;
11
use Loevgaard\DandomainAltapayBundle\Entity\WebhookExchangeRepository;
12
use PHPUnit\Framework\TestCase;
13
use Symfony\Component\Console\Application;
14
use Symfony\Component\Console\Tester\CommandTester;
15
use Symfony\Component\DependencyInjection\ContainerInterface;
16
17
class EnqueueWebhooksCommandTest extends TestCase
18
{
19
    public function testNoWebhookUrls()
20
    {
21
        $command = $this->getCommand();
22
23
        $application = new Application();
24
        $application->setAutoExit(false);
25
        $application->add($command);
26
27
        $command = $application->find('loevgaard:dandomain:altapay:enqueue-webhooks');
28
        $commandTester = new CommandTester($command);
29
        $exitCode = $commandTester->execute([
30
            'command' => $command->getName(),
31
        ]);
32
33
        $this->assertSame('No webhook URLs defined', trim($commandTester->getDisplay()));
34
        $this->assertSame(0, $exitCode, 'Returns 0 if there are not webhook URLs');
35
    }
36
37
    public function testExecute()
38
    {
39
        $webhookUrl = 'https://www.example.com';
40
41
        $container = $this->getContainer();
42
        $container
43
            ->method('getParameter')
44
            ->with('loevgaard_dandomain_altapay.webhook_urls')
45
            ->willReturn([$webhookUrl]);
46
47
        $webhookExchangeRepository = $this->getWebhookExchangeRepository();
48
        $webhookExchangeRepository
49
            ->method('findByUrlOrCreate')
50
            ->with($webhookUrl)
51
            ->willReturn(new WebhookExchange($webhookUrl));
52
53
        $event = new Event('event', 'event_body');
54
        $event->setId(1);
55
        $eventRepository = $this->getEventRepository();
56
        $eventRepository
57
            ->method('findRecentEvents')
58
            ->willReturn([$event]);
59
60
        $command = $this->getCommand($webhookExchangeRepository, $eventRepository, null, $container);
61
62
        $application = new Application();
63
        $application->setAutoExit(false);
64
        $application->add($command);
65
66
        $command = $application->find('loevgaard:dandomain:altapay:enqueue-webhooks');
67
        $commandTester = new CommandTester($command);
68
        $exitCode = $commandTester->execute([
69
            'command' => $command->getName(),
70
        ]);
71
72
        $this->assertSame(0, $exitCode, 'Returns 0 on success');
73
    }
74
75
    /**
76
     * @param null $webhookExchangeRepository
77
     * @param null $eventRepository
78
     * @param null $serializer
79
     * @param null $container
80
     *
81
     * @return EnqueueWebhooksCommand
82
     */
83
    private function getCommand($webhookExchangeRepository = null, $eventRepository = null, $serializer = null, $container = null)
84
    {
85
        if (!$webhookExchangeRepository) {
86
            $webhookExchangeRepository = $this->getWebhookExchangeRepository();
87
        }
88
89
        if (!$eventRepository) {
90
            $eventRepository = $this->getEventRepository();
91
        }
92
93
        if (!$serializer) {
94
            $serializer = $this->getSerializer();
95
        }
96
97
        if (!$container) {
98
            $container = $this->getContainer();
99
        }
100
101
        $command = new EnqueueWebhooksCommand($webhookExchangeRepository, $eventRepository, $serializer);
102
        $command->setContainer($container);
0 ignored issues
show
It seems like $container defined by $this->getContainer() on line 98 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Symfony\Bundle\Framework...Command::setContainer() does only seem to accept null|object<Symfony\Comp...ion\ContainerInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
103
104
        return $command;
105
    }
106
107
    /**
108
     * @return WebhookExchangeRepository|\PHPUnit_Framework_MockObject_MockObject
109
     */
110
    private function getWebhookExchangeRepository()
111
    {
112
        return $this->createMock(WebhookExchangeRepository::class);
113
    }
114
115
    /**
116
     * @return EventRepository|\PHPUnit_Framework_MockObject_MockObject
117
     */
118
    private function getEventRepository()
119
    {
120
        return $this->createMock(EventRepository::class);
121
    }
122
123
    private function getSerializer(): SerializerInterface
124
    {
125
        return SerializerBuilder::create()->build();
126
    }
127
128
    /**
129
     * @return \PHPUnit_Framework_MockObject_MockObject|ContainerInterface
130
     */
131
    private function getContainer()
132
    {
133
        return $this->createMock(ContainerInterface::class);
134
    }
135
}
136