Issues (220)

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/DropDatabaseDoctrineTest.php (1 issue)

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 Doctrine\Bundle\DoctrineBundle\Tests\Command;
4
5
use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand;
6
use Doctrine\DBAL\DBALException;
7
use Generator;
8
use PHPUnit\Framework\MockObject\MockObject;
9
use PHPUnit\Framework\TestCase;
10
use Symfony\Component\Console\Application;
11
use Symfony\Component\Console\Tester\CommandTester;
12
13
class DropDatabaseDoctrineTest extends TestCase
14
{
15
    /**
16
     * @dataProvider provideForceOption
17
     */
18
    public function testExecute(array $options) : void
19
    {
20
        $connectionName = 'default';
21
        $dbName         = 'test';
22
        $params         = [
23
            'url' => 'sqlite:///' . sys_get_temp_dir() . '/test.db',
24
            'path' => sys_get_temp_dir() . '/' . $dbName,
25
            'driver' => 'pdo_sqlite',
26
        ];
27
28
        $container = $this->getMockContainer($connectionName, $params);
29
30
        $application = new Application();
31
        $application->add(new DropDatabaseDoctrineCommand($container->get('doctrine')));
32
33
        $command = $application->find('doctrine:database:drop');
34
35
        $commandTester = new CommandTester($command);
36
        $commandTester->execute(
37
            array_merge(['command' => $command->getName()], $options)
38
        );
39
40
        $this->assertContains(
41
            sprintf(
42
                'Dropped database %s for connection named %s',
43
                sys_get_temp_dir() . '/' . $dbName,
44
                $connectionName
45
            ),
46
            $commandTester->getDisplay()
47
        );
48
    }
49
50
    /**
51
     * @dataProvider provideIncompatibleDriverOptions
52
     */
53
    public function testItThrowsWhenUsingIfExistsWithAnIncompatibleDriver(array $options) : void
54
    {
55
        static::expectException(DBALException::class);
56
        $this->testExecute($options);
57
    }
58
59
    public function testExecuteWithoutOptionForceWillFailWithAttentionMessage() : void
60
    {
61
        $connectionName = 'default';
62
        $dbName         = 'test';
63
        $params         = [
64
            'path' => sys_get_temp_dir() . '/' . $dbName,
65
            'driver' => 'pdo_sqlite',
66
        ];
67
68
        $container = $this->getMockContainer($connectionName, $params);
69
70
        $application = new Application();
71
        $application->add(new DropDatabaseDoctrineCommand($container->get('doctrine')));
72
73
        $command = $application->find('doctrine:database:drop');
74
75
        $commandTester = new CommandTester($command);
76
        $commandTester->execute(
77
            array_merge(['command' => $command->getName()])
78
        );
79
80
        $this->assertContains(
81
            sprintf(
82
                'Would drop the database %s for connection named %s.',
83
                sys_get_temp_dir() . '/' . $dbName,
84
                $connectionName
85
            ),
86
            $commandTester->getDisplay()
87
        );
88
        $this->assertContains('Please run the operation with --force to execute', $commandTester->getDisplay());
89
    }
90
91
    public function provideForceOption() : Generator
92
    {
93
        yield 'full name' => [
94
            ['--force' => true],
95
        ];
96
        yield 'short name' => [
97
            ['-f' => true],
98
        ];
99
    }
100
101
    public function provideIncompatibleDriverOptions() : Generator
102
    {
103
        yield 'full name' => [
104
            [
105
                '--force' => true,
106
                '--if-exists' => true,
107
            ],
108
        ];
109
        yield 'short name' => [
110
            [
111
                '-f' => true,
112
                '--if-exists' => true,
113
            ],
114
        ];
115
    }
116
117
    /**
118
     * @param array|null $params Connection parameters
119
     */
120 View Code Duplication
    private function getMockContainer(string $connectionName, array $params = null) : MockObject
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
121
    {
122
        // Mock the container and everything you'll need here
123
        $mockDoctrine = $this->getMockBuilder('Doctrine\Persistence\ManagerRegistry')
124
            ->getMock();
125
126
        $mockDoctrine->expects($this->any())
127
            ->method('getDefaultConnectionName')
128
            ->withAnyParameters()
129
            ->willReturn($connectionName);
130
131
        $mockConnection = $this->getMockBuilder('Doctrine\DBAL\Connection')
132
            ->disableOriginalConstructor()
133
            ->setMethods(['getParams'])
134
            ->getMockForAbstractClass();
135
136
        $mockConnection->expects($this->any())
137
            ->method('getParams')
138
            ->withAnyParameters()
139
            ->willReturn($params);
140
141
        $mockDoctrine->expects($this->any())
142
            ->method('getConnection')
143
            ->withAnyParameters()
144
            ->willReturn($mockConnection);
145
146
        $mockContainer = $this->getMockBuilder('Symfony\Component\DependencyInjection\Container')
147
            ->setMethods(['get'])
148
            ->getMock();
149
150
        $mockContainer->expects($this->any())
151
            ->method('get')
152
            ->with('doctrine')
153
            ->willReturn($mockDoctrine);
154
155
        return $mockContainer;
156
    }
157
}
158