Issues (8)

Security Analysis    no request data  

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/Reader/DbalReaderTest.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 Port\Dbal\Tests;
4
5
use Port\Dbal\DbalReader;
6
use Doctrine\DBAL\Configuration;
7
use Doctrine\DBAL\Connection;
8
use Doctrine\DBAL\DriverManager;
9
use Doctrine\DBAL\Platforms\SqlitePlatform;
10
use Doctrine\DBAL\Schema\Schema;
11
12
class DbalReaderTest extends \PHPUnit_Framework_TestCase
13
{
14
    public function testCalculateRowCount()
15
    {
16
        $reader = $this->getReader();
17
18
        $reader->setRowCountCalculated();
19
        $this->assertTrue($reader->isRowCountCalculated());
20
21
        $reader->setRowCountCalculated(false);
22
        $this->assertFalse($reader->isRowCountCalculated());
23
24
        $reader->setRowCountCalculated(true);
25
        $this->assertTrue($reader->isRowCountCalculated());
26
    }
27
28
    public function testCount()
29
    {
30
        $this->assertEquals(10, $this->getReader()->count());
31
    }
32
33
    public function testCountInhibited()
34
    {
35
        $reader = $this->getReader();
36
        $reader->setRowCountCalculated(false);
37
38
        $this->assertEquals(null, $reader->count());
39
    }
40
41
    public function testSqlAndParamsAreMutable()
42
    {
43
        $reader = $this->getReader();
44
45
        $reader->setSql('SELECT * FROM groups WHERE id = :id', array('id' => 2));
46
        $this->assertAttributeEquals('SELECT * FROM groups WHERE id = :id', 'sql', $reader);
47
        $this->assertAttributeEquals(array('id' => 2), 'params', $reader);
48
    }
49
50
    public function testChangeSqlOrParamsClearsNumRowsAndStatement()
51
    {
52
        $reader = $this->getReader();
53
        $reader->count();
54
        $reader->current();
55
56
        $this->assertAttributeNotEmpty('rowCount', $reader);
57
        $this->assertAttributeNotEmpty('stmt', $reader);
58
59
        $reader->setSql('SELECT * FROM `user` WHERE id IN (:id)', array('id' => array()));
60
61
        $this->assertAttributeEmpty('rowCount', $reader);
62
        $this->assertAttributeEmpty('stmt', $reader);
63
    }
64
65
    public function testIterate()
66
    {
67
        $i=31;
68
        foreach ($this->getReader() as $key => $row) {
69
            $this->assertInternalType('array', $row);
70
            $this->assertEquals('user-'.$i, $row['username']);
71
            $this->assertEquals($i - 31, $key);
72
            $i++;
73
        }
74
75
        $this->assertEquals(41, $i);
76
    }
77
78
    public function testReaderRewindWorksCorrectly()
79
    {
80
        $reader = $this->getReader();
81
        foreach ($reader as $row) {
82
            if (!isset($row['username'])) {
83
                $this->fail('There should be a username');
84
            }
85
            if ($row['username'] == 'user-35') {
86
                break;
87
            }
88
        }
89
90
        $reader->rewind();
91
92
        $this->assertEquals(array(
93
            'id' => 31,
94
            'username' => 'user-31',
95
            'name' => 'name 4',
96
        ), $reader->current());
97
    }
98
99
    public function testCallingCurrentTwiceShouldNotAdvance()
100
    {
101
        $reader = $this->getReader();
102
103
        $expected = array(
104
            'id' => 31,
105
            'username' => 'user-31',
106
            'name' => 'name 4',
107
        );
108
        $this->assertEquals($expected, $reader->current());
109
        $this->assertEquals($expected, $reader->current());
110
    }
111
112
    public function testEmptyResultDoesNotThrowException()
113
    {
114
        $reader = $this->getReader();
115
116
        $reader->setSql(null, array('name' => 'unknown group'));
117
        $this->assertFalse($reader->current());
118
    }
119
120
    public function testCallValidRewindsIfNeeded()
121
    {
122
        $reader = $this->getReader();
123
124
        $this->assertTrue($reader->valid());
125
        $this->assertAttributeInternalType('array', 'data', $reader);
126
    }
127
128
    public function getConnection()
129
    {
130
        $params = array(
131
            'driver' => 'pdo_sqlite',
132
            'memory' => true,
133
        );
134
135
        $connection = DriverManager::getConnection($params, new Configuration());
136
137
        $schema = new Schema();
138
139
        $table = $schema->createTable('groups');
140
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
141
        $table->addColumn('name', 'string', array('length' => 45));
142
        $table->setPrimaryKey(array('id'));
143
144
        $myTable = $schema->createTable('user');
145
        $myTable->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true));
146
        $myTable->addColumn('username', 'string', array('length' => 32));
147
        $myTable->addColumn('group_id', 'integer');
148
        $myTable->setPrimaryKey(array('id'));
149
        $myTable->addUniqueIndex(array('username'));
150
        $myTable->addForeignKeyConstraint($table, array('group_id'), array('id'));
151
152
        foreach ($schema->toSql(new SqlitePlatform()) as $query) {
153
            $connection->query($query);
0 ignored issues
show
Deprecated Code introduced by
The method Doctrine\DBAL\Connection::query() has been deprecated with message: Use {@link executeQuery()} instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
154
        };
155
156
        return $connection;
157
    }
158
159
    protected function getReader()
160
    {
161
        $connection = $this->getConnection();
162
        $this->loadFixtures($connection);
163
164
        return new DbalReader($connection, implode(' ', array(
165
            'SELECT u.id, u.username, g.name',
166
            'FROM `user` u INNER JOIN groups g ON u.group_id = g.id',
167
            'WHERE g.name LIKE :name',
168
        )), array(
169
            'name' => 'name 4',
170
        ));
171
    }
172
173
    /**
174
     * @param Connection $connection
175
     */
176
    protected function loadFixtures($connection)
177
    {
178
        $counter = 1;
179
        for ($i = 1; $i <= 10; $i++) {
180
            $connection->insert('groups', array('name' => "name {$i}"));
181
            $id = $connection->lastInsertId();
182
183
            for ($j = 1; $j <= 10; $j++) {
184
                $connection->insert('user', array(
185
                    'username' => "user-{$counter}",
186
                    'group_id' => $id,
187
                ));
188
189
                $counter++;
190
            }
191
        }
192
    }
193
}
194